From 4f3647beaeffb95c227bee1febc1b0c9932d22a8 Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Mon, 7 Oct 2024 14:50:11 +0700 Subject: [PATCH] Show is Customer Online in the customer list --- system/controllers/autoload.php | 55 ++++++++++++++++++++++++++---- system/devices/MikrotikHotspot.php | 5 +-- ui/ui/customers.tpl | 2 +- 3 files changed, 52 insertions(+), 10 deletions(-) diff --git a/system/controllers/autoload.php b/system/controllers/autoload.php index e0920b5e..92f7688c 100644 --- a/system/controllers/autoload.php +++ b/system/controllers/autoload.php @@ -85,15 +85,56 @@ switch ($action) { $ui->display('autoload.tpl'); break; case 'customer_is_active': - $d = ORM::for_table('tbl_user_recharges')->where('customer_id', $routes['2'])->findOne(); - if ($d) { - if ($d['status'] == 'on') { - die('' . $d['namebp'] . ''); - } else { - die('' . $d['namebp'] . ''); + $c = ORM::for_table('tbl_customers')->where('username', $routes['2'])->find_one(); + $p = ORM::for_table('tbl_plans')->find_one($routes['3']); + $dvc = Package::getDevice($p); + if ($_app_stage != 'demo') { + if (file_exists($dvc)) { + require_once $dvc; + try { + //don't wait more than 5 seconds for response from device, otherwise we get timeout error. + ini_set('default_socket_timeout', 5); + if ((new $p['device'])->online_customer($c, $p['routers'])) { + echo ' '; + } + } catch (Exception $e) { + echo ' '; + } } + } + break; + case 'plan_is_active': + $ds = ORM::for_table('tbl_user_recharges')->where('customer_id', $routes['2'])->find_array(); + if ($ds) { + $ps = []; + $c = ORM::for_table('tbl_customers')->find_one($routes['2']); + foreach ($ds as $d) { + if ($d['status'] == 'on') { + $p = ORM::for_table('tbl_plans')->find_one($d['plan_id']); + $dvc = Package::getDevice($p); + $status = ""; + if ($_app_stage != 'demo') { + if (file_exists($dvc)) { + require_once $dvc; + try { + //don't wait more than 5 seconds for response from device, otherwise we get timeout error. + ini_set('default_socket_timeout', 5); + if ((new $p['device'])->online_customer($c, $p['routers'])) { + $status = ' '; + } + } catch (Exception $e) { + $status = ' '; + } + } + } + $ps[] = ('' . $d['namebp'] . ' ' . $status . ''); + } else { + $ps[] = ('' . $d['namebp'] . ''); + } + } + echo implode("
", $ps); } else { - die(''); + die(''); } break; case 'customer_select2': diff --git a/system/devices/MikrotikHotspot.php b/system/devices/MikrotikHotspot.php index f3b6226a..84c041f4 100644 --- a/system/devices/MikrotikHotspot.php +++ b/system/devices/MikrotikHotspot.php @@ -109,9 +109,10 @@ class MikrotikHotspot $client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); $printRequest = new RouterOS\Request( '/ip hotspot active print', - RouterOS\Query::where('name', $customer['username']) + RouterOS\Query::where('user', $customer['username']) ); - return $client->sendSync($printRequest)->getProperty('.id'); + $id = $client->sendSync($printRequest)->getProperty('.id'); + return $id; } function connect_customer($customer, $ip, $mac_address, $router_name) diff --git a/ui/ui/customers.tpl b/ui/ui/customers.tpl index 7829ffcd..7bb00743 100644 --- a/ui/ui/customers.tpl +++ b/ui/ui/customers.tpl @@ -132,7 +132,7 @@ class="glyphicon glyphicon-map-marker"> {/if} - + {$ds['service_type']}