diff --git a/system/autoload/Mikrotik.php b/system/autoload/Mikrotik.php index fbc32af..99ffc0c 100644 --- a/system/autoload/Mikrotik.php +++ b/system/autoload/Mikrotik.php @@ -210,7 +210,7 @@ class Mikrotik } } - public static function setHotspotUser($client, $user, $pass, $nuser = null) + public static function setHotspotUser($client, $user, $pass) { $printRequest = new RouterOS\Request('/ip/hotspot/user/print'); $printRequest->setArgument('.proplist', '.id'); @@ -223,6 +223,19 @@ class Mikrotik $client->sendSync($setRequest); } + public static function setHotspotUserPackage($client, $user, $plan) + { + $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('profile', $plan); + $client->sendSync($setRequest); + } + public static function removeHotspotActiveUser($client, $username) { $onlineRequest = new RouterOS\Request('/ip/hotspot/active/print'); @@ -235,19 +248,6 @@ class Mikrotik $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) { @@ -281,7 +281,7 @@ class Mikrotik ); } - public static function setPpoeUser($client, $user, $pass, $nuser = null) + public static function setPpoeUser($client, $user, $pass) { $printRequest = new RouterOS\Request('/ppp/secret/print'); $printRequest->setArgument('.proplist', '.id'); @@ -294,15 +294,16 @@ class Mikrotik $client->sendSync($setRequest); } - public static function disablePpoeUser($client, $username) + public static function setPpoeUserPlan($client, $user, $plan) { $printRequest = new RouterOS\Request('/ppp/secret/print'); $printRequest->setArgument('.proplist', '.id'); - $printRequest->setQuery(RouterOS\Query::where('name', $username)); + $printRequest->setQuery(RouterOS\Query::where('name', $user)); $id = $client->sendSync($printRequest)->getProperty('.id'); - $setRequest = new RouterOS\Request('/ppp/secret/disable'); + $setRequest = new RouterOS\Request('/ppp/secret/set'); $setRequest->setArgument('numbers', $id); + $setRequest->setArgument('profile', $plan); $client->sendSync($setRequest); } diff --git a/system/cron.php b/system/cron.php index ddd060c..d573c7e 100644 --- a/system/cron.php +++ b/system/cron.php @@ -79,12 +79,16 @@ foreach ($d as $ds) { $u = ORM::for_table('tbl_user_recharges')->where('id', $ds['id'])->find_one(); $c = ORM::for_table('tbl_customers')->where('id', $ds['customer_id'])->find_one(); $m = ORM::for_table('tbl_routers')->where('name', $ds['routers'])->find_one(); + $p = ORM::for_table('tbl_plans')->where('id', $u['plan_id'])->find_one(); if (!$_c['radius_mode']) { $client = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']); - Mikrotik::setHotspotLimitUptime($client, $c['username']); - Mikrotik::removeHotspotActiveUser($client, $c['username']); - Mikrotik::removeHotspotUser($client, $c['username']); + if(!empty($p['pool_expired'])){ + Mikrotik::setHotspotUserPackage($client, $c['username'], 'EXPIRED NUXBILL '.$p['pool_expired']); + }else{ + Mikrotik::removeHotspotActiveUser($client, $c['username']); + Mikrotik::removeHotspotUser($client, $c['username']); + } Message::sendPackageNotification($c['phonenumber'], $c['fullname'], $u['namebp'], $textExpired, $config['user_notification_expired']); } //update database user dengan status off @@ -93,7 +97,6 @@ foreach ($d as $ds) { // autorenewal from deposit if ($config['enable_balance'] == 'yes' && $c['auto_renewal']) { - $p = ORM::for_table('tbl_plans')->where('id', $u['plan_id'])->find_one(); if ($p && $p['enabled'] && $c['balance'] >= $p['price']) { if (Package::rechargeUser($ds['customer_id'], $p['routers'], $p['id'], 'Customer', 'Balance')) { // if success, then get the balance @@ -123,12 +126,16 @@ foreach ($d as $ds) { $u = ORM::for_table('tbl_user_recharges')->where('id', $ds['id'])->find_one(); $c = ORM::for_table('tbl_customers')->where('id', $ds['customer_id'])->find_one(); $m = ORM::for_table('tbl_routers')->where('name', $ds['routers'])->find_one(); + $p = ORM::for_table('tbl_plans')->where('id', $u['plan_id'])->find_one(); if (!$_c['radius_mode']) { $client = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']); - Mikrotik::disablePpoeUser($client, $c['username']); - Mikrotik::removePpoeActive($client, $c['username']); - Mikrotik::removePpoeUser($client, $c['username']); + if(!empty($p['pool_expired'])){ + Mikrotik::setPpoeUserPlan($client, $c['username'], 'EXPIRED NUXBILL '.$p['pool_expired']); + }else{ + Mikrotik::removePpoeActive($client, $c['username']); + Mikrotik::removePpoeUser($client, $c['username']); + } Message::sendPackageNotification($c['phonenumber'], $c['fullname'], $u['namebp'], $textExpired, $config['user_notification_expired']); } @@ -137,7 +144,6 @@ foreach ($d as $ds) { // autorenewal from deposit if ($config['enable_balance'] == 'yes' && $c['auto_renewal']) { - $p = ORM::for_table('tbl_plans')->where('id', $u['plan_id'])->find_one(); if ($p && $p['enabled'] && $c['balance'] >= $p['price']) { if (Package::rechargeUser($ds['customer_id'], $p['routers'], $p['id'], 'Customer', 'Balance')) { // if success, then get the balance