Fix Customer self Deactivate Radius

This commit is contained in:
Ibnu Maksum 2023-10-17 16:32:18 +07:00
parent 0c0d7a963e
commit a5a5969642
No known key found for this signature in database
GPG key ID: 7FC82848810579E5
3 changed files with 25 additions and 14 deletions

View file

@ -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;
}

View file

@ -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');

View file

@ -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'] . '<br>';
}
$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'] . '<br>';
}
$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);
}