186 lines
7.6 KiB
PHP
Raw Normal View History

2017-03-11 02:51:06 +07:00
<?php
2023-10-12 15:55:42 +07:00
/**
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
* by https://t.me/ibnux
**/
2023-08-23 12:11:07 +07:00
2017-03-11 02:51:06 +07:00
/**
2023-08-23 12:11:07 +07:00
* used for ajax
**/
2022-09-18 00:00:40 +07:00
2017-03-11 02:51:06 +07:00
_admin();
2024-02-13 13:54:01 +07:00
$ui->assign('_title', Lang::T('Network'));
2017-03-11 02:51:06 +07:00
$ui->assign('_system_menu', 'network');
$action = $routes['1'];
$ui->assign('_admin', $admin);
switch ($action) {
case 'pool':
2023-08-23 12:11:07 +07:00
$routers = _get('routers');
if (empty($routers)) {
2023-10-04 11:25:58 +07:00
$d = ORM::for_table('tbl_pool')->find_many();
} else {
2023-10-04 11:25:58 +07:00
$d = ORM::for_table('tbl_pool')->where('routers', $routers)->find_many();
}
$ui->assign('routers', $routers);
2023-08-23 12:11:07 +07:00
$ui->assign('d', $d);
2025-02-04 10:22:14 +07:00
$ui->display('admin/autoload/pool.tpl');
2017-03-11 02:51:06 +07:00
break;
2024-09-25 15:00:13 +07:00
case 'bw_name':
$bw = ORM::for_table('tbl_bandwidth')->select("name_bw")->find_one($routes['2']);
echo $bw['name_bw'];
die();
case 'balance':
$balance = ORM::for_table('tbl_customers')->select("balance")->find_one($routes['2'])['balance'];
if ($routes['3'] == '1') {
echo Lang::moneyFormat($balance);
} else {
echo $balance;
}
die();
2017-03-11 02:51:06 +07:00
case 'server':
2023-08-23 12:11:07 +07:00
$d = ORM::for_table('tbl_routers')->where('enabled', '1')->find_many();
$ui->assign('d', $d);
2022-09-01 14:52:32 +07:00
2025-02-04 10:22:14 +07:00
$ui->display('admin/autoload/server.tpl');
2017-03-11 02:51:06 +07:00
break;
case 'pppoe_ip_used':
if (!empty(_get('ip'))) {
$cs = ORM::for_table('tbl_customers')
->select("username")
->where_not_equal('id', _get('id'))
->where("pppoe_ip", _get('ip'))
->findArray();
if (count($cs) > 0) {
$c = array_column($cs, 'username');
die(Lang::T("IP has been used by") . ' : ' . implode(", ", $c));
}
}
die();
case 'pppoe_username_used':
if (!empty(_get('u'))) {
$cs = ORM::for_table('tbl_customers')
->select("username")
->where_not_equal('id', _get('id'))
->where("pppoe_username", _get('u'))
->findArray();
if (count($cs) > 0) {
$c = array_column($cs, 'username');
die(Lang::T("Username has been used by") . ' : ' . implode(", ", $c));
}
}
die();
2017-03-11 02:51:06 +07:00
case 'plan':
2023-08-23 12:11:07 +07:00
$server = _post('server');
$jenis = _post('jenis');
if (in_array($admin['user_type'], array('SuperAdmin', 'Admin'))) {
switch ($server) {
case 'radius':
$d = ORM::for_table('tbl_plans')->where('is_radius', 1)->where('type', $jenis)->find_many();
break;
case '':
break;
default:
$d = ORM::for_table('tbl_plans')->where('routers', $server)->where('type', $jenis)->find_many();
break;
2024-03-12 13:58:42 +07:00
}
} else {
switch ($server) {
case 'radius':
$d = ORM::for_table('tbl_plans')->where('is_radius', 1)->where('type', $jenis)->find_many();
break;
case '':
break;
default:
$d = ORM::for_table('tbl_plans')->where('routers', $server)->where('type', $jenis)->find_many();
break;
2024-03-12 13:58:42 +07:00
}
2023-10-04 15:51:51 +07:00
}
2023-08-23 12:11:07 +07:00
$ui->assign('d', $d);
2022-09-01 14:52:32 +07:00
2025-02-04 10:22:14 +07:00
$ui->display('admin/autoload/plan.tpl');
2017-03-11 02:51:06 +07:00
break;
2023-09-07 10:54:20 +07:00
case 'customer_is_active':
if ($config['check_customer_online'] == 'yes') {
$c = ORM::for_table('tbl_customers')->where('username', $routes['2'])->find_one();
$p = ORM::for_table('tbl_plans')->find_one($routes['3']);
$dvc = Package::getDevice($p);
if ($_app_stage != 'Demo') {
if (file_exists($dvc)) {
require_once $dvc;
try {
//don't wait more than 5 seconds for response from device, otherwise we get timeout error.
ini_set('default_socket_timeout', 5);
if ((new $p['device'])->online_customer($c, $p['routers'])) {
2025-01-07 16:41:52 +07:00
echo '<span style="color: green;" title="online">&bull;</span>';
}else{
echo '<span style="color: yellow;" title="offline">&bull;</span>';
}
} catch (Exception $e) {
2025-01-07 16:41:52 +07:00
echo '<span style="color: red;" title="'.$e->getMessage().'">&bull;</span>';
}
}
}
}
break;
case 'plan_is_active':
$ds = ORM::for_table('tbl_user_recharges')->where('customer_id', $routes['2'])->find_array();
if ($ds) {
$ps = [];
$c = ORM::for_table('tbl_customers')->find_one($routes['2']);
foreach ($ds as $d) {
if ($d['status'] == 'on') {
if ($config['check_customer_online'] == 'yes') {
$p = ORM::for_table('tbl_plans')->find_one($d['plan_id']);
$dvc = Package::getDevice($p);
$status = "";
if ($_app_stage != 'Demo') {
if (file_exists($dvc)) {
require_once $dvc;
try {
//don't wait more than 5 seconds for response from device, otherwise we get timeout error.
ini_set('default_socket_timeout', 5);
if ((new $p['device'])->online_customer($c, $p['routers'])) {
2025-01-07 16:41:52 +07:00
$status = '<span style="color: green;" title="online">&bull;</span>';
}else{
$status = '<span style="color: yellow;" title="offline">&bull;</span>';
}
} catch (Exception $e) {
2025-01-07 16:41:52 +07:00
$status = '<span style="color: red;" title="'.$e->getMessage().'">&bull;</span>';
}
}
}
}
$ps[] = ('<span class="label label-primary m-1" title="Expired ' . Lang::dateAndTimeFormat($d['expiration'], $d['time']) . '">' . $d['namebp'] . ' ' . $status . '</span>');
} else {
$ps[] = ('<span class="label label-danger m-1" title="Expired ' . Lang::dateAndTimeFormat($d['expiration'], $d['time']) . '">' . $d['namebp'] . '</span>');
}
2023-09-07 10:54:20 +07:00
}
echo implode("<br>", $ps);
2023-09-07 10:54:20 +07:00
} else {
die('');
2023-09-07 10:54:20 +07:00
}
break;
2023-08-23 12:11:07 +07:00
case 'customer_select2':
$s = addslashes(_get('s'));
if (empty($s)) {
$c = ORM::for_table('tbl_customers')->limit(30)->find_many();
} else {
2023-12-19 09:55:55 +07:00
$c = ORM::for_table('tbl_customers')->where_raw("(`username` LIKE '%$s%' OR `fullname` LIKE '%$s%' OR `phonenumber` LIKE '%$s%' OR `email` LIKE '%$s%')")->limit(30)->find_many();
2023-08-23 12:11:07 +07:00
}
header('Content-Type: application/json');
2023-08-23 15:00:34 +07:00
foreach ($c as $cust) {
2023-08-23 12:11:07 +07:00
$json[] = [
'id' => $cust['id'],
2023-08-23 15:00:34 +07:00
'text' => $cust['username'] . ' - ' . $cust['fullname'] . ' - ' . $cust['email']
2023-08-23 12:11:07 +07:00
];
}
2023-08-23 15:00:34 +07:00
echo json_encode(['results' => $json]);
2023-08-23 12:11:07 +07:00
die();
2017-03-11 02:51:06 +07:00
default:
2025-02-04 09:23:55 +07:00
$ui->display('admin/404.tpl');
2023-08-23 12:11:07 +07:00
}