diff --git a/system/autoload/Mikrotik.php b/system/autoload/Mikrotik.php index e3f6d71b..5031fc83 100644 --- a/system/autoload/Mikrotik.php +++ b/system/autoload/Mikrotik.php @@ -244,25 +244,29 @@ class Mikrotik public static function addPool($client, $name, $ip_address){ $addRequest = new RouterOS\Request('/ip/pool/add'); - $client->sendSync($addRequest - ->setArgument('name', $name) - ->setArgument('ranges', $ip_address) - ); + $client->sendSync($addRequest + ->setArgument('name', $name) + ->setArgument('ranges', $ip_address) + ); } - public static function setPool($client, $oldName, $name, $ip_address){ + public static function setPool($client, $name, $ip_address){ $printRequest = new RouterOS\Request( '/ip pool print .proplist=name', - RouterOS\Query::where('name', $oldName) + RouterOS\Query::where('name', $name) ); $poolName = $client->sendSync($printRequest)->getProperty('name'); - $setRequest = new RouterOS\Request('/ip/pool/set'); - $client( - $setRequest - ->setArgument('numbers', $name) - ->setArgument('ranges', $ip_address) - ); + if(empty($poolName)){ + self::addPool($client, $name, $ip_address); + }else{ + $setRequest = new RouterOS\Request('/ip/pool/set'); + $client( + $setRequest + ->setArgument('numbers', $poolName) + ->setArgument('ranges', $ip_address) + ); + } } @@ -283,15 +287,18 @@ class Mikrotik RouterOS\Query::where('name', $name) ); $profileName = $client->sendSync($printRequest)->getProperty('name'); - - $setRequest = new RouterOS\Request('/ppp/profile/set'); - $client( - $setRequest - ->setArgument('numbers', $profileName) - ->setArgument('local-address', $pool) - ->setArgument('remote-address', $pool) - ->setArgument('rate-limit', $rate) - ); + if(empty($profileName)){ + self::addPpoePlan($client, $name, $pool, $rate); + }else{ + $setRequest = new RouterOS\Request('/ppp/profile/set'); + $client( + $setRequest + ->setArgument('numbers', $profileName) + ->setArgument('local-address', $pool) + ->setArgument('remote-address', $pool) + ->setArgument('rate-limit', $rate) + ); + } } public static function removePpoePlan($client, $name){ diff --git a/system/autoload/Router.php b/system/autoload/Router.php deleted file mode 100644 index 1f4cda1e..00000000 --- a/system/autoload/Router.php +++ /dev/null @@ -1,8 +0,0 @@ - $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 = '') { if (!isset($_GET[$param])) { @@ -100,7 +56,9 @@ ORM::configure('username', $db_user); ORM::configure('password', $db_password); ORM::configure('driver_options', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); ORM::configure('return_result_sets', true); -ORM::configure('logging', true); +if($_app_stage != 'Live'){ + ORM::configure('logging', true); +} $result = ORM::for_table('tbl_appconfig')->find_many(); foreach ($result as $value) { @@ -110,6 +68,14 @@ foreach ($result as $value) { date_default_timezone_set($config['timezone']); $_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') { $_SESSION['ntype'] = $type; @@ -162,6 +128,8 @@ if (isset($_SESSION['notify'])) { unset($_SESSION['ntype']); } +include "autoload/Hookers.php"; + //register all plugin foreach (glob("system/plugin/*.php") as $filename) @@ -263,20 +231,20 @@ function alphanumeric($str, $tambahan = "") function sendTelegram($txt) { - global $_c; + global $config; run_hook('send_telegram'); #HOOK - if (!empty($_c['telegram_bot']) && !empty($_c['telegram_target_id'])) { - file_get_contents('https://api.telegram.org/bot' . $_c['telegram_bot'] . '/sendMessage?chat_id=' . $_c['telegram_target_id'] . '&text=' . urlencode($txt)); + if (!empty($config['telegram_bot']) && !empty($config['telegram_target_id'])) { + 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) { - global $_c; + global $config; run_hook('send_sms'); #HOOK - if (!empty($_c['sms_url'])) { - $smsurl = str_replace('[number]', urlencode($phone), $_c['sms_url']); + if (!empty($config['sms_url'])) { + $smsurl = str_replace('[number]', urlencode($phone), $config['sms_url']); $smsurl = str_replace('[text]', urlencode($txt), $smsurl); file_get_contents($smsurl); } @@ -284,10 +252,10 @@ function sendSMS($phone, $txt) function sendWhatsapp($phone, $txt) { - global $_c; + global $config; run_hook('send_whatsapp'); #HOOK - if (!empty($_c['wa_url'])) { - $waurl = str_replace('[number]', urlencode($phone), $_c['wa_url']); + if (!empty($config['wa_url'])) { + $waurl = str_replace('[number]', urlencode($phone), $config['wa_url']); $waurl = str_replace('[text]', urlencode($txt), $waurl); file_get_contents($waurl); } diff --git a/system/controllers/pool.php b/system/controllers/pool.php index 363bd270..84d4675d 100644 --- a/system/controllers/pool.php +++ b/system/controllers/pool.php @@ -94,7 +94,7 @@ switch ($action) { if ($msg == '') { if (!$config['radius_mode']) { $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(); @@ -111,14 +111,11 @@ switch ($action) { case 'edit-post': - $name = _post('name'); $ip_address = _post('ip_address'); $routers = _post('routers'); run_hook('edit_pool'); #HOOK $msg = ''; - if (Validator::Length($name, 30, 2) == false) { - $msg .= 'Name should be between 3 to 30 characters' . '
'; - } + if ($ip_address == '' or $routers == '') { $msg .= $_L['All_field_is_required'] . '
'; } @@ -134,10 +131,9 @@ switch ($action) { if ($msg == '') { if (!$config['radius_mode']) { $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->routers = $routers; $d->save();