getIDby customer
This commit is contained in:
parent
0214b6436d
commit
096d3ea56d
@ -32,10 +32,7 @@ class MikrotikPppoe
|
||||
global $isChangePlan;
|
||||
$mikrotik = $this->info($plan['routers']);
|
||||
$client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
//check if customer exists
|
||||
$printRequest = new RouterOS\Request('/ppp/secret/print');
|
||||
$printRequest->setQuery(RouterOS\Query::where('name', $customer['username']));
|
||||
$cid = $client->sendSync($printRequest)->getProperty('.id');
|
||||
$cid = self::getIdByCustomer($customer, $client);
|
||||
if (empty($cid)) {
|
||||
//customer not exists, add it
|
||||
$this->addPpoeUser($client, $plan, $customer);
|
||||
@ -65,6 +62,7 @@ class MikrotikPppoe
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function remove_customer($customer, $plan)
|
||||
{
|
||||
$mikrotik = $this->info($plan['routers']);
|
||||
@ -130,6 +128,23 @@ class MikrotikPppoe
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to ID by username from Mikrotik
|
||||
*/
|
||||
function getIdByCustomer($customer, $client){
|
||||
$printRequest = new RouterOS\Request('/ppp/secret/print');
|
||||
$printRequest->setQuery(RouterOS\Query::where('name', $customer['username']));
|
||||
$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)
|
||||
{
|
||||
$mikrotik = $this->info($new_plan['routers']);
|
||||
@ -312,36 +327,6 @@ class MikrotikPppoe
|
||||
$client->sendSync($setRequest);
|
||||
}
|
||||
|
||||
function setPpoeUser($client, $user, $pass)
|
||||
{
|
||||
$printRequest = new RouterOS\Request('/ppp/secret/print');
|
||||
$printRequest->setArgument('.proplist', '.id');
|
||||
$printRequest->setQuery(RouterOS\Query::where('name', $user));
|
||||
$id = $client->sendSync($printRequest)->getProperty('.id');
|
||||
|
||||
$setRequest = new RouterOS\Request('/ppp/secret/set');
|
||||
$setRequest->setArgument('numbers', $id);
|
||||
$setRequest->setArgument('password', $pass);
|
||||
$client->sendSync($setRequest);
|
||||
}
|
||||
|
||||
function setPpoeUserPlan($client, $user, $plan)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
return null;
|
||||
}
|
||||
$printRequest = new RouterOS\Request('/ppp/secret/print');
|
||||
$printRequest->setArgument('.proplist', '.id');
|
||||
$printRequest->setQuery(RouterOS\Query::where('name', $user));
|
||||
$id = $client->sendSync($printRequest)->getProperty('.id');
|
||||
|
||||
$setRequest = new RouterOS\Request('/ppp/secret/set');
|
||||
$setRequest->setArgument('numbers', $id);
|
||||
$setRequest->setArgument('profile', $plan);
|
||||
$client->sendSync($setRequest);
|
||||
}
|
||||
|
||||
function removePpoeActive($client, $username)
|
||||
{
|
||||
global $_app_stage;
|
||||
|
Loading…
x
Reference in New Issue
Block a user