Files
.github
admin
docs
install
pages_template
qrcode
scan
system
autoload
cache
controllers
accounts.php
admin.php
autoload.php
autoload_user.php
bandwidth.php
callback.php
community.php
customers.php
dashboard.php
default.php
export.php
home.php
index.html
login.php
logout.php
logs.php
mail.php
map.php
message.php
order.php
page.php
pages.php
paymentgateway.php
plan.php
plugin.php
pluginmanager.php
pool.php
radius.php
register.php
reports.php
routers.php
services.php
settings.php
voucher.php
devices
lan
paymentgateway
plugin
uploads
vendor
.htaccess
api.php
boot.php
composer.json
composer.lock
cron.php
cron_reminder.php
index.html
orm.php
updates.json
ui
.gitignore
.htaccess_firewall
CHANGELOG.md
Dockerfile
LICENSE
README.md
composer.json
config.sample.php
docker-compose.example.yml
favicon.ico
index.php
init.php
radius.php
update.php
version.json
mitrobill/system/controllers/home.php

329 lines
14 KiB
PHP
Raw Normal View History

2017-03-11 02:51:06 +07:00
<?php
2022-09-11 11:02:30 +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-09-11 11:02:30 +07:00
**/
2023-10-12 15:55:42 +07:00
2017-03-11 02:51:06 +07:00
_auth();
2024-02-13 13:54:01 +07:00
$ui->assign('_title', Lang::T('Dashboard'));
2017-03-11 02:51:06 +07:00
$user = User::_info();
$ui->assign('_user', $user);
2023-08-23 16:46:05 +07:00
if (isset($_GET['renewal'])) {
2023-08-15 10:27:46 +07:00
$user->auto_renewal = $_GET['renewal'];
$user->save();
}
2023-08-23 16:46:05 +07:00
if (_post('send') == 'balance') {
if ($config['enable_balance'] == 'yes' && $config['allow_balance_transfer'] == 'yes') {
if ($user['status'] != 'Active') {
2024-05-17 09:25:26 +07:00
_alert(Lang::T('This account status') . ' : ' . Lang::T($user['status']), 'danger', "");
}
2023-08-23 16:46:05 +07:00
$target = ORM::for_table('tbl_customers')->where('username', _post('username'))->find_one();
if (!$target) {
r2(U . 'home', 'd', Lang::T('Username not found'));
}
$username = _post('username');
$balance = _post('balance');
if ($user['balance'] < $balance) {
r2(U . 'home', 'd', Lang::T('insufficient balance'));
}
2023-09-13 16:23:51 +07:00
if (!empty($config['minimum_transfer']) && intval($balance) < intval($config['minimum_transfer'])) {
2023-08-24 11:52:43 +07:00
r2(U . 'home', 'd', Lang::T('Minimum Transfer') . ' ' . Lang::moneyFormat($config['minimum_transfer']));
}
2023-08-23 16:46:05 +07:00
if ($user['username'] == $target['username']) {
r2(U . 'home', 'd', Lang::T('Cannot send to yourself'));
}
2023-08-24 11:35:23 +07:00
if (Balance::transfer($user['id'], $username, $balance)) {
2023-08-23 16:46:05 +07:00
//sender
$d = ORM::for_table('tbl_payment_gateway')->create();
$d->username = $user['username'];
$d->gateway = $target['username'];
$d->plan_id = 0;
$d->plan_name = 'Send Balance';
$d->routers_id = 0;
$d->routers = 'balance';
$d->price = $balance;
$d->payment_method = "Customer";
$d->payment_channel = "Balance";
$d->created_date = date('Y-m-d H:i:s');
$d->paid_date = date('Y-m-d H:i:s');
$d->expired_date = date('Y-m-d H:i:s');
$d->pg_url_payment = 'balance';
$d->status = 2;
$d->save();
//receiver
$d = ORM::for_table('tbl_payment_gateway')->create();
$d->username = $target['username'];
$d->gateway = $user['username'];
$d->plan_id = 0;
$d->plan_name = 'Receive Balance';
$d->routers_id = 0;
$d->routers = 'balance';
$d->payment_method = "Customer";
$d->payment_channel = "Balance";
$d->price = $balance;
$d->created_date = date('Y-m-d H:i:s');
$d->paid_date = date('Y-m-d H:i:s');
$d->expired_date = date('Y-m-d H:i:s');
$d->pg_url_payment = 'balance';
$d->status = 2;
$d->save();
2024-07-22 15:19:29 +07:00
Message::sendBalanceNotification($user, $balance, ($user['balance'] - $balance), Lang::getNotifText('balance_send'), $config['user_notification_payment']);
Message::sendBalanceNotification($target, $balance, ($target['balance'] + $balance), Lang::getNotifText('balance_received'), $config['user_notification_payment']);
2023-08-24 11:35:23 +07:00
Message::sendTelegram("#u$user[username] send balance to #u$target[username] \n" . Lang::moneyFormat($balance));
2023-08-23 16:46:05 +07:00
r2(U . 'home', 's', Lang::T('Sending balance success'));
}
2023-08-24 11:35:23 +07:00
} else {
2023-09-13 15:38:56 +07:00
r2(U . 'home', 'd', Lang::T('Failed, balance is not available'));
}
2023-09-13 16:23:51 +07:00
} else if (_post('send') == 'plan') {
if ($user['status'] != 'Active') {
2024-05-17 09:25:26 +07:00
_alert(Lang::T('This account status') . ' : ' . Lang::T($user['status']), 'danger', "");
}
2024-04-05 11:18:28 +07:00
$actives = ORM::for_table('tbl_user_recharges')
2023-09-13 15:38:56 +07:00
->where('username', _post('username'))
2024-04-05 11:18:28 +07:00
->find_many();
foreach ($actives as $active) {
$router = ORM::for_table('tbl_routers')->where('name', $active['routers'])->find_one();
2024-04-05 11:18:28 +07:00
if ($router) {
r2(U . "order/send/$router[id]/$active[plan_id]&u=" . trim(_post('username')), 's', Lang::T('Review package before recharge'));
}
2023-08-23 16:46:05 +07:00
}
2024-04-05 11:18:28 +07:00
r2(U . 'home', 'w', Lang::T('Your friend do not have active package'));
2023-08-23 16:46:05 +07:00
}
2024-08-01 11:08:01 +07:00
$_bill = User::_billing();
$ui->assign('_bills', $_bill);
2024-08-01 11:08:01 +07:00
// Sync plan to router
if (isset($_GET['sync']) && !empty($_GET['sync'])) {
foreach ($_bill as $tur) {
2024-08-01 20:21:58 +07:00
if($tur['status'] == 'on'){
$p = ORM::for_table('tbl_plans')->findOne($tur['plan_id']);
if ($p) {
$c = ORM::for_table('tbl_customers')->findOne($tur['customer_id']);
if ($c) {
$dvc = Package::getDevice($p);
if ($_app_stage != 'demo') {
if (file_exists($dvc)) {
require_once $dvc;
(new $p['device'])->add_customer($c, $p);
} else {
new Exception(Lang::T("Devices Not Found"));
}
2024-08-01 11:08:01 +07:00
}
2024-08-01 20:21:58 +07:00
$log .= "DONE : $ptur[namebp], $tur[type], $tur[routers]<br>";
} else {
$log .= "Customer NOT FOUND : $tur[namebp], $tur[type], $tur[routers]<br>";
2024-08-01 11:08:01 +07:00
}
} else {
2024-08-01 20:21:58 +07:00
$log .= "PLAN NOT FOUND : $tur[namebp], $tur[type], $tur[routers]<br>";
2024-08-01 11:08:01 +07:00
}
}
}
r2(U . 'home', 's', $log);
}
2017-03-11 02:51:06 +07:00
if (isset($_GET['recharge']) && !empty($_GET['recharge'])) {
if ($user['status'] != 'Active') {
2024-05-17 09:25:26 +07:00
_alert(Lang::T('This account status') . ' : ' . Lang::T($user['status']), 'danger', "");
}
if (!empty(App::getTokenValue(_get('stoken')))) {
r2(U . "voucher/invoice/");
die();
}
2023-11-15 11:49:03 +07:00
$bill = ORM::for_table('tbl_user_recharges')->where('id', $_GET['recharge'])->where('username', $user['username'])->findOne();
if ($bill) {
if ($bill['routers'] == 'radius') {
$router = 'radius';
} else {
$routers = ORM::for_table('tbl_routers')->where('name', $bill['routers'])->find_one();
2024-04-14 21:13:11 +07:00
$router = $routers['id'];
}
2023-11-15 11:49:03 +07:00
if ($config['enable_balance'] == 'yes') {
$plan = ORM::for_table('tbl_plans')->find_one($bill['plan_id']);
if (!$plan['enabled']) {
r2(U . "home", 'e', 'Plan is not exists');
}
if ($user['balance'] > $plan['price']) {
r2(U . "order/pay/$router/$bill[plan_id]&stoken=" . _get('stoken'), 'e', 'Order Plan');
} else {
r2(U . "order/buy/$router/$bill[plan_id]", 'e', 'Order Plan');
2023-11-15 11:49:03 +07:00
}
} else {
r2(U . "order/buy/$router/$bill[plan_id]", 'e', 'Order Plan');
2023-09-21 16:04:18 +07:00
}
}
} else if (!empty(_get('extend'))) {
if ($user['status'] != 'Active') {
2024-05-17 09:25:26 +07:00
_alert(Lang::T('This account status') . ' : ' . Lang::T($user['status']), 'danger', "");
}
if (!$config['extend_expired']) {
r2(U . 'home', 'e', "cannot extend");
}
if (!empty(App::getTokenValue(_get('stoken')))) {
r2(U . 'home', 'e', "You already extend");
}
$id = _get('extend');
$tur = ORM::for_table('tbl_user_recharges')->where('customer_id', $user['id'])->where('id', $id)->find_one();
if ($tur) {
$m = date("m");
$path = $CACHE_PATH . DIRECTORY_SEPARATOR . "extends" . DIRECTORY_SEPARATOR;
2024-05-17 09:25:26 +07:00
if (!file_exists($path)) {
mkdir($path);
}
$path .= $user['id'] . ".txt";
if (file_exists($path)) {
// is already extend
$last = file_get_contents($path);
if ($last == $m) {
r2(U . 'home', 'e', "You already extend for this month");
}
}
if ($tur['status'] != 'on') {
$p = ORM::for_table('tbl_plans')->findOne($tur['plan_id']);
2024-06-05 17:19:24 +07:00
$dvc = Package::getDevice($p);
2024-06-20 14:16:09 +07:00
if ($_app_stage != 'demo') {
if (file_exists($dvc)) {
require_once $dvc;
(new $p['device'])->add_customer($user, $p);
} else {
new Exception(Lang::T("Devices Not Found"));
}
}
2024-06-05 17:19:24 +07:00
// make customer cannot extend again
2024-04-21 20:51:44 +07:00
$days = $config['extend_days'];
$expiration = date('Y-m-d', strtotime(" +$days day"));
$tur->expiration = $expiration;
$tur->status = "on";
$tur->save();
App::setToken(_get('stoken'), $id);
file_put_contents($path, $m);
2024-04-15 14:35:36 +07:00
_log("Customer $tur[customer_id] $tur[username] extend for $days days", "Customer", $user['id']);
2024-05-17 09:25:26 +07:00
Message::sendTelegram("#u$user[username] #extend #" . $p['type'] . " \n" . $p['name_plan'] .
"\nLocation: " . $p['routers'] .
"\nCustomer: " . $user['fullname'] .
"\nNew Expired: " . Lang::dateAndTimeFormat($expiration, $tur['time']));
r2(U . 'home', 's', "Extend until $expiration");
2024-05-17 09:25:26 +07:00
} else {
r2(U . 'home', 'e', "Plan is not expired");
}
} else {
r2(U . 'home', 'e', "Plan Not Found or Not Active");
}
} else if (isset($_GET['deactivate']) && !empty($_GET['deactivate'])) {
2023-11-15 11:49:03 +07:00
$bill = ORM::for_table('tbl_user_recharges')->where('id', $_GET['deactivate'])->where('username', $user['username'])->findOne();
2023-09-21 14:12:49 +07:00
if ($bill) {
2023-10-17 16:32:18 +07:00
$p = ORM::for_table('tbl_plans')->where('id', $bill['plan_id'])->find_one();
2024-06-05 17:19:24 +07:00
$dvc = Package::getDevice($p);
2024-06-20 14:16:09 +07:00
if ($_app_stage != 'demo') {
if (file_exists($dvc)) {
require_once $dvc;
(new $p['device'])->remove_customer($user, $p);
} else {
new Exception(Lang::T("Devices Not Found"));
}
2023-09-21 14:12:49 +07:00
}
$bill->status = 'off';
$bill->expiration = date('Y-m-d');
$bill->time = date('H:i:s');
$bill->save();
2024-04-15 14:35:36 +07:00
_log('User ' . $bill['username'] . ' Deactivate ' . $bill['namebp'], 'Customer', $bill['customer_id']);
Message::sendTelegram('User u' . $bill['username'] . ' Deactivate ' . $bill['namebp']);
r2(U . 'home', 's', 'Success deactivate ' . $bill['namebp']);
} else {
2023-09-21 14:12:49 +07:00
r2(U . 'home', 'e', 'No Active Plan');
}
}
2024-07-10 20:37:03 +07:00
if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'] && $_c['hs_auth_method'] != 'hchap')) {
2023-06-15 15:26:38 +07:00
$ui->assign('nux_mac', $_SESSION['nux-mac']);
$ui->assign('nux_ip', $_SESSION['nux-ip']);
2023-11-15 11:49:03 +07:00
$bill = ORM::for_table('tbl_user_recharges')->where('id', $_GET['id'])->where('username', $user['username'])->findOne();
2024-06-05 17:19:24 +07:00
$p = ORM::for_table('tbl_plans')->where('id', $bill['plan_id'])->find_one();
$dvc = Package::getDevice($p);
2024-06-20 14:16:09 +07:00
if ($_app_stage != 'demo') {
if (file_exists($dvc)) {
require_once $dvc;
if ($_GET['mikrotik'] == 'login') {
(new $p['device'])->connect_customer($user, $_SESSION['nux-ip'], $_SESSION['nux-mac'], $bill['routers']);
r2(U . 'home', 's', Lang::T('Login Request successfully'));
} else if ($_GET['mikrotik'] == 'logout') {
(new $p['device'])->disconnect_customer($user, $bill['routers']);
r2(U . 'home', 's', Lang::T('Logout Request successfully'));
}
} else {
new Exception(Lang::T("Devices Not Found"));
2024-06-05 17:19:24 +07:00
}
2023-06-15 15:26:38 +07:00
}
}
2022-09-11 11:02:30 +07:00
if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'] && !empty($_SESSION['nux-hostname']) && $_c['hs_auth_method'] == 'hchap')) {
$apkurl = (((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'onoff')|| $_SERVER['SERVER_PORT'] == 443)?'https':'http').'://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$ui->assign('nux_mac', $_SESSION['nux-mac']);
$ui->assign('nux_ip', $_SESSION['nux-ip']);
$keys = explode('-', $_SESSION['nux-key']);
$ui->assign('hostname', $_SESSION['nux-hostname']);
$ui->assign('apkurl', $apkurl);
$ui->assign('key1', $keys[0]);
$ui->assign('key2', $keys[1]);
$ui->assign('hchap', $_GET['hchap']);
$ui->assign('logged', $_GET['logged']);
if ($_app_stage != 'demo') {
if ($_GET['mikrotik'] == 'login') {
2024-07-22 15:19:29 +07:00
r2(U . 'home&hchap=true', 's', Lang::T('Login Request successfully'));
}
$getmsg = $_GET['msg'];
///get auth notification from mikrotik
if($getmsg == 'Connected') {
$msg .= Lang::T($getmsg);
2024-07-22 15:19:29 +07:00
r2(U . 'home&logged=1', 's', $msg);
} else if($getmsg){
$msg .= Lang::T($getmsg);
2024-07-22 15:19:29 +07:00
r2(U . 'home', 's', $msg);
}
}
}
if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'] && !empty($_SESSION['nux-hostname']) && $_c['hs_auth_method'] == 'hchap')) {
$apkurl = (((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'onoff')|| $_SERVER['SERVER_PORT'] == 443)?'https':'http').'://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$ui->assign('nux_mac', $_SESSION['nux-mac']);
$ui->assign('nux_ip', $_SESSION['nux-ip']);
$keys = explode('-', $_SESSION['nux-key']);
$ui->assign('hostname', $_SESSION['nux-hostname']);
$ui->assign('apkurl', $apkurl);
$ui->assign('key1', $keys[0]);
$ui->assign('key2', $keys[1]);
$ui->assign('hchap', $_GET['hchap']);
$ui->assign('logged', $_GET['logged']);
if ($_app_stage != 'demo') {
if ($_GET['mikrotik'] == 'login') {
2024-07-22 15:19:29 +07:00
r2(U . 'home&hchap=true', 's', Lang::T('Login Request successfully'));
}
$getmsg = $_GET['msg'];
///get auth notification from mikrotik
if($getmsg == 'Connected') {
$msg .= Lang::T($getmsg);
2024-07-22 15:19:29 +07:00
r2(U . 'home&logged=1', 's', $msg);
} else if($getmsg){
$msg .= Lang::T($getmsg);
2024-07-22 15:19:29 +07:00
r2(U . 'home', 's', $msg);
}
}
}
2022-09-11 11:02:30 +07:00
$ui->assign('unpaid', ORM::for_table('tbl_payment_gateway')
->where('username', $user['username'])
->where('status', 1)
->find_one());
2024-06-20 14:16:09 +07:00
$ui->assign('code', alphanumeric(_get('code'), "-"));
$abills = User::getAttributes("Bill");
$ui->assign('abills', $abills);
2022-09-18 00:00:40 +07:00
run_hook('view_customer_dashboard'); #HOOK
$ui->display('user-ui/dashboard.tpl');