2024-05-24 12:12:49 +07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
|
|
|
|
* by https://t.me/ibnux
|
|
|
|
*
|
|
|
|
* This is Core, don't modification except you want to contribute
|
|
|
|
* better create new plugin
|
|
|
|
**/
|
|
|
|
|
|
|
|
use PEAR2\Net\RouterOS;
|
|
|
|
|
2024-06-04 17:14:04 +07:00
|
|
|
class MikrotikHotspot
|
|
|
|
{
|
2024-05-24 12:12:49 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Establishes a connection between a MikroTik router and a customer.
|
|
|
|
*
|
|
|
|
* This function takes two parameters: $routers and $customer.
|
|
|
|
*
|
|
|
|
* @param array $routers An array containing information about the MikroTik routers.
|
|
|
|
* This can include IP addresses or connection details.
|
|
|
|
* @param mixed $customer An object or array representing a specific customer.
|
|
|
|
* This can contain relevant information about the customer,
|
|
|
|
* such as their username or account details.
|
|
|
|
* @return void
|
|
|
|
*/
|
2024-06-04 17:14:04 +07:00
|
|
|
function connect_customer($customer, $plan)
|
|
|
|
{
|
|
|
|
global $_app_stage;
|
|
|
|
if ($_app_stage == 'demo') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$mikrotik = $this->info($plan['routers']);
|
|
|
|
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
|
|
|
Mikrotik::removePpoeUser($client, $customer['username']);
|
|
|
|
Mikrotik::removePpoeActive($client, $customer['username']);
|
|
|
|
Mikrotik::addPpoeUser($client, $plan, $customer);
|
2024-05-24 12:12:49 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disconnects a customer from a MikroTik router.
|
|
|
|
*
|
|
|
|
* This function takes two parameters: $routers and $customer.
|
|
|
|
*
|
|
|
|
* @param array $routers An array containing information about the MikroTik routers.
|
|
|
|
* This can include IP addresses or connection details.
|
|
|
|
* @param mixed $customer An object or array representing a specific customer.
|
|
|
|
* This can contain relevant information about the customer,
|
|
|
|
* such as their username or account details.
|
|
|
|
* @return void
|
|
|
|
*/
|
2024-06-04 17:14:04 +07:00
|
|
|
function disconnect_customer($customer, $plan)
|
2024-05-24 12:12:49 +07:00
|
|
|
{
|
|
|
|
global $_app_stage;
|
|
|
|
if ($_app_stage == 'demo') {
|
2024-06-04 17:14:04 +07:00
|
|
|
return;
|
2024-05-24 12:12:49 +07:00
|
|
|
}
|
2024-06-04 17:14:04 +07:00
|
|
|
$mikrotik = $this->info($plan['routers']);
|
|
|
|
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
|
|
|
if (!empty($p['pool_expired'])) {
|
|
|
|
Mikrotik::setPpoeUserPlan($client, $customer['username'], 'EXPIRED NUXBILL ' . $p['pool_expired']);
|
|
|
|
} else {
|
|
|
|
Mikrotik::removePpoeUser($client, $customer['username']);
|
2024-05-24 12:12:49 +07:00
|
|
|
}
|
2024-06-04 17:14:04 +07:00
|
|
|
Mikrotik::removePpoeActive($client, $customer['username']);
|
2024-05-24 12:12:49 +07:00
|
|
|
}
|
|
|
|
|
2024-06-04 17:14:04 +07:00
|
|
|
function change_customer($tur, $customer, $plan)
|
2024-05-24 12:12:49 +07:00
|
|
|
{
|
|
|
|
global $_app_stage;
|
|
|
|
if ($_app_stage == 'demo') {
|
2024-06-04 17:14:04 +07:00
|
|
|
return;
|
2024-05-24 12:12:49 +07:00
|
|
|
}
|
2024-06-04 17:14:04 +07:00
|
|
|
$mikrotik = $this->info($plan['routers']);
|
|
|
|
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
|
|
|
Mikrotik::removePpoeUser($client, $customer['username']);
|
|
|
|
Mikrotik::removePpoeActive($client, $customer['username']);
|
|
|
|
Mikrotik::addPpoeUser($client, $plan, $customer);
|
2024-05-24 12:12:49 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-06-04 17:14:04 +07:00
|
|
|
function add_plan($plan)
|
2024-05-24 12:12:49 +07:00
|
|
|
{
|
|
|
|
global $_app_stage;
|
|
|
|
if ($_app_stage == 'demo') {
|
2024-06-04 17:14:04 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
$mikrotik = $this->info($plan['routers']);
|
|
|
|
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
|
|
|
if ($plan['rate_down_unit'] == 'Kbps') {
|
|
|
|
$unitdown = 'K';
|
|
|
|
} else {
|
|
|
|
$unitdown = 'M';
|
2024-05-24 12:12:49 +07:00
|
|
|
}
|
2024-06-04 17:14:04 +07:00
|
|
|
if ($plan['rate_up_unit'] == 'Kbps') {
|
|
|
|
$unitup = 'K';
|
|
|
|
} else {
|
|
|
|
$unitup = 'M';
|
|
|
|
}
|
|
|
|
$rate = $plan['rate_up'] . $unitup . "/" . $plan['rate_down'] . $unitdown;
|
2024-05-24 12:12:49 +07:00
|
|
|
$addRequest = new RouterOS\Request('/ip/hotspot/user/profile/add');
|
|
|
|
$client->sendSync(
|
|
|
|
$addRequest
|
2024-06-04 17:14:04 +07:00
|
|
|
->setArgument('name', $plan['name_plan'])
|
|
|
|
->setArgument('shared-users', $plan['shared_users'])
|
2024-05-24 12:12:49 +07:00
|
|
|
->setArgument('rate-limit', $rate)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-06-04 17:14:04 +07:00
|
|
|
function update_plan($old_name, $plan)
|
2024-05-24 12:12:49 +07:00
|
|
|
{
|
|
|
|
global $_app_stage;
|
|
|
|
if ($_app_stage == 'demo') {
|
2024-06-04 17:14:04 +07:00
|
|
|
return;
|
2024-05-24 12:12:49 +07:00
|
|
|
}
|
2024-06-04 17:14:04 +07:00
|
|
|
$mikrotik = $this->info($plan['routers']);
|
|
|
|
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
|
|
|
if ($plan['rate_down_unit'] == 'Kbps') {
|
|
|
|
$unitdown = 'K';
|
2024-05-24 12:12:49 +07:00
|
|
|
} else {
|
2024-06-04 17:14:04 +07:00
|
|
|
$unitdown = 'M';
|
2024-05-24 12:12:49 +07:00
|
|
|
}
|
2024-06-04 17:14:04 +07:00
|
|
|
if ($plan['rate_up_unit'] == 'Kbps') {
|
|
|
|
$unitup = 'K';
|
|
|
|
} else {
|
|
|
|
$unitup = 'M';
|
2024-05-24 12:12:49 +07:00
|
|
|
}
|
2024-06-04 17:14:04 +07:00
|
|
|
$rate = $plan['rate_up'] . $unitup . "/" . $plan['rate_down'] . $unitdown;
|
2024-05-24 12:12:49 +07:00
|
|
|
$printRequest = new RouterOS\Request(
|
|
|
|
'/ip hotspot user profile print .proplist=.id',
|
2024-06-04 17:14:04 +07:00
|
|
|
RouterOS\Query::where('name', $old_name)
|
2024-05-24 12:12:49 +07:00
|
|
|
);
|
|
|
|
$profileID = $client->sendSync($printRequest)->getProperty('.id');
|
|
|
|
if (empty($profileID)) {
|
2024-06-04 17:14:04 +07:00
|
|
|
Mikrotik::addHotspotPlan($client, $plan['name_plan'], $plan['shared_users'], $rate);
|
2024-05-24 12:12:49 +07:00
|
|
|
} else {
|
|
|
|
$setRequest = new RouterOS\Request('/ip/hotspot/user/profile/set');
|
|
|
|
$client->sendSync(
|
|
|
|
$setRequest
|
|
|
|
->setArgument('numbers', $profileID)
|
2024-06-04 17:14:04 +07:00
|
|
|
->setArgument('name', $plan['name_plan'])
|
|
|
|
->setArgument('shared-users', $plan['shared_users'])
|
|
|
|
->setArgument('rate-limit', $rate)
|
2024-05-24 12:12:49 +07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-04 17:14:04 +07:00
|
|
|
function remove_plan($plan)
|
2024-05-24 12:12:49 +07:00
|
|
|
{
|
|
|
|
global $_app_stage;
|
|
|
|
if ($_app_stage == 'demo') {
|
2024-06-04 17:14:04 +07:00
|
|
|
return;
|
2024-05-24 12:12:49 +07:00
|
|
|
}
|
2024-06-04 17:14:04 +07:00
|
|
|
$mikrotik = $this->info($plan['routers']);
|
|
|
|
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
2024-05-24 12:12:49 +07:00
|
|
|
$printRequest = new RouterOS\Request(
|
|
|
|
'/ip hotspot user profile print .proplist=.id',
|
2024-06-04 17:14:04 +07:00
|
|
|
RouterOS\Query::where('name', $plan['name_plan'])
|
2024-05-24 12:12:49 +07:00
|
|
|
);
|
|
|
|
$profileID = $client->sendSync($printRequest)->getProperty('.id');
|
|
|
|
$removeRequest = new RouterOS\Request('/ip/hotspot/user/profile/remove');
|
|
|
|
$client->sendSync(
|
|
|
|
$removeRequest
|
|
|
|
->setArgument('numbers', $profileID)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-06-04 17:14:04 +07:00
|
|
|
function add_pool($pool){
|
2024-05-24 12:12:49 +07:00
|
|
|
global $_app_stage;
|
|
|
|
if ($_app_stage == 'demo') {
|
|
|
|
return null;
|
|
|
|
}
|
2024-06-04 17:14:04 +07:00
|
|
|
$mikrotik = $this->info($pool['routers']);
|
|
|
|
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
|
|
|
$addRequest = new RouterOS\Request('/ip/pool/add');
|
2024-05-24 12:12:49 +07:00
|
|
|
$client->sendSync(
|
2024-06-04 17:14:04 +07:00
|
|
|
$addRequest
|
|
|
|
->setArgument('name', $pool['pool_name'])
|
|
|
|
->setArgument('ranges', $pool['range_ip'])
|
2024-05-24 12:12:49 +07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-06-04 17:14:04 +07:00
|
|
|
function update_pool($old_pool, $new_pool){
|
2024-05-24 12:12:49 +07:00
|
|
|
global $_app_stage;
|
|
|
|
if ($_app_stage == 'demo') {
|
|
|
|
return null;
|
|
|
|
}
|
2024-06-04 17:14:04 +07:00
|
|
|
$mikrotik = $this->info($new_pool['routers']);
|
|
|
|
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
|
|
|
$printRequest = new RouterOS\Request(
|
|
|
|
'/ip pool print .proplist=.id',
|
|
|
|
RouterOS\Query::where('name', $old_pool['pool_name'])
|
|
|
|
);
|
|
|
|
$poolID = $client->sendSync($printRequest)->getProperty('.id');
|
|
|
|
if (empty($poolID)) {
|
|
|
|
$this->add_pool($new_pool);
|
2024-05-24 12:12:49 +07:00
|
|
|
} else {
|
2024-06-04 17:14:04 +07:00
|
|
|
$setRequest = new RouterOS\Request('/ip/pool/set');
|
2024-05-24 12:12:49 +07:00
|
|
|
$client->sendSync(
|
2024-06-04 17:14:04 +07:00
|
|
|
$setRequest
|
|
|
|
->setArgument('numbers', $poolID)
|
|
|
|
->setArgument('name', $new_pool['pool_name'])
|
|
|
|
->setArgument('ranges', $new_pool['range_ip'])
|
2024-05-24 12:12:49 +07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-04 17:14:04 +07:00
|
|
|
function remove_pool($pool){
|
2024-05-24 12:12:49 +07:00
|
|
|
global $_app_stage;
|
|
|
|
if ($_app_stage == 'demo') {
|
|
|
|
return null;
|
|
|
|
}
|
2024-06-04 17:14:04 +07:00
|
|
|
$mikrotik = $this->info($pool['routers']);
|
|
|
|
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
|
|
|
$printRequest = new RouterOS\Request(
|
|
|
|
'/ip pool print .proplist=.id',
|
|
|
|
RouterOS\Query::where('name', $pool['pool_name'])
|
|
|
|
);
|
|
|
|
$poolID = $client->sendSync($printRequest)->getProperty('.id');
|
|
|
|
$removeRequest = new RouterOS\Request('/ip/pool/remove');
|
|
|
|
$client->sendSync(
|
|
|
|
$removeRequest
|
|
|
|
->setArgument('numbers', $poolID)
|
|
|
|
);
|
|
|
|
}
|
2024-05-24 12:12:49 +07:00
|
|
|
|
2024-06-04 17:14:04 +07:00
|
|
|
function info($name)
|
|
|
|
{
|
|
|
|
return ORM::for_table('tbl_routers')->where('name', $name)->find_one();
|
2024-05-24 12:12:49 +07:00
|
|
|
}
|
|
|
|
|
2024-06-04 17:14:04 +07:00
|
|
|
function getClient($ip, $user, $pass)
|
2024-05-24 12:12:49 +07:00
|
|
|
{
|
|
|
|
global $_app_stage;
|
|
|
|
if ($_app_stage == 'demo') {
|
|
|
|
return null;
|
|
|
|
}
|
2024-06-04 17:14:04 +07:00
|
|
|
$iport = explode(":", $ip);
|
|
|
|
return new RouterOS\Client($iport[0], $user, $pass, ($iport[1]) ? $iport[1] : null);
|
2024-05-24 12:12:49 +07:00
|
|
|
}
|
|
|
|
|
2024-06-04 17:14:04 +07:00
|
|
|
function isUserLogin($client, $username)
|
2024-05-24 12:12:49 +07:00
|
|
|
{
|
|
|
|
global $_app_stage;
|
|
|
|
if ($_app_stage == 'demo') {
|
|
|
|
return null;
|
|
|
|
}
|
2024-06-04 17:14:04 +07:00
|
|
|
$printRequest = new RouterOS\Request(
|
|
|
|
'/ip hotspot active print',
|
|
|
|
RouterOS\Query::where('user', $username)
|
|
|
|
);
|
|
|
|
return $client->sendSync($printRequest)->getProperty('.id');
|
2024-05-24 12:12:49 +07:00
|
|
|
}
|
|
|
|
|
2024-06-04 17:14:04 +07:00
|
|
|
function logMeIn($client, $user, $pass, $ip, $mac)
|
|
|
|
{
|
|
|
|
global $_app_stage;
|
|
|
|
if ($_app_stage == 'demo') {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
$addRequest = new RouterOS\Request('/ip/hotspot/active/login');
|
|
|
|
$client->sendSync(
|
|
|
|
$addRequest
|
|
|
|
->setArgument('user', $user)
|
|
|
|
->setArgument('password', $pass)
|
|
|
|
->setArgument('ip', $ip)
|
|
|
|
->setArgument('mac-address', $mac)
|
|
|
|
);
|
|
|
|
}
|
2024-05-24 12:12:49 +07:00
|
|
|
function removePpoeUser($client, $username)
|
|
|
|
{
|
|
|
|
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', $username));
|
|
|
|
$id = $client->sendSync($printRequest)->getProperty('.id');
|
|
|
|
$removeRequest = new RouterOS\Request('/ppp/secret/remove');
|
|
|
|
$removeRequest->setArgument('numbers', $id);
|
|
|
|
$client->sendSync($removeRequest);
|
|
|
|
}
|
|
|
|
|
|
|
|
function addPpoeUser($client, $plan, $customer)
|
|
|
|
{
|
|
|
|
global $_app_stage;
|
|
|
|
if ($_app_stage == 'demo') {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
$addRequest = new RouterOS\Request('/ppp/secret/add');
|
|
|
|
if (!empty($customer['pppoe_password'])) {
|
|
|
|
$pass = $customer['pppoe_password'];
|
|
|
|
} else {
|
|
|
|
$pass = $customer['password'];
|
|
|
|
}
|
|
|
|
$client->sendSync(
|
|
|
|
$addRequest
|
|
|
|
->setArgument('name', $customer['username'])
|
|
|
|
->setArgument('service', 'pppoe')
|
|
|
|
->setArgument('profile', $plan['name_plan'])
|
|
|
|
->setArgument('comment', $customer['fullname'] . ' | ' . $customer['email'])
|
|
|
|
->setArgument('password', $pass)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function setPpoeUser($client, $user, $pass)
|
|
|
|
{
|
|
|
|
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('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;
|
|
|
|
if ($_app_stage == 'demo') {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
$onlineRequest = new RouterOS\Request('/ppp/active/print');
|
|
|
|
$onlineRequest->setArgument('.proplist', '.id');
|
|
|
|
$onlineRequest->setQuery(RouterOS\Query::where('name', $username));
|
|
|
|
$id = $client->sendSync($onlineRequest)->getProperty('.id');
|
|
|
|
|
|
|
|
$removeRequest = new RouterOS\Request('/ppp/active/remove');
|
|
|
|
$removeRequest->setArgument('numbers', $id);
|
|
|
|
$client->sendSync($removeRequest);
|
|
|
|
}
|
|
|
|
|
|
|
|
function addPpoePlan($client, $name, $pool, $rate)
|
|
|
|
{
|
|
|
|
global $_app_stage;
|
|
|
|
if ($_app_stage == 'demo') {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
$addRequest = new RouterOS\Request('/ppp/profile/add');
|
|
|
|
$client->sendSync(
|
|
|
|
$addRequest
|
|
|
|
->setArgument('name', $name)
|
|
|
|
->setArgument('local-address', $pool)
|
|
|
|
->setArgument('remote-address', $pool)
|
|
|
|
->setArgument('rate-limit', $rate)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function setPpoePlan($client, $name, $pool, $rate)
|
|
|
|
{
|
|
|
|
global $_app_stage;
|
|
|
|
if ($_app_stage == 'demo') {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
$printRequest = new RouterOS\Request(
|
|
|
|
'/ppp profile print .proplist=.id',
|
|
|
|
RouterOS\Query::where('name', $name)
|
|
|
|
);
|
|
|
|
$profileID = $client->sendSync($printRequest)->getProperty('.id');
|
|
|
|
if (empty($profileID)) {
|
|
|
|
self::addPpoePlan($client, $name, $pool, $rate);
|
|
|
|
} else {
|
|
|
|
$setRequest = new RouterOS\Request('/ppp/profile/set');
|
|
|
|
$client->sendSync(
|
|
|
|
$setRequest
|
|
|
|
->setArgument('numbers', $profileID)
|
|
|
|
->setArgument('local-address', $pool)
|
|
|
|
->setArgument('remote-address', $pool)
|
|
|
|
->setArgument('rate-limit', $rate)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function removePpoePlan($client, $name)
|
|
|
|
{
|
|
|
|
global $_app_stage;
|
|
|
|
if ($_app_stage == 'demo') {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
$printRequest = new RouterOS\Request(
|
|
|
|
'/ppp profile print .proplist=.id',
|
|
|
|
RouterOS\Query::where('name', $name)
|
|
|
|
);
|
|
|
|
$profileID = $client->sendSync($printRequest)->getProperty('.id');
|
|
|
|
|
|
|
|
$removeRequest = new RouterOS\Request('/ppp/profile/remove');
|
|
|
|
$client->sendSync(
|
|
|
|
$removeRequest
|
|
|
|
->setArgument('numbers', $profileID)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function sendSMS($client, $to, $message)
|
|
|
|
{
|
|
|
|
global $_app_stage;
|
|
|
|
if ($_app_stage == 'demo') {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
$smsRequest = new RouterOS\Request('/tool sms send');
|
|
|
|
$smsRequest
|
|
|
|
->setArgument('phone-number', $to)
|
|
|
|
->setArgument('message', $message);
|
|
|
|
$client->sendSync($smsRequest);
|
|
|
|
}
|
|
|
|
|
2024-06-04 17:14:04 +07:00
|
|
|
function getIpHotspotUser($client, $username)
|
|
|
|
{
|
2024-05-24 12:12:49 +07:00
|
|
|
global $_app_stage;
|
|
|
|
if ($_app_stage == 'demo') {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
$printRequest = new RouterOS\Request(
|
|
|
|
'/ip hotspot active print',
|
|
|
|
RouterOS\Query::where('user', $username)
|
|
|
|
);
|
|
|
|
return $client->sendSync($printRequest)->getProperty('address');
|
|
|
|
}
|
|
|
|
|
|
|
|
function addIpToAddressList($client, $ip, $listName, $comment = '')
|
|
|
|
{
|
|
|
|
global $_app_stage;
|
|
|
|
if ($_app_stage == 'demo') {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
$addRequest = new RouterOS\Request('/ip/firewall/address-list/add');
|
|
|
|
$client->sendSync(
|
|
|
|
$addRequest
|
|
|
|
->setArgument('address', $ip)
|
|
|
|
->setArgument('comment', $comment)
|
|
|
|
->setArgument('list', $listName)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeIpFromAddressList($client, $ip)
|
|
|
|
{
|
|
|
|
global $_app_stage;
|
|
|
|
if ($_app_stage == 'demo') {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
$printRequest = new RouterOS\Request(
|
|
|
|
'/ip firewall address-list print .proplist=.id',
|
|
|
|
RouterOS\Query::where('address', $ip)
|
|
|
|
);
|
|
|
|
$id = $client->sendSync($printRequest)->getProperty('.id');
|
|
|
|
$removeRequest = new RouterOS\Request('/ip/firewall/address-list/remove');
|
|
|
|
$client->sendSync(
|
|
|
|
$removeRequest
|
|
|
|
->setArgument('numbers', $id)
|
|
|
|
);
|
|
|
|
}
|
2024-06-04 17:14:04 +07:00
|
|
|
}
|