forked from kevinowino869/mitrobill
Show error, and fix IP Port custom
This commit is contained in:
@ -25,7 +25,7 @@ require_once 'system/autoload/PEAR2/Autoload.php';
|
||||
switch ($action) {
|
||||
case 'list':
|
||||
$ui->assign('xfooter', '<script type="text/javascript" src="ui/lib/c/pool.js"></script>');
|
||||
|
||||
|
||||
$name = _post('name');
|
||||
if ($name != ''){
|
||||
$paginator = Paginator::bootstrap('tbl_pool','pool_name','%'.$name.'%');
|
||||
@ -34,7 +34,7 @@ switch ($action) {
|
||||
$paginator = Paginator::bootstrap('tbl_pool');
|
||||
$d = ORM::for_table('tbl_pool')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many();
|
||||
}
|
||||
|
||||
|
||||
$ui->assign('d',$d);
|
||||
$ui->assign('paginator',$paginator);
|
||||
$ui->display('pool.tpl');
|
||||
@ -43,7 +43,7 @@ switch ($action) {
|
||||
case 'add':
|
||||
$r = ORM::for_table('tbl_routers')->find_many();
|
||||
$ui->assign('r',$r);
|
||||
|
||||
|
||||
$ui->display('pool-add.tpl');
|
||||
break;
|
||||
|
||||
@ -65,23 +65,24 @@ switch ($action) {
|
||||
$mikrotik = Router::_info($d['routers']);
|
||||
if($d){
|
||||
try {
|
||||
$client = new RouterOS\Client($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$iport = explode(":",$mikrotik['ip_address']);
|
||||
$client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'],($iport[1])?$iport[1]:null);
|
||||
} catch (Exception $e) {
|
||||
die('Unable to connect to the router.');
|
||||
die("Unable to connect to the router.<br>".$e->getMessage());
|
||||
}
|
||||
$printRequest = new RouterOS\Request(
|
||||
'/ip pool print .proplist=name',
|
||||
RouterOS\Query::where('name', $d['pool_name'])
|
||||
);
|
||||
$poolName = $client->sendSync($printRequest)->getProperty('name');
|
||||
|
||||
|
||||
$removeRequest = new RouterOS\Request('/ip/pool/remove');
|
||||
$client($removeRequest
|
||||
->setArgument('numbers', $poolName)
|
||||
);
|
||||
|
||||
|
||||
$d->delete();
|
||||
|
||||
|
||||
r2(U . 'pool/list', 's', $_L['Delete_Successfully']);
|
||||
}
|
||||
break;
|
||||
@ -90,7 +91,7 @@ switch ($action) {
|
||||
$name = _post('name');
|
||||
$ip_address = _post('ip_address');
|
||||
$routers = _post('routers');
|
||||
|
||||
|
||||
$msg = '';
|
||||
if(Validator::Length($name,30,2) == false){
|
||||
$msg .= 'Name should be between 3 to 30 characters'. '<br>';
|
||||
@ -98,7 +99,7 @@ switch ($action) {
|
||||
if ($ip_address == '' OR $routers == ''){
|
||||
$msg .= $_L['All_field_is_required']. '<br>';
|
||||
}
|
||||
|
||||
|
||||
$d = ORM::for_table('tbl_pool')->where('pool_name',$name)->find_one();
|
||||
if($d){
|
||||
$msg .= $_L['Pool_already_exist']. '<br>';
|
||||
@ -106,22 +107,23 @@ switch ($action) {
|
||||
$mikrotik = Router::_info($routers);
|
||||
if($msg == ''){
|
||||
try {
|
||||
$client = new RouterOS\Client($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$iport = explode(":",$mikrotik['ip_address']);
|
||||
$client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'],($iport[1])?$iport[1]:null);
|
||||
} catch (Exception $e) {
|
||||
die('Unable to connect to the router.');
|
||||
die("Unable to connect to the router.<br>".$e->getMessage());
|
||||
}
|
||||
$addRequest = new RouterOS\Request('/ip/pool/add');
|
||||
$client->sendSync($addRequest
|
||||
->setArgument('name', $name)
|
||||
->setArgument('ranges', $ip_address)
|
||||
);
|
||||
|
||||
|
||||
$b = ORM::for_table('tbl_pool')->create();
|
||||
$b->pool_name = $name;
|
||||
$b->range_ip = $ip_address;
|
||||
$b->routers = $routers;
|
||||
$b->save();
|
||||
|
||||
|
||||
r2(U . 'pool/list', 's', $_L['Created_Successfully']);
|
||||
}else{
|
||||
r2(U . 'pool/add', 'e', $msg);
|
||||
@ -149,31 +151,32 @@ switch ($action) {
|
||||
}else{
|
||||
$msg .= $_L['Data_Not_Found']. '<br>';
|
||||
}
|
||||
|
||||
|
||||
$mikrotik = Router::_info($routers);
|
||||
if($msg == ''){
|
||||
try {
|
||||
$client = new RouterOS\Client($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$iport = explode(":",$mikrotik['ip_address']);
|
||||
$client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'],($iport[1])?$iport[1]:null);
|
||||
} catch (Exception $e) {
|
||||
die('Unable to connect to the router.');
|
||||
die("Unable to connect to the router.<br>".$e->getMessage());
|
||||
}
|
||||
$printRequest = new RouterOS\Request(
|
||||
'/ip pool print .proplist=name',
|
||||
RouterOS\Query::where('name', $name)
|
||||
);
|
||||
$poolName = $client->sendSync($printRequest)->getProperty('name');
|
||||
|
||||
|
||||
$setRequest = new RouterOS\Request('/ip/pool/set');
|
||||
$client($setRequest
|
||||
->setArgument('numbers', $poolName)
|
||||
->setArgument('ranges', $ip_address)
|
||||
);
|
||||
|
||||
|
||||
$d->pool_name = $name;
|
||||
$d->range_ip = $ip_address;
|
||||
$d->routers = $routers;
|
||||
$d->save();
|
||||
|
||||
|
||||
r2(U . 'pool/list', 's', $_L['Updated_Successfully']);
|
||||
}else{
|
||||
r2(U . 'pool/edit/'.$id, 'e', $msg);
|
||||
|
Reference in New Issue
Block a user