From 28ec7883e20cfb5a6dce5b3e51a00219b6f4a959 Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Thu, 20 Jun 2024 14:16:09 +0700 Subject: [PATCH] Fix Demo mode --- system/autoload/Package.php | 43 ++++------ system/controllers/accounts.php | 12 +-- system/controllers/autoload_user.php | 26 +++--- system/controllers/customers.php | 52 ++++++----- system/controllers/home.php | 48 ++++++----- system/controllers/login.php | 36 ++++---- system/controllers/plan.php | 91 +++++++++++--------- system/controllers/services.php | 124 +++++++++++++++------------ system/cron.php | 14 +-- system/lan/english.json | 3 +- 10 files changed, 242 insertions(+), 207 deletions(-) diff --git a/system/autoload/Package.php b/system/autoload/Package.php index a2f9039a..1ec76e95 100644 --- a/system/autoload/Package.php +++ b/system/autoload/Package.php @@ -68,7 +68,7 @@ class Package if ($p['prepaid'] == 'no') { $day_exp = $p['expired_date']; } - if(empty($day_exp)){ + if (empty($day_exp)) { $day_exp = 20; } @@ -214,11 +214,13 @@ class Package if ($isChangePlan || $b['status'] == 'off') { $dvc = Package::getDevice($p); - if (file_exists($dvc) && $_app_stage != 'demo') { - require_once $dvc; - (new $p['device'])->add_customer($c, $p); - } else { - new Exception(Lang::T("Devices Not Found")); + 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")); + } } } @@ -297,11 +299,13 @@ class Package } else { // active plan not exists $dvc = Package::getDevice($p); - if (file_exists($dvc) && $_app_stage != 'demo') { - require_once $dvc; - (new $p['device'])->add_customer($c, $p); - } else { - new Exception(Lang::T("Devices Not Found")); + 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(); @@ -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; diff --git a/system/controllers/accounts.php b/system/controllers/accounts.php index c72842f2..a0bb1fa9 100644 --- a/system/controllers/accounts.php +++ b/system/controllers/accounts.php @@ -44,11 +44,13 @@ 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') { - require_once $dvc; - (new $p['device'])->remove_customer($c, $p); - } else { - new Exception(Lang::T("Devices Not Found")); + 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; diff --git a/system/controllers/autoload_user.php b/system/controllers/autoload_user.php index 1e347388..5fabf893 100644 --- a/system/controllers/autoload_user.php +++ b/system/controllers/autoload_user.php @@ -1,4 +1,5 @@ find_one($bill['plan_id']); $dvc = Package::getDevice($p); - if (file_exists($dvc) && $_app_stage != 'demo') { - require_once $dvc; - if ((new $p['device'])->online_customer($user, $bill['routers'])) { - die(''.Lang::T('You are Online, Logout?').''); - } else { - if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'])) { - die(''.Lang::T('Not Online, Login now?').''); - }else{ - die(Lang::T('Your account not connected to internet')); + if ($_app_stage != 'demo') { + if (file_exists($dvc)) { + require_once $dvc; + if ((new $p['device'])->online_customer($user, $bill['routers'])) { + die('' . Lang::T('You are Online, Logout?') . ''); + } else { + if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'])) { + die('' . Lang::T('Not Online, Login now?') . ''); + } else { + die(Lang::T('Your account not connected to internet')); + } } + } else { + new Exception(Lang::T("Devices Not Found")); } - - } else { - new Exception(Lang::T("Devices Not Found")); } } else { die('--'); diff --git a/system/controllers/customers.php b/system/controllers/customers.php index 9172b8fe..ae01655b 100644 --- a/system/controllers/customers.php +++ b/system/controllers/customers.php @@ -214,11 +214,13 @@ 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') { - require_once $dvc; - (new $p['device'])->change_customer($c, $p); - } else { - new Exception(Lang::T("Devices Not Found")); + 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'); @@ -242,11 +244,13 @@ switch ($action) { if ($p) { $routers[] = $b['routers']; $dvc = Package::getDevice($p); - if (file_exists($dvc) && $_app_stage != 'demo') { - require_once $dvc; - (new $p['device'])->add_customer($c, $p); - } else { - new Exception(Lang::T("Devices Not Found")); + 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")); + } } } } @@ -328,13 +332,15 @@ switch ($action) { $c = ORM::for_table('tbl_user_recharges')->where('username', $d['username'])->find_one(); if ($c) { $p = ORM::for_table('tbl_plans')->find_one($c['plan_id']); - if($p){ + if ($p) { $dvc = Package::getDevice($p); - if (file_exists($dvc) && $_app_stage != 'demo') { - require_once $dvc; - (new $p['device'])->remove_customer($d, $p); - } else { - new Exception(Lang::T("Devices Not Found")); + 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 { @@ -569,12 +575,14 @@ 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') { - require_once $dvc; - (new $p['device'])->remove_customer($d, $p); - (new $p['device'])->add_customer($d, $p); - } else { - new Exception(Lang::T("Devices Not Found")); + 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); + } else { + new Exception(Lang::T("Devices Not Found")); + } } } } diff --git a/system/controllers/home.php b/system/controllers/home.php index bce30af5..f7b8983d 100644 --- a/system/controllers/home.php +++ b/system/controllers/home.php @@ -156,11 +156,13 @@ 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') { - require_once $dvc; - (new $p['device'])->add_customer($user, $p); - } else { - new Exception(Lang::T("Devices Not Found")); + 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 @@ -188,11 +190,13 @@ 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') { - require_once $dvc; - (new $p['device'])->remove_customer($user, $p); - } else { - new Exception(Lang::T("Devices Not Found")); + 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'); @@ -212,17 +216,19 @@ 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') { - 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')); + 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")); } - } else { - new Exception(Lang::T("Devices Not Found")); } } @@ -230,6 +236,6 @@ $ui->assign('unpaid', ORM::for_table('tbl_payment_gateway') ->where('username', $user['username']) ->where('status', 1) ->find_one()); - $ui->assign('code', alphanumeric(_get('code'),"-")); +$ui->assign('code', alphanumeric(_get('code'), "-")); run_hook('view_customer_dashboard'); #HOOK $ui->display('user-dashboard.tpl'); diff --git a/system/controllers/login.php b/system/controllers/login.php index e04370ce..cc26883d 100644 --- a/system/controllers/login.php +++ b/system/controllers/login.php @@ -97,14 +97,17 @@ 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') { - 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")); + 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']); + 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 { - r2(U . "login", 's', Lang::T("Voucher activation success, now you can login")); + new Exception(Lang::T("Devices Not Found")); } } if (!empty($config['voucher_redirect'])) { @@ -141,14 +144,17 @@ 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') { - 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")); + 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']); + 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 { - r2(U . "login", 's', Lang::T("Voucher activation success, now you can login")); + new Exception(Lang::T("Devices Not Found")); } } if (!empty($config['voucher_redirect'])) { @@ -182,7 +188,7 @@ switch ($do) { default: run_hook('customer_view_login'); #HOOK if ($config['disable_registration'] == 'yes') { - $ui->assign('code', alphanumeric(_get('code'),"-")); + $ui->assign('code', alphanumeric(_get('code'), "-")); $ui->display('user-login-noreg.tpl'); } else { $ui->display('user-login.tpl'); diff --git a/system/controllers/plan.php b/system/controllers/plan.php index c71f2bae..27b25e06 100644 --- a/system/controllers/plan.php +++ b/system/controllers/plan.php @@ -42,21 +42,23 @@ switch ($action) { $router = ''; foreach ($turs as $tur) { $p = ORM::for_table('tbl_plans')->findOne($tur['plan_id']); - if($p){ + if ($p) { $c = ORM::for_table('tbl_customers')->findOne($tur['customer_id']); - if($c){ + if ($c) { $dvc = Package::getDevice($p); - if (file_exists($dvc) && $_app_stage != 'demo') { - require_once $dvc; - (new $p['device'])->add_customer($c, $p); - } else { - new Exception(Lang::T("Devices Not Found")); + 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]
"; - }else{ + } else { $log .= "Customer NOT FOUND : $tur[username], $tur[namebp], $tur[type], $tur[routers]
"; } - }else{ + } else { $log .= "PLAN NOT FOUND : $tur[username], $tur[namebp], $tur[type], $tur[routers]
"; } } @@ -71,7 +73,7 @@ switch ($action) { } $usings = explode(',', $config['payment_usings']); $usings = array_filter(array_unique($usings)); - if(count($usings)==0){ + if (count($usings) == 0) { $usings[] = Lang::T('Cash'); } $ui->assign('usings', $usings); @@ -117,7 +119,7 @@ switch ($action) { } $usings = explode(',', $config['payment_usings']); $usings = array_filter(array_unique($usings)); - if(count($usings)==0){ + if (count($usings) == 0) { $usings[] = Lang::T('Cash'); } $ui->assign('usings', $usings); @@ -267,11 +269,14 @@ 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') { - require_once $dvc; - (new $p['device'])->remove_customer($c, $p); - } else { - new Exception(Lang::T("Devices Not Found")); + $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']); @@ -316,19 +321,23 @@ 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') { - require_once $dvc; - (new $p['device'])->remove_customer($customer, $p); - } else { - new Exception(Lang::T("Devices Not Found")); + 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') { - require_once $dvc; - (new $newPlan['device'])->add_customer($customer, $newPlan); - } else { - new Exception(Lang::T("Devices Not Found")); + 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(); @@ -580,13 +589,12 @@ switch ($action) { } run_hook('create_voucher'); #HOOK $vouchers = []; - if($voucher_format == 'numbers'){ - if (strlen($lengthcode)<6) { + if ($voucher_format == 'numbers') { + if (strlen($lengthcode) < 6) { $msg .= 'The Length Code must be a more than 6 for numbers' . '
'; } $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,11 +603,10 @@ switch ($action) { $code = Lang::randomUpLowCase($code); } $vouchers[] = $code; - } } - foreach($vouchers as $code){ + foreach ($vouchers as $code) { $d = ORM::for_table('tbl_voucher')->create(); $d->type = $type; $d->routers = $server; @@ -758,7 +765,7 @@ switch ($action) { $c = ORM::for_table('tbl_customers')->where('id', $user)->find_one(); $in = ORM::for_table('tbl_transactions')->where('username', $c['username'])->order_by_desc('id')->find_one(); Package::createInvoice($in); - if(!empty($stoken)){ + if (!empty($stoken)) { App::setToken($stoken, $in['id']); } $ui->display('invoice.tpl'); @@ -793,15 +800,17 @@ 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') { - require_once $dvc; - (new $p['device'])->add_customer($c, $p); - } else { - new Exception(Lang::T("Devices Not Found")); + 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{ + } else { r2(U . 'plan', 's', "Customer is not expired yet"); } break; @@ -811,8 +820,8 @@ switch ($action) { $search = _post('search'); if ($search != '') { $query = ORM::for_table('tbl_user_recharges') - ->whereRaw("username LIKE '%$search%' OR namebp LIKE '%$search%' OR method LIKE '%$search%' OR routers LIKE '%$search%' OR type LIKE '%$search%'") - ->order_by_desc('id'); + ->whereRaw("username LIKE '%$search%' OR namebp LIKE '%$search%' OR method LIKE '%$search%' OR routers LIKE '%$search%' OR type LIKE '%$search%'") + ->order_by_desc('id'); $d = Paginator::findMany($query, ['search' => $search]); } else { $query = ORM::for_table('tbl_user_recharges')->order_by_desc('id'); diff --git a/system/controllers/services.php b/system/controllers/services.php index 5aae6b50..1c2eaac5 100644 --- a/system/controllers/services.php +++ b/system/controllers/services.php @@ -24,11 +24,13 @@ switch ($action) { $router = ''; foreach ($plans as $plan) { $dvc = Package::getDevice($plan); - if (file_exists($dvc) && $_app_stage != 'demo') { - require_once $dvc; - (new $p['device'])->add_plan($plan); - } else { - new Exception(Lang::T("Devices Not Found")); + 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); @@ -38,11 +40,13 @@ switch ($action) { $router = ''; foreach ($plans as $plan) { $dvc = Package::getDevice($plan); - if (file_exists($dvc) && $_app_stage != 'demo') { - require_once $dvc; - (new $p['device'])->add_plan($plan); - } else { - new Exception(Lang::T("Devices Not Found")); + 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); @@ -128,11 +132,13 @@ switch ($action) { if ($d) { run_hook('delete_plan'); #HOOK $dvc = Package::getDevice($d); - if (file_exists($dvc) && $_app_stage != 'demo') { - require_once $dvc; - (new $p['device'])->remove_plan($d); - } else { - new Exception(Lang::T("Devices Not Found")); + 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(); @@ -210,24 +216,25 @@ switch ($action) { $d->enabled = $enabled; $d->prepaid = $prepaid; $d->device = $device; - if($prepaid == 'no'){ - if($expired_date>28 && $expired_date < 1){ + if ($prepaid == 'no') { + if ($expired_date > 28 && $expired_date < 1) { $expired_date = 20; } $d->expired_date = $expired_date; - }else{ + } else { $d->expired_date = 0; } $d->save(); $dvc = Package::getDevice($d); - if (file_exists($dvc) && $_app_stage != 'demo') { - require_once $dvc; - (new $p['device'])->add_plan($d); - } else { - new Exception(Lang::T("Devices Not Found")); + 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); @@ -311,24 +318,25 @@ switch ($action) { $d->enabled = $enabled; $d->prepaid = $prepaid; $d->device = $device; - if($prepaid == 'no'){ - if($expired_date>28 && $expired_date < 1){ + if ($prepaid == 'no') { + if ($expired_date > 28 && $expired_date < 1) { $expired_date = 20; } $d->expired_date = $expired_date; - }else{ + } else { $d->expired_date = 0; } $d->save(); $dvc = Package::getDevice($d); - if (file_exists($dvc) && $_app_stage != 'demo') { - require_once $dvc; - (new $d['device'])->update_plan($old, $d); - } else { - new Exception(Lang::T("Devices Not Found")); + 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,11 +434,13 @@ switch ($action) { run_hook('delete_ppoe'); #HOOK $dvc = Package::getDevice($d); - if (file_exists($dvc) && $_app_stage != 'demo') { - require_once $dvc; - (new $p['device'])->remove_plan($d); - } else { - new Exception(Lang::T("Devices Not Found")); + 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(); @@ -510,12 +520,12 @@ switch ($action) { $d->is_radius = 0; $d->routers = $routers; } - if($prepaid == 'no'){ - if($expired_date>28 && $expired_date < 1){ + if ($prepaid == 'no') { + if ($expired_date > 28 && $expired_date < 1) { $expired_date = 20; } $d->expired_date = $expired_date; - }else{ + } else { $d->expired_date = 0; } $d->enabled = $enabled; @@ -524,13 +534,14 @@ switch ($action) { $d->save(); $dvc = Package::getDevice($d); - if (file_exists($dvc) && $_app_stage != 'demo') { - require_once $dvc; - (new $p['device'])->add_plan($d); - } else { - new Exception(Lang::T("Devices Not Found")); + 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); @@ -603,24 +614,25 @@ switch ($action) { $d->enabled = $enabled; $d->prepaid = $prepaid; $d->device = $device; - if($prepaid == 'no'){ - if($expired_date>28 && $expired_date < 1){ + if ($prepaid == 'no') { + if ($expired_date > 28 && $expired_date < 1) { $expired_date = 20; } $d->expired_date = $expired_date; - }else{ + } else { $d->expired_date = 0; } $d->save(); $dvc = Package::getDevice($d); - if (file_exists($dvc) && $_app_stage != 'demo') { - require_once $dvc; - (new $d['device'])->update_plan($old, $d); - } else { - new Exception(Lang::T("Devices Not Found")); + 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); diff --git a/system/cron.php b/system/cron.php index ea39a6dc..4a5e98e7 100644 --- a/system/cron.php +++ b/system/cron.php @@ -33,12 +33,14 @@ 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') { - 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]"); + 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 diff --git a/system/lan/english.json b/system/lan/english.json index 3268664e..8635cc24 100644 --- a/system/lan/english.json +++ b/system/lan/english.json @@ -644,5 +644,6 @@ "Category": "Category", "later": "later", "Package_Details": "Package Details", - "Summary": "Summary" + "Summary": "Summary", + "Devices_Not_Found": "Devices Not Found" } \ No newline at end of file