delete nas

This commit is contained in:
Ibnu Maksum
2023-10-02 17:11:02 +07:00
parent d002ed2286
commit 3b87630986
8 changed files with 256 additions and 92 deletions

View File

@ -19,13 +19,6 @@ if ($admin['user_type'] != 'Admin') {
switch ($action) {
case 'nas-list':
$ui->assign('_system_menu', 'network');
$ui->assign('_title', "Network Access Server");
$nas = ORM::for_table('nas', 'radius')->find_many();
$ui->assign('nas', $nas);
$ui->display('radius-nas.tpl');
break;
case 'nas-add':
$ui->assign('_system_menu', 'network');
$ui->assign('_title', "Network Access Server");
@ -73,15 +66,100 @@ switch ($action) {
$b->description = $description;
$b->save();
$id = $b->id();
if($id>0){
r2(U . 'radius/nas-edit/'.$id, 's', "NAS Added");
}else{
if ($id > 0) {
r2(U . 'radius/nas-edit/' . $id, 's', "NAS Added");
} else {
r2(U . 'radius/nas-add/', 'e', "NAS Added Failed");
}
}else{
} else {
r2(U . 'radius/nas-add', 'e', $msg);
}
break;
case 'nas-edit':
$ui->assign('_system_menu', 'network');
$ui->assign('_title', "Network Access Server");
$id = $routes['2'];
$d = ORM::for_table('nas', 'radius')->find_one($id);
if (!$d) {
$d = ORM::for_table('nas', 'radius')->where_equal('shortname', _get('name'))->find_one();
}
if ($d) {
$ui->assign('d', $d);
$ui->display('radius-nas-edit.tpl');
} else {
r2(U . 'radius/list', 'e', $_L['Account_Not_Found']);
}
break;
case 'nas-edit-post':
$id = $routes['2'];
$shortname = _post('shortname');
$nasname = _post('nasname');
$secret = _post('secret');
$ports = _post('ports', null);
$type = _post('type', 'other');
$server = _post('server', null);
$community = _post('community', null);
$description = _post('description');
$msg = '';
if (Validator::Length($shortname, 30, 2) == false) {
$msg .= 'Name should be between 3 to 30 characters' . '<br>';
}
if (empty($ports)) {
$ports = null;
}
if (empty($server)) {
$server = null;
}
if (empty($community)) {
$community = null;
}
if (empty($type)) {
$type = null;
}
$d = ORM::for_table('nas', 'radius')->find_one($id);
if (!$d) {
$msg .= 'NAS NOT Exists<br>';
}
if ($msg == '') {
$d->nasname = $nasname;
$d->shortname = $shortname;
$d->secret = $secret;
$d->ports = $ports;
$d->type = $type;
$d->server = $server;
$d->community = $community;
$d->description = $description;
$d->save();
r2(U . 'radius/nas-edit/' . $id, 's', "NAS Saved");
} else {
r2(U . 'radius/nas-add', 'e', $msg);
}
break;
case 'nas-delete':
$id = $routes['2'];
$d = ORM::for_table('nas', 'radius')->find_one($id);
if ($d) {
$d->delete();
} else {
r2(U . 'radius/nas-list', 'e', 'NAS Not found');
}
default:
$ui->display('a404.tpl');
$ui->assign('_system_menu', 'network');
$ui->assign('_title', "Network Access Server");
$name = _post('name');
if (empty($name)) {
$nas = ORM::for_table('nas', 'radius')->find_many();
} else {
$nas = ORM::for_table('nas', 'radius')
->where_like('nasname', $name)
->where_like('shortname', $name)
->where_like('description', $name)
->find_many();
}
$ui->assign('name', $name);
$ui->assign('nas', $nas);
$ui->display('radius-nas.tpl');
}