From 5867a0c9caaab3b395a3bcf0a3a8c3da58fc89cd Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Mon, 15 Jan 2024 10:22:03 +0700 Subject: [PATCH 01/10] Fix Cron for --- CHANGELOG.md | 4 ++++ system/boot.php | 19 ++++++++++++------- system/cron.php | 24 ++++++++++++++++-------- system/cron_reminder.php | 8 +++++++- version.json | 2 +- 5 files changed, 40 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1be54699..2453b43a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ # CHANGELOG +## 2024.1.15 + +- Fix cron job for Plan only for admin by @Focuslinkstech + ## 2024.1.11 - Add Plan only for admin by @Focuslinkstech diff --git a/system/boot.php b/system/boot.php index 56ed2d60..5bd9fdb6 100644 --- a/system/boot.php +++ b/system/boot.php @@ -118,7 +118,7 @@ try { $ui->assign("error_title", "PHPNuxBill Crash"); if (isset($_SESSION['uid'])) { $ui->assign("error_message", $e->getMessage() . '
'); - }else{ + } else { $ui->assign("error_message", $e->getMessage() . '
' . $e->getTraceAsString() . '
'); } $ui->display('router-error.tpl'); @@ -130,13 +130,13 @@ function _notify($msg, $type = 'e') $_SESSION['ntype'] = $type; $_SESSION['notify'] = $msg; } -if(empty($config['language'])){ +if (empty($config['language'])) { $config['language'] = 'english'; } $lan_file = File::pathFixer('system/lan/' . $config['language'] . '/common.lan.php'); -if(file_exists($lan_file)){ +if (file_exists($lan_file)) { require $lan_file; -}else{ +} else { die("$lan_file not found"); } @@ -190,7 +190,11 @@ $_notifmsg_default = json_decode(file_get_contents(File::pathFixer('system/uploa //register all plugin foreach (glob(File::pathFixer("system/plugin/*.php")) as $filename) { - include $filename; + try { + include $filename; + } catch (Throwable $e) { + } catch (Exception $e) { + } } @@ -293,7 +297,8 @@ function time_elapsed_string($datetime, $full = false) } } - if (!$full) $string = array_slice($string, 0, 1); + if (!$full) + $string = array_slice($string, 0, 1); return $string ? implode(', ', $string) . ' ago' : 'just now'; } @@ -340,7 +345,7 @@ try { } } catch (Exception $e) { if (!isset($_SESSION['aid']) || empty($_SESSION['aid'])) { - r2(U . 'home' , 'e', $e->getMessage()); + r2(U . 'home', 'e', $e->getMessage()); } $ui->assign("error_message", $e->getMessage() . '
' . $e->getTraceAsString() . '
'); $ui->assign("error_title", "PHPNuxBill Crash"); diff --git a/system/cron.php b/system/cron.php index cac928ab..eda037d0 100644 --- a/system/cron.php +++ b/system/cron.php @@ -35,16 +35,16 @@ if (php_sapi_name() !== 'cli') { echo "
";
 }
 
-if(!file_exists('../config.php')){
+if (!file_exists('../config.php')) {
     die("config.php file not found");
 }
 
 
-if(!file_exists('orm.php')){
+if (!file_exists('orm.php')) {
     die("orm.php file not found");
 }
 
-if(!file_exists('uploads/notifications.default.json')){
+if (!file_exists('uploads/notifications.default.json')) {
     die("uploads/notifications.default.json file not found");
 }
 
@@ -68,7 +68,13 @@ $_notifmsg_default = json_decode(file_get_contents('uploads/notifications.defaul
 
 //register all plugin
 foreach (glob(File::pathFixer("plugin/*.php")) as $filename) {
-    include $filename;
+    try{
+        include $filename;
+    } catch(Throwable $e){
+        //ignore plugin error
+    }catch(Exception $e){
+        //ignore plugin error
+    }
 }
 
 $result = ORM::for_table('tbl_appconfig')->find_many();
@@ -137,7 +143,7 @@ foreach ($d as $ds) {
 
             // autorenewal from deposit
             if ($config['enable_balance'] == 'yes' && $c['auto_renewal']) {
-                if ($p && $p['enabled'] && $c['balance'] >= $p['price'] && $p['allow_purchase'] =='yes') {
+                if ($p && $p['enabled'] && $c['balance'] >= $p['price'] && $p['allow_purchase'] == 'yes') {
                     if (Package::rechargeUser($ds['customer_id'], $p['routers'], $p['id'], 'Customer', 'Balance')) {
                         // if success, then get the balance
                         Balance::min($ds['customer_id'], $p['price']);
@@ -156,7 +162,8 @@ foreach ($d as $ds) {
             } else {
                 echo "no renewall | balance $config[enable_balance] auto_renewal $c[auto_renewal]\n";
             }
-        } else echo " : ACTIVE \r\n";
+        } else
+            echo " : ACTIVE \r\n";
     } else {
         $date_now = strtotime(date("Y-m-d H:i:s"));
         $expiration = strtotime($ds['expiration'] . ' ' . $ds['time']);
@@ -191,7 +198,7 @@ foreach ($d as $ds) {
 
             // autorenewal from deposit
             if ($config['enable_balance'] == 'yes' && $c['auto_renewal']) {
-                if ($p && $p['enabled'] && $c['balance'] >= $p['price']&& $p['allow_purchase'] =='yes') {
+                if ($p && $p['enabled'] && $c['balance'] >= $p['price'] && $p['allow_purchase'] == 'yes') {
                     if (Package::rechargeUser($ds['customer_id'], $p['routers'], $p['id'], 'Customer', 'Balance')) {
                         // if success, then get the balance
                         Balance::min($ds['customer_id'], $p['price']);
@@ -206,6 +213,7 @@ foreach ($d as $ds) {
                     }
                 }
             }
-        } else echo " : ACTIVE \r\n";
+        } else
+            echo " : ACTIVE \r\n";
     }
 }
diff --git a/system/cron_reminder.php b/system/cron_reminder.php
index 1b77aac8..d15fa953 100644
--- a/system/cron_reminder.php
+++ b/system/cron_reminder.php
@@ -67,7 +67,13 @@ $_notifmsg_default = json_decode(file_get_contents('uploads/notifications.defaul
 
 //register all plugin
 foreach (glob(File::pathFixer("plugin/*.php")) as $filename) {
-    include $filename;
+    try{
+        include $filename;
+    } catch(Throwable $e){
+        //ignore plugin error
+    }catch(Exception $e){
+        //ignore plugin error
+    }
 }
 
 $result = ORM::for_table('tbl_appconfig')->find_many();
diff --git a/version.json b/version.json
index 9fdb534f..8cd16b4f 100644
--- a/version.json
+++ b/version.json
@@ -1,3 +1,3 @@
 {
-    "version": "2024.1.11"
+    "version": "2024.1.15"
 }
\ No newline at end of file

From 470c219e611727259378a265fed477f9c4d901f9 Mon Sep 17 00:00:00 2001
From: Ibnu Maksum 
Date: Tue, 16 Jan 2024 09:00:56 +0700
Subject: [PATCH 02/10] Add Yellow line for plan not allowed to purchase

---
 system/controllers/home.php       |  6 ++++++
 system/controllers/order.php      | 14 +++++++++++++-
 system/controllers/pool.php       |  2 ++
 system/controllers/services.php   |  4 ++++
 system/lan/english/common.lan.php |  6 ++++++
 ui/ui/hotspot.tpl                 |  3 ++-
 ui/ui/pppoe.tpl                   |  3 ++-
 7 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/system/controllers/home.php b/system/controllers/home.php
index e480b92a..265c8e89 100644
--- a/system/controllers/home.php
+++ b/system/controllers/home.php
@@ -96,6 +96,12 @@ if (isset($_GET['recharge']) && !empty($_GET['recharge'])) {
         $router = ORM::for_table('tbl_routers')->where('name', $bill['routers'])->find_one();
         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($plan['allow_purchase'] != 'yes'){
+                r2(U . "home", 'e', 'Cannot recharge this plan');
+            }
             if ($user['balance'] > $plan['price']) {
                 r2(U . "order/pay/$router[id]/$bill[plan_id]", 'e', 'Order Plan');
             } else {
diff --git a/system/controllers/order.php b/system/controllers/order.php
index a14d15e0..31b53dd0 100644
--- a/system/controllers/order.php
+++ b/system/controllers/order.php
@@ -149,6 +149,12 @@ switch ($action) {
         if (empty($plan)) {
             r2(U . "order/package", 'e', Lang::T("Plan Not found"));
         }
+        if(!$plan['enabled']){
+            r2(U . "home", 'e', 'Plan is not exists');
+        }
+        if($plan['allow_purchase'] != 'yes'){
+            r2(U . "home", 'e', 'Cannot recharge this plan');
+        }
         if ($routes['2'] == 'radius') {
             $router_name = 'radius';
         } else {
@@ -166,7 +172,7 @@ switch ($action) {
                     "\nPrice: " . $p['price']);
             }
         } else {
-            echo "no renewall | plan enabled: $p[enabled] | User balance: $c[balance] | price $p[price]\n";
+            r2(U . "home", 'e', 'Plan is not exists');
         }
         break;
     case 'send':
@@ -179,6 +185,12 @@ switch ($action) {
         if (empty($plan)) {
             r2(U . "order/package", 'e', Lang::T("Plan Not found"));
         }
+        if(!$plan['enabled']){
+            r2(U . "home", 'e', 'Plan is not exists');
+        }
+        if($plan['allow_purchase'] != 'yes'){
+            r2(U . "home", 'e', 'Cannot recharge this plan');
+        }
         if ($routes['2'] == 'radius') {
             $router_name = 'radius';
         } else {
diff --git a/system/controllers/pool.php b/system/controllers/pool.php
index de7b2932..2261d8eb 100644
--- a/system/controllers/pool.php
+++ b/system/controllers/pool.php
@@ -68,6 +68,8 @@ switch ($action) {
                     Mikrotik::removePool($client, $d['pool_name']);
                 } catch (Exception $e) {
                     //ignore exception, it means router has already deleted
+                } catch(Throwable $e){
+                    //ignore exception, it means router has already deleted
                 }
             }
             $d->delete();
diff --git a/system/controllers/services.php b/system/controllers/services.php
index 093c1343..4909a9c3 100644
--- a/system/controllers/services.php
+++ b/system/controllers/services.php
@@ -173,6 +173,8 @@ switch ($action) {
                     Mikrotik::removeHotspotPlan($client, $d['name_plan']);
                 } catch (Exception $e) {
                     //ignore exception, it means router has already deleted
+                } catch(Throwable $e){
+                    //ignore exception, it means router has already deleted
                 }
             }
 
@@ -441,6 +443,8 @@ switch ($action) {
                     Mikrotik::removePpoePlan($client, $d['name_plan']);
                 } catch (Exception $e) {
                     //ignore exception, it means router has already deleted
+                } catch(Throwable $e){
+                    //ignore exception, it means router has already deleted
                 }
             }
             $d->delete();
diff --git a/system/lan/english/common.lan.php b/system/lan/english/common.lan.php
index 2dd0680e..d0d1e4ac 100644
--- a/system/lan/english/common.lan.php
+++ b/system/lan/english/common.lan.php
@@ -420,3 +420,9 @@ $_L['After_Customer_activate_voucher_or_login_customer_will_be_redirected_to_thi
 $_L['Voucher_Prefix'] = 'Voucher Prefix';
 $_L['Voucher_activation_success_now_you_can_login'] = 'Voucher activation success, now you can login';
 $_L['Client_Can_Purchase'] = 'Client Can Purchase';
+$_L['Buy_this_your_active_package_will_be_overwritten'] = 'Buy this? your active package will be overwritten';
+$_L['Pay_this_with_Balance_your_active_package_will_be_overwritten'] = 'Pay this with Balance? your active package will be overwritten';
+$_L['Buy_this_your_active_package_will_be_overwritten'] = 'Buy this? your active package will be overwritten';
+$_L['Pay_this_with_Balance_your_active_package_will_be_overwritten'] = 'Pay this with Balance? your active package will be overwritten';
+$_L['Buy_this_your_active_package_will_be_overwritten'] = 'Buy this? your active package will be overwritten';
+$_L['Pay_this_with_Balance_your_active_package_will_be_overwritten'] = 'Pay this with Balance? your active package will be overwritten';
diff --git a/ui/ui/hotspot.tpl b/ui/ui/hotspot.tpl
index ffd33913..6203b307 100644
--- a/ui/ui/hotspot.tpl
+++ b/ui/ui/hotspot.tpl
@@ -49,7 +49,8 @@
                         
                         
                             {foreach $d as $ds}
-                                
+                                
                                     {$ds['name_plan']}
                                     {$ds['typebp']}
                                     {$ds['name_bw']}
diff --git a/ui/ui/pppoe.tpl b/ui/ui/pppoe.tpl
index 5fe10771..dd3c548a 100644
--- a/ui/ui/pppoe.tpl
+++ b/ui/ui/pppoe.tpl
@@ -47,7 +47,8 @@
                         
                         
                             {foreach $d as $ds}
-                                
+                                
                                     {$ds['name_plan']}
                                     {$ds['name_bw']}
                                     {Lang::moneyFormat($ds['price'])}

From b504723e7c5c7d0ac6db212a3cd003399d2aedfb Mon Sep 17 00:00:00 2001
From: Ibnu Maksum 
Date: Tue, 16 Jan 2024 09:39:20 +0700
Subject: [PATCH 03/10] fix radius pool select

---
 CHANGELOG.md                 |  4 ++++
 system/autoload/Mikrotik.php |  1 +
 system/cron.php              |  2 +-
 ui/ui/hotspot-add.tpl        | 19 +++++++++----------
 ui/ui/hotspot-edit.tpl       |  2 +-
 ui/ui/pppoe-edit.tpl         |  2 +-
 6 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2453b43a..cb80646b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,10 @@
 
 # CHANGELOG
 
+## 2024.1.16
+
+- Add yellow color to table for plan not allowed to purchase
+
 ## 2024.1.15
 
 - Fix cron job for Plan only for admin by @Focuslinkstech
diff --git a/system/autoload/Mikrotik.php b/system/autoload/Mikrotik.php
index b622a3d9..da5d1615 100644
--- a/system/autoload/Mikrotik.php
+++ b/system/autoload/Mikrotik.php
@@ -130,6 +130,7 @@ class Mikrotik
                     ->setArgument('address-pool', $pool)
                     ->setArgument('rate-limit', '512K/512K')
             );
+            die("| $profileID | $name | $pool |");
         } else {
             $setRequest = new RouterOS\Request('/ip/hotspot/user/profile/set');
             $client->sendSync(
diff --git a/system/cron.php b/system/cron.php
index eda037d0..86aa764e 100644
--- a/system/cron.php
+++ b/system/cron.php
@@ -117,7 +117,7 @@ foreach ($d as $ds) {
             echo " : EXPIRED \r\n";
             $u = ORM::for_table('tbl_user_recharges')->where('id', $ds['id'])->find_one();
             $c = ORM::for_table('tbl_customers')->where('id', $ds['customer_id'])->find_one();
-            $m = ORM::for_table('tbl_routers')->where('name', $ds['routers'])->find_one();
+            $m = Mikrotik::info($ds['routers']);
             $p = ORM::for_table('tbl_plans')->where('id', $u['plan_id'])->find_one();
 
             if ($p['is_radius']) {
diff --git a/ui/ui/hotspot-add.tpl b/ui/ui/hotspot-add.tpl
index 4472be80..fd16f816 100644
--- a/ui/ui/hotspot-add.tpl
+++ b/ui/ui/hotspot-add.tpl
@@ -175,21 +175,20 @@
                 if (cek.checked) {
                     $("#routerChoose").addClass('hidden');
                     document.getElementById("routers").required = false;
+                    $("#pool_expired").html('');
+                    $.ajax({
+                        url: "index.php?_route=autoload/pool",
+                        data: "routers=radius",
+                        cache: false,
+                        success: function(msg) {
+                            $("#pool_expired").html(msg);
+                        }
+                    });
                 } else {
                     document.getElementById("routers").required = true;
                     $("#routerChoose").removeClass('hidden');
                 }
             }
-            setTimeout(() => {
-                $.ajax({
-                    url: "index.php?_route=autoload/pool",
-                    data: "routers=radius",
-                    cache: false,
-                    success: function(msg) {
-                        $("#pool_expired").html(msg);
-                    }
-                });
-            }, 2000);
         
     {/literal}
 {/if}
diff --git a/ui/ui/hotspot-edit.tpl b/ui/ui/hotspot-edit.tpl
index ffe6af7a..b5fa76a6 100644
--- a/ui/ui/hotspot-edit.tpl
+++ b/ui/ui/hotspot-edit.tpl
@@ -179,7 +179,7 @@
     
 
 
-{if $_c['radius_enable']}
+{if $_c['radius_enable'] && $d['is_radius']}
     {literal}