From d7d9d9efa18420d7d2792f64b2335ead9e47ef3b Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Wed, 21 Sep 2022 14:15:00 +0700 Subject: [PATCH] $_c ke $config --- system/autoload/Hookers.php | 48 ++++++++++++++++++++++++++++++++ system/controllers/accounts.php | 4 +-- system/controllers/customers.php | 8 +++--- system/controllers/export.php | 12 ++++---- system/controllers/order.php | 18 ++++++------ system/controllers/pool.php | 6 ++-- system/controllers/prepaid.php | 48 ++++++++++++++++---------------- system/controllers/register.php | 6 ++-- system/controllers/routers.php | 4 +-- system/controllers/services.php | 12 ++++---- system/controllers/voucher.php | 8 +++--- system/cron.php | 38 ++++++++++++++++++++++++- 12 files changed, 148 insertions(+), 64 deletions(-) create mode 100644 system/autoload/Hookers.php diff --git a/system/autoload/Hookers.php b/system/autoload/Hookers.php new file mode 100644 index 00000000..84c1670b --- /dev/null +++ b/system/autoload/Hookers.php @@ -0,0 +1,48 @@ + $name, + "admin" => $admin, + "position" => $position, + "icon" => $icon, + "function" => $function + ]; +} + +$hook_registered = array(); + +function register_hook($action, $function){ + $hook_registered[] = [ + 'action' => $action, + 'function' => $function + ]; +} + +function run_hook($action){ + global $hook_registered; + foreach($hook_registered as $hook){ + if($hook['action'] == $action){ + if(function_exists($hook['function'])){ + call_user_func($hook['function']); + } + } + } +} + diff --git a/system/controllers/accounts.php b/system/controllers/accounts.php index a8e0cd73..9907d2ec 100644 --- a/system/controllers/accounts.php +++ b/system/controllers/accounts.php @@ -42,7 +42,7 @@ switch ($action) { if ($c){ $mikrotik = Mikrotik::info($c['routers']); if($c['type'] == 'Hotspot'){ - if(!$_c['radius_mode']){ + if(!$config['radius_mode']){ $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::setHotspotUser($client,$c['username'],$npass); Mikrotik::removeHotspotActiveUser($client,$user['username']); @@ -56,7 +56,7 @@ switch ($action) { r2(U.'login'); }else{ - if(!$_c['radius_mode']){ + if(!$config['radius_mode']){ $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::setPpoeUser($client,$c['username'],$npass); Mikrotik::removePpoeActive($client,$user['username']); diff --git a/system/controllers/customers.php b/system/controllers/customers.php index 34e5d6f8..4086bb38 100644 --- a/system/controllers/customers.php +++ b/system/controllers/customers.php @@ -64,13 +64,13 @@ switch ($action) { if ($c) { $mikrotik = Mikrotik::info($c['routers']); if ($c['type'] == 'Hotspot') { - if(!$_c['radius_mode']){ + if(!$config['radius_mode']){ $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::removeHotspotUser($client,$c['username']); Mikrotik::removeHotspotActiveUser($client,$user['username']); } } else { - if(!$_c['radius_mode']){ + if(!$config['radius_mode']){ $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::removePpoeUser($client,$c['username']); Mikrotik::removePpoeActive($client,$user['username']); @@ -182,7 +182,7 @@ switch ($action) { if ($c) { $mikrotik = Mikrotik::info($c['routers']); if ($c['type'] == 'Hotspot') { - if(!$_c['radius_mode']){ + if(!$config['radius_mode']){ $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::setHotspotUser($client,$c['username'],$password); Mikrotik::removeHotspotActiveUser($client,$user['username']); @@ -191,7 +191,7 @@ switch ($action) { $d->password = $password; $d->save(); } else { - if(!$_c['radius_mode']){ + if(!$config['radius_mode']){ $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::setPpoeUser($client,$c['username'],$password); Mikrotik::removePpoeActive($client,$user['username']); diff --git a/system/controllers/export.php b/system/controllers/export.php index abbc1f49..07bb8d3a 100644 --- a/system/controllers/export.php +++ b/system/controllers/export.php @@ -70,7 +70,7 @@ switch ($action) { - + @@ -88,7 +88,7 @@ switch ($action) { $username = $value['username']; $plan_name = $value['plan_name']; $type = $value['type']; - $price = $_c['currency_code'].' '. number_format($value['price'],0,$_c['dec_point'],$_c['thousands_sep']); + $price = $config['currency_code'].' '. number_format($value['price'],0,$config['dec_point'],$config['thousands_sep']); $recharged_on = date( $config['date_format'], strtotime($value['recharged_on'])); $expiration = date( $config['date_format'], strtotime($value['expiration'])); $time = $value['time']; @@ -108,7 +108,7 @@ switch ($action) { } $html .= '
'.$_L['Username'].'

'.$_L['Total_Income'].':

-

'.$_c['currency_code'].' '.number_format($xy,2,$_c['dec_point'],$_c['thousands_sep']).'

'; +

'.$config['currency_code'].' '.number_format($xy,2,$config['dec_point'],$config['thousands_sep']).'

'; run_hook('print_pdf_by_date'); #HOOK define('_MPDF_PATH','system/vendors/mpdf/'); @@ -243,7 +243,7 @@ EOF; - + @@ -261,7 +261,7 @@ EOF; $username = $value['username']; $plan_name = $value['plan_name']; $type = $value['type']; - $price = $_c['currency_code'].' '. number_format($value['price'],0,$_c['dec_point'],$_c['thousands_sep']); + $price = $config['currency_code'].' '. number_format($value['price'],0,$config['dec_point'],$config['thousands_sep']); $recharged_on = date( $config['date_format'], strtotime($value['recharged_on'])); $expiration = date( $config['date_format'], strtotime($value['expiration'])); $time = $value['time']; @@ -281,7 +281,7 @@ EOF; } $html .= '
'.$_L['Username'].'

'.$_L['Total_Income'].':

-

'.$_c['currency_code'].' '.number_format($xy,2,$_c['dec_point'],$_c['thousands_sep']).'

'; +

'.$config['currency_code'].' '.number_format($xy,2,$config['dec_point'],$config['thousands_sep']).'

'; run_hook('pdf_by_period'); #HOOK define('_MPDF_PATH','system/vendors/mpdf/'); diff --git a/system/controllers/order.php b/system/controllers/order.php index e99b8ae9..a5fc9553 100644 --- a/system/controllers/order.php +++ b/system/controllers/order.php @@ -71,7 +71,7 @@ switch ($action) { run_hook('customer_check_payment_status'); #HOOK include 'system/paymentgateway/' . $trx['gateway'] . '.php'; call_user_func($trx['gateway'] . '_validate_config'); - call_user_func($_c['payment_gateway'] . '_get_status', $trx, $user); + call_user_func($config['payment_gateway'] . '_get_status', $trx, $user); } else if ($routes['3'] == 'cancel') { run_hook('customer_cancel_payment'); #HOOK @@ -100,15 +100,15 @@ switch ($action) { $ui->display('user-orderView.tpl'); break; case 'buy': - if ($_c['payment_gateway'] == 'none') { + if ($config['payment_gateway'] == 'none') { r2(U . 'home', 'e', Lang::T("No Payment Gateway Available")); } - if (!file_exists('system/paymentgateway/' . $_c['payment_gateway'] . '.php')) { + if (!file_exists('system/paymentgateway/' . $config['payment_gateway'] . '.php')) { r2(U . 'home', 'e', Lang::T("No Payment Gateway Available")); } run_hook('customer_buy_plan'); #HOOK - include 'system/paymentgateway/' . $_c['payment_gateway'] . '.php'; - call_user_func($_c['payment_gateway'] . '_validate_config'); + include 'system/paymentgateway/' . $config['payment_gateway'] . '.php'; + call_user_func($config['payment_gateway'] . '_validate_config'); $router = ORM::for_table('tbl_routers')->where('enabled', '1')->find_one($routes['2'] * 1); $plan = ORM::for_table('tbl_plans')->where('enabled', '1')->find_one($routes['3'] * 1); @@ -123,7 +123,7 @@ switch ($action) { if ($d['pg_url_payment']) { r2(U . "order/view/" . $d['id'], 'w', Lang::T("You already have unpaid transaction, cancel it or pay it.")); } else { - if ($_c['payment_gateway'] == $d['gateway']) { + if ($config['payment_gateway'] == $d['gateway']) { $id = $d['id']; } else { $d->status = 4; @@ -134,7 +134,7 @@ switch ($action) { if (empty($id)) { $d = ORM::for_table('tbl_payment_gateway')->create(); $d->username = $user['username']; - $d->gateway = $_c['payment_gateway']; + $d->gateway = $config['payment_gateway']; $d->plan_id = $plan['id']; $d->plan_name = $plan['name_plan']; $d->routers_id = $router['id']; @@ -146,7 +146,7 @@ switch ($action) { $id = $d->id(); } else { $d->username = $user['username']; - $d->gateway = $_c['payment_gateway']; + $d->gateway = $config['payment_gateway']; $d->plan_id = $plan['id']; $d->plan_name = $plan['name_plan']; $d->routers_id = $router['id']; @@ -159,7 +159,7 @@ switch ($action) { if (!$id) { r2(U . "order/package/" . $d['id'], 'e', Lang::T("Failed to create Transaction..")); } else { - call_user_func($_c['payment_gateway'] . '_create_transaction', $d, $user); + call_user_func($config['payment_gateway'] . '_create_transaction', $d, $user); } break; default: diff --git a/system/controllers/pool.php b/system/controllers/pool.php index 14ba3f04..363bd270 100644 --- a/system/controllers/pool.php +++ b/system/controllers/pool.php @@ -63,7 +63,7 @@ switch ($action) { $d = ORM::for_table('tbl_pool')->find_one($id); $mikrotik = Mikrotik::info($d['routers']); if ($d) { - if (!$_c['radius_mode']) { + if (!$config['radius_mode']) { $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::removePool($client, $d['pool_name']); } @@ -92,7 +92,7 @@ switch ($action) { } $mikrotik = Mikrotik::info($routers); if ($msg == '') { - if (!$_c['radius_mode']) { + if (!$config['radius_mode']) { $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::removePool($client, $name, $ip_address); } @@ -132,7 +132,7 @@ switch ($action) { $mikrotik = Mikrotik::info($routers); if ($msg == '') { - if (!$_c['radius_mode']) { + if (!$config['radius_mode']) { $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::setPool($client, $name,$poolName, $ip_address); } diff --git a/system/controllers/prepaid.php b/system/controllers/prepaid.php index 846bb75b..b03872a5 100644 --- a/system/controllers/prepaid.php +++ b/system/controllers/prepaid.php @@ -103,7 +103,7 @@ switch ($action) { run_hook('recharge_customer'); #HOOK if ($type == 'Hotspot') { if ($b) { - if(!$_c['radius_mode']){ + if(!$config['radius_mode']){ $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::removeHotspotUser($client,$c['username']); Mikrotik::addHotspotUser($client,$p,$c); @@ -136,7 +136,7 @@ switch ($action) { $t->type = "Hotspot"; $t->save(); } else { - if(!$_c['radius_mode']){ + if(!$config['radius_mode']){ $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::addHotspotUser($client,$p,$c); } @@ -175,7 +175,7 @@ switch ($action) { } else { if ($b) { - if(!$_c['radius_mode']){ + if(!$config['radius_mode']){ $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::removePpoeUser($client,$c['username']); Mikrotik::addPpoeUser($client,$p,$c); @@ -208,7 +208,7 @@ switch ($action) { $t->type = "PPPOE"; $t->save(); } else { - if(!$_c['radius_mode']){ + if(!$config['radius_mode']){ $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::addPpoeUser($client,$p,$c); } @@ -249,9 +249,9 @@ switch ($action) { $in = ORM::for_table('tbl_transactions')->where('username', $c['username'])->order_by_desc('id')->find_one(); $ui->assign('in', $in); - sendWhatsapp($c['username'], "*$_c[CompanyName]*\n". - "$_c[address]\n". - "$_c[phone]\n". + sendWhatsapp($c['username'], "*$config[CompanyName]*\n". + "$config[address]\n". + "$config[phone]\n". "\n\n". "INVOICE: *$in[invoice]*\n". "$_L[Date] : $date_now\n". @@ -259,13 +259,13 @@ switch ($action) { "\n\n". "$_L[Type] : *$in[type]*\n". "$_L[Plan_Name] : *$in[plan_name]*\n". - "$_L[Plan_Price] : *$_c[currency_code] ".number_format($in['price'],2,$_c['dec_point'],$_c['thousands_sep'])."*\n\n". + "$_L[Plan_Price] : *$config[currency_code] ".number_format($in['price'],2,$config['dec_point'],$config['thousands_sep'])."*\n\n". "$_L[Username] : *$in[username]*\n". "$_L[Password] : **********\n\n". - "$_L[Created_On] :\n*".date($_c['date_format'], strtotime($in['recharged_on']))." $in[time]*\n". - "$_L[Expires_On] :\n*".date($_c['date_format'], strtotime($in['expiration']))." $in[time]*\n". + "$_L[Created_On] :\n*".date($config['date_format'], strtotime($in['recharged_on']))." $in[time]*\n". + "$_L[Expires_On] :\n*".date($config['date_format'], strtotime($in['expiration']))." $in[time]*\n". "\n\n". - "$_c[note]"); + "$config[note]"); $ui->assign('date', $date_now); @@ -309,14 +309,14 @@ switch ($action) { if ($d) { run_hook('delete_customer_active_plan'); #HOOK if ($d['type'] == 'Hotspot') { - if(!$_c['radius_mode']){ + if(!$config['radius_mode']){ $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::removeHotspotUser($client,$c['username']); } $d->delete(); } else { - if(!$_c['radius_mode']){ + if(!$config['radius_mode']){ $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::removePpoeUser($client,$c['username']); } @@ -560,7 +560,7 @@ switch ($action) { if ($v1) { if ($v1['type'] == 'Hotspot') { if ($b) { - if(!$_c['radius_mode']){ + if(!$config['radius_mode']){ $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::removeHotspotUser($client,$c['username']); Mikrotik::addHotspotUser($client,$p,$c); @@ -593,7 +593,7 @@ switch ($action) { $t->type = "Hotspot"; $t->save(); } else { - if(!$_c['radius_mode']){ + if(!$config['radius_mode']){ $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::addHotspotUser($client,$p,$c); } @@ -637,7 +637,7 @@ switch ($action) { "\nPrice: ".$p['price']); } else { if ($b) { - if(!$_c['radius_mode']){ + if(!$config['radius_mode']){ $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::removePpoeUser($client,$c['username']); Mikrotik::addPpoeUser($client,$p,$c); @@ -670,7 +670,7 @@ switch ($action) { $t->type = "PPPOE"; $t->save(); } else { - if(!$_c['radius_mode']){ + if(!$config['radius_mode']){ $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::addPpoeUser($client,$p,$c); } @@ -718,9 +718,9 @@ switch ($action) { $ui->assign('in', $in); - sendWhatsapp($c['username'], "*$_c[CompanyName]*\n". - "$_c[address]\n". - "$_c[phone]\n". + sendWhatsapp($c['username'], "*$config[CompanyName]*\n". + "$config[address]\n". + "$config[phone]\n". "\n\n". "INVOICE: *$in[invoice]*\n". "$_L[Date] : $date_now\n". @@ -728,13 +728,13 @@ switch ($action) { "\n\n". "$_L[Type] : *$in[type]*\n". "$_L[Plan_Name] : *$in[plan_name]*\n". - "$_L[Plan_Price] : *$_c[currency_code] ".number_format($in['price'],2,$_c['dec_point'],$_c['thousands_sep'])."*\n\n". + "$_L[Plan_Price] : *$config[currency_code] ".number_format($in['price'],2,$config['dec_point'],$config['thousands_sep'])."*\n\n". "$_L[Username] : *$in[username]*\n". "$_L[Password] : **********\n\n". - "$_L[Created_On] :\n*".date($_c['date_format'], strtotime($in['recharged_on']))." $in[time]*\n". - "$_L[Expires_On] :\n*".date($_c['date_format'], strtotime($in['expiration']))." $in[time]*\n". + "$_L[Created_On] :\n*".date($config['date_format'], strtotime($in['recharged_on']))." $in[time]*\n". + "$_L[Expires_On] :\n*".date($config['date_format'], strtotime($in['expiration']))." $in[time]*\n". "\n\n". - "$_c[note]"); + "$config[note]"); $ui->assign('date', $date_now); $ui->display('invoice.tpl'); diff --git a/system/controllers/register.php b/system/controllers/register.php index b3c53f74..a369e52b 100644 --- a/system/controllers/register.php +++ b/system/controllers/register.php @@ -39,7 +39,7 @@ switch ($do) { $msg .= $_L['PasswordsNotMatch'] . '
'; } - if(!empty($_c['sms_url'])){ + if(!empty($config['sms_url'])){ $otpPath .= sha1($username.$db_password).".txt"; run_hook('validate_otp'); #HOOK if(file_exists($otpPath) && time()-filemtime($otpPath)>300){ @@ -109,7 +109,7 @@ switch ($do) { break; default: - if(!empty($_c['sms_url'])){ + if(!empty($config['sms_url'])){ $username = _post('username'); if(!empty($username)){ $d = ORM::for_table('tbl_customers')->where('username', $username)->find_one(); @@ -132,7 +132,7 @@ switch ($do) { }else{ $otp = rand(100000,999999); file_put_contents($otpPath, $otp); - sendSMS($username,$_c['CompanyName']."\nYour Verification code are: $otp"); + sendSMS($username,$config['CompanyName']."\nYour Verification code are: $otp"); $ui->assign('username', $username); $ui->assign('notify', '