Fix Demo mode

This commit is contained in:
Ibnu Maksum 2024-06-20 14:16:09 +07:00
parent 29ad9dec73
commit 28ec7883e2
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
10 changed files with 242 additions and 207 deletions

View File

@ -214,13 +214,15 @@ class Package
if ($isChangePlan || $b['status'] == 'off') {
$dvc = Package::getDevice($p);
if (file_exists($dvc) && $_app_stage != 'demo') {
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"));
}
}
}
$b->customer_id = $id_customer;
$b->username = $c['username'];
@ -297,12 +299,14 @@ class Package
} else {
// active plan not exists
$dvc = Package::getDevice($p);
if (file_exists($dvc) && $_app_stage != 'demo') {
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"));
}
}
$d = ORM::for_table('tbl_user_recharges')->create();
$d->customer_id = $id_customer;
@ -397,23 +401,6 @@ class Package
return $inv;
}
public static function changeTo($username, $plan_id, $from_id)
{
global $_app_stage;
$c = ORM::for_table('tbl_customers')->where('username', $username)->find_one();
$p = ORM::for_table('tbl_plans')->where('id', $plan_id)->find_one();
$b = ORM::for_table('tbl_user_recharges')->find_one($from_id);
$dvc = Package::getDevice($p);
if (file_exists($dvc) && $_app_stage != 'demo') {
require_once $dvc;
(new $p['device'])->change_customer($b, $c, $p);
} else {
new Exception(Lang::T("Devices Not Found"));
}
}
public static function _raid()
{
return ORM::for_table('tbl_transactions')->max('id') + 1;

View File

@ -44,13 +44,15 @@ switch ($action) {
// if has active plan, change the password to devices
$p = ORM::for_table('tbl_plans')->where('id', $c['plan_id'])->find_one();
$dvc = Package::getDevice($p);
if (file_exists($dvc) && $_app_stage != 'demo') {
if ($_app_stage != 'demo') {
if (file_exists($dvc)) {
require_once $dvc;
(new $p['device'])->remove_customer($c, $p);
} else {
new Exception(Lang::T("Devices Not Found"));
}
}
}
$d->password = $npass;
$d->save();

View File

@ -1,4 +1,5 @@
<?php
/**
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
* by https://t.me/ibnux
@ -19,7 +20,8 @@ switch ($action) {
if ($bill['type'] == 'Hotspot' && $bill['status'] == 'on') {
$p = ORM::for_table('tbl_plans')->find_one($bill['plan_id']);
$dvc = Package::getDevice($p);
if (file_exists($dvc) && $_app_stage != 'demo') {
if ($_app_stage != 'demo') {
if (file_exists($dvc)) {
require_once $dvc;
if ((new $p['device'])->online_customer($user, $bill['routers'])) {
die('<a href="' . U . 'home&mikrotik=logout&id=' . $bill['id'] . '" onclick="return confirm(\'' . Lang::T('Disconnect Internet?') . '\')" class="btn btn-success btn-xs btn-block">' . Lang::T('You are Online, Logout?') . '</a>');
@ -30,10 +32,10 @@ switch ($action) {
die(Lang::T('Your account not connected to internet'));
}
}
} else {
new Exception(Lang::T("Devices Not Found"));
}
}
} else {
die('--');
}

View File

@ -214,12 +214,14 @@ switch ($action) {
if ($p) {
$p = ORM::for_table('tbl_plans')->where('id', $c['plan_id'])->find_one();
$dvc = Package::getDevice($p);
if (file_exists($dvc) && $_app_stage != 'demo') {
if ($_app_stage != 'demo') {
if (file_exists($dvc)) {
require_once $dvc;
(new $p['device'])->change_customer($c, $p);
} else {
new Exception(Lang::T("Devices Not Found"));
}
}
$b->status = 'off';
$b->expiration = date('Y-m-d');
$b->time = date('H:i:s');
@ -242,7 +244,8 @@ switch ($action) {
if ($p) {
$routers[] = $b['routers'];
$dvc = Package::getDevice($p);
if (file_exists($dvc) && $_app_stage != 'demo') {
if ($_app_stage != 'demo') {
if (file_exists($dvc)) {
require_once $dvc;
(new $p['device'])->add_customer($c, $p);
} else {
@ -250,6 +253,7 @@ switch ($action) {
}
}
}
}
r2(U . 'customers/view/' . $id_customer, 's', 'Sync success to ' . implode(", ", $routers));
}
r2(U . 'customers/view/' . $id_customer, 'e', 'Cannot find active plan');
@ -330,13 +334,15 @@ switch ($action) {
$p = ORM::for_table('tbl_plans')->find_one($c['plan_id']);
if ($p) {
$dvc = Package::getDevice($p);
if (file_exists($dvc) && $_app_stage != 'demo') {
if ($_app_stage != 'demo') {
if (file_exists($dvc)) {
require_once $dvc;
(new $p['device'])->remove_customer($d, $p);
} else {
new Exception(Lang::T("Devices Not Found"));
}
}
}
try {
$c->delete();
} catch (Exception $e) {
@ -569,7 +575,8 @@ switch ($action) {
$c->save();
$p = ORM::for_table('tbl_plans')->find_one($c['plan_id']);
$dvc = Package::getDevice($p);
if (file_exists($dvc) && $_app_stage != 'demo') {
if ($_app_stage != 'demo') {
if (file_exists($dvc)) {
require_once $dvc;
(new $p['device'])->remove_customer($d, $p);
(new $p['device'])->add_customer($d, $p);
@ -578,6 +585,7 @@ switch ($action) {
}
}
}
}
r2(U . 'customers/view/' . $id, 's', 'User Updated Successfully');
} else {
r2(U . 'customers/edit/' . $id, 'e', $msg);

View File

@ -156,12 +156,14 @@ if (isset($_GET['recharge']) && !empty($_GET['recharge'])) {
if ($tur['status'] != 'on') {
$p = ORM::for_table('tbl_plans')->findOne($tur['plan_id']);
$dvc = Package::getDevice($p);
if (file_exists($dvc) && $_app_stage != 'demo') {
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"));
}
}
// make customer cannot extend again
$days = $config['extend_days'];
@ -188,12 +190,14 @@ if (isset($_GET['recharge']) && !empty($_GET['recharge'])) {
if ($bill) {
$p = ORM::for_table('tbl_plans')->where('id', $bill['plan_id'])->find_one();
$dvc = Package::getDevice($p);
if (file_exists($dvc) && $_app_stage != 'demo') {
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"));
}
}
$bill->status = 'off';
$bill->expiration = date('Y-m-d');
$bill->time = date('H:i:s');
@ -212,7 +216,8 @@ if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'])) {
$bill = ORM::for_table('tbl_user_recharges')->where('id', $_GET['id'])->where('username', $user['username'])->findOne();
$p = ORM::for_table('tbl_plans')->where('id', $bill['plan_id'])->find_one();
$dvc = Package::getDevice($p);
if (file_exists($dvc) && $_app_stage != 'demo') {
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']);
@ -225,6 +230,7 @@ if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'])) {
new Exception(Lang::T("Devices Not Found"));
}
}
}
$ui->assign('unpaid', ORM::for_table('tbl_payment_gateway')
->where('username', $user['username'])

View File

@ -97,15 +97,18 @@ switch ($do) {
try {
$p = ORM::for_table('tbl_plans')->where('id', $v1['id_plan'])->find_one();
$dvc = Package::getDevice($p);
if (file_exists($dvc) && $_app_stage != 'demo') {
if ($_app_stage != 'demo') {
if (file_exists($dvc)) {
require_once $dvc;
(new $p['device'])->connect_customer($user, $_SESSION['nux-ip'], $_SESSION['nux-mac'], $v1['routers']);
} else {
if (!empty($config['voucher_redirect'])) {
r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, now you can login"));
} else {
r2(U . "login", 's', Lang::T("Voucher activation success, now you can login"));
}
} else {
new Exception(Lang::T("Devices Not Found"));
}
}
if (!empty($config['voucher_redirect'])) {
r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, you are connected to internet"));
@ -141,15 +144,18 @@ switch ($do) {
try {
$p = ORM::for_table('tbl_plans')->where('id', $v1['id_plan'])->find_one();
$dvc = Package::getDevice($p);
if (file_exists($dvc) && $_app_stage != 'demo') {
if ($_app_stage != 'demo') {
if (file_exists($dvc)) {
require_once $dvc;
(new $p['device'])->connect_customer($user, $_SESSION['nux-ip'], $_SESSION['nux-mac'], $v1['routers']);
} else {
if (!empty($config['voucher_redirect'])) {
r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, now you can login"));
} else {
r2(U . "login", 's', Lang::T("Voucher activation success, now you can login"));
}
} else {
new Exception(Lang::T("Devices Not Found"));
}
}
if (!empty($config['voucher_redirect'])) {
r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, you are connected to internet"));

View File

@ -46,12 +46,14 @@ switch ($action) {
$c = ORM::for_table('tbl_customers')->findOne($tur['customer_id']);
if ($c) {
$dvc = Package::getDevice($p);
if (file_exists($dvc) && $_app_stage != 'demo') {
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"));
}
}
$log .= "DONE : $tur[username], $ptur[namebp], $tur[type], $tur[routers]<br>";
} else {
$log .= "Customer NOT FOUND : $tur[username], $tur[namebp], $tur[type], $tur[routers]<br>";
@ -267,12 +269,15 @@ switch ($action) {
if ($d) {
run_hook('delete_customer_active_plan'); #HOOK
$p = ORM::for_table('tbl_plans')->find_one($d['plan_id']);
if (file_exists($dvc) && $_app_stage != 'demo') {
$dvc = Package::getDevice($p);
if ($_app_stage != 'demo') {
if (file_exists($dvc)) {
require_once $dvc;
(new $p['device'])->remove_customer($c, $p);
} else {
new Exception(Lang::T("Devices Not Found"));
}
}
$d->delete();
_log('[' . $admin['username'] . ']: ' . 'Delete Plan for Customer ' . $c['username'] . ' [' . $in['plan_name'] . '][' . Lang::moneyFormat($in['price']) . ']', $admin['user_type'], $admin['id']);
r2(U . 'plan/list', 's', Lang::T('Data Deleted Successfully'));
@ -316,21 +321,25 @@ switch ($action) {
//remove from old plan
$p = ORM::for_table('tbl_plans')->find_one($oldPlanID);
$dvc = Package::getDevice($p);
if (file_exists($dvc) && $_app_stage != 'demo') {
if ($_app_stage != 'demo') {
if (file_exists($dvc)) {
require_once $dvc;
(new $p['device'])->remove_customer($customer, $p);
} else {
new Exception(Lang::T("Devices Not Found"));
}
}
//add new plan
$dvc = Package::getDevice($newPlan);
if (file_exists($dvc) && $_app_stage != 'demo') {
if ($_app_stage != 'demo') {
if (file_exists($dvc)) {
require_once $dvc;
(new $newPlan['device'])->add_customer($customer, $newPlan);
} else {
new Exception(Lang::T("Devices Not Found"));
}
}
}
$d->save();
_log('[' . $admin['username'] . ']: ' . 'Edit Plan for Customer ' . $d['username'] . ' to [' . $d['namebp'] . '][' . Lang::moneyFormat($p['price']) . ']', $admin['user_type'], $admin['id']);
r2(U . 'plan/list', 's', Lang::T('Data Updated Successfully'));
@ -585,8 +594,7 @@ switch ($action) {
$msg .= 'The Length Code must be a more than 6 for numbers' . '<br>';
}
$vouchers = generateUniqueNumericVouchers($numbervoucher, $lengthcode);
}
else {
} else {
for ($i = 0; $i < $numbervoucher; $i++) {
$code = strtoupper(substr(md5(time() . rand(10000, 99999)), 0, $lengthcode));
if ($voucher_format == 'low') {
@ -595,7 +603,6 @@ switch ($action) {
$code = Lang::randomUpLowCase($code);
}
$vouchers[] = $code;
}
}
@ -793,12 +800,14 @@ switch ($action) {
$c = ORM::for_table('tbl_customers')->findOne($tur['customer_id']);
$p = ORM::for_table('tbl_plans')->find_one($d['plan_id']);
$dvc = Package::getDevice($p);
if (file_exists($dvc) && $_app_stage != 'demo') {
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"));
}
}
_log("$admin[fullname] extend Customer $tur[customer_id] $tur[username] for $days days", $admin['user_type'], $admin['id']);
r2(U . 'plan', 's', "Extend until $expiration");
} else {

View File

@ -24,13 +24,15 @@ switch ($action) {
$router = '';
foreach ($plans as $plan) {
$dvc = Package::getDevice($plan);
if (file_exists($dvc) && $_app_stage != 'demo') {
if ($_app_stage != 'demo') {
if (file_exists($dvc)) {
require_once $dvc;
(new $p['device'])->add_plan($plan);
} else {
new Exception(Lang::T("Devices Not Found"));
}
}
}
r2(U . 'services/hotspot', 's', $log);
} else if ($routes['2'] == 'pppoe') {
$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();
@ -38,13 +40,15 @@ switch ($action) {
$router = '';
foreach ($plans as $plan) {
$dvc = Package::getDevice($plan);
if (file_exists($dvc) && $_app_stage != 'demo') {
if ($_app_stage != 'demo') {
if (file_exists($dvc)) {
require_once $dvc;
(new $p['device'])->add_plan($plan);
} else {
new Exception(Lang::T("Devices Not Found"));
}
}
}
r2(U . 'services/pppoe', 's', $log);
}
r2(U . 'services/hotspot', 'w', 'Unknown command');
@ -128,12 +132,14 @@ switch ($action) {
if ($d) {
run_hook('delete_plan'); #HOOK
$dvc = Package::getDevice($d);
if (file_exists($dvc) && $_app_stage != 'demo') {
if ($_app_stage != 'demo') {
if (file_exists($dvc)) {
require_once $dvc;
(new $p['device'])->remove_plan($d);
} else {
new Exception(Lang::T("Devices Not Found"));
}
}
$d->delete();
r2(U . 'services/hotspot', 's', Lang::T('Data Deleted Successfully'));
@ -221,13 +227,14 @@ switch ($action) {
$d->save();
$dvc = Package::getDevice($d);
if (file_exists($dvc) && $_app_stage != 'demo') {
if ($_app_stage != 'demo') {
if (file_exists($dvc)) {
require_once $dvc;
(new $p['device'])->add_plan($d);
} else {
new Exception(Lang::T("Devices Not Found"));
}
}
r2(U . 'services/edit/' . $d->id(), 's', Lang::T('Data Created Successfully'));
} else {
r2(U . 'services/add', 'e', $msg);
@ -322,13 +329,14 @@ switch ($action) {
$d->save();
$dvc = Package::getDevice($d);
if (file_exists($dvc) && $_app_stage != 'demo') {
if ($_app_stage != 'demo') {
if (file_exists($dvc)) {
require_once $dvc;
(new $d['device'])->update_plan($old, $d);
} else {
new Exception(Lang::T("Devices Not Found"));
}
}
r2(U . 'services/hotspot', 's', Lang::T('Data Updated Successfully'));
} else {
r2(U . 'services/edit/' . $id, 'e', $msg);
@ -426,12 +434,14 @@ switch ($action) {
run_hook('delete_ppoe'); #HOOK
$dvc = Package::getDevice($d);
if (file_exists($dvc) && $_app_stage != 'demo') {
if ($_app_stage != 'demo') {
if (file_exists($dvc)) {
require_once $dvc;
(new $p['device'])->remove_plan($d);
} else {
new Exception(Lang::T("Devices Not Found"));
}
}
$d->delete();
r2(U . 'services/pppoe', 's', Lang::T('Data Deleted Successfully'));
@ -524,13 +534,14 @@ switch ($action) {
$d->save();
$dvc = Package::getDevice($d);
if (file_exists($dvc) && $_app_stage != 'demo') {
if ($_app_stage != 'demo') {
if (file_exists($dvc)) {
require_once $dvc;
(new $p['device'])->add_plan($d);
} else {
new Exception(Lang::T("Devices Not Found"));
}
}
r2(U . 'services/pppoe', 's', Lang::T('Data Created Successfully'));
} else {
r2(U . 'services/pppoe-add', 'e', $msg);
@ -614,13 +625,14 @@ switch ($action) {
$d->save();
$dvc = Package::getDevice($d);
if (file_exists($dvc) && $_app_stage != 'demo') {
if ($_app_stage != 'demo') {
if (file_exists($dvc)) {
require_once $dvc;
(new $d['device'])->update_plan($old, $d);
} else {
new Exception(Lang::T("Devices Not Found"));
}
}
r2(U . 'services/pppoe', 's', Lang::T('Data Updated Successfully'));
} else {
r2(U . 'services/pppoe-edit/' . $id, 'e', $msg);

View File

@ -33,13 +33,15 @@ foreach ($d as $ds) {
$c = ORM::for_table('tbl_customers')->where('id', $ds['customer_id'])->find_one();
$p = ORM::for_table('tbl_plans')->where('id', $u['plan_id'])->find_one();
$dvc = Package::getDevice($p);
if (file_exists($dvc) && $_app_stage != 'demo') {
if($_app_stage != 'demo'){
if (file_exists($dvc)) {
require_once $dvc;
(new $p['device'])->remove_customer($c, $p);
} else {
echo "Cron error Devices $p[device] not found, cannot disconnect $c[username]";
Message::sendTelegram("Cron error Devices $p[device] not found, cannot disconnect $c[username]");
}
}
echo Message::sendPackageNotification($c, $u['namebp'], $p['price'], $textExpired, $config['user_notification_expired']) . "\n";
//update database user dengan status off
$u->status = 'off';

View File

@ -644,5 +644,6 @@
"Category": "Category",
"later": "later",
"Package_Details": "Package Details",
"Summary": "Summary"
"Summary": "Summary",
"Devices_Not_Found": "Devices Not Found"
}