From 84bc680f40b1281b6e0ddb2a65e0e3672c556466 Mon Sep 17 00:00:00 2001 From: gerandonk Date: Mon, 9 Sep 2024 07:19:48 +0700 Subject: [PATCH] Change Local-Ip PPPoE to Remote-IP Change Local-Ip PPPoE to Remote-IP in customer page and ignor attribute if empty --- system/devices/MikrotikPppoe.php | 58 +++++++++++++++++++++++++++----- ui/ui/customers-add.tpl | 2 +- ui/ui/customers-edit.tpl | 2 +- ui/ui/customers-view.tpl | 2 +- 4 files changed, 53 insertions(+), 11 deletions(-) diff --git a/system/devices/MikrotikPppoe.php b/system/devices/MikrotikPppoe.php index 6f291c48..f9d46dd0 100644 --- a/system/devices/MikrotikPppoe.php +++ b/system/devices/MikrotikPppoe.php @@ -10,14 +10,14 @@ use PEAR2\Net\RouterOS; -class MikrotikPppoe +class MikrotikPppoeCustom { // show Description function description() { return [ 'title' => 'Mikrotik PPPOE', - 'description' => 'To handle connection between PHPNuxBill with Mikrotik PPPOE', + 'description' => 'To handle connection between PHPNuxBill with Mikrotik PPPOE using Custom Username, IP and Password', 'author' => 'ibnux', 'url' => [ 'Github' => 'https://github.com/hotspotbilling/phpnuxbill/', @@ -39,14 +39,28 @@ class MikrotikPppoe }else{ $setRequest = new RouterOS\Request('/ppp/secret/set'); $setRequest->setArgument('numbers', $cid); - $setRequest->setArgument('password', $customer['password']); - $setRequest->setArgument('name', $customer['username']); + if (!empty($customer['pppoe_password'])) { + $setRequest->setArgument('password', $customer['pppoe_password']); + } else { + $setRequest->setArgument('password', $customer['password']); + } + if (!empty($customer['pppoe_username'])) { + $setRequest->setArgument('name', $customer['pppoe_username']); + } else { + $setRequest->setArgument('name', $customer['username']); + } + if (!empty($customer['pppoe_ip'])) { + $setRequest->setArgument('remote-address', $customer['pppoe_ip']); + } $setRequest->setArgument('profile', $plan['name_plan']); $setRequest->setArgument('comment', $customer['fullname'] . ' | ' . $customer['email'] . ' | ' . implode(', ', User::getBillNames($customer['id']))); $client->sendSync($setRequest); //disconnect then if(isset($isChangePlan) && $isChangePlan){ $this->removePpoeActive($client, $customer['username']); + if (!empty($customer['pppoe_username'])) { + $this->removePpoeActive($client, $customer['pppoe_username']); + } } } } @@ -60,11 +74,20 @@ class MikrotikPppoe if($p){ $this->add_customer($customer, $p); $this->removePpoeActive($client, $customer['username']); + if (!empty($customer['pppoe_username'])) { + $this->removePpoeActive($client, $customer['pppoe_username']); + } return; } } - $this->removePpoeActive($client, $customer['username']); $this->removePpoeUser($client, $customer['username']); + if (!empty($customer['pppoe_username'])) { + $this->removePpoeUser($client, $customer['pppoe_username']); + } + $this->removePpoeActive($client, $customer['username']); + if (!empty($customer['pppoe_username'])) { + $this->removePpoeActive($client, $customer['pppoe_username']); + } } // customer change username @@ -125,7 +148,15 @@ class MikrotikPppoe function getIdByCustomer($customer, $client){ $printRequest = new RouterOS\Request('/ppp/secret/print'); $printRequest->setQuery(RouterOS\Query::where('name', $customer['username'])); - return $client->sendSync($printRequest)->getProperty('.id'); + $id = $client->sendSync($printRequest)->getProperty('.id'); + if(empty($id)){ + if (!empty($customer['pppoe_username'])) { + $printRequest = new RouterOS\Request('/ppp/secret/print'); + $printRequest->setQuery(RouterOS\Query::where('name', $customer['pppoe_username'])); + $id = $client->sendSync($printRequest)->getProperty('.id'); + } + } + return $id; } function update_plan($old_name, $new_plan) @@ -294,8 +325,19 @@ class MikrotikPppoe $setRequest->setArgument('service', 'pppoe'); $setRequest->setArgument('profile', $plan['name_plan']); $setRequest->setArgument('comment', $customer['fullname'] . ' | ' . $customer['email'] . ' | ' . implode(', ', User::getBillNames($customer['id']))); - $setRequest->setArgument('password', $customer['password']); - $setRequest->setArgument('name', $customer['username']); + if (!empty($customer['pppoe_password'])) { + $setRequest->setArgument('password', $customer['pppoe_password']); + } else { + $setRequest->setArgument('password', $customer['password']); + } + if (!empty($customer['pppoe_username'])) { + $setRequest->setArgument('name', $customer['pppoe_username']); + } else { + $setRequest->setArgument('name', $customer['username']); + } + if (!empty($customer['pppoe_ip'])) { + $setRequest->setArgument('remote-address', $customer['pppoe_ip']); + } $client->sendSync($setRequest); } diff --git a/ui/ui/customers-add.tpl b/ui/ui/customers-add.tpl index 1839bcea..4a849946 100644 --- a/ui/ui/customers-add.tpl +++ b/ui/ui/customers-add.tpl @@ -110,7 +110,7 @@
- +
{Lang::T('Not Working for freeradius')} diff --git a/ui/ui/customers-edit.tpl b/ui/ui/customers-edit.tpl index e1ce53f8..e0f670c2 100644 --- a/ui/ui/customers-edit.tpl +++ b/ui/ui/customers-edit.tpl @@ -135,7 +135,7 @@
- +
diff --git a/ui/ui/customers-view.tpl b/ui/ui/customers-view.tpl index 6d7de98c..7dd0ca0e 100644 --- a/ui/ui/customers-view.tpl +++ b/ui/ui/customers-view.tpl @@ -56,7 +56,7 @@ {/if} {if $d['pppoe_ip'] != ''}
  • - PPPOE Local IP {$d['pppoe_ip']} + PPPOE Remote IP {$d['pppoe_ip']}
  • {/if}