From 13b448da69ae0d2c647bfb6424b25ab6e943a7e9 Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Tue, 19 Dec 2023 11:35:49 +0700 Subject: [PATCH] Disable Registration --- system/controllers/login.php | 91 ++++++++++- system/controllers/settings.php | 260 ++---------------------------- system/lan/english/common.lan.php | 4 + ui/ui/app-settings.tpl | 39 ++++- ui/ui/user-login-noreg.tpl | 82 ++++++++++ 5 files changed, 223 insertions(+), 253 deletions(-) create mode 100644 ui/ui/user-login-noreg.tpl diff --git a/system/controllers/login.php b/system/controllers/login.php index 8a491dd6..7b80deca 100644 --- a/system/controllers/login.php +++ b/system/controllers/login.php @@ -42,8 +42,97 @@ switch ($do) { break; + case 'activation': + $voucher = _post('voucher'); + $username = _post('username'); + $v1 = ORM::for_table('tbl_voucher')->where('code', $voucher)->find_one(); + if ($v1) { + // coucher exists, check customer exists or not + $user = ORM::for_table('tbl_customers')->where('username', $username)->find_one(); + if (!$user) { + $d = ORM::for_table('tbl_customers')->create(); + $d->username = alphanumeric($username, "+_."); + $d->password = $voucher; + $d->fullname = ''; + $d->address = ''; + $d->email = ''; + $d->phonenumber = (strlen($username) < 21) ? $username : ''; + if ($d->save()) { + $user = ORM::for_table('tbl_customers')->where('username', $username)->find_one($d->id()); + if (!$user) { + r2(U . 'login', 'e', Lang::T('Voucher activation failed')); + } + } else { + r2(U . 'login', 'e', Lang::T('Voucher activation failed').'.'); + } + } + if ($v1['status'] == 0) { + $oldPass = $user['password']; + // change customer password to voucher code + $user->password = $voucher; + $user->save(); + // voucher activation + if (Package::rechargeUser($user['id'], $v1['routers'], $v1['id_plan'], "Activation", "Voucher")) { + $v1->status = "1"; + $v1->user = $user['username']; + $v1->save(); + // add customer to mikrotik + if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'])) { + $m = Mikrotik::info($v1['routers']); + $c = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']); + Mikrotik::logMeIn($c, $user['username'], $user['password'], $_SESSION['nux-ip'], $_SESSION['nux-mac']); + if(!empty($config['voucher_redirect'])){ + r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, you are connected to internet")); + }else{ + r2(U . "login", 's', Lang::T("Voucher activation success, you are connected to internet")); + } + } + 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 { + // if failed to recharge, restore old password + $user->password = $oldPass; + $user->save(); + r2(U . 'login', 'e', Lang::T("Failed to activate voucher")); + } + } else { + // used voucher + // check if voucher used by this username + if ($v1['user'] == $user['username']) { + if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'])) { + $m = Mikrotik::info($v1['routers']); + $c = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']); + Mikrotik::logMeIn($c, $user['username'], $user['password'], $_SESSION['nux-ip'], $_SESSION['nux-mac']); + if(!empty($config['voucher_redirect'])){ + r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, you are connected to internet")); + }else{ + r2(U . "login", 's', Lang::T("Voucher activation success, now you can login")); + } + }else{ + if(!empty($config['voucher_redirect'])){ + r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, you are connected to internet")); + }else{ + r2(U . "login", 's', Lang::T("Voucher activation success, now you can login")); + } + } + } else { + // voucher used by other customer + r2(U . 'login', 'e', $_L['Voucher_Not_Valid']); + } + } + } else { + // voucher not found + r2(U . 'login', 'e', $_L['Voucher_Not_Valid']); + } default: run_hook('customer_view_login'); #HOOK - $ui->display('user-login.tpl'); + if($config['disable_registration']=='yes'){ + $ui->display('user-login-noreg.tpl'); + }else{ + $ui->display('user-login.tpl'); + } break; } diff --git a/system/controllers/settings.php b/system/controllers/settings.php index e49fca14..346d695d 100644 --- a/system/controllers/settings.php +++ b/system/controllers/settings.php @@ -243,27 +243,7 @@ switch ($action) { break; case 'app-post': - $company = _post('company'); - $footer = _post('footer'); - $enable_balance = _post('enable_balance'); - $allow_balance_transfer = _post('allow_balance_transfer'); - $disable_voucher = _post('disable_voucher'); - $telegram_bot = _post('telegram_bot'); - $telegram_target_id = _post('telegram_target_id'); - $sms_url = _post('sms_url'); - $wa_url = _post('wa_url'); - $minimum_transfer = _post('minimum_transfer'); - $user_notification_expired = _post('user_notification_expired'); - $user_notification_reminder = _post('user_notification_reminder'); - $user_notification_payment = _post('user_notification_payment'); - $address = _post('address'); - $tawkto = _post('tawkto'); - $http_proxy = _post('http_proxy'); - $http_proxyauth = _post('http_proxyauth'); - $radius_enable = _post('radius_enable'); - $radius_client = _post('radius_client'); - $theme = _post('theme'); - $voucher_format = _post('voucher_format'); + $company = _post('CompanyName'); run_hook('save_settings'); #HOOK @@ -279,206 +259,6 @@ switch ($action) { if ($company == '') { r2(U . 'settings/app', 'e', $_L['All_field_is_required']); } else { - $d = ORM::for_table('tbl_appconfig')->where('setting', 'CompanyName')->find_one(); - $d->value = $company; - $d->save(); - - $d = ORM::for_table('tbl_appconfig')->where('setting', 'address')->find_one(); - $d->value = $address; - $d->save(); - - $phone = _post('phone'); - $d = ORM::for_table('tbl_appconfig')->where('setting', 'phone')->find_one(); - $d->value = $phone; - $d->save(); - - - $d = ORM::for_table('tbl_appconfig')->where('setting', 'http_proxy')->find_one(); - if ($d) { - $d->value = $http_proxy; - $d->save(); - } else { - $d = ORM::for_table('tbl_appconfig')->create(); - $d->setting = 'http_proxy'; - $d->value = $http_proxy; - $d->save(); - } - - $d = ORM::for_table('tbl_appconfig')->where('setting', 'http_proxyauth')->find_one(); - if ($d) { - $d->value = $http_proxyauth; - $d->save(); - } else { - $d = ORM::for_table('tbl_appconfig')->create(); - $d->setting = 'http_proxyauth'; - $d->value = $http_proxyauth; - $d->save(); - } - - - $d = ORM::for_table('tbl_appconfig')->where('setting', 'theme')->find_one(); - if ($d) { - $d->value = $theme; - $d->save(); - } else { - $d = ORM::for_table('tbl_appconfig')->create(); - $d->setting = 'theme'; - $d->value = $theme; - $d->save(); - } - - $d = ORM::for_table('tbl_appconfig')->where('setting', 'CompanyFooter')->find_one(); - if ($d) { - $d->value = $footer; - $d->save(); - } else { - $d = ORM::for_table('tbl_appconfig')->create(); - $d->setting = 'CompanyFooter'; - $d->value = $footer; - $d->save(); - } - - $d = ORM::for_table('tbl_appconfig')->where('setting', 'voucher_format')->find_one(); - if ($d) { - $d->value = $voucher_format; - $d->save(); - } else { - $d = ORM::for_table('tbl_appconfig')->create(); - $d->setting = 'voucher_format'; - $d->value = $voucher_format; - $d->save(); - } - $d = ORM::for_table('tbl_appconfig')->where('setting', 'disable_voucher')->find_one(); - if ($d) { - $d->value = $disable_voucher; - $d->save(); - } else { - $d = ORM::for_table('tbl_appconfig')->create(); - $d->setting = 'disable_voucher'; - $d->value = $disable_voucher; - $d->save(); - } - - $d = ORM::for_table('tbl_appconfig')->where('setting', 'enable_balance')->find_one(); - if ($d) { - $d->value = $enable_balance; - $d->save(); - } else { - $d = ORM::for_table('tbl_appconfig')->create(); - $d->setting = 'enable_balance'; - $d->value = $enable_balance; - $d->save(); - } - - $d = ORM::for_table('tbl_appconfig')->where('setting', 'allow_balance_transfer')->find_one(); - if ($d) { - $d->value = $allow_balance_transfer; - $d->save(); - } else { - $d = ORM::for_table('tbl_appconfig')->create(); - $d->setting = 'allow_balance_transfer'; - $d->value = $allow_balance_transfer; - $d->save(); - } - - $d = ORM::for_table('tbl_appconfig')->where('setting', 'minimum_transfer')->find_one(); - if ($d) { - $d->value = $minimum_transfer; - $d->save(); - } else { - $d = ORM::for_table('tbl_appconfig')->create(); - $d->setting = 'minimum_transfer'; - $d->value = $minimum_transfer; - $d->save(); - } - - $d = ORM::for_table('tbl_appconfig')->where('setting', 'telegram_bot')->find_one(); - if ($d) { - $d->value = $telegram_bot; - $d->save(); - } else { - $d = ORM::for_table('tbl_appconfig')->create(); - $d->setting = 'telegram_bot'; - $d->value = $telegram_bot; - $d->save(); - } - - $d = ORM::for_table('tbl_appconfig')->where('setting', 'telegram_target_id')->find_one(); - if ($d) { - $d->value = $telegram_target_id; - $d->save(); - } else { - $d = ORM::for_table('tbl_appconfig')->create(); - $d->setting = 'telegram_target_id'; - $d->value = $telegram_target_id; - $d->save(); - } - - $d = ORM::for_table('tbl_appconfig')->where('setting', 'sms_url')->find_one(); - if ($d) { - $d->value = $sms_url; - $d->save(); - } else { - $d = ORM::for_table('tbl_appconfig')->create(); - $d->setting = 'sms_url'; - $d->value = $sms_url; - $d->save(); - } - - $d = ORM::for_table('tbl_appconfig')->where('setting', 'wa_url')->find_one(); - if ($d) { - $d->value = $wa_url; - $d->save(); - } else { - $d = ORM::for_table('tbl_appconfig')->create(); - $d->setting = 'wa_url'; - $d->value = $wa_url; - $d->save(); - } - - $d = ORM::for_table('tbl_appconfig')->where('setting', 'user_notification_expired')->find_one(); - if ($d) { - $d->value = $user_notification_expired; - $d->save(); - } else { - $d = ORM::for_table('tbl_appconfig')->create(); - $d->setting = 'user_notification_expired'; - $d->value = $user_notification_expired; - $d->save(); - } - - $d = ORM::for_table('tbl_appconfig')->where('setting', 'user_notification_reminder')->find_one(); - if ($d) { - $d->value = $user_notification_reminder; - $d->save(); - } else { - $d = ORM::for_table('tbl_appconfig')->create(); - $d->setting = 'user_notification_reminder'; - $d->value = $user_notification_reminder; - $d->save(); - } - - $d = ORM::for_table('tbl_appconfig')->where('setting', 'user_notification_payment')->find_one(); - if ($d) { - $d->value = $user_notification_payment; - $d->save(); - } else { - $d = ORM::for_table('tbl_appconfig')->create(); - $d->setting = 'user_notification_payment'; - $d->value = $user_notification_payment; - $d->save(); - } - - $d = ORM::for_table('tbl_appconfig')->where('setting', 'tawkto')->find_one(); - if ($d) { - $d->value = $tawkto; - $d->save(); - } else { - $d = ORM::for_table('tbl_appconfig')->create(); - $d->setting = 'tawkto'; - $d->value = $tawkto; - $d->save(); - } if ($radius_enable) { try { Radius::getTableNas()->find_many(); @@ -491,34 +271,20 @@ switch ($action) { die(); } } - - $d = ORM::for_table('tbl_appconfig')->where('setting', 'radius_enable')->find_one(); - if ($d) { - $d->value = $radius_enable; - $d->save(); - } else { - $d = ORM::for_table('tbl_appconfig')->create(); - $d->setting = 'radius_enable'; - $d->value = $radius_enable; - $d->save(); + // save all settings + foreach($_POST 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(); + } } - $d = ORM::for_table('tbl_appconfig')->where('setting', 'radius_client')->find_one(); - if ($d) { - $d->value = $radius_client; - $d->save(); - } else { - $d = ORM::for_table('tbl_appconfig')->create(); - $d->setting = 'radius_client'; - $d->value = $radius_client; - $d->save(); - } - - $note = _post('note'); - $d = ORM::for_table('tbl_appconfig')->where('setting', 'note')->find_one(); - $d->value = $note; - $d->save(); - _log('[' . $admin['username'] . ']: ' . $_L['Settings_Saved_Successfully'], 'Admin', $admin['id']); r2(U . 'settings/app', 's', $_L['Settings_Saved_Successfully']); diff --git a/system/lan/english/common.lan.php b/system/lan/english/common.lan.php index c4b03034..99ca4f10 100644 --- a/system/lan/english/common.lan.php +++ b/system/lan/english/common.lan.php @@ -413,3 +413,7 @@ $_L['Service_Type'] = 'Service Type'; $_L['Others'] = 'Others'; $_L['PPPoE'] = 'PPPoE'; $_L['Hotspot'] = 'Hotspot'; +$_L['Disable_Registration'] = 'Disable Registration'; +$_L['Customer_just_Login_with_Phone_number_and_Voucher_Code_Voucher_will_be_password'] = 'Customer just Login with Phone number and Voucher Code, Voucher will be password'; +$_L['Login__Activate_Voucher'] = 'Login / Activate Voucher'; +$_L['After_Customer_activate_voucher_or_login_customer_will_be_redirected_to_this_url'] = 'After Customer activate voucher or login, customer will be redirected to this url'; diff --git a/ui/ui/app-settings.tpl b/ui/ui/app-settings.tpl index e66a3a4d..f84b56f5 100644 --- a/ui/ui/app-settings.tpl +++ b/ui/ui/app-settings.tpl @@ -15,7 +15,7 @@
-
{$_L['App_Name_Help_Text']} @@ -34,7 +34,7 @@
-
{Lang::T('Will show below user pages')} @@ -113,6 +113,33 @@

UPPERCASE lowercase RaNdoM

+ {if $_c['disable_voucher'] != 'yes'} +
+ +
+ +
+

+ {Lang::T('Customer just Login with Phone number and Voucher Code, Voucher will be password')} +

+
+
+ +
+ +
+

+ {Lang::T('After Customer activate voucher or login, customer will be redirected to this url')} +

+
+ {/if}
@@ -198,7 +225,7 @@
- +
@@ -228,10 +255,12 @@
- {foreach $r as $rs} - + {/foreach}
diff --git a/ui/ui/user-login-noreg.tpl b/ui/ui/user-login-noreg.tpl new file mode 100644 index 00000000..1dec6020 --- /dev/null +++ b/ui/ui/user-login-noreg.tpl @@ -0,0 +1,82 @@ + + + + + + + {$_title} - {$_L['Login']} + + + + + + + + +
+ +
+

{$_c['CompanyName']}

+
+
+ {if isset($notify)} +
+
+ {$notify} +
+
+ {/if} +
+
+
+
{$_L['Announcement']}
+
+ {include file="$_path/../pages/Announcement.html"} +
+
+
+
+
+
{Lang::T('Login / Activate Voucher')}
+
+
+
+ +
+ {if $_c['country_code_phone']!= ''} + + + {else} + + {/if} + +
+
+
+ + +
+
+
+ +
+
+
+
+ Privacy + • + ToC +
+
+
+
+
+
+
+ + + + \ No newline at end of file