Change Local-Ip PPPoE to Remote-IP

Change Local-Ip PPPoE to Remote-IP in customer page and ignor attribute if empty
This commit is contained in:
gerandonk 2024-09-09 07:19:48 +07:00
parent 53512cfa58
commit 84bc680f40
4 changed files with 53 additions and 11 deletions

View File

@ -10,14 +10,14 @@
use PEAR2\Net\RouterOS; use PEAR2\Net\RouterOS;
class MikrotikPppoe class MikrotikPppoeCustom
{ {
// show Description // show Description
function description() function description()
{ {
return [ return [
'title' => 'Mikrotik PPPOE', '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', 'author' => 'ibnux',
'url' => [ 'url' => [
'Github' => 'https://github.com/hotspotbilling/phpnuxbill/', 'Github' => 'https://github.com/hotspotbilling/phpnuxbill/',
@ -39,14 +39,28 @@ class MikrotikPppoe
}else{ }else{
$setRequest = new RouterOS\Request('/ppp/secret/set'); $setRequest = new RouterOS\Request('/ppp/secret/set');
$setRequest->setArgument('numbers', $cid); $setRequest->setArgument('numbers', $cid);
if (!empty($customer['pppoe_password'])) {
$setRequest->setArgument('password', $customer['pppoe_password']);
} else {
$setRequest->setArgument('password', $customer['password']); $setRequest->setArgument('password', $customer['password']);
}
if (!empty($customer['pppoe_username'])) {
$setRequest->setArgument('name', $customer['pppoe_username']);
} else {
$setRequest->setArgument('name', $customer['username']); $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('profile', $plan['name_plan']);
$setRequest->setArgument('comment', $customer['fullname'] . ' | ' . $customer['email'] . ' | ' . implode(', ', User::getBillNames($customer['id']))); $setRequest->setArgument('comment', $customer['fullname'] . ' | ' . $customer['email'] . ' | ' . implode(', ', User::getBillNames($customer['id'])));
$client->sendSync($setRequest); $client->sendSync($setRequest);
//disconnect then //disconnect then
if(isset($isChangePlan) && $isChangePlan){ if(isset($isChangePlan) && $isChangePlan){
$this->removePpoeActive($client, $customer['username']); $this->removePpoeActive($client, $customer['username']);
if (!empty($customer['pppoe_username'])) {
$this->removePpoeActive($client, $customer['pppoe_username']);
}
} }
} }
} }
@ -60,11 +74,20 @@ class MikrotikPppoe
if($p){ if($p){
$this->add_customer($customer, $p); $this->add_customer($customer, $p);
$this->removePpoeActive($client, $customer['username']); $this->removePpoeActive($client, $customer['username']);
if (!empty($customer['pppoe_username'])) {
$this->removePpoeActive($client, $customer['pppoe_username']);
}
return; return;
} }
} }
$this->removePpoeActive($client, $customer['username']);
$this->removePpoeUser($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 // customer change username
@ -125,7 +148,15 @@ class MikrotikPppoe
function getIdByCustomer($customer, $client){ function getIdByCustomer($customer, $client){
$printRequest = new RouterOS\Request('/ppp/secret/print'); $printRequest = new RouterOS\Request('/ppp/secret/print');
$printRequest->setQuery(RouterOS\Query::where('name', $customer['username'])); $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) function update_plan($old_name, $new_plan)
@ -294,8 +325,19 @@ class MikrotikPppoe
$setRequest->setArgument('service', 'pppoe'); $setRequest->setArgument('service', 'pppoe');
$setRequest->setArgument('profile', $plan['name_plan']); $setRequest->setArgument('profile', $plan['name_plan']);
$setRequest->setArgument('comment', $customer['fullname'] . ' | ' . $customer['email'] . ' | ' . implode(', ', User::getBillNames($customer['id']))); $setRequest->setArgument('comment', $customer['fullname'] . ' | ' . $customer['email'] . ' | ' . implode(', ', User::getBillNames($customer['id'])));
if (!empty($customer['pppoe_password'])) {
$setRequest->setArgument('password', $customer['pppoe_password']);
} else {
$setRequest->setArgument('password', $customer['password']); $setRequest->setArgument('password', $customer['password']);
}
if (!empty($customer['pppoe_username'])) {
$setRequest->setArgument('name', $customer['pppoe_username']);
} else {
$setRequest->setArgument('name', $customer['username']); $setRequest->setArgument('name', $customer['username']);
}
if (!empty($customer['pppoe_ip'])) {
$setRequest->setArgument('remote-address', $customer['pppoe_ip']);
}
$client->sendSync($setRequest); $client->sendSync($setRequest);
} }

View File

@ -110,7 +110,7 @@
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-md-3 control-label">Local IP <span class="label label-danger" id="warning_ip"></span></label> <label class="col-md-3 control-label">Remote IP <span class="label label-danger" id="warning_ip"></span></label>
<div class="col-md-9"> <div class="col-md-9">
<input type="text" class="form-control" id="pppoe_ip" name="pppoe_ip" onkeyup="checkIP(this, '0')"> <input type="text" class="form-control" id="pppoe_ip" name="pppoe_ip" onkeyup="checkIP(this, '0')">
<span class="help-block">{Lang::T('Not Working for freeradius')}</span> <span class="help-block">{Lang::T('Not Working for freeradius')}</span>

View File

@ -135,7 +135,7 @@
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-md-3 control-label">Local IP <span class="label label-danger" id="warning_ip"></span></label> <label class="col-md-3 control-label">Remote IP <span class="label label-danger" id="warning_ip"></span></label>
<div class="col-md-9"> <div class="col-md-9">
<input type="text" class="form-control" id="pppoe_ip" name="pppoe_ip" <input type="text" class="form-control" id="pppoe_ip" name="pppoe_ip"
onkeyup="checkIP(this, {$d['id']})" value="{$d['pppoe_ip']}"> onkeyup="checkIP(this, {$d['id']})" value="{$d['pppoe_ip']}">

View File

@ -56,7 +56,7 @@
{/if} {/if}
{if $d['pppoe_ip'] != ''} {if $d['pppoe_ip'] != ''}
<li class="list-group-item"> <li class="list-group-item">
<b>PPPOE Local IP</b> <span class="pull-right">{$d['pppoe_ip']}</span> <b>PPPOE Remote IP</b> <span class="pull-right">{$d['pppoe_ip']}</span>
</li> </li>
{/if} {/if}
<!--Customers Attributes view start --> <!--Customers Attributes view start -->