740 lines
28 KiB
PHP
Raw Normal View History

2017-03-11 02:51:06 +07:00
<?php
2023-10-16 13:54:34 +07:00
2017-03-11 02:51:06 +07:00
/**
2023-10-12 15:55:42 +07:00
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
* by https://t.me/ibnux
2022-08-23 16:33:21 +07:00
**/
2017-03-11 02:51:06 +07:00
_admin();
2024-02-13 13:54:01 +07:00
$ui->assign('_title', Lang::T('Hotspot Plans'));
2017-03-11 02:51:06 +07:00
$ui->assign('_system_menu', 'services');
$action = $routes['1'];
$ui->assign('_admin', $admin);
if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
2024-03-18 22:55:08 +03:00
_alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard");
2017-03-11 02:51:06 +07:00
}
switch ($action) {
2023-09-15 14:03:23 +07:00
case 'sync':
set_time_limit(-1);
if ($routes['2'] == 'hotspot') {
2024-05-21 11:45:23 +07:00
$plans = ORM::for_table('tbl_bandwidth')->left_outer_join('tbl_plans', array('tbl_bandwidth.id', '=', 'tbl_plans.id_bw'))->where('tbl_plans.type', 'Hotspot')->where('tbl_plans.enabled', '1')->find_many();
2023-09-15 14:03:23 +07:00
$log = '';
$router = '';
foreach ($plans as $plan) {
2024-06-05 17:19:24 +07:00
$dvc = Package::getDevice($plan);
2024-06-12 15:39:43 +07:00
if (file_exists($dvc) && $_app_stage != 'demo') {
2024-06-05 17:19:24 +07:00
require_once $dvc;
2024-06-05 17:37:01 +07:00
(new $p['device'])->add_plan($plan);
2024-06-05 17:19:24 +07:00
} else {
new Exception(Lang::T("Devices Not Found"));
2023-09-15 14:03:23 +07:00
}
}
r2(U . 'services/hotspot', 's', $log);
2023-10-04 11:37:32 +07:00
} else if ($routes['2'] == 'pppoe') {
2024-05-21 11:45:23 +07:00
$plans = ORM::for_table('tbl_bandwidth')->left_outer_join('tbl_plans', array('tbl_bandwidth.id', '=', 'tbl_plans.id_bw'))->where('tbl_plans.type', 'PPPOE')->where('tbl_plans.enabled', '1')->find_many();
2023-09-15 14:03:23 +07:00
$log = '';
$router = '';
foreach ($plans as $plan) {
2024-06-05 17:19:24 +07:00
$dvc = Package::getDevice($plan);
2024-06-12 15:39:43 +07:00
if (file_exists($dvc) && $_app_stage != 'demo') {
2024-06-05 17:19:24 +07:00
require_once $dvc;
2024-06-05 17:37:01 +07:00
(new $p['device'])->add_plan($plan);
2024-06-05 17:19:24 +07:00
} else {
new Exception(Lang::T("Devices Not Found"));
2023-09-15 14:03:23 +07:00
}
}
r2(U . 'services/pppoe', 's', $log);
}
r2(U . 'services/hotspot', 'w', 'Unknown command');
2017-03-11 02:51:06 +07:00
case 'hotspot':
2022-08-23 16:33:21 +07:00
$ui->assign('xfooter', '<script type="text/javascript" src="ui/lib/c/hotspot.js"></script>');
$name = _post('name');
if ($name != '') {
2024-05-21 11:45:23 +07:00
$query = ORM::for_table('tbl_bandwidth')->left_outer_join('tbl_plans', array('tbl_bandwidth.id', '=', 'tbl_plans.id_bw'))->where('tbl_plans.type', 'Hotspot')->where_like('tbl_plans.name_plan', '%' . $name . '%');
$d = Paginator::findMany($query, ['name' => $name]);
2022-08-23 16:33:21 +07:00
} else {
2024-05-21 11:45:23 +07:00
$query = ORM::for_table('tbl_bandwidth')->left_outer_join('tbl_plans', array('tbl_bandwidth.id', '=', 'tbl_plans.id_bw'))->where('tbl_plans.type', 'Hotspot');
2024-03-27 09:44:48 +07:00
$d = Paginator::findMany($query);
2022-08-23 16:33:21 +07:00
}
$ui->assign('d', $d);
2022-09-18 00:00:40 +07:00
run_hook('view_list_plans'); #HOOK
2017-03-11 02:51:06 +07:00
$ui->display('hotspot.tpl');
break;
case 'add':
2022-08-23 16:33:21 +07:00
$d = ORM::for_table('tbl_bandwidth')->find_many();
$ui->assign('d', $d);
$r = ORM::for_table('tbl_routers')->find_many();
$ui->assign('r', $r);
2024-06-10 17:33:49 +07:00
$devices = [];
$files = scandir($DEVICE_PATH);
2024-06-11 13:28:05 +07:00
foreach ($files as $file) {
2024-06-10 17:33:49 +07:00
$ext = pathinfo($file, PATHINFO_EXTENSION);
2024-06-11 13:28:05 +07:00
if ($ext == 'php') {
2024-06-10 17:33:49 +07:00
$devices[] = pathinfo($file, PATHINFO_FILENAME);
}
}
$ui->assign('devices', $devices);
2022-09-18 00:00:40 +07:00
run_hook('view_add_plan'); #HOOK
2017-03-11 02:51:06 +07:00
$ui->display('hotspot-add.tpl');
break;
case 'edit':
2024-03-18 22:55:08 +03:00
$id = $routes['2'];
2017-03-11 02:51:06 +07:00
$d = ORM::for_table('tbl_plans')->find_one($id);
2022-08-23 16:33:21 +07:00
if ($d) {
2024-06-11 13:28:05 +07:00
if (empty($d['device'])) {
if ($d['is_radius']) {
2024-06-10 17:33:49 +07:00
$d->device = 'Radius';
2024-06-11 13:28:05 +07:00
} else {
2024-06-10 17:33:49 +07:00
$d->device = 'MikrotikHotspot';
}
$d->save();
}
2022-08-23 16:33:21 +07:00
$ui->assign('d', $d);
$b = ORM::for_table('tbl_bandwidth')->find_many();
$ui->assign('b', $b);
2024-06-10 17:33:49 +07:00
$devices = [];
$files = scandir($DEVICE_PATH);
2024-06-11 13:28:05 +07:00
foreach ($files as $file) {
2024-06-10 17:33:49 +07:00
$ext = pathinfo($file, PATHINFO_EXTENSION);
2024-06-11 13:28:05 +07:00
if ($ext == 'php') {
2024-06-10 17:33:49 +07:00
$devices[] = pathinfo($file, PATHINFO_FILENAME);
}
}
$ui->assign('devices', $devices);
2024-06-11 13:28:05 +07:00
//select expired plan
2024-06-12 15:27:33 +07:00
if ($d['is_radius']) {
$exps = ORM::for_table('tbl_plans')->selects('id', 'name_plan')->where('type', 'Hotspot')->where("is_radius", 1)->findArray();
} else {
$exps = ORM::for_table('tbl_plans')->selects('id', 'name_plan')->where('type', 'Hotspot')->where("routers", $d['routers'])->findArray();
2024-06-11 13:28:05 +07:00
}
$ui->assign('exps', $exps);
2022-09-18 00:00:40 +07:00
run_hook('view_edit_plan'); #HOOK
2017-03-11 02:51:06 +07:00
$ui->display('hotspot-edit.tpl');
2022-08-23 16:33:21 +07:00
} else {
2024-03-30 12:02:57 +07:00
r2(U . 'services/hotspot', 'e', Lang::T('Account Not Found'));
2017-03-11 02:51:06 +07:00
}
break;
case 'delete':
2024-03-18 22:55:08 +03:00
$id = $routes['2'];
2022-08-23 16:33:21 +07:00
2017-03-11 02:51:06 +07:00
$d = ORM::for_table('tbl_plans')->find_one($id);
2022-08-23 16:33:21 +07:00
if ($d) {
2022-09-18 00:00:40 +07:00
run_hook('delete_plan'); #HOOK
2024-06-05 17:19:24 +07:00
$dvc = Package::getDevice($d);
2024-06-12 15:39:43 +07:00
if (file_exists($dvc) && $_app_stage != 'demo') {
2024-06-05 17:19:24 +07:00
require_once $dvc;
2024-06-05 17:37:01 +07:00
(new $p['device'])->remove_plan($d);
2023-10-16 13:54:34 +07:00
} else {
2024-06-05 17:19:24 +07:00
new Exception(Lang::T("Devices Not Found"));
2022-08-23 16:33:21 +07:00
}
2017-03-11 02:51:06 +07:00
$d->delete();
2022-08-23 16:33:21 +07:00
2024-02-13 13:54:01 +07:00
r2(U . 'services/hotspot', 's', Lang::T('Data Deleted Successfully'));
2017-03-11 02:51:06 +07:00
}
break;
case 'add-post':
$name = _post('name');
2024-03-18 22:55:08 +03:00
$plan_type = _post('plan_type'); //Personal / Business
2023-10-03 15:46:55 +07:00
$radius = _post('radius');
2017-03-11 02:51:06 +07:00
$typebp = _post('typebp');
2022-08-23 16:33:21 +07:00
$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');
2023-08-15 13:24:44 +07:00
$price = _post('price');
2022-08-23 16:33:21 +07:00
$sharedusers = _post('sharedusers');
2017-03-11 02:51:06 +07:00
$validity = _post('validity');
2022-08-23 16:33:21 +07:00
$validity_unit = _post('validity_unit');
$routers = _post('routers');
2024-06-10 17:33:49 +07:00
$device = _post('device');
2023-08-14 15:01:47 +07:00
$enabled = _post('enabled');
2024-03-13 14:32:10 +07:00
$prepaid = _post('prepaid');
2024-06-19 15:26:26 +07:00
$expired_date = _post('expired_date');
2022-08-23 16:33:21 +07:00
2017-03-11 02:51:06 +07:00
$msg = '';
2022-08-23 16:33:21 +07:00
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>';
2017-03-11 02:51:06 +07:00
}
2023-10-03 15:46:55 +07:00
if ($name == '' or $id_bw == '' or $price == '' or $validity == '') {
2024-02-13 13:54:01 +07:00
$msg .= Lang::T('All field is required') . '<br>';
2017-03-11 02:51:06 +07:00
}
if (empty($radius)) {
2023-10-03 15:46:55 +07:00
if ($routers == '') {
2024-02-13 13:54:01 +07:00
$msg .= Lang::T('All field is required') . '<br>';
2023-10-03 15:46:55 +07:00
}
}
2022-08-23 16:33:21 +07:00
$d = ORM::for_table('tbl_plans')->where('name_plan', $name)->where('type', 'Hotspot')->find_one();
if ($d) {
2024-02-13 13:54:01 +07:00
$msg .= Lang::T('Name Plan Already Exist') . '<br>';
2017-03-11 02:51:06 +07:00
}
2022-09-18 00:00:40 +07:00
run_hook('add_plan'); #HOOK
2022-08-23 16:33:21 +07:00
if ($msg == '') {
// Create new plan
2017-03-11 02:51:06 +07:00
$d = ORM::for_table('tbl_plans')->create();
$d->name_plan = $name;
$d->id_bw = $id_bw;
$d->price = $price; // Set price with or without tax based on configuration
2022-08-23 16:33:21 +07:00
$d->type = 'Hotspot';
2017-03-11 02:51:06 +07:00
$d->typebp = $typebp;
2024-03-18 22:55:08 +03:00
$d->plan_type = $plan_type;
2022-08-23 16:33:21 +07:00
$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;
2017-03-11 02:51:06 +07:00
$d->validity_unit = $validity_unit;
2022-08-23 16:33:21 +07:00
$d->shared_users = $sharedusers;
if (!empty($radius)) {
2023-10-03 15:46:55 +07:00
$d->is_radius = 1;
$d->routers = '';
2023-10-04 11:37:32 +07:00
} else {
2023-10-03 15:46:55 +07:00
$d->is_radius = 0;
$d->routers = $routers;
}
2022-09-08 10:43:46 +07:00
$d->enabled = $enabled;
2024-03-13 14:32:10 +07:00
$d->prepaid = $prepaid;
2024-06-10 17:33:49 +07:00
$d->device = $device;
2024-06-19 15:26:26 +07:00
if($prepaid == 'no'){
if($expired_date>28 && $expired_date < 1){
$expired_date = 20;
}
$d->expired_date = $expired_date;
}else{
$d->expired_date = 0;
}
2017-03-11 02:51:06 +07:00
$d->save();
2023-10-03 15:46:55 +07:00
2024-06-05 17:19:24 +07:00
$dvc = Package::getDevice($d);
2024-06-12 15:39:43 +07:00
if (file_exists($dvc) && $_app_stage != 'demo') {
2024-06-05 17:19:24 +07:00
require_once $dvc;
2024-06-05 17:37:01 +07:00
(new $p['device'])->add_plan($d);
2024-06-05 17:19:24 +07:00
} else {
new Exception(Lang::T("Devices Not Found"));
2023-10-03 15:46:55 +07:00
}
2024-06-12 15:27:33 +07:00
r2(U . 'services/edit/' . $d->id(), 's', Lang::T('Data Created Successfully'));
2022-08-23 16:33:21 +07:00
} else {
2017-03-11 02:51:06 +07:00
r2(U . 'services/add', 'e', $msg);
}
break;
case 'edit-post':
2022-08-23 16:33:21 +07:00
$id = _post('id');
2017-03-11 02:51:06 +07:00
$name = _post('name');
2024-03-18 22:55:08 +03:00
$plan_type = _post('plan_type');
2017-03-11 02:51:06 +07:00
$id_bw = _post('id_bw');
2022-08-23 16:33:21 +07:00
$typebp = _post('typebp');
2017-03-11 02:51:06 +07:00
$price = _post('price');
2022-08-23 16:33:21 +07:00
$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');
2017-03-11 02:51:06 +07:00
$validity = _post('validity');
2022-08-23 16:33:21 +07:00
$validity_unit = _post('validity_unit');
2024-06-11 13:28:05 +07:00
$plan_expired = _post('plan_expired', '0');
2024-06-10 17:33:49 +07:00
$device = _post('device');
2023-08-14 15:01:47 +07:00
$enabled = _post('enabled');
2024-03-13 14:32:10 +07:00
$prepaid = _post('prepaid');
$routers = _post('routers');
2024-06-19 15:26:26 +07:00
$expired_date = _post('expired_date');
2017-03-11 02:51:06 +07:00
$msg = '';
2022-08-23 16:33:21 +07:00
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>';
2017-03-11 02:51:06 +07:00
}
2023-10-03 15:46:55 +07:00
if ($name == '' or $id_bw == '' or $price == '' or $validity == '') {
2024-02-13 13:54:01 +07:00
$msg .= Lang::T('All field is required') . '<br>';
2017-03-11 02:51:06 +07:00
}
2022-08-23 16:33:21 +07:00
$d = ORM::for_table('tbl_plans')->where('id', $id)->find_one();
2024-06-05 17:19:24 +07:00
$old = ORM::for_table('tbl_plans')->where('id', $id)->find_one();
2022-08-23 16:33:21 +07:00
if ($d) {
} else {
2024-02-13 13:54:01 +07:00
$msg .= Lang::T('Data Not Found') . '<br>';
2017-03-11 02:51:06 +07:00
}
2022-09-18 00:00:40 +07:00
run_hook('edit_plan'); #HOOK
2022-08-23 16:33:21 +07:00
if ($msg == '') {
$b = ORM::for_table('tbl_bandwidth')->where('id', $id_bw)->find_one();
if ($b['rate_down_unit'] == 'Kbps') {
$unitdown = 'K';
2023-10-03 15:46:55 +07:00
$raddown = '000';
2022-08-23 16:33:21 +07:00
} else {
$unitdown = 'M';
2023-10-03 15:46:55 +07:00
$raddown = '000000';
2022-08-23 16:33:21 +07:00
}
if ($b['rate_up_unit'] == 'Kbps') {
$unitup = 'K';
2023-10-03 15:46:55 +07:00
$radup = '000';
2022-08-23 16:33:21 +07:00
} else {
$unitup = 'M';
2023-10-03 15:46:55 +07:00
$radup = '000000';
2022-08-23 16:33:21 +07:00
}
$rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown;
2024-05-07 08:11:16 +07:00
$radiusRate = $b['rate_up'] . $radup . '/' . $b['rate_down'] . $raddown . '/' . $b['burst'];
2022-08-23 16:33:21 +07:00
2024-02-19 18:03:40 +07:00
$rate = trim($rate . " " . $b['burst']);
2017-03-11 02:51:06 +07:00
$d->name_plan = $name;
$d->id_bw = $id_bw;
$d->price = $price; // Set price with or without tax based on configuration
2017-03-11 02:51:06 +07:00
$d->typebp = $typebp;
2022-08-23 16:33:21 +07:00
$d->limit_type = $limit_type;
$d->time_limit = $time_limit;
$d->time_unit = $time_unit;
$d->data_limit = $data_limit;
2024-03-18 22:55:08 +03:00
$d->plan_type = $plan_type;
2022-08-23 16:33:21 +07:00
$d->data_unit = $data_unit;
$d->validity = $validity;
2017-03-11 02:51:06 +07:00
$d->validity_unit = $validity_unit;
2022-08-23 16:33:21 +07:00
$d->shared_users = $sharedusers;
2024-06-11 13:28:05 +07:00
$d->plan_expired = $plan_expired;
2022-09-08 10:43:46 +07:00
$d->enabled = $enabled;
2024-03-13 14:32:10 +07:00
$d->prepaid = $prepaid;
2024-06-10 17:33:49 +07:00
$d->device = $device;
2024-06-19 15:26:26 +07:00
if($prepaid == 'no'){
if($expired_date>28 && $expired_date < 1){
$expired_date = 20;
}
$d->expired_date = $expired_date;
}else{
$d->expired_date = 0;
}
2017-03-11 02:51:06 +07:00
$d->save();
2022-08-23 16:33:21 +07:00
2024-06-05 17:19:24 +07:00
$dvc = Package::getDevice($d);
2024-06-12 15:39:43 +07:00
if (file_exists($dvc) && $_app_stage != 'demo') {
2024-06-05 17:19:24 +07:00
require_once $dvc;
2024-06-05 17:37:01 +07:00
(new $d['device'])->update_plan($old, $d);
2024-06-05 17:19:24 +07:00
} else {
new Exception(Lang::T("Devices Not Found"));
}
2024-02-13 13:54:01 +07:00
r2(U . 'services/hotspot', 's', Lang::T('Data Updated Successfully'));
2022-08-23 16:33:21 +07:00
} else {
r2(U . 'services/edit/' . $id, 'e', $msg);
2017-03-11 02:51:06 +07:00
}
break;
2022-08-23 16:33:21 +07:00
2017-03-11 02:51:06 +07:00
case 'pppoe':
2024-02-13 13:54:01 +07:00
$ui->assign('_title', Lang::T('PPPOE Plans'));
2022-08-23 16:33:21 +07:00
$ui->assign('xfooter', '<script type="text/javascript" src="ui/lib/c/pppoe.js"></script>');
$name = _post('name');
if ($name != '') {
2024-05-21 11:45:23 +07:00
$query = ORM::for_table('tbl_bandwidth')->left_outer_join('tbl_plans', array('tbl_bandwidth.id', '=', 'tbl_plans.id_bw'))->where('tbl_plans.type', 'PPPOE')->where_like('tbl_plans.name_plan', '%' . $name . '%');
2024-03-27 09:44:48 +07:00
$d = Paginator::findMany($query, ['name' => $name]);
2022-08-23 16:33:21 +07:00
} else {
2024-05-21 11:45:23 +07:00
$query = ORM::for_table('tbl_bandwidth')->left_outer_join('tbl_plans', array('tbl_bandwidth.id', '=', 'tbl_plans.id_bw'))->where('tbl_plans.type', 'PPPOE');
2024-03-27 09:44:48 +07:00
$d = Paginator::findMany($query);
2022-08-23 16:33:21 +07:00
}
$ui->assign('d', $d);
2022-09-18 00:00:40 +07:00
run_hook('view_list_ppoe'); #HOOK
2017-03-11 02:51:06 +07:00
$ui->display('pppoe.tpl');
break;
case 'pppoe-add':
2024-02-13 13:54:01 +07:00
$ui->assign('_title', Lang::T('PPPOE Plans'));
2022-08-23 16:33:21 +07:00
$d = ORM::for_table('tbl_bandwidth')->find_many();
$ui->assign('d', $d);
$r = ORM::for_table('tbl_routers')->find_many();
$ui->assign('r', $r);
2024-06-10 17:33:49 +07:00
$devices = [];
$files = scandir($DEVICE_PATH);
2024-06-11 13:28:05 +07:00
foreach ($files as $file) {
2024-06-10 17:33:49 +07:00
$ext = pathinfo($file, PATHINFO_EXTENSION);
2024-06-11 13:28:05 +07:00
if ($ext == 'php') {
2024-06-10 17:33:49 +07:00
$devices[] = pathinfo($file, PATHINFO_FILENAME);
}
}
$ui->assign('devices', $devices);
2022-09-18 00:00:40 +07:00
run_hook('view_add_ppoe'); #HOOK
2017-03-11 02:51:06 +07:00
$ui->display('pppoe-add.tpl');
break;
case 'pppoe-edit':
2024-02-13 13:54:01 +07:00
$ui->assign('_title', Lang::T('PPPOE Plans'));
2024-03-18 22:55:08 +03:00
$id = $routes['2'];
2017-03-11 02:51:06 +07:00
$d = ORM::for_table('tbl_plans')->find_one($id);
2022-08-23 16:33:21 +07:00
if ($d) {
2024-06-11 13:28:05 +07:00
if (empty($d['device'])) {
if ($d['is_radius']) {
2024-06-10 17:33:49 +07:00
$d->device = 'Radius';
2024-06-11 13:28:05 +07:00
} else {
2024-06-10 17:33:49 +07:00
$d->device = 'MikrotikPppoe';
}
$d->save();
}
2022-08-23 16:33:21 +07:00
$ui->assign('d', $d);
2023-10-04 11:37:32 +07:00
$p = ORM::for_table('tbl_pool')->where('routers', ($d['is_radius']) ? 'radius' : $d['routers'])->find_many();
2023-09-05 16:40:23 +07:00
$ui->assign('p', $p);
2022-08-23 16:33:21 +07:00
$b = ORM::for_table('tbl_bandwidth')->find_many();
$ui->assign('b', $b);
2023-10-04 11:37:32 +07:00
$r = [];
2023-10-04 16:11:55 +07:00
if ($d['is_radius']) {
2023-10-04 11:37:32 +07:00
$r = ORM::for_table('tbl_routers')->find_many();
}
2022-08-23 16:33:21 +07:00
$ui->assign('r', $r);
2024-06-10 17:33:49 +07:00
$devices = [];
$files = scandir($DEVICE_PATH);
2024-06-11 13:28:05 +07:00
foreach ($files as $file) {
2024-06-10 17:33:49 +07:00
$ext = pathinfo($file, PATHINFO_EXTENSION);
2024-06-11 13:28:05 +07:00
if ($ext == 'php') {
2024-06-10 17:33:49 +07:00
$devices[] = pathinfo($file, PATHINFO_FILENAME);
}
}
$ui->assign('devices', $devices);
2024-06-11 13:28:05 +07:00
//select expired plan
2024-06-12 15:27:33 +07:00
if ($d['is_radius']) {
$exps = ORM::for_table('tbl_plans')->selects('id', 'name_plan')->where('type', 'PPPOE')->where("is_radius", 1)->findArray();
} else {
$exps = ORM::for_table('tbl_plans')->selects('id', 'name_plan')->where('type', 'PPPOE')->where("routers", $d['routers'])->findArray();
2024-06-11 13:28:05 +07:00
}
$ui->assign('exps', $exps);
2022-09-18 00:00:40 +07:00
run_hook('view_edit_ppoe'); #HOOK
2017-03-11 02:51:06 +07:00
$ui->display('pppoe-edit.tpl');
2022-08-23 16:33:21 +07:00
} else {
2024-03-30 12:02:57 +07:00
r2(U . 'services/pppoe', 'e', Lang::T('Account Not Found'));
2017-03-11 02:51:06 +07:00
}
break;
case 'pppoe-delete':
2024-03-18 22:55:08 +03:00
$id = $routes['2'];
2022-08-23 16:33:21 +07:00
2017-03-11 02:51:06 +07:00
$d = ORM::for_table('tbl_plans')->find_one($id);
2022-08-23 16:33:21 +07:00
if ($d) {
2022-09-18 00:00:40 +07:00
run_hook('delete_ppoe'); #HOOK
2024-06-05 17:19:24 +07:00
$dvc = Package::getDevice($d);
2024-06-12 15:39:43 +07:00
if (file_exists($dvc) && $_app_stage != 'demo') {
2024-06-05 17:19:24 +07:00
require_once $dvc;
2024-06-05 17:37:01 +07:00
(new $p['device'])->remove_plan($d);
2023-10-16 13:54:34 +07:00
} else {
2024-06-05 17:19:24 +07:00
new Exception(Lang::T("Devices Not Found"));
2022-08-23 16:33:21 +07:00
}
2017-03-11 02:51:06 +07:00
$d->delete();
2024-02-13 13:54:01 +07:00
r2(U . 'services/pppoe', 's', Lang::T('Data Deleted Successfully'));
2017-03-11 02:51:06 +07:00
}
break;
case 'pppoe-add-post':
$name = _post('name_plan');
2024-03-18 22:55:08 +03:00
$plan_type = _post('plan_type');
2023-10-04 11:37:32 +07:00
$radius = _post('radius');
2022-08-23 16:33:21 +07:00
$id_bw = _post('id_bw');
$price = _post('price');
2017-03-11 02:51:06 +07:00
$validity = _post('validity');
2022-08-23 16:33:21 +07:00
$validity_unit = _post('validity_unit');
$routers = _post('routers');
2024-06-10 17:33:49 +07:00
$device = _post('device');
2022-08-23 16:33:21 +07:00
$pool = _post('pool_name');
2023-08-14 15:01:47 +07:00
$enabled = _post('enabled');
2024-03-13 14:32:10 +07:00
$prepaid = _post('prepaid');
2024-06-19 15:26:26 +07:00
$expired_date = _post('expired_date');
2022-08-23 16:33:21 +07:00
2017-03-11 02:51:06 +07:00
$msg = '';
2022-08-23 16:33:21 +07:00
if (Validator::UnsignedNumber($validity) == false) {
$msg .= 'The validity must be a number' . '<br>';
2017-03-11 02:51:06 +07:00
}
2022-08-23 16:33:21 +07:00
if (Validator::UnsignedNumber($price) == false) {
$msg .= 'The price must be a number' . '<br>';
2017-03-11 02:51:06 +07:00
}
2023-10-04 11:37:32 +07:00
if ($name == '' or $id_bw == '' or $price == '' or $validity == '' or $pool == '') {
2024-02-13 13:54:01 +07:00
$msg .= Lang::T('All field is required') . '<br>';
2017-03-11 02:51:06 +07:00
}
if (empty($radius)) {
2023-10-04 11:37:32 +07:00
if ($routers == '') {
2024-02-13 13:54:01 +07:00
$msg .= Lang::T('All field is required') . '<br>';
2023-10-04 11:37:32 +07:00
}
}
2017-03-11 02:51:06 +07:00
2022-08-23 16:33:21 +07:00
$d = ORM::for_table('tbl_plans')->where('name_plan', $name)->find_one();
if ($d) {
2024-02-13 13:54:01 +07:00
$msg .= Lang::T('Name Plan Already Exist') . '<br>';
2022-08-23 16:33:21 +07:00
}
2022-09-18 00:00:40 +07:00
run_hook('add_ppoe'); #HOOK
2022-08-23 16:33:21 +07:00
if ($msg == '') {
$b = ORM::for_table('tbl_bandwidth')->where('id', $id_bw)->find_one();
if ($b['rate_down_unit'] == 'Kbps') {
$unitdown = 'K';
2023-10-04 11:37:32 +07:00
$raddown = '000';
2022-08-23 16:33:21 +07:00
} else {
$unitdown = 'M';
2023-10-04 11:37:32 +07:00
$raddown = '000000';
2022-08-23 16:33:21 +07:00
}
if ($b['rate_up_unit'] == 'Kbps') {
$unitup = 'K';
2023-10-04 11:37:32 +07:00
$radup = '000';
2022-08-23 16:33:21 +07:00
} else {
$unitup = 'M';
2023-10-04 11:37:32 +07:00
$radup = '000000';
2022-08-23 16:33:21 +07:00
}
$rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown;
2024-05-07 08:11:16 +07:00
$radiusRate = $b['rate_up'] . $radup . '/' . $b['rate_down'] . $raddown . '/' . $b['burst'];
2024-02-19 18:03:40 +07:00
$rate = trim($rate . " " . $b['burst']);
2017-03-11 02:51:06 +07:00
$d = ORM::for_table('tbl_plans')->create();
$d->type = 'PPPOE';
2022-08-23 16:33:21 +07:00
$d->name_plan = $name;
2017-03-11 02:51:06 +07:00
$d->id_bw = $id_bw;
$d->price = $price;
2024-03-18 22:55:08 +03:00
$d->plan_type = $plan_type;
2022-08-23 16:33:21 +07:00
$d->validity = $validity;
2017-03-11 02:51:06 +07:00
$d->validity_unit = $validity_unit;
2022-08-23 16:33:21 +07:00
$d->pool = $pool;
if (!empty($radius)) {
2023-10-04 11:37:32 +07:00
$d->is_radius = 1;
$d->routers = '';
} else {
$d->is_radius = 0;
$d->routers = $routers;
}
2024-06-19 15:26:26 +07:00
if($prepaid == 'no'){
if($expired_date>28 && $expired_date < 1){
$expired_date = 20;
}
$d->expired_date = $expired_date;
}else{
$d->expired_date = 0;
}
2022-09-08 10:43:46 +07:00
$d->enabled = $enabled;
2024-03-13 14:32:10 +07:00
$d->prepaid = $prepaid;
2024-06-10 17:33:49 +07:00
$d->device = $device;
2017-03-11 02:51:06 +07:00
$d->save();
2023-10-04 11:37:32 +07:00
2024-06-05 17:19:24 +07:00
$dvc = Package::getDevice($d);
2024-06-12 15:39:43 +07:00
if (file_exists($dvc) && $_app_stage != 'demo') {
2024-06-05 17:19:24 +07:00
require_once $dvc;
2024-06-05 17:37:01 +07:00
(new $p['device'])->add_plan($d);
2024-06-05 17:19:24 +07:00
} else {
new Exception(Lang::T("Devices Not Found"));
2023-10-04 11:37:32 +07:00
}
2017-03-11 02:51:06 +07:00
2024-02-13 13:54:01 +07:00
r2(U . 'services/pppoe', 's', Lang::T('Data Created Successfully'));
2022-08-23 16:33:21 +07:00
} else {
2017-03-11 02:51:06 +07:00
r2(U . 'services/pppoe-add', 'e', $msg);
}
break;
case 'edit-pppoe-post':
2022-08-23 16:33:21 +07:00
$id = _post('id');
2024-03-18 22:55:08 +03:00
$plan_type = _post('plan_type');
2017-03-11 02:51:06 +07:00
$name = _post('name_plan');
2022-08-23 16:33:21 +07:00
$id_bw = _post('id_bw');
$price = _post('price');
2017-03-11 02:51:06 +07:00
$validity = _post('validity');
2022-08-23 16:33:21 +07:00
$validity_unit = _post('validity_unit');
$routers = _post('routers');
2024-06-10 17:33:49 +07:00
$device = _post('device');
2022-08-23 16:33:21 +07:00
$pool = _post('pool_name');
2024-06-11 13:28:05 +07:00
$plan_expired = _post('plan_expired');
2023-08-14 15:01:47 +07:00
$enabled = _post('enabled');
2024-03-13 14:32:10 +07:00
$prepaid = _post('prepaid');
2024-06-19 15:26:26 +07:00
$expired_date = _post('expired_date');
2022-08-23 16:33:21 +07:00
2017-03-11 02:51:06 +07:00
$msg = '';
2022-08-23 16:33:21 +07:00
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>';
2017-03-11 02:51:06 +07:00
}
2023-10-04 11:37:32 +07:00
if ($name == '' or $id_bw == '' or $price == '' or $validity == '' or $pool == '') {
2024-02-13 13:54:01 +07:00
$msg .= Lang::T('All field is required') . '<br>';
2017-03-11 02:51:06 +07:00
}
2022-08-23 16:33:21 +07:00
$d = ORM::for_table('tbl_plans')->where('id', $id)->find_one();
2024-06-05 17:19:24 +07:00
$old = ORM::for_table('tbl_plans')->where('id', $id)->find_one();
2022-08-23 16:33:21 +07:00
if ($d) {
} else {
2024-02-13 13:54:01 +07:00
$msg .= Lang::T('Data Not Found') . '<br>';
2017-03-11 02:51:06 +07:00
}
2022-09-18 00:00:40 +07:00
run_hook('edit_ppoe'); #HOOK
2022-08-23 16:33:21 +07:00
if ($msg == '') {
$b = ORM::for_table('tbl_bandwidth')->where('id', $id_bw)->find_one();
if ($b['rate_down_unit'] == 'Kbps') {
$unitdown = 'K';
2023-10-04 11:37:32 +07:00
$raddown = '000';
2022-08-23 16:33:21 +07:00
} else {
$unitdown = 'M';
2023-10-04 11:37:32 +07:00
$raddown = '000000';
2022-08-23 16:33:21 +07:00
}
if ($b['rate_up_unit'] == 'Kbps') {
$unitup = 'K';
2023-10-04 11:37:32 +07:00
$radup = '000';
2022-08-23 16:33:21 +07:00
} else {
$unitup = 'M';
2023-10-04 11:37:32 +07:00
$radup = '000000';
2022-08-23 16:33:21 +07:00
}
$rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown;
2024-05-07 08:11:16 +07:00
$radiusRate = $b['rate_up'] . $radup . '/' . $b['rate_down'] . $raddown . '/' . $b['burst'];
2024-02-19 18:03:40 +07:00
$rate = trim($rate . " " . $b['burst']);
2022-08-23 16:33:21 +07:00
2017-03-11 02:51:06 +07:00
$d->name_plan = $name;
$d->id_bw = $id_bw;
$d->price = $price;
2024-03-18 22:55:08 +03:00
$d->plan_type = $plan_type;
2022-08-23 16:33:21 +07:00
$d->validity = $validity;
2017-03-11 02:51:06 +07:00
$d->validity_unit = $validity_unit;
2022-08-23 16:33:21 +07:00
$d->routers = $routers;
$d->pool = $pool;
2024-06-11 13:28:05 +07:00
$d->plan_expired = $plan_expired;
2022-09-08 10:43:46 +07:00
$d->enabled = $enabled;
2024-03-13 14:32:10 +07:00
$d->prepaid = $prepaid;
2024-06-10 17:33:49 +07:00
$d->device = $device;
2024-06-19 15:26:26 +07:00
if($prepaid == 'no'){
if($expired_date>28 && $expired_date < 1){
$expired_date = 20;
}
$d->expired_date = $expired_date;
}else{
$d->expired_date = 0;
}
2017-03-11 02:51:06 +07:00
$d->save();
2022-08-23 16:33:21 +07:00
2024-06-05 17:19:24 +07:00
$dvc = Package::getDevice($d);
2024-06-12 15:39:43 +07:00
if (file_exists($dvc) && $_app_stage != 'demo') {
2024-06-05 17:19:24 +07:00
require_once $dvc;
2024-06-05 17:37:01 +07:00
(new $d['device'])->update_plan($old, $d);
2024-06-05 17:19:24 +07:00
} else {
new Exception(Lang::T("Devices Not Found"));
}
2024-02-13 13:54:01 +07:00
r2(U . 'services/pppoe', 's', Lang::T('Data Updated Successfully'));
2022-08-23 16:33:21 +07:00
} else {
r2(U . 'services/pppoe-edit/' . $id, 'e', $msg);
2017-03-11 02:51:06 +07:00
}
break;
2023-08-14 15:01:47 +07:00
case 'balance':
$ui->assign('_title', Lang::T('Balance Plans'));
$name = _post('name');
if ($name != '') {
$query = ORM::for_table('tbl_plans')->where('tbl_plans.type', 'Balance')->where_like('tbl_plans.name_plan', '%' . $name . '%');
2024-03-27 09:44:48 +07:00
$d = Paginator::findMany($query, ['name' => $name]);
2023-08-14 15:01:47 +07:00
} else {
$query = ORM::for_table('tbl_plans')->where('tbl_plans.type', 'Balance');
2024-03-27 09:44:48 +07:00
$d = Paginator::findMany($query);
2023-08-14 15:01:47 +07:00
}
$ui->assign('d', $d);
run_hook('view_list_balance'); #HOOK
$ui->display('balance.tpl');
break;
case 'balance-add':
$ui->assign('_title', Lang::T('Balance Plans'));
run_hook('view_add_balance'); #HOOK
$ui->display('balance-add.tpl');
break;
case 'balance-edit':
$ui->assign('_title', Lang::T('Balance Plans'));
2024-03-18 22:55:08 +03:00
$id = $routes['2'];
2023-08-14 15:01:47 +07:00
$d = ORM::for_table('tbl_plans')->find_one($id);
$ui->assign('d', $d);
run_hook('view_edit_balance'); #HOOK
$ui->display('balance-edit.tpl');
break;
case 'balance-delete':
2024-03-18 22:55:08 +03:00
$id = $routes['2'];
2023-08-14 15:01:47 +07:00
$d = ORM::for_table('tbl_plans')->find_one($id);
if ($d) {
run_hook('delete_balance'); #HOOK
$d->delete();
2024-02-13 13:54:01 +07:00
r2(U . 'services/balance', 's', Lang::T('Data Deleted Successfully'));
2023-08-14 15:01:47 +07:00
}
break;
case 'balance-edit-post':
$id = _post('id');
$name = _post('name');
$price = _post('price');
$enabled = _post('enabled');
2024-03-13 14:32:10 +07:00
$prepaid = _post('prepaid');
2023-08-14 15:01:47 +07:00
$msg = '';
if (Validator::UnsignedNumber($price) == false) {
$msg .= 'The price must be a number' . '<br>';
}
if ($name == '') {
2024-02-13 13:54:01 +07:00
$msg .= Lang::T('All field is required') . '<br>';
2023-08-14 15:01:47 +07:00
}
2022-08-23 16:33:21 +07:00
2023-08-14 15:01:47 +07:00
$d = ORM::for_table('tbl_plans')->where('id', $id)->find_one();
if ($d) {
} else {
2024-02-13 13:54:01 +07:00
$msg .= Lang::T('Data Not Found') . '<br>';
2023-08-14 15:01:47 +07:00
}
run_hook('edit_ppoe'); #HOOK
if ($msg == '') {
$d->name_plan = $name;
$d->price = $price;
2023-08-14 15:01:47 +07:00
$d->enabled = $enabled;
2024-03-13 14:32:10 +07:00
$d->prepaid = 'yes';
2023-08-14 15:01:47 +07:00
$d->save();
2024-02-13 13:54:01 +07:00
r2(U . 'services/balance', 's', Lang::T('Data Updated Successfully'));
2023-08-14 15:01:47 +07:00
} else {
r2(U . 'services/balance-edit/' . $id, 'e', $msg);
}
break;
case 'balance-add-post':
$name = _post('name');
$price = _post('price');
$enabled = _post('enabled');
$msg = '';
if (Validator::UnsignedNumber($price) == false) {
$msg .= 'The price must be a number' . '<br>';
}
if ($name == '') {
2024-02-13 13:54:01 +07:00
$msg .= Lang::T('All field is required') . '<br>';
2023-08-14 15:01:47 +07:00
}
$d = ORM::for_table('tbl_plans')->where('name_plan', $name)->find_one();
if ($d) {
2024-02-13 13:54:01 +07:00
$msg .= Lang::T('Name Plan Already Exist') . '<br>';
2023-08-14 15:01:47 +07:00
}
run_hook('add_ppoe'); #HOOK
if ($msg == '') {
$d = ORM::for_table('tbl_plans')->create();
$d->type = 'Balance';
$d->name_plan = $name;
$d->id_bw = 0;
$d->price = $price;
2023-08-14 15:01:47 +07:00
$d->validity = 0;
$d->validity_unit = 'Months';
$d->routers = '';
$d->pool = '';
$d->enabled = $enabled;
2024-03-13 14:32:10 +07:00
$d->prepaid = 'yes';
2023-08-14 15:01:47 +07:00
$d->save();
2024-02-13 13:54:01 +07:00
r2(U . 'services/balance', 's', Lang::T('Data Created Successfully'));
2023-08-14 15:01:47 +07:00
} else {
r2(U . 'services/balance-add', 'e', $msg);
}
break;
2017-03-11 02:51:06 +07:00
default:
2023-09-27 15:01:48 +07:00
$ui->display('a404.tpl');
2022-08-23 16:33:21 +07:00
}