Assign router to NAS

This commit is contained in:
Ibnu Maksum 2023-10-24 13:55:34 +07:00
parent 02a68589a1
commit ef25633275
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
7 changed files with 53 additions and 16 deletions

View File

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

View File

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

View File

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

View File

@ -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`;"
]
}

View File

@ -57,6 +57,18 @@
<p class="help-block">{Lang::T('Explain Coverage of router')}</p>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label"><a href="{$_url}routers/add">{$_L['Routers']}</a></label>
<div class="col-md-6">
<select id="routers" name="routers" class="form-control select2">
<option value="">No Router</option>
{foreach $routers as $rs}
<option value="{$rs['name']}">{$rs['name']}</option>
{/foreach}
</select>
</div>
<p class="help-block col-md-4">Assign NAS to Router</p>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button class="btn btn-primary waves-effect waves-light"

View File

@ -57,6 +57,19 @@
<p class="help-block">{Lang::T('Explain Coverage of router')}</p>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label"><a href="{$_url}routers/add">{$_L['Routers']}</a></label>
<div class="col-md-6">
<select id="routers" name="routers" class="form-control select2">
<option value="">No Router</option>
{foreach $routers as $rs}
<option {if $rs['name'] == $d['routers']}selected{/if} value="{$rs['name']}">{$rs['name']}</option>
{/foreach}
</select>
</div>
<p class="help-block col-md-4">Assign NAS to Router</p>
</div>
<div class="form-gro
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button class="btn btn-primary waves-effect waves-light"

View File

@ -38,6 +38,7 @@
<th>Port</th>
<th>Server</th>
<th>Community</th>
<th>Routers</th>
<th>{$_L['Manage']}</th>
</tr>
</thead>
@ -51,6 +52,7 @@
<td>{$ds['ports']}</td>
<td>{$ds['server']}</td>
<td>{$ds['community']}</td>
<td>{$ds['routers']}</td>
<td align="center">
<a href="{$_url}radius/nas-edit/{$ds['id']}" class="btn btn-info btn-xs">{$_L['Edit']}</a>
<a href="{$_url}radius/nas-delete/{$ds['id']}" id="{$ds['id']}"