Fix Pools
This commit is contained in:
parent
d7d9d9efa1
commit
89e0dd9380
@ -250,20 +250,24 @@ class Mikrotik
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function setPool($client, $oldName, $name, $ip_address){
|
public static function setPool($client, $name, $ip_address){
|
||||||
$printRequest = new RouterOS\Request(
|
$printRequest = new RouterOS\Request(
|
||||||
'/ip pool print .proplist=name',
|
'/ip pool print .proplist=name',
|
||||||
RouterOS\Query::where('name', $oldName)
|
RouterOS\Query::where('name', $name)
|
||||||
);
|
);
|
||||||
$poolName = $client->sendSync($printRequest)->getProperty('name');
|
$poolName = $client->sendSync($printRequest)->getProperty('name');
|
||||||
|
|
||||||
|
if(empty($poolName)){
|
||||||
|
self::addPool($client, $name, $ip_address);
|
||||||
|
}else{
|
||||||
$setRequest = new RouterOS\Request('/ip/pool/set');
|
$setRequest = new RouterOS\Request('/ip/pool/set');
|
||||||
$client(
|
$client(
|
||||||
$setRequest
|
$setRequest
|
||||||
->setArgument('numbers', $name)
|
->setArgument('numbers', $poolName)
|
||||||
->setArgument('ranges', $ip_address)
|
->setArgument('ranges', $ip_address)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function addPpoePlan($client, $name, $pool, $rate){
|
public static function addPpoePlan($client, $name, $pool, $rate){
|
||||||
@ -283,7 +287,9 @@ class Mikrotik
|
|||||||
RouterOS\Query::where('name', $name)
|
RouterOS\Query::where('name', $name)
|
||||||
);
|
);
|
||||||
$profileName = $client->sendSync($printRequest)->getProperty('name');
|
$profileName = $client->sendSync($printRequest)->getProperty('name');
|
||||||
|
if(empty($profileName)){
|
||||||
|
self::addPpoePlan($client, $name, $pool, $rate);
|
||||||
|
}else{
|
||||||
$setRequest = new RouterOS\Request('/ppp/profile/set');
|
$setRequest = new RouterOS\Request('/ppp/profile/set');
|
||||||
$client(
|
$client(
|
||||||
$setRequest
|
$setRequest
|
||||||
@ -293,6 +299,7 @@ class Mikrotik
|
|||||||
->setArgument('rate-limit', $rate)
|
->setArgument('rate-limit', $rate)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static function removePpoePlan($client, $name){
|
public static function removePpoePlan($client, $name){
|
||||||
$printRequest = new RouterOS\Request(
|
$printRequest = new RouterOS\Request(
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* PHP Mikrotik Billing (https://ibnux.github.io/phpmixbill/)
|
|
||||||
**/
|
|
||||||
|
|
||||||
Class Router{
|
|
||||||
|
|
||||||
}
|
|
@ -39,50 +39,6 @@ function _post($param, $defvalue = '')
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$menu_registered = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register for global menu
|
|
||||||
* @param string name Name of the menu
|
|
||||||
* @param bool admin true if for admin and false for customer
|
|
||||||
* @param string function function to run after menu clicks
|
|
||||||
* @param string position position of menu, use AFTER_ for root menu |
|
|
||||||
* Admin/Sales menu: AFTER_DASHBOARD, CUSTOMERS, PREPAID, SERVICES, REPORTS, VOUCHER, AFTER_ORDER, NETWORK, SETTINGS, AFTER_PAYMENTGATEWAY
|
|
||||||
* | Customer menu: AFTER_DASHBOARD, ORDER, HISTORY, ACCOUNTS
|
|
||||||
* @param string icon from ion icon, ion-person, only for AFTER_
|
|
||||||
*/
|
|
||||||
function register_menu($name, $admin, $function, $position, $icon = '')
|
|
||||||
{
|
|
||||||
global $menu_registered;
|
|
||||||
$menu_registered[] = [
|
|
||||||
"name" => $name,
|
|
||||||
"admin" => $admin,
|
|
||||||
"position" => $position,
|
|
||||||
"icon" => $icon,
|
|
||||||
"function" => $function
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
$hook_registered = array();
|
|
||||||
|
|
||||||
function register_hook($action, $function){
|
|
||||||
$hook_registered[] = [
|
|
||||||
'action' => $action,
|
|
||||||
'function' => $function
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
function run_hook($action){
|
|
||||||
global $hook_registered;
|
|
||||||
foreach($hook_registered as $hook){
|
|
||||||
if($hook['action'] == $action){
|
|
||||||
if(function_exists($hook['function'])){
|
|
||||||
call_user_func($hook['function']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function _get($param, $defvalue = '')
|
function _get($param, $defvalue = '')
|
||||||
{
|
{
|
||||||
if (!isset($_GET[$param])) {
|
if (!isset($_GET[$param])) {
|
||||||
@ -100,7 +56,9 @@ ORM::configure('username', $db_user);
|
|||||||
ORM::configure('password', $db_password);
|
ORM::configure('password', $db_password);
|
||||||
ORM::configure('driver_options', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
|
ORM::configure('driver_options', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
|
||||||
ORM::configure('return_result_sets', true);
|
ORM::configure('return_result_sets', true);
|
||||||
|
if($_app_stage != 'Live'){
|
||||||
ORM::configure('logging', true);
|
ORM::configure('logging', true);
|
||||||
|
}
|
||||||
|
|
||||||
$result = ORM::for_table('tbl_appconfig')->find_many();
|
$result = ORM::for_table('tbl_appconfig')->find_many();
|
||||||
foreach ($result as $value) {
|
foreach ($result as $value) {
|
||||||
@ -110,6 +68,14 @@ foreach ($result as $value) {
|
|||||||
date_default_timezone_set($config['timezone']);
|
date_default_timezone_set($config['timezone']);
|
||||||
$_c = $config;
|
$_c = $config;
|
||||||
|
|
||||||
|
if($config['radius_mode']){
|
||||||
|
ORM::configure("mysql:host=$radius_host;dbname=$radius_name", null, 'radius');
|
||||||
|
ORM::configure('username', $radius_user, 'radius');
|
||||||
|
ORM::configure('password', $radius_password, 'radius');
|
||||||
|
ORM::configure('driver_options', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'), 'radius');
|
||||||
|
ORM::configure('return_result_sets', true, 'radius');
|
||||||
|
}
|
||||||
|
|
||||||
function _notify($msg, $type = 'e')
|
function _notify($msg, $type = 'e')
|
||||||
{
|
{
|
||||||
$_SESSION['ntype'] = $type;
|
$_SESSION['ntype'] = $type;
|
||||||
@ -162,6 +128,8 @@ if (isset($_SESSION['notify'])) {
|
|||||||
unset($_SESSION['ntype']);
|
unset($_SESSION['ntype']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
include "autoload/Hookers.php";
|
||||||
|
|
||||||
|
|
||||||
//register all plugin
|
//register all plugin
|
||||||
foreach (glob("system/plugin/*.php") as $filename)
|
foreach (glob("system/plugin/*.php") as $filename)
|
||||||
@ -263,20 +231,20 @@ function alphanumeric($str, $tambahan = "")
|
|||||||
|
|
||||||
function sendTelegram($txt)
|
function sendTelegram($txt)
|
||||||
{
|
{
|
||||||
global $_c;
|
global $config;
|
||||||
run_hook('send_telegram'); #HOOK
|
run_hook('send_telegram'); #HOOK
|
||||||
if (!empty($_c['telegram_bot']) && !empty($_c['telegram_target_id'])) {
|
if (!empty($config['telegram_bot']) && !empty($config['telegram_target_id'])) {
|
||||||
file_get_contents('https://api.telegram.org/bot' . $_c['telegram_bot'] . '/sendMessage?chat_id=' . $_c['telegram_target_id'] . '&text=' . urlencode($txt));
|
file_get_contents('https://api.telegram.org/bot' . $config['telegram_bot'] . '/sendMessage?chat_id=' . $config['telegram_target_id'] . '&text=' . urlencode($txt));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function sendSMS($phone, $txt)
|
function sendSMS($phone, $txt)
|
||||||
{
|
{
|
||||||
global $_c;
|
global $config;
|
||||||
run_hook('send_sms'); #HOOK
|
run_hook('send_sms'); #HOOK
|
||||||
if (!empty($_c['sms_url'])) {
|
if (!empty($config['sms_url'])) {
|
||||||
$smsurl = str_replace('[number]', urlencode($phone), $_c['sms_url']);
|
$smsurl = str_replace('[number]', urlencode($phone), $config['sms_url']);
|
||||||
$smsurl = str_replace('[text]', urlencode($txt), $smsurl);
|
$smsurl = str_replace('[text]', urlencode($txt), $smsurl);
|
||||||
file_get_contents($smsurl);
|
file_get_contents($smsurl);
|
||||||
}
|
}
|
||||||
@ -284,10 +252,10 @@ function sendSMS($phone, $txt)
|
|||||||
|
|
||||||
function sendWhatsapp($phone, $txt)
|
function sendWhatsapp($phone, $txt)
|
||||||
{
|
{
|
||||||
global $_c;
|
global $config;
|
||||||
run_hook('send_whatsapp'); #HOOK
|
run_hook('send_whatsapp'); #HOOK
|
||||||
if (!empty($_c['wa_url'])) {
|
if (!empty($config['wa_url'])) {
|
||||||
$waurl = str_replace('[number]', urlencode($phone), $_c['wa_url']);
|
$waurl = str_replace('[number]', urlencode($phone), $config['wa_url']);
|
||||||
$waurl = str_replace('[text]', urlencode($txt), $waurl);
|
$waurl = str_replace('[text]', urlencode($txt), $waurl);
|
||||||
file_get_contents($waurl);
|
file_get_contents($waurl);
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ switch ($action) {
|
|||||||
if ($msg == '') {
|
if ($msg == '') {
|
||||||
if (!$config['radius_mode']) {
|
if (!$config['radius_mode']) {
|
||||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||||
Mikrotik::removePool($client, $name, $ip_address);
|
Mikrotik::addPool($client, $name, $ip_address);
|
||||||
}
|
}
|
||||||
|
|
||||||
$b = ORM::for_table('tbl_pool')->create();
|
$b = ORM::for_table('tbl_pool')->create();
|
||||||
@ -111,14 +111,11 @@ switch ($action) {
|
|||||||
|
|
||||||
|
|
||||||
case 'edit-post':
|
case 'edit-post':
|
||||||
$name = _post('name');
|
|
||||||
$ip_address = _post('ip_address');
|
$ip_address = _post('ip_address');
|
||||||
$routers = _post('routers');
|
$routers = _post('routers');
|
||||||
run_hook('edit_pool'); #HOOK
|
run_hook('edit_pool'); #HOOK
|
||||||
$msg = '';
|
$msg = '';
|
||||||
if (Validator::Length($name, 30, 2) == false) {
|
|
||||||
$msg .= 'Name should be between 3 to 30 characters' . '<br>';
|
|
||||||
}
|
|
||||||
if ($ip_address == '' or $routers == '') {
|
if ($ip_address == '' or $routers == '') {
|
||||||
$msg .= $_L['All_field_is_required'] . '<br>';
|
$msg .= $_L['All_field_is_required'] . '<br>';
|
||||||
}
|
}
|
||||||
@ -134,10 +131,9 @@ switch ($action) {
|
|||||||
if ($msg == '') {
|
if ($msg == '') {
|
||||||
if (!$config['radius_mode']) {
|
if (!$config['radius_mode']) {
|
||||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||||
Mikrotik::setPool($client, $name,$poolName, $ip_address);
|
Mikrotik::setPool($client, $d['pool_name'], $ip_address);
|
||||||
}
|
}
|
||||||
|
|
||||||
$d->pool_name = $name;
|
|
||||||
$d->range_ip = $ip_address;
|
$d->range_ip = $ip_address;
|
||||||
$d->routers = $routers;
|
$d->routers = $routers;
|
||||||
$d->save();
|
$d->save();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user