From 6a4ac274d1b9303352345d2ac7e8f29d2f7709f1 Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Wed, 12 Jun 2024 15:39:43 +0700 Subject: [PATCH] check if demo or not --- system/autoload/Package.php | 10 ++++---- system/controllers/accounts.php | 2 +- system/controllers/autoload_user.php | 2 +- system/controllers/customers.php | 8 +++---- system/controllers/home.php | 6 ++--- system/controllers/login.php | 4 ++-- system/controllers/plan.php | 6 ++--- system/controllers/services.php | 16 ++++++------- system/cron.php | 2 +- system/devices/MikrotikHotspot.php | 36 ---------------------------- system/devices/MikrotikPppoe.php | 36 ---------------------------- system/devices/radius.php | 16 ------------- system/devices/readme.md | 36 ---------------------------- 13 files changed, 28 insertions(+), 152 deletions(-) diff --git a/system/autoload/Package.php b/system/autoload/Package.php index 012f0d48..dcd296eb 100644 --- a/system/autoload/Package.php +++ b/system/autoload/Package.php @@ -20,7 +20,7 @@ class Package */ public static function rechargeUser($id_customer, $router_name, $plan_id, $gateway, $channel, $note = '') { - global $config, $admin, $c, $p, $b, $t, $d, $zero, $trx, $DEVICE_PATH; + global $config, $admin, $c, $p, $b, $t, $d, $zero, $trx, $_app_stage; $date_now = date("Y-m-d H:i:s"); $date_only = date("Y-m-d"); $time_only = date("H:i:s"); @@ -222,7 +222,7 @@ class Package if ($isChangePlan || $b['status'] == 'off') { $dvc = Package::getDevice($p); - if (file_exists($dvc)) { + if (file_exists($dvc) && $_app_stage != 'demo') { require_once $dvc; (new $p['device'])->add_customer($c, $p); } else { @@ -305,7 +305,7 @@ class Package } else { // active plan not exists $dvc = Package::getDevice($p); - if (file_exists($dvc)) { + if (file_exists($dvc) && $_app_stage != 'demo') { require_once $dvc; (new $p['device'])->add_customer($c, $p); } else { @@ -407,13 +407,13 @@ class Package public static function changeTo($username, $plan_id, $from_id) { - global $DEVICE_PATH; + 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)) { + if (file_exists($dvc) && $_app_stage != 'demo') { require_once $dvc; (new $p['device'])->change_customer($b, $c, $p); } else { diff --git a/system/controllers/accounts.php b/system/controllers/accounts.php index 8c582f4d..c72842f2 100644 --- a/system/controllers/accounts.php +++ b/system/controllers/accounts.php @@ -44,7 +44,7 @@ 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)) { + if (file_exists($dvc) && $_app_stage != 'demo') { require_once $dvc; (new $p['device'])->remove_customer($c, $p); } else { diff --git a/system/controllers/autoload_user.php b/system/controllers/autoload_user.php index b75010f4..f8ad6d42 100644 --- a/system/controllers/autoload_user.php +++ b/system/controllers/autoload_user.php @@ -18,7 +18,7 @@ switch ($action) { $bill = ORM::for_table('tbl_user_recharges')->where('id', $routes['2'])->where('username', $user['username'])->findOne(); if ($bill['type'] == 'Hotspot' && $bill['status'] == 'on') { $dvc = Package::getDevice($d); - if (file_exists($dvc)) { + if (file_exists($dvc) && $_app_stage != 'demo') { require_once $dvc; if ((new $d['device'])->online_customer($user, $bill['routers'])) { die(''.Lang::T('You are Online, Logout?').''); diff --git a/system/controllers/customers.php b/system/controllers/customers.php index 5087c2a0..9172b8fe 100644 --- a/system/controllers/customers.php +++ b/system/controllers/customers.php @@ -214,7 +214,7 @@ 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)) { + if (file_exists($dvc) && $_app_stage != 'demo') { require_once $dvc; (new $p['device'])->change_customer($c, $p); } else { @@ -242,7 +242,7 @@ switch ($action) { if ($p) { $routers[] = $b['routers']; $dvc = Package::getDevice($p); - if (file_exists($dvc)) { + if (file_exists($dvc) && $_app_stage != 'demo') { require_once $dvc; (new $p['device'])->add_customer($c, $p); } else { @@ -330,7 +330,7 @@ switch ($action) { $p = ORM::for_table('tbl_plans')->find_one($c['plan_id']); if($p){ $dvc = Package::getDevice($p); - if (file_exists($dvc)) { + if (file_exists($dvc) && $_app_stage != 'demo') { require_once $dvc; (new $p['device'])->remove_customer($d, $p); } else { @@ -569,7 +569,7 @@ switch ($action) { $c->save(); $p = ORM::for_table('tbl_plans')->find_one($c['plan_id']); $dvc = Package::getDevice($p); - if (file_exists($dvc)) { + if (file_exists($dvc) && $_app_stage != 'demo') { require_once $dvc; (new $p['device'])->remove_customer($d, $p); (new $p['device'])->add_customer($d, $p); diff --git a/system/controllers/home.php b/system/controllers/home.php index 7c4cc59d..ce172d87 100644 --- a/system/controllers/home.php +++ b/system/controllers/home.php @@ -156,7 +156,7 @@ 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)) { + if (file_exists($dvc) && $_app_stage != 'demo') { require_once $dvc; (new $p['device'])->add_customer($user, $p); } else { @@ -188,7 +188,7 @@ 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)) { + if (file_exists($dvc) && $_app_stage != 'demo') { require_once $dvc; (new $p['device'])->remove_customer($user, $p); } else { @@ -212,7 +212,7 @@ 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)) { + if (file_exists($dvc) && $_app_stage != 'demo') { require_once $dvc; if ($_GET['mikrotik'] == 'login') { (new $p['device'])->connect_customer($user, $_SESSION['nux-ip'], $_SESSION['nux-mac'], $bill['routers']); diff --git a/system/controllers/login.php b/system/controllers/login.php index f093514b..f86f752d 100644 --- a/system/controllers/login.php +++ b/system/controllers/login.php @@ -97,7 +97,7 @@ switch ($do) { try { $p = ORM::for_table('tbl_plans')->where('id', $v1['id_plan'])->find_one(); $dvc = Package::getDevice($p); - if (file_exists($dvc)) { + if (file_exists($dvc) && $_app_stage != 'demo') { require_once $dvc; (new $p['device'])->connect_customer($user, $_SESSION['nux-ip'], $_SESSION['nux-mac'], $v1['routers']); } else { @@ -141,7 +141,7 @@ switch ($do) { try { $p = ORM::for_table('tbl_plans')->where('id', $v1['id_plan'])->find_one(); $dvc = Package::getDevice($p); - if (file_exists($dvc)) { + if (file_exists($dvc) && $_app_stage != 'demo') { require_once $dvc; (new $p['device'])->connect_customer($user, $_SESSION['nux-ip'], $_SESSION['nux-mac'], $v1['routers']); } else { diff --git a/system/controllers/plan.php b/system/controllers/plan.php index 3805721f..c5d083a4 100644 --- a/system/controllers/plan.php +++ b/system/controllers/plan.php @@ -44,7 +44,7 @@ switch ($action) { $p = ORM::for_table('tbl_plans')->findOne($plan['plan_id']); $c = ORM::for_table('tbl_customers')->findOne($plan['customer_id']); $dvc = Package::getDevice($plan); - if (file_exists($dvc)) { + if (file_exists($dvc) && $_app_stage != 'demo') { require_once $dvc; (new $p['device'])->add_customer($c, $p); } else { @@ -258,7 +258,7 @@ 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)) { + if (file_exists($dvc) && $_app_stage != 'demo') { require_once $dvc; (new $p['device'])->remove_customer($c, $p); } else { @@ -774,7 +774,7 @@ 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)) { + if (file_exists($dvc) && $_app_stage != 'demo') { require_once $dvc; (new $p['device'])->add_customer($c, $p); } else { diff --git a/system/controllers/services.php b/system/controllers/services.php index 24710b43..c2bf7a9e 100644 --- a/system/controllers/services.php +++ b/system/controllers/services.php @@ -24,7 +24,7 @@ switch ($action) { $router = ''; foreach ($plans as $plan) { $dvc = Package::getDevice($plan); - if (file_exists($dvc)) { + if (file_exists($dvc) && $_app_stage != 'demo') { require_once $dvc; (new $p['device'])->add_plan($plan); } else { @@ -38,7 +38,7 @@ switch ($action) { $router = ''; foreach ($plans as $plan) { $dvc = Package::getDevice($plan); - if (file_exists($dvc)) { + if (file_exists($dvc) && $_app_stage != 'demo') { require_once $dvc; (new $p['device'])->add_plan($plan); } else { @@ -128,7 +128,7 @@ switch ($action) { if ($d) { run_hook('delete_plan'); #HOOK $dvc = Package::getDevice($d); - if (file_exists($dvc)) { + if (file_exists($dvc) && $_app_stage != 'demo') { require_once $dvc; (new $p['device'])->remove_plan($d); } else { @@ -212,7 +212,7 @@ switch ($action) { $d->save(); $dvc = Package::getDevice($d); - if (file_exists($dvc)) { + if (file_exists($dvc) && $_app_stage != 'demo') { require_once $dvc; (new $p['device'])->add_plan($d); } else { @@ -304,7 +304,7 @@ switch ($action) { $d->save(); $dvc = Package::getDevice($d); - if (file_exists($dvc)) { + if (file_exists($dvc) && $_app_stage != 'demo') { require_once $dvc; (new $d['device'])->update_plan($old, $d); } else { @@ -408,7 +408,7 @@ switch ($action) { run_hook('delete_ppoe'); #HOOK $dvc = Package::getDevice($d); - if (file_exists($dvc)) { + if (file_exists($dvc) && $_app_stage != 'demo') { require_once $dvc; (new $p['device'])->remove_plan($d); } else { @@ -497,7 +497,7 @@ switch ($action) { $d->save(); $dvc = Package::getDevice($d); - if (file_exists($dvc)) { + if (file_exists($dvc) && $_app_stage != 'demo') { require_once $dvc; (new $p['device'])->add_plan($d); } else { @@ -578,7 +578,7 @@ switch ($action) { $d->save(); $dvc = Package::getDevice($d); - if (file_exists($dvc)) { + if (file_exists($dvc) && $_app_stage != 'demo') { require_once $dvc; (new $d['device'])->update_plan($old, $d); } else { diff --git a/system/cron.php b/system/cron.php index 099c315d..ea39a6dc 100644 --- a/system/cron.php +++ b/system/cron.php @@ -33,7 +33,7 @@ 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)) { + if (file_exists($dvc) && $_app_stage != 'demo') { require_once $dvc; (new $p['device'])->remove_customer($c, $p); } else { diff --git a/system/devices/MikrotikHotspot.php b/system/devices/MikrotikHotspot.php index 03117646..8aab6d32 100644 --- a/system/devices/MikrotikHotspot.php +++ b/system/devices/MikrotikHotspot.php @@ -15,10 +15,6 @@ class MikrotikHotspot function add_customer($customer, $plan) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } $mikrotik = $this->info($plan['routers']); $client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); $this->removeHotspotUser($client, $customer['username']); @@ -28,10 +24,6 @@ class MikrotikHotspot function remove_customer($customer, $plan) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } $mikrotik = $this->info($plan['routers']); $client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); if (!empty($plan['plan_expired'])) { @@ -45,10 +37,6 @@ class MikrotikHotspot function change_customer($customer, $plan) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } $mikrotik = $this->info($plan['routers']); $client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); $this->removeHotspotUser($client, $customer['username']); @@ -58,10 +46,6 @@ class MikrotikHotspot function add_plan($plan) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } $mikrotik = $this->info($plan['routers']); $client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); $bw = ORM::for_table("tbl_bandwidth")->find_one($plan['id_bw']); @@ -90,10 +74,6 @@ class MikrotikHotspot function online_customer($customer, $router_name) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } $mikrotik = $this->info($router_name); $client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); $printRequest = new RouterOS\Request( @@ -105,10 +85,6 @@ class MikrotikHotspot function connect_customer($customer, $ip, $mac_address, $router_name) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } $mikrotik = $this->info($router_name); $client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); $addRequest = new RouterOS\Request('/ip/hotspot/active/login'); @@ -123,10 +99,6 @@ class MikrotikHotspot function disconnect_customer($customer, $router_name) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } $mikrotik = $this->info($router_name); $client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); $printRequest = new RouterOS\Request( @@ -144,10 +116,6 @@ class MikrotikHotspot function update_plan($old_plan, $new_plan) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } $mikrotik = $this->info($new_plan['routers']); $client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); @@ -187,10 +155,6 @@ class MikrotikHotspot function remove_plan($plan) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } $mikrotik = $this->info($plan['routers']); $client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); $printRequest = new RouterOS\Request( diff --git a/system/devices/MikrotikPppoe.php b/system/devices/MikrotikPppoe.php index 6ad8ba51..bc333288 100644 --- a/system/devices/MikrotikPppoe.php +++ b/system/devices/MikrotikPppoe.php @@ -15,10 +15,6 @@ class MikrotikPppoe function add_customer($customer, $plan) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } $mikrotik = $this->info($plan['routers']); $client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); $this->removePpoeUser($client, $customer['username']); @@ -28,10 +24,6 @@ class MikrotikPppoe function remove_customer($customer, $plan) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } $mikrotik = $this->info($plan['routers']); $client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); if (!empty($plan['plan_expired'])) { @@ -45,10 +37,6 @@ class MikrotikPppoe function change_customer($customer, $plan) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } $mikrotik = $this->info($plan['routers']); $client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); $this->removePpoeUser($client, $customer['username']); @@ -59,10 +47,6 @@ class MikrotikPppoe function add_plan($plan) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } $mikrotik = $this->info($plan['routers']); $client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); @@ -96,10 +80,6 @@ class MikrotikPppoe function update_plan($old_name, $new_plan) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } $mikrotik = $this->info($new_plan['routers']); $client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); @@ -140,10 +120,6 @@ class MikrotikPppoe function remove_plan($plan) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } $mikrotik = $this->info($plan['routers']); $client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); $printRequest = new RouterOS\Request( @@ -221,10 +197,6 @@ class MikrotikPppoe function online_customer($customer, $router_name) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } $mikrotik = $this->info($router_name); $client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); $printRequest = new RouterOS\Request( @@ -237,18 +209,10 @@ class MikrotikPppoe function connect_customer($customer, $ip, $mac_address, $router_name) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } } function disconnect_customer($customer, $router_name) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } } function info($name) diff --git a/system/devices/radius.php b/system/devices/radius.php index 2579b5f0..5c392d22 100644 --- a/system/devices/radius.php +++ b/system/devices/radius.php @@ -19,10 +19,6 @@ class Radius { function remove_customer($customer, $plan) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } if (empty($plan['plan_expired'])) { $p = ORM::for_table("tbl_plans")->find_one($plan['plan_expired']); $this->customerDeactivate($customer['username']); @@ -89,26 +85,14 @@ class Radius { function online_customer($customer, $router_name) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } } function connect_customer($customer, $ip, $mac_address, $router_name) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } } function disconnect_customer($customer, $router_name) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } } public function getTableNas() diff --git a/system/devices/readme.md b/system/devices/readme.md index 783a3140..12e626ee 100644 --- a/system/devices/readme.md +++ b/system/devices/readme.md @@ -9,74 +9,38 @@ class FileName { function add_customer($customer, $plan) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } } function remove_customer($customer, $plan) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } } function change_customer($customer, $plan) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } } function add_plan($plan) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } } function update_plan($old_name, $plan) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } } function remove_plan($plan) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } } function online_customer($customer, $router_name) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } } function connect_customer($customer, $ip, $mac_address, $router_name) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } } function disconnect_customer($customer, $router_name) { - global $_app_stage; - if ($_app_stage == 'demo') { - return; - } } }