From 7a94254df90313de583ae8b89a583e5b3052b105 Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Fri, 7 Jun 2024 17:21:29 +0700 Subject: [PATCH] done, maybe, need to test all --- system/controllers/autoload_user.php | 23 ++++++++++++-------- system/controllers/login.php | 32 ++++++++++++++++++++++------ system/controllers/order.php | 2 +- system/controllers/radius.php | 6 ++++-- system/controllers/settings.php | 11 ++-------- system/devices/MikrotikHotspot.php | 2 +- system/devices/MikrotikPppoe.php | 17 +++++++++++++++ ui/ui/app-settings.tpl | 6 ------ 8 files changed, 64 insertions(+), 35 deletions(-) diff --git a/system/controllers/autoload_user.php b/system/controllers/autoload_user.php index 8e50773b..b75010f4 100644 --- a/system/controllers/autoload_user.php +++ b/system/controllers/autoload_user.php @@ -17,16 +17,21 @@ switch ($action) { case 'isLogin': $bill = ORM::for_table('tbl_user_recharges')->where('id', $routes['2'])->where('username', $user['username'])->findOne(); if ($bill['type'] == 'Hotspot' && $bill['status'] == 'on') { - $m = Mikrotik::info($bill['routers']); - $client = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']); - if (Mikrotik::isUserLogin($client, $user['username'])) { - die(''.Lang::T('You are Online, Logout?').''); - } else { - if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'])) { - die(''.Lang::T('Not Online, Login now?').''); - }else{ - die(Lang::T('Your account not connected to internet')); + $dvc = Package::getDevice($d); + if (file_exists($dvc)) { + require_once $dvc; + if ((new $d['device'])->online_customer($user, $bill['routers'])) { + die(''.Lang::T('You are Online, Logout?').''); + } else { + if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'])) { + die(''.Lang::T('Not Online, Login now?').''); + }else{ + die(Lang::T('Your account not connected to internet')); + } } + + } else { + new Exception(Lang::T("Devices Not Found")); } } else { die('--'); diff --git a/system/controllers/login.php b/system/controllers/login.php index 663d3c02..f093514b 100644 --- a/system/controllers/login.php +++ b/system/controllers/login.php @@ -8,7 +8,7 @@ $maintenance_mode = $config['maintenance_mode']; if ($maintenance_mode == true){ displayMaintenanceMessage(); - } + } if (User::getID()) { r2(U . 'home'); @@ -95,9 +95,18 @@ switch ($do) { // add customer to mikrotik if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'])) { try { - $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']); + $p = ORM::for_table('tbl_plans')->where('id', $v1['id_plan'])->find_one(); + $dvc = Package::getDevice($p); + if (file_exists($dvc)) { + require_once $dvc; + (new $p['device'])->connect_customer($user, $_SESSION['nux-ip'], $_SESSION['nux-mac'], $v1['routers']); + } else { + 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")); + } + } if (!empty($config['voucher_redirect'])) { r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, you are connected to internet")); } else { @@ -130,9 +139,18 @@ switch ($do) { $user->save(); if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'])) { try { - $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']); + $p = ORM::for_table('tbl_plans')->where('id', $v1['id_plan'])->find_one(); + $dvc = Package::getDevice($p); + if (file_exists($dvc)) { + require_once $dvc; + (new $p['device'])->connect_customer($user, $_SESSION['nux-ip'], $_SESSION['nux-mac'], $v1['routers']); + } else { + 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")); + } + } if (!empty($config['voucher_redirect'])) { r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, you are connected to internet")); } else { diff --git a/system/controllers/order.php b/system/controllers/order.php index bc07be16..f22e97ce 100644 --- a/system/controllers/order.php +++ b/system/controllers/order.php @@ -128,7 +128,7 @@ switch ($action) { r2(U . "order/package", 'e', Lang::T("Transaction Not found")); } - $router = Mikrotik::info($trx['routers']); + $router = ORM::for_table('tbl_routers')->where('name', $trx['routers'])->find_one(); $plan = ORM::for_table('tbl_plans')->find_one($trx['plan_id']); $bandw = ORM::for_table('tbl_bandwidth')->find_one($plan['id_bw']); $invoice = ORM::for_table('tbl_transactions')->where("invoice", $trx['trx_invoice'])->find_one(); diff --git a/system/controllers/radius.php b/system/controllers/radius.php index 3e1357f3..24e6b8ac 100644 --- a/system/controllers/radius.php +++ b/system/controllers/radius.php @@ -56,7 +56,8 @@ switch ($action) { $msg .= 'NAS IP Exists
'; } if ($msg == '') { - $id = Radius::nasAdd($shortname, $nasname, $ports, $secret, $routers, $description, $type, $server, $community); + require_once $DEVICE_PATH . DIRECTORY_SEPARATOR . "Radius.php"; + (new Radius())->nasAdd($shortname, $nasname, $ports, $secret, $routers, $description, $type, $server, $community); if ($id > 0) { r2(U . 'radius/nas-list/', 's', "NAS Added"); } else { @@ -113,7 +114,8 @@ switch ($action) { $type = null; } if ($msg == '') { - if (Radius::nasUpdate($id, $shortname, $nasname, $ports, $secret, $routers, $description, $type, $server, $community)) { + require_once $DEVICE_PATH . DIRECTORY_SEPARATOR . "Radius.php"; + if ((new Radius())->nasUpdate($id, $shortname, $nasname, $ports, $secret, $routers, $description, $type, $server, $community)) { r2(U . 'radius/list/', 's', "NAS Saved"); } else { r2(U . 'radius/nas-add', 'e', 'NAS NOT Exists'); diff --git a/system/controllers/settings.php b/system/controllers/settings.php index 83fcd41e..9596e2f5 100644 --- a/system/controllers/settings.php +++ b/system/controllers/settings.php @@ -41,14 +41,6 @@ switch ($action) { $logo = $UPLOAD_URL_PATH . DIRECTORY_SEPARATOR . 'logo.default.png'; } $ui->assign('logo', $logo); - if ($config['radius_enable'] && empty($config['radius_client'])) { - try { - $config['radius_client'] = Radius::getClient(); - $ui->assign('_c', $_c); - } catch (Exception $e) { - //ignore - } - } $themes = []; $files = scandir('ui/themes/'); foreach ($files as $file) { @@ -109,7 +101,8 @@ switch ($action) { } else { if ($radius_enable) { try { - Radius::getTableNas()->find_many(); + require_once $DEVICE_PATH . DIRECTORY_SEPARATOR . "Radius.php"; + (new Radius())->getTableNas()->find_many(); } catch (Exception $e) { $ui->assign("error_title", "RADIUS Error"); $ui->assign("error_message", "Radius table not found.

" . diff --git a/system/devices/MikrotikHotspot.php b/system/devices/MikrotikHotspot.php index bc6177a7..a2d88c38 100644 --- a/system/devices/MikrotikHotspot.php +++ b/system/devices/MikrotikHotspot.php @@ -93,7 +93,7 @@ class MikrotikHotspot $client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); $printRequest = new RouterOS\Request( '/ip hotspot active print', - RouterOS\Query::where('user', $customer['username']) + RouterOS\Query::where('name', $customer['username']) ); return $client->sendSync($printRequest)->getProperty('.id'); } diff --git a/system/devices/MikrotikPppoe.php b/system/devices/MikrotikPppoe.php index 0eb910d5..2f096c55 100644 --- a/system/devices/MikrotikPppoe.php +++ b/system/devices/MikrotikPppoe.php @@ -208,6 +208,23 @@ class MikrotikPppoe ); } + + function online_customer($customer, $router_name) + { + global $_app_stage; + if ($_app_stage == 'demo') { + return; + } + $mikrotik = $this->info($router_name); + $client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + $printRequest = new RouterOS\Request( + '/ppp active print', + RouterOS\Query::where('user', $customer['username']) + ); + return $client->sendSync($printRequest)->getProperty('.id'); + } + + function connect_customer($customer, $ip, $mac_address, $router_name) { global $_app_stage; diff --git a/ui/ui/app-settings.tpl b/ui/ui/app-settings.tpl index 141a0ab7..37ecad48 100644 --- a/ui/ui/app-settings.tpl +++ b/ui/ui/app-settings.tpl @@ -220,12 +220,6 @@ href="https://github.com/hotspotbilling/phpnuxbill/wiki/FreeRadius" target="_blank">Radius Instructions

-
- -
- -
-