diff --git a/system/autoload/Mikrotik.php b/system/autoload/Mikrotik.php new file mode 100644 index 0000000..e3f6d71 --- /dev/null +++ b/system/autoload/Mikrotik.php @@ -0,0 +1,310 @@ +where('name',$name)->find_one(); + return $d; + } + + public static function getClient($ip, $user, $pass) + { + try { + $iport = explode(":", $ip); + return new RouterOS\Client($iport[0], $user, $pass, ($iport[1]) ? $iport[1] : null); + } catch (Exception $e) { + die("Unable to connect to the router.
" . $e->getMessage()); + } + } + + public static function addHotspotPlan($client, $name, $sharedusers, $rate){ + $addRequest = new RouterOS\Request('/ip/hotspot/user/profile/add'); + $client->sendSync( + $addRequest + ->setArgument('name', $name) + ->setArgument('shared-users', $sharedusers) + ->setArgument('rate-limit', $rate) + ); + } + + public static function setHotspotPlan($client, $name, $sharedusers, $rate){ + $printRequest = new RouterOS\Request( + '/ip hotspot user profile print .proplist=name', + RouterOS\Query::where('name', $name) + ); + $profileName = $client->sendSync($printRequest)->getProperty('name'); + + $setRequest = new RouterOS\Request('/ip/hotspot/user/profile/set'); + $client( + $setRequest + ->setArgument('numbers', $profileName) + ->setArgument('shared-users', $sharedusers) + ->setArgument('rate-limit', $rate) + ); + } + + public static function removeHotspotPlan($client, $name){ + $printRequest = new RouterOS\Request( + '/ip hotspot user profile print .proplist=name', + RouterOS\Query::where('name', $name) + ); + $profileName = $client->sendSync($printRequest)->getProperty('name'); + + $removeRequest = new RouterOS\Request('/ip/hotspot/user/profile/remove'); + $client( + $removeRequest + ->setArgument('numbers', $profileName) + ); + } + + public static function removeHotspotUser($client, $username) + { + $printRequest = new RouterOS\Request( + '/ip hotspot user print .proplist=name', + RouterOS\Query::where('name', $username) + ); + $userName = $client->sendSync($printRequest)->getProperty('name'); + $removeRequest = new RouterOS\Request('/ip/hotspot/user/remove'); + $client( + $removeRequest + ->setArgument('numbers', $userName) + ); + } + + public static function addHotspotUser($client, $plan, $customer) + { + $addRequest = new RouterOS\Request('/ip/hotspot/user/add'); + if ($plan['typebp'] == "Limited") { + if ($plan['limit_type'] == "Time_Limit") { + if ($plan['time_unit'] == 'Hrs') + $timelimit = $plan['time_limit'] . ":00:00"; + else + $timelimit = "00:" . $plan['time_limit'] . ":00"; + $client->sendSync( + $addRequest + ->setArgument('name', $customer['username']) + ->setArgument('profile', $plan['name_plan']) + ->setArgument('password', $customer['password']) + ->setArgument('limit-uptime', $timelimit) + ); + } else if ($plan['limit_type'] == "Data_Limit") { + if ($plan['data_unit'] == 'GB') + $datalimit = $plan['data_limit'] . "000000000"; + else + $datalimit = $plan['data_limit'] . "000000"; + $client->sendSync( + $addRequest + ->setArgument('name', $customer['username']) + ->setArgument('profile', $plan['name_plan']) + ->setArgument('password', $customer['password']) + ->setArgument('limit-bytes-total', $datalimit) + ); + } else if ($plan['limit_type'] == "Both_Limit") { + if ($plan['time_unit'] == 'Hrs') + $timelimit = $plan['time_limit'] . ":00:00"; + else + $timelimit = "00:" . $plan['time_limit'] . ":00"; + if ($plan['data_unit'] == 'GB') + $datalimit = $plan['data_limit'] . "000000000"; + else + $datalimit = $plan['data_limit'] . "000000"; + $client->sendSync( + $addRequest + ->setArgument('name', $customer['username']) + ->setArgument('profile', $plan['name_plan']) + ->setArgument('password', $customer['password']) + ->setArgument('limit-uptime', $timelimit) + ->setArgument('limit-bytes-total', $datalimit) + ); + } + } else { + $client->sendSync( + $addRequest + ->setArgument('name', $customer['username']) + ->setArgument('profile', $plan['name_plan']) + ->setArgument('password', $customer['password']) + ); + } + } + + public static function setHotspotUser($client, $user, $pass, $nuser= null){ + $printRequest = new RouterOS\Request('/ip/hotspot/user/print'); + $printRequest->setArgument('.proplist', '.id'); + $printRequest->setQuery(RouterOS\Query::where('name', $user)); + $id = $client->sendSync($printRequest)->getProperty('.id'); + + $setRequest = new RouterOS\Request('/ip/hotspot/user/set'); + $setRequest->setArgument('numbers', $id); + $setRequest->setArgument('password', $pass); + $client->sendSync($setRequest); + } + + public static function removeHotspotActiveUser($client, $username) + { + $onlineRequest = new RouterOS\Request('/ip/hotspot/active/print'); + $onlineRequest->setArgument('.proplist', '.id'); + $onlineRequest->setQuery(RouterOS\Query::where('user', $username)); + $id = $client->sendSync($onlineRequest)->getProperty('.id'); + + $removeRequest = new RouterOS\Request('/ip/hotspot/active/remove'); + $removeRequest->setArgument('numbers', $id); + $client->sendSync($removeRequest); + } + + public static function setHotspotLimitUptime($client, $username) + { + $printRequest = new RouterOS\Request('/ip/hotspot/user/print'); + $printRequest->setArgument('.proplist', '.id'); + $printRequest->setQuery(RouterOS\Query::where('name', $username)); + $id = $client->sendSync($printRequest)->getProperty('.id'); + + $setRequest = new RouterOS\Request('/ip/hotspot/user/set'); + $setRequest->setArgument('numbers', $id); + $setRequest->setArgument('limit-uptime', '00:00:05'); + $client->sendSync($setRequest); + } + + public static function removePpoeUser($client, $username) + { + $printRequest = new RouterOS\Request( + '/ppp secret print .proplist=name', + RouterOS\Query::where('name', $username) + ); + $userName = $client->sendSync($printRequest)->getProperty('name'); + + $removeRequest = new RouterOS\Request('/ppp/secret/remove'); + $client( + $removeRequest + ->setArgument('numbers', $userName) + ); + } + + public static function addPpoeUser($client, $plan, $customer) + { + $addRequest = new RouterOS\Request('/ppp/secret/add'); + $client->sendSync( + $addRequest + ->setArgument('name', $customer['username']) + ->setArgument('service', 'pppoe') + ->setArgument('profile', $plan['name_plan']) + ->setArgument('password', $customer['password']) + ); + } + + public static function setPpoeUser($client, $user, $pass, $nuser= null){ + $printRequest = new RouterOS\Request('/ppp/secret/print'); + $printRequest->setArgument('.proplist', '.id'); + $printRequest->setQuery(RouterOS\Query::where('name', $user['username'])); + $id = $client->sendSync($printRequest)->getProperty('.id'); + + $setRequest = new RouterOS\Request('/ppp/secret/set'); + $setRequest->setArgument('numbers', $id); + $setRequest->setArgument('password', $pass); + $client->sendSync($setRequest); + } + + public static function disablePpoeUser($client, $username) + { + $printRequest = new RouterOS\Request('/ppp/secret/print'); + $printRequest->setArgument('.proplist', '.id'); + $printRequest->setQuery(RouterOS\Query::where('name', $username)); + $id = $client->sendSync($printRequest)->getProperty('.id'); + + $setRequest = new RouterOS\Request('/ppp/secret/disable'); + $setRequest->setArgument('numbers', $id); + $client->sendSync($setRequest); + } + + public static function removePpoeActive($client, $username) + { + $onlineRequest = new RouterOS\Request('/ppp/active/print'); + $onlineRequest->setArgument('.proplist', '.id'); + $onlineRequest->setQuery(RouterOS\Query::where('name', $username)); + $id = $client->sendSync($onlineRequest)->getProperty('.id'); + + $removeRequest = new RouterOS\Request('/ppp/active/remove'); + $removeRequest->setArgument('numbers', $id); + $client->sendSync($removeRequest); + } + + public static function removePool($client, $name){ + $printRequest = new RouterOS\Request( + '/ip pool print .proplist=name', + RouterOS\Query::where('name', $name) + ); + $poolName = $client->sendSync($printRequest)->getProperty('name'); + + $removeRequest = new RouterOS\Request('/ip/pool/remove'); + $client($removeRequest + ->setArgument('numbers', $poolName) + ); + } + + 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) + ); + } + + public static function setPool($client, $oldName, $name, $ip_address){ + $printRequest = new RouterOS\Request( + '/ip pool print .proplist=name', + RouterOS\Query::where('name', $oldName) + ); + $poolName = $client->sendSync($printRequest)->getProperty('name'); + + $setRequest = new RouterOS\Request('/ip/pool/set'); + $client( + $setRequest + ->setArgument('numbers', $name) + ->setArgument('ranges', $ip_address) + ); + } + + + public static function addPpoePlan($client, $name, $pool, $rate){ + $addRequest = new RouterOS\Request('/ppp/profile/add'); + $client->sendSync( + $addRequest + ->setArgument('name', $name) + ->setArgument('local-address', $pool) + ->setArgument('remote-address', $pool) + ->setArgument('rate-limit', $rate) + ); + } + + public static function setPpoePlan($client, $name, $pool, $rate){ + $printRequest = new RouterOS\Request( + '/ppp profile print .proplist=name', + 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) + ); + } + + public static function removePpoePlan($client, $name){ + $printRequest = new RouterOS\Request( + '/ppp profile print .proplist=name', + RouterOS\Query::where('name', $name) + ); + $profileName = $client->sendSync($printRequest)->getProperty('name'); + + $removeRequest = new RouterOS\Request('/ppp/profile/remove'); + $client( + $removeRequest + ->setArgument('numbers', $profileName) + ); + } +} diff --git a/system/autoload/Package.php b/system/autoload/Package.php index 6b1f447..fce1c58 100644 --- a/system/autoload/Package.php +++ b/system/autoload/Package.php @@ -32,7 +32,7 @@ class Package $p = ORM::for_table('tbl_plans')->where('id', $plan_id)->where('enabled', '1')->find_one(); $b = ORM::for_table('tbl_user_recharges')->where('customer_id', $id_customer)->find_one(); - $mikrotik = Router::_info($router_name); + $mikrotik = Mikrotik::info($router_name); if ($p['validity_unit'] == 'Months') { $date_exp = date("Y-m-d", strtotime('+' . $p['validity'] . ' month')); } else if ($p['validity_unit'] == 'Days') { @@ -50,79 +50,9 @@ class Package if ($p['type'] == 'Hotspot') { if ($b) { if (!$_c['radius_mode']) { - try { - $iport = explode(":", $mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null); - } catch (Exception $e) { - die("Unable to connect to the router.
" . $e->getMessage()); - } - - $printRequest = new RouterOS\Request( - '/ip hotspot user print .proplist=name', - RouterOS\Query::where('name', $c['username']) - ); - $userName = $client->sendSync($printRequest)->getProperty('name'); - $removeRequest = new RouterOS\Request('/ip/hotspot/user/remove'); - $client( - $removeRequest - ->setArgument('numbers', $userName) - ); - /* iBNuX Added: - * Time limit to Mikrotik - * 'Time_Limit', 'Data_Limit', 'Both_Limit' - */ - $addRequest = new RouterOS\Request('/ip/hotspot/user/add'); - if ($p['typebp'] == "Limited") { - if ($p['limit_type'] == "Time_Limit") { - if ($p['time_unit'] == 'Hrs') - $timelimit = $p['time_limit'] . ":00:00"; - else - $timelimit = "00:" . $p['time_limit'] . ":00"; - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-uptime', $timelimit) - ); - } else if ($p['limit_type'] == "Data_Limit") { - if ($p['data_unit'] == 'GB') - $datalimit = $p['data_limit'] . "000000000"; - else - $datalimit = $p['data_limit'] . "000000"; - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-bytes-total', $datalimit) - ); - } else if ($p['limit_type'] == "Both_Limit") { - if ($p['time_unit'] == 'Hrs') - $timelimit = $p['time_limit'] . ":00:00"; - else - $timelimit = "00:" . $p['time_limit'] . ":00"; - if ($p['data_unit'] == 'GB') - $datalimit = $p['data_limit'] . "000000000"; - else - $datalimit = $p['data_limit'] . "000000"; - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-uptime', $timelimit) - ->setArgument('limit-bytes-total', $datalimit) - ); - } - } else { - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ); - } + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::removeHotspotUser($client,$c['username']); + Mikrotik::addHotspotUser($client,$p,$c); } $b->customer_id = $id_customer; @@ -153,69 +83,8 @@ class Package $t->save(); } else { if (!$_c['radius_mode']) { - try { - $iport = explode(":", $mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null); - } catch (Exception $e) { - die("Unable to connect to the router.
" . $e->getMessage()); - } - - /* iBNuX Added: - * Time limit to Mikrotik - * 'Time_Limit', 'Data_Limit', 'Both_Limit' - */ - $addRequest = new RouterOS\Request('/ip/hotspot/user/add'); - if ($p['typebp'] == "Limited") { - if ($p['limit_type'] == "Time_Limit") { - if ($p['time_unit'] == 'Hrs') - $timelimit = $p['time_limit'] . ":00:00"; - else - $timelimit = "00:" . $p['time_limit'] . ":00"; - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-uptime', $timelimit) - ); - } else if ($p['limit_type'] == "Data_Limit") { - if ($p['data_unit'] == 'GB') - $datalimit = $p['data_limit'] . "000000000"; - else - $datalimit = $p['data_limit'] . "000000"; - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-bytes-total', $datalimit) - ); - } else if ($p['limit_type'] == "Both_Limit") { - if ($p['time_unit'] == 'Hrs') - $timelimit = $p['time_limit'] . ":00:00"; - else - $timelimit = "00:" . $p['time_limit'] . ":00"; - if ($p['data_unit'] == 'GB') - $datalimit = $p['data_limit'] . "000000000"; - else - $datalimit = $p['data_limit'] . "000000"; - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-uptime', $timelimit) - ->setArgument('limit-bytes-total', $datalimit) - ); - } - } else { - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ); - } + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::addHotspotUser($client,$p,$c); } $d = ORM::for_table('tbl_user_recharges')->create(); @@ -255,32 +124,9 @@ class Package if ($b) { if (!$_c['radius_mode']) { - try { - $iport = explode(":", $mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null); - } catch (Exception $e) { - die("Unable to connect to the router.
" . $e->getMessage()); - } - $printRequest = new RouterOS\Request( - '/ppp secret print .proplist=name', - RouterOS\Query::where('name', $c['username']) - ); - $userName = $client->sendSync($printRequest)->getProperty('name'); - - $removeRequest = new RouterOS\Request('/ppp/secret/remove'); - $client( - $removeRequest - ->setArgument('numbers', $userName) - ); - - $addRequest = new RouterOS\Request('/ppp/secret/add'); - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('service', 'pppoe') - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ); + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::removePpoeUser($client,$c['username']); + Mikrotik::addPpoeUser($client,$p,$c); } $b->customer_id = $id_customer; @@ -311,20 +157,8 @@ class Package $t->save(); } else { if (!$_c['radius_mode']) { - try { - $iport = explode(":", $mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null); - } catch (Exception $e) { - die("Unable to connect to the router.
" . $e->getMessage()); - } - $addRequest = new RouterOS\Request('/ppp/secret/add'); - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('service', 'pppoe') - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ); + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::addPpoeUser($client,$p,$c); } $d = ORM::for_table('tbl_user_recharges')->create(); diff --git a/system/autoload/Router.php b/system/autoload/Router.php index cc4f366..1f4cda1 100644 --- a/system/autoload/Router.php +++ b/system/autoload/Router.php @@ -4,8 +4,5 @@ **/ Class Router{ - public static function _info($name){ - $d = ORM::for_table('tbl_routers')->where('name',$name)->find_one(); - return $d; - } + } \ No newline at end of file diff --git a/system/controllers/accounts.php b/system/controllers/accounts.php index f3cfa6c..a8e0cd7 100644 --- a/system/controllers/accounts.php +++ b/system/controllers/accounts.php @@ -40,34 +40,12 @@ switch ($action) { $c = ORM::for_table('tbl_user_recharges')->where('username',$user['username'])->find_one(); if ($c){ - $mikrotik = Router::_info($c['routers']); + $mikrotik = Mikrotik::info($c['routers']); if($c['type'] == 'Hotspot'){ if(!$_c['radius_mode']){ - try { - $iport = explode(":",$mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'],($iport[1])?$iport[1]:null); - } catch (Exception $e) { - die("Unable to connect to the router.
".$e->getMessage()); - } - $printRequest = new RouterOS\Request('/ip/hotspot/user/print'); - $printRequest->setArgument('.proplist', '.id'); - $printRequest->setQuery(RouterOS\Query::where('name', $user['username'])); - $id = $client->sendSync($printRequest)->getProperty('.id'); - - $setRequest = new RouterOS\Request('/ip/hotspot/user/set'); - $setRequest->setArgument('numbers', $id); - $setRequest->setArgument('password', $npass); - $client->sendSync($setRequest); - - //remove hotspot active - $onlineRequest = new RouterOS\Request('/ip/hotspot/active/print'); - $onlineRequest->setArgument('.proplist', '.id'); - $onlineRequest->setQuery(RouterOS\Query::where('user', $user['username'])); - $id = $client->sendSync($onlineRequest)->getProperty('.id'); - - $removeRequest = new RouterOS\Request('/ip/hotspot/active/remove'); - $removeRequest->setArgument('numbers', $id); - $client->sendSync($removeRequest); + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::setHotspotUser($client,$c['username'],$npass); + Mikrotik::removeHotspotActiveUser($client,$user['username']); } $d->password = $npass; $d->save(); @@ -79,31 +57,9 @@ switch ($action) { }else{ if(!$_c['radius_mode']){ - try { - $iport = explode(":",$mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'],($iport[1])?$iport[1]:null); - } catch (Exception $e) { - die("Unable to connect to the router.
".$e->getMessage()); - } - $printRequest = new RouterOS\Request('/ppp/secret/print'); - $printRequest->setArgument('.proplist', '.id'); - $printRequest->setQuery(RouterOS\Query::where('name', $user['username'])); - $id = $client->sendSync($printRequest)->getProperty('.id'); - - $setRequest = new RouterOS\Request('/ppp/secret/set'); - $setRequest->setArgument('numbers', $id); - $setRequest->setArgument('password', $npass); - $client->sendSync($setRequest); - - //remove pppoe active - $onlineRequest = new RouterOS\Request('/ppp/active/print'); - $onlineRequest->setArgument('.proplist', '.id'); - $onlineRequest->setQuery(RouterOS\Query::where('name', $user['username'])); - $id = $client->sendSync($onlineRequest)->getProperty('.id'); - - $removeRequest = new RouterOS\Request('/ppp/active/remove'); - $removeRequest->setArgument('numbers', $id); - $client->sendSync($removeRequest); + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::setPpoeUser($client,$c['username'],$npass); + Mikrotik::removePpoeActive($client,$user['username']); } $d->password = $npass; $d->save(); diff --git a/system/controllers/customers.php b/system/controllers/customers.php index e93221d..34e5d6f 100644 --- a/system/controllers/customers.php +++ b/system/controllers/customers.php @@ -62,60 +62,18 @@ switch ($action) { if ($d) { $c = ORM::for_table('tbl_user_recharges')->where('username', $d['username'])->find_one(); if ($c) { - $mikrotik = Router::_info($c['routers']); + $mikrotik = Mikrotik::info($c['routers']); if ($c['type'] == 'Hotspot') { if(!$_c['radius_mode']){ - try { - $iport = explode(":", $mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null); - } catch (Exception $e) { - die("Unable to connect to the router.
" . $e->getMessage()); - } - $printRequest = new RouterOS\Request('/ip/hotspot/user/print'); - $printRequest->setArgument('.proplist', '.id'); - $printRequest->setQuery(RouterOS\Query::where('name', $c['username'])); - $id = $client->sendSync($printRequest)->getProperty('.id'); - - $setRequest = new RouterOS\Request('/ip/hotspot/user/remove'); - $setRequest->setArgument('numbers', $id); - $client->sendSync($setRequest); - - //remove hotspot active - $onlineRequest = new RouterOS\Request('/ip/hotspot/active/print'); - $onlineRequest->setArgument('.proplist', '.id'); - $onlineRequest->setQuery(RouterOS\Query::where('user', $c['username'])); - $id = $client->sendSync($onlineRequest)->getProperty('.id'); - - $removeRequest = new RouterOS\Request('/ip/hotspot/active/remove'); - $removeRequest->setArgument('numbers', $id); - $client->sendSync($removeRequest); + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::removeHotspotUser($client,$c['username']); + Mikrotik::removeHotspotActiveUser($client,$user['username']); } } else { if(!$_c['radius_mode']){ - try { - $iport = explode(":", $mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null); - } catch (Exception $e) { - die("Unable to connect to the router.
" . $e->getMessage()); - } - $printRequest = new RouterOS\Request('/ppp/secret/print'); - $printRequest->setArgument('.proplist', '.id'); - $printRequest->setQuery(RouterOS\Query::where('name', $c['username'])); - $id = $client->sendSync($printRequest)->getProperty('.id'); - - $setRequest = new RouterOS\Request('/ppp/secret/remove'); - $setRequest->setArgument('numbers', $id); - $client->sendSync($setRequest); - - //remove pppoe active - $onlineRequest = new RouterOS\Request('/ppp/active/print'); - $onlineRequest->setArgument('.proplist', '.id'); - $onlineRequest->setQuery(RouterOS\Query::where('name', $c['username'])); - $id = $client->sendSync($onlineRequest)->getProperty('.id'); - - $removeRequest = new RouterOS\Request('/ppp/active/remove'); - $removeRequest->setArgument('numbers', $id); - $client->sendSync($removeRequest); + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::removePpoeUser($client,$c['username']); + Mikrotik::removePpoeActive($client,$user['username']); } } try { @@ -222,65 +180,21 @@ switch ($action) { if ($msg == '') { $c = ORM::for_table('tbl_user_recharges')->where('username', $username)->find_one(); if ($c) { - $mikrotik = Router::_info($c['routers']); + $mikrotik = Mikrotik::info($c['routers']); if ($c['type'] == 'Hotspot') { if(!$_c['radius_mode']){ - try { - $iport = explode(":", $mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null); - } catch (Exception $e) { - die("Unable to connect to the router.
" . $e->getMessage()); - } - $printRequest = new RouterOS\Request('/ip/hotspot/user/print'); - $printRequest->setArgument('.proplist', '.id'); - $printRequest->setQuery(RouterOS\Query::where('name', $c['username'])); - $id = $client->sendSync($printRequest)->getProperty('.id'); - - $setRequest = new RouterOS\Request('/ip/hotspot/user/set'); - $setRequest->setArgument('numbers', $id); - $setRequest->setArgument('password', $password); - $client->sendSync($setRequest); - - //remove hotspot active - $onlineRequest = new RouterOS\Request('/ip/hotspot/active/print'); - $onlineRequest->setArgument('.proplist', '.id'); - $onlineRequest->setQuery(RouterOS\Query::where('user', $c['username'])); - $id = $client->sendSync($onlineRequest)->getProperty('.id'); - - $removeRequest = new RouterOS\Request('/ip/hotspot/active/remove'); - $removeRequest->setArgument('numbers', $id); - $client->sendSync($removeRequest); + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::setHotspotUser($client,$c['username'],$password); + Mikrotik::removeHotspotActiveUser($client,$user['username']); } $d->password = $password; $d->save(); } else { if(!$_c['radius_mode']){ - try { - $iport = explode(":", $mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null); - } catch (Exception $e) { - die("Unable to connect to the router.
" . $e->getMessage()); - } - $printRequest = new RouterOS\Request('/ppp/secret/print'); - $printRequest->setArgument('.proplist', '.id'); - $printRequest->setQuery(RouterOS\Query::where('name', $c['username'])); - $id = $client->sendSync($printRequest)->getProperty('.id'); - - $setRequest = new RouterOS\Request('/ppp/secret/set'); - $setRequest->setArgument('numbers', $id); - $setRequest->setArgument('password', $password); - $client->sendSync($setRequest); - - //remove pppoe active - $onlineRequest = new RouterOS\Request('/ppp/active/print'); - $onlineRequest->setArgument('.proplist', '.id'); - $onlineRequest->setQuery(RouterOS\Query::where('name', $c['username'])); - $id = $client->sendSync($onlineRequest)->getProperty('.id'); - - $removeRequest = new RouterOS\Request('/ppp/active/remove'); - $removeRequest->setArgument('numbers', $id); - $client->sendSync($removeRequest); + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::setPpoeUser($client,$c['username'],$password); + Mikrotik::removePpoeActive($client,$user['username']); } $d->password = $password; diff --git a/system/controllers/pool.php b/system/controllers/pool.php index b3a076c..14ba3f0 100644 --- a/system/controllers/pool.php +++ b/system/controllers/pool.php @@ -1,56 +1,58 @@ assign('_title', $_L['Network'].' - '. $config['CompanyName']); +$ui->assign('_title', $_L['Network'] . ' - ' . $config['CompanyName']); $ui->assign('_system_menu', 'network'); $action = $routes['1']; $admin = Admin::_info(); $ui->assign('_admin', $admin); -if($admin['user_type'] != 'Admin'){ - r2(U."dashboard",'e',$_L['Do_Not_Access']); +if ($admin['user_type'] != 'Admin') { + r2(U . "dashboard", 'e', $_L['Do_Not_Access']); } use PEAR2\Net\RouterOS; + require_once 'system/autoload/PEAR2/Autoload.php'; switch ($action) { case 'list': - $ui->assign('xfooter', ''); + $ui->assign('xfooter', ''); - $name = _post('name'); - if ($name != ''){ - $paginator = Paginator::bootstrap('tbl_pool','pool_name','%'.$name.'%'); - $d = ORM::for_table('tbl_pool')->where_like('pool_name','%'.$name.'%')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); - }else{ - $paginator = Paginator::bootstrap('tbl_pool'); - $d = ORM::for_table('tbl_pool')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); - } + $name = _post('name'); + if ($name != '') { + $paginator = Paginator::bootstrap('tbl_pool', 'pool_name', '%' . $name . '%'); + $d = ORM::for_table('tbl_pool')->where_like('pool_name', '%' . $name . '%')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); + } else { + $paginator = Paginator::bootstrap('tbl_pool'); + $d = ORM::for_table('tbl_pool')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); + } - $ui->assign('d',$d); - $ui->assign('paginator',$paginator); + $ui->assign('d', $d); + $ui->assign('paginator', $paginator); run_hook('view_pool'); #HOOK $ui->display('pool.tpl'); break; case 'add': - $r = ORM::for_table('tbl_routers')->find_many(); - $ui->assign('r',$r); + $r = ORM::for_table('tbl_routers')->find_many(); + $ui->assign('r', $r); run_hook('view_add_pool'); #HOOK - $ui->display('pool-add.tpl'); + $ui->display('pool-add.tpl'); break; case 'edit': $id = $routes['2']; $d = ORM::for_table('tbl_pool')->find_one($id); - if($d){ - $ui->assign('d',$d); + if ($d) { + $ui->assign('d', $d); run_hook('view_edit_pool'); #HOOK $ui->display('pool-edit.tpl'); - }else{ + } else { r2(U . 'pool/list', 'e', $_L['Account_Not_Found']); } break; @@ -59,27 +61,12 @@ switch ($action) { $id = $routes['2']; run_hook('delete_pool'); #HOOK $d = ORM::for_table('tbl_pool')->find_one($id); - $mikrotik = Router::_info($d['routers']); - if($d){ - if(!$_c['radius_mode']){ - try { - $iport = explode(":",$mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'],($iport[1])?$iport[1]:null); - } catch (Exception $e) { - die("Unable to connect to the router.
".$e->getMessage()); - } - $printRequest = new RouterOS\Request( - '/ip pool print .proplist=name', - RouterOS\Query::where('name', $d['pool_name']) - ); - $poolName = $client->sendSync($printRequest)->getProperty('name'); - - $removeRequest = new RouterOS\Request('/ip/pool/remove'); - $client($removeRequest - ->setArgument('numbers', $poolName) - ); + $mikrotik = Mikrotik::info($d['routers']); + if ($d) { + if (!$_c['radius_mode']) { + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::removePool($client, $d['pool_name']); } - $d->delete(); r2(U . 'pool/list', 's', $_L['Delete_Successfully']); @@ -89,44 +76,35 @@ switch ($action) { case 'add-post': $name = _post('name'); $ip_address = _post('ip_address'); - $routers = _post('routers'); + $routers = _post('routers'); run_hook('add_pool'); #HOOK $msg = ''; - if(Validator::Length($name,30,2) == false){ - $msg .= 'Name should be between 3 to 30 characters'. '
'; + 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'] . '
'; } - if ($ip_address == '' OR $routers == ''){ - $msg .= $_L['All_field_is_required']. '
'; - } - $d = ORM::for_table('tbl_pool')->where('pool_name',$name)->find_one(); - if($d){ - $msg .= $_L['Pool_already_exist']. '
'; + $d = ORM::for_table('tbl_pool')->where('pool_name', $name)->find_one(); + if ($d) { + $msg .= $_L['Pool_already_exist'] . '
'; } - $mikrotik = Router::_info($routers); - if($msg == ''){ - if(!$_c['radius_mode']){ - try { - $iport = explode(":",$mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'],($iport[1])?$iport[1]:null); - } catch (Exception $e) { - die("Unable to connect to the router.
".$e->getMessage()); - } - $addRequest = new RouterOS\Request('/ip/pool/add'); - $client->sendSync($addRequest - ->setArgument('name', $name) - ->setArgument('ranges', $ip_address) - ); + $mikrotik = Mikrotik::info($routers); + if ($msg == '') { + if (!$_c['radius_mode']) { + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::removePool($client, $name, $ip_address); } $b = ORM::for_table('tbl_pool')->create(); $b->pool_name = $name; $b->range_ip = $ip_address; - $b->routers = $routers; + $b->routers = $routers; $b->save(); r2(U . 'pool/list', 's', $_L['Created_Successfully']); - }else{ + } else { r2(U . 'pool/add', 'e', $msg); } break; @@ -138,54 +116,38 @@ switch ($action) { $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 (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'] . '
'; } - if ($ip_address == '' OR $routers == ''){ - $msg .= $_L['All_field_is_required']. '
'; - } $id = _post('id'); $d = ORM::for_table('tbl_pool')->find_one($id); - if($d){ - - }else{ - $msg .= $_L['Data_Not_Found']. '
'; + if ($d) { + } else { + $msg .= $_L['Data_Not_Found'] . '
'; } - $mikrotik = Router::_info($routers); - if($msg == ''){ - if(!$_c['radius_mode']){ - try { - $iport = explode(":",$mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'],($iport[1])?$iport[1]:null); - } catch (Exception $e) { - die("Unable to connect to the router.
".$e->getMessage()); - } - $printRequest = new RouterOS\Request( - '/ip pool print .proplist=name', - RouterOS\Query::where('name', $name) - ); - $poolName = $client->sendSync($printRequest)->getProperty('name'); - - $setRequest = new RouterOS\Request('/ip/pool/set'); - $client($setRequest - ->setArgument('numbers', $poolName) - ->setArgument('ranges', $ip_address) - ); + $mikrotik = Mikrotik::info($routers); + if ($msg == '') { + if (!$_c['radius_mode']) { + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::setPool($client, $name,$poolName, $ip_address); } $d->pool_name = $name; $d->range_ip = $ip_address; - $d->routers = $routers; + $d->routers = $routers; $d->save(); r2(U . 'pool/list', 's', $_L['Updated_Successfully']); - }else{ - r2(U . 'pool/edit/'.$id, 'e', $msg); + } else { + r2(U . 'pool/edit/' . $id, 'e', $msg); } break; default: echo 'action not defined'; -} \ No newline at end of file +} diff --git a/system/controllers/prepaid.php b/system/controllers/prepaid.php index 46e2d14..846bb75 100644 --- a/system/controllers/prepaid.php +++ b/system/controllers/prepaid.php @@ -86,7 +86,7 @@ switch ($action) { $p = ORM::for_table('tbl_plans')->where('id', $plan)->where('enabled', '1')->find_one(); $b = ORM::for_table('tbl_user_recharges')->where('customer_id', $id_customer)->find_one(); - $mikrotik = Router::_info($server); + $mikrotik = Mikrotik::info($server); if($p['validity_unit']=='Months'){ $date_exp = date("Y-m-d", strtotime('+'.$p['validity'].' month')); }else if($p['validity_unit']=='Days'){ @@ -104,79 +104,9 @@ switch ($action) { if ($type == 'Hotspot') { if ($b) { if(!$_c['radius_mode']){ - try { - $iport = explode(":", $mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null); - } catch (Exception $e) { - die("Unable to connect to the router.
".$e->getMessage()); - } - - $printRequest = new RouterOS\Request( - '/ip hotspot user print .proplist=name', - RouterOS\Query::where('name', $c['username']) - ); - $userName = $client->sendSync($printRequest)->getProperty('name'); - $removeRequest = new RouterOS\Request('/ip/hotspot/user/remove'); - $client( - $removeRequest - ->setArgument('numbers', $userName) - ); - /* iBNuX Added: - * Time limit to Mikrotik - * 'Time_Limit', 'Data_Limit', 'Both_Limit' - */ - $addRequest = new RouterOS\Request('/ip/hotspot/user/add'); - if ($p['typebp'] == "Limited") { - if ($p['limit_type'] == "Time_Limit") { - if ($p['time_unit'] == 'Hrs') - $timelimit = $p['time_limit'] . ":00:00"; - else - $timelimit = "00:" . $p['time_limit'] . ":00"; - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-uptime', $timelimit) - ); - } else if ($p['limit_type'] == "Data_Limit") { - if ($p['data_unit'] == 'GB') - $datalimit = $p['data_limit'] . "000000000"; - else - $datalimit = $p['data_limit'] . "000000"; - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-bytes-total', $datalimit) - ); - } else if ($p['limit_type'] == "Both_Limit") { - if ($p['time_unit'] == 'Hrs') - $timelimit = $p['time_limit'] . ":00:00"; - else - $timelimit = "00:" . $p['time_limit'] . ":00"; - if ($p['data_unit'] == 'GB') - $datalimit = $p['data_limit'] . "000000000"; - else - $datalimit = $p['data_limit'] . "000000"; - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-uptime', $timelimit) - ->setArgument('limit-bytes-total', $datalimit) - ); - } - } else { - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ); - } + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::removeHotspotUser($client,$c['username']); + Mikrotik::addHotspotUser($client,$p,$c); } $b->customer_id = $id_customer; @@ -207,69 +137,8 @@ switch ($action) { $t->save(); } else { if(!$_c['radius_mode']){ - try { - $iport = explode(":", $mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null); - } catch (Exception $e) { - die("Unable to connect to the router.
".$e->getMessage()); - } - - /* iBNuX Added: - * Time limit to Mikrotik - * 'Time_Limit', 'Data_Limit', 'Both_Limit' - */ - $addRequest = new RouterOS\Request('/ip/hotspot/user/add'); - if ($p['typebp'] == "Limited") { - if ($p['limit_type'] == "Time_Limit") { - if ($p['time_unit'] == 'Hrs') - $timelimit = $p['time_limit'] . ":00:00"; - else - $timelimit = "00:" . $p['time_limit'] . ":00"; - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-uptime', $timelimit) - ); - } else if ($p['limit_type'] == "Data_Limit") { - if ($p['data_unit'] == 'GB') - $datalimit = $p['data_limit'] . "000000000"; - else - $datalimit = $p['data_limit'] . "000000"; - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-bytes-total', $datalimit) - ); - } else if ($p['limit_type'] == "Both_Limit") { - if ($p['time_unit'] == 'Hrs') - $timelimit = $p['time_limit'] . ":00:00"; - else - $timelimit = "00:" . $p['time_limit'] . ":00"; - if ($p['data_unit'] == 'GB') - $datalimit = $p['data_limit'] . "000000000"; - else - $datalimit = $p['data_limit'] . "000000"; - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-uptime', $timelimit) - ->setArgument('limit-bytes-total', $datalimit) - ); - } - } else { - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ); - } + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::addHotspotUser($client,$p,$c); } $d = ORM::for_table('tbl_user_recharges')->create(); @@ -307,32 +176,9 @@ switch ($action) { if ($b) { if(!$_c['radius_mode']){ - try { - $iport = explode(":", $mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null); - } catch (Exception $e) { - die("Unable to connect to the router.
".$e->getMessage()); - } - $printRequest = new RouterOS\Request( - '/ppp secret print .proplist=name', - RouterOS\Query::where('name', $c['username']) - ); - $userName = $client->sendSync($printRequest)->getProperty('name'); - - $removeRequest = new RouterOS\Request('/ppp/secret/remove'); - $client( - $removeRequest - ->setArgument('numbers', $userName) - ); - - $addRequest = new RouterOS\Request('/ppp/secret/add'); - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('service', 'pppoe') - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ); + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::removePpoeUser($client,$c['username']); + Mikrotik::addPpoeUser($client,$p,$c); } $b->customer_id = $id_customer; @@ -363,20 +209,8 @@ switch ($action) { $t->save(); } else { if(!$_c['radius_mode']){ - try { - $iport = explode(":", $mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null); - } catch (Exception $e) { - die("Unable to connect to the router.
".$e->getMessage()); - } - $addRequest = new RouterOS\Request('/ppp/secret/add'); - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('service', 'pppoe') - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ); + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::addPpoeUser($client,$p,$c); } $d = ORM::for_table('tbl_user_recharges')->create(); @@ -471,49 +305,20 @@ switch ($action) { $id = $routes['2']; $d = ORM::for_table('tbl_user_recharges')->find_one($id); - $mikrotik = Router::_info($d['routers']); + $mikrotik = Mikrotik::info($d['routers']); if ($d) { run_hook('delete_customer_active_plan'); #HOOK if ($d['type'] == 'Hotspot') { if(!$_c['radius_mode']){ - try { - $iport = explode(":", $mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null); - } catch (Exception $e) { - die("Unable to connect to the router.
".$e->getMessage()); - } - $printRequest = new RouterOS\Request( - '/ip hotspot user print .proplist=name', - RouterOS\Query::where('name', $d['username']) - ); - $userName = $client->sendSync($printRequest)->getProperty('name'); - $removeRequest = new RouterOS\Request('/ip/hotspot/user/remove'); - $client( - $removeRequest - ->setArgument('numbers', $userName) - ); + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::removeHotspotUser($client,$c['username']); } $d->delete(); } else { if(!$_c['radius_mode']){ - try { - $iport = explode(":", $mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null); - } catch (Exception $e) { - die("Unable to connect to the router.
".$e->getMessage()); - } - $printRequest = new RouterOS\Request( - '/ppp secret print .proplist=name', - RouterOS\Query::where('name', $d['username']) - ); - $userName = $client->sendSync($printRequest)->getProperty('name'); - - $removeRequest = new RouterOS\Request('/ppp/secret/remove'); - $client( - $removeRequest - ->setArgument('numbers', $userName) - ); + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::removePpoeUser($client,$c['username']); } $d->delete(); } @@ -736,7 +541,7 @@ switch ($action) { $date_only = date("Y-m-d"); $time = date("H:i:s"); - $mikrotik = Router::_info($v1['routers']); + $mikrotik = Mikrotik::info($v1['routers']); if($p['validity_unit']=='Months'){ $date_exp = date("Y-m-d", strtotime('+'.$p['validity'].' month')); @@ -756,78 +561,9 @@ switch ($action) { if ($v1['type'] == 'Hotspot') { if ($b) { if(!$_c['radius_mode']){ - try { - $iport = explode(":", $mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null); - } catch (Exception $e) { - die("Unable to connect to the router.
".$e->getMessage()); - } - $printRequest = new RouterOS\Request( - '/ip hotspot user print .proplist=name', - RouterOS\Query::where('name', $c['username']) - ); - $userName = $client->sendSync($printRequest)->getProperty('name'); - $removeRequest = new RouterOS\Request('/ip/hotspot/user/remove'); - $client( - $removeRequest - ->setArgument('numbers', $userName) - ); - /* iBNuX Added: - * Time limit to Mikrotik - * 'Time_Limit', 'Data_Limit', 'Both_Limit' - */ - $addRequest = new RouterOS\Request('/ip/hotspot/user/add'); - if ($p['typebp'] == "Limited") { - if ($p['limit_type'] == "Time_Limit") { - if ($p['time_unit'] == 'Hrs') - $timelimit = $p['time_limit'] . ":00:00"; - else - $timelimit = "00:" . $p['time_limit'] . ":00"; - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-uptime', $timelimit) - ); - } else if ($p['limit_type'] == "Data_Limit") { - if ($p['data_unit'] == 'GB') - $datalimit = $p['data_limit'] . "000000000"; - else - $datalimit = $p['data_limit'] . "000000"; - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-bytes-total', $datalimit) - ); - } else if ($p['limit_type'] == "Both_Limit") { - if ($p['time_unit'] == 'Hrs') - $timelimit = $p['time_limit'] . ":00:00"; - else - $timelimit = "00:" . $p['time_limit'] . ":00"; - if ($p['data_unit'] == 'GB') - $datalimit = $p['data_limit'] . "000000000"; - else - $datalimit = $p['data_limit'] . "000000"; - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-uptime', $timelimit) - ->setArgument('limit-bytes-total', $datalimit) - ); - } - } else { - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ); - } + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::removeHotspotUser($client,$c['username']); + Mikrotik::addHotspotUser($client,$p,$c); } $b->customer_id = $user; @@ -858,68 +594,8 @@ switch ($action) { $t->save(); } else { if(!$_c['radius_mode']){ - try { - $iport = explode(":", $mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null); - } catch (Exception $e) { - die("Unable to connect to the router.
".$e->getMessage()); - } - /* iBNuX Added: - * Time limit to Mikrotik - * 'Time_Limit', 'Data_Limit', 'Both_Limit' - */ - $addRequest = new RouterOS\Request('/ip/hotspot/user/add'); - if ($p['typebp'] == "Limited") { - if ($p['limit_type'] == "Time_Limit") { - if ($p['time_unit'] == 'Hrs') - $timelimit = $p['time_limit'] . ":00:00"; - else - $timelimit = "00:" . $p['time_limit'] . ":00"; - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-uptime', $timelimit) - ); - } else if ($p['limit_type'] == "Data_Limit") { - if ($p['data_unit'] == 'GB') - $datalimit = $p['data_limit'] . "000000000"; - else - $datalimit = $p['data_limit'] . "000000"; - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-bytes-total', $datalimit) - ); - } else if ($p['limit_type'] == "Both_Limit") { - if ($p['time_unit'] == 'Hrs') - $timelimit = $p['time_limit'] . ":00:00"; - else - $timelimit = "00:" . $p['time_limit'] . ":00"; - if ($p['data_unit'] == 'GB') - $datalimit = $p['data_limit'] . "000000000"; - else - $datalimit = $p['data_limit'] . "000000"; - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-uptime', $timelimit) - ->setArgument('limit-bytes-total', $datalimit) - ); - } - } else { - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ); - } + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::addHotspotUser($client,$p,$c); } $d = ORM::for_table('tbl_user_recharges')->create(); @@ -962,32 +638,9 @@ switch ($action) { } else { if ($b) { if(!$_c['radius_mode']){ - try { - $iport = explode(":", $mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null); - } catch (Exception $e) { - die("Unable to connect to the router.
".$e->getMessage()); - } - $printRequest = new RouterOS\Request( - '/ppp secret print .proplist=name', - RouterOS\Query::where('name', $c['username']) - ); - $userName = $client->sendSync($printRequest)->getProperty('name'); - - $removeRequest = new RouterOS\Request('/ppp/secret/remove'); - $client( - $removeRequest - ->setArgument('numbers', $userName) - ); - - $addRequest = new RouterOS\Request('/ppp/secret/add'); - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('service', 'pppoe') - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ); + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::removePpoeUser($client,$c['username']); + Mikrotik::addPpoeUser($client,$p,$c); } $b->customer_id = $user; @@ -1018,20 +671,8 @@ switch ($action) { $t->save(); } else { if(!$_c['radius_mode']){ - try { - $iport = explode(":", $mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null); - } catch (Exception $e) { - die("Unable to connect to the router.
".$e->getMessage()); - } - $addRequest = new RouterOS\Request('/ppp/secret/add'); - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('service', 'pppoe') - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ); + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::addPpoeUser($client,$p,$c); } $d = ORM::for_table('tbl_user_recharges')->create(); diff --git a/system/controllers/routers.php b/system/controllers/routers.php index 25ed4bf..88685fe 100644 --- a/system/controllers/routers.php +++ b/system/controllers/routers.php @@ -86,12 +86,7 @@ switch ($action) { } if(!$_c['radius_mode']){ - try { - $iport = explode(":", $ip_address); - $client = new RouterOS\Client($iport[0], $username, $password, ($iport[1]) ? $iport[1] : null); - } catch (Exception $e) { - $msg .= "Unable to connect to the router.
".$e->getMessage().'
'; - } + Mikrotik::getClient($ip_address,$username,$password); } if($msg == ''){ @@ -152,12 +147,7 @@ switch ($action) { if(!$_c['radius_mode']){ - try { - $iport = explode(":", $ip_address); - $client = new RouterOS\Client($iport[0], $username, $password, ($iport[1]) ? $iport[1] : null); - } catch (Exception $e) { - $msg .= "Unable to connect to the router.
".$e->getMessage().'
'; - } + Mikrotik::getClient($ip_address,$username,$password); } diff --git a/system/controllers/services.php b/system/controllers/services.php index 4c84116..51b4f8a 100644 --- a/system/controllers/services.php +++ b/system/controllers/services.php @@ -71,24 +71,9 @@ switch ($action) { if ($d) { run_hook('delete_plan'); #HOOK if(!$_c['radius_mode']){ - $mikrotik = Router::_info($d['routers']); - try { - $iport = explode(":", $mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null); - } catch (Exception $e) { - die("Unable to connect to the router.
".$e->getMessage()); - } - $printRequest = new RouterOS\Request( - '/ip hotspot user profile print .proplist=name', - RouterOS\Query::where('name', $d['name_plan']) - ); - $profileName = $client->sendSync($printRequest)->getProperty('name'); - - $removeRequest = new RouterOS\Request('/ip/hotspot/user/profile/remove'); - $client( - $removeRequest - ->setArgument('numbers', $profileName) - ); + $mikrotik = Mikrotik::info($d['routers']); + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::removeHotspotPlan($client,$d['name_plan']); } $d->delete(); @@ -146,20 +131,9 @@ switch ($action) { $rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown; if(!$_c['radius_mode']){ - $mikrotik = Router::_info($routers); - try { - $iport = explode(":", $mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null); - } catch (Exception $e) { - die("Unable to connect to the router.
".$e->getMessage()); - } - $addRequest = new RouterOS\Request('/ip/hotspot/user/profile/add'); - $client->sendSync( - $addRequest - ->setArgument('name', $name) - ->setArgument('shared-users', $sharedusers) - ->setArgument('rate-limit', $rate) - ); + $mikrotik = Mikrotik::info($routers); + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::addHotspotPlan($client, $name, $sharedusers, $rate); } $d = ORM::for_table('tbl_plans')->create(); @@ -236,26 +210,9 @@ switch ($action) { $rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown; if(!$_c['radius_mode']){ - $mikrotik = Router::_info($routers); - try { - $iport = explode(":", $mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null); - } catch (Exception $e) { - die("Unable to connect to the router.
".$e->getMessage()); - } - $printRequest = new RouterOS\Request( - '/ip hotspot user profile print .proplist=name', - RouterOS\Query::where('name', $name) - ); - $profileName = $client->sendSync($printRequest)->getProperty('name'); - - $setRequest = new RouterOS\Request('/ip/hotspot/user/profile/set'); - $client( - $setRequest - ->setArgument('numbers', $profileName) - ->setArgument('shared-users', $sharedusers) - ->setArgument('rate-limit', $rate) - ); + $mikrotik = Mikrotik::info($routers); + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::setHotspotPlan($client, $name, $sharedusers, $rate); } $d->name_plan = $name; @@ -334,24 +291,9 @@ switch ($action) { if ($d) { run_hook('delete_ppoe'); #HOOK if(!$_c['radius_mode']){ - $mikrotik = Router::_info($d['routers']); - try { - $iport = explode(":", $mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null); - } catch (Exception $e) { - die("Unable to connect to the router.
".$e->getMessage()); - } - $printRequest = new RouterOS\Request( - '/ppp profile print .proplist=name', - RouterOS\Query::where('name', $d['name_plan']) - ); - $profileName = $client->sendSync($printRequest)->getProperty('name'); - - $removeRequest = new RouterOS\Request('/ppp/profile/remove'); - $client( - $removeRequest - ->setArgument('numbers', $profileName) - ); + $mikrotik = Mikrotik::info($d['routers']); + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::removePpoePlan($client, $d['name_plan']); } $d->delete(); @@ -400,21 +342,9 @@ switch ($action) { $rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown; if(!$_c['radius_mode']){ - $mikrotik = Router::_info($routers); - try { - $iport = explode(":", $mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null); - } catch (Exception $e) { - die("Unable to connect to the router.
".$e->getMessage()); - } - $addRequest = new RouterOS\Request('/ppp/profile/add'); - $client->sendSync( - $addRequest - ->setArgument('name', $name) - ->setArgument('local-address', $pool) - ->setArgument('remote-address', $pool) - ->setArgument('rate-limit', $rate) - ); + $mikrotik = Mikrotik::info($routers); + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::addPpoePlan($client, $name, $pool, $rate); } $d = ORM::for_table('tbl_plans')->create(); @@ -478,27 +408,9 @@ switch ($action) { $rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown; if(!$_c['radius_mode']){ - $mikrotik = Router::_info($routers); - try { - $iport = explode(":", $mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null); - } catch (Exception $e) { - die("Unable to connect to the router.
".$e->getMessage()); - } - $printRequest = new RouterOS\Request( - '/ppp profile print .proplist=name', - 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) - ); + $mikrotik = Mikrotik::info($routers); + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::setPpoePlan($client, $name, $pool, $rate); } $d->name_plan = $name; diff --git a/system/controllers/voucher.php b/system/controllers/voucher.php index ccc3220..9cef885 100644 --- a/system/controllers/voucher.php +++ b/system/controllers/voucher.php @@ -35,17 +35,17 @@ switch ($action) { $date_only = date("Y-m-d"); $time = date("H:i:s"); - $mikrotik = Router::_info($v1['routers']); - if($p['validity_unit']=='Months'){ - $date_exp = date("Y-m-d", strtotime('+'.$p['validity'].' month')); - }else if($p['validity_unit']=='Days'){ - $date_exp = date("Y-m-d", strtotime('+'.$p['validity'].' day')); - }else if($p['validity_unit']=='Hrs'){ - $datetime = explode(' ',date("Y-m-d H:i:s", strtotime('+'.$p['validity'].' hour'))); + $mikrotik = Mikrotik::info($v1['routers']); + if ($p['validity_unit'] == 'Months') { + $date_exp = date("Y-m-d", strtotime('+' . $p['validity'] . ' month')); + } else if ($p['validity_unit'] == 'Days') { + $date_exp = date("Y-m-d", strtotime('+' . $p['validity'] . ' day')); + } else if ($p['validity_unit'] == 'Hrs') { + $datetime = explode(' ', date("Y-m-d H:i:s", strtotime('+' . $p['validity'] . ' hour'))); $date_exp = $datetime[0]; $time = $datetime[1]; - }else if($p['validity_unit']=='Mins'){ - $datetime = explode(' ',date("Y-m-d H:i:s", strtotime('+'.$p['validity'].' minute'))); + } else if ($p['validity_unit'] == 'Mins') { + $datetime = explode(' ', date("Y-m-d H:i:s", strtotime('+' . $p['validity'] . ' minute'))); $date_exp = $datetime[0]; $time = $datetime[1]; } @@ -53,78 +53,10 @@ switch ($action) { if ($v1) { if ($v1['type'] == 'Hotspot') { if ($b) { - if(!$_c['radius_mode']){ - try { - $iport = explode(":", $mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null); - } catch (Exception $e) { - die("Unable to connect to the router.
".$e->getMessage()); - } - $printRequest = new RouterOS\Request('/ip/hotspot/user/print'); - $printRequest->setArgument('.proplist', '.id'); - $printRequest->setQuery(RouterOS\Query::where('name', $c['username'])); - $id = $client->sendSync($printRequest)->getProperty('.id'); - - $setRequest = new RouterOS\Request('/ip/hotspot/user/remove'); - $setRequest->setArgument('numbers', $id); - $client->sendSync($setRequest); - - /* iBNuX Added: - * Time limit to Mikrotik - * 'Time_Limit', 'Data_Limit', 'Both_Limit' - */ - $addRequest = new RouterOS\Request('/ip/hotspot/user/add'); - if ($p['typebp'] == "Limited") { - if ($p['limit_type'] == "Time_Limit") { - if ($p['time_unit'] == 'Hrs') - $timelimit = $p['time_limit'] . ":00:00"; - else - $timelimit = "00:" . $p['time_limit'] . ":00"; - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-uptime', $timelimit) - ); - } else if ($p['limit_type'] == "Data_Limit") { - if ($p['data_unit'] == 'GB') - $datalimit = $p['data_limit'] . "000000000"; - else - $datalimit = $p['data_limit'] . "000000"; - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-bytes-total', $datalimit) - ); - } else if ($p['limit_type'] == "Both_Limit") { - if ($p['time_unit'] == 'Hrs') - $timelimit = $p['time_limit'] . ":00:00"; - else - $timelimit = "00:" . $p['time_limit'] . ":00"; - if ($p['data_unit'] == 'GB') - $datalimit = $p['data_limit'] . "000000000"; - else - $datalimit = $p['data_limit'] . "000000"; - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-uptime', $timelimit) - ->setArgument('limit-bytes-total', $datalimit) - ); - } - } else { - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ); - } + if (!$_c['radius_mode']) { + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::removeHotspotUser($client, $c['username']); + Mikrotik::addHotspotUser($client, $p, $c); } $b->customer_id = $user['id']; $b->username = $c['username']; @@ -153,69 +85,9 @@ switch ($action) { $t->type = "Hotspot"; $t->save(); } else { - if(!$_c['radius_mode']){ - try { - $iport = explode(":", $mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null); - } catch (Exception $e) { - die("Unable to connect to the router.
".$e->getMessage()); - } - /* iBNuX Added: - * Time limit to Mikrotik - * 'Time_Limit', 'Data_Limit', 'Both_Limit' - */ - $addRequest = new RouterOS\Request('/ip/hotspot/user/add'); - if ($p['typebp'] == "Limited") { - if ($p['limit_type'] == "Time_Limit") { - if ($p['time_unit'] == 'Hrs') - $timelimit = $p['time_limit'] . ":00:00"; - else - $timelimit = "00:" . $p['time_limit'] . ":00"; - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-uptime', $timelimit) - ); - } else if ($p['limit_type'] == "Data_Limit") { - if ($p['data_unit'] == 'GB') - $datalimit = $p['data_limit'] . "000000000"; - else - $datalimit = $p['data_limit'] . "000000"; - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-bytes-total', $datalimit) - ); - } else if ($p['limit_type'] == "Both_Limit") { - if ($p['time_unit'] == 'Hrs') - $timelimit = $p['time_limit'] . ":00:00"; - else - $timelimit = "00:" . $p['time_limit'] . ":00"; - if ($p['data_unit'] == 'GB') - $datalimit = $p['data_limit'] . "000000000"; - else - $datalimit = $p['data_limit'] . "000000"; - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-uptime', $timelimit) - ->setArgument('limit-bytes-total', $datalimit) - ); - } - } else { - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ); - } + if (!$_c['radius_mode']) { + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::addHotspotUser($client, $p, $c); } $d = ORM::for_table('tbl_user_recharges')->create(); @@ -251,36 +123,16 @@ switch ($action) { $v1->user = $c['username']; $v1->save(); // Telegram to Admin - sendTelegram( '#u'.$c['username']." Activate #Voucher #Hotspot\n".$p['name_plan']. - "\nCode: ".$code. - "\nRouter: ".$v1['routers']. - "\nPrice: ".$p['price']); + sendTelegram('#u' . $c['username'] . " Activate #Voucher #Hotspot\n" . $p['name_plan'] . + "\nCode: " . $code . + "\nRouter: " . $v1['routers'] . + "\nPrice: " . $p['price']); } else { if ($b) { - if(!$_c['radius_mode']){ - try { - $iport = explode(":", $mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null); - } catch (Exception $e) { - die("Unable to connect to the router.
".$e->getMessage()); - } - $printRequest = new RouterOS\Request('/ppp/secret/print'); - $printRequest->setArgument('.proplist', '.id'); - $printRequest->setQuery(RouterOS\Query::where('name', $c['username'])); - $id = $client->sendSync($printRequest)->getProperty('.id'); - - $setRequest = new RouterOS\Request('/ppp/secret/remove'); - $setRequest->setArgument('numbers', $id); - $client->sendSync($setRequest); - - $addRequest = new RouterOS\Request('/ppp/secret/add'); - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('service', 'pppoe') - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ); + if (!$_c['radius_mode']) { + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::removePpoeUser($client, $c['username']); + Mikrotik::addPpoeUser($client, $p, $c); } $b->customer_id = $user['id']; @@ -310,21 +162,9 @@ switch ($action) { $t->type = "PPPOE"; $t->save(); } else { - if(!$_c['radius_mode']){ - try { - $iport = explode(":", $mikrotik['ip_address']); - $client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null); - } catch (Exception $e) { - die("Unable to connect to the router.
".$e->getMessage()); - } - $addRequest = new RouterOS\Request('/ppp/secret/add'); - $client->sendSync( - $addRequest - ->setArgument('name', $c['username']) - ->setArgument('service', 'pppoe') - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ); + if (!$_c['radius_mode']) { + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::addPpoeUser($client, $p, $c); } $d = ORM::for_table('tbl_user_recharges')->create(); @@ -360,10 +200,10 @@ switch ($action) { $v1->user = $c['username']; $v1->save(); // Telegram to Admin - sendTelegram( '#u'.$c['username']." Activate #Voucher #PPPOE\n".$p['name_plan']. - "\nCode: ".$code. - "\nRouter: ".$v1['routers']. - "\nPrice: ".$p['price']); + sendTelegram('#u' . $c['username'] . " Activate #Voucher #PPPOE\n" . $p['name_plan'] . + "\nCode: " . $code . + "\nRouter: " . $v1['routers'] . + "\nPrice: " . $p['price']); } r2(U . "voucher/list-activated", 's', $_L['Activation_Vouchers_Successfully']); diff --git a/system/cron.php b/system/cron.php index 65962de..8f3c685 100644 --- a/system/cron.php +++ b/system/cron.php @@ -35,32 +35,9 @@ foreach ($d as $ds){ $m = ORM::for_table('tbl_routers')->where('name',$ds['routers'])->find_one(); if(!$_c['radius_mode']){ - try { - $iport = explode(":",$m['ip_address']); - $client = new RouterOS\Client($iport[0], $m['username'], $m['password'],($iport[1])?$iport[1]:null); - } catch (Exception $e) { - die("Unable to connect to the router.
".$e->getMessage()); - } - - $printRequest = new RouterOS\Request('/ip/hotspot/user/print'); - $printRequest->setArgument('.proplist', '.id'); - $printRequest->setQuery(RouterOS\Query::where('name', $c['username'])); - $id = $client->sendSync($printRequest)->getProperty('.id'); - - $setRequest = new RouterOS\Request('/ip/hotspot/user/set'); - $setRequest->setArgument('numbers', $id); - $setRequest->setArgument('limit-uptime', '00:00:05'); - $client->sendSync($setRequest); - - //remove hotspot active - $onlineRequest = new RouterOS\Request('/ip/hotspot/active/print'); - $onlineRequest->setArgument('.proplist', '.id'); - $onlineRequest->setQuery(RouterOS\Query::where('user', $c['username'])); - $id = $client->sendSync($onlineRequest)->getProperty('.id'); - - $removeRequest = new RouterOS\Request('/ip/hotspot/active/remove'); - $removeRequest->setArgument('numbers', $id); - $client->sendSync($removeRequest); + $client = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']); + Mikrotik::setHotspotLimitUptime($client,$c['username']); + Mikrotik::removeHotspotActiveUser($client,$c['username']); } //update database user dengan status off @@ -78,30 +55,9 @@ foreach ($d as $ds){ $m = ORM::for_table('tbl_routers')->where('name',$ds['routers'])->find_one(); if(!$_c['radius_mode']){ - try { - $iport = explode(":",$m['ip_address']); - $client = new RouterOS\Client($iport[0], $m['username'], $m['password'],($iport[1])?$iport[1]:null); - } catch (Exception $e) { - die("Unable to connect to the router.
".$e->getMessage()); - } - $printRequest = new RouterOS\Request('/ppp/secret/print'); - $printRequest->setArgument('.proplist', '.id'); - $printRequest->setQuery(RouterOS\Query::where('name', $c['username'])); - $id = $client->sendSync($printRequest)->getProperty('.id'); - - $setRequest = new RouterOS\Request('/ppp/secret/disable'); - $setRequest->setArgument('numbers', $id); - $client->sendSync($setRequest); - - //remove hotspot active - $onlineRequest = new RouterOS\Request('/ppp/active/print'); - $onlineRequest->setArgument('.proplist', '.id'); - $onlineRequest->setQuery(RouterOS\Query::where('name', $c['username'])); - $id = $client->sendSync($onlineRequest)->getProperty('.id'); - - $removeRequest = new RouterOS\Request('/ppp/active/remove'); - $removeRequest->setArgument('numbers', $id); - $client->sendSync($removeRequest); + $client = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']); + Mikrotik::disablePpoeUser($client,$c['username']); + Mikrotik::removePpoeActive($client,$c['username']); } $u->status = 'off';