From 0bb20d4a160a65c3d23fc72b78a646d72d038465 Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Wed, 4 Oct 2023 16:25:21 +0700 Subject: [PATCH] Radius name reserved --- system/controllers/accounts.php | 56 ++++++++++++--------------------- system/controllers/pool.php | 4 +-- system/controllers/routers.php | 12 ++++--- 3 files changed, 30 insertions(+), 42 deletions(-) diff --git a/system/controllers/accounts.php b/system/controllers/accounts.php index c70e9837..a7d431f0 100644 --- a/system/controllers/accounts.php +++ b/system/controllers/accounts.php @@ -42,47 +42,31 @@ switch ($action) { $c = ORM::for_table('tbl_user_recharges')->where('username', $user['username'])->find_one(); if ($c) { - $mikrotik = Mikrotik::info($c['routers']); - if ($c['type'] == 'Hotspot') { - if (!$config['radius_enable']) { - $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); - Mikrotik::setHotspotUser($client, $c['username'], $npass); - Mikrotik::removeHotspotActiveUser($client, $user['username']); + $p = ORM::for_table('tbl_plans')->where('id', $c['plan_id'])->find_one(); + if($p['is_radius']){ + if($c['type'] == 'Hotspot' || ($c['type'] == 'PPPOE' && empty($d['pppoe_password']))){ + Radius::customerAdd($d, $p); } - $d->password = $npass; - $d->save(); - - _msglog('s', $_L['Password_Changed_Successfully']); - _log('[' . $user['username'] . ']: Password changed successfully', 'User', $user['id']); - - r2(U . 'login'); - } else { - if (!$config['radius_enable']) { - $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); - if(!empty($d['pppoe_password'])){ - Mikrotik::setPpoeUser($client, $c['username'], $d['pppoe_password']); - }else{ - Mikrotik::setPpoeUser($client, $c['username'], $npass); - } + }else{ + $mikrotik = Mikrotik::info($c['routers']); + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + if ($c['type'] == 'Hotspot') { + Mikrotik::setHotspotUser($client, $c['username'], $npass); + Mikrotik::removeHotspotActiveUser($client, $user['username']); + } else if(empty($d['pppoe_password'])){ + // only change when pppoe_password empty + Mikrotik::setPpoeUser($client, $c['username'], $npass); Mikrotik::removePpoeActive($client, $user['username']); } - $d->password = $npass; - $d->save(); - - _msglog('s', $_L['Password_Changed_Successfully']); - _log('[' . $user['username'] . ']: Password changed successfully', 'User', $user['id']); - - r2(U . 'login'); } - } else { - $d->password = $npass; - $d->save(); - - _msglog('s', $_L['Password_Changed_Successfully']); - _log('[' . $user['username'] . ']: Password changed successfully', 'User', $user['id']); - - r2(U . 'login'); } + $d->password = $npass; + $d->save(); + + _msglog('s', $_L['Password_Changed_Successfully']); + _log('[' . $user['username'] . ']: Password changed successfully', 'User', $user['id']); + + r2(U . 'login'); } else { r2(U . 'accounts/change-password', 'e', $_L['Incorrect_Current_Password']); } diff --git a/system/controllers/pool.php b/system/controllers/pool.php index fb1544b7..f0eb6a4b 100644 --- a/system/controllers/pool.php +++ b/system/controllers/pool.php @@ -60,7 +60,7 @@ switch ($action) { $d = ORM::for_table('tbl_pool')->find_one($id); $mikrotik = Mikrotik::info($d['routers']); if ($d) { - if (!$config['radius_enable']) { + if ($d['routers']!='radius') { $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::removePool($client, $d['pool_name']); } @@ -100,7 +100,7 @@ switch ($action) { } $mikrotik = Mikrotik::info($routers); if ($msg == '') { - if (!$config['radius_enable'] && $routers != 'radius') { + if ($routers != 'radius') { $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::addPool($client, $name, $ip_address); } diff --git a/system/controllers/routers.php b/system/controllers/routers.php index b59337ae..e4e39bde 100644 --- a/system/controllers/routers.php +++ b/system/controllers/routers.php @@ -88,10 +88,12 @@ switch ($action) { if ($d) { $msg .= $_L['Router_already_exist'] . '
'; } - - Mikrotik::getClient($ip_address, $username, $password); + if (strtolower($name) == 'radius') { + $msg .= 'Radius name is reserved
'; + } if ($msg == '') { + Mikrotik::getClient($ip_address, $username, $password); run_hook('add_router'); #HOOK $d = ORM::for_table('tbl_routers')->create(); $d->name = $name; @@ -146,11 +148,13 @@ switch ($action) { } } - - Mikrotik::getClient($ip_address, $username, $password); + if (strtolower($name) == 'radius') { + $msg .= 'Radius name is reserved
'; + } if ($msg == '') { + Mikrotik::getClient($ip_address, $username, $password); run_hook('router_edit'); #HOOK $d->name = $name; $d->ip_address = $ip_address;