diff --git a/index.php b/index.php index c9fd7289..c63c6bde 100644 --- a/index.php +++ b/index.php @@ -7,8 +7,6 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt **/ -//ini_set('display_errors', 1); -//ini_set('display_startup_errors', 1); -//error_reporting(E_ALL); + require ('system/boot.php'); App::_run(); diff --git a/system/controllers/accounts.php b/system/controllers/accounts.php index ba53775f..ae7f7874 100644 --- a/system/controllers/accounts.php +++ b/system/controllers/accounts.php @@ -19,7 +19,7 @@ use PEAR2\Net\RouterOS; require_once 'system/autoload/PEAR2/Autoload.php'; switch ($action) { - + case 'change-password': $ui->display('user-change-password.tpl'); break; @@ -32,7 +32,7 @@ switch ($action) { $d_pass = $d['password']; $npass = _post('npass'); $cnpass = _post('cnpass'); - + if(Password::_uverify($password,$d_pass) == true){ if(!Validator::Length($npass,15,2)){ r2(U.'accounts/change-password','e','New Password must be 3 to 14 character'); @@ -46,20 +46,21 @@ switch ($action) { $mikrotik = Router::_info($c['routers']); if($c['type'] == 'Hotspot'){ 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.
".$e->getMessage()); } $printRequest = new RouterOS\Request('/ip/hotspot/user/print'); $printRequest->setArgument('.proplist', '.id'); $printRequest->setQuery(RouterOS\Query::where('name', $user['username'])); $id = $client->sendSync($printRequest)->getProperty('.id'); - + $setRequest = new RouterOS\Request('/ip/hotspot/user/set'); $setRequest->setArgument('numbers', $id); $setRequest->setArgument('password', $npass); $client->sendSync($setRequest); - + //remove hotspot active $onlineRequest = new RouterOS\Request('/ip/hotspot/active/print'); $onlineRequest->setArgument('.proplist', '.id'); @@ -69,31 +70,32 @@ switch ($action) { $removeRequest = new RouterOS\Request('/ip/hotspot/active/remove'); $removeRequest->setArgument('numbers', $id); $client->sendSync($removeRequest); - + $d->password = $npass; $d->save(); - + _msglog('s',$_L['Password_Changed_Successfully']); _log('['.$user['username'].']: Password changed successfully','User',$user['id']); - + r2(U.'login'); - + }else{ 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.
".$e->getMessage()); } $printRequest = new RouterOS\Request('/ppp/secret/print'); $printRequest->setArgument('.proplist', '.id'); $printRequest->setQuery(RouterOS\Query::where('name', $user['username'])); $id = $client->sendSync($printRequest)->getProperty('.id'); - + $setRequest = new RouterOS\Request('/ppp/secret/set'); $setRequest->setArgument('numbers', $id); $setRequest->setArgument('password', $npass); $client->sendSync($setRequest); - + //remove pppoe active $onlineRequest = new RouterOS\Request('/ppp/active/print'); $onlineRequest->setArgument('.proplist', '.id'); @@ -103,25 +105,25 @@ switch ($action) { $removeRequest = new RouterOS\Request('/ppp/active/remove'); $removeRequest->setArgument('numbers', $id); $client->sendSync($removeRequest); - + $d->password = $npass; $d->save(); - + _msglog('s',$_L['Password_Changed_Successfully']); _log('['.$user['username'].']: Password changed successfully','User',$user['id']); - + r2(U.'login'); } }else{ $d->password = $npass; $d->save(); - + _msglog('s',$_L['Password_Changed_Successfully']); _log('['.$user['username'].']: Password changed successfully','User',$user['id']); - + r2(U.'login'); } - + }else{ r2(U.'accounts/change-password','e',$_L['Incorrect_Current_Password']); } @@ -134,7 +136,7 @@ switch ($action) { break; case 'profile': - + $id = $_SESSION['uid']; $d = ORM::for_table('tbl_customers')->find_one($id); if($d){ @@ -157,7 +159,7 @@ switch ($action) { if(Validator::UnsignedNumber($phonenumber) == false){ $msg .= 'Phone Number must be a number'. '
'; } - + $id = _post('id'); $d = ORM::for_table('tbl_customers')->find_one($id); if($d){ @@ -170,14 +172,14 @@ switch ($action) { $d->address = $address; $d->phonenumber = $phonenumber; $d->save(); - + _log('['.$user['username'].']: '.$_L['User_Updated_Successfully'],'User',$user['id']); r2(U . 'accounts/profile', 's', $_L['User_Updated_Successfully']); }else{ r2(U . 'accounts/profile', 'e', $msg); } break; - + default: echo 'action not defined'; } \ No newline at end of file diff --git a/system/controllers/customers.php b/system/controllers/customers.php index 72526438..e27f9eff 100644 --- a/system/controllers/customers.php +++ b/system/controllers/customers.php @@ -33,7 +33,7 @@ switch ($action) { $paginator = Paginator::bootstrap('tbl_customers'); $d = ORM::for_table('tbl_customers')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); } - + $ui->assign('d',$d); $ui->assign('paginator',$paginator); $ui->display('customers.tpl'); @@ -64,19 +64,20 @@ switch ($action) { $mikrotik = Router::_info($c['routers']); if($c['type'] == 'Hotspot'){ 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.
".$e->getMessage()); } $printRequest = new RouterOS\Request('/ip/hotspot/user/print'); $printRequest->setArgument('.proplist', '.id'); $printRequest->setQuery(RouterOS\Query::where('name', $c['username'])); $id = $client->sendSync($printRequest)->getProperty('.id'); - + $setRequest = new RouterOS\Request('/ip/hotspot/user/remove'); $setRequest->setArgument('numbers', $id); $client->sendSync($setRequest); - + //remove hotspot active $onlineRequest = new RouterOS\Request('/ip/hotspot/active/print'); $onlineRequest->setArgument('.proplist', '.id'); @@ -86,23 +87,24 @@ switch ($action) { $removeRequest = new RouterOS\Request('/ip/hotspot/active/remove'); $removeRequest->setArgument('numbers', $id); $client->sendSync($removeRequest); - + }else{ - + 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.
".$e->getMessage()); } $printRequest = new RouterOS\Request('/ppp/secret/print'); $printRequest->setArgument('.proplist', '.id'); $printRequest->setQuery(RouterOS\Query::where('name', $c['username'])); $id = $client->sendSync($printRequest)->getProperty('.id'); - + $setRequest = new RouterOS\Request('/ppp/secret/remove'); $setRequest->setArgument('numbers', $id); $client->sendSync($setRequest); - + //remove pppoe active $onlineRequest = new RouterOS\Request('/ppp/active/print'); $onlineRequest->setArgument('.proplist', '.id'); @@ -127,7 +129,7 @@ switch ($action) { $c->delete(); }catch(Exception $e){} } - + r2(U . 'customers/list', 's', $_L['User_Delete_Ok']); } break; @@ -139,7 +141,7 @@ switch ($action) { $cpassword = _post('cpassword'); $address = _post('address'); $phonenumber = _post('phonenumber'); - + $msg = ''; if(Validator::Length($username,35,2) == false){ $msg .= 'Username should be between 3 to 55 characters'. '
'; @@ -220,20 +222,21 @@ switch ($action) { $mikrotik = Router::_info($c['routers']); if($c['type'] == 'Hotspot'){ 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.
".$e->getMessage()); } $printRequest = new RouterOS\Request('/ip/hotspot/user/print'); $printRequest->setArgument('.proplist', '.id'); $printRequest->setQuery(RouterOS\Query::where('name', $c['username'])); $id = $client->sendSync($printRequest)->getProperty('.id'); - + $setRequest = new RouterOS\Request('/ip/hotspot/user/set'); $setRequest->setArgument('numbers', $id); $setRequest->setArgument('password', $password); $client->sendSync($setRequest); - + //remove hotspot active $onlineRequest = new RouterOS\Request('/ip/hotspot/active/print'); $onlineRequest->setArgument('.proplist', '.id'); @@ -243,26 +246,27 @@ switch ($action) { $removeRequest = new RouterOS\Request('/ip/hotspot/active/remove'); $removeRequest->setArgument('numbers', $id); $client->sendSync($removeRequest); - + $d->password = $password; $d->save(); - + }else{ 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.
".$e->getMessage()); } $printRequest = new RouterOS\Request('/ppp/secret/print'); $printRequest->setArgument('.proplist', '.id'); $printRequest->setQuery(RouterOS\Query::where('name', $c['username'])); $id = $client->sendSync($printRequest)->getProperty('.id'); - + $setRequest = new RouterOS\Request('/ppp/secret/set'); $setRequest->setArgument('numbers', $id); $setRequest->setArgument('password', $password); $client->sendSync($setRequest); - + //remove pppoe active $onlineRequest = new RouterOS\Request('/ppp/active/print'); $onlineRequest->setArgument('.proplist', '.id'); @@ -272,7 +276,7 @@ switch ($action) { $removeRequest = new RouterOS\Request('/ppp/active/remove'); $removeRequest->setArgument('numbers', $id); $client->sendSync($removeRequest); - + $d->password = $password; $d->save(); } diff --git a/system/controllers/pool.php b/system/controllers/pool.php index 440c626e..f80d5b46 100644 --- a/system/controllers/pool.php +++ b/system/controllers/pool.php @@ -25,7 +25,7 @@ require_once 'system/autoload/PEAR2/Autoload.php'; switch ($action) { case 'list': $ui->assign('xfooter', ''); - + $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.
".$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'. '
'; @@ -98,7 +99,7 @@ switch ($action) { if ($ip_address == '' OR $routers == ''){ $msg .= $_L['All_field_is_required']. '
'; } - + $d = ORM::for_table('tbl_pool')->where('pool_name',$name)->find_one(); if($d){ $msg .= $_L['Pool_already_exist']. '
'; @@ -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.
".$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']. '
'; } - + $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.
".$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); diff --git a/system/controllers/prepaid.php b/system/controllers/prepaid.php index 915270f1..92366cec 100644 --- a/system/controllers/prepaid.php +++ b/system/controllers/prepaid.php @@ -91,9 +91,10 @@ switch ($action) { if ($type == 'Hotspot') { if ($b) { 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.
".$e->getMessage()); } $printRequest = new RouterOS\Request( @@ -191,9 +192,10 @@ switch ($action) { $t->save(); } else { 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.
".$e->getMessage()); } /* iBNuX Added: @@ -285,9 +287,10 @@ switch ($action) { if ($b) { 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.
".$e->getMessage()); } $printRequest = new RouterOS\Request( '/ppp secret print .proplist=name', @@ -338,9 +341,10 @@ switch ($action) { $t->save(); } else { 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.
".$e->getMessage()); } $addRequest = new RouterOS\Request('/ppp/secret/add'); $client->sendSync( @@ -424,9 +428,10 @@ switch ($action) { if ($d) { if ($d['type'] == 'Hotspot') { 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.
".$e->getMessage()); } $printRequest = new RouterOS\Request( '/ip hotspot user print .proplist=name', @@ -442,9 +447,10 @@ switch ($action) { $d->delete(); } else { 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.
".$e->getMessage()); } $printRequest = new RouterOS\Request( '/ppp secret print .proplist=name', @@ -682,9 +688,10 @@ switch ($action) { if ($v1['type'] == 'Hotspot') { if ($b) { 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.
".$e->getMessage()); } $printRequest = new RouterOS\Request( '/ip hotspot user print .proplist=name', @@ -781,9 +788,10 @@ switch ($action) { $t->save(); } else { 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.
".$e->getMessage()); } /* iBNuX Added: * Time limit to Mikrotik @@ -877,9 +885,10 @@ switch ($action) { } else { if ($b) { 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.
".$e->getMessage()); } $printRequest = new RouterOS\Request( '/ppp secret print .proplist=name', @@ -930,9 +939,10 @@ switch ($action) { $t->save(); } else { 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.
".$e->getMessage()); } $addRequest = new RouterOS\Request('/ppp/secret/add'); $client->sendSync( diff --git a/system/controllers/register.php b/system/controllers/register.php index 60a80799..9f3f7b90 100644 --- a/system/controllers/register.php +++ b/system/controllers/register.php @@ -1,249 +1,257 @@ where('code',$code)->where('status',0)->find_one(); - if ($v1){ - $msg = ''; - if(Validator::Length($username,35,2) == false){ - $msg .= 'Username should be between 3 to 55 characters'. '
'; - } - if(Validator::Length($fullname,36,2) == false){ - $msg .= 'Full Name should be between 3 to 25 characters'. '
'; - } - if(!Validator::Length($password,35,2)){ - $msg .= 'Password should be between 3 to 35 characters'. '
'; + $phonenumber = _post('phonenumber'); + $code = _post('kodevoucher'); + $v1 = ORM::for_table('tbl_voucher')->where('code', $code)->where('status', 0)->find_one(); + if ($v1) { + $msg = ''; + if (Validator::Length($username, 35, 2) == false) { + $msg .= 'Username should be between 3 to 55 characters' . '
'; + } + if (Validator::Length($fullname, 36, 2) == false) { + $msg .= 'Full Name should be between 3 to 25 characters' . '
'; + } + if (!Validator::Length($password, 35, 2)) { + $msg .= 'Password should be between 3 to 35 characters' . '
'; + } + if ($password != $cpassword) { + $msg .= $_L['PasswordsNotMatch'] . '
'; + } - } - if($password != $cpassword){ - $msg .= $_L['PasswordsNotMatch']. '
'; - } + $d = ORM::for_table('tbl_customers')->where('username', $username)->find_one(); + if ($d) { + $msg .= $_L['account_already_exist'] . '
'; + } + if ($msg == '') { + $d = ORM::for_table('tbl_customers')->create(); + $d->username = $username; + $d->password = $password; + $d->fullname = $fullname; + $d->address = $address; + $d->phonenumber = $phonenumber; + if ($d->save()) { + $user = $d->id(); + //check voucher plan + $p = ORM::for_table('tbl_plans')->find_one($v1['id_plan']); + $c = ORM::for_table('tbl_customers')->find_one($user); + $p = ORM::for_table('tbl_plans')->find_one($v1['id_plan']); - $d = ORM::for_table('tbl_customers')->where('username',$username)->find_one(); - if($d){ - $msg .= $_L['account_already_exist']. '
'; - } - if($msg == ''){ - $d = ORM::for_table('tbl_customers')->create(); - $d->username = $username; - $d->password = $password; - $d->fullname = $fullname; - $d->address = $address; - $d->phonenumber = $phonenumber; - if($d->save()){ - $user = $d->id(); - //check voucher plan - $p = ORM::for_table('tbl_plans')->find_one($v1['id_plan']); - $c = ORM::for_table('tbl_customers')->find_one($user); - $p = ORM::for_table('tbl_plans')->find_one($v1['id_plan']); - - $date_now = date("Y-m-d H:i:s"); - $date_only = date("Y-m-d"); - $time = date("H:i:s"); - - $mikrotik = Router::_info($v1['routers']); - $date_exp = date("Y-m-d", mktime(0,0,0,date("m"),date("d") + $p['validity'],date("Y"))); + $date_now = date("Y-m-d H:i:s"); + $date_only = date("Y-m-d"); + $time = date("H:i:s"); - if($v1['type'] == 'Hotspot'){ - try { - $client = new RouterOS\Client($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); - } catch (Exception $e) { - die('Unable to connect to the router.'); - } - /* iBNuX Added: + $mikrotik = Router::_info($v1['routers']); + $date_exp = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") + $p['validity'], date("Y"))); + + if ($v1['type'] == 'Hotspot') { + try { + $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.
".$e->getMessage()); + } + /* iBNuX Added: * Time limit to Mikrotik * 'Time_Limit', 'Data_Limit', 'Both_Limit' */ - $addRequest = new RouterOS\Request('/ip/hotspot/user/add'); - if($p['typebp']=="Limited"){ - if($p['limit_type']=="Time_Limit"){ - if($p['time_unit']=='Hrs') - $timelimit = $p['time_limit'].":00:00"; - else - $timelimit = "00:".$p['time_limit'].":00"; - $client->sendSync($addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-uptime', $timelimit) - ); - }else if($p['limit_type']=="Data_Limit"){ - if($p['data_unit']=='GB') - $datalimit = $p['data_limit']."000000000"; - else - $datalimit = $p['data_limit']."000000"; - $client->sendSync($addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-bytes-total', $datalimit) - ); - }else if($p['limit_type']=="Both_Limit"){ - if($p['time_unit']=='Hrs') - $timelimit = $p['time_limit'].":00:00"; - else - $timelimit = "00:".$p['time_limit'].":00"; - if($p['data_unit']=='GB') - $datalimit = $p['data_limit']."000000000"; - else - $datalimit = $p['data_limit']."000000"; - $client->sendSync($addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-uptime', $timelimit) - ->setArgument('limit-bytes-total', $datalimit) - ); - } - }else{ - $client->sendSync($addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ); - } - - $d = ORM::for_table('tbl_user_recharges')->create(); - $d->customer_id = $user; - $d->username = $c['username']; - $d->plan_id = $v1['id_plan']; - $d->namebp = $p['name_plan']; - $d->recharged_on = $date_only; - $d->expiration = $date_exp; - $d->time = $time; - $d->status = "on"; - $d->method = "voucher"; - $d->routers = $v1['routers']; - $d->type = "Hotspot"; - $d->save(); - - // insert table transactions - $t = ORM::for_table('tbl_transactions')->create(); - $t->invoice = "INV-"._raid(5); - $t->username = $c['username']; - $t->plan_name = $p['name_plan']; - $t->price = $p['price']; - $t->recharged_on = $date_only; - $t->expiration = $date_exp; - $t->time = $time; - $t->method = "voucher"; - $t->routers = $v1['routers']; - $t->type = "Hotspot"; - $t->save(); - - $v1->status = "1"; - $v1->user = $c['username']; - $v1->save(); - - }else{ - try { - $client = new RouterOS\Client($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); - } catch (Exception $e) { - die('Unable to connect to the router.'); - } - $addRequest = new RouterOS\Request('/ppp/secret/add'); - $client->sendSync($addRequest - ->setArgument('name', $c['username']) - ->setArgument('service', 'pppoe') - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ); - - $d = ORM::for_table('tbl_user_recharges')->create(); - $d->customer_id = $user; - $d->username = $c['username']; - $d->plan_id = $v1['id_plan']; - $d->namebp = $p['name_plan']; - $d->recharged_on = $date_only; - $d->expiration = $date_exp; - $d->time = $time; - $d->status = "on"; - $d->method = "voucher"; - $d->routers = $v1['routers']; - $d->type = "PPPOE"; - $d->save(); - - // insert table transactions - $t = ORM::for_table('tbl_transactions')->create(); - $t->invoice = "INV-"._raid(5); - $t->username = $c['username']; - $t->plan_name = $p['name_plan']; - $t->price = $p['price']; - $t->recharged_on = $date_only; - $t->expiration = $date_exp; - $t->time = $time; - $t->method = "voucher"; - $t->routers = $v1['routers']; - $t->type = "PPPOE"; - $t->save(); + $addRequest = new RouterOS\Request('/ip/hotspot/user/add'); + if ($p['typebp'] == "Limited") { + if ($p['limit_type'] == "Time_Limit") { + if ($p['time_unit'] == 'Hrs') + $timelimit = $p['time_limit'] . ":00:00"; + else + $timelimit = "00:" . $p['time_limit'] . ":00"; + $client->sendSync( + $addRequest + ->setArgument('name', $c['username']) + ->setArgument('profile', $p['name_plan']) + ->setArgument('password', $c['password']) + ->setArgument('limit-uptime', $timelimit) + ); + } else if ($p['limit_type'] == "Data_Limit") { + if ($p['data_unit'] == 'GB') + $datalimit = $p['data_limit'] . "000000000"; + else + $datalimit = $p['data_limit'] . "000000"; + $client->sendSync( + $addRequest + ->setArgument('name', $c['username']) + ->setArgument('profile', $p['name_plan']) + ->setArgument('password', $c['password']) + ->setArgument('limit-bytes-total', $datalimit) + ); + } else if ($p['limit_type'] == "Both_Limit") { + if ($p['time_unit'] == 'Hrs') + $timelimit = $p['time_limit'] . ":00:00"; + else + $timelimit = "00:" . $p['time_limit'] . ":00"; + if ($p['data_unit'] == 'GB') + $datalimit = $p['data_limit'] . "000000000"; + else + $datalimit = $p['data_limit'] . "000000"; + $client->sendSync( + $addRequest + ->setArgument('name', $c['username']) + ->setArgument('profile', $p['name_plan']) + ->setArgument('password', $c['password']) + ->setArgument('limit-uptime', $timelimit) + ->setArgument('limit-bytes-total', $datalimit) + ); + } + } else { + $client->sendSync( + $addRequest + ->setArgument('name', $c['username']) + ->setArgument('profile', $p['name_plan']) + ->setArgument('password', $c['password']) + ); + } - $v1->status = "1"; - $v1->user = $c['username']; - $v1->save(); - } - r2(U . 'login', 's', $_L['Register_Success']); - }else{ - $ui->assign('username', $username); - $ui->assign('fullname', $fullname); - $ui->assign('address', $address); - $ui->assign('phonenumber', $phonenumber); - $ui->assign('notify','
+ $d = ORM::for_table('tbl_user_recharges')->create(); + $d->customer_id = $user; + $d->username = $c['username']; + $d->plan_id = $v1['id_plan']; + $d->namebp = $p['name_plan']; + $d->recharged_on = $date_only; + $d->expiration = $date_exp; + $d->time = $time; + $d->status = "on"; + $d->method = "voucher"; + $d->routers = $v1['routers']; + $d->type = "Hotspot"; + $d->save(); + + // insert table transactions + $t = ORM::for_table('tbl_transactions')->create(); + $t->invoice = "INV-" . _raid(5); + $t->username = $c['username']; + $t->plan_name = $p['name_plan']; + $t->price = $p['price']; + $t->recharged_on = $date_only; + $t->expiration = $date_exp; + $t->time = $time; + $t->method = "voucher"; + $t->routers = $v1['routers']; + $t->type = "Hotspot"; + $t->save(); + + $v1->status = "1"; + $v1->user = $c['username']; + $v1->save(); + } else { + try { + $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.
".$e->getMessage()); + } + $addRequest = new RouterOS\Request('/ppp/secret/add'); + $client->sendSync( + $addRequest + ->setArgument('name', $c['username']) + ->setArgument('service', 'pppoe') + ->setArgument('profile', $p['name_plan']) + ->setArgument('password', $c['password']) + ); + + $d = ORM::for_table('tbl_user_recharges')->create(); + $d->customer_id = $user; + $d->username = $c['username']; + $d->plan_id = $v1['id_plan']; + $d->namebp = $p['name_plan']; + $d->recharged_on = $date_only; + $d->expiration = $date_exp; + $d->time = $time; + $d->status = "on"; + $d->method = "voucher"; + $d->routers = $v1['routers']; + $d->type = "PPPOE"; + $d->save(); + + // insert table transactions + $t = ORM::for_table('tbl_transactions')->create(); + $t->invoice = "INV-" . _raid(5); + $t->username = $c['username']; + $t->plan_name = $p['name_plan']; + $t->price = $p['price']; + $t->recharged_on = $date_only; + $t->expiration = $date_exp; + $t->time = $time; + $t->method = "voucher"; + $t->routers = $v1['routers']; + $t->type = "PPPOE"; + $t->save(); + + $v1->status = "1"; + $v1->user = $c['username']; + $v1->save(); + } + r2(U . 'login', 's', $_L['Register_Success']); + } else { + $ui->assign('username', $username); + $ui->assign('fullname', $fullname); + $ui->assign('address', $address); + $ui->assign('phonenumber', $phonenumber); + $ui->assign('notify', '
Failed to register
'); - $ui->display('register.tpl'); - } - //r2(U . 'register', 's', $_L['account_created_successfully']); - }else{ - $ui->assign('username', $username); - $ui->assign('fullname', $fullname); - $ui->assign('address', $address); - $ui->assign('phonenumber', $phonenumber); - $ui->assign('notify','
+ $ui->display('register.tpl'); + } + //r2(U . 'register', 's', $_L['account_created_successfully']); + } else { + $ui->assign('username', $username); + $ui->assign('fullname', $fullname); + $ui->assign('address', $address); + $ui->assign('phonenumber', $phonenumber); + $ui->assign('notify', '
-
'.$msg.'
'); - $ui->display('register.tpl'); - } - }else{ - $ui->assign('username', $username); - $ui->assign('fullname', $fullname); - $ui->assign('address', $address); - $ui->assign('phonenumber', $phonenumber); - $ui->assign('notify','
+
' . $msg . '
'); + $ui->display('register.tpl'); + } + } else { + $ui->assign('username', $username); + $ui->assign('fullname', $fullname); + $ui->assign('address', $address); + $ui->assign('phonenumber', $phonenumber); + $ui->assign('notify', '
-
'.$_L['Voucher_Not_Valid'].'
'); - $ui->display('register.tpl'); - //r2(U . 'register', 'e', $_L['Voucher_Not_Valid']); - } - /*$password = _post('password'); +
' . $_L['Voucher_Not_Valid'] . '
'); + $ui->display('register.tpl'); + //r2(U . 'register', 'e', $_L['Voucher_Not_Valid']); + } + /*$password = _post('password'); if($username != '' AND $password != ''){ $d = ORM::for_table('tbl_customers')->where('username',$username)->find_one(); if($d){ @@ -267,15 +275,14 @@ switch($do){ _msglog('e',$_L['Invalid_Username_or_Password']); r2(U.'login'); }*/ - + break; default: - $ui->assign('username', ""); - $ui->assign('fullname', ""); - $ui->assign('address', ""); - $ui->assign('phonenumber', ""); + $ui->assign('username', ""); + $ui->assign('fullname', ""); + $ui->assign('address', ""); + $ui->assign('phonenumber', ""); $ui->display('register.tpl'); break; } - diff --git a/system/controllers/services.php b/system/controllers/services.php index 235ce4e4..01e4c8d1 100644 --- a/system/controllers/services.php +++ b/system/controllers/services.php @@ -1,94 +1,98 @@ assign('_title', $_L['Hotspot_Plans'].' - '. $config['CompanyName']); +$ui->assign('_title', $_L['Hotspot_Plans'] . ' - ' . $config['CompanyName']); $ui->assign('_system_menu', 'services'); $action = $routes['1']; $admin = Admin::_info(); $ui->assign('_admin', $admin); -if($admin['user_type'] != 'Admin' AND $admin['user_type'] != 'Sales'){ - r2(U."dashboard",'e',$_L['Do_Not_Access']); +if ($admin['user_type'] != 'Admin' and $admin['user_type'] != 'Sales') { + r2(U . "dashboard", 'e', $_L['Do_Not_Access']); } use PEAR2\Net\RouterOS; + require_once 'system/autoload/PEAR2/Autoload.php'; switch ($action) { case 'hotspot': - $ui->assign('xfooter', ''); + $ui->assign('xfooter', ''); - $name = _post('name'); - if ($name != ''){ - $paginator = Paginator::bootstrap('tbl_plans','name_plan','%'.$name.'%','type','Hotspot'); - $d = ORM::for_table('tbl_bandwidth')->join('tbl_plans', array('tbl_bandwidth.id', '=', 'tbl_plans.id_bw'))->where('tbl_plans.type','Hotspot')->where_like('tbl_plans.name_plan','%'.$name.'%')->offset($paginator['startpoint'])->limit($paginator['limit'])->find_many(); - }else{ - $paginator = Paginator::bootstrap('tbl_plans','type','Hotspot'); - $d = ORM::for_table('tbl_bandwidth')->join('tbl_plans', array('tbl_bandwidth.id', '=', 'tbl_plans.id_bw'))->where('tbl_plans.type','Hotspot')->offset($paginator['startpoint'])->limit($paginator['limit'])->find_many(); - } + $name = _post('name'); + if ($name != '') { + $paginator = Paginator::bootstrap('tbl_plans', 'name_plan', '%' . $name . '%', 'type', 'Hotspot'); + $d = ORM::for_table('tbl_bandwidth')->join('tbl_plans', array('tbl_bandwidth.id', '=', 'tbl_plans.id_bw'))->where('tbl_plans.type', 'Hotspot')->where_like('tbl_plans.name_plan', '%' . $name . '%')->offset($paginator['startpoint'])->limit($paginator['limit'])->find_many(); + } else { + $paginator = Paginator::bootstrap('tbl_plans', 'type', 'Hotspot'); + $d = ORM::for_table('tbl_bandwidth')->join('tbl_plans', array('tbl_bandwidth.id', '=', 'tbl_plans.id_bw'))->where('tbl_plans.type', 'Hotspot')->offset($paginator['startpoint'])->limit($paginator['limit'])->find_many(); + } - $ui->assign('d',$d); - $ui->assign('paginator',$paginator); + $ui->assign('d', $d); + $ui->assign('paginator', $paginator); $ui->display('hotspot.tpl'); break; case 'add': - $d = ORM::for_table('tbl_bandwidth')->find_many(); - $ui->assign('d',$d); - $r = ORM::for_table('tbl_routers')->find_many(); - $ui->assign('r',$r); - + $d = ORM::for_table('tbl_bandwidth')->find_many(); + $ui->assign('d', $d); + $r = ORM::for_table('tbl_routers')->find_many(); + $ui->assign('r', $r); + $ui->display('hotspot-add.tpl'); break; case 'edit': $id = $routes['2']; $d = ORM::for_table('tbl_plans')->find_one($id); - if($d){ - $ui->assign('d',$d); - $b = ORM::for_table('tbl_bandwidth')->find_many(); - $ui->assign('b',$b); - $r = ORM::for_table('tbl_routers')->find_many(); - $ui->assign('r',$r); - + if ($d) { + $ui->assign('d', $d); + $b = ORM::for_table('tbl_bandwidth')->find_many(); + $ui->assign('b', $b); + $r = ORM::for_table('tbl_routers')->find_many(); + $ui->assign('r', $r); + $ui->display('hotspot-edit.tpl'); - }else{ + } else { r2(U . 'services/hotspot', 'e', $_L['Account_Not_Found']); } break; case 'delete': $id = $routes['2']; - + $d = ORM::for_table('tbl_plans')->find_one($id); - if($d){ - $mikrotik = Router::_info($d['routers']); - try { - $client = new RouterOS\Client($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); - } catch (Exception $e) { - die('Unable to connect to the router.'); - } - $printRequest = new RouterOS\Request( - '/ip hotspot user profile print .proplist=name', - RouterOS\Query::where('name', $d['name_plan']) - ); - $profileName = $client->sendSync($printRequest)->getProperty('name'); - - $removeRequest = new RouterOS\Request('/ip/hotspot/user/profile/remove'); - $client($removeRequest - ->setArgument('numbers', $profileName) + if ($d) { + $mikrotik = Router::_info($d['routers']); + try { + $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.
".$e->getMessage()); + } + $printRequest = new RouterOS\Request( + '/ip hotspot user profile print .proplist=name', + RouterOS\Query::where('name', $d['name_plan']) + ); + $profileName = $client->sendSync($printRequest)->getProperty('name'); + + $removeRequest = new RouterOS\Request('/ip/hotspot/user/profile/remove'); + $client( + $removeRequest + ->setArgument('numbers', $profileName) ); $d->delete(); - + r2(U . 'services/hotspot', 's', $_L['Delete_Successfully']); } break; @@ -96,224 +100,246 @@ switch ($action) { case 'add-post': $name = _post('name'); $typebp = _post('typebp'); - $limit_type = _post('limit_type'); - $time_limit = _post('time_limit'); - $time_unit = _post('time_unit'); - $data_limit = _post('data_limit'); - $data_unit = _post('data_unit'); - $id_bw = _post('id_bw'); - $price = _post('pricebp'); - $sharedusers = _post('sharedusers'); + $limit_type = _post('limit_type'); + $time_limit = _post('time_limit'); + $time_unit = _post('time_unit'); + $data_limit = _post('data_limit'); + $data_unit = _post('data_unit'); + $id_bw = _post('id_bw'); + $price = _post('pricebp'); + $sharedusers = _post('sharedusers'); $validity = _post('validity'); - $validity_unit = _post('validity_unit'); - $routers = _post('routers'); - + $validity_unit = _post('validity_unit'); + $routers = _post('routers'); + $msg = ''; - if(Validator::UnsignedNumber($validity) == false){ - $msg .= 'The validity must be a number'. '
'; + if (Validator::UnsignedNumber($validity) == false) { + $msg .= 'The validity must be a number' . '
'; } - if(Validator::UnsignedNumber($price) == false){ - $msg .= 'The price must be a number'. '
'; + if (Validator::UnsignedNumber($price) == false) { + $msg .= 'The price must be a number' . '
'; } - if ($name == '' OR $id_bw == '' OR $price == '' OR $validity == '' OR $routers == ''){ - $msg .= $_L['All_field_is_required']. '
'; - } - - $d = ORM::for_table('tbl_plans')->where('name_plan',$name)->where('type','Hotspot')->find_one(); - if($d){ - $msg .= $_L['Plan_already_exist']. '
'; + if ($name == '' or $id_bw == '' or $price == '' or $validity == '' or $routers == '') { + $msg .= $_L['All_field_is_required'] . '
'; } - if($msg == ''){ - $b = ORM::for_table('tbl_bandwidth')->where('id',$id_bw)->find_one(); - if($b['rate_down_unit'] == 'Kbps'){ $unitdown = 'K'; }else{ $unitdown = 'M'; } - if($b['rate_up_unit'] == 'Kbps'){ $unitup = 'K'; }else{ $unitup = 'M'; } - $rate = $b['rate_up'].$unitup."/".$b['rate_down'].$unitdown; + $d = ORM::for_table('tbl_plans')->where('name_plan', $name)->where('type', 'Hotspot')->find_one(); + if ($d) { + $msg .= $_L['Plan_already_exist'] . '
'; + } - $mikrotik = Router::_info($routers); - try { - $client = new RouterOS\Client($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); - } catch (Exception $e) { - die('Unable to connect to the router.'); - } - $addRequest = new RouterOS\Request('/ip/hotspot/user/profile/add'); - $client->sendSync($addRequest - ->setArgument('name', $name) - ->setArgument('shared-users', $sharedusers) - ->setArgument('rate-limit', $rate) + if ($msg == '') { + $b = ORM::for_table('tbl_bandwidth')->where('id', $id_bw)->find_one(); + if ($b['rate_down_unit'] == 'Kbps') { + $unitdown = 'K'; + } else { + $unitdown = 'M'; + } + if ($b['rate_up_unit'] == 'Kbps') { + $unitup = 'K'; + } else { + $unitup = 'M'; + } + $rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown; + + $mikrotik = Router::_info($routers); + try { + $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.
".$e->getMessage()); + } + $addRequest = new RouterOS\Request('/ip/hotspot/user/profile/add'); + $client->sendSync( + $addRequest + ->setArgument('name', $name) + ->setArgument('shared-users', $sharedusers) + ->setArgument('rate-limit', $rate) ); - + $d = ORM::for_table('tbl_plans')->create(); $d->name_plan = $name; $d->id_bw = $id_bw; $d->price = $price; - $d->type = 'Hotspot'; + $d->type = 'Hotspot'; $d->typebp = $typebp; - $d->limit_type = $limit_type; - $d->time_limit = $time_limit; - $d->time_unit = $time_unit; - $d->data_limit = $data_limit; - $d->data_unit = $data_unit; - $d->validity = $validity; + $d->limit_type = $limit_type; + $d->time_limit = $time_limit; + $d->time_unit = $time_unit; + $d->data_limit = $data_limit; + $d->data_unit = $data_unit; + $d->validity = $validity; $d->validity_unit = $validity_unit; - $d->shared_users = $sharedusers; - $d->routers = $routers; + $d->shared_users = $sharedusers; + $d->routers = $routers; $d->save(); - + r2(U . 'services/hotspot', 's', $_L['Created_Successfully']); - }else{ + } else { r2(U . 'services/add', 'e', $msg); } break; case 'edit-post': - $id = _post('id'); + $id = _post('id'); $name = _post('name'); $id_bw = _post('id_bw'); - $typebp = _post('typebp'); + $typebp = _post('typebp'); $price = _post('price'); - $limit_type = _post('limit_type'); - $time_limit = _post('time_limit'); - $time_unit = _post('time_unit'); - $data_limit = _post('data_limit'); - $data_unit = _post('data_unit'); - $sharedusers = _post('sharedusers'); + $limit_type = _post('limit_type'); + $time_limit = _post('time_limit'); + $time_unit = _post('time_unit'); + $data_limit = _post('data_limit'); + $data_unit = _post('data_unit'); + $sharedusers = _post('sharedusers'); $validity = _post('validity'); - $validity_unit = _post('validity_unit'); - $routers = _post('routers'); - + $validity_unit = _post('validity_unit'); + $routers = _post('routers'); + $msg = ''; - if(Validator::UnsignedNumber($validity) == false){ - $msg .= 'The validity must be a number'. '
'; + if (Validator::UnsignedNumber($validity) == false) { + $msg .= 'The validity must be a number' . '
'; } - if(Validator::UnsignedNumber($price) == false){ - $msg .= 'The price must be a number'. '
'; + if (Validator::UnsignedNumber($price) == false) { + $msg .= 'The price must be a number' . '
'; } - if ($name == '' OR $id_bw == '' OR $price == '' OR $validity == '' OR $routers == ''){ - $msg .= $_L['All_field_is_required']. '
'; - } - - $d = ORM::for_table('tbl_plans')->where('id',$id)->find_one(); - if($d){ - }else{ - $msg .= $_L['Data_Not_Found']. '
'; + if ($name == '' or $id_bw == '' or $price == '' or $validity == '' or $routers == '') { + $msg .= $_L['All_field_is_required'] . '
'; } - if($msg == ''){ - $b = ORM::for_table('tbl_bandwidth')->where('id',$id_bw)->find_one(); - if($b['rate_down_unit'] == 'Kbps'){ $unitdown = 'K'; }else{ $unitdown = 'M'; } - if($b['rate_up_unit'] == 'Kbps'){ $unitup = 'K'; }else{ $unitup = 'M'; } - $rate = $b['rate_up'].$unitup."/".$b['rate_down'].$unitdown; - - $mikrotik = Router::_info($routers); - try { - $client = new RouterOS\Client($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); - } catch (Exception $e) { - die('Unable to connect to the router.'); - } - $printRequest = new RouterOS\Request( - '/ip hotspot user profile print .proplist=name', - RouterOS\Query::where('name', $name) - ); - $profileName = $client->sendSync($printRequest)->getProperty('name'); - - $setRequest = new RouterOS\Request('/ip/hotspot/user/profile/set'); - $client($setRequest - ->setArgument('numbers', $profileName) - ->setArgument('shared-users', $sharedusers) - ->setArgument('rate-limit', $rate) + $d = ORM::for_table('tbl_plans')->where('id', $id)->find_one(); + if ($d) { + } else { + $msg .= $_L['Data_Not_Found'] . '
'; + } + + if ($msg == '') { + $b = ORM::for_table('tbl_bandwidth')->where('id', $id_bw)->find_one(); + if ($b['rate_down_unit'] == 'Kbps') { + $unitdown = 'K'; + } else { + $unitdown = 'M'; + } + if ($b['rate_up_unit'] == 'Kbps') { + $unitup = 'K'; + } else { + $unitup = 'M'; + } + $rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown; + + $mikrotik = Router::_info($routers); + try { + $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.
".$e->getMessage()); + } + $printRequest = new RouterOS\Request( + '/ip hotspot user profile print .proplist=name', + RouterOS\Query::where('name', $name) ); - + $profileName = $client->sendSync($printRequest)->getProperty('name'); + + $setRequest = new RouterOS\Request('/ip/hotspot/user/profile/set'); + $client( + $setRequest + ->setArgument('numbers', $profileName) + ->setArgument('shared-users', $sharedusers) + ->setArgument('rate-limit', $rate) + ); + $d->name_plan = $name; $d->id_bw = $id_bw; $d->price = $price; $d->typebp = $typebp; - $d->limit_type = $limit_type; - $d->time_limit = $time_limit; - $d->time_unit = $time_unit; - $d->data_limit = $data_limit; - $d->data_unit = $data_unit; - $d->validity = $validity; + $d->limit_type = $limit_type; + $d->time_limit = $time_limit; + $d->time_unit = $time_unit; + $d->data_limit = $data_limit; + $d->data_unit = $data_unit; + $d->validity = $validity; $d->validity_unit = $validity_unit; - $d->shared_users = $sharedusers; - $d->routers = $routers; + $d->shared_users = $sharedusers; + $d->routers = $routers; $d->save(); - + r2(U . 'services/hotspot', 's', $_L['Updated_Successfully']); - }else{ - r2(U . 'services/edit/'.$id, 'e', $msg); + } else { + r2(U . 'services/edit/' . $id, 'e', $msg); } break; - + case 'pppoe': - $ui->assign('xfooter', ''); - - $name = _post('name'); - if ($name != ''){ - $paginator = Paginator::bootstrap('tbl_plans','name_plan','%'.$name.'%','type','Hotspot'); - $d = ORM::for_table('tbl_bandwidth')->join('tbl_plans', array('tbl_bandwidth.id', '=', 'tbl_plans.id_bw'))->where('tbl_plans.type','PPPOE')->where_like('tbl_plans.name_plan','%'.$name.'%')->offset($paginator['startpoint'])->limit($paginator['limit'])->find_many(); - }else{ - $paginator = Paginator::bootstrap('tbl_plans','type','Hotspot'); - $d = ORM::for_table('tbl_bandwidth')->join('tbl_plans', array('tbl_bandwidth.id', '=', 'tbl_plans.id_bw'))->where('tbl_plans.type','PPPOE')->offset($paginator['startpoint'])->limit($paginator['limit'])->find_many(); - } - - $ui->assign('d',$d); - $ui->assign('paginator',$paginator); + $ui->assign('xfooter', ''); + + $name = _post('name'); + if ($name != '') { + $paginator = Paginator::bootstrap('tbl_plans', 'name_plan', '%' . $name . '%', 'type', 'Hotspot'); + $d = ORM::for_table('tbl_bandwidth')->join('tbl_plans', array('tbl_bandwidth.id', '=', 'tbl_plans.id_bw'))->where('tbl_plans.type', 'PPPOE')->where_like('tbl_plans.name_plan', '%' . $name . '%')->offset($paginator['startpoint'])->limit($paginator['limit'])->find_many(); + } else { + $paginator = Paginator::bootstrap('tbl_plans', 'type', 'Hotspot'); + $d = ORM::for_table('tbl_bandwidth')->join('tbl_plans', array('tbl_bandwidth.id', '=', 'tbl_plans.id_bw'))->where('tbl_plans.type', 'PPPOE')->offset($paginator['startpoint'])->limit($paginator['limit'])->find_many(); + } + + $ui->assign('d', $d); + $ui->assign('paginator', $paginator); $ui->display('pppoe.tpl'); break; case 'pppoe-add': - $d = ORM::for_table('tbl_bandwidth')->find_many(); - $ui->assign('d',$d); - $p = ORM::for_table('tbl_pool')->find_many(); - $ui->assign('p',$p); - $r = ORM::for_table('tbl_routers')->find_many(); - $ui->assign('r',$r); - + $d = ORM::for_table('tbl_bandwidth')->find_many(); + $ui->assign('d', $d); + $p = ORM::for_table('tbl_pool')->find_many(); + $ui->assign('p', $p); + $r = ORM::for_table('tbl_routers')->find_many(); + $ui->assign('r', $r); + $ui->display('pppoe-add.tpl'); break; case 'pppoe-edit': $id = $routes['2']; $d = ORM::for_table('tbl_plans')->find_one($id); - if($d){ - $ui->assign('d',$d); - $b = ORM::for_table('tbl_bandwidth')->find_many(); - $ui->assign('b',$b); - $p = ORM::for_table('tbl_pool')->find_many(); - $ui->assign('p',$p); - $r = ORM::for_table('tbl_routers')->find_many(); - $ui->assign('r',$r); - + if ($d) { + $ui->assign('d', $d); + $b = ORM::for_table('tbl_bandwidth')->find_many(); + $ui->assign('b', $b); + $p = ORM::for_table('tbl_pool')->find_many(); + $ui->assign('p', $p); + $r = ORM::for_table('tbl_routers')->find_many(); + $ui->assign('r', $r); + $ui->display('pppoe-edit.tpl'); - }else{ + } else { r2(U . 'services/pppoe', 'e', $_L['Account_Not_Found']); } break; case 'pppoe-delete': $id = $routes['2']; - + $d = ORM::for_table('tbl_plans')->find_one($id); - if($d){ - $mikrotik = Router::_info($d['routers']); - try { - $client = new RouterOS\Client($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); - } catch (Exception $e) { - die('Unable to connect to the router.'); - } - $printRequest = new RouterOS\Request( - '/ppp profile print .proplist=name', - RouterOS\Query::where('name', $d['name_plan']) - ); - $profileName = $client->sendSync($printRequest)->getProperty('name'); - - $removeRequest = new RouterOS\Request('/ppp/profile/remove'); - $client($removeRequest - ->setArgument('numbers', $profileName) + if ($d) { + $mikrotik = Router::_info($d['routers']); + try { + $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.
".$e->getMessage()); + } + $printRequest = new RouterOS\Request( + '/ppp profile print .proplist=name', + RouterOS\Query::where('name', $d['name_plan']) ); - + $profileName = $client->sendSync($printRequest)->getProperty('name'); + + $removeRequest = new RouterOS\Request('/ppp/profile/remove'); + $client( + $removeRequest + ->setArgument('numbers', $profileName) + ); + $d->delete(); r2(U . 'services/pppoe', 's', $_L['Delete_Successfully']); @@ -322,134 +348,154 @@ switch ($action) { case 'pppoe-add-post': $name = _post('name_plan'); - $id_bw = _post('id_bw'); - $price = _post('price'); + $id_bw = _post('id_bw'); + $price = _post('price'); $validity = _post('validity'); - $validity_unit = _post('validity_unit'); - $routers = _post('routers'); - $pool = _post('pool_name'); - + $validity_unit = _post('validity_unit'); + $routers = _post('routers'); + $pool = _post('pool_name'); + $msg = ''; - if(Validator::UnsignedNumber($validity) == false){ - $msg .= 'The validity must be a number'. '
'; + if (Validator::UnsignedNumber($validity) == false) { + $msg .= 'The validity must be a number' . '
'; } - if(Validator::UnsignedNumber($price) == false){ - $msg .= 'The price must be a number'. '
'; + if (Validator::UnsignedNumber($price) == false) { + $msg .= 'The price must be a number' . '
'; } - if ($name == '' OR $id_bw == '' OR $price == '' OR $validity == '' OR $routers == '' OR $pool == ''){ - $msg .= $_L['All_field_is_required']. '
'; - } - - $d = ORM::for_table('tbl_plans')->where('name_plan',$name)->find_one(); - if($d){ - $msg .= $_L['Plan_already_exist']. '
'; + if ($name == '' or $id_bw == '' or $price == '' or $validity == '' or $routers == '' or $pool == '') { + $msg .= $_L['All_field_is_required'] . '
'; } - if($msg == ''){ - $b = ORM::for_table('tbl_bandwidth')->where('id',$id_bw)->find_one(); - if($b['rate_down_unit'] == 'Kbps'){ $unitdown = 'K'; }else{ $unitdown = 'M'; } - if($b['rate_up_unit'] == 'Kbps'){ $unitup = 'K'; }else{ $unitup = 'M'; } - $rate = $b['rate_up'].$unitup."/".$b['rate_down'].$unitdown; - - $mikrotik = Router::_info($routers); - try { - $client = new RouterOS\Client($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); - } catch (Exception $e) { - die('Unable to connect to the router.'); - } - $addRequest = new RouterOS\Request('/ppp/profile/add'); - $client->sendSync($addRequest - ->setArgument('name', $name) - ->setArgument('local-address', $pool) - ->setArgument('remote-address', $pool) - ->setArgument('rate-limit', $rate) + $d = ORM::for_table('tbl_plans')->where('name_plan', $name)->find_one(); + if ($d) { + $msg .= $_L['Plan_already_exist'] . '
'; + } + + if ($msg == '') { + $b = ORM::for_table('tbl_bandwidth')->where('id', $id_bw)->find_one(); + if ($b['rate_down_unit'] == 'Kbps') { + $unitdown = 'K'; + } else { + $unitdown = 'M'; + } + if ($b['rate_up_unit'] == 'Kbps') { + $unitup = 'K'; + } else { + $unitup = 'M'; + } + $rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown; + + $mikrotik = Router::_info($routers); + try { + $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.
".$e->getMessage()); + } + $addRequest = new RouterOS\Request('/ppp/profile/add'); + $client->sendSync( + $addRequest + ->setArgument('name', $name) + ->setArgument('local-address', $pool) + ->setArgument('remote-address', $pool) + ->setArgument('rate-limit', $rate) ); - + $d = ORM::for_table('tbl_plans')->create(); $d->type = 'PPPOE'; - $d->name_plan = $name; + $d->name_plan = $name; $d->id_bw = $id_bw; $d->price = $price; - $d->validity = $validity; + $d->validity = $validity; $d->validity_unit = $validity_unit; - $d->routers = $routers; - $d->pool = $pool; + $d->routers = $routers; + $d->pool = $pool; $d->save(); r2(U . 'services/pppoe', 's', $_L['Created_Successfully']); - }else{ + } else { r2(U . 'services/pppoe-add', 'e', $msg); } break; case 'edit-pppoe-post': - $id = _post('id'); + $id = _post('id'); $name = _post('name_plan'); - $id_bw = _post('id_bw'); - $price = _post('price'); + $id_bw = _post('id_bw'); + $price = _post('price'); $validity = _post('validity'); - $validity_unit = _post('validity_unit'); - $routers = _post('routers'); - $pool = _post('pool_name'); - + $validity_unit = _post('validity_unit'); + $routers = _post('routers'); + $pool = _post('pool_name'); + $msg = ''; - if(Validator::UnsignedNumber($validity) == false){ - $msg .= 'The validity must be a number'. '
'; + if (Validator::UnsignedNumber($validity) == false) { + $msg .= 'The validity must be a number' . '
'; } - if(Validator::UnsignedNumber($price) == false){ - $msg .= 'The price must be a number'. '
'; + if (Validator::UnsignedNumber($price) == false) { + $msg .= 'The price must be a number' . '
'; } - if ($name == '' OR $id_bw == '' OR $price == '' OR $validity == '' OR $routers == '' OR $pool == ''){ - $msg .= $_L['All_field_is_required']. '
'; - } - - $d = ORM::for_table('tbl_plans')->where('id',$id)->find_one(); - if($d){ - }else{ - $msg .= $_L['Data_Not_Found']. '
'; + if ($name == '' or $id_bw == '' or $price == '' or $validity == '' or $routers == '' or $pool == '') { + $msg .= $_L['All_field_is_required'] . '
'; } - if($msg == ''){ - $b = ORM::for_table('tbl_bandwidth')->where('id',$id_bw)->find_one(); - if($b['rate_down_unit'] == 'Kbps'){ $unitdown = 'K'; }else{ $unitdown = 'M'; } - if($b['rate_up_unit'] == 'Kbps'){ $unitup = 'K'; }else{ $unitup = 'M'; } - $rate = $b['rate_up'].$unitup."/".$b['rate_down'].$unitdown; - - $mikrotik = Router::_info($routers); - try { - $client = new RouterOS\Client($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); - } catch (Exception $e) { - die('Unable to connect to the router.'); - } - $printRequest = new RouterOS\Request( - '/ppp profile print .proplist=name', - RouterOS\Query::where('name', $name) - ); - $profileName = $client->sendSync($printRequest)->getProperty('name'); - - $setRequest = new RouterOS\Request('/ppp/profile/set'); - $client($setRequest - ->setArgument('numbers', $profileName) - ->setArgument('local-address', $pool) - ->setArgument('remote-address', $pool) - ->setArgument('rate-limit', $rate) + $d = ORM::for_table('tbl_plans')->where('id', $id)->find_one(); + if ($d) { + } else { + $msg .= $_L['Data_Not_Found'] . '
'; + } + + if ($msg == '') { + $b = ORM::for_table('tbl_bandwidth')->where('id', $id_bw)->find_one(); + if ($b['rate_down_unit'] == 'Kbps') { + $unitdown = 'K'; + } else { + $unitdown = 'M'; + } + if ($b['rate_up_unit'] == 'Kbps') { + $unitup = 'K'; + } else { + $unitup = 'M'; + } + $rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown; + + $mikrotik = Router::_info($routers); + try { + $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.
".$e->getMessage()); + } + $printRequest = new RouterOS\Request( + '/ppp profile print .proplist=name', + RouterOS\Query::where('name', $name) ); - + $profileName = $client->sendSync($printRequest)->getProperty('name'); + + $setRequest = new RouterOS\Request('/ppp/profile/set'); + $client( + $setRequest + ->setArgument('numbers', $profileName) + ->setArgument('local-address', $pool) + ->setArgument('remote-address', $pool) + ->setArgument('rate-limit', $rate) + ); + $d->name_plan = $name; $d->id_bw = $id_bw; $d->price = $price; - $d->validity = $validity; + $d->validity = $validity; $d->validity_unit = $validity_unit; - $d->routers = $routers; - $d->pool = $pool; + $d->routers = $routers; + $d->pool = $pool; $d->save(); - + r2(U . 'services/pppoe', 's', $_L['Updated_Successfully']); - }else{ - r2(U . 'services/pppoe-edit/'.$id, 'e', $msg); + } else { + r2(U . 'services/pppoe-edit/' . $id, 'e', $msg); } break; - + default: echo 'action not defined'; -} \ No newline at end of file +} diff --git a/system/controllers/voucher.php b/system/controllers/voucher.php index 3ea24be5..b236f6d5 100644 --- a/system/controllers/voucher.php +++ b/system/controllers/voucher.php @@ -1,14 +1,15 @@ assign('_title', $_L['Voucher'].'- '. $config['CompanyName']); +$ui->assign('_title', $_L['Voucher'] . '- ' . $config['CompanyName']); $ui->assign('_system_menu', 'voucher'); $action = $routes['1']; @@ -16,335 +17,346 @@ $user = User::_info(); $ui->assign('_user', $user); use PEAR2\Net\RouterOS; + require_once 'system/autoload/PEAR2/Autoload.php'; switch ($action) { - + case 'activation': $ui->display('user-activation.tpl'); break; case 'activation-post': $code = _post('code'); - - $v1 = ORM::for_table('tbl_voucher')->where('code',$code)->where('status',0)->find_one(); - - $c = ORM::for_table('tbl_customers')->find_one($user['id']); - $p = ORM::for_table('tbl_plans')->find_one($v1['id_plan']); - $b = ORM::for_table('tbl_user_recharges')->where('customer_id',$user['id'])->find_one(); - - $date_now = date("Y-m-d H:i:s"); - $date_only = date("Y-m-d"); - $time = date("H:i:s"); - - $mikrotik = Router::_info($v1['routers']); - $date_exp = date("Y-m-d", mktime(0,0,0,date("m"),date("d") + $p['validity'],date("Y"))); - if ($v1){ - if($v1['type'] == 'Hotspot'){ - if($b){ - try { - $client = new RouterOS\Client($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); - } catch (Exception $e) { - die('Unable to connect to the router.'); - } - $printRequest = new RouterOS\Request('/ip/hotspot/user/print'); - $printRequest->setArgument('.proplist', '.id'); - $printRequest->setQuery(RouterOS\Query::where('name', $c['username'])); - $id = $client->sendSync($printRequest)->getProperty('.id'); - - $setRequest = new RouterOS\Request('/ip/hotspot/user/remove'); - $setRequest->setArgument('numbers', $id); - $client->sendSync($setRequest); - - /* iBNuX Added: + $v1 = ORM::for_table('tbl_voucher')->where('code', $code)->where('status', 0)->find_one(); + + $c = ORM::for_table('tbl_customers')->find_one($user['id']); + $p = ORM::for_table('tbl_plans')->find_one($v1['id_plan']); + $b = ORM::for_table('tbl_user_recharges')->where('customer_id', $user['id'])->find_one(); + + $date_now = date("Y-m-d H:i:s"); + $date_only = date("Y-m-d"); + $time = date("H:i:s"); + + $mikrotik = Router::_info($v1['routers']); + $date_exp = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") + $p['validity'], date("Y"))); + + if ($v1) { + if ($v1['type'] == 'Hotspot') { + if ($b) { + try { + $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.
".$e->getMessage()); + } + $printRequest = new RouterOS\Request('/ip/hotspot/user/print'); + $printRequest->setArgument('.proplist', '.id'); + $printRequest->setQuery(RouterOS\Query::where('name', $c['username'])); + $id = $client->sendSync($printRequest)->getProperty('.id'); + + $setRequest = new RouterOS\Request('/ip/hotspot/user/remove'); + $setRequest->setArgument('numbers', $id); + $client->sendSync($setRequest); + + /* iBNuX Added: * Time limit to Mikrotik * 'Time_Limit', 'Data_Limit', 'Both_Limit' */ - $addRequest = new RouterOS\Request('/ip/hotspot/user/add'); - if($p['typebp']=="Limited"){ - if($p['limit_type']=="Time_Limit"){ - if($p['time_unit']=='Hrs') - $timelimit = $p['time_limit'].":00:00"; - else - $timelimit = "00:".$p['time_limit'].":00"; - $client->sendSync($addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-uptime', $timelimit) - ); - }else if($p['limit_type']=="Data_Limit"){ - if($p['data_unit']=='GB') - $datalimit = $p['data_limit']."000000000"; - else - $datalimit = $p['data_limit']."000000"; - $client->sendSync($addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-bytes-total', $datalimit) - ); - }else if($p['limit_type']=="Both_Limit"){ - if($p['time_unit']=='Hrs') - $timelimit = $p['time_limit'].":00:00"; - else - $timelimit = "00:".$p['time_limit'].":00"; - if($p['data_unit']=='GB') - $datalimit = $p['data_limit']."000000000"; - else - $datalimit = $p['data_limit']."000000"; - $client->sendSync($addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-uptime', $timelimit) - ->setArgument('limit-bytes-total', $datalimit) - ); - } - }else{ - $client->sendSync($addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ); - } - - $b->customer_id = $user['id']; - $b->username = $c['username']; - $b->plan_id = $v1['id_plan']; - $b->namebp = $p['name_plan']; - $b->recharged_on = $date_only; - $b->expiration = $date_exp; - $b->time = $time; - $b->status = "on"; - $b->method = "voucher"; - $b->routers = $v1['routers']; - $b->type = "Hotspot"; - $b->save(); - - // insert table transactions - $t = ORM::for_table('tbl_transactions')->create(); - $t->invoice = "INV-"._raid(5); - $t->username = $c['username']; - $t->plan_name = $p['name_plan']; - $t->price = $p['price']; - $t->recharged_on = $date_only; - $t->expiration = $date_exp; - $t->time = $time; - $t->method = "voucher"; - $t->routers = $v1['routers']; - $t->type = "Hotspot"; - $t->save(); - - }else{ - try { - $client = new RouterOS\Client($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); - } catch (Exception $e) { - die('Unable to connect to the router.'); - } - /* iBNuX Added: + $addRequest = new RouterOS\Request('/ip/hotspot/user/add'); + if ($p['typebp'] == "Limited") { + if ($p['limit_type'] == "Time_Limit") { + if ($p['time_unit'] == 'Hrs') + $timelimit = $p['time_limit'] . ":00:00"; + else + $timelimit = "00:" . $p['time_limit'] . ":00"; + $client->sendSync( + $addRequest + ->setArgument('name', $c['username']) + ->setArgument('profile', $p['name_plan']) + ->setArgument('password', $c['password']) + ->setArgument('limit-uptime', $timelimit) + ); + } else if ($p['limit_type'] == "Data_Limit") { + if ($p['data_unit'] == 'GB') + $datalimit = $p['data_limit'] . "000000000"; + else + $datalimit = $p['data_limit'] . "000000"; + $client->sendSync( + $addRequest + ->setArgument('name', $c['username']) + ->setArgument('profile', $p['name_plan']) + ->setArgument('password', $c['password']) + ->setArgument('limit-bytes-total', $datalimit) + ); + } else if ($p['limit_type'] == "Both_Limit") { + if ($p['time_unit'] == 'Hrs') + $timelimit = $p['time_limit'] . ":00:00"; + else + $timelimit = "00:" . $p['time_limit'] . ":00"; + if ($p['data_unit'] == 'GB') + $datalimit = $p['data_limit'] . "000000000"; + else + $datalimit = $p['data_limit'] . "000000"; + $client->sendSync( + $addRequest + ->setArgument('name', $c['username']) + ->setArgument('profile', $p['name_plan']) + ->setArgument('password', $c['password']) + ->setArgument('limit-uptime', $timelimit) + ->setArgument('limit-bytes-total', $datalimit) + ); + } + } else { + $client->sendSync( + $addRequest + ->setArgument('name', $c['username']) + ->setArgument('profile', $p['name_plan']) + ->setArgument('password', $c['password']) + ); + } + + $b->customer_id = $user['id']; + $b->username = $c['username']; + $b->plan_id = $v1['id_plan']; + $b->namebp = $p['name_plan']; + $b->recharged_on = $date_only; + $b->expiration = $date_exp; + $b->time = $time; + $b->status = "on"; + $b->method = "voucher"; + $b->routers = $v1['routers']; + $b->type = "Hotspot"; + $b->save(); + + // insert table transactions + $t = ORM::for_table('tbl_transactions')->create(); + $t->invoice = "INV-" . _raid(5); + $t->username = $c['username']; + $t->plan_name = $p['name_plan']; + $t->price = $p['price']; + $t->recharged_on = $date_only; + $t->expiration = $date_exp; + $t->time = $time; + $t->method = "voucher"; + $t->routers = $v1['routers']; + $t->type = "Hotspot"; + $t->save(); + } else { + try { + $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.
".$e->getMessage()); + } + /* iBNuX Added: * Time limit to Mikrotik * 'Time_Limit', 'Data_Limit', 'Both_Limit' */ - $addRequest = new RouterOS\Request('/ip/hotspot/user/add'); - if($p['typebp']=="Limited"){ - if($p['limit_type']=="Time_Limit"){ - if($p['time_unit']=='Hrs') - $timelimit = $p['time_limit'].":00:00"; - else - $timelimit = "00:".$p['time_limit'].":00"; - $client->sendSync($addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-uptime', $timelimit) - ); - }else if($p['limit_type']=="Data_Limit"){ - if($p['data_unit']=='GB') - $datalimit = $p['data_limit']."000000000"; - else - $datalimit = $p['data_limit']."000000"; - $client->sendSync($addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-bytes-total', $datalimit) - ); - }else if($p['limit_type']=="Both_Limit"){ - if($p['time_unit']=='Hrs') - $timelimit = $p['time_limit'].":00:00"; - else - $timelimit = "00:".$p['time_limit'].":00"; - if($p['data_unit']=='GB') - $datalimit = $p['data_limit']."000000000"; - else - $datalimit = $p['data_limit']."000000"; - $client->sendSync($addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ->setArgument('limit-uptime', $timelimit) - ->setArgument('limit-bytes-total', $datalimit) - ); - } - }else{ - $client->sendSync($addRequest - ->setArgument('name', $c['username']) - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ); - } - - $d = ORM::for_table('tbl_user_recharges')->create(); - $d->customer_id = $user['id']; - $d->username = $c['username']; - $d->plan_id = $v1['id_plan']; - $d->namebp = $p['name_plan']; - $d->recharged_on = $date_only; - $d->expiration = $date_exp; - $d->time = $time; - $d->status = "on"; - $d->method = "voucher"; - $d->routers = $v1['routers']; - $d->type = "Hotspot"; - $d->save(); - - // insert table transactions - $t = ORM::for_table('tbl_transactions')->create(); - $t->invoice = "INV-"._raid(5); - $t->username = $c['username']; - $t->plan_name = $p['name_plan']; - $t->price = $p['price']; - $t->recharged_on = $date_only; - $t->expiration = $date_exp; - $t->time = $time; - $t->method = "voucher"; - $t->routers = $v1['routers']; - $t->type = "Hotspot"; - $t->save(); - - } - - $v1->status = "1"; - $v1->user = $c['username']; - $v1->save(); - - }else{ - if($b){ - try { - $client = new RouterOS\Client($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); - } catch (Exception $e) { - die('Unable to connect to the router.'); - } - $printRequest = new RouterOS\Request('/ppp/secret/print'); - $printRequest->setArgument('.proplist', '.id'); - $printRequest->setQuery(RouterOS\Query::where('name', $c['username'])); - $id = $client->sendSync($printRequest)->getProperty('.id'); - - $setRequest = new RouterOS\Request('/ppp/secret/remove'); - $setRequest->setArgument('numbers', $id); - $client->sendSync($setRequest); - - $addRequest = new RouterOS\Request('/ppp/secret/add'); - $client->sendSync($addRequest - ->setArgument('name', $c['username']) - ->setArgument('service', 'pppoe') - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ); - - $b->customer_id = $user['id']; - $b->username = $c['username']; - $b->plan_id = $v1['id_plan']; - $b->namebp = $p['name_plan']; - $b->recharged_on = $date_only; - $b->expiration = $date_exp; - $b->time = $time; - $b->status = "on"; - $b->method = "voucher"; - $b->routers = $v1['routers']; - $b->type = "PPPOE"; - $b->save(); - - // insert table transactions - $t = ORM::for_table('tbl_transactions')->create(); - $t->invoice = "INV-"._raid(5); - $t->username = $c['username']; - $t->plan_name = $p['name_plan']; - $t->price = $p['price']; - $t->recharged_on = $date_only; - $t->expiration = $date_exp; - $t->time = $time; - $t->method = "voucher"; - $t->routers = $v1['routers']; - $t->type = "PPPOE"; - $t->save(); - - }else{ - try { - $client = new RouterOS\Client($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); - } catch (Exception $e) { - die('Unable to connect to the router.'); - } - $addRequest = new RouterOS\Request('/ppp/secret/add'); - $client->sendSync($addRequest - ->setArgument('name', $c['username']) - ->setArgument('service', 'pppoe') - ->setArgument('profile', $p['name_plan']) - ->setArgument('password', $c['password']) - ); - - $d = ORM::for_table('tbl_user_recharges')->create(); - $d->customer_id = $user['id']; - $d->username = $c['username']; - $d->plan_id = $v1['id_plan']; - $d->namebp = $p['name_plan']; - $d->recharged_on = $date_only; - $d->expiration = $date_exp; - $d->time = $time; - $d->status = "on"; - $d->method = "voucher"; - $d->routers = $v1['routers']; - $d->type = "PPPOE"; - $d->save(); - - // insert table transactions - $t = ORM::for_table('tbl_transactions')->create(); - $t->invoice = "INV-"._raid(5); - $t->username = $c['username']; - $t->plan_name = $p['name_plan']; - $t->price = $p['price']; - $t->recharged_on = $date_only; - $t->expiration = $date_exp; - $t->time = $time; - $t->method = "voucher"; - $t->routers = $v1['routers']; - $t->type = "PPPOE"; - $t->save(); - } - - $v1->status = "1"; - $v1->user = $c['username']; - $v1->save(); - } - - r2(U."voucher/list-activated",'s',$_L['Activation_Vouchers_Successfully']); - }else{ - r2(U . 'voucher/activation', 'e', $_L['Voucher_Not_Valid']); - } + $addRequest = new RouterOS\Request('/ip/hotspot/user/add'); + if ($p['typebp'] == "Limited") { + if ($p['limit_type'] == "Time_Limit") { + if ($p['time_unit'] == 'Hrs') + $timelimit = $p['time_limit'] . ":00:00"; + else + $timelimit = "00:" . $p['time_limit'] . ":00"; + $client->sendSync( + $addRequest + ->setArgument('name', $c['username']) + ->setArgument('profile', $p['name_plan']) + ->setArgument('password', $c['password']) + ->setArgument('limit-uptime', $timelimit) + ); + } else if ($p['limit_type'] == "Data_Limit") { + if ($p['data_unit'] == 'GB') + $datalimit = $p['data_limit'] . "000000000"; + else + $datalimit = $p['data_limit'] . "000000"; + $client->sendSync( + $addRequest + ->setArgument('name', $c['username']) + ->setArgument('profile', $p['name_plan']) + ->setArgument('password', $c['password']) + ->setArgument('limit-bytes-total', $datalimit) + ); + } else if ($p['limit_type'] == "Both_Limit") { + if ($p['time_unit'] == 'Hrs') + $timelimit = $p['time_limit'] . ":00:00"; + else + $timelimit = "00:" . $p['time_limit'] . ":00"; + if ($p['data_unit'] == 'GB') + $datalimit = $p['data_limit'] . "000000000"; + else + $datalimit = $p['data_limit'] . "000000"; + $client->sendSync( + $addRequest + ->setArgument('name', $c['username']) + ->setArgument('profile', $p['name_plan']) + ->setArgument('password', $c['password']) + ->setArgument('limit-uptime', $timelimit) + ->setArgument('limit-bytes-total', $datalimit) + ); + } + } else { + $client->sendSync( + $addRequest + ->setArgument('name', $c['username']) + ->setArgument('profile', $p['name_plan']) + ->setArgument('password', $c['password']) + ); + } + + $d = ORM::for_table('tbl_user_recharges')->create(); + $d->customer_id = $user['id']; + $d->username = $c['username']; + $d->plan_id = $v1['id_plan']; + $d->namebp = $p['name_plan']; + $d->recharged_on = $date_only; + $d->expiration = $date_exp; + $d->time = $time; + $d->status = "on"; + $d->method = "voucher"; + $d->routers = $v1['routers']; + $d->type = "Hotspot"; + $d->save(); + + // insert table transactions + $t = ORM::for_table('tbl_transactions')->create(); + $t->invoice = "INV-" . _raid(5); + $t->username = $c['username']; + $t->plan_name = $p['name_plan']; + $t->price = $p['price']; + $t->recharged_on = $date_only; + $t->expiration = $date_exp; + $t->time = $time; + $t->method = "voucher"; + $t->routers = $v1['routers']; + $t->type = "Hotspot"; + $t->save(); + } + + $v1->status = "1"; + $v1->user = $c['username']; + $v1->save(); + } else { + if ($b) { + try { + $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.
".$e->getMessage()); + } + $printRequest = new RouterOS\Request('/ppp/secret/print'); + $printRequest->setArgument('.proplist', '.id'); + $printRequest->setQuery(RouterOS\Query::where('name', $c['username'])); + $id = $client->sendSync($printRequest)->getProperty('.id'); + + $setRequest = new RouterOS\Request('/ppp/secret/remove'); + $setRequest->setArgument('numbers', $id); + $client->sendSync($setRequest); + + $addRequest = new RouterOS\Request('/ppp/secret/add'); + $client->sendSync( + $addRequest + ->setArgument('name', $c['username']) + ->setArgument('service', 'pppoe') + ->setArgument('profile', $p['name_plan']) + ->setArgument('password', $c['password']) + ); + + $b->customer_id = $user['id']; + $b->username = $c['username']; + $b->plan_id = $v1['id_plan']; + $b->namebp = $p['name_plan']; + $b->recharged_on = $date_only; + $b->expiration = $date_exp; + $b->time = $time; + $b->status = "on"; + $b->method = "voucher"; + $b->routers = $v1['routers']; + $b->type = "PPPOE"; + $b->save(); + + // insert table transactions + $t = ORM::for_table('tbl_transactions')->create(); + $t->invoice = "INV-" . _raid(5); + $t->username = $c['username']; + $t->plan_name = $p['name_plan']; + $t->price = $p['price']; + $t->recharged_on = $date_only; + $t->expiration = $date_exp; + $t->time = $time; + $t->method = "voucher"; + $t->routers = $v1['routers']; + $t->type = "PPPOE"; + $t->save(); + } else { + try { + $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.
".$e->getMessage()); + } + $addRequest = new RouterOS\Request('/ppp/secret/add'); + $client->sendSync( + $addRequest + ->setArgument('name', $c['username']) + ->setArgument('service', 'pppoe') + ->setArgument('profile', $p['name_plan']) + ->setArgument('password', $c['password']) + ); + + $d = ORM::for_table('tbl_user_recharges')->create(); + $d->customer_id = $user['id']; + $d->username = $c['username']; + $d->plan_id = $v1['id_plan']; + $d->namebp = $p['name_plan']; + $d->recharged_on = $date_only; + $d->expiration = $date_exp; + $d->time = $time; + $d->status = "on"; + $d->method = "voucher"; + $d->routers = $v1['routers']; + $d->type = "PPPOE"; + $d->save(); + + // insert table transactions + $t = ORM::for_table('tbl_transactions')->create(); + $t->invoice = "INV-" . _raid(5); + $t->username = $c['username']; + $t->plan_name = $p['name_plan']; + $t->price = $p['price']; + $t->recharged_on = $date_only; + $t->expiration = $date_exp; + $t->time = $time; + $t->method = "voucher"; + $t->routers = $v1['routers']; + $t->type = "PPPOE"; + $t->save(); + } + + $v1->status = "1"; + $v1->user = $c['username']; + $v1->save(); + } + + r2(U . "voucher/list-activated", 's', $_L['Activation_Vouchers_Successfully']); + } else { + r2(U . 'voucher/activation', 'e', $_L['Voucher_Not_Valid']); + } break; case 'list-activated': - $paginator = Paginator::bootstrap('tbl_transactions','username',$user['username']); - $d = ORM::for_table('tbl_transactions')->where('username',$user['username'])->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); - - $ui->assign('d',$d); - $ui->assign('paginator',$paginator); - $ui->display('user-activation-list.tpl'); + $paginator = Paginator::bootstrap('tbl_transactions', 'username', $user['username']); + $d = ORM::for_table('tbl_transactions')->where('username', $user['username'])->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); + + $ui->assign('d', $d); + $ui->assign('paginator', $paginator); + $ui->display('user-activation-list.tpl'); break; default: $ui->display('404.tpl'); -} \ No newline at end of file +} diff --git a/system/cron.php b/system/cron.php index 77addbcd..411dfa4d 100644 --- a/system/cron.php +++ b/system/cron.php @@ -40,9 +40,10 @@ foreach ($d as $ds){ $m = ORM::for_table('tbl_routers')->where('name',$ds['routers'])->find_one(); try { - $client = new RouterOS\Client($m['ip_address'], $m['username'], $m['password']); + $iport = explode(":",$m['ip_address']); + $client = new RouterOS\Client($iport[0], $m['username'], $m['password'],($iport[1])?$iport[1]:null); } catch (Exception $e) { - die('Unable to connect to the router.'); + die("Unable to connect to the router.
".$e->getMessage()); } $printRequest = new RouterOS\Request('/ip/hotspot/user/print'); @@ -81,9 +82,10 @@ foreach ($d as $ds){ $m = ORM::for_table('tbl_routers')->where('name',$ds['routers'])->find_one(); try { - $client = new RouterOS\Client($m['ip_address'], $m['username'], $m['password']); + $iport = explode(":",$m['ip_address']); + $client = new RouterOS\Client($iport[0], $m['username'], $m['password'],($iport[1])?$iport[1]:null); } catch (Exception $e) { - die('Unable to connect to the router.'); + die("Unable to connect to the router.
".$e->getMessage()); } $printRequest = new RouterOS\Request('/ppp/secret/print'); $printRequest->setArgument('.proplist', '.id'); diff --git a/ui/theme/default/routers-add.tpl b/ui/theme/default/routers-add.tpl index 11d236bb..7a6f3b03 100644 --- a/ui/theme/default/routers-add.tpl +++ b/ui/theme/default/routers-add.tpl @@ -5,8 +5,8 @@
{$_L['Add_Router']}
- -
+ +
@@ -16,7 +16,7 @@
- +
@@ -37,7 +37,7 @@
- +
@@ -46,7 +46,7 @@
- +
diff --git a/ui/theme/default/routers-edit.tpl b/ui/theme/default/routers-edit.tpl index 6ae9d139..754c755d 100644 --- a/ui/theme/default/routers-edit.tpl +++ b/ui/theme/default/routers-edit.tpl @@ -6,8 +6,8 @@
{$_L['Edit_Router']}
-
- + +
@@ -17,7 +17,7 @@
- +
@@ -38,7 +38,7 @@
- +
@@ -46,7 +46,7 @@
- +