From a5a59696420d462bf5085b980c630507b322164d Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Tue, 17 Oct 2023 16:32:18 +0700 Subject: [PATCH] Fix Customer self Deactivate Radius --- system/autoload/Radius.php | 8 +++++--- system/controllers/home.php | 25 +++++++++++++++++-------- system/controllers/pool.php | 6 +++--- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/system/autoload/Radius.php b/system/autoload/Radius.php index 26b0a9d..2ce4421 100644 --- a/system/autoload/Radius.php +++ b/system/autoload/Radius.php @@ -132,7 +132,7 @@ class Radius } } - public static function customerDeactivate($username) + public static function customerDeactivate($username, $radiusDisconnect = true) { { global $radius_pass; $r = Radius::getTableCustomer()->where_equal('username', $username)->whereEqual('attribute', 'Cleartext-Password')->findOne(); @@ -141,7 +141,9 @@ class Radius // we just change the password $r->value = md5(time() . $username . $radius_pass); $r->save(); - return Radius::disconnectCustomer($username); + if($radiusDisconnect) + return Radius::disconnectCustomer($username); + } } return ''; } @@ -307,7 +309,7 @@ class Radius if (!empty($n['ports'])) { $port = $n['ports']; } - $result[] = $n['nasname'] . ': ' . shell_exec("echo 'User-Name = $username' | " . Radius::getClient() . " " . trim($n['nasname']) . ":$port disconnect '" . $n['secret'] . "'"); + $result[] = $n['nasname'] . ': ' . @shell_exec("echo 'User-Name = $username' | " . Radius::getClient() . " " . trim($n['nasname']) . ":$port disconnect '" . $n['secret'] . "'"); } return $result; } diff --git a/system/controllers/home.php b/system/controllers/home.php index 2533ed6..cbe92eb 100644 --- a/system/controllers/home.php +++ b/system/controllers/home.php @@ -106,14 +106,23 @@ if(isset($_GET['recharge']) && $_GET['recharge'] == 1){ } }else if(isset($_GET['deactivate']) && $_GET['deactivate'] == 1){ if ($bill) { - $mikrotik = Mikrotik::info($bill['routers']); - $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); - if ($bill['type'] == 'Hotspot') { - Mikrotik::removeHotspotUser($client, $bill['username']); - Mikrotik::removeHotspotActiveUser($client, $bill['username']); - } else if ($bill['type'] == 'PPPOE') { - Mikrotik::removePpoeUser($client, $bill['username']); - Mikrotik::removePpoeActive($client, $bill['username']); + $p = ORM::for_table('tbl_plans')->where('id', $bill['plan_id'])->find_one(); + if($p['is_radius']){ + Radius::customerDeactivate($user['username']); + }else{ + try{ + $mikrotik = Mikrotik::info($bill['routers']); + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + if ($bill['type'] == 'Hotspot') { + Mikrotik::removeHotspotUser($client, $bill['username']); + Mikrotik::removeHotspotActiveUser($client, $bill['username']); + } else if ($bill['type'] == 'PPPOE') { + Mikrotik::removePpoeUser($client, $bill['username']); + Mikrotik::removePpoeActive($client, $bill['username']); + } + }catch(Exception $e){ + //ignore it maybe mikrotik has been deleted + } } $bill->status = 'off'; $bill->expiration = date('Y-m-d'); diff --git a/system/controllers/pool.php b/system/controllers/pool.php index 5ac5a25..a75db50 100644 --- a/system/controllers/pool.php +++ b/system/controllers/pool.php @@ -60,10 +60,10 @@ switch ($action) { $id = $routes['2']; run_hook('delete_pool'); #HOOK $d = ORM::for_table('tbl_pool')->find_one($id); - $mikrotik = Mikrotik::info($d['routers']); if ($d) { if ($d['routers'] != 'radius') { try{ + $mikrotik = Mikrotik::info($d['routers']); $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::removePool($client, $d['pool_name']); }catch(Exception $e){ @@ -106,9 +106,9 @@ switch ($action) { if ($d) { $msg .= $_L['Pool_already_exist'] . '
'; } - $mikrotik = Mikrotik::info($routers); if ($msg == '') { if ($routers != 'radius') { + $mikrotik = Mikrotik::info($routers); $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::addPool($client, $name, $ip_address); } @@ -143,9 +143,9 @@ switch ($action) { $msg .= $_L['Data_Not_Found'] . '
'; } - $mikrotik = Mikrotik::info($routers); if ($msg == '') { if ($routers != 'radius') { + $mikrotik = Mikrotik::info($routers); $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::setPool($client, $d['pool_name'], $ip_address); }