delete nas

This commit is contained in:
Ibnu Maksum 2023-10-02 17:11:02 +07:00
parent d002ed2286
commit 3b87630986
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
8 changed files with 256 additions and 92 deletions

View File

@ -1,4 +1,3 @@
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
CREATE TABLE `nas` (
`id` int(10) NOT NULL,

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

View File

@ -1,7 +1,8 @@
<?php
/**
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
**/
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
**/
_admin();
$ui->assign('_title', $_L['Network']);
$ui->assign('_system_menu', 'network');
@ -14,25 +15,25 @@ use PEAR2\Net\RouterOS;
require_once 'system/autoload/PEAR2/Autoload.php';
if($admin['user_type'] != 'Admin'){
r2(U."dashboard",'e',$_L['Do_Not_Access']);
if ($admin['user_type'] != 'Admin') {
r2(U . "dashboard", 'e', $_L['Do_Not_Access']);
}
switch ($action) {
case 'list':
$ui->assign('xfooter', '<script type="text/javascript" src="ui/lib/c/routers.js"></script>');
$ui->assign('xfooter', '<script type="text/javascript" src="ui/lib/c/routers.js"></script>');
$name = _post('name');
if ($name != ''){
$paginator = Paginator::bootstrap('tbl_routers','name','%'.$name.'%');
$d = ORM::for_table('tbl_routers')->where_like('name','%'.$name.'%')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many();
}else{
$paginator = Paginator::bootstrap('tbl_routers');
$d = ORM::for_table('tbl_routers')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many();
}
$name = _post('name');
if ($name != '') {
$paginator = Paginator::bootstrap('tbl_routers', 'name', '%' . $name . '%');
$d = ORM::for_table('tbl_routers')->where_like('name', '%' . $name . '%')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many();
} else {
$paginator = Paginator::bootstrap('tbl_routers');
$d = ORM::for_table('tbl_routers')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many();
}
$ui->assign('d',$d);
$ui->assign('paginator',$paginator);
$ui->assign('d', $d);
$ui->assign('paginator', $paginator);
run_hook('view_list_routers'); #HOOK
$ui->display('routers.tpl');
break;
@ -45,11 +46,14 @@ switch ($action) {
case 'edit':
$id = $routes['2'];
$d = ORM::for_table('tbl_routers')->find_one($id);
if($d){
$ui->assign('d',$d);
if (!$d) {
$d = ORM::for_table('tbl_routers')->where_equal('name', _get('name'))->find_one();
}
if ($d) {
$ui->assign('d', $d);
run_hook('view_router_edit'); #HOOK
$ui->display('routers-edit.tpl');
}else{
} else {
r2(U . 'routers/list', 'e', $_L['Account_Not_Found']);
}
break;
@ -58,7 +62,7 @@ switch ($action) {
$id = $routes['2'];
run_hook('router_delete'); #HOOK
$d = ORM::for_table('tbl_routers')->find_one($id);
if($d){
if ($d) {
$d->delete();
r2(U . 'routers/list', 's', $_L['Delete_Successfully']);
}
@ -73,35 +77,35 @@ switch ($action) {
$enabled = _post('enabled');
$msg = '';
if(Validator::Length($name,30,4) == false){
$msg .= 'Name should be between 5 to 30 characters'. '<br>';
if (Validator::Length($name, 30, 4) == false) {
$msg .= 'Name should be between 5 to 30 characters' . '<br>';
}
if ($ip_address == '' OR $username == ''){
$msg .= $_L['All_field_is_required']. '<br>';
}
$d = ORM::for_table('tbl_routers')->where('ip_address',$ip_address)->find_one();
if($d){
$msg .= $_L['Router_already_exist']. '<br>';
if ($ip_address == '' or $username == '') {
$msg .= $_L['All_field_is_required'] . '<br>';
}
if(!$config['radius_mode']){
Mikrotik::getClient($ip_address,$username,$password);
$d = ORM::for_table('tbl_routers')->where('ip_address', $ip_address)->find_one();
if ($d) {
$msg .= $_L['Router_already_exist'] . '<br>';
}
if($msg == ''){
if (!$config['radius_mode']) {
Mikrotik::getClient($ip_address, $username, $password);
}
if ($msg == '') {
run_hook('add_router'); #HOOK
$d = ORM::for_table('tbl_routers')->create();
$d->name = $name;
$d->ip_address = $ip_address;
$d->username = $username;
$d->password = $password;
$d->description = $description;
$d->enabled = $enabled;
$d->description = $description;
$d->enabled = $enabled;
$d->save();
r2(U . 'routers/list', 's', $_L['Created_Successfully']);
}else{
} else {
r2(U . 'routers/add', 'e', $msg);
}
break;
@ -115,77 +119,76 @@ switch ($action) {
$description = _post('description');
$enabled = $_POST['enabled'];
$msg = '';
if(Validator::Length($name,30,4) == false){
$msg .= 'Name should be between 5 to 30 characters'. '<br>';
if (Validator::Length($name, 30, 4) == false) {
$msg .= 'Name should be between 5 to 30 characters' . '<br>';
}
if ($ip_address == '' or $username == '') {
$msg .= $_L['All_field_is_required'] . '<br>';
}
if ($ip_address == '' OR $username == ''){
$msg .= $_L['All_field_is_required']. '<br>';
}
$id = _post('id');
$d = ORM::for_table('tbl_routers')->find_one($id);
if($d){
}else{
$msg .= $_L['Data_Not_Found']. '<br>';
if ($d) {
} else {
$msg .= $_L['Data_Not_Found'] . '<br>';
}
if($d['name'] != $name){
$c = ORM::for_table('tbl_routers')->where('name',$name)->where_not_equal('id',$id)->find_one();
if($c){
if ($d['name'] != $name) {
$c = ORM::for_table('tbl_routers')->where('name', $name)->where_not_equal('id', $id)->find_one();
if ($c) {
$msg .= 'Name Already Exists<br>';
}
}
$oldname = $d['name'];
if($d['ip_address'] != $ip_address){
$c = ORM::for_table('tbl_routers')->where('ip_address',$ip_address)->where_not_equal('id',$id)->find_one();
if($c){
if ($d['ip_address'] != $ip_address) {
$c = ORM::for_table('tbl_routers')->where('ip_address', $ip_address)->where_not_equal('id', $id)->find_one();
if ($c) {
$msg .= 'IP Already Exists<br>';
}
}
if(!$config['radius_mode']){
Mikrotik::getClient($ip_address,$username,$password);
if (!$config['radius_mode']) {
Mikrotik::getClient($ip_address, $username, $password);
}
if($msg == ''){
if ($msg == '') {
run_hook('router_edit'); #HOOK
$d->name = $name;
$d->ip_address = $ip_address;
$d->username = $username;
$d->password = $password;
$d->description = $description;
$d->enabled = $enabled;
$d->description = $description;
$d->enabled = $enabled;
$d->save();
if($name!=$oldname){
$p = ORM::for_table('tbl_plans')->where('routers',$oldname)->find_result_set();
$p->set('routers',$name);
if ($name != $oldname) {
$p = ORM::for_table('tbl_plans')->where('routers', $oldname)->find_result_set();
$p->set('routers', $name);
$p->save();
$p = ORM::for_table('tbl_payment_gateway')->where('routers',$oldname)->find_result_set();
$p->set('routers',$name);
$p = ORM::for_table('tbl_payment_gateway')->where('routers', $oldname)->find_result_set();
$p->set('routers', $name);
$p->save();
$p = ORM::for_table('tbl_pool')->where('routers',$oldname)->find_result_set();
$p->set('routers',$name);
$p = ORM::for_table('tbl_pool')->where('routers', $oldname)->find_result_set();
$p->set('routers', $name);
$p->save();
$p = ORM::for_table('tbl_transactions')->where('routers',$oldname)->find_result_set();
$p->set('routers',$name);
$p = ORM::for_table('tbl_transactions')->where('routers', $oldname)->find_result_set();
$p->set('routers', $name);
$p->save();
$p = ORM::for_table('tbl_user_recharges')->where('routers',$oldname)->find_result_set();
$p->set('routers',$name);
$p = ORM::for_table('tbl_user_recharges')->where('routers', $oldname)->find_result_set();
$p->set('routers', $name);
$p->save();
$p = ORM::for_table('tbl_voucher')->where('routers',$oldname)->find_result_set();
$p->set('routers',$name);
$p = ORM::for_table('tbl_voucher')->where('routers', $oldname)->find_result_set();
$p->set('routers', $name);
$p->save();
}
r2(U . 'routers/list', 's', $_L['Updated_Successfully']);
}else{
r2(U . 'routers/edit/'.$id, 'e', $msg);
} else {
r2(U . 'routers/edit/' . $id, 'e', $msg);
}
break;
default:
r2(U . 'routers/list/', 's', '');
}
}

View File

@ -25,5 +25,12 @@
"2023.9.27" : [
"ALTER TABLE `tbl_plans` CHANGE `type` `type` ENUM('Hotspot','PPPOE','Balance','Radius') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;",
"ALTER TABLE `tbl_transactions` CHANGE `type` `type` ENUM('Hotspot','PPPOE','Balance','Radius') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;"
],
"2023.9.28" : [
"ALTER TABLE `tbl_plans` CHANGE `type` `type` ENUM('Hotspot','PPPOE','Balance') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;",
"ALTER TABLE `tbl_transactions` CHANGE `type` `type` ENUM('Hotspot','PPPOE','Balance') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;"
],
"2023.10.1" : [
"ALTER TABLE `tbl_plans` ADD `is_radius` TINYINT(1) NOT NULL DEFAULT '0' COMMENT '1 is radius' AFTER `routers`; "
]
}

View File

@ -57,7 +57,15 @@
<td>{$ds['time_limit']} {$ds['time_unit']}</td>
<td>{$ds['data_limit']} {$ds['data_unit']}</td>
<td>{$ds['validity']} {$ds['validity_unit']}</td>
<td>{$ds['routers']}</td>
<td>
{if $ds['is_radius']==1}
<span class="label label-primary">RADIUS</span>
{else}
{if $ds['routers']!=''}
<a href="{$_url}routers/edit/0&name={$ds['routers']}">{$ds['routers']}</a>
{/if}
{/if}
</td>
<td>{$ds['pool_expired']}</td>
<td>
<a href="{$_url}services/edit/{$ds['id']}"

74
ui/ui/radius-nas-edit.tpl Normal file
View File

@ -0,0 +1,74 @@
{include file="sections/header.tpl"}
<!-- routers-add -->
<div class="row">
<div class="col-sm-12 col-md-12">
<div class="panel panel-primary panel-hovered panel-stacked mb30">
<div class="panel-heading">Radius - Edit NAS</div>
<div class="panel-body">
<form class="form-horizontal" method="post" role="form" action="{$_url}radius/nas-edit-post/{$d['id']}">
<div class="form-group">
<label class="col-md-2 control-label">{$_L['Router_Name']}</label>
<div class="col-md-6">
<input type="text" required class="form-control" id="shortname" name="shortname" value="{$d['shortname']}" maxlength="32">
<p class="help-block">{Lang::T('Name of Area that router operated')}</p>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">{$_L['IP_Address']}</label>
<div class="col-md-6">
<input type="text" placeholder="192.168.88.1" value="{$d['nasname']}" required class="form-control" id="nasname"
name="nasname" maxlength="128">
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">Secret</label>
<div class="col-md-6">
<input type="password" class="form-control" id="secret" name="secret" required value="{$d['secret']}"
onmouseleave="this.type = 'password'" onmouseenter="this.type = 'text'" maxlength="60">
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">Ports</label>
<div class="col-md-2">
<input type="text" class="form-control" id="ports" name="ports" placeholder="null" value="{$d['ports']}">
</div>
<label class="col-md-2 control-label">Type</label>
<div class="col-md-2">
<input type="text" class="form-control" id="type" name="type" value="other" value="{$d['type']}" required
placeholder="other">
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">Server</label>
<div class="col-md-2">
<input type="text" class="form-control" id="server" name="server" value="{$d['server']}" placeholder="null">
</div>
<label class="col-md-2 control-label">Community</label>
<div class="col-md-2">
<input type="text" class="form-control" id="community" name="community" value="{$d['community']}" placeholder="null">
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">{$_L['Description']}</label>
<div class="col-md-6">
<textarea class="form-control" id="description" name="description"> {htmlentities($d['description'])}</textarea>
<p class="help-block">{Lang::T('Explain Coverage of router')}</p>
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button class="btn btn-primary waves-effect waves-light"
type="submit">{$_L['Save']}</button>
Or <a href="{$_url}radius/nas-list">{$_L['Cancel']}</a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
{include file="sections/footer.tpl"}

View File

@ -14,7 +14,7 @@
<div class="input-group-addon">
<span class="fa fa-search"></span>
</div>
<input type="text" name="name" class="form-control"
<input type="text" name="name" class="form-control" value="{$name}"
placeholder="{$_L['Search_by_Name']}...">
<div class="input-group-btn">
<button class="btn btn-success" type="submit">{$_L['Search']}</button>
@ -31,7 +31,7 @@
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>#</th>
<th>ID</th>
<th>Name</th>
<th>IP</th>
<th>Type</th>
@ -42,10 +42,9 @@
</tr>
</thead>
<tbody>
{$no = 1}
{foreach $nas as $ds}
<tr>
<td align="center">{$no++}</td>
<td align="center">{$ds['id']}</td>
<td>{$ds['shortname']}</td>
<td>{$ds['nasname']}</td>
<td>{$ds['type']}</td>

View File

@ -163,10 +163,6 @@
href="{$_url}services/hotspot">{$_L['Hotspot_Plans']}</a></li>
<li {if $_routes[1] eq 'pppoe'}class="active" {/if}><a
href="{$_url}services/pppoe">{$_L['PPPOE_Plans']}</a></li>
{if $_c['radius_enable'] == 'yes'}
<li {if $_routes[1] eq 'radius'}class="active" {/if}><a
href="{$_url}services/radius">{Lang::T('Radius Plans')}</a></li>
{/if}
<li {if $_routes[1] eq 'list'}class="active" {/if}><a
href="{$_url}bandwidth/list">{$_L['Bandwidth_Plans']}</a></li>
<li {if $_routes[1] eq 'balance'}class="active" {/if}><a