diff --git a/init.php b/init.php index c6072656..76c9cd27 100644 --- a/init.php +++ b/init.php @@ -322,3 +322,16 @@ function _alert($text, $type = 'success', $url = "home", $time = 3) if (!isset($api_secret)) { $api_secret = $db_password; } + +function displayMaintenanceMessage(): void +{ + global $config, $ui; + $date = $config['maintenance_date']; + if ($date){ + $ui->assign('date', $date); + } + http_response_code(503); + $ui->assign('companyName', $config['CompanyName']); + $ui->display('maintenance.tpl'); + die(); +} diff --git a/install/phpnuxbill.sql b/install/phpnuxbill.sql index b87ddb99..26202e3a 100644 --- a/install/phpnuxbill.sql +++ b/install/phpnuxbill.sql @@ -24,6 +24,10 @@ CREATE TABLE `tbl_customers` ( `pppoe_password` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'For PPPOE Login', `fullname` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, `address` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, + `city` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, + `district` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, + `state` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, + `zip` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, `phonenumber` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '0', `email` varchar(128) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '1', `coordinates` VARCHAR(50) NOT NULL DEFAULT '' COMMENT 'Latitude and Longitude coordinates', diff --git a/system/autoload/Radius.php b/system/autoload/Radius.php index a445b21f..ab026562 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 { @@ -194,9 +194,9 @@ 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); // Mikrotik Spesific - Radius::upsertCustomer($customer['username'], 'Max-Data', $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; @@ -206,10 +206,10 @@ 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); @@ -218,9 +218,9 @@ class Radius } 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']); @@ -229,8 +229,8 @@ 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'], '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'], @@ -238,8 +238,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(), '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') { diff --git a/system/controllers/customers.php b/system/controllers/customers.php index 082f29d7..2375ad86 100644 --- a/system/controllers/customers.php +++ b/system/controllers/customers.php @@ -392,6 +392,11 @@ switch ($action) { //post Customers Attributes $custom_field_names = (array) $_POST['custom_field_name']; $custom_field_values = (array) $_POST['custom_field_value']; + //additional information + $city = _post('city'); + $district = _post('district'); + $state = _post('state'); + $zip = _post('zip'); run_hook('add_customer'); #HOOK $msg = ''; @@ -423,6 +428,10 @@ switch ($action) { $d->phonenumber = Lang::phoneFormat($phonenumber); $d->service_type = $service_type; $d->coordinates = $coordinates; + $d->city = $city; + $d->district = $district; + $d->state = $state; + $d->zip = $zip; $d->save(); // Retrieve the customer ID of the newly created customer @@ -461,6 +470,11 @@ switch ($action) { $service_type = _post('service_type'); $coordinates = _post('coordinates'); $status = _post('status'); + //additional information + $city = _post('city'); + $district = _post('district'); + $state = _post('state'); + $zip = _post('zip'); run_hook('edit_customer'); #HOOK $msg = ''; if (Validator::Length($username, 35, 2) == false) { @@ -523,6 +537,10 @@ switch ($action) { $d->phonenumber = $phonenumber; $d->service_type = $service_type; $d->coordinates = $coordinates; + $d->city = $city; + $d->district = $district; + $d->state = $state; + $d->zip = $zip; $d->save(); diff --git a/system/controllers/login.php b/system/controllers/login.php index cb246dec..663d3c02 100644 --- a/system/controllers/login.php +++ b/system/controllers/login.php @@ -5,6 +5,11 @@ * by https://t.me/ibnux **/ + $maintenance_mode = $config['maintenance_mode']; + if ($maintenance_mode == true){ + displayMaintenanceMessage(); + } + if (User::getID()) { r2(U . 'home'); } diff --git a/system/controllers/settings.php b/system/controllers/settings.php index 5575ebdd..c58fc60a 100644 --- a/system/controllers/settings.php +++ b/system/controllers/settings.php @@ -732,12 +732,12 @@ switch ($action) { $suc = 0; $fal = 0; $json = json_decode(file_get_contents($_FILES['json']['tmp_name']), true); - try{ + try { ORM::raw_execute("SET FOREIGN_KEY_CHECKS=0;"); } catch (Throwable $e) { } catch (Exception $e) { } - try{ + try { ORM::raw_execute("SET GLOBAL FOREIGN_KEY_CHECKS=0;"); } catch (Throwable $e) { } catch (Exception $e) { @@ -745,7 +745,7 @@ switch ($action) { foreach ($json as $table => $records) { ORM::raw_execute("TRUNCATE $table;"); foreach ($records as $rec) { - try{ + try { $t = ORM::for_table($table)->create(); foreach ($rec as $k => $v) { if ($k != 'id') { @@ -764,12 +764,12 @@ switch ($action) { } } } - try{ + try { ORM::raw_execute("SET FOREIGN_KEY_CHECKS=1;"); } catch (Throwable $e) { } catch (Exception $e) { } - try{ + try { ORM::raw_execute("SET GLOBAL FOREIGN_KEY_CHECKS=1;"); } catch (Throwable $e) { } catch (Exception $e) { @@ -798,6 +798,40 @@ switch ($action) { r2(U . 'settings/language', 's', Lang::T('Translation saved Successfully')); break; + case 'maintenance': + if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { + _alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard"); + exit; + } + if (_post('save') == 'save') { + $status = isset($_POST['maintenance_mode']) ? 1 : 0; // Checkbox returns 1 if checked, otherwise 0 + $date = isset($_POST['maintenance_date']) ? $_POST['maintenance_date'] : null; + + $settings = [ + 'maintenance_mode' => $status, + 'maintenance_date' => $date + ]; + + foreach ($settings as $key => $value) { + $d = ORM::for_table('tbl_appconfig')->where('setting', $key)->find_one(); + if ($d) { + $d->value = $value; + $d->save(); + } else { + $d = ORM::for_table('tbl_appconfig')->create(); + $d->setting = $key; + $d->value = $value; + $d->save(); + } + } + + r2(U . "settings/maintenance", 's', Lang::T('Settings Saved Successfully')); + } + $ui->assign('_c', $config); + $ui->assign('_title', Lang::T('Maintenance Mode Settings')); + $ui->display('maintenance-mode.tpl'); + break; + default: $ui->display('a404.tpl'); } diff --git a/system/updates.json b/system/updates.json index 9146363c..d2326100 100644 --- a/system/updates.json +++ b/system/updates.json @@ -99,5 +99,8 @@ ], "2024.5.18" : [ "ALTER TABLE `tbl_customers` CHANGE `status` `status` ENUM('Active','Banned','Disabled','Inactive','Limited','Suspended') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'Active';" + ], + "2024.5.20" : [ + "ALTER TABLE `tbl_customers` ADD `city` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci AFTER `address`, ADD `district` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci AFTER `city`, ADD `state` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci AFTER `district`, ADD `zip` VARCHAR(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci AFTER `state`;" ] } \ No newline at end of file diff --git a/ui/ui/customers-add.tpl b/ui/ui/customers-add.tpl index db70e9cd..4985dfb5 100644 --- a/ui/ui/customers-add.tpl +++ b/ui/ui/customers-add.tpl @@ -121,6 +121,51 @@ +