From 938173cab7e1fda12ea2014846040812b6e09c34 Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Thu, 18 Jul 2024 09:48:22 +0700 Subject: [PATCH] add change_username function --- system/controllers/plan.php | 1 + system/devices/Dummy.php | 6 +++++ system/devices/MikrotikHotspot.php | 21 +++++++++++++++++ system/devices/Radius.php | 36 +++++++++++++++--------------- system/devices/RadiusRest.php | 5 +++++ system/devices/readme.md | 5 +++++ 6 files changed, 56 insertions(+), 18 deletions(-) diff --git a/system/controllers/plan.php b/system/controllers/plan.php index 3153660e..d860e06b 100644 --- a/system/controllers/plan.php +++ b/system/controllers/plan.php @@ -322,6 +322,7 @@ switch ($action) { $d->status = 'on'; } } + // plan different then do something if ($oldPlanID != $id_plan) { $d->plan_id = $newPlan['id']; $d->namebp = $newPlan['name_plan']; diff --git a/system/devices/Dummy.php b/system/devices/Dummy.php index e4db1519..cdb0761b 100644 --- a/system/devices/Dummy.php +++ b/system/devices/Dummy.php @@ -27,6 +27,12 @@ class Dummy { { } + // customer change username + public function change_username($from, $to) + { + } + + // Add Plan to Mikrotik/Device function add_plan($plan) { diff --git a/system/devices/MikrotikHotspot.php b/system/devices/MikrotikHotspot.php index b4b44b35..e1ade421 100644 --- a/system/devices/MikrotikHotspot.php +++ b/system/devices/MikrotikHotspot.php @@ -51,6 +51,27 @@ class MikrotikHotspot $this->removeHotspotActiveUser($client, $customer['username']); } + // customer change username + public function change_username($plan, $from, $to) + { + $mikrotik = $this->info($plan['routers']); + $client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + //check if customer exists + $printRequest = new RouterOS\Request('/ip/hotspot/user/print'); + $printRequest->setArgument('.proplist', '.id'); + $printRequest->setQuery(RouterOS\Query::where('name', $from)); + $id = $client->sendSync($printRequest)->getProperty('.id'); + + if (!empty($cid)) { + $setRequest = new RouterOS\Request('/ip/hotspot/user/set'); + $setRequest->setArgument('numbers', $id); + $setRequest->setArgument('name', $to); + $client->sendSync($setRequest); + //disconnect then + $this->removeHotspotActiveUser($client, $from); + } + } + function add_plan($plan) { $mikrotik = $this->info($plan['routers']); diff --git a/system/devices/Radius.php b/system/devices/Radius.php index 60e4d080..1164099c 100644 --- a/system/devices/Radius.php +++ b/system/devices/Radius.php @@ -42,6 +42,24 @@ class Radius } } + public function change_username($from, $to) + { + $c = $this->getTableCustomer()->where_equal('username', $from)->findMany(); + if ($c) { + foreach ($c as $u) { + $u->username = $to; + $u->save(); + } + } + $c = $this->getTableUserPackage()->where_equal('username', $from)->findMany(); + if ($c) { + foreach ($c as $u) { + $u->username = $to; + $u->save(); + } + } + } + function add_plan($plan) { $bw = ORM::for_table("tbl_bandwidth")->find_one($plan['id_bw']); @@ -169,24 +187,6 @@ class Radius return $n->save(); } - public function customerChangeUsername($from, $to) - { - $c = $this->getTableCustomer()->where_equal('username', $from)->findMany(); - if ($c) { - foreach ($c as $u) { - $u->username = $to; - $u->save(); - } - } - $c = $this->getTableUserPackage()->where_equal('username', $from)->findMany(); - if ($c) { - foreach ($c as $u) { - $u->username = $to; - $u->save(); - } - } - } - public function customerDeactivate($username, $radiusDisconnect = true) { { global $radius_pass; diff --git a/system/devices/RadiusRest.php b/system/devices/RadiusRest.php index 0dc34eae..c1095ef6 100644 --- a/system/devices/RadiusRest.php +++ b/system/devices/RadiusRest.php @@ -27,6 +27,11 @@ class RadiusRest { { } + // customer change username + public function change_username($from, $to) + { + } + // Add Plan to Mikrotik/Device function add_plan($plan) { diff --git a/system/devices/readme.md b/system/devices/readme.md index 52551ef0..0a0022e8 100644 --- a/system/devices/readme.md +++ b/system/devices/readme.md @@ -33,6 +33,11 @@ class FileName { { } + // customer change username + public function change_username($from, $to) + { + } + // Add Plan to Mikrotik/Device function add_plan($plan) {