From ec7dee5c8ac38a267bfef901c19a44dc866d618b Mon Sep 17 00:00:00 2001
From: Ibnu Maksum <ibnumaksum@gmail.com>
Date: Wed, 22 May 2024 08:50:45 +0700
Subject: [PATCH 1/4] Fix if user Active in dashboard customer and order

---
 system/autoload/Radius.php   | 56 +++++++++++++++++-------------------
 system/autoload/User.php     |  4 +--
 system/controllers/home.php  |  8 +++---
 system/controllers/order.php |  9 ++++++
 4 files changed, 42 insertions(+), 35 deletions(-)

diff --git a/system/autoload/Radius.php b/system/autoload/Radius.php
index ab026562..b5d7e2b4 100644
--- a/system/autoload/Radius.php
+++ b/system/autoload/Radius.php
@@ -15,13 +15,13 @@ class Radius
     public static function getClient()
     {
         global $config;
-        if(empty($config['radius_client'])){
-            if(function_exists("shell_exec")){
+        if (empty($config['radius_client'])) {
+            if (function_exists("shell_exec")) {
                 shell_exec('which radclient');
-            }else{
+            } else {
                 return "";
             }
-        }else{
+        } else {
             $config['radius_client'];
         }
     }
@@ -91,13 +91,13 @@ class Radius
     public static function planUpSert($plan_id, $rate, $pool = null)
     {
         $rates = explode('/', $rate);
- ##burst fixed
-		if (strpos($rate, ' ')) {
-          $ratos = $rates[0].'/'.$rates[1].' '.$rates[2].'/'.$rates[3].'/'.$rates[4].'/'.$rates[5].'/'.$rates[6];
-         } else {
-		 $ratos = $rates[0].'/'.$rates[1];
-		 }
-		
+        ##burst fixed
+        if (strpos($rate, ' ')) {
+            $ratos = $rates[0] . '/' . $rates[1] . ' ' . $rates[2] . '/' . $rates[3] . '/' . $rates[4] . '/' . $rates[5] . '/' . $rates[6];
+        } else {
+            $ratos = $rates[0] . '/' . $rates[1];
+        }
+
         Radius::upsertPackage($plan_id, 'Ascend-Data-Rate', $rates[1], ':=');
         Radius::upsertPackage($plan_id, 'Ascend-Xmit-Rate', $rates[0], ':=');
         Radius::upsertPackage($plan_id, 'Mikrotik-Rate-Limit', $ratos, ':=');
@@ -171,7 +171,7 @@ class Radius
             $p = Radius::getTableUserPackage()->where_equal('username', $customer['username'])->findOne();
             if ($p) {
                 // if exists
-				Radius::delAtribute(Radius::getTableCustomer(), 'Max-All-Session', 'username', $customer['username']);
+                Radius::delAtribute(Radius::getTableCustomer(), 'Max-All-Session', 'username', $customer['username']);
                 Radius::delAtribute(Radius::getTableCustomer(), 'Max-Volume', 'username', $customer['username']);
                 $p->groupname = "plan_" . $plan['id'];
                 $p->save();
@@ -210,23 +210,21 @@ class Radius
                     Radius::upsertCustomer($customer['username'], 'Max-All-Session', $timelimit);
                     // Mikrotik Spesific
                     //Radius::upsertCustomer($customer['username'], 'Max-Data', $datalimit);
-					
-					
-				
-				
+
+
+
+
                 }
-				
-				
             } else {
                 Radius::delAtribute(Radius::getTableCustomer(), 'Max-Volume', 'username', $customer['username']);
                 Radius::delAtribute(Radius::getTableCustomer(), 'Max-All-Session', 'username', $customer['username']);
                 //Radius::delAtribute(Radius::getTableCustomer(), 'Max-Data', 'username', $customer['username']);
             }
-			
-			Radius::disconnectCustomer($customer['username']);
-			Radius::getTableAcct()->where_equal('username', $customer['username'])->delete_many();
-			
-			
+
+            Radius::disconnectCustomer($customer['username']);
+            Radius::getTableAcct()->where_equal('username', $customer['username'])->delete_many();
+
+
             // expired user
             if ($expired != null) {
                 Radius::upsertCustomer($customer['username'], 'Max-All-Session', strtotime($expired) - time());
@@ -245,8 +243,8 @@ class Radius
             if ($plan['type'] == 'PPPOE') {
                 Radius::upsertCustomerAttr($customer['username'], 'Framed-Pool', $plan['pool'], ':=');
             }
-			
-			
+
+
             return true;
         }
         return false;
@@ -326,10 +324,10 @@ class Radius
         if ($_app_stage == 'demo') {
             return null;
         }
-		/**
-		* Fix loop to all Nas but still detecting Hotspot Multylogin from other Nas
-		*/
-		$act = ORM::for_table('radacct')->where_raw("acctstoptime IS NULL")->where('username', $username)->find_one();
+        /**
+         * Fix loop to all Nas but still detecting Hotspot Multylogin from other Nas
+         */
+        $act = ORM::for_table('radacct')->where_raw("acctstoptime IS NULL")->where('username', $username)->find_one();
         $nas = Radius::getTableNas()->where('nasname', $act['nasipaddress'])->find_many();
         $count = count($nas) * 15;
         set_time_limit($count);
diff --git a/system/autoload/User.php b/system/autoload/User.php
index 3d897bdf..1e5c7436 100644
--- a/system/autoload/User.php
+++ b/system/autoload/User.php
@@ -161,8 +161,8 @@ class User
     {
         global $config;
         if ($config['maintenance_mode'] == true) {
-           displayMaintenanceMessage();
-           // r2(U . 'logout', 'd', '');
+            displayMaintenanceMessage();
+            // r2(U . 'logout', 'd', '');
         }
         if (!$id) {
             $id = User::getID();
diff --git a/system/controllers/home.php b/system/controllers/home.php
index d1a24a9a..7640d057 100644
--- a/system/controllers/home.php
+++ b/system/controllers/home.php
@@ -18,7 +18,7 @@ if (isset($_GET['renewal'])) {
 
 if (_post('send') == 'balance') {
     if ($config['enable_balance'] == 'yes' && $config['allow_balance_transfer'] == 'yes') {
-        if ($user['status'] == 'Active') {
+        if ($user['status'] != 'Active') {
             _alert(Lang::T('This account status') . ' : ' . Lang::T($user['status']), 'danger', "");
         }
         $target = ORM::for_table('tbl_customers')->where('username', _post('username'))->find_one();
@@ -80,7 +80,7 @@ if (_post('send') == 'balance') {
         r2(U . 'home', 'd', Lang::T('Failed, balance is not available'));
     }
 } else if (_post('send') == 'plan') {
-    if ($user['status'] == 'Active') {
+    if ($user['status'] != 'Active') {
         _alert(Lang::T('This account status') . ' : ' . Lang::T($user['status']), 'danger', "");
     }
     $actives = ORM::for_table('tbl_user_recharges')
@@ -98,7 +98,7 @@ if (_post('send') == 'balance') {
 $ui->assign('_bills', User::_billing());
 
 if (isset($_GET['recharge']) && !empty($_GET['recharge'])) {
-    if ($user['status'] == 'Active') {
+    if ($user['status'] != 'Active') {
         _alert(Lang::T('This account status') . ' : ' . Lang::T($user['status']), 'danger', "");
     }
     if (!empty(App::getTokenValue(_get('stoken')))) {
@@ -128,7 +128,7 @@ if (isset($_GET['recharge']) && !empty($_GET['recharge'])) {
         }
     }
 } else if (!empty(_get('extend'))) {
-    if ($user['status'] == 'Active') {
+    if ($user['status'] != 'Active') {
         _alert(Lang::T('This account status') . ' : ' . Lang::T($user['status']), 'danger', "");
     }
     if (!$config['extend_expired']) {
diff --git a/system/controllers/order.php b/system/controllers/order.php
index 0e25677d..bc07be16 100644
--- a/system/controllers/order.php
+++ b/system/controllers/order.php
@@ -148,6 +148,9 @@ switch ($action) {
             r2(U . "voucher/invoice/");
             die();
         }
+        if ($user['status'] != 'Active') {
+            _alert(Lang::T('This account status') . ' : ' . Lang::T($user['status']), 'danger', "");
+        }
         $plan = ORM::for_table('tbl_plans')->where('enabled', '1')->find_one($routes['3']);
         if (empty($plan)) {
             r2(U . "order/package", 'e', Lang::T("Plan Not found"));
@@ -202,6 +205,9 @@ switch ($action) {
         if ($config['enable_balance'] != 'yes') {
             r2(U . "order/package", 'e', Lang::T("Balance not enabled"));
         }
+        if ($user['status'] != 'Active') {
+            _alert(Lang::T('This account status') . ' : ' . Lang::T($user['status']), 'danger', "");
+        }
         $ui->assign('_title', Lang::T('Buy for friend'));
         $ui->assign('_system_menu', 'package');
         $plan = ORM::for_table('tbl_plans')->find_one($routes['3']);
@@ -372,6 +378,9 @@ switch ($action) {
         } else if (!empty($gateway)) {
             $_SESSION['gateway'] = $gateway;
         }
+        if ($user['status'] != 'Active') {
+            _alert(Lang::T('This account status') . ' : ' . Lang::T($user['status']), 'danger', "");
+        }
         if (empty($gateway)) {
             r2(U . 'order/gateway/' . $routes[2] . '/' . $routes[3], 'w', Lang::T("Please select Payment Gateway"));
         }

From c2f220f7707fe9b1fc2fc1263ac3ff777ef8d5b9 Mon Sep 17 00:00:00 2001
From: Ibnu Maksum <ibnumaksum@gmail.com>
Date: Wed, 22 May 2024 08:55:07 +0700
Subject: [PATCH 2/4] comment deleted variable

---
 system/autoload/Radius.php | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/system/autoload/Radius.php b/system/autoload/Radius.php
index b5d7e2b4..a8f7dc1b 100644
--- a/system/autoload/Radius.php
+++ b/system/autoload/Radius.php
@@ -189,6 +189,7 @@ class Radius
                     else
                         $timelimit = $plan['time_limit'] * 60;
                     Radius::upsertCustomer($customer['username'], 'Max-All-Session', $timelimit);
+                    //Radius::upsertCustomer($customer['username'], 'Expire-After', $timelimit);
                 } else if ($plan['limit_type'] == "Data_Limit") {
                     if ($plan['data_unit'] == 'GB')
                         $datalimit = $plan['data_limit'] . "000000000";
@@ -197,6 +198,7 @@ class Radius
                     Radius::upsertCustomer($customer['username'], 'Max-Volume', $datalimit);
                     // Mikrotik Spesific
                     //Radius::upsertCustomer($customer['username'], 'Max-Data', $datalimit);
+                    //Radius::upsertCustomer($customer['username'], 'Mikrotik-Total-Limit', $datalimit);
                 } else if ($plan['limit_type'] == "Both_Limit") {
                     if ($plan['time_unit'] == 'Hrs')
                         $timelimit = $plan['time_limit'] * 60 * 60;
@@ -210,6 +212,7 @@ class Radius
                     Radius::upsertCustomer($customer['username'], 'Max-All-Session', $timelimit);
                     // Mikrotik Spesific
                     //Radius::upsertCustomer($customer['username'], 'Max-Data', $datalimit);
+                    //Radius::upsertCustomer($customer['username'], 'Mikrotik-Total-Limit', $datalimit);
 
 
 
@@ -227,6 +230,7 @@ class Radius
 
             // expired user
             if ($expired != null) {
+                //Radius::upsertCustomer($customer['username'], 'access-period', strtotime($expired) - time());
                 Radius::upsertCustomer($customer['username'], 'Max-All-Session', strtotime($expired) - time());
                 //Radius::upsertCustomer($customer['username'], 'expiration', date('d M Y H:i:s', strtotime($expired)));
                 // Mikrotik Spesific
@@ -237,6 +241,7 @@ class Radius
                 );
             } else {
                 Radius::delAtribute(Radius::getTableCustomer(), 'Max-All-Session', 'username', $customer['username']);
+                //Radius::delAtribute(Radius::getTableCustomer(), 'access-period', 'username', $customer['username']);
                 //Radius::delAtribute(Radius::getTableCustomer(), 'expiration', 'username', $customer['username']);
             }
 

From 13eedc814dafe0fa89565c27d9a74bdd5dd895db Mon Sep 17 00:00:00 2001
From: Ibnu Maksum <ibnumaksum@gmail.com>
Date: Wed, 22 May 2024 11:31:43 +0700
Subject: [PATCH 3/4] rollback Radius Function

---
 system/autoload/Radius.php | 31 +++++++++++--------------------
 1 file changed, 11 insertions(+), 20 deletions(-)

diff --git a/system/autoload/Radius.php b/system/autoload/Radius.php
index a8f7dc1b..c2ca2b4f 100644
--- a/system/autoload/Radius.php
+++ b/system/autoload/Radius.php
@@ -172,7 +172,7 @@ class Radius
             if ($p) {
                 // if exists
                 Radius::delAtribute(Radius::getTableCustomer(), 'Max-All-Session', 'username', $customer['username']);
-                Radius::delAtribute(Radius::getTableCustomer(), 'Max-Volume', 'username', $customer['username']);
+                Radius::delAtribute(Radius::getTableCustomer(), 'Max-Data', 'username', $customer['username']);
                 $p->groupname = "plan_" . $plan['id'];
                 $p->save();
             } else {
@@ -189,16 +189,14 @@ class Radius
                     else
                         $timelimit = $plan['time_limit'] * 60;
                     Radius::upsertCustomer($customer['username'], 'Max-All-Session', $timelimit);
-                    //Radius::upsertCustomer($customer['username'], 'Expire-After', $timelimit);
                 } else if ($plan['limit_type'] == "Data_Limit") {
                     if ($plan['data_unit'] == 'GB')
                         $datalimit = $plan['data_limit'] . "000000000";
                     else
                         $datalimit = $plan['data_limit'] . "000000";
-                    Radius::upsertCustomer($customer['username'], 'Max-Volume', $datalimit);
+                    //Radius::upsertCustomer($customer['username'], 'Max-Volume', $datalimit);
                     // Mikrotik Spesific
-                    //Radius::upsertCustomer($customer['username'], 'Max-Data', $datalimit);
-                    //Radius::upsertCustomer($customer['username'], 'Mikrotik-Total-Limit', $datalimit);
+                    Radius::upsertCustomer($customer['username'], 'Max-Data', $datalimit);
                 } else if ($plan['limit_type'] == "Both_Limit") {
                     if ($plan['time_unit'] == 'Hrs')
                         $timelimit = $plan['time_limit'] * 60 * 60;
@@ -208,20 +206,15 @@ class Radius
                         $datalimit = $plan['data_limit'] . "000000000";
                     else
                         $datalimit = $plan['data_limit'] . "000000";
-                    Radius::upsertCustomer($customer['username'], 'Max-Volume', $datalimit);
+                    //Radius::upsertCustomer($customer['username'], 'Max-Volume', $datalimit);
                     Radius::upsertCustomer($customer['username'], 'Max-All-Session', $timelimit);
                     // Mikrotik Spesific
-                    //Radius::upsertCustomer($customer['username'], 'Max-Data', $datalimit);
-                    //Radius::upsertCustomer($customer['username'], 'Mikrotik-Total-Limit', $datalimit);
-
-
-
-
+                    Radius::upsertCustomer($customer['username'], 'Max-Data', $datalimit);
                 }
             } else {
-                Radius::delAtribute(Radius::getTableCustomer(), 'Max-Volume', 'username', $customer['username']);
+                //Radius::delAtribute(Radius::getTableCustomer(), 'Max-Volume', 'username', $customer['username']);
                 Radius::delAtribute(Radius::getTableCustomer(), 'Max-All-Session', 'username', $customer['username']);
-                //Radius::delAtribute(Radius::getTableCustomer(), 'Max-Data', 'username', $customer['username']);
+                Radius::delAtribute(Radius::getTableCustomer(), 'Max-Data', 'username', $customer['username']);
             }
 
             Radius::disconnectCustomer($customer['username']);
@@ -230,9 +223,8 @@ class Radius
 
             // expired user
             if ($expired != null) {
-                //Radius::upsertCustomer($customer['username'], 'access-period', strtotime($expired) - time());
-                Radius::upsertCustomer($customer['username'], 'Max-All-Session', strtotime($expired) - time());
-                //Radius::upsertCustomer($customer['username'], 'expiration', date('d M Y H:i:s', strtotime($expired)));
+                //Radius::upsertCustomer($customer['username'], 'Max-All-Session', strtotime($expired) - time());
+                Radius::upsertCustomer($customer['username'], 'expiration', date('d M Y H:i:s', strtotime($expired)));
                 // Mikrotik Spesific
                 Radius::upsertCustomer(
                     $customer['username'],
@@ -240,9 +232,8 @@ class Radius
                     date('Y-m-d', strtotime($expired)) . 'T' . date('H:i:s', strtotime($expired)) . Timezone::getTimeOffset($config['timezone'])
                 );
             } else {
-                Radius::delAtribute(Radius::getTableCustomer(), 'Max-All-Session', 'username', $customer['username']);
-                //Radius::delAtribute(Radius::getTableCustomer(), 'access-period', 'username', $customer['username']);
-                //Radius::delAtribute(Radius::getTableCustomer(), 'expiration', 'username', $customer['username']);
+                //Radius::delAtribute(Radius::getTableCustomer(), 'Max-All-Session', 'username', $customer['username']);
+                Radius::delAtribute(Radius::getTableCustomer(), 'expiration', 'username', $customer['username']);
             }
 
             if ($plan['type'] == 'PPPOE') {

From e5b28c2c153f33ad92b7862050eabec4f2a5f11b Mon Sep 17 00:00:00 2001
From: Ibnu Maksum <ibnumaksum@gmail.com>
Date: Wed, 22 May 2024 13:27:07 +0700
Subject: [PATCH 4/4] 2024.5.22

---
 system/autoload/Radius.php | 31 ++++++++++++++++++++-----------
 version.json               |  2 +-
 2 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/system/autoload/Radius.php b/system/autoload/Radius.php
index c2ca2b4f..a8f7dc1b 100644
--- a/system/autoload/Radius.php
+++ b/system/autoload/Radius.php
@@ -172,7 +172,7 @@ class Radius
             if ($p) {
                 // if exists
                 Radius::delAtribute(Radius::getTableCustomer(), 'Max-All-Session', 'username', $customer['username']);
-                Radius::delAtribute(Radius::getTableCustomer(), 'Max-Data', 'username', $customer['username']);
+                Radius::delAtribute(Radius::getTableCustomer(), 'Max-Volume', 'username', $customer['username']);
                 $p->groupname = "plan_" . $plan['id'];
                 $p->save();
             } else {
@@ -189,14 +189,16 @@ class Radius
                     else
                         $timelimit = $plan['time_limit'] * 60;
                     Radius::upsertCustomer($customer['username'], 'Max-All-Session', $timelimit);
+                    //Radius::upsertCustomer($customer['username'], 'Expire-After', $timelimit);
                 } else if ($plan['limit_type'] == "Data_Limit") {
                     if ($plan['data_unit'] == 'GB')
                         $datalimit = $plan['data_limit'] . "000000000";
                     else
                         $datalimit = $plan['data_limit'] . "000000";
-                    //Radius::upsertCustomer($customer['username'], 'Max-Volume', $datalimit);
+                    Radius::upsertCustomer($customer['username'], 'Max-Volume', $datalimit);
                     // Mikrotik Spesific
-                    Radius::upsertCustomer($customer['username'], 'Max-Data', $datalimit);
+                    //Radius::upsertCustomer($customer['username'], 'Max-Data', $datalimit);
+                    //Radius::upsertCustomer($customer['username'], 'Mikrotik-Total-Limit', $datalimit);
                 } else if ($plan['limit_type'] == "Both_Limit") {
                     if ($plan['time_unit'] == 'Hrs')
                         $timelimit = $plan['time_limit'] * 60 * 60;
@@ -206,15 +208,20 @@ class Radius
                         $datalimit = $plan['data_limit'] . "000000000";
                     else
                         $datalimit = $plan['data_limit'] . "000000";
-                    //Radius::upsertCustomer($customer['username'], 'Max-Volume', $datalimit);
+                    Radius::upsertCustomer($customer['username'], 'Max-Volume', $datalimit);
                     Radius::upsertCustomer($customer['username'], 'Max-All-Session', $timelimit);
                     // Mikrotik Spesific
-                    Radius::upsertCustomer($customer['username'], 'Max-Data', $datalimit);
+                    //Radius::upsertCustomer($customer['username'], 'Max-Data', $datalimit);
+                    //Radius::upsertCustomer($customer['username'], 'Mikrotik-Total-Limit', $datalimit);
+
+
+
+
                 }
             } else {
-                //Radius::delAtribute(Radius::getTableCustomer(), 'Max-Volume', 'username', $customer['username']);
+                Radius::delAtribute(Radius::getTableCustomer(), 'Max-Volume', 'username', $customer['username']);
                 Radius::delAtribute(Radius::getTableCustomer(), 'Max-All-Session', 'username', $customer['username']);
-                Radius::delAtribute(Radius::getTableCustomer(), 'Max-Data', 'username', $customer['username']);
+                //Radius::delAtribute(Radius::getTableCustomer(), 'Max-Data', 'username', $customer['username']);
             }
 
             Radius::disconnectCustomer($customer['username']);
@@ -223,8 +230,9 @@ class Radius
 
             // expired user
             if ($expired != null) {
-                //Radius::upsertCustomer($customer['username'], 'Max-All-Session', strtotime($expired) - time());
-                Radius::upsertCustomer($customer['username'], 'expiration', date('d M Y H:i:s', strtotime($expired)));
+                //Radius::upsertCustomer($customer['username'], 'access-period', strtotime($expired) - time());
+                Radius::upsertCustomer($customer['username'], 'Max-All-Session', strtotime($expired) - time());
+                //Radius::upsertCustomer($customer['username'], 'expiration', date('d M Y H:i:s', strtotime($expired)));
                 // Mikrotik Spesific
                 Radius::upsertCustomer(
                     $customer['username'],
@@ -232,8 +240,9 @@ class Radius
                     date('Y-m-d', strtotime($expired)) . 'T' . date('H:i:s', strtotime($expired)) . Timezone::getTimeOffset($config['timezone'])
                 );
             } else {
-                //Radius::delAtribute(Radius::getTableCustomer(), 'Max-All-Session', 'username', $customer['username']);
-                Radius::delAtribute(Radius::getTableCustomer(), 'expiration', 'username', $customer['username']);
+                Radius::delAtribute(Radius::getTableCustomer(), 'Max-All-Session', 'username', $customer['username']);
+                //Radius::delAtribute(Radius::getTableCustomer(), 'access-period', 'username', $customer['username']);
+                //Radius::delAtribute(Radius::getTableCustomer(), 'expiration', 'username', $customer['username']);
             }
 
             if ($plan['type'] == 'PPPOE') {
diff --git a/version.json b/version.json
index 7078700b..e2d2d815 100644
--- a/version.json
+++ b/version.json
@@ -1,3 +1,3 @@
 {
-    "version": "2024.5.21"
+    "version": "2024.5.22"
 }
\ No newline at end of file