2017-03-11 03:51:06 +08:00
|
|
|
<?php
|
|
|
|
/**
|
2022-10-16 15:50:24 +08:00
|
|
|
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
|
2017-03-11 03:51:06 +08:00
|
|
|
**/
|
|
|
|
_admin();
|
2022-10-13 15:00:54 +08:00
|
|
|
$ui->assign('_title', $_L['Network']);
|
2017-03-11 03:51:06 +08:00
|
|
|
$ui->assign('_system_menu', 'network');
|
|
|
|
|
|
|
|
$action = $routes['1'];
|
|
|
|
$admin = Admin::_info();
|
|
|
|
$ui->assign('_admin', $admin);
|
|
|
|
|
2022-09-02 16:44:22 +08:00
|
|
|
use PEAR2\Net\RouterOS;
|
|
|
|
|
|
|
|
require_once 'system/autoload/PEAR2/Autoload.php';
|
|
|
|
|
2017-03-11 03:51:06 +08:00
|
|
|
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>');
|
2022-09-02 16:44:22 +08:00
|
|
|
|
2017-03-11 03:51:06 +08:00
|
|
|
$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();
|
|
|
|
}
|
2022-09-02 16:44:22 +08:00
|
|
|
|
2017-03-11 03:51:06 +08:00
|
|
|
$ui->assign('d',$d);
|
|
|
|
$ui->assign('paginator',$paginator);
|
2022-09-18 01:00:40 +08:00
|
|
|
run_hook('view_list_routers'); #HOOK
|
2017-03-11 03:51:06 +08:00
|
|
|
$ui->display('routers.tpl');
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'add':
|
2022-09-18 01:00:40 +08:00
|
|
|
run_hook('view_add_routers'); #HOOK
|
2017-03-11 03:51:06 +08:00
|
|
|
$ui->display('routers-add.tpl');
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'edit':
|
|
|
|
$id = $routes['2'];
|
|
|
|
$d = ORM::for_table('tbl_routers')->find_one($id);
|
|
|
|
if($d){
|
|
|
|
$ui->assign('d',$d);
|
2022-09-18 01:00:40 +08:00
|
|
|
run_hook('view_router_edit'); #HOOK
|
2017-03-11 03:51:06 +08:00
|
|
|
$ui->display('routers-edit.tpl');
|
|
|
|
}else{
|
|
|
|
r2(U . 'routers/list', 'e', $_L['Account_Not_Found']);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'delete':
|
|
|
|
$id = $routes['2'];
|
2022-09-18 01:00:40 +08:00
|
|
|
run_hook('router_delete'); #HOOK
|
2017-03-11 03:51:06 +08:00
|
|
|
$d = ORM::for_table('tbl_routers')->find_one($id);
|
|
|
|
if($d){
|
|
|
|
$d->delete();
|
|
|
|
r2(U . 'routers/list', 's', $_L['Delete_Successfully']);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'add-post':
|
|
|
|
$name = _post('name');
|
|
|
|
$ip_address = _post('ip_address');
|
|
|
|
$username = _post('username');
|
|
|
|
$password = _post('password');
|
|
|
|
$description = _post('description');
|
2022-09-08 11:43:46 +08:00
|
|
|
$enabled = _post('enabled')*1;
|
2022-09-02 16:44:22 +08:00
|
|
|
|
2017-03-11 03:51:06 +08:00
|
|
|
$msg = '';
|
|
|
|
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>';
|
|
|
|
}
|
2022-09-02 16:44:22 +08:00
|
|
|
|
2017-03-11 03:51:06 +08:00
|
|
|
$d = ORM::for_table('tbl_routers')->where('ip_address',$ip_address)->find_one();
|
|
|
|
if($d){
|
|
|
|
$msg .= $_L['Router_already_exist']. '<br>';
|
|
|
|
}
|
|
|
|
|
2022-09-21 15:15:00 +08:00
|
|
|
if(!$config['radius_mode']){
|
2022-09-18 01:52:39 +08:00
|
|
|
Mikrotik::getClient($ip_address,$username,$password);
|
2022-09-02 16:44:22 +08:00
|
|
|
}
|
|
|
|
|
2017-03-11 03:51:06 +08:00
|
|
|
if($msg == ''){
|
2022-09-18 01:00:40 +08:00
|
|
|
run_hook('add_router'); #HOOK
|
2017-03-11 03:51:06 +08:00
|
|
|
$d = ORM::for_table('tbl_routers')->create();
|
|
|
|
$d->name = $name;
|
|
|
|
$d->ip_address = $ip_address;
|
|
|
|
$d->username = $username;
|
|
|
|
$d->password = $password;
|
|
|
|
$d->description = $description;
|
2022-09-08 11:43:46 +08:00
|
|
|
$d->enabled = $enabled;
|
2017-03-11 03:51:06 +08:00
|
|
|
$d->save();
|
|
|
|
|
|
|
|
r2(U . 'routers/list', 's', $_L['Created_Successfully']);
|
|
|
|
}else{
|
|
|
|
r2(U . 'routers/add', 'e', $msg);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case 'edit-post':
|
|
|
|
$name = _post('name');
|
|
|
|
$ip_address = _post('ip_address');
|
|
|
|
$username = _post('username');
|
|
|
|
$password = _post('password');
|
|
|
|
$description = _post('description');
|
2022-09-08 11:43:46 +08:00
|
|
|
$enabled = $_POST['enabled']*1;
|
2017-03-11 03:51:06 +08:00
|
|
|
$msg = '';
|
|
|
|
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>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$id = _post('id');
|
|
|
|
$d = ORM::for_table('tbl_routers')->find_one($id);
|
|
|
|
if($d){
|
|
|
|
|
|
|
|
}else{
|
|
|
|
$msg .= $_L['Data_Not_Found']. '<br>';
|
|
|
|
}
|
|
|
|
|
|
|
|
if($d['name'] != $name){
|
2022-09-07 15:44:04 +08:00
|
|
|
$c = ORM::for_table('tbl_routers')->where('name',$name)->where_not_equal('id',$id)->find_one();
|
2017-03-11 03:51:06 +08:00
|
|
|
if($c){
|
2022-09-07 15:44:04 +08:00
|
|
|
$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){
|
|
|
|
$msg .= 'IP Already Exists<br>';
|
2017-03-11 03:51:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-02 16:44:22 +08:00
|
|
|
|
2022-09-21 15:15:00 +08:00
|
|
|
if(!$config['radius_mode']){
|
2022-09-18 01:52:39 +08:00
|
|
|
Mikrotik::getClient($ip_address,$username,$password);
|
2022-09-02 16:44:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-11 03:51:06 +08:00
|
|
|
if($msg == ''){
|
2022-09-18 01:00:40 +08:00
|
|
|
run_hook('router_edit'); #HOOK
|
2017-03-11 03:51:06 +08:00
|
|
|
$d->name = $name;
|
|
|
|
$d->ip_address = $ip_address;
|
|
|
|
$d->username = $username;
|
|
|
|
$d->password = $password;
|
|
|
|
$d->description = $description;
|
2022-09-08 11:43:46 +08:00
|
|
|
$d->enabled = $enabled;
|
2017-03-11 03:51:06 +08:00
|
|
|
$d->save();
|
2022-09-08 11:43:46 +08:00
|
|
|
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->save();
|
|
|
|
$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->save();
|
|
|
|
$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->save();
|
|
|
|
}
|
2017-03-11 03:51:06 +08:00
|
|
|
r2(U . 'routers/list', 's', $_L['Updated_Successfully']);
|
|
|
|
}else{
|
|
|
|
r2(U . 'routers/edit/'.$id, 'e', $msg);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
echo 'action not defined';
|
|
|
|
}
|