From ef256332755ff981ec4619007eaedc7a16d46d9c Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Tue, 24 Oct 2023 13:55:34 +0700 Subject: [PATCH] Assign router to NAS --- install/radius.sql | 3 ++- system/autoload/Radius.php | 28 +++++++++++++++------------- system/controllers/radius.php | 8 ++++++-- system/updates.json | 3 +++ ui/ui/radius-nas-add.tpl | 12 ++++++++++++ ui/ui/radius-nas-edit.tpl | 13 +++++++++++++ ui/ui/radius-nas.tpl | 2 ++ 7 files changed, 53 insertions(+), 16 deletions(-) diff --git a/install/radius.sql b/install/radius.sql index b556bbcb..fbe9879d 100644 --- a/install/radius.sql +++ b/install/radius.sql @@ -9,7 +9,8 @@ CREATE TABLE `nas` ( `secret` varchar(60) COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'secret', `server` varchar(64) COLLATE utf8mb4_general_ci DEFAULT NULL, `community` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL, - `description` varchar(200) COLLATE utf8mb4_general_ci DEFAULT 'RADIUS Client' + `description` varchar(200) COLLATE utf8mb4_general_ci DEFAULT 'RADIUS Client', + `routers` varchar(32) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; DROP TABLE IF EXISTS `radacct`; diff --git a/system/autoload/Radius.php b/system/autoload/Radius.php index a7a64a23..ad64a5f8 100644 --- a/system/autoload/Radius.php +++ b/system/autoload/Radius.php @@ -43,7 +43,7 @@ class Radius return ORM::for_table('radusergroup', 'radius'); } - public static function nasAdd($name, $ip, $ports, $secret, $description = "", $type = 'other', $server = null, $community = null) + public static function nasAdd($name, $ip, $ports, $secret, $routers = "", $description = "", $type = 'other', $server = null, $community = null) { $n = Radius::getTableNas()->create(); $n->nasname = $ip; @@ -54,11 +54,12 @@ class Radius $n->description = $description; $n->server = $server; $n->community = $community; + $n->routers = $routers; $n->save(); return $n->id(); } - public static function nasUpdate($id, $name, $ip, $ports, $secret, $description = "", $type = 'other', $server = null, $community = null) + public static function nasUpdate($id, $name, $ip, $ports, $secret, $routers = "", $description = "", $type = 'other', $server = null, $community = null) { $n = Radius::getTableNas()->find_one($id); if (empty($n)) { @@ -72,6 +73,7 @@ class Radius $n->description = $description; $n->server = $server; $n->community = $community; + $n->routers = $routers; return $n->save(); } @@ -119,17 +121,17 @@ class Radius } } - public static function customerDeactivate($username, $radiusDisconnect = true) { - { - global $radius_pass; - $r = Radius::getTableCustomer()->where_equal('username', $username)->whereEqual('attribute', 'Cleartext-Password')->findOne(); - if ($r) { - // no need to delete, because it will make ID got higher - // we just change the password - $r->value = md5(time() . $username . $radius_pass); - $r->save(); - if($radiusDisconnect) - return Radius::disconnectCustomer($username); + public static function customerDeactivate($username, $radiusDisconnect = true) + { { + global $radius_pass; + $r = Radius::getTableCustomer()->where_equal('username', $username)->whereEqual('attribute', 'Cleartext-Password')->findOne(); + if ($r) { + // no need to delete, because it will make ID got higher + // we just change the password + $r->value = md5(time() . $username . $radius_pass); + $r->save(); + if ($radiusDisconnect) + return Radius::disconnectCustomer($username); } } return ''; diff --git a/system/controllers/radius.php b/system/controllers/radius.php index 95cf12ae..2cf1cf36 100644 --- a/system/controllers/radius.php +++ b/system/controllers/radius.php @@ -21,6 +21,7 @@ switch ($action) { case 'nas-add': $ui->assign('_system_menu', 'network'); $ui->assign('_title', "Network Access Server"); + $ui->assign('routers', ORM::for_table('tbl_routers')->find_many()); $ui->display('radius-nas-add.tpl'); break; case 'nas-add-post': @@ -32,6 +33,7 @@ switch ($action) { $server = _post('server', null); $community = _post('community', null); $description = _post('description'); + $routers = _post('routers'); $msg = ''; if (Validator::Length($shortname, 30, 2) == false) { @@ -54,7 +56,7 @@ switch ($action) { $msg .= 'NAS IP Exists
'; } if ($msg == '') { - $id = Radius::nasAdd($shortname, $nasname, $ports, $secret, $description, $type, $server, $community); + $id = Radius::nasAdd($shortname, $nasname, $ports, $secret, $routers, $description, $type, $server, $community); if ($id > 0) { r2(U . 'radius/nas-list/', 's', "NAS Added"); } else { @@ -74,6 +76,7 @@ switch ($action) { $d = ORM::for_table('nas', 'radius')->where_equal('shortname', _get('name'))->find_one(); } if ($d) { + $ui->assign('routers', ORM::for_table('tbl_routers')->find_many()); $ui->assign('d', $d); $ui->display('radius-nas-edit.tpl'); } else { @@ -91,6 +94,7 @@ switch ($action) { $server = _post('server', null); $community = _post('community', null); $description = _post('description'); + $routers = _post('routers'); $msg = ''; if (Validator::Length($shortname, 30, 2) == false) { @@ -109,7 +113,7 @@ switch ($action) { $type = null; } if ($msg == '') { - if (Radius::nasUpdate($id, $shortname, $nasname, $ports, $secret, $description, $type, $server, $community)) { + if (Radius::nasUpdate($id, $shortname, $nasname, $ports, $secret, $routers, $description, $type, $server, $community)) { r2(U . 'radius/list/', 's', "NAS Saved"); } else { r2(U . 'radius/nas-add', 'e', 'NAS NOT Exists'); diff --git a/system/updates.json b/system/updates.json index ef347220..86796d35 100644 --- a/system/updates.json +++ b/system/updates.json @@ -32,5 +32,8 @@ ], "2023.10.1" : [ "ALTER TABLE `tbl_plans` ADD `is_radius` TINYINT(1) NOT NULL DEFAULT '0' COMMENT '1 is radius' AFTER `routers`; " + ], + "2023.10.24" : [ + "ALTER TABLE `nas` ADD `routers` VARCHAR(32) NOT NULL DEFAULT '' AFTER `description`;" ] } \ No newline at end of file diff --git a/ui/ui/radius-nas-add.tpl b/ui/ui/radius-nas-add.tpl index 27c18e8b..0d788b47 100644 --- a/ui/ui/radius-nas-add.tpl +++ b/ui/ui/radius-nas-add.tpl @@ -57,6 +57,18 @@

{Lang::T('Explain Coverage of router')}

+
+ +
+ +
+

Assign NAS to Router

+
+
+ +
+ +
+

Assign NAS to Router

+
+