forked from kevinowino869/mitrobill
PHPMixBill v5.0 - First Upload
This commit is contained in:
183
system/controllers/accounts.php
Normal file
183
system/controllers/accounts.php
Normal file
@ -0,0 +1,183 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Mikrotik Billing (www.phpmixbill.com)
|
||||
* Ismail Marzuqi <iesien22@yahoo.com>
|
||||
* @version 5.0
|
||||
* @copyright Copyright (C) 2014-2015 PHP Mikrotik Billing
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
* @donate PayPal: iesien22@yahoo.com / Bank Mandiri: 130.00.1024957.4
|
||||
**/
|
||||
_auth();
|
||||
$ui->assign('_title', $_L['My_Account'].'- '. $config['CompanyName']);
|
||||
$ui->assign('_system_menu', 'accounts');
|
||||
|
||||
$action = $routes['1'];
|
||||
$user = User::_info();
|
||||
$ui->assign('_user', $user);
|
||||
|
||||
use PEAR2\Net\RouterOS;
|
||||
require_once 'system/autoload/PEAR2/Autoload.php';
|
||||
|
||||
switch ($action) {
|
||||
|
||||
case 'change-password':
|
||||
$ui->display('user-change-password.tpl');
|
||||
break;
|
||||
|
||||
case 'change-password-post':
|
||||
$password = _post('password');
|
||||
if($password != ''){
|
||||
$d = ORM::for_table('tbl_customers')->where('username',$user['username'])->find_one();
|
||||
if($d){
|
||||
$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');
|
||||
}
|
||||
if($npass != $cnpass){
|
||||
r2(U.'accounts/change-password','e','Both Password should be same');
|
||||
}
|
||||
|
||||
$c = ORM::for_table('tbl_user_recharges')->where('username',$user['username'])->find_one();
|
||||
if ($c){
|
||||
$mikrotik = Router::_info($c['routers']);
|
||||
if($c['type'] == 'Hotspot'){
|
||||
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', $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');
|
||||
$onlineRequest->setQuery(RouterOS\Query::where('user', $user['username']));
|
||||
$id = $client->sendSync($onlineRequest)->getProperty('.id');
|
||||
|
||||
$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']);
|
||||
} 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', $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');
|
||||
$onlineRequest->setQuery(RouterOS\Query::where('name', $user['username']));
|
||||
$id = $client->sendSync($onlineRequest)->getProperty('.id');
|
||||
|
||||
$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']);
|
||||
}
|
||||
}else{
|
||||
r2(U.'accounts/change-password','e',$_L['Incorrect_Current_Password']);
|
||||
}
|
||||
}else{
|
||||
r2(U.'accounts/change-password','e',$_L['Incorrect_Current_Password']);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'profile':
|
||||
|
||||
$id = $_SESSION['uid'];
|
||||
$d = ORM::for_table('tbl_customers')->find_one($id);
|
||||
if($d){
|
||||
$ui->assign('d',$d);
|
||||
$ui->display('user-profile.tpl');
|
||||
}else{
|
||||
r2(U . 'accounts/users', 'e', $_L['Account_Not_Found']);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'edit-profile-post':
|
||||
$fullname = _post('fullname');
|
||||
$address = _post('address');
|
||||
$phonenumber = _post('phonenumber');
|
||||
|
||||
$msg = '';
|
||||
if(Validator::Length($fullname,31,2) == false){
|
||||
$msg .= 'Full Name should be between 3 to 30 characters'. '<br>';
|
||||
}
|
||||
if(Validator::UnsignedNumber($phonenumber) == false){
|
||||
$msg .= 'Phone Number must be a number'. '<br>';
|
||||
}
|
||||
|
||||
$id = _post('id');
|
||||
$d = ORM::for_table('tbl_customers')->find_one($id);
|
||||
if($d){
|
||||
}else{
|
||||
$msg .= $_L['Data_Not_Found']. '<br>';
|
||||
}
|
||||
|
||||
if($msg == ''){
|
||||
$d->fullname = $fullname;
|
||||
$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';
|
||||
}
|
54
system/controllers/admin.php
Normal file
54
system/controllers/admin.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Mikrotik Billing (www.phpmixbill.com)
|
||||
* Ismail Marzuqi <iesien22@yahoo.com>
|
||||
* @version 5.0
|
||||
* @copyright Copyright (C) 2014-2015 PHP Mikrotik Billing
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
* @donate PayPal: iesien22@yahoo.com / Bank Mandiri: 130.00.1024957.4
|
||||
**/
|
||||
if (isset($routes['1'])) {
|
||||
$do = $routes['1'];
|
||||
} else {
|
||||
$do = 'login-display';
|
||||
}
|
||||
|
||||
switch($do){
|
||||
case 'post':
|
||||
$username = _post('username');
|
||||
$password = _post('password');
|
||||
if($username != '' AND $password != ''){
|
||||
$d = ORM::for_table('tbl_users')->where('username',$username)->find_one();
|
||||
if($d){
|
||||
$d_pass = $d['password'];
|
||||
if(Password::_verify($password,$d_pass) == true){
|
||||
$_SESSION['aid'] = $d['id'];
|
||||
$d->last_login = date('Y-m-d H:i:s');
|
||||
$d->save();
|
||||
_log($username .' '. $_L['Login_Successful'],'Admin',$d['id']);
|
||||
r2(U.'dashboard');
|
||||
}else{
|
||||
_msglog('e',$_L['Invalid_Username_or_Password']);
|
||||
_log($username .' '. $_L['Failed_Login'],'Admin');
|
||||
r2(U.'admin');
|
||||
}
|
||||
}else{
|
||||
_msglog('e',$_L['Invalid_Username_or_Password']);
|
||||
r2(U.'admin');
|
||||
}
|
||||
}else{
|
||||
_msglog('e',$_L['Invalid_Username_or_Password']);
|
||||
r2(U.'admin');
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'login-display':
|
||||
$ui->display('admin.tpl');
|
||||
break;
|
||||
|
||||
default:
|
||||
$ui->display('admin.tpl');
|
||||
break;
|
||||
}
|
||||
|
45
system/controllers/autoload.php
Normal file
45
system/controllers/autoload.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Mikrotik Billing (www.phpmixbill.com)
|
||||
* Ismail Marzuqi <iesien22@yahoo.com>
|
||||
* @version 5.0
|
||||
* @copyright Copyright (C) 2014-2015 PHP Mikrotik Billing
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
* @donate PayPal: iesien22@yahoo.com / Bank Mandiri: 130.00.1024957.4
|
||||
**/
|
||||
_admin();
|
||||
$ui->assign('_title', $_L['Network'].' - '. $config['CompanyName']);
|
||||
$ui->assign('_system_menu', 'network');
|
||||
|
||||
$action = $routes['1'];
|
||||
$admin = Admin::_info();
|
||||
$ui->assign('_admin', $admin);
|
||||
|
||||
switch ($action) {
|
||||
case 'pool':
|
||||
$routers = _get('routers');
|
||||
$d = ORM::for_table('tbl_pool')->where('routers', $routers)->find_many();
|
||||
$ui->assign('d',$d);
|
||||
|
||||
$ui->display('autoload-pool.tpl');
|
||||
break;
|
||||
|
||||
case 'server':
|
||||
$d = ORM::for_table('tbl_routers')->find_many();
|
||||
$ui->assign('d',$d);
|
||||
|
||||
$ui->display('autoload-server.tpl');
|
||||
break;
|
||||
|
||||
case 'plan':
|
||||
$server = _post('server');
|
||||
$jenis = _post('jenis');
|
||||
$d = ORM::for_table('tbl_plans')->where('routers', $server)->where('type', $jenis)->find_many();
|
||||
$ui->assign('d',$d);
|
||||
|
||||
$ui->display('autoload.tpl');
|
||||
break;
|
||||
|
||||
default:
|
||||
echo 'action not defined';
|
||||
}
|
141
system/controllers/bandwidth.php
Normal file
141
system/controllers/bandwidth.php
Normal file
@ -0,0 +1,141 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Mikrotik Billing (www.phpmixbill.com)
|
||||
* Ismail Marzuqi <iesien22@yahoo.com>
|
||||
* @version 5.0
|
||||
* @copyright Copyright (C) 2014-2015 PHP Mikrotik Billing
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
* @donate PayPal: iesien22@yahoo.com / Bank Mandiri: 130.00.1024957.4
|
||||
**/
|
||||
_admin();
|
||||
$ui->assign('_title', $_L['Bandwidth_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']);
|
||||
}
|
||||
|
||||
switch ($action) {
|
||||
case 'list':
|
||||
$ui->assign('xfooter', '<script type="text/javascript" src="ui/lib/c/bandwidth.js"></script>');
|
||||
|
||||
$name = _post('name');
|
||||
if ($name != ''){
|
||||
$paginator = Paginator::bootstrap('tbl_bandwidth','name_bw','%'.$name.'%');
|
||||
$d = ORM::for_table('tbl_bandwidth')->where_like('name_bw','%'.$name.'%')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many();
|
||||
}else{
|
||||
$paginator = Paginator::bootstrap('tbl_bandwidth');
|
||||
$d = ORM::for_table('tbl_bandwidth')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many();
|
||||
}
|
||||
|
||||
$ui->assign('d',$d);
|
||||
$ui->assign('paginator',$paginator);
|
||||
$ui->display('bandwidth.tpl');
|
||||
break;
|
||||
|
||||
case 'add':
|
||||
$ui->display('bandwidth-add.tpl');
|
||||
break;
|
||||
|
||||
case 'edit':
|
||||
$id = $routes['2'];
|
||||
$d = ORM::for_table('tbl_bandwidth')->find_one($id);
|
||||
if($d){
|
||||
$ui->assign('d',$d);
|
||||
$ui->display('bandwidth-edit.tpl');
|
||||
}else{
|
||||
r2(U . 'bandwidth/list', 'e', $_L['Account_Not_Found']);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
$id = $routes['2'];
|
||||
$d = ORM::for_table('tbl_bandwidth')->find_one($id);
|
||||
if($d){
|
||||
$d->delete();
|
||||
r2(U . 'bandwidth/list', 's', $_L['Delete_Successfully']);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'add-post':
|
||||
$name = _post('name');
|
||||
$rate_down = _post('rate_down');
|
||||
$rate_down_unit = _post('rate_down_unit');
|
||||
$rate_up = _post('rate_up');
|
||||
$rate_up_unit = _post('rate_up_unit');
|
||||
|
||||
$msg = '';
|
||||
if(Validator::Length($name,16,4) == false){
|
||||
$msg .= 'Name should be between 5 to 15 characters'. '<br>';
|
||||
}
|
||||
|
||||
if($rate_down_unit == 'Kbps'){ $unit_rate_down = $rate_down * 1024; }else{ $unit_rate_down = $rate_down * 1048576; }
|
||||
if($rate_up_unit == 'Kbps'){ $unit_rate_up = $min_up * 1024; }else{ $unit_rate_up = $min_up * 1048576; }
|
||||
|
||||
$d = ORM::for_table('tbl_bandwidth')->where('name_bw',$name)->find_one();
|
||||
if($d){
|
||||
$msg .= $_L['BW_already_exist']. '<br>';
|
||||
}
|
||||
|
||||
if($msg == ''){
|
||||
$d = ORM::for_table('tbl_bandwidth')->create();
|
||||
$d->name_bw = $name;
|
||||
$d->rate_down = $rate_down;
|
||||
$d->rate_down_unit = $rate_down_unit;
|
||||
$d->rate_up = $rate_up;
|
||||
$d->rate_up_unit = $rate_up_unit;
|
||||
$d->save();
|
||||
|
||||
r2(U . 'bandwidth/list', 's', $_L['Created_Successfully']);
|
||||
}else{
|
||||
r2(U . 'bandwidth/add', 'e', $msg);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'edit-post':
|
||||
$name = _post('name');
|
||||
$rate_down = _post('rate_down');
|
||||
$rate_down_unit = _post('rate_down_unit');
|
||||
$rate_up = _post('rate_up');
|
||||
$rate_up_unit = _post('rate_up_unit');
|
||||
|
||||
$msg = '';
|
||||
if(Validator::Length($name,16,4) == false){
|
||||
$msg .= 'Name should be between 5 to 15 characters'. '<br>';
|
||||
}
|
||||
|
||||
$id = _post('id');
|
||||
$d = ORM::for_table('tbl_bandwidth')->find_one($id);
|
||||
if($d){
|
||||
}else{
|
||||
$msg .= $_L['Data_Not_Found']. '<br>';
|
||||
}
|
||||
|
||||
if($d['name_bw'] != $name){
|
||||
$c = ORM::for_table('tbl_bandwidth')->where('name_bw',$name)->find_one();
|
||||
if($c){
|
||||
$msg .= $_L['BW_already_exist']. '<br>';
|
||||
}
|
||||
}
|
||||
|
||||
if($msg == ''){
|
||||
$d->name_bw = $name;
|
||||
$d->rate_down = $rate_down;
|
||||
$d->rate_down_unit = $rate_down_unit;
|
||||
$d->rate_up = $rate_up;
|
||||
$d->rate_up_unit = $rate_up_unit;
|
||||
$d->save();
|
||||
|
||||
r2(U . 'bandwidth/list', 's', $_L['Updated_Successfully']);
|
||||
}else{
|
||||
r2(U . 'bandwidth/edit/'.$id, 'e', $msg);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
echo 'action not defined';
|
||||
}
|
297
system/controllers/customers.php
Normal file
297
system/controllers/customers.php
Normal file
@ -0,0 +1,297 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Mikrotik Billing (www.phpmixbill.com)
|
||||
* Ismail Marzuqi <iesien22@yahoo.com>
|
||||
* @version 5.0
|
||||
* @copyright Copyright (C) 2014-2015 PHP Mikrotik Billing
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
* @donate PayPal: iesien22@yahoo.com / Bank Mandiri: 130.00.1024957.4
|
||||
**/
|
||||
_admin();
|
||||
$ui->assign('_title', $_L['Customers'].' - '. $config['CompanyName']);
|
||||
$ui->assign('_system_menu', 'customers');
|
||||
|
||||
$action = $routes['1'];
|
||||
$admin = Admin::_info();
|
||||
$ui->assign('_admin', $admin);
|
||||
|
||||
use PEAR2\Net\RouterOS;
|
||||
require_once 'system/autoload/PEAR2/Autoload.php';
|
||||
|
||||
if($admin['user_type'] != 'Admin' AND $admin['user_type'] != 'Sales'){
|
||||
r2(U."dashboard",'e',$_L['Do_Not_Access']);
|
||||
}
|
||||
|
||||
switch ($action) {
|
||||
case 'list':
|
||||
$ui->assign('xfooter', '<script type="text/javascript" src="ui/lib/c/customers.js"></script>');
|
||||
$username = _post('username');
|
||||
if ($username != ''){
|
||||
$paginator = Paginator::bootstrap('tbl_customers','username','%'.$username.'%');
|
||||
$d = ORM::for_table('tbl_customers')->where_like('username','%'.$username.'%')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many();
|
||||
}else{
|
||||
$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');
|
||||
break;
|
||||
|
||||
case 'add':
|
||||
$ui->display('customers-add.tpl');
|
||||
break;
|
||||
|
||||
case 'edit':
|
||||
$id = $routes['2'];
|
||||
$d = ORM::for_table('tbl_customers')->find_one($id);
|
||||
if($d){
|
||||
$ui->assign('d',$d);
|
||||
$ui->display('customers-edit.tpl');
|
||||
}else{
|
||||
r2(U . 'customers/list', 'e', $_L['Account_Not_Found']);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
$id = $routes['2'];
|
||||
|
||||
$d = ORM::for_table('tbl_customers')->find_one($id);
|
||||
if($d){
|
||||
$c = ORM::for_table('tbl_user_recharges')->where('username',$d['username'])->find_one();
|
||||
if ($c){
|
||||
$mikrotik = Router::_info($c['routers']);
|
||||
if($c['type'] == 'Hotspot'){
|
||||
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);
|
||||
|
||||
//remove hotspot active
|
||||
$onlineRequest = new RouterOS\Request('/ip/hotspot/active/print');
|
||||
$onlineRequest->setArgument('.proplist', '.id');
|
||||
$onlineRequest->setQuery(RouterOS\Query::where('user', $c['username']));
|
||||
$id = $client->sendSync($onlineRequest)->getProperty('.id');
|
||||
|
||||
$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']);
|
||||
} 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);
|
||||
|
||||
//remove pppoe active
|
||||
$onlineRequest = new RouterOS\Request('/ppp/active/print');
|
||||
$onlineRequest->setArgument('.proplist', '.id');
|
||||
$onlineRequest->setQuery(RouterOS\Query::where('name', $c['username']));
|
||||
$id = $client->sendSync($onlineRequest)->getProperty('.id');
|
||||
|
||||
$removeRequest = new RouterOS\Request('/ppp/active/remove');
|
||||
$removeRequest->setArgument('numbers', $id);
|
||||
$client->sendSync($removeRequest);
|
||||
}
|
||||
$d->delete();
|
||||
$c->delete();
|
||||
}else{
|
||||
$d->delete();
|
||||
$c->delete();
|
||||
}
|
||||
|
||||
r2(U . 'customers/list', 's', $_L['User_Delete_Ok']);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'add-post':
|
||||
$username = _post('username');
|
||||
$fullname = _post('fullname');
|
||||
$password = _post('password');
|
||||
$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'. '<br>';
|
||||
}
|
||||
if(Validator::Length($fullname,36,2) == false){
|
||||
$msg .= 'Full Name should be between 3 to 25 characters'. '<br>';
|
||||
}
|
||||
if(!Validator::Length($password,35,2)){
|
||||
$msg .= 'Password should be between 3 to 35 characters'. '<br>';
|
||||
|
||||
}
|
||||
if($password != $cpassword){
|
||||
$msg .= 'Passwords does not match'. '<br>';
|
||||
}
|
||||
|
||||
$d = ORM::for_table('tbl_customers')->where('username',$username)->find_one();
|
||||
if($d){
|
||||
$msg .= $_L['account_already_exist']. '<br>';
|
||||
}
|
||||
|
||||
if($msg == ''){
|
||||
$d = ORM::for_table('tbl_customers')->create();
|
||||
$d->username = $username;
|
||||
$d->password = $password;
|
||||
$d->fullname = $fullname;
|
||||
$d->address = $address;
|
||||
$d->phonenumber = $phonenumber;
|
||||
$d->save();
|
||||
r2(U . 'customers/list', 's', $_L['account_created_successfully']);
|
||||
}else{
|
||||
r2(U . 'customers/add', 'e', $msg);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'edit-post':
|
||||
$username = _post('username');
|
||||
$fullname = _post('fullname');
|
||||
$password = _post('password');
|
||||
$cpassword = _post('cpassword');
|
||||
$address = _post('address');
|
||||
$phonenumber = _post('phonenumber');
|
||||
|
||||
$msg = '';
|
||||
if(Validator::Length($username,16,2) == false){
|
||||
$msg .= 'Username should be between 3 to 15 characters'. '<br>';
|
||||
}
|
||||
if(Validator::Length($fullname,26,2) == false){
|
||||
$msg .= 'Full Name should be between 3 to 25 characters'. '<br>';
|
||||
}
|
||||
if($password != ''){
|
||||
if(!Validator::Length($password,15,2)){
|
||||
$msg .= 'Password should be between 3 to 15 characters'. '<br>';
|
||||
|
||||
}
|
||||
if($password != $cpassword){
|
||||
$msg .= 'Passwords does not match'. '<br>';
|
||||
}
|
||||
}
|
||||
|
||||
$id = _post('id');
|
||||
$d = ORM::for_table('tbl_customers')->find_one($id);
|
||||
if($d){
|
||||
|
||||
}else{
|
||||
$msg .= $_L['Data_Not_Found']. '<br>';
|
||||
}
|
||||
|
||||
if($d['username'] != $username){
|
||||
$c = ORM::for_table('tbl_customers')->where('username',$username)->find_one();
|
||||
if($c){
|
||||
$msg .= $_L['account_already_exist']. '<br>';
|
||||
}
|
||||
}
|
||||
|
||||
if($msg == ''){
|
||||
$c = ORM::for_table('tbl_user_recharges')->where('username',$username)->find_one();
|
||||
if ($c){
|
||||
$mikrotik = Router::_info($c['routers']);
|
||||
if($c['type'] == 'Hotspot'){
|
||||
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/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');
|
||||
$onlineRequest->setQuery(RouterOS\Query::where('user', $c['username']));
|
||||
$id = $client->sendSync($onlineRequest)->getProperty('.id');
|
||||
|
||||
$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']);
|
||||
} 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/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');
|
||||
$onlineRequest->setQuery(RouterOS\Query::where('name', $c['username']));
|
||||
$id = $client->sendSync($onlineRequest)->getProperty('.id');
|
||||
|
||||
$removeRequest = new RouterOS\Request('/ppp/active/remove');
|
||||
$removeRequest->setArgument('numbers', $id);
|
||||
$client->sendSync($removeRequest);
|
||||
|
||||
$d->password = $password;
|
||||
$d->save();
|
||||
}
|
||||
$d->username = $username;
|
||||
if($password != ''){
|
||||
$d->password = $password;
|
||||
}
|
||||
$d->fullname = $fullname;
|
||||
$d->address = $address;
|
||||
$d->phonenumber = $phonenumber;
|
||||
$d->save();
|
||||
}else{
|
||||
$d->username = $username;
|
||||
if($password != ''){
|
||||
$d->password = $password;
|
||||
}
|
||||
$d->fullname = $fullname;
|
||||
$d->address = $address;
|
||||
$d->phonenumber = $phonenumber;
|
||||
$d->save();
|
||||
}
|
||||
r2(U . 'customers/list', 's', 'User Updated Successfully');
|
||||
}else{
|
||||
r2(U . 'customers/edit/'.$id, 'e', $msg);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
echo 'action not defined';
|
||||
}
|
59
system/controllers/dashboard.php
Normal file
59
system/controllers/dashboard.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Mikrotik Billing (www.phpmixbill.com)
|
||||
* Ismail Marzuqi <iesien22@yahoo.com>
|
||||
* @version 5.0
|
||||
* @copyright Copyright (C) 2014-2015 PHP Mikrotik Billing
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
* @donate PayPal: iesien22@yahoo.com / Bank Mandiri: 130.00.1024957.4
|
||||
**/
|
||||
_admin();
|
||||
$ui->assign('_title', $_L['Dashboard'].' - '. $config['CompanyName']);
|
||||
$admin = Admin::_info();
|
||||
$ui->assign('_admin', $admin);
|
||||
|
||||
if($admin['user_type'] != 'Admin' AND $admin['user_type'] != 'Sales'){
|
||||
r2(U."home",'e',$_L['Do_Not_Access']);
|
||||
}
|
||||
|
||||
$fdate = date('Y-m-01');
|
||||
$tdate = date('Y-m-t');
|
||||
//first day of month
|
||||
$first_day_month = date('Y-m-01');
|
||||
$mdate = date('Y-m-d');
|
||||
$month_n = date('n');
|
||||
|
||||
$iday = ORM::for_table('tbl_transactions')->where('recharged_on',$mdate)->sum('price');
|
||||
if($iday == ''){
|
||||
$iday = '0.00';
|
||||
}
|
||||
$ui->assign('iday',$iday);
|
||||
|
||||
$imonth = ORM::for_table('tbl_transactions')->where_gte('recharged_on',$first_day_month)->where_lte('recharged_on',$mdate)->sum('price');
|
||||
if($imonth == ''){
|
||||
$imonth = '0.00';
|
||||
}
|
||||
$ui->assign('imonth',$imonth);
|
||||
|
||||
$u_act = ORM::for_table('tbl_user_recharges')->where('status','on')->count();
|
||||
if($u_act == ''){
|
||||
$u_act = '0';
|
||||
}
|
||||
$ui->assign('u_act',$u_act);
|
||||
|
||||
$u_all = ORM::for_table('tbl_user_recharges')->count();
|
||||
if($u_all == ''){
|
||||
$u_all = '0';
|
||||
}
|
||||
$ui->assign('u_all',$u_all);
|
||||
//user expire
|
||||
$expire = ORM::for_table('tbl_user_recharges')->where('expiration',$mdate)->order_by_desc('id')->find_many();
|
||||
$ui->assign('expire',$expire);
|
||||
|
||||
//activity log
|
||||
$dlog = ORM::for_table('tbl_logs')->limit(5)->order_by_desc('id')->find_many();
|
||||
$ui->assign('dlog',$dlog);
|
||||
$log = ORM::for_table('tbl_logs')->count();
|
||||
$ui->assign('log',$log);
|
||||
|
||||
$ui->display('dashboard.tpl');
|
11
system/controllers/default.php
Normal file
11
system/controllers/default.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Mikrotik Billing (www.phpmixbill.com)
|
||||
* Ismail Marzuqi <iesien22@yahoo.com>
|
||||
* @version 5.0
|
||||
* @copyright Copyright (C) 2014-2015 PHP Mikrotik Billing
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
* @donate PayPal: iesien22@yahoo.com / Bank Mandiri: 130.00.1024957.4
|
||||
**/
|
||||
|
||||
r2(APP_URL.'/index.php?_route=dashboard');
|
355
system/controllers/export.php
Normal file
355
system/controllers/export.php
Normal file
@ -0,0 +1,355 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Mikrotik Billing (www.phpmixbill.com)
|
||||
* Ismail Marzuqi <iesien22@yahoo.com>
|
||||
* @version 5.0
|
||||
* @copyright Copyright (C) 2014-2015 PHP Mikrotik Billing
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
* @donate PayPal: iesien22@yahoo.com / Bank Mandiri: 130.00.1024957.4
|
||||
**/
|
||||
_admin();
|
||||
$ui->assign('_title', $_L['Reports'].'- '. $config['CompanyName']);
|
||||
$ui->assign('_sysfrm_menu', 'reports');
|
||||
|
||||
$action = $routes['1'];
|
||||
$admin = Admin::_info();
|
||||
$ui->assign('_admin', $admin);
|
||||
|
||||
$mdate = date('Y-m-d');
|
||||
$tdate = date('Y-m-d', strtotime('today - 30 days'));
|
||||
|
||||
//first day of month
|
||||
$first_day_month = date('Y-m-01');
|
||||
//
|
||||
$this_week_start = date('Y-m-d',strtotime( 'previous sunday'));
|
||||
// 30 days before
|
||||
$before_30_days = date('Y-m-d', strtotime('today - 30 days'));
|
||||
//this month
|
||||
$month_n = date('n');
|
||||
|
||||
switch ($action) {
|
||||
|
||||
case 'print-by-date':
|
||||
$mdate = date('Y-m-d');
|
||||
$d = ORM::for_table('tbl_transactions');
|
||||
$d->where('recharged_on', $mdate);
|
||||
$d->order_by_desc('id');
|
||||
$x = $d->find_many();
|
||||
|
||||
$dr = ORM::for_table('tbl_transactions');
|
||||
$dr->where('recharged_on', $mdate);
|
||||
$dr->order_by_desc('id');
|
||||
$xy = $dr->sum('price');
|
||||
|
||||
$ui->assign('d',$x);
|
||||
$ui->assign('dr',$xy);
|
||||
$ui->assign('mdate',$mdate);
|
||||
$ui->assign('recharged_on',$mdate);
|
||||
|
||||
$ui->display('print-by-date.tpl');
|
||||
break;
|
||||
|
||||
case 'pdf-by-date':
|
||||
$mdate = date('Y-m-d');
|
||||
|
||||
$d = ORM::for_table('tbl_transactions');
|
||||
$d->where('recharged_on', $mdate);
|
||||
$d->order_by_desc('id');
|
||||
$x = $d->find_many();
|
||||
|
||||
$dr = ORM::for_table('tbl_transactions');
|
||||
$dr->where('recharged_on', $mdate);
|
||||
$dr->order_by_desc('id');
|
||||
$xy = $dr->sum('price');
|
||||
|
||||
$title = ' Reports ['.$mdate.']';
|
||||
$title = str_replace('-',' ',$title);
|
||||
|
||||
if ($x) {
|
||||
$html = '
|
||||
<div id="page-wrap">
|
||||
<div id="address">
|
||||
<h3>'.$config['CompanyName'].'</h3>
|
||||
'.$config['address'].'<br>
|
||||
'.$_L['Phone_Number'].': '.$config['phone'].'<br>
|
||||
</div>
|
||||
<div id="logo"><img id="image" src="system/uploads/logo.png" alt="logo" /></div>
|
||||
</div>
|
||||
<div id="header">'.$_L['All_Transactions_at_Date'].': '. date($_c['date_format'], strtotime($mdate)).'</div>
|
||||
<table id="customers">
|
||||
<tr>
|
||||
<th>'.$_L['Username'].'</th>
|
||||
<th>'.$_L['Plan_Name'].'</th>
|
||||
<th>'.$_L['Type'].'</th>
|
||||
<th>'.$_L['Plan_Price'].'</th>
|
||||
<th>'.$_L['Created_On'].'</th>
|
||||
<th>'.$_L['Expires_On'].'</th>
|
||||
<th>'.$_L['Method'].'</th>
|
||||
<th>'.$_L['Routers'].'</th>
|
||||
</tr>';
|
||||
$c = true;
|
||||
foreach ($x as $value) {
|
||||
|
||||
$username = $value['username'];
|
||||
$plan_name = $value['plan_name'];
|
||||
$type = $value['type'];
|
||||
$price = $_c['currency_code'].' '. number_format($value['price'],0,$_c['dec_point'],$_c['thousands_sep']);
|
||||
$recharged_on = date( $config['date_format'], strtotime($value['recharged_on']));
|
||||
$expiration = date( $config['date_format'], strtotime($value['expiration']));
|
||||
$time = $value['time'];
|
||||
$method = $value['method'];
|
||||
$routers = $value['routers'];
|
||||
|
||||
$html .= "<tr".(($c = !$c)?' class="alt"':' class=""').">"."
|
||||
<td>$username</td>
|
||||
<td>$plan_name</td>
|
||||
<td>$type</td>
|
||||
<td align='right'>$price</td>
|
||||
<td>$recharged_on $time </td>
|
||||
<td>$expiration $time </td>
|
||||
<td>$method</td>
|
||||
<td>$routers</td>
|
||||
</tr>";
|
||||
}
|
||||
$html .= '</table>
|
||||
<h4 class="text-uppercase text-bold">'.$_L['Total_Income'].':</h4>
|
||||
<h3 class="sum">'.$_c['currency_code'].' '.number_format($xy,2,$_c['dec_point'],$_c['thousands_sep']).'</h3>';
|
||||
|
||||
define('_MPDF_PATH','system/vendors/mpdf/');
|
||||
|
||||
require('system/vendors/mpdf/mpdf.php');
|
||||
|
||||
$mpdf=new mPDF('c','A4','','',20,15,25,25,10,10);
|
||||
$mpdf->SetProtection(array('print'));
|
||||
$mpdf->SetTitle($config['CompanyName'].' Reports');
|
||||
$mpdf->SetAuthor($config['CompanyName']);
|
||||
$mpdf->SetWatermarkText($d['price']);
|
||||
$mpdf->showWatermarkText = true;
|
||||
$mpdf->watermark_font = 'Helvetica';
|
||||
$mpdf->watermarkTextAlpha = 0.1;
|
||||
$mpdf->SetDisplayMode('fullpage');
|
||||
|
||||
$style = '<style>
|
||||
#page-wrap { width: 100%; margin: 0 auto; }
|
||||
#header { text-align: center; position: relative; color: black; font: bold 15px Helvetica, Sans-Serif; margin-top: 10px; margin-bottom: 10px;}
|
||||
|
||||
#address { width: 300px; float: left; }
|
||||
#logo { text-align: right; float: right; position: relative; margin-top: 15px; border: 5px solid #fff; overflow: hidden; }
|
||||
|
||||
#customers
|
||||
{
|
||||
font-family: Helvetica, sans-serif;
|
||||
width:100%;
|
||||
border-collapse:collapse;
|
||||
}
|
||||
#customers td, #customers th
|
||||
{
|
||||
font-size:0.8em;
|
||||
border:1px solid #98bf21;
|
||||
padding:3px 5px 2px 5px;
|
||||
}
|
||||
#customers th
|
||||
{
|
||||
font-size:0.8em;
|
||||
text-align:left;
|
||||
padding-top:5px;
|
||||
padding-bottom:4px;
|
||||
background-color:#A7C942;
|
||||
color:#fff;
|
||||
}
|
||||
#customers tr.alt td
|
||||
{
|
||||
color:#000;
|
||||
background-color:#EAF2D3;
|
||||
}
|
||||
</style>';
|
||||
|
||||
$nhtml = <<<EOF
|
||||
$style
|
||||
$html
|
||||
EOF;
|
||||
$mpdf->WriteHTML($nhtml);
|
||||
$mpdf->Output(date('Y-m-d')._raid(4).'.pdf', 'D');
|
||||
|
||||
}else{
|
||||
echo 'No Data';
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'print-by-period':
|
||||
$fdate = _post('fdate');
|
||||
$tdate = _post('tdate');
|
||||
$stype = _post('stype');
|
||||
|
||||
$d = ORM::for_table('tbl_transactions');
|
||||
if ($stype != ''){
|
||||
$d->where('type', $stype);
|
||||
}
|
||||
|
||||
$d->where_gte('recharged_on', $fdate);
|
||||
$d->where_lte('recharged_on', $tdate);
|
||||
$d->order_by_desc('id');
|
||||
$x = $d->find_many();
|
||||
|
||||
$dr = ORM::for_table('tbl_transactions');
|
||||
if ($stype != ''){
|
||||
$dr->where('type', $stype);
|
||||
}
|
||||
|
||||
$dr->where_gte('recharged_on', $fdate);
|
||||
$dr->where_lte('recharged_on', $tdate);
|
||||
$xy = $dr->sum('price');
|
||||
|
||||
$ui->assign('d',$x);
|
||||
$ui->assign('dr',$xy);
|
||||
$ui->assign('fdate',$fdate);
|
||||
$ui->assign('tdate',$tdate);
|
||||
$ui->assign('stype',$stype);
|
||||
|
||||
$ui->display('print-by-period.tpl');
|
||||
break;
|
||||
|
||||
|
||||
case 'pdf-by-period':
|
||||
$fdate = _post('fdate');
|
||||
$tdate = _post('tdate');
|
||||
$stype = _post('stype');
|
||||
|
||||
$d = ORM::for_table('tbl_transactions');
|
||||
if ($stype != ''){
|
||||
$d->where('type', $stype);
|
||||
}
|
||||
|
||||
$d->where_gte('recharged_on', $fdate);
|
||||
$d->where_lte('recharged_on', $tdate);
|
||||
$d->order_by_desc('id');
|
||||
$x = $d->find_many();
|
||||
|
||||
$dr = ORM::for_table('tbl_transactions');
|
||||
if ($stype != ''){
|
||||
$dr->where('type', $stype);
|
||||
}
|
||||
|
||||
$dr->where_gte('recharged_on', $fdate);
|
||||
$dr->where_lte('recharged_on', $tdate);
|
||||
$xy = $dr->sum('price');
|
||||
|
||||
$title = ' Reports ['.$mdate.']';
|
||||
$title = str_replace('-',' ',$title);
|
||||
|
||||
if ($x) {
|
||||
$html = '
|
||||
<div id="page-wrap">
|
||||
<div id="address">
|
||||
<h3>'.$config['CompanyName'].'</h3>
|
||||
'.$config['address'].'<br>
|
||||
'.$_L['Phone_Number'].': '.$config['phone'].'<br>
|
||||
</div>
|
||||
<div id="logo"><img id="image" src="system/uploads/logo.png" alt="logo" /></div>
|
||||
</div>
|
||||
<div id="header">'.$_L['All_Transactions_at_Date'].': '.date( $_c['date_format'], strtotime($fdate)).' - ' .date( $_c['date_format'], strtotime($tdate)).'</div>
|
||||
<table id="customers">
|
||||
<tr>
|
||||
<th>'.$_L['Username'].'</th>
|
||||
<th>'.$_L['Plan_Name'].'</th>
|
||||
<th>'.$_L['Type'].'</th>
|
||||
<th>'.$_L['Plan_Price'].'</th>
|
||||
<th>'.$_L['Created_On'].'</th>
|
||||
<th>'.$_L['Expires_On'].'</th>
|
||||
<th>'.$_L['Method'].'</th>
|
||||
<th>'.$_L['Routers'].'</th>
|
||||
</tr>';
|
||||
$c = true;
|
||||
foreach ($x as $value) {
|
||||
|
||||
$username = $value['username'];
|
||||
$plan_name = $value['plan_name'];
|
||||
$type = $value['type'];
|
||||
$price = $_c['currency_code'].' '. number_format($value['price'],0,$_c['dec_point'],$_c['thousands_sep']);
|
||||
$recharged_on = date( $config['date_format'], strtotime($value['recharged_on']));
|
||||
$expiration = date( $config['date_format'], strtotime($value['expiration']));
|
||||
$time = $value['time'];
|
||||
$method = $value['method'];
|
||||
$routers = $value['routers'];
|
||||
|
||||
$html .= "<tr".(($c = !$c)?' class="alt"':' class=""').">"."
|
||||
<td>$username</td>
|
||||
<td>$plan_name</td>
|
||||
<td>$type</td>
|
||||
<td align='right'>$price</td>
|
||||
<td>$recharged_on $time </td>
|
||||
<td>$expiration $time </td>
|
||||
<td>$method</td>
|
||||
<td>$routers</td>
|
||||
</tr>";
|
||||
}
|
||||
$html .= '</table>
|
||||
<h4 class="text-uppercase text-bold">'.$_L['Total_Income'].':</h4>
|
||||
<h3 class="sum">'.$_c['currency_code'].' '.number_format($xy,2,$_c['dec_point'],$_c['thousands_sep']).'</h3>';
|
||||
|
||||
define('_MPDF_PATH','system/vendors/mpdf/');
|
||||
|
||||
require('system/vendors/mpdf/mpdf.php');
|
||||
|
||||
$mpdf=new mPDF('c','A4','','',20,15,25,25,10,10);
|
||||
$mpdf->SetProtection(array('print'));
|
||||
$mpdf->SetTitle($config['CompanyName'].' Reports');
|
||||
$mpdf->SetAuthor($config['CompanyName']);
|
||||
$mpdf->SetWatermarkText($d['price']);
|
||||
$mpdf->showWatermarkText = true;
|
||||
$mpdf->watermark_font = 'Helvetica';
|
||||
$mpdf->watermarkTextAlpha = 0.1;
|
||||
$mpdf->SetDisplayMode('fullpage');
|
||||
|
||||
$style = '<style>
|
||||
#page-wrap { width: 100%; margin: 0 auto; }
|
||||
#header { text-align: center; position: relative; color: black; font: bold 15px Helvetica, Sans-Serif; margin-top: 10px; margin-bottom: 10px;}
|
||||
|
||||
#address { width: 300px; float: left; }
|
||||
#logo { text-align: right; float: right; position: relative; margin-top: 15px; border: 5px solid #fff; overflow: hidden; }
|
||||
|
||||
#customers
|
||||
{
|
||||
font-family: Helvetica, sans-serif;
|
||||
width:100%;
|
||||
border-collapse:collapse;
|
||||
}
|
||||
#customers td, #customers th
|
||||
{
|
||||
font-size:0.8em;
|
||||
border:1px solid #98bf21;
|
||||
padding:3px 5px 2px 5px;
|
||||
}
|
||||
#customers th
|
||||
{
|
||||
font-size:0.8em;
|
||||
text-align:left;
|
||||
padding-top:5px;
|
||||
padding-bottom:4px;
|
||||
background-color:#A7C942;
|
||||
color:#fff;
|
||||
}
|
||||
#customers tr.alt td
|
||||
{
|
||||
color:#000;
|
||||
background-color:#EAF2D3;
|
||||
}
|
||||
</style>';
|
||||
|
||||
$nhtml = <<<EOF
|
||||
$style
|
||||
$html
|
||||
EOF;
|
||||
$mpdf->WriteHTML($nhtml);
|
||||
$mpdf->Output(date('Y-m-d')._raid(4).'.pdf', 'D');
|
||||
|
||||
}else{
|
||||
echo 'No Data';
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
echo 'action not defined';
|
||||
}
|
20
system/controllers/home.php
Normal file
20
system/controllers/home.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Mikrotik Billing (www.phpmixbill.com)
|
||||
* Ismail Marzuqi <iesien22@yahoo.com>
|
||||
* @version 5.0
|
||||
* @copyright Copyright (C) 2014-2015 PHP Mikrotik Billing
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
* @donate PayPal: iesien22@yahoo.com / Bank Mandiri: 130.00.1024957.4
|
||||
**/
|
||||
_auth();
|
||||
$ui->assign('_title', $_L['Dashboard'].' - '. $config['CompanyName']);
|
||||
|
||||
$user = User::_info();
|
||||
$ui->assign('_user', $user);
|
||||
|
||||
//Client Page
|
||||
$bill = User::_billing();
|
||||
$ui->assign('_bill', $bill);
|
||||
|
||||
$ui->display('user-dashboard.tpl');
|
8
system/controllers/index.html
Normal file
8
system/controllers/index.html
Normal file
@ -0,0 +1,8 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Directory access is forbidden.</p>
|
||||
</body>
|
||||
</html>
|
55
system/controllers/login.php
Normal file
55
system/controllers/login.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Mikrotik Billing (www.phpmixbill.com)
|
||||
* Ismail Marzuqi <iesien22@yahoo.com>
|
||||
* @version 5.0
|
||||
* @copyright Copyright (C) 2014-2015 PHP Mikrotik Billing
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
* @donate PayPal: iesien22@yahoo.com / Bank Mandiri: 130.00.1024957.4
|
||||
**/
|
||||
|
||||
if (isset($routes['1'])) {
|
||||
$do = $routes['1'];
|
||||
} else {
|
||||
$do = 'login-display';
|
||||
}
|
||||
|
||||
switch($do){
|
||||
case 'post':
|
||||
$username = _post('username');
|
||||
$password = _post('password');
|
||||
if($username != '' AND $password != ''){
|
||||
$d = ORM::for_table('tbl_customers')->where('username',$username)->find_one();
|
||||
if($d){
|
||||
$d_pass = $d['password'];
|
||||
if(Password::_uverify($password,$d_pass) == true){
|
||||
$_SESSION['uid'] = $d['id'];
|
||||
$d->last_login = date('Y-m-d H:i:s');
|
||||
$d->save();
|
||||
_log($username .' '. $_L['Login_Successful'],'User',$d['id']);
|
||||
r2(U.'home');
|
||||
}else{
|
||||
_msglog('e',$_L['Invalid_Username_or_Password']);
|
||||
_log($username .' '. $_L['Failed_Login'],'User');
|
||||
r2(U.'login');
|
||||
}
|
||||
}else{
|
||||
_msglog('e',$_L['Invalid_Username_or_Password']);
|
||||
r2(U.'login');
|
||||
}
|
||||
}else{
|
||||
_msglog('e',$_L['Invalid_Username_or_Password']);
|
||||
r2(U.'login');
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'login-display':
|
||||
$ui->display('login.tpl');
|
||||
break;
|
||||
|
||||
default:
|
||||
$ui->display('login.tpl');
|
||||
break;
|
||||
}
|
||||
|
12
system/controllers/logout.php
Normal file
12
system/controllers/logout.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Mikrotik Billing (www.phpmixbill.com)
|
||||
* Ismail Marzuqi <iesien22@yahoo.com>
|
||||
* @version 5.0
|
||||
* @copyright Copyright (C) 2014-2015 PHP Mikrotik Billing
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
* @donate PayPal: iesien22@yahoo.com / Bank Mandiri: 130.00.1024957.4
|
||||
**/
|
||||
session_start();
|
||||
session_destroy();
|
||||
header('location: index.php');
|
21
system/controllers/message.php
Normal file
21
system/controllers/message.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Mikrotik Billing (www.phpmixbill.com)
|
||||
* Ismail Marzuqi <iesien22@yahoo.com>
|
||||
* @version 5.0
|
||||
* @copyright Copyright (C) 2014-2015 PHP Mikrotik Billing
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
* @donate PayPal: iesien22@yahoo.com / Bank Mandiri: 130.00.1024957.4
|
||||
**/
|
||||
_admin();
|
||||
$ui->assign('_title', $_L['Private_Message'].'- '. $config['CompanyName']);
|
||||
$ui->assign('_system_menu', 'message');
|
||||
|
||||
$action = $routes['1'];
|
||||
$admin = Admin::_info();
|
||||
$ui->assign('_admin', $admin);
|
||||
|
||||
switch ($action) {
|
||||
default:
|
||||
$ui->display('a404.tpl');
|
||||
}
|
20
system/controllers/order.php
Normal file
20
system/controllers/order.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Mikrotik Billing (www.phpmixbill.com)
|
||||
* Ismail Marzuqi <iesien22@yahoo.com>
|
||||
* @version 5.0
|
||||
* @copyright Copyright (C) 2014-2015 PHP Mikrotik Billing
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
* @donate PayPal: iesien22@yahoo.com / Bank Mandiri: 130.00.1024957.4
|
||||
**/
|
||||
_auth();
|
||||
$ui->assign('_title', $_L['Order_Voucher'].'- '. $config['CompanyName']);
|
||||
$ui->assign('_system_menu', 'order');
|
||||
|
||||
$user = User::_info();
|
||||
$ui->assign('_user', $user);
|
||||
|
||||
switch ($action) {
|
||||
default:
|
||||
$ui->display('404.tpl');
|
||||
}
|
21
system/controllers/pm.php
Normal file
21
system/controllers/pm.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Mikrotik Billing (www.phpmixbill.com)
|
||||
* Ismail Marzuqi <iesien22@yahoo.com>
|
||||
* @version 5.0
|
||||
* @copyright Copyright (C) 2014-2015 PHP Mikrotik Billing
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
* @donate PayPal: iesien22@yahoo.com / Bank Mandiri: 130.00.1024957.4
|
||||
**/
|
||||
_auth();
|
||||
$ui->assign('_title', $_L['Private_Message'].'- '. $config['CompanyName']);
|
||||
$ui->assign('_system_menu', 'pm');
|
||||
|
||||
$action = $routes['1'];
|
||||
$user = User::_info();
|
||||
$ui->assign('_user', $user);
|
||||
|
||||
switch ($action) {
|
||||
default:
|
||||
$ui->display('404.tpl');
|
||||
}
|
185
system/controllers/pool.php
Normal file
185
system/controllers/pool.php
Normal file
@ -0,0 +1,185 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Mikrotik Billing (www.phpmixbill.com)
|
||||
* Ismail Marzuqi <iesien22@yahoo.com>
|
||||
* @version 5.0
|
||||
* @copyright Copyright (C) 2014-2015 PHP Mikrotik Billing
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
* @donate PayPal: iesien22@yahoo.com / Bank Mandiri: 130.00.1024957.4
|
||||
**/
|
||||
_admin();
|
||||
$ui->assign('_title', $_L['Network'].' - '. $config['CompanyName']);
|
||||
$ui->assign('_system_menu', 'network');
|
||||
|
||||
$action = $routes['1'];
|
||||
$admin = Admin::_info();
|
||||
$ui->assign('_admin', $admin);
|
||||
|
||||
if($admin['user_type'] != 'Admin'){
|
||||
r2(U."dashboard",'e',$_L['Do_Not_Access']);
|
||||
}
|
||||
|
||||
use PEAR2\Net\RouterOS;
|
||||
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.'%');
|
||||
$d = ORM::for_table('tbl_pool')->where_like('pool_name','%'.$name.'%')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many();
|
||||
}else{
|
||||
$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');
|
||||
break;
|
||||
|
||||
case 'add':
|
||||
$r = ORM::for_table('tbl_routers')->find_many();
|
||||
$ui->assign('r',$r);
|
||||
|
||||
$ui->display('pool-add.tpl');
|
||||
break;
|
||||
|
||||
case 'edit':
|
||||
$id = $routes['2'];
|
||||
$d = ORM::for_table('tbl_pool')->find_one($id);
|
||||
if($d){
|
||||
$ui->assign('d',$d);
|
||||
$ui->display('pool-edit.tpl');
|
||||
}else{
|
||||
r2(U . 'pool/list', 'e', $_L['Account_Not_Found']);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
$id = $routes['2'];
|
||||
|
||||
$d = ORM::for_table('tbl_pool')->find_one($id);
|
||||
$mikrotik = Router::_info($d['routers']);
|
||||
if($d){
|
||||
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 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;
|
||||
|
||||
case 'add-post':
|
||||
$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>';
|
||||
}
|
||||
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>';
|
||||
}
|
||||
$mikrotik = Router::_info($routers);
|
||||
if($msg == ''){
|
||||
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/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);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case 'edit-post':
|
||||
$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>';
|
||||
}
|
||||
if ($ip_address == '' OR $routers == ''){
|
||||
$msg .= $_L['All_field_is_required']. '<br>';
|
||||
}
|
||||
|
||||
$id = _post('id');
|
||||
$d = ORM::for_table('tbl_pool')->find_one($id);
|
||||
if($d){
|
||||
|
||||
}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']);
|
||||
} catch (Exception $e) {
|
||||
die('Unable to connect to the router.');
|
||||
}
|
||||
$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);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
echo 'action not defined';
|
||||
}
|
702
system/controllers/prepaid.php
Normal file
702
system/controllers/prepaid.php
Normal file
@ -0,0 +1,702 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Mikrotik Billing (www.phpmixbill.com)
|
||||
* Ismail Marzuqi <iesien22@yahoo.com>
|
||||
* @version 5.0
|
||||
* @copyright Copyright (C) 2014-2015 PHP Mikrotik Billing
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
* @donate PayPal: iesien22@yahoo.com / Bank Mandiri: 130.00.1024957.4
|
||||
**/
|
||||
_admin();
|
||||
$ui->assign('_title', $_L['Recharge_Account'].' - '. $config['CompanyName']);
|
||||
$ui->assign('_system_menu', 'prepaid');
|
||||
|
||||
$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']);
|
||||
}
|
||||
|
||||
use PEAR2\Net\RouterOS;
|
||||
require_once 'system/autoload/PEAR2/Autoload.php';
|
||||
|
||||
switch ($action) {
|
||||
case 'list':
|
||||
$ui->assign('xfooter', '<script type="text/javascript" src="ui/lib/c/prepaid.js"></script>');
|
||||
|
||||
$username = _post('username');
|
||||
if ($username != ''){
|
||||
$paginator = Paginator::bootstrap('tbl_user_recharges','username','%'.$username.'%');
|
||||
$d = ORM::for_table('tbl_user_recharges')->where_like('username','%'.$username.'%')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many();
|
||||
}else{
|
||||
$paginator = Paginator::bootstrap('tbl_user_recharges');
|
||||
$d = ORM::for_table('tbl_user_recharges')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many();
|
||||
}
|
||||
|
||||
$ui->assign('d',$d);
|
||||
$ui->assign('paginator',$paginator);
|
||||
$ui->display('prepaid.tpl');
|
||||
break;
|
||||
|
||||
case 'recharge':
|
||||
$c = ORM::for_table('tbl_customers')->find_many();
|
||||
$ui->assign('c',$c);
|
||||
$p = ORM::for_table('tbl_plans')->find_many();
|
||||
$ui->assign('p',$p);
|
||||
$r = ORM::for_table('tbl_routers')->find_many();
|
||||
$ui->assign('r',$r);
|
||||
|
||||
$ui->display('recharge.tpl');
|
||||
break;
|
||||
|
||||
case 'recharge-user':
|
||||
$id = $routes['2'];
|
||||
$ui->assign('id',$id);
|
||||
|
||||
$c = ORM::for_table('tbl_customers')->find_many();
|
||||
$ui->assign('c',$c);
|
||||
$p = ORM::for_table('tbl_plans')->find_many();
|
||||
$ui->assign('p',$p);
|
||||
$r = ORM::for_table('tbl_routers')->find_many();
|
||||
$ui->assign('r',$r);
|
||||
|
||||
$ui->display('recharge-user.tpl');
|
||||
break;
|
||||
|
||||
case 'recharge-post':
|
||||
$id_customer = _post('id_customer');
|
||||
$type = _post('type');
|
||||
$server = _post('server');
|
||||
$plan = _post('plan');
|
||||
|
||||
$date_now = date("Y-m-d H:i:s");
|
||||
$date_only = date("Y-m-d");
|
||||
$time = date("H:i:s");
|
||||
|
||||
$msg = '';
|
||||
if ($id_customer == '' OR $type == '' OR $server == '' OR $plan == ''){
|
||||
$msg .= 'All field is required'. '<br>';
|
||||
}
|
||||
|
||||
if($msg == ''){
|
||||
$c = ORM::for_table('tbl_customers')->where('id',$id_customer)->find_one();
|
||||
$p = ORM::for_table('tbl_plans')->where('id',$plan)->find_one();
|
||||
$b = ORM::for_table('tbl_user_recharges')->where('customer_id',$id_customer)->find_one();
|
||||
|
||||
$mikrotik = Router::_info($server);
|
||||
$date_exp = date("Y-m-d", mktime(0,0,0,date("m"),date("d") + $p['validity'],date("Y")));
|
||||
|
||||
if($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 .proplist=name',
|
||||
RouterOS\Query::where('name', $c['username'])
|
||||
);
|
||||
$userName = $client->sendSync($printRequest)->getProperty('name');
|
||||
$removeRequest = new RouterOS\Request('/ip/hotspot/user/remove');
|
||||
$client($removeRequest
|
||||
->setArgument('numbers', $userName)
|
||||
);
|
||||
$addRequest = new RouterOS\Request('/ip/hotspot/user/add');
|
||||
$client->sendSync($addRequest
|
||||
->setArgument('name', $c['username'])
|
||||
->setArgument('profile', $p['name_plan'])
|
||||
->setArgument('password', $c['password'])
|
||||
);
|
||||
|
||||
$b->customer_id = $id_customer;
|
||||
$b->username = $c['username'];
|
||||
$b->plan_id = $plan;
|
||||
$b->namebp = $p['name_plan'];
|
||||
$b->recharged_on = $date_only;
|
||||
$b->expiration = $date_exp;
|
||||
$b->time = $time;
|
||||
$b->status = "on";
|
||||
$b->method = "admin";
|
||||
$b->routers = $server;
|
||||
$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 = "admin";
|
||||
$t->routers = $server;
|
||||
$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.');
|
||||
}
|
||||
$addRequest = new RouterOS\Request('/ip/hotspot/user/add');
|
||||
$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 = $id_customer;
|
||||
$d->username = $c['username'];
|
||||
$d->plan_id = $plan;
|
||||
$d->namebp = $p['name_plan'];
|
||||
$d->recharged_on = $date_only;
|
||||
$d->expiration = $date_exp;
|
||||
$d->time = $time;
|
||||
$d->status = "on";
|
||||
$d->method = "admin";
|
||||
$d->routers = $server;
|
||||
$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 = "admin";
|
||||
$t->routers = $server;
|
||||
$t->type = "Hotspot";
|
||||
$t->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 .proplist=name',
|
||||
RouterOS\Query::where('name', $c['username'])
|
||||
);
|
||||
$userName = $client->sendSync($printRequest)->getProperty('name');
|
||||
|
||||
$removeRequest = new RouterOS\Request('/ppp/secret/remove');
|
||||
$client($removeRequest
|
||||
->setArgument('numbers', $userName)
|
||||
);
|
||||
|
||||
$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 = $id_customer;
|
||||
$b->username = $c['username'];
|
||||
$b->plan_id = $plan;
|
||||
$b->namebp = $p['name_plan'];
|
||||
$b->recharged_on = $date_only;
|
||||
$b->expiration = $date_exp;
|
||||
$b->time = $time;
|
||||
$b->status = "on";
|
||||
$b->method = "admin";
|
||||
$b->routers = $server;
|
||||
$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 = "admin";
|
||||
$t->routers = $server;
|
||||
$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 = $id_customer;
|
||||
$d->username = $c['username'];
|
||||
$d->plan_id = $plan;
|
||||
$d->namebp = $p['name_plan'];
|
||||
$d->recharged_on = $date_only;
|
||||
$d->expiration = $date_exp;
|
||||
$d->time = $time;
|
||||
$d->status = "on";
|
||||
$d->method = "admin";
|
||||
$d->routers = $server;
|
||||
$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 = "admin";
|
||||
$t->routers = $server;
|
||||
$t->type = "PPPOE";
|
||||
$t->save();
|
||||
}
|
||||
}
|
||||
$in = ORM::for_table('tbl_transactions')->where('username',$c['username'])->order_by_desc('id')->find_one();
|
||||
$ui->assign('in',$in);
|
||||
|
||||
$ui->assign('date',$date_now);
|
||||
$ui->display('invoice.tpl');
|
||||
|
||||
}else{
|
||||
r2(U . 'prepaid/recharge', 'e', $msg);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'print':
|
||||
$date_now = date("Y-m-d H:i:s");
|
||||
$id = _post('id');
|
||||
|
||||
$d = ORM::for_table('tbl_transactions')->where('id',$id)->find_one();
|
||||
$ui->assign('d',$d);
|
||||
|
||||
$ui->assign('date',$date_now);
|
||||
$ui->display('invoice-print.tpl');
|
||||
break;
|
||||
break;
|
||||
|
||||
case 'edit':
|
||||
$id = $routes['2'];
|
||||
$d = ORM::for_table('tbl_user_recharges')->find_one($id);
|
||||
if($d){
|
||||
$ui->assign('d',$d);
|
||||
$p = ORM::for_table('tbl_plans')->find_many();
|
||||
$ui->assign('p',$p);
|
||||
|
||||
$ui->display('prepaid-edit.tpl');
|
||||
}else{
|
||||
r2(U . 'services/list', 'e', $_L['Account_Not_Found']);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
$id = $routes['2'];
|
||||
|
||||
$d = ORM::for_table('tbl_user_recharges')->find_one($id);
|
||||
$mikrotik = Router::_info($d['routers']);
|
||||
if($d){
|
||||
if($d['type'] == 'Hotspot'){
|
||||
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 .proplist=name',
|
||||
RouterOS\Query::where('name', $d['username'])
|
||||
);
|
||||
$userName = $client->sendSync($printRequest)->getProperty('name');
|
||||
$removeRequest = new RouterOS\Request('/ip/hotspot/user/remove');
|
||||
$client($removeRequest
|
||||
->setArgument('numbers', $userName)
|
||||
);
|
||||
|
||||
$d->delete();
|
||||
}else{
|
||||
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 .proplist=name',
|
||||
RouterOS\Query::where('name', $d['username'])
|
||||
);
|
||||
$userName = $client->sendSync($printRequest)->getProperty('name');
|
||||
|
||||
$removeRequest = new RouterOS\Request('/ppp/secret/remove');
|
||||
$client($removeRequest
|
||||
->setArgument('numbers', $userName)
|
||||
);
|
||||
$d->delete();
|
||||
}
|
||||
r2(U . 'prepaid/list', 's', $_L['Delete_Successfully']);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'edit-post':
|
||||
$username = _post('username');
|
||||
$id_plan = _post('id_plan');
|
||||
$recharged_on = _post('recharged_on');
|
||||
$expiration = _post('expiration');
|
||||
|
||||
$id = _post('id');
|
||||
$d = ORM::for_table('tbl_user_recharges')->find_one($id);
|
||||
if($d){
|
||||
|
||||
}else{
|
||||
$msg .= $_L['Data_Not_Found']. '<br>';
|
||||
}
|
||||
|
||||
if($msg == ''){
|
||||
$d->username = $username;
|
||||
$d->plan_id = $id_plan;
|
||||
$d->recharged_on = $recharged_on;
|
||||
$d->expiration = $expiration;
|
||||
$d->save();
|
||||
|
||||
r2(U . 'prepaid/list', 's', $_L['Updated_Successfully']);
|
||||
}else{
|
||||
r2(U . 'prepaid/edit/'.$id, 'e', $msg);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'voucher':
|
||||
$ui->assign('xfooter', '<script type="text/javascript" src="ui/lib/c/voucher.js"></script>');
|
||||
|
||||
$code = _post('code');
|
||||
if ($code != ''){
|
||||
$paginator = Paginator::bootstrap('tbl_voucher','code','%'.$code.'%');
|
||||
$d = ORM::for_table('tbl_plans')->join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))->where_like('tbl_plans.code','%'.$code.'%')->offset($paginator['startpoint'])->limit($paginator['limit'])->find_many();
|
||||
}else{
|
||||
$paginator = Paginator::bootstrap('tbl_voucher');
|
||||
$d = ORM::for_table('tbl_plans')->join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))->offset($paginator['startpoint'])->limit($paginator['limit'])->find_many();
|
||||
}
|
||||
|
||||
$ui->assign('d',$d);
|
||||
$ui->assign('paginator',$paginator);
|
||||
$ui->display('voucher.tpl');
|
||||
break;
|
||||
|
||||
case 'add-voucher':
|
||||
|
||||
$c = ORM::for_table('tbl_customers')->find_many();
|
||||
$ui->assign('c',$c);
|
||||
$p = ORM::for_table('tbl_plans')->find_many();
|
||||
$ui->assign('p',$p);
|
||||
$r = ORM::for_table('tbl_routers')->find_many();
|
||||
$ui->assign('r',$r);
|
||||
|
||||
$ui->display('voucher-add.tpl');
|
||||
break;
|
||||
|
||||
case 'voucher-post':
|
||||
$type = _post('type');
|
||||
$plan = _post('plan');
|
||||
$server = _post('server');
|
||||
$numbervoucher = _post('numbervoucher');
|
||||
$lengthcode = _post('lengthcode');
|
||||
|
||||
$msg = '';
|
||||
if ($type == '' OR $plan == '' OR $server == '' OR $numbervoucher == '' OR $lengthcode == ''){
|
||||
$msg .= $_L['All_field_is_required']. '<br>';
|
||||
}
|
||||
if(Validator::UnsignedNumber($numbervoucher) == false){
|
||||
$msg .= 'The Number of Vouchers must be a number'. '<br>';
|
||||
}
|
||||
if(Validator::UnsignedNumber($lengthcode) == false){
|
||||
$msg .= 'The Length Code must be a number'. '<br>';
|
||||
}
|
||||
if($msg == ''){
|
||||
for ($i=0; $i < $numbervoucher; $i++){
|
||||
$code = strtoupper(substr(md5(time().rand(10000,99999)),0,$lengthcode));
|
||||
|
||||
$d = ORM::for_table('tbl_voucher')->create();
|
||||
$d->type = $type;
|
||||
$d->routers = $server;
|
||||
$d->id_plan = $plan;
|
||||
$d->code = $code;
|
||||
$d->user = '0';
|
||||
$d->status = '0';
|
||||
$d->save();
|
||||
}
|
||||
|
||||
r2(U . 'prepaid/voucher', 's', $_L['Voucher_Successfully']);
|
||||
}else{
|
||||
r2(U . 'prepaid/add-voucher/'.$id, 'e', $msg);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'voucher-delete':
|
||||
$id = $routes['2'];
|
||||
|
||||
$d = ORM::for_table('tbl_voucher')->find_one($id);
|
||||
if($d){
|
||||
$d->delete();
|
||||
r2(U . 'prepaid/voucher', 's', $_L['Delete_Successfully']);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'refill':
|
||||
$ui->assign('xfooter', '<script type="text/javascript" src="' . $_theme . '/scripts/form-elements.init.js"></script>');
|
||||
|
||||
$c = ORM::for_table('tbl_customers')->find_many();
|
||||
$ui->assign('c',$c);
|
||||
|
||||
$ui->display('refill.tpl');
|
||||
|
||||
break;
|
||||
|
||||
case 'refill-post':
|
||||
$user = _post('id_customer');
|
||||
$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);
|
||||
$p = ORM::for_table('tbl_plans')->find_one($v1['id_plan']);
|
||||
$b = ORM::for_table('tbl_user_recharges')->where('customer_id',$user)->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 .proplist=name',
|
||||
RouterOS\Query::where('name', $c['username'])
|
||||
);
|
||||
$userName = $client->sendSync($printRequest)->getProperty('name');
|
||||
$removeRequest = new RouterOS\Request('/ip/hotspot/user/remove');
|
||||
$client($removeRequest
|
||||
->setArgument('numbers', $userName)
|
||||
);
|
||||
$addRequest = new RouterOS\Request('/ip/hotspot/user/add');
|
||||
$client->sendSync($addRequest
|
||||
->setArgument('name', $c['username'])
|
||||
->setArgument('profile', $p['name_plan'])
|
||||
->setArgument('password', $c['password'])
|
||||
);
|
||||
|
||||
$b->customer_id = $user;
|
||||
$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.');
|
||||
}
|
||||
$addRequest = new RouterOS\Request('/ip/hotspot/user/add');
|
||||
$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{
|
||||
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 .proplist=name',
|
||||
RouterOS\Query::where('name', $c['username'])
|
||||
);
|
||||
$userName = $client->sendSync($printRequest)->getProperty('name');
|
||||
|
||||
$removeRequest = new RouterOS\Request('/ppp/secret/remove');
|
||||
$client($removeRequest
|
||||
->setArgument('numbers', $userName)
|
||||
);
|
||||
|
||||
$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;
|
||||
$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;
|
||||
$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();
|
||||
}
|
||||
$in = ORM::for_table('tbl_transactions')->where('username',$c['username'])->order_by_desc('id')->find_one();
|
||||
$ui->assign('in',$in);
|
||||
|
||||
$ui->assign('date',$date_now);
|
||||
$ui->display('invoice.tpl');
|
||||
}else{
|
||||
r2(U . 'prepaid/refill', 'e', $_L['Voucher_Not_Valid']);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
echo 'action not defined';
|
||||
}
|
88
system/controllers/reports.php
Normal file
88
system/controllers/reports.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Mikrotik Billing (www.phpmixbill.com)
|
||||
* Ismail Marzuqi <iesien22@yahoo.com>
|
||||
* @version 5.0
|
||||
* @copyright Copyright (C) 2014-2015 PHP Mikrotik Billing
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
* @donate PayPal: iesien22@yahoo.com / Bank Mandiri: 130.00.1024957.4
|
||||
**/
|
||||
_admin();
|
||||
$ui->assign('_title', $_L['Reports'].' - '. $config['CompanyName']);
|
||||
$ui->assign('_system_menu', 'reports');
|
||||
|
||||
$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']);
|
||||
}
|
||||
|
||||
$mdate = date('Y-m-d');
|
||||
$mtime = date('H:i:s');
|
||||
$tdate = date('Y-m-d', strtotime('today - 30 days'));
|
||||
$firs_day_month = date('Y-m-01');
|
||||
$this_week_start = date('Y-m-d', strtotime('previous sunday'));
|
||||
$before_30_days = date('Y-m-d', strtotime('today - 30 days'));
|
||||
$month_n = date('n');
|
||||
|
||||
switch ($action) {
|
||||
case 'daily-report':
|
||||
$paginator = Paginator::bootstrap('tbl_transactions','recharged_on',$mdate);
|
||||
$d = ORM::for_table('tbl_transactions')->where('recharged_on',$mdate)->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many();
|
||||
$dr = ORM::for_table('tbl_transactions')->where('recharged_on',$mdate)->sum('price');
|
||||
|
||||
$ui->assign('d',$d);
|
||||
$ui->assign('dr',$dr);
|
||||
$ui->assign('mdate',$mdate);
|
||||
$ui->assign('mtime',$mtime);
|
||||
$ui->assign('paginator',$paginator);
|
||||
|
||||
$ui->display('reports-daily.tpl');
|
||||
break;
|
||||
|
||||
case 'by-period':
|
||||
$ui->assign('mdate',$mdate);
|
||||
$ui->assign('mtime',$mtime);
|
||||
$ui->assign('tdate', $tdate);
|
||||
|
||||
$ui->display('reports-period.tpl');
|
||||
break;
|
||||
|
||||
case 'period-view':
|
||||
$fdate = _post('fdate');
|
||||
$tdate = _post('tdate');
|
||||
$stype = _post('stype');
|
||||
|
||||
$d = ORM::for_table('tbl_transactions');
|
||||
if ($stype != ''){
|
||||
$d->where('type', $stype);
|
||||
}
|
||||
|
||||
$d->where_gte('recharged_on', $fdate);
|
||||
$d->where_lte('recharged_on', $tdate);
|
||||
$d->order_by_desc('id');
|
||||
$x = $d->find_many();
|
||||
|
||||
$dr = ORM::for_table('tbl_transactions');
|
||||
if ($stype != ''){
|
||||
$dr->where('type', $stype);
|
||||
}
|
||||
|
||||
$dr->where_gte('recharged_on', $fdate);
|
||||
$dr->where_lte('recharged_on', $tdate);
|
||||
$xy = $dr->sum('price');
|
||||
|
||||
$ui->assign('d',$x);
|
||||
$ui->assign('dr',$xy);
|
||||
$ui->assign('fdate',$fdate);
|
||||
$ui->assign('tdate',$tdate);
|
||||
$ui->assign('stype',$stype);
|
||||
|
||||
$ui->display('reports-period-view.tpl');
|
||||
break;
|
||||
|
||||
default:
|
||||
echo 'action not defined';
|
||||
}
|
148
system/controllers/routers.php
Normal file
148
system/controllers/routers.php
Normal file
@ -0,0 +1,148 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Mikrotik Billing (www.phpmixbill.com)
|
||||
* Ismail Marzuqi <iesien22@yahoo.com>
|
||||
* @version 5.0
|
||||
* @copyright Copyright (C) 2014-2015 PHP Mikrotik Billing
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
* @donate PayPal: iesien22@yahoo.com / Bank Mandiri: 130.00.1024957.4
|
||||
**/
|
||||
_admin();
|
||||
$ui->assign('_title', $_L['Network'].' - '. $config['CompanyName']);
|
||||
$ui->assign('_system_menu', 'network');
|
||||
|
||||
$action = $routes['1'];
|
||||
$admin = Admin::_info();
|
||||
$ui->assign('_admin', $admin);
|
||||
|
||||
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>');
|
||||
|
||||
$name = _post('name');
|
||||
if ($name != ''){
|
||||
$paginator = Paginator::bootstrap('tbl_routers','name','%'.$name.'%');
|
||||
$d = ORM::for_table('tbl_routers')->where_like('name','%'.$name.'%')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many();
|
||||
}else{
|
||||
$paginator = Paginator::bootstrap('tbl_routers');
|
||||
$d = ORM::for_table('tbl_routers')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many();
|
||||
}
|
||||
|
||||
$ui->assign('d',$d);
|
||||
$ui->assign('paginator',$paginator);
|
||||
$ui->display('routers.tpl');
|
||||
break;
|
||||
|
||||
case 'add':
|
||||
$d = ORM::for_table('tbl_routers')->find_many();
|
||||
$ui->assign('d',$d);
|
||||
$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);
|
||||
$ui->display('routers-edit.tpl');
|
||||
}else{
|
||||
r2(U . 'routers/list', 'e', $_L['Account_Not_Found']);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
$id = $routes['2'];
|
||||
|
||||
$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');
|
||||
|
||||
$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>';
|
||||
}
|
||||
|
||||
$d = ORM::for_table('tbl_routers')->where('ip_address',$ip_address)->find_one();
|
||||
if($d){
|
||||
$msg .= $_L['Router_already_exist']. '<br>';
|
||||
}
|
||||
|
||||
if($msg == ''){
|
||||
$d = ORM::for_table('tbl_routers')->create();
|
||||
$d->name = $name;
|
||||
$d->ip_address = $ip_address;
|
||||
$d->username = $username;
|
||||
$d->password = $password;
|
||||
$d->description = $description;
|
||||
$d->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');
|
||||
|
||||
$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){
|
||||
$c = ORM::for_table('tbl_routers')->where('ip_address',$ip_address)->find_one();
|
||||
if($c){
|
||||
$msg .= $_L['Router_already_exist']. '<br>';
|
||||
}
|
||||
}
|
||||
|
||||
if($msg == ''){
|
||||
$d->name = $name;
|
||||
$d->ip_address = $ip_address;
|
||||
$d->username = $username;
|
||||
$d->password = $password;
|
||||
$d->description = $description;
|
||||
$d->save();
|
||||
r2(U . 'routers/list', 's', $_L['Updated_Successfully']);
|
||||
}else{
|
||||
r2(U . 'routers/edit/'.$id, 'e', $msg);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
echo 'action not defined';
|
||||
}
|
455
system/controllers/services.php
Normal file
455
system/controllers/services.php
Normal file
@ -0,0 +1,455 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Mikrotik Billing (www.phpmixbill.com)
|
||||
* Ismail Marzuqi <iesien22@yahoo.com>
|
||||
* @version 5.0
|
||||
* @copyright Copyright (C) 2014-2015 PHP Mikrotik Billing
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
* @donate PayPal: iesien22@yahoo.com / Bank Mandiri: 130.00.1024957.4
|
||||
**/
|
||||
_admin();
|
||||
$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']);
|
||||
}
|
||||
|
||||
use PEAR2\Net\RouterOS;
|
||||
require_once 'system/autoload/PEAR2/Autoload.php';
|
||||
|
||||
switch ($action) {
|
||||
case 'hotspot':
|
||||
$ui->assign('xfooter', '<script type="text/javascript" src="ui/lib/c/hotspot.js"></script>');
|
||||
|
||||
$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->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);
|
||||
|
||||
$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);
|
||||
|
||||
$ui->display('hotspot-edit.tpl');
|
||||
}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)
|
||||
);
|
||||
|
||||
$d->delete();
|
||||
|
||||
r2(U . 'services/hotspot', 's', $_L['Delete_Successfully']);
|
||||
}
|
||||
break;
|
||||
|
||||
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');
|
||||
$validity = _post('validity');
|
||||
$validity_unit = _post('validity_unit');
|
||||
$routers = _post('routers');
|
||||
|
||||
$msg = '';
|
||||
if(Validator::UnsignedNumber($validity) == false){
|
||||
$msg .= 'The validity must be a number'. '<br>';
|
||||
}
|
||||
if(Validator::UnsignedNumber($price) == false){
|
||||
$msg .= 'The price must be a number'. '<br>';
|
||||
}
|
||||
if ($name == '' OR $id_bw == '' OR $price == '' OR $validity == '' OR $routers == ''){
|
||||
$msg .= $_L['All_field_is_required']. '<br>';
|
||||
}
|
||||
|
||||
$d = ORM::for_table('tbl_plans')->where('name_plan',$name)->where('type','Hotspot')->find_one();
|
||||
if($d){
|
||||
$msg .= $_L['Plan_already_exist']. '<br>';
|
||||
}
|
||||
|
||||
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('/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->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->validity_unit = $validity_unit;
|
||||
$d->shared_users = $sharedusers;
|
||||
$d->routers = $routers;
|
||||
$d->save();
|
||||
|
||||
r2(U . 'services/hotspot', 's', $_L['Created_Successfully']);
|
||||
}else{
|
||||
r2(U . 'services/add', 'e', $msg);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case 'edit-post':
|
||||
$id = _post('id');
|
||||
$name = _post('name');
|
||||
$id_bw = _post('id_bw');
|
||||
$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');
|
||||
$validity = _post('validity');
|
||||
$validity_unit = _post('validity_unit');
|
||||
$routers = _post('routers');
|
||||
|
||||
$msg = '';
|
||||
if(Validator::UnsignedNumber($validity) == false){
|
||||
$msg .= 'The validity must be a number'. '<br>';
|
||||
}
|
||||
if(Validator::UnsignedNumber($price) == false){
|
||||
$msg .= 'The price must be a number'. '<br>';
|
||||
}
|
||||
if ($name == '' OR $id_bw == '' OR $price == '' OR $validity == '' OR $routers == ''){
|
||||
$msg .= $_L['All_field_is_required']. '<br>';
|
||||
}
|
||||
|
||||
$d = ORM::for_table('tbl_plans')->where('id',$id)->find_one();
|
||||
if($d){
|
||||
}else{
|
||||
$msg .= $_L['Data_Not_Found']. '<br>';
|
||||
}
|
||||
|
||||
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->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->validity_unit = $validity_unit;
|
||||
$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);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'pppoe':
|
||||
$ui->assign('xfooter', '<script type="text/javascript" src="ui/lib/c/pppoe.js"></script>');
|
||||
|
||||
$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);
|
||||
|
||||
$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);
|
||||
|
||||
$ui->display('pppoe-edit.tpl');
|
||||
}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)
|
||||
);
|
||||
|
||||
$d->delete();
|
||||
|
||||
r2(U . 'services/pppoe', 's', $_L['Delete_Successfully']);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'pppoe-add-post':
|
||||
$name = _post('name_plan');
|
||||
$id_bw = _post('id_bw');
|
||||
$price = _post('price');
|
||||
$validity = _post('validity');
|
||||
$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'. '<br>';
|
||||
}
|
||||
if(Validator::UnsignedNumber($price) == false){
|
||||
$msg .= 'The price must be a number'. '<br>';
|
||||
}
|
||||
if ($name == '' OR $id_bw == '' OR $price == '' OR $validity == '' OR $routers == '' OR $pool == ''){
|
||||
$msg .= $_L['All_field_is_required']. '<br>';
|
||||
}
|
||||
|
||||
$d = ORM::for_table('tbl_plans')->where('name_plan',$name)->find_one();
|
||||
if($d){
|
||||
$msg .= $_L['Plan_already_exist']. '<br>';
|
||||
}
|
||||
|
||||
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')->create();
|
||||
$d->type = 'PPPOE';
|
||||
$d->name_plan = $name;
|
||||
$d->id_bw = $id_bw;
|
||||
$d->price = $price;
|
||||
$d->validity = $validity;
|
||||
$d->validity_unit = $validity_unit;
|
||||
$d->routers = $routers;
|
||||
$d->pool = $pool;
|
||||
$d->save();
|
||||
|
||||
r2(U . 'services/pppoe', 's', $_L['Created_Successfully']);
|
||||
}else{
|
||||
r2(U . 'services/pppoe-add', 'e', $msg);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'edit-pppoe-post':
|
||||
$id = _post('id');
|
||||
$name = _post('name_plan');
|
||||
$id_bw = _post('id_bw');
|
||||
$price = _post('price');
|
||||
$validity = _post('validity');
|
||||
$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'. '<br>';
|
||||
}
|
||||
if(Validator::UnsignedNumber($price) == false){
|
||||
$msg .= 'The price must be a number'. '<br>';
|
||||
}
|
||||
if ($name == '' OR $id_bw == '' OR $price == '' OR $validity == '' OR $routers == '' OR $pool == ''){
|
||||
$msg .= $_L['All_field_is_required']. '<br>';
|
||||
}
|
||||
|
||||
$d = ORM::for_table('tbl_plans')->where('id',$id)->find_one();
|
||||
if($d){
|
||||
}else{
|
||||
$msg .= $_L['Data_Not_Found']. '<br>';
|
||||
}
|
||||
|
||||
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->name_plan = $name;
|
||||
$d->id_bw = $id_bw;
|
||||
$d->price = $price;
|
||||
$d->validity = $validity;
|
||||
$d->validity_unit = $validity_unit;
|
||||
$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);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
echo 'action not defined';
|
||||
}
|
478
system/controllers/settings.php
Normal file
478
system/controllers/settings.php
Normal file
@ -0,0 +1,478 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Mikrotik Billing (www.phpmixbill.com)
|
||||
* Ismail Marzuqi <iesien22@yahoo.com>
|
||||
* @version 5.0
|
||||
* @copyright Copyright (C) 2014-2015 PHP Mikrotik Billing
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
* @donate PayPal: iesien22@yahoo.com / Bank Mandiri: 130.00.1024957.4
|
||||
**/
|
||||
_admin();
|
||||
$ui->assign('_title', $_L['Settings'].'- '. $config['CompanyName']);
|
||||
$ui->assign('_system_menu', 'settings');
|
||||
|
||||
$action = $routes['1'];
|
||||
$admin = Admin::_info();
|
||||
$ui->assign('_admin', $admin);
|
||||
|
||||
switch ($action) {
|
||||
case 'app':
|
||||
if($admin['user_type'] != 'Admin'){
|
||||
r2(U."dashboard",'e',$_L['Do_Not_Access']);
|
||||
}
|
||||
|
||||
$ui->display('app-settings.tpl');
|
||||
break;
|
||||
|
||||
case 'localisation':
|
||||
if($admin['user_type'] != 'Admin'){
|
||||
r2(U."dashboard",'e',$_L['Do_Not_Access']);
|
||||
}
|
||||
$lan = ORM::for_table('tbl_language')->find_many();
|
||||
$ui->assign('lan',$lan);
|
||||
|
||||
$timezonelist = Timezone::timezoneList();
|
||||
$ui->assign('tlist',$timezonelist);
|
||||
$ui->assign('xjq', ' $("#tzone").select2(); ');
|
||||
$ui->display('app-localisation.tpl');
|
||||
break;
|
||||
|
||||
case 'users':
|
||||
if($admin['user_type'] != 'Admin'){
|
||||
r2(U."dashboard",'e',$_L['Do_Not_Access']);
|
||||
}
|
||||
|
||||
$ui->assign('xfooter', '<script type="text/javascript" src="ui/lib/c/users.js"></script>');
|
||||
|
||||
$username = _post('username');
|
||||
if ($username != ''){
|
||||
$paginator = Paginator::bootstrap('tbl_users','username','%'.$username.'%');
|
||||
$d = ORM::for_table('tbl_users')->where_like('username','%'.$username.'%')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_asc('id')->find_many();
|
||||
}else{
|
||||
$paginator = Paginator::bootstrap('tbl_users');
|
||||
$d = ORM::for_table('tbl_users')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_asc('id')->find_many();
|
||||
}
|
||||
|
||||
$ui->assign('d',$d);
|
||||
$ui->assign('paginator',$paginator);
|
||||
$ui->display('users.tpl');
|
||||
break;
|
||||
|
||||
case 'users-add':
|
||||
if($admin['user_type'] != 'Admin'){
|
||||
r2(U."dashboard",'e',$_L['Do_Not_Access']);
|
||||
}
|
||||
|
||||
$ui->display('users-add.tpl');
|
||||
break;
|
||||
|
||||
case 'users-edit':
|
||||
if($admin['user_type'] != 'Admin'){
|
||||
r2(U."dashboard",'e',$_L['Do_Not_Access']);
|
||||
}
|
||||
|
||||
$id = $routes['2'];
|
||||
$d = ORM::for_table('tbl_users')->find_one($id);
|
||||
if($d){
|
||||
$ui->assign('d',$d);
|
||||
$ui->display('users-edit.tpl');
|
||||
}else{
|
||||
r2(U . 'settings/users', 'e', $_L['Account_Not_Found']);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'users-delete':
|
||||
if($admin['user_type'] != 'Admin'){
|
||||
r2(U."dashboard",'e',$_L['Do_Not_Access']);
|
||||
}
|
||||
|
||||
$id = $routes['2'];
|
||||
if(($admin['id']) == $id){
|
||||
r2(U . 'settings/users', 'e', 'Sorry You can\'t delete yourself');
|
||||
}
|
||||
$d = ORM::for_table('tbl_users')->find_one($id);
|
||||
if($d){
|
||||
$d->delete();
|
||||
r2(U . 'settings/users', 's', $_L['User_Delete_Ok']);
|
||||
}else{
|
||||
r2(U . 'settings/users', 'e', $_L['Account_Not_Found']);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'users-post':
|
||||
$username = _post('username');
|
||||
$fullname = _post('fullname');
|
||||
$password = _post('password');
|
||||
$cpassword = _post('cpassword');
|
||||
$user_type = _post('user_type');
|
||||
$msg = '';
|
||||
if(Validator::Length($username,16,2) == false){
|
||||
$msg .= 'Username should be between 3 to 15 characters'. '<br>';
|
||||
}
|
||||
if(Validator::Length($fullname,26,2) == false){
|
||||
$msg .= 'Full Name should be between 3 to 25 characters'. '<br>';
|
||||
}
|
||||
if(!Validator::Length($password,15,5)){
|
||||
$msg .= 'Password should be between 6 to 15 characters'. '<br>';
|
||||
}
|
||||
if($password != $cpassword){
|
||||
$msg .= 'Passwords does not match'. '<br>';
|
||||
}
|
||||
|
||||
$d = ORM::for_table('tbl_users')->where('username',$username)->find_one();
|
||||
if($d){
|
||||
$msg .= $_L['account_already_exist']. '<br>';
|
||||
}
|
||||
$date_now = date("Y-m-d H:i:s");
|
||||
if($msg == ''){
|
||||
$password = Password::_crypt($password);
|
||||
$d = ORM::for_table('tbl_users')->create();
|
||||
$d->username = $username;
|
||||
$d->fullname = $fullname;
|
||||
$d->password = $password;
|
||||
$d->user_type = $user_type;
|
||||
$d->status = 'Active';
|
||||
$d->creationdate = $date_now;
|
||||
|
||||
$d->save();
|
||||
|
||||
_log('['.$admin['username'].']: '.$_L['account_created_successfully'],'Admin',$admin['id']);
|
||||
r2(U . 'settings/users', 's', $_L['account_created_successfully']);
|
||||
}else{
|
||||
r2(U . 'settings/users-add', 'e', $msg);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'users-edit-post':
|
||||
$username = _post('username');
|
||||
$fullname = _post('fullname');
|
||||
$password = _post('password');
|
||||
$cpassword = _post('cpassword');
|
||||
|
||||
$msg = '';
|
||||
if(Validator::Length($username,16,2) == false){
|
||||
$msg .= 'Username should be between 3 to 15 characters'. '<br>';
|
||||
}
|
||||
if(Validator::Length($fullname,26,2) == false){
|
||||
$msg .= 'Full Name should be between 3 to 25 characters'. '<br>';
|
||||
}
|
||||
if($password != ''){
|
||||
if(!Validator::Length($password,15,5)){
|
||||
$msg .= 'Password should be between 6 to 15 characters'. '<br>';
|
||||
}
|
||||
if($password != $cpassword){
|
||||
$msg .= 'Passwords does not match'. '<br>';
|
||||
}
|
||||
}
|
||||
|
||||
$id = _post('id');
|
||||
$d = ORM::for_table('tbl_users')->find_one($id);
|
||||
if($d){
|
||||
}else{
|
||||
$msg .= $_L['Data_Not_Found']. '<br>';
|
||||
}
|
||||
|
||||
if($d['username'] != $username){
|
||||
$c = ORM::for_table('tbl_users')->where('username',$username)->find_one();
|
||||
if($c){
|
||||
$msg .= $_L['account_already_exist']. '<br>';
|
||||
}
|
||||
}
|
||||
|
||||
if($msg == ''){
|
||||
$d->username = $username;
|
||||
if($password != ''){
|
||||
$password = Password::_crypt($password);
|
||||
$d->password = $password;
|
||||
}
|
||||
|
||||
$d->fullname = $fullname;
|
||||
if(($admin['id']) != $id){
|
||||
$user_type = _post('user_type');
|
||||
$d->user_type = $user_type;
|
||||
}
|
||||
|
||||
$d->save();
|
||||
|
||||
_log('['.$admin['username'].']: '.$_L['User_Updated_Successfully'],'Admin',$admin['id']);
|
||||
r2(U . 'settings/users', 's', 'User Updated Successfully');
|
||||
}else{
|
||||
r2(U . 'settings/users-edit/'.$id, 'e', $msg);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'app-post':
|
||||
$company = _post('company');
|
||||
$theme = _post('theme');
|
||||
$address = _post('address');
|
||||
if($company == '' OR $theme == '' OR $address == ''){
|
||||
r2(U.'settings/app','e',$_L['All_field_is_required']);
|
||||
}else{
|
||||
$d = ORM::for_table('tbl_appconfig')->where('setting','CompanyName')->find_one();
|
||||
$d->value = $company;
|
||||
$d->save();
|
||||
|
||||
$d = ORM::for_table('tbl_appconfig')->where('setting','address')->find_one();
|
||||
$d->value = $address;
|
||||
$d->save();
|
||||
|
||||
$phone = _post('phone');
|
||||
$d = ORM::for_table('tbl_appconfig')->where('setting','phone')->find_one();
|
||||
$d->value = $phone;
|
||||
$d->save();
|
||||
|
||||
$d = ORM::for_table('tbl_appconfig')->where('setting','theme')->find_one();
|
||||
$d->value = $theme;
|
||||
$d->save();
|
||||
|
||||
$note = _post('note');
|
||||
$d = ORM::for_table('tbl_appconfig')->where('setting','note')->find_one();
|
||||
$d->value = $note;
|
||||
$d->save();
|
||||
|
||||
_log('['.$admin['username'].']: '.$_L['Settings_Saved_Successfully'],'Admin',$admin['id']);
|
||||
|
||||
r2(U.'settings/app','s',$_L['Settings_Saved_Successfully']);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'localisation-post':
|
||||
$tzone = _post('tzone');
|
||||
$date_format = _post('date_format');
|
||||
$lan = _post('lan');
|
||||
if($tzone == '' OR $date_format == '' OR $lan == ''){
|
||||
r2(U.'settings/app','e',$_L['All_field_is_required']);
|
||||
}else{
|
||||
$d = ORM::for_table('tbl_appconfig')->where('setting','timezone')->find_one();
|
||||
$d->value = $tzone;
|
||||
$d->save();
|
||||
|
||||
$d = ORM::for_table('tbl_appconfig')->where('setting','date_format')->find_one();
|
||||
$d->value = $date_format;
|
||||
$d->save();
|
||||
|
||||
$dec_point = $_POST['dec_point'];
|
||||
if(strlen($dec_point) == '1'){
|
||||
$d = ORM::for_table('tbl_appconfig')->where('setting','dec_point')->find_one();
|
||||
$d->value = $dec_point;
|
||||
$d->save();
|
||||
}
|
||||
|
||||
$thousands_sep = $_POST['thousands_sep'];
|
||||
if(strlen($thousands_sep) == '1'){
|
||||
$d = ORM::for_table('tbl_appconfig')->where('setting','thousands_sep')->find_one();
|
||||
$d->value = $thousands_sep;
|
||||
$d->save();
|
||||
}
|
||||
|
||||
$currency_code = $_POST['currency_code'];
|
||||
$d = ORM::for_table('tbl_appconfig')->where('setting','currency_code')->find_one();
|
||||
$d->value = $currency_code;
|
||||
$d->save();
|
||||
|
||||
$d = ORM::for_table('tbl_appconfig')->where('setting','language')->find_one();
|
||||
$d->value = $lan;
|
||||
$d->save();
|
||||
|
||||
_log('['.$admin['username'].']: '.$_L['Settings_Saved_Successfully'],'Admin',$admin['id']);
|
||||
r2(U.'settings/localisation','s',$_L['Settings_Saved_Successfully']);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'change-password':
|
||||
if($admin['user_type'] != 'Admin' AND $admin['user_type'] != 'Sales'){
|
||||
r2(U."dashboard",'e',$_L['Do_Not_Access']);
|
||||
}
|
||||
|
||||
$ui->display('change-password.tpl');
|
||||
break;
|
||||
|
||||
case 'change-password-post':
|
||||
$password = _post('password');
|
||||
if($password != ''){
|
||||
$d = ORM::for_table('tbl_users')->where('username',$admin['username'])->find_one();
|
||||
if($d){
|
||||
$d_pass = $d['password'];
|
||||
if(Password::_verify($password,$d_pass) == true){
|
||||
$npass = _post('npass');
|
||||
$cnpass = _post('cnpass');
|
||||
if(!Validator::Length($npass,15,5)){
|
||||
r2(U.'settings/change-password','e','New Password must be 6 to 14 character');
|
||||
}
|
||||
if($npass != $cnpass){
|
||||
r2(U.'settings/change-password','e','Both Password should be same');
|
||||
}
|
||||
|
||||
$npass = Password::_crypt($npass);
|
||||
$d->password = $npass;
|
||||
$d->save();
|
||||
|
||||
_msglog('s',$_L['Password_Changed_Successfully']);
|
||||
_log('['.$admin['username'].']: Password changed successfully','Admin',$admin['id']);
|
||||
|
||||
r2(U.'admin');
|
||||
}else{
|
||||
r2(U.'settings/change-password','e',$_L['Incorrect_Current_Password']);
|
||||
}
|
||||
}else{
|
||||
r2(U.'settings/change-password','e',$_L['Incorrect_Current_Password']);
|
||||
}
|
||||
}else{
|
||||
r2(U.'settings/change-password','e',$_L['Incorrect_Current_Password']);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case 'dbstatus':
|
||||
if($admin['user_type'] != 'Admin'){
|
||||
r2(U."dashboard",'e',$_L['Do_Not_Access']);
|
||||
}
|
||||
|
||||
$dbc = new mysqli($db_host,$db_user ,$db_password,$db_name);
|
||||
if ($result = $dbc->query('SHOW TABLE STATUS')) {
|
||||
$size = 0;
|
||||
$decimals = 2;
|
||||
$tables = array();
|
||||
while($row = $result->fetch_array()){
|
||||
$size += $row["Data_length"] + $row["Index_length"];
|
||||
$total_size = ($row[ "Data_length" ] + $row[ "Index_length" ]) / 1024;
|
||||
$tables[$row['Name']]['size'] = number_format($total_size,'0');
|
||||
$tables[$row['Name']]['rows'] = $row[ "Rows" ];
|
||||
$tables[$row['Name']]['name'] = $row[ "Name" ];
|
||||
}
|
||||
$mbytes = number_format($size/(1024*1024),$decimals,$config['dec_point'],$config['thousands_sep']);
|
||||
|
||||
$ui->assign('tables',$tables);
|
||||
$ui->assign('dbsize',$mbytes);
|
||||
$ui->display('dbstatus.tpl');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'dbbackup':
|
||||
if($admin['user_type'] != 'Admin'){
|
||||
r2(U."dashboard",'e',$_L['Do_Not_Access']);
|
||||
}
|
||||
|
||||
try {
|
||||
$mysqli = new mysqli($db_host,$db_user ,$db_password,$db_name);
|
||||
if ($mysqli->connect_errno) {
|
||||
throw new Exception("Failed to connect to MySQL: " . $mysqli->connect_error);
|
||||
}
|
||||
|
||||
header('Pragma: public');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||
header('Content-Type: application/force-download');
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-Type: application/download');
|
||||
header('Content-Disposition: attachment;filename="backup_'.date('Y-m-d_h_i_s') . '.sql"');
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
|
||||
ob_start();
|
||||
$f_output = fopen("php://output", 'w');
|
||||
|
||||
print("-- pjl SQL Dump\n");
|
||||
print("-- Server version:".$mysqli->server_info."\n");
|
||||
print("-- Generated: ".date('Y-m-d h:i:s')."\n");
|
||||
print('-- Current PHP version: '.phpversion()."\n");
|
||||
print('-- Host: '.$db_host."\n");
|
||||
print('-- Database:'.$db_name."\n");
|
||||
|
||||
$aTables = array();
|
||||
$strSQL = 'SHOW TABLES';
|
||||
if (!$res_tables = $mysqli->query($strSQL))
|
||||
throw new Exception("MySQL Error: " . $mysqli->error . 'SQL: '.$strSQL);
|
||||
|
||||
while($row = $res_tables->fetch_array()) {
|
||||
$aTables[] = $row[0];
|
||||
}
|
||||
|
||||
$res_tables->free();
|
||||
|
||||
foreach($aTables as $table)
|
||||
{
|
||||
print("-- --------------------------------------------------------\n");
|
||||
print("-- Structure for '". $table."'\n");
|
||||
print("--\n\n");
|
||||
|
||||
$strSQL = 'SHOW CREATE TABLE '.$table;
|
||||
if (!$res_create = $mysqli->query($strSQL))
|
||||
throw new Exception("MySQL Error: " . $mysqli->error . 'SQL: '.$strSQL);
|
||||
$row_create = $res_create->fetch_assoc();
|
||||
|
||||
print("\n".$row_create['Create Table'].";\n");
|
||||
print("-- --------------------------------------------------------\n");
|
||||
print('-- Dump Data for `'. $table."`\n");
|
||||
print("--\n\n");
|
||||
$res_create->free();
|
||||
|
||||
$strSQL = 'SELECT * FROM '.$table;
|
||||
if (!$res_select = $mysqli->query($strSQL))
|
||||
throw new Exception("MySQL Error: " . $mysqli->error . 'SQL: '.$strSQL);
|
||||
|
||||
$fields_info = $res_select->fetch_fields();
|
||||
|
||||
while ($values = $res_select->fetch_assoc()) {
|
||||
$strFields = '';
|
||||
$strValues = '';
|
||||
foreach ($fields_info as $field) {
|
||||
if ($strFields != '') $strFields .= ',';
|
||||
$strFields .= "`".$field->name."`";
|
||||
|
||||
if ($strValues != '') $strValues .= ',';
|
||||
$strValues .= '"'.preg_replace('/[^(\x20-\x7F)\x0A]*/','',$values[$field->name].'"');
|
||||
}
|
||||
print("INSERT INTO ".$table." (".$strFields.") VALUES (".$strValues.");\n");
|
||||
}
|
||||
print("\n\n\n");
|
||||
$res_select->free();
|
||||
}
|
||||
_log('['.$admin['username'].']: '.$_L['Download_Database_Backup'],'Admin',$admin['id']);
|
||||
|
||||
} catch (Exception $e) {
|
||||
print($e->getMessage());
|
||||
}
|
||||
|
||||
fclose($f_output);
|
||||
print(ob_get_clean());
|
||||
$mysqli->close();
|
||||
|
||||
break;
|
||||
|
||||
case 'language':
|
||||
if($admin['user_type'] != 'Admin'){
|
||||
r2(U."dashboard",'e',$_L['Do_Not_Access']);
|
||||
}
|
||||
|
||||
$ui->display('language-add.tpl');
|
||||
break;
|
||||
|
||||
case 'lang-post':
|
||||
$name = _post('name');
|
||||
$folder = _post('folder');
|
||||
$translator = _post('translator');
|
||||
|
||||
if ($name == '' OR $folder == ''){
|
||||
$msg .= $_L['All_field_is_required']. '<br>';
|
||||
}
|
||||
|
||||
$d = ORM::for_table('tbl_language')->where('name',$name)->find_one();
|
||||
if($d){
|
||||
$msg .= $_L['Lang_already_exist']. '<br>';
|
||||
}
|
||||
if($msg == ''){
|
||||
$b = ORM::for_table('tbl_language')->create();
|
||||
$b->name = $name;
|
||||
$b->folder = $folder;
|
||||
$b->author = $translator;
|
||||
$b->save();
|
||||
|
||||
r2(U . 'settings/localisation', 's', $_L['Created_Successfully']);
|
||||
}else{
|
||||
r2(U . 'settings/language', 'e', $msg);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
echo 'action not defined';
|
||||
}
|
258
system/controllers/voucher.php
Normal file
258
system/controllers/voucher.php
Normal file
@ -0,0 +1,258 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Mikrotik Billing (www.phpmixbill.com)
|
||||
* Ismail Marzuqi <iesien22@yahoo.com>
|
||||
* @version 5.0
|
||||
* @copyright Copyright (C) 2014-2015 PHP Mikrotik Billing
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
* @donate PayPal: iesien22@yahoo.com / Bank Mandiri: 130.00.1024957.4
|
||||
**/
|
||||
_auth();
|
||||
$ui->assign('_title', $_L['Voucher'].'- '. $config['CompanyName']);
|
||||
$ui->assign('_system_menu', 'voucher');
|
||||
|
||||
$action = $routes['1'];
|
||||
$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);
|
||||
|
||||
$addRequest = new RouterOS\Request('/ip/hotspot/user/add');
|
||||
$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.');
|
||||
}
|
||||
$addRequest = new RouterOS\Request('/ip/hotspot/user/add');
|
||||
$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']);
|
||||
}
|
||||
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');
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
$ui->display('404.tpl');
|
||||
}
|
Reference in New Issue
Block a user