phpnuxbill/system/controllers/bandwidth.php

191 lines
6.4 KiB
PHP
Raw Normal View History

2017-03-11 03:51:06 +08:00
<?php
2017-03-11 03:51:06 +08:00
/**
2023-10-12 16:55:42 +08:00
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
* by https://t.me/ibnux
**/
2017-03-11 03:51:06 +08:00
_admin();
2024-02-13 14:54:01 +08:00
$ui->assign('_title', Lang::T('Bandwidth Plans'));
2017-03-11 03:51:06 +08:00
$ui->assign('_system_menu', 'services');
$action = $routes['1'];
$ui->assign('_admin', $admin);
if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
r2(U . "dashboard", 'e', Lang::T('You do not have permission to access this page'));
2017-03-11 03:51:06 +08:00
}
switch ($action) {
case 'list':
$ui->assign('xfooter', '<script type="text/javascript" src="ui/lib/c/bandwidth.js"></script>');
2022-09-18 01:00:40 +08:00
run_hook('view_list_bandwidth'); #HOOK
$name = _post('name');
if ($name != '') {
2024-03-27 10:44:48 +08:00
$query = ORM::for_table('tbl_bandwidth')->where_like('name_bw', '%' . $name . '%')->order_by_desc('id');
$d = Paginator::findMany($query, ['name' => $name]);
} else {
2024-03-27 10:44:48 +08:00
$query = ORM::for_table('tbl_bandwidth')->order_by_desc('id');
$d = Paginator::findMany($query);
}
$ui->assign('d', $d);
2017-03-11 03:51:06 +08:00
$ui->display('bandwidth.tpl');
break;
case 'add':
2024-02-26 12:01:54 +08:00
if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
_alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard");
2024-02-26 12:01:54 +08:00
}
2022-09-18 01:00:40 +08:00
run_hook('view_add_bandwidth'); #HOOK
2017-03-11 03:51:06 +08:00
$ui->display('bandwidth-add.tpl');
break;
case 'edit':
2024-02-26 12:01:54 +08:00
if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
_alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard");
2024-02-26 12:01:54 +08:00
}
2017-03-11 03:51:06 +08:00
$id = $routes['2'];
2022-09-18 01:00:40 +08:00
run_hook('view_edit_bandwith'); #HOOK
2017-03-11 03:51:06 +08:00
$d = ORM::for_table('tbl_bandwidth')->find_one($id);
if ($d) {
$ui->assign('burst', explode(" ", $d['burst']));
$ui->assign('d', $d);
2017-03-11 03:51:06 +08:00
$ui->display('bandwidth-edit.tpl');
} else {
2024-03-30 13:02:57 +08:00
r2(U . 'bandwidth/list', 'e', Lang::T('Account Not Found'));
2017-03-11 03:51:06 +08:00
}
break;
case 'delete':
2024-02-26 12:01:54 +08:00
if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
_alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard");
2024-02-26 12:01:54 +08:00
}
2017-03-11 03:51:06 +08:00
$id = $routes['2'];
2022-09-18 01:00:40 +08:00
run_hook('delete_bandwidth'); #HOOK
2017-03-11 03:51:06 +08:00
$d = ORM::for_table('tbl_bandwidth')->find_one($id);
if ($d) {
2017-03-11 03:51:06 +08:00
$d->delete();
2024-02-13 14:54:01 +08:00
r2(U . 'bandwidth/list', 's', Lang::T('Data Deleted Successfully'));
2017-03-11 03:51:06 +08:00
}
break;
case 'add-post':
2024-02-26 12:01:54 +08:00
if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
_alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard");
2024-02-26 12:01:54 +08:00
}
2017-03-11 03:51:06 +08:00
$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');
2022-09-18 01:00:40 +08:00
run_hook('add_bandwidth'); #HOOK
2024-02-21 15:11:19 +08:00
$isBurst = true;
$burst = "";
if (isset($_POST['burst'])) {
foreach ($_POST['burst'] as $b) {
if (empty($b)) {
2024-02-21 15:11:19 +08:00
$isBurst = false;
}
}
if ($isBurst) {
2024-02-21 15:11:19 +08:00
$burst = implode(' ', $_POST['burst']);
};
}
2017-03-11 03:51:06 +08:00
$msg = '';
if (Validator::Length($name, 16, 4) == false) {
$msg .= 'Name should be between 5 to 15 characters' . '<br>';
2017-03-11 03:51:06 +08:00
}
2022-09-01 15:52:32 +08:00
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;
}
2017-03-11 03:51:06 +08:00
$d = ORM::for_table('tbl_bandwidth')->where('name_bw', $name)->find_one();
if ($d) {
$msg .= Lang::T('Name Bandwidth Already Exist') . '<br>';
2017-03-11 03:51:06 +08:00
}
if ($msg == '') {
2017-03-11 03:51:06 +08:00
$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;
2024-02-19 19:03:40 +08:00
$d->burst = $burst;
2017-03-11 03:51:06 +08:00
$d->save();
2022-09-01 15:52:32 +08:00
2024-02-13 14:54:01 +08:00
r2(U . 'bandwidth/list', 's', Lang::T('Data Created Successfully'));
} else {
2017-03-11 03:51:06 +08:00
r2(U . 'bandwidth/add', 'e', $msg);
}
break;
case 'edit-post':
2024-02-26 12:01:54 +08:00
if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
_alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard");
2024-02-26 12:01:54 +08:00
}
2017-03-11 03:51:06 +08:00
$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');
run_hook('edit_bandwidth'); #HOOK
2024-02-21 15:11:19 +08:00
$isBurst = true;
$burst = "";
if (isset($_POST['burst'])) {
foreach ($_POST['burst'] as $b) {
if (empty($b)) {
2024-02-21 15:11:19 +08:00
$isBurst = false;
}
}
if ($isBurst) {
2024-02-21 15:11:19 +08:00
$burst = implode(' ', $_POST['burst']);
};
}
2017-03-11 03:51:06 +08:00
$msg = '';
if (Validator::Length($name, 16, 4) == false) {
$msg .= 'Name should be between 5 to 15 characters' . '<br>';
2017-03-11 03:51:06 +08:00
}
$id = _post('id');
$d = ORM::for_table('tbl_bandwidth')->find_one($id);
if ($d) {
} else {
$msg .= Lang::T('Data Not Found') . '<br>';
2017-03-11 03:51:06 +08:00
}
if ($d['name_bw'] != $name) {
$c = ORM::for_table('tbl_bandwidth')->where('name_bw', $name)->find_one();
if ($c) {
$msg .= Lang::T('Name Bandwidth Already Exist') . '<br>';
2017-03-11 03:51:06 +08:00
}
}
if ($msg == '') {
2017-03-11 03:51:06 +08:00
$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;
2024-02-19 19:03:40 +08:00
$d->burst = $burst;
2017-03-11 03:51:06 +08:00
$d->save();
2022-09-01 15:52:32 +08:00
2024-02-13 14:54:01 +08:00
r2(U . 'bandwidth/list', 's', Lang::T('Data Updated Successfully'));
} else {
r2(U . 'bandwidth/edit/' . $id, 'e', $msg);
2017-03-11 03:51:06 +08:00
}
break;
default:
2023-09-27 16:01:48 +08:00
$ui->display('a404.tpl');
}