Change to devices
This commit is contained in:
parent
c21c7689a8
commit
8ea853c617
@ -8,6 +8,8 @@
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
use PHPMailer\PHPMailer\SMTP;
|
||||
use PEAR2\Net\RouterOS;
|
||||
|
||||
require $root_path . 'system/autoload/mail/Exception.php';
|
||||
require $root_path . 'system/autoload/mail/PHPMailer.php';
|
||||
require $root_path . 'system/autoload/mail/SMTP.php';
|
||||
@ -37,10 +39,8 @@ class Message
|
||||
if (strlen($txt) > 160) {
|
||||
$txts = str_split($txt, 160);
|
||||
try {
|
||||
$mikrotik = Mikrotik::info($config['sms_url']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
foreach ($txts as $txt) {
|
||||
Mikrotik::sendSMS($client, $phone, $txt);
|
||||
self::sendSMS($config['sms_url'], $phone, $txt);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
// ignore, add to logs
|
||||
@ -48,9 +48,7 @@ class Message
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
$mikrotik = Mikrotik::info($config['sms_url']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::sendSMS($client, $phone, $txt);
|
||||
self::sendSMS($config['sms_url'], $phone, $txt);
|
||||
} catch (Exception $e) {
|
||||
// ignore, add to logs
|
||||
_log("Failed to send SMS using Mikrotik.\n" . $e->getMessage(), 'SMS', 0);
|
||||
@ -64,6 +62,24 @@ class Message
|
||||
}
|
||||
}
|
||||
|
||||
public static function MikrotikSendSMS($router_name, $to, $message)
|
||||
{
|
||||
global $_app_stage, $client_m;
|
||||
if ($_app_stage == 'demo') {
|
||||
return null;
|
||||
}
|
||||
if(!isset($client_m)){
|
||||
$mikrotik = ORM::for_table('tbl_routers')->where('name', $router_name)->find_one();
|
||||
$iport = explode(":", $mikrotik['ip_address']);
|
||||
$client_m = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null);
|
||||
}
|
||||
$smsRequest = new RouterOS\Request('/tool sms send');
|
||||
$smsRequest
|
||||
->setArgument('phone-number', $to)
|
||||
->setArgument('message', $message);
|
||||
$client_m->sendSync($smsRequest);
|
||||
}
|
||||
|
||||
public static function sendWhatsapp($phone, $txt)
|
||||
{
|
||||
global $config;
|
||||
|
@ -1,562 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
|
||||
* by https://t.me/ibnux
|
||||
**/
|
||||
|
||||
use PEAR2\Net\RouterOS;
|
||||
|
||||
class Mikrotik
|
||||
{
|
||||
public static function info($name)
|
||||
{
|
||||
return ORM::for_table('tbl_routers')->where('name', $name)->find_one();
|
||||
}
|
||||
|
||||
public static function getClient($ip, $user, $pass)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
return null;
|
||||
}
|
||||
$iport = explode(":", $ip);
|
||||
return new RouterOS\Client($iport[0], $user, $pass, ($iport[1]) ? $iport[1] : null);
|
||||
}
|
||||
|
||||
public static function isUserLogin($client, $username)
|
||||
{
|
||||
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('.id');
|
||||
}
|
||||
|
||||
public static 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)
|
||||
);
|
||||
}
|
||||
|
||||
public static function logMeOut($client, $user)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
return null;
|
||||
}
|
||||
$printRequest = new RouterOS\Request(
|
||||
'/ip hotspot active print',
|
||||
RouterOS\Query::where('user', $user)
|
||||
);
|
||||
$id = $client->sendSync($printRequest)->getProperty('.id');
|
||||
$removeRequest = new RouterOS\Request('/ip/hotspot/active/remove');
|
||||
$client->sendSync(
|
||||
$removeRequest
|
||||
->setArgument('numbers', $id)
|
||||
);
|
||||
}
|
||||
|
||||
public static function addHotspotPlan($client, $name, $sharedusers, $rate)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
return null;
|
||||
}
|
||||
$addRequest = new RouterOS\Request('/ip/hotspot/user/profile/add');
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
->setArgument('name', $name)
|
||||
->setArgument('shared-users', $sharedusers)
|
||||
->setArgument('rate-limit', $rate)
|
||||
);
|
||||
}
|
||||
|
||||
public static function setHotspotPlan($client, $name, $sharedusers, $rate)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
return null;
|
||||
}
|
||||
$printRequest = new RouterOS\Request(
|
||||
'/ip hotspot user profile print .proplist=.id',
|
||||
RouterOS\Query::where('name', $name)
|
||||
);
|
||||
$profileID = $client->sendSync($printRequest)->getProperty('.id');
|
||||
if (empty($profileID)) {
|
||||
Mikrotik::addHotspotPlan($client, $name, $sharedusers, $rate);
|
||||
} else {
|
||||
$setRequest = new RouterOS\Request('/ip/hotspot/user/profile/set');
|
||||
$client->sendSync(
|
||||
$setRequest
|
||||
->setArgument('numbers', $profileID)
|
||||
->setArgument('shared-users', $sharedusers)
|
||||
->setArgument('rate-limit', $rate)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public static function setHotspotExpiredPlan($client, $name, $pool)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
return null;
|
||||
}
|
||||
$printRequest = new RouterOS\Request(
|
||||
'/ip hotspot user profile print .proplist=.id',
|
||||
RouterOS\Query::where('name', $name)
|
||||
);
|
||||
$profileID = $client->sendSync($printRequest)->getProperty('.id');
|
||||
if (empty($profileID)) {
|
||||
$addRequest = new RouterOS\Request('/ip/hotspot/user/profile/add');
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
->setArgument('name', $name)
|
||||
->setArgument('shared-users', 3)
|
||||
->setArgument('address-pool', $pool)
|
||||
->setArgument('rate-limit', '512K/512K')
|
||||
);
|
||||
} else {
|
||||
$setRequest = new RouterOS\Request('/ip/hotspot/user/profile/set');
|
||||
$client->sendSync(
|
||||
$setRequest
|
||||
->setArgument('numbers', $profileID)
|
||||
->setArgument('shared-users', 3)
|
||||
->setArgument('address-pool', $pool)
|
||||
->setArgument('rate-limit', '512K/512K')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public static function removeHotspotPlan($client, $name)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
return null;
|
||||
}
|
||||
$printRequest = new RouterOS\Request(
|
||||
'/ip hotspot user profile print .proplist=.id',
|
||||
RouterOS\Query::where('name', $name)
|
||||
);
|
||||
$profileID = $client->sendSync($printRequest)->getProperty('.id');
|
||||
|
||||
$removeRequest = new RouterOS\Request('/ip/hotspot/user/profile/remove');
|
||||
$client->sendSync(
|
||||
$removeRequest
|
||||
->setArgument('numbers', $profileID)
|
||||
);
|
||||
}
|
||||
|
||||
public static function removeHotspotUser($client, $username)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
return null;
|
||||
}
|
||||
$printRequest = new RouterOS\Request(
|
||||
'/ip hotspot user print .proplist=.id',
|
||||
RouterOS\Query::where('name', $username)
|
||||
);
|
||||
$userID = $client->sendSync($printRequest)->getProperty('.id');
|
||||
$removeRequest = new RouterOS\Request('/ip/hotspot/user/remove');
|
||||
$client->sendSync(
|
||||
$removeRequest
|
||||
->setArgument('numbers', $userID)
|
||||
);
|
||||
}
|
||||
|
||||
public static function addHotspotUser($client, $plan, $customer)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
return null;
|
||||
}
|
||||
$addRequest = new RouterOS\Request('/ip/hotspot/user/add');
|
||||
if ($plan['typebp'] == "Limited") {
|
||||
if ($plan['limit_type'] == "Time_Limit") {
|
||||
if ($plan['time_unit'] == 'Hrs')
|
||||
$timelimit = $plan['time_limit'] . ":00:00";
|
||||
else
|
||||
$timelimit = "00:" . $plan['time_limit'] . ":00";
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
->setArgument('name', $customer['username'])
|
||||
->setArgument('profile', $plan['name_plan'])
|
||||
->setArgument('password', $customer['password'])
|
||||
->setArgument('comment', $customer['fullname'])
|
||||
->setArgument('email', $customer['email'])
|
||||
->setArgument('limit-uptime', $timelimit)
|
||||
);
|
||||
} else if ($plan['limit_type'] == "Data_Limit") {
|
||||
if ($plan['data_unit'] == 'GB')
|
||||
$datalimit = $plan['data_limit'] . "000000000";
|
||||
else
|
||||
$datalimit = $plan['data_limit'] . "000000";
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
->setArgument('name', $customer['username'])
|
||||
->setArgument('profile', $plan['name_plan'])
|
||||
->setArgument('password', $customer['password'])
|
||||
->setArgument('comment', $customer['fullname'])
|
||||
->setArgument('email', $customer['email'])
|
||||
->setArgument('limit-bytes-total', $datalimit)
|
||||
);
|
||||
} else if ($plan['limit_type'] == "Both_Limit") {
|
||||
if ($plan['time_unit'] == 'Hrs')
|
||||
$timelimit = $plan['time_limit'] . ":00:00";
|
||||
else
|
||||
$timelimit = "00:" . $plan['time_limit'] . ":00";
|
||||
if ($plan['data_unit'] == 'GB')
|
||||
$datalimit = $plan['data_limit'] . "000000000";
|
||||
else
|
||||
$datalimit = $plan['data_limit'] . "000000";
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
->setArgument('name', $customer['username'])
|
||||
->setArgument('profile', $plan['name_plan'])
|
||||
->setArgument('password', $customer['password'])
|
||||
->setArgument('comment', $customer['fullname'])
|
||||
->setArgument('email', $customer['email'])
|
||||
->setArgument('limit-uptime', $timelimit)
|
||||
->setArgument('limit-bytes-total', $datalimit)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
->setArgument('name', $customer['username'])
|
||||
->setArgument('profile', $plan['name_plan'])
|
||||
->setArgument('comment', $customer['fullname'])
|
||||
->setArgument('email', $customer['email'])
|
||||
->setArgument('password', $customer['password'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public static function setHotspotUser($client, $user, $pass)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
return null;
|
||||
}
|
||||
$printRequest = new RouterOS\Request('/ip/hotspot/user/print');
|
||||
$printRequest->setArgument('.proplist', '.id');
|
||||
$printRequest->setQuery(RouterOS\Query::where('name', $user));
|
||||
$id = $client->sendSync($printRequest)->getProperty('.id');
|
||||
|
||||
$setRequest = new RouterOS\Request('/ip/hotspot/user/set');
|
||||
$setRequest->setArgument('numbers', $id);
|
||||
$setRequest->setArgument('password', $pass);
|
||||
$client->sendSync($setRequest);
|
||||
}
|
||||
|
||||
public static function setHotspotUserPackage($client, $user, $plan)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
return null;
|
||||
}
|
||||
$printRequest = new RouterOS\Request('/ip/hotspot/user/print');
|
||||
$printRequest->setArgument('.proplist', '.id');
|
||||
$printRequest->setQuery(RouterOS\Query::where('name', $user));
|
||||
$id = $client->sendSync($printRequest)->getProperty('.id');
|
||||
|
||||
$setRequest = new RouterOS\Request('/ip/hotspot/user/set');
|
||||
$setRequest->setArgument('numbers', $id);
|
||||
$setRequest->setArgument('profile', $plan);
|
||||
$client->sendSync($setRequest);
|
||||
}
|
||||
|
||||
public static function removeHotspotActiveUser($client, $username)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
return null;
|
||||
}
|
||||
$onlineRequest = new RouterOS\Request('/ip/hotspot/active/print');
|
||||
$onlineRequest->setArgument('.proplist', '.id');
|
||||
$onlineRequest->setQuery(RouterOS\Query::where('user', $username));
|
||||
$id = $client->sendSync($onlineRequest)->getProperty('.id');
|
||||
|
||||
$removeRequest = new RouterOS\Request('/ip/hotspot/active/remove');
|
||||
$removeRequest->setArgument('numbers', $id);
|
||||
$client->sendSync($removeRequest);
|
||||
}
|
||||
|
||||
public static 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);
|
||||
}
|
||||
|
||||
public static 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)
|
||||
);
|
||||
}
|
||||
|
||||
public static 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);
|
||||
}
|
||||
|
||||
public static 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);
|
||||
}
|
||||
|
||||
public static 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);
|
||||
}
|
||||
|
||||
public static function removePool($client, $name)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
return null;
|
||||
}
|
||||
$printRequest = new RouterOS\Request(
|
||||
'/ip pool print .proplist=.id',
|
||||
RouterOS\Query::where('name', $name)
|
||||
);
|
||||
$poolID = $client->sendSync($printRequest)->getProperty('.id');
|
||||
|
||||
$removeRequest = new RouterOS\Request('/ip/pool/remove');
|
||||
$client->sendSync(
|
||||
$removeRequest
|
||||
->setArgument('numbers', $poolID)
|
||||
);
|
||||
}
|
||||
|
||||
public static function addPool($client, $name, $ip_address)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
return null;
|
||||
}
|
||||
$addRequest = new RouterOS\Request('/ip/pool/add');
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
->setArgument('name', $name)
|
||||
->setArgument('ranges', $ip_address)
|
||||
);
|
||||
}
|
||||
|
||||
public static function setPool($client, $name, $ip_address)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
return null;
|
||||
}
|
||||
$printRequest = new RouterOS\Request(
|
||||
'/ip pool print .proplist=.id',
|
||||
RouterOS\Query::where('name', $name)
|
||||
);
|
||||
$poolID = $client->sendSync($printRequest)->getProperty('.id');
|
||||
|
||||
if (empty($poolID)) {
|
||||
self::addPool($client, $name, $ip_address);
|
||||
} else {
|
||||
$setRequest = new RouterOS\Request('/ip/pool/set');
|
||||
$client->sendSync(
|
||||
$setRequest
|
||||
->setArgument('numbers', $poolID)
|
||||
->setArgument('ranges', $ip_address)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static 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)
|
||||
);
|
||||
}
|
||||
|
||||
public static 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)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public static 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)
|
||||
);
|
||||
}
|
||||
|
||||
public static 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);
|
||||
}
|
||||
|
||||
public static function getIpHotspotUser($client, $username){
|
||||
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');
|
||||
}
|
||||
|
||||
public static 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)
|
||||
);
|
||||
}
|
||||
|
||||
public static 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)
|
||||
);
|
||||
}
|
||||
}
|
@ -221,10 +221,10 @@ class Package
|
||||
}
|
||||
|
||||
if ($isChangePlan || $b['status'] == 'off') {
|
||||
$dvc = $DEVICE_PATH . DIRECTORY_SEPARATOR . $p['device'] . '.php';
|
||||
$dvc = Package::getDevice($p);
|
||||
if (file_exists($dvc)) {
|
||||
include $dvc;
|
||||
new $p['device']->connect_customer($c, $p);
|
||||
require_once $dvc;
|
||||
new $p['device']->add_customer($c, $p);
|
||||
} else {
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
@ -303,11 +303,11 @@ class Package
|
||||
"\nPrice: " . Lang::moneyFormat($p['price'] + $add_cost) .
|
||||
"\nNote:\n" . $note);
|
||||
} else {
|
||||
// plan not exists
|
||||
$dvc = $DEVICE_PATH . DIRECTORY_SEPARATOR . $p['device'] . '.php';
|
||||
// active plan not exists
|
||||
$dvc = Package::getDevice($p);
|
||||
if (file_exists($dvc)) {
|
||||
include $dvc;
|
||||
new $p['device']->connect_customer($c, $p);
|
||||
require_once $dvc;
|
||||
new $p['device']->add_customer($c, $p);
|
||||
} else {
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
@ -412,86 +412,13 @@ class Package
|
||||
$p = ORM::for_table('tbl_plans')->where('id', $plan_id)->find_one();
|
||||
$b = ORM::for_table('tbl_user_recharges')->find_one($from_id);
|
||||
|
||||
$dvc = $DEVICE_PATH . DIRECTORY_SEPARATOR . $p['device'] . '.php';
|
||||
$dvc = Package::getDevice($p);
|
||||
if (file_exists($dvc)) {
|
||||
include $dvc;
|
||||
require_once $dvc;
|
||||
new $p['device']->change_customer($b, $c, $p);
|
||||
} else {
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
|
||||
// if ($p['routers'] == $b['routers'] && $b['routers'] != 'radius') {
|
||||
// $mikrotik = Mikrotik::info($p['routers']);
|
||||
// } else {
|
||||
// $mikrotik = Mikrotik::info($b['routers']);
|
||||
// }
|
||||
// // delete first
|
||||
// if ($p['type'] == 'Hotspot') {
|
||||
// if ($b) {
|
||||
// if (!$p['is_radius']) {
|
||||
// $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
// Mikrotik::removeHotspotUser($client, $c['username']);
|
||||
// Mikrotik::removeHotspotActiveUser($client, $c['username']);
|
||||
// }
|
||||
// } else {
|
||||
// if (!$p['is_radius']) {
|
||||
// $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
// Mikrotik::removeHotspotUser($client, $c['username']);
|
||||
// Mikrotik::removeHotspotActiveUser($client, $c['username']);
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// if ($b) {
|
||||
// if (!$p['is_radius']) {
|
||||
// $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
// Mikrotik::removePpoeUser($client, $c['username']);
|
||||
// Mikrotik::removePpoeActive($client, $c['username']);
|
||||
// }
|
||||
// } else {
|
||||
// if (!$p['is_radius']) {
|
||||
// $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
// Mikrotik::removePpoeUser($client, $c['username']);
|
||||
// Mikrotik::removePpoeActive($client, $c['username']);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// // call the next mikrotik
|
||||
// if ($p['routers'] != $b['routers'] && $p['routers'] != 'radius') {
|
||||
// $mikrotik = Mikrotik::info($p['routers']);
|
||||
// }
|
||||
// if ($p['type'] == 'Hotspot') {
|
||||
// if ($b) {
|
||||
// if ($p['is_radius']) {
|
||||
// Radius::customerAddPlan($c, $p, $b['expiration'] . '' . $b['time']);
|
||||
// } else {
|
||||
// $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
// Mikrotik::addHotspotUser($client, $p, $c);
|
||||
// }
|
||||
// } else {
|
||||
// if ($p['is_radius']) {
|
||||
// Radius::customerAddPlan($c, $p, $b['expiration'] . '' . $b['time']);
|
||||
// } else {
|
||||
// $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
// Mikrotik::addHotspotUser($client, $p, $c);
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// if ($b) {
|
||||
// if ($p['is_radius']) {
|
||||
// Radius::customerAddPlan($c, $p);
|
||||
// } else {
|
||||
// $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
// Mikrotik::addPpoeUser($client, $p, $c);
|
||||
// }
|
||||
// } else {
|
||||
// if ($p['is_radius']) {
|
||||
// Radius::customerAddPlan($c, $p);
|
||||
// } else {
|
||||
// $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
// Mikrotik::addPpoeUser($client, $p, $c);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@ -620,4 +547,25 @@ class Package
|
||||
$tax = $price * $tax_rate_decimal;
|
||||
return $tax;
|
||||
}
|
||||
|
||||
public static function getDevice($plan)
|
||||
{
|
||||
global $DEVICE_PATH;
|
||||
if (!empty($plan['device'])) {
|
||||
return $DEVICE_PATH . DIRECTORY_SEPARATOR . $plan['device'] . '.php';
|
||||
}
|
||||
if ($plan['is_radius'] == 1) {
|
||||
$plan->device = 'Radius';
|
||||
$plan->save();
|
||||
return $DEVICE_PATH . DIRECTORY_SEPARATOR . 'Radius' . '.php';
|
||||
}
|
||||
if ($plan['type'] == 'PPPOE') {
|
||||
$plan->device = 'MikrotikPppoe';
|
||||
$plan->save();
|
||||
return $DEVICE_PATH . DIRECTORY_SEPARATOR . 'MikrotikPppoe' . '.php';
|
||||
}
|
||||
$plan->device = 'MikrotikHotspot';
|
||||
$plan->save();
|
||||
return $DEVICE_PATH . DIRECTORY_SEPARATOR . 'MikrotikHotspot' . '.php';
|
||||
}
|
||||
}
|
||||
|
@ -1,350 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
|
||||
* by https://t.me/ibnux
|
||||
**/
|
||||
|
||||
/**
|
||||
* Radius Class
|
||||
* based https://gist.github.com/nasirhafeez/6669b24aab0bda545f60f9da5ed14f25
|
||||
*/
|
||||
class Radius
|
||||
{
|
||||
|
||||
public static function getClient()
|
||||
{
|
||||
global $config;
|
||||
if (empty($config['radius_client'])) {
|
||||
if (function_exists("shell_exec")) {
|
||||
shell_exec('which radclient');
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
} else {
|
||||
$config['radius_client'];
|
||||
}
|
||||
}
|
||||
|
||||
public static function getTableNas()
|
||||
{
|
||||
return ORM::for_table('nas', 'radius');
|
||||
}
|
||||
public static function getTableAcct()
|
||||
{
|
||||
return ORM::for_table('radacct', 'radius');
|
||||
}
|
||||
public static function getTableCustomer()
|
||||
{
|
||||
return ORM::for_table('radcheck', 'radius');
|
||||
}
|
||||
|
||||
public static function getTableCustomerAttr()
|
||||
{
|
||||
return ORM::for_table('radreply', 'radius');
|
||||
}
|
||||
|
||||
public static function getTablePackage()
|
||||
{
|
||||
return ORM::for_table('radgroupreply', 'radius');
|
||||
}
|
||||
|
||||
public static function getTableUserPackage()
|
||||
{
|
||||
return ORM::for_table('radusergroup', 'radius');
|
||||
}
|
||||
|
||||
public static function nasAdd($name, $ip, $ports, $secret, $routers = "", $description = "", $type = 'other', $server = null, $community = null)
|
||||
{
|
||||
$n = Radius::getTableNas()->create();
|
||||
$n->nasname = $ip;
|
||||
$n->shortname = $name;
|
||||
$n->type = $type;
|
||||
$n->ports = $ports;
|
||||
$n->secret = $secret;
|
||||
$n->description = $description;
|
||||
$n->server = $server;
|
||||
$n->community = $community;
|
||||
$n->routers = $routers;
|
||||
$n->save();
|
||||
return $n->id();
|
||||
}
|
||||
|
||||
public static function nasUpdate($id, $name, $ip, $ports, $secret, $routers = "", $description = "", $type = 'other', $server = null, $community = null)
|
||||
{
|
||||
$n = Radius::getTableNas()->find_one($id);
|
||||
if (empty($n)) {
|
||||
return false;
|
||||
}
|
||||
$n->nasname = $ip;
|
||||
$n->shortname = $name;
|
||||
$n->type = $type;
|
||||
$n->ports = $ports;
|
||||
$n->secret = $secret;
|
||||
$n->description = $description;
|
||||
$n->server = $server;
|
||||
$n->community = $community;
|
||||
$n->routers = $routers;
|
||||
return $n->save();
|
||||
}
|
||||
|
||||
public static function planUpSert($plan_id, $rate, $pool = null)
|
||||
{
|
||||
$rates = explode('/', $rate);
|
||||
##burst fixed
|
||||
if (strpos($rate, ' ')) {
|
||||
$ratos = $rates[0] . '/' . $rates[1] . ' ' . $rates[2] . '/' . $rates[3] . '/' . $rates[4] . '/' . $rates[5] . '/' . $rates[6];
|
||||
} else {
|
||||
$ratos = $rates[0] . '/' . $rates[1];
|
||||
}
|
||||
|
||||
Radius::upsertPackage($plan_id, 'Ascend-Data-Rate', $rates[1], ':=');
|
||||
Radius::upsertPackage($plan_id, 'Ascend-Xmit-Rate', $rates[0], ':=');
|
||||
Radius::upsertPackage($plan_id, 'Mikrotik-Rate-Limit', $ratos, ':=');
|
||||
// if ($pool != null) {
|
||||
// Radius::upsertPackage($plan_id, 'Framed-Pool', $pool, ':=');
|
||||
// }
|
||||
}
|
||||
|
||||
public static function planDelete($plan_id)
|
||||
{
|
||||
// Delete Plan
|
||||
Radius::getTablePackage()->where_equal('plan_id', "plan_" . $plan_id)->delete_many();
|
||||
// Reset User Plan
|
||||
$c = Radius::getTableUserPackage()->where_equal('groupname', "plan_" . $plan_id)->findMany();
|
||||
if ($c) {
|
||||
foreach ($c as $u) {
|
||||
$u->groupname = '';
|
||||
$u->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function customerChangeUsername($from, $to)
|
||||
{
|
||||
$c = Radius::getTableCustomer()->where_equal('username', $from)->findMany();
|
||||
if ($c) {
|
||||
foreach ($c as $u) {
|
||||
$u->username = $to;
|
||||
$u->save();
|
||||
}
|
||||
}
|
||||
$c = Radius::getTableUserPackage()->where_equal('username', $from)->findMany();
|
||||
if ($c) {
|
||||
foreach ($c as $u) {
|
||||
$u->username = $to;
|
||||
$u->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function customerDeactivate($username, $radiusDisconnect = true)
|
||||
{ {
|
||||
global $radius_pass;
|
||||
$r = Radius::getTableCustomer()->where_equal('username', $username)->whereEqual('attribute', 'Cleartext-Password')->findOne();
|
||||
if ($r) {
|
||||
// no need to delete, because it will make ID got higher
|
||||
// we just change the password
|
||||
$r->value = md5(time() . $username . $radius_pass);
|
||||
$r->save();
|
||||
if ($radiusDisconnect)
|
||||
return Radius::disconnectCustomer($username);
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public static function customerDelete($username)
|
||||
{
|
||||
Radius::getTableCustomer()->where_equal('username', $username)->delete_many();
|
||||
Radius::getTableUserPackage()->where_equal('username', $username)->delete_many();
|
||||
}
|
||||
|
||||
/**
|
||||
* When add a plan to Customer, use this
|
||||
*/
|
||||
public static function customerAddPlan($customer, $plan, $expired = null)
|
||||
{
|
||||
global $config;
|
||||
if (Radius::customerUpsert($customer, $plan)) {
|
||||
$p = Radius::getTableUserPackage()->where_equal('username', $customer['username'])->findOne();
|
||||
if ($p) {
|
||||
// if exists
|
||||
Radius::delAtribute(Radius::getTableCustomer(), 'Max-All-Session', 'username', $customer['username']);
|
||||
//Radius::delAtribute(Radius::getTableCustomer(), 'Max-Volume', 'username', $customer['username']);
|
||||
Radius::delAtribute(Radius::getTableCustomer(), 'Max-Data', 'username', $customer['username']);
|
||||
$p->groupname = "plan_" . $plan['id'];
|
||||
$p->save();
|
||||
} else {
|
||||
$p = Radius::getTableUserPackage()->create();
|
||||
$p->username = $customer['username'];
|
||||
$p->groupname = "plan_" . $plan['id'];
|
||||
$p->priority = 1;
|
||||
$p->save();
|
||||
}
|
||||
if ($plan['type'] == 'Hotspot' && $plan['typebp'] == "Limited") {
|
||||
if ($plan['limit_type'] == "Time_Limit") {
|
||||
if ($plan['time_unit'] == 'Hrs')
|
||||
$timelimit = $plan['time_limit'] * 60 * 60;
|
||||
else
|
||||
$timelimit = $plan['time_limit'] * 60;
|
||||
Radius::upsertCustomer($customer['username'], 'Max-All-Session', $timelimit);
|
||||
//Radius::upsertCustomer($customer['username'], 'Expire-After', $timelimit);
|
||||
} else if ($plan['limit_type'] == "Data_Limit") {
|
||||
if ($plan['data_unit'] == 'GB')
|
||||
$datalimit = $plan['data_limit'] . "000000000";
|
||||
else
|
||||
$datalimit = $plan['data_limit'] . "000000";
|
||||
//Radius::upsertCustomer($customer['username'], 'Max-Volume', $datalimit);
|
||||
// Mikrotik Spesific
|
||||
Radius::upsertCustomer($customer['username'], 'Max-Data', $datalimit);
|
||||
//Radius::upsertCustomer($customer['username'], 'Mikrotik-Total-Limit', $datalimit);
|
||||
} else if ($plan['limit_type'] == "Both_Limit") {
|
||||
if ($plan['time_unit'] == 'Hrs')
|
||||
$timelimit = $plan['time_limit'] * 60 * 60;
|
||||
else
|
||||
$timelimit = $plan['time_limit'] * 60;
|
||||
if ($plan['data_unit'] == 'GB')
|
||||
$datalimit = $plan['data_limit'] . "000000000";
|
||||
else
|
||||
$datalimit = $plan['data_limit'] . "000000";
|
||||
//Radius::upsertCustomer($customer['username'], 'Max-Volume', $datalimit);
|
||||
Radius::upsertCustomer($customer['username'], 'Max-All-Session', $timelimit);
|
||||
// Mikrotik Spesific
|
||||
Radius::upsertCustomer($customer['username'], 'Max-Data', $datalimit);
|
||||
//Radius::upsertCustomer($customer['username'], 'Mikrotik-Total-Limit', $datalimit);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
} else {
|
||||
//Radius::delAtribute(Radius::getTableCustomer(), 'Max-Volume', 'username', $customer['username']);
|
||||
Radius::delAtribute(Radius::getTableCustomer(), 'Max-All-Session', 'username', $customer['username']);
|
||||
Radius::delAtribute(Radius::getTableCustomer(), 'Max-Data', 'username', $customer['username']);
|
||||
}
|
||||
|
||||
Radius::disconnectCustomer($customer['username']);
|
||||
Radius::getTableAcct()->where_equal('username', $customer['username'])->delete_many();
|
||||
|
||||
|
||||
// expired user
|
||||
if ($expired != null) {
|
||||
//Radius::upsertCustomer($customer['username'], 'access-period', strtotime($expired) - time());
|
||||
Radius::upsertCustomer($customer['username'], 'Max-All-Session', strtotime($expired) - time());
|
||||
//Radius::upsertCustomer($customer['username'], 'expiration', date('d M Y H:i:s', strtotime($expired)));
|
||||
// Mikrotik Spesific
|
||||
Radius::upsertCustomer(
|
||||
$customer['username'],
|
||||
'WISPr-Session-Terminate-Time',
|
||||
date('Y-m-d', strtotime($expired)) . 'T' . date('H:i:s', strtotime($expired)) . Timezone::getTimeOffset($config['timezone'])
|
||||
);
|
||||
} else {
|
||||
Radius::delAtribute(Radius::getTableCustomer(), 'Max-All-Session', 'username', $customer['username']);
|
||||
//Radius::delAtribute(Radius::getTableCustomer(), 'access-period', 'username', $customer['username']);
|
||||
//Radius::delAtribute(Radius::getTableCustomer(), 'expiration', 'username', $customer['username']);
|
||||
}
|
||||
|
||||
if ($plan['type'] == 'PPPOE') {
|
||||
Radius::upsertCustomerAttr($customer['username'], 'Framed-Pool', $plan['pool'], ':=');
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function customerUpsert($customer, $plan)
|
||||
{
|
||||
if ($plan['type'] == 'PPPOE') {
|
||||
Radius::upsertCustomer($customer['username'], 'Cleartext-Password', (empty($customer['pppoe_password'])) ? $customer['password'] : $customer['pppoe_password']);
|
||||
} else {
|
||||
Radius::upsertCustomer($customer['username'], 'Cleartext-Password', $customer['password']);
|
||||
}
|
||||
Radius::upsertCustomer($customer['username'], 'Simultaneous-Use', ($plan['type'] == 'PPPOE') ? 1 : $plan['shared_users']);
|
||||
// Mikrotik Spesific
|
||||
Radius::upsertCustomer($customer['username'], 'Port-Limit', ($plan['type'] == 'PPPOE') ? 1 : $plan['shared_users']);
|
||||
Radius::upsertCustomer($customer['username'], 'Mikrotik-Wireless-Comment', $customer['fullname']);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static function delAtribute($tabel, $attribute, $key, $value)
|
||||
{
|
||||
$r = $tabel->where_equal($key, $value)->whereEqual('attribute', $attribute)->findOne();
|
||||
if ($r) $r->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* To insert or update existing plan
|
||||
*/
|
||||
private static function upsertPackage($plan_id, $attr, $value, $op = ':=')
|
||||
{
|
||||
$r = Radius::getTablePackage()->where_equal('plan_id', $plan_id)->whereEqual('attribute', $attr)->find_one();
|
||||
if (!$r) {
|
||||
$r = Radius::getTablePackage()->create();
|
||||
$r->groupname = "plan_" . $plan_id;
|
||||
$r->plan_id = $plan_id;
|
||||
}
|
||||
$r->attribute = $attr;
|
||||
$r->op = $op;
|
||||
$r->value = $value;
|
||||
return $r->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* To insert or update existing customer
|
||||
*/
|
||||
public static function upsertCustomer($username, $attr, $value, $op = ':=')
|
||||
{
|
||||
$r = Radius::getTableCustomer()->where_equal('username', $username)->whereEqual('attribute', $attr)->find_one();
|
||||
if (!$r) {
|
||||
$r = Radius::getTableCustomer()->create();
|
||||
$r->username = $username;
|
||||
}
|
||||
$r->attribute = $attr;
|
||||
$r->op = $op;
|
||||
$r->value = $value;
|
||||
return $r->save();
|
||||
}
|
||||
/**
|
||||
* To insert or update existing customer Attribute
|
||||
*/
|
||||
public static function upsertCustomerAttr($username, $attr, $value, $op = ':=')
|
||||
{
|
||||
$r = Radius::getTableCustomerAttr()->where_equal('username', $username)->whereEqual('attribute', $attr)->find_one();
|
||||
if (!$r) {
|
||||
$r = Radius::getTableCustomerAttr()->create();
|
||||
$r->username = $username;
|
||||
}
|
||||
$r->attribute = $attr;
|
||||
$r->op = $op;
|
||||
$r->value = $value;
|
||||
return $r->save();
|
||||
}
|
||||
|
||||
public static function disconnectCustomer($username)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Fix loop to all Nas but still detecting Hotspot Multylogin from other Nas
|
||||
*/
|
||||
$act = ORM::for_table('radacct')->where_raw("acctstoptime IS NULL")->where('username', $username)->find_one();
|
||||
$nas = Radius::getTableNas()->where('nasname', $act['nasipaddress'])->find_many();
|
||||
$count = count($nas) * 15;
|
||||
set_time_limit($count);
|
||||
$result = [];
|
||||
foreach ($nas as $n) {
|
||||
$port = 3799;
|
||||
if (!empty($n['ports'])) {
|
||||
$port = $n['ports'];
|
||||
}
|
||||
$result[] = $n['nasname'] . ': ' . @shell_exec("echo 'User-Name = $username,Framed-IP-Address = " . $act['framedipaddress'] . "' | radclient -x " . trim($n['nasname']) . ":$port disconnect '" . $n['secret'] . "'");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
@ -41,22 +41,14 @@ switch ($action) {
|
||||
|
||||
$c = ORM::for_table('tbl_user_recharges')->where('username', $user['username'])->find_one();
|
||||
if ($c) {
|
||||
// if has active plan, change the password to devices
|
||||
$p = ORM::for_table('tbl_plans')->where('id', $c['plan_id'])->find_one();
|
||||
if ($p['is_radius']) {
|
||||
if ($c['type'] == 'Hotspot' || ($c['type'] == 'PPPOE' && empty($d['pppoe_password']))) {
|
||||
Radius::customerUpsert($d, $p);
|
||||
}
|
||||
$dvc = Package::getDevice($p);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->remove_customer($c, $p);
|
||||
} else {
|
||||
$mikrotik = Mikrotik::info($c['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
if ($c['type'] == 'Hotspot') {
|
||||
Mikrotik::setHotspotUser($client, $c['username'], $npass);
|
||||
Mikrotik::removeHotspotActiveUser($client, $user['username']);
|
||||
} else if (empty($d['pppoe_password'])) {
|
||||
// only change when pppoe_password empty
|
||||
Mikrotik::setPpoeUser($client, $c['username'], $npass);
|
||||
Mikrotik::removePpoeActive($client, $user['username']);
|
||||
}
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
}
|
||||
$d->password = $npass;
|
||||
|
@ -212,18 +212,13 @@ switch ($action) {
|
||||
if ($b) {
|
||||
$p = ORM::for_table('tbl_plans')->where('id', $b['plan_id'])->find_one();
|
||||
if ($p) {
|
||||
if ($p['is_radius']) {
|
||||
Radius::customerDeactivate($b['username']);
|
||||
$p = ORM::for_table('tbl_plans')->where('id', $c['plan_id'])->find_one();
|
||||
$dvc = Package::getDevice($p);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->change_customer($c, $p);
|
||||
} else {
|
||||
$mikrotik = Mikrotik::info($b['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
if ($b['type'] == 'Hotspot') {
|
||||
Mikrotik::removeHotspotUser($client, $b['username']);
|
||||
Mikrotik::removeHotspotActiveUser($client, $b['username']);
|
||||
} else if ($b['type'] == 'PPPOE') {
|
||||
Mikrotik::removePpoeUser($client, $b['username']);
|
||||
Mikrotik::removePpoeActive($client, $b['username']);
|
||||
}
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
$b->status = 'off';
|
||||
$b->expiration = date('Y-m-d');
|
||||
@ -246,16 +241,12 @@ switch ($action) {
|
||||
$p = ORM::for_table('tbl_plans')->where('id', $b['plan_id'])->where('enabled', '1')->find_one();
|
||||
if ($p) {
|
||||
$routers[] = $b['routers'];
|
||||
if ($p['is_radius']) {
|
||||
Radius::customerAddPlan($c, $p, $p['expiration'] . ' ' . $p['time']);
|
||||
$dvc = Package::getDevice($p);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->add_customer($c, $p);
|
||||
} else {
|
||||
$mikrotik = Mikrotik::info($b['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
if ($b['type'] == 'Hotspot') {
|
||||
Mikrotik::addHotspotUser($client, $p, $c);
|
||||
} else if ($b['type'] == 'PPPOE') {
|
||||
Mikrotik::addPpoeUser($client, $p, $c);
|
||||
}
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -337,43 +328,25 @@ switch ($action) {
|
||||
$c = ORM::for_table('tbl_user_recharges')->where('username', $d['username'])->find_one();
|
||||
if ($c) {
|
||||
$p = ORM::for_table('tbl_plans')->find_one($c['plan_id']);
|
||||
if ($p['is_radius']) {
|
||||
Radius::customerDelete($d['username']);
|
||||
} else {
|
||||
$mikrotik = Mikrotik::info($c['routers']);
|
||||
if ($c['type'] == 'Hotspot') {
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removeHotspotUser($client, $d['username']);
|
||||
Mikrotik::removeHotspotActiveUser($client, $d['username']);
|
||||
if($p){
|
||||
$dvc = Package::getDevice($p);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->remove_customer($d, $p);
|
||||
} else {
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removePpoeUser($client, $d['username']);
|
||||
Mikrotik::removePpoeActive($client, $d['username']);
|
||||
}
|
||||
try {
|
||||
$d->delete();
|
||||
} catch (Exception $e) {
|
||||
} catch (Throwable $e) {
|
||||
}
|
||||
try {
|
||||
$c->delete();
|
||||
} catch (Exception $e) {
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
$d->delete();
|
||||
$c->delete();
|
||||
} catch (Exception $e) {
|
||||
} catch (Throwable $e) {
|
||||
}
|
||||
try {
|
||||
if ($c)
|
||||
$c->delete();
|
||||
} catch (Exception $e) {
|
||||
} catch (Throwable $e) {
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$d->delete();
|
||||
} catch (Exception $e) {
|
||||
} catch (Throwable $e) {
|
||||
}
|
||||
r2(U . 'customers/list', 's', Lang::T('User deleted Successfully'));
|
||||
}
|
||||
break;
|
||||
@ -595,26 +568,13 @@ switch ($action) {
|
||||
$c->username = $username;
|
||||
$c->save();
|
||||
$p = ORM::for_table('tbl_plans')->find_one($c['plan_id']);
|
||||
if ($p['is_radius']) {
|
||||
if ($userDiff) {
|
||||
Radius::customerChangeUsername($oldusername, $username);
|
||||
}
|
||||
Radius::customerAddPlan($d, $p, $p['expiration'] . ' ' . $p['time']);
|
||||
$dvc = Package::getDevice($p);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->remove_customer($d, $p);
|
||||
new $p['device']->add_customer($d, $p);
|
||||
} else {
|
||||
$mikrotik = Mikrotik::info($c['routers']);
|
||||
if ($c['type'] == 'Hotspot') {
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::setHotspotUser($client, $c['username'], $password);
|
||||
Mikrotik::removeHotspotActiveUser($client, $d['username']);
|
||||
} else {
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
if (!empty($d['pppoe_password'])) {
|
||||
Mikrotik::setPpoeUser($client, $c['username'], $d['pppoe_password']);
|
||||
} else {
|
||||
Mikrotik::setPpoeUser($client, $c['username'], $password);
|
||||
}
|
||||
Mikrotik::removePpoeActive($client, $d['username']);
|
||||
}
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -154,26 +154,15 @@ if (isset($_GET['recharge']) && !empty($_GET['recharge'])) {
|
||||
}
|
||||
}
|
||||
if ($tur['status'] != 'on') {
|
||||
if ($tur['routers'] != 'radius') {
|
||||
$mikrotik = Mikrotik::info($tur['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$router = $tur['routers'];
|
||||
}
|
||||
$p = ORM::for_table('tbl_plans')->findOne($tur['plan_id']);
|
||||
if (!$p) {
|
||||
r2(U . 'home', '3', "Plan Not Found");
|
||||
}
|
||||
if ($tur['routers'] == 'radius') {
|
||||
Radius::customerAddPlan($user, $p, $tur['expiration'] . ' ' . $tur['time']);
|
||||
$dvc = Package::getDevice($p);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->add_customer($user, $p);
|
||||
} else {
|
||||
if ($tur['type'] == 'Hotspot') {
|
||||
Mikrotik::removeHotspotUser($client, $user['username']);
|
||||
Mikrotik::addHotspotUser($client, $p, $user);
|
||||
} else if ($tur['type'] == 'PPPOE') {
|
||||
Mikrotik::removePpoeUser($client, $user['username']);
|
||||
Mikrotik::addPpoeUser($client, $p, $user);
|
||||
}
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
|
||||
// make customer cannot extend again
|
||||
$days = $config['extend_days'];
|
||||
$expiration = date('Y-m-d', strtotime(" +$days day"));
|
||||
@ -198,22 +187,12 @@ if (isset($_GET['recharge']) && !empty($_GET['recharge'])) {
|
||||
$bill = ORM::for_table('tbl_user_recharges')->where('id', $_GET['deactivate'])->where('username', $user['username'])->findOne();
|
||||
if ($bill) {
|
||||
$p = ORM::for_table('tbl_plans')->where('id', $bill['plan_id'])->find_one();
|
||||
if ($p['is_radius']) {
|
||||
Radius::customerDeactivate($user['username']);
|
||||
$dvc = Package::getDevice($p);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->remove_customer($user, $p);
|
||||
} else {
|
||||
try {
|
||||
$mikrotik = Mikrotik::info($bill['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
if ($bill['type'] == 'Hotspot') {
|
||||
Mikrotik::removeHotspotUser($client, $bill['username']);
|
||||
Mikrotik::removeHotspotActiveUser($client, $bill['username']);
|
||||
} else if ($bill['type'] == 'PPPOE') {
|
||||
Mikrotik::removePpoeUser($client, $bill['username']);
|
||||
Mikrotik::removePpoeActive($client, $bill['username']);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
//ignore it maybe mikrotik has been deleted
|
||||
}
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
$bill->status = 'off';
|
||||
$bill->expiration = date('Y-m-d');
|
||||
@ -231,16 +210,19 @@ if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'])) {
|
||||
$ui->assign('nux_mac', $_SESSION['nux-mac']);
|
||||
$ui->assign('nux_ip', $_SESSION['nux-ip']);
|
||||
$bill = ORM::for_table('tbl_user_recharges')->where('id', $_GET['id'])->where('username', $user['username'])->findOne();
|
||||
if ($_GET['mikrotik'] == 'login') {
|
||||
$m = Mikrotik::info($bill['routers']);
|
||||
$c = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']);
|
||||
Mikrotik::logMeIn($c, $user['username'], $user['password'], $_SESSION['nux-ip'], $_SESSION['nux-mac']);
|
||||
r2(U . 'home', 's', Lang::T('Login Request successfully'));
|
||||
} else if ($_GET['mikrotik'] == 'logout') {
|
||||
$m = Mikrotik::info($bill['routers']);
|
||||
$c = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']);
|
||||
Mikrotik::logMeOut($c, $user['username']);
|
||||
r2(U . 'home', 's', Lang::T('Logout Request successfully'));
|
||||
$p = ORM::for_table('tbl_plans')->where('id', $bill['plan_id'])->find_one();
|
||||
$dvc = Package::getDevice($p);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
if ($_GET['mikrotik'] == 'login') {
|
||||
new $p['device']->connect_customer($user, $_SESSION['nux-ip'], $_SESSION['nux-mac'], $bill['routers']);
|
||||
r2(U . 'home', 's', Lang::T('Login Request successfully'));
|
||||
} else if ($_GET['mikrotik'] == 'logout') {
|
||||
new $p['device']->disconnect_customer($user, $bill['routers']);
|
||||
r2(U . 'home', 's', Lang::T('Logout Request successfully'));
|
||||
}
|
||||
} else {
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,21 +41,14 @@ switch ($action) {
|
||||
$log = '';
|
||||
$router = '';
|
||||
foreach ($plans as $plan) {
|
||||
if ($router != $plan['routers'] && $plan['routers'] != 'radius') {
|
||||
$mikrotik = Mikrotik::info($plan['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$router = $plan['routers'];
|
||||
}
|
||||
$p = ORM::for_table('tbl_plans')->findOne($plan['plan_id']);
|
||||
$c = ORM::for_table('tbl_customers')->findOne($plan['customer_id']);
|
||||
if ($plan['routers'] == 'radius') {
|
||||
Radius::customerAddPlan($c, $p, $plan['expiration'] . ' ' . $plan['time']);
|
||||
$dvc = Package::getDevice($plan);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->add_customer($c, $p);
|
||||
} else {
|
||||
if ($plan['type'] == 'Hotspot') {
|
||||
Mikrotik::addHotspotUser($client, $p, $c);
|
||||
} else if ($plan['type'] == 'PPPOE') {
|
||||
Mikrotik::addPpoeUser($client, $p, $c);
|
||||
}
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
$log .= "DONE : $plan[username], $plan[namebp], $plan[type], $plan[routers]<br>";
|
||||
}
|
||||
@ -265,19 +258,11 @@ switch ($action) {
|
||||
if ($d) {
|
||||
run_hook('delete_customer_active_plan'); #HOOK
|
||||
$p = ORM::for_table('tbl_plans')->find_one($d['plan_id']);
|
||||
if ($p['is_radius']) {
|
||||
Radius::customerDeactivate($d['username']);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->remove_customer($c, $p);
|
||||
} else {
|
||||
$mikrotik = Mikrotik::info($d['routers']);
|
||||
if ($d['type'] == 'Hotspot') {
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removeHotspotUser($client, $d['username']);
|
||||
Mikrotik::removeHotspotActiveUser($client, $d['username']);
|
||||
} else {
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removePpoeUser($client, $d['username']);
|
||||
Mikrotik::removePpoeActive($client, $d['username']);
|
||||
}
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
$d->delete();
|
||||
_log('[' . $admin['username'] . ']: ' . 'Delete Plan for Customer ' . $c['username'] . ' [' . $in['plan_name'] . '][' . Lang::moneyFormat($in['price']) . ']', $admin['user_type'], $admin['id']);
|
||||
@ -786,25 +771,14 @@ switch ($action) {
|
||||
$tur->status = "on";
|
||||
$tur->save();
|
||||
App::setToken($stoken, $id);
|
||||
if ($tur['routers'] != 'radius') {
|
||||
$mikrotik = Mikrotik::info($tur['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$router = $tur['routers'];
|
||||
}
|
||||
$p = ORM::for_table('tbl_plans')->findOne($tur['plan_id']);
|
||||
$c = ORM::for_table('tbl_customers')->findOne($tur['customer_id']);
|
||||
if ($tur['routers'] == 'radius') {
|
||||
Radius::customerAddPlan($c, $p, $tur['expiration'] . ' ' . $tur['time']);
|
||||
$p = ORM::for_table('tbl_plans')->find_one($d['plan_id']);
|
||||
$dvc = Package::getDevice($p);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->add_customer($c, $p);
|
||||
} else {
|
||||
if ($tur['type'] == 'Hotspot') {
|
||||
Mikrotik::removeHotspotUser($client, $c['username']);
|
||||
Mikrotik::removeHotspotActiveUser($client, $c['username']);
|
||||
Mikrotik::addHotspotUser($client, $p, $c);
|
||||
} else if ($tur['type'] == 'PPPOE') {
|
||||
Mikrotik::removePpoeUser($client, $c['username']);
|
||||
Mikrotik::removePpoeActive($client, $c['username']);
|
||||
Mikrotik::addPpoeUser($client, $p, $c);
|
||||
}
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
_log("$admin[fullname] extend Customer $tur[customer_id] $tur[username] for $days days", $admin['user_type'], $admin['id']);
|
||||
r2(U . 'plan', 's', "Extend until $expiration");
|
||||
|
@ -13,9 +13,10 @@ $action = $routes['1'];
|
||||
$ui->assign('_admin', $admin);
|
||||
|
||||
if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
|
||||
_alert(Lang::T('You do not have permission to access this page'),'danger', "dashboard");
|
||||
_alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard");
|
||||
}
|
||||
|
||||
require_once $DEVICE_PATH . DIRECTORY_SEPARATOR . "MikrotikPppoe.php";
|
||||
|
||||
switch ($action) {
|
||||
case 'list':
|
||||
@ -60,15 +61,7 @@ switch ($action) {
|
||||
$d = ORM::for_table('tbl_pool')->find_one($id);
|
||||
if ($d) {
|
||||
if ($d['routers'] != 'radius') {
|
||||
try {
|
||||
$mikrotik = Mikrotik::info($d['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removePool($client, $d['pool_name']);
|
||||
} catch (Exception $e) {
|
||||
//ignore exception, it means router has already deleted
|
||||
} catch(Throwable $e){
|
||||
//ignore exception, it means router has already deleted
|
||||
}
|
||||
(new MikrotikPppoe())->remove_pool($d);
|
||||
}
|
||||
$d->delete();
|
||||
|
||||
@ -81,9 +74,7 @@ switch ($action) {
|
||||
$log = '';
|
||||
foreach ($pools as $pool) {
|
||||
if ($pool['routers'] != 'radius') {
|
||||
$mikrotik = Mikrotik::info($pool['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::addPool($client, $pool['pool_name'], $pool['range_ip']);
|
||||
(new MikrotikPppoe())->update_pool($pool, $pool);
|
||||
$log .= 'DONE: ' . $pool['pool_name'] . ': ' . $pool['range_ip'] . '<br>';
|
||||
}
|
||||
}
|
||||
@ -108,9 +99,7 @@ switch ($action) {
|
||||
}
|
||||
if ($msg == '') {
|
||||
if ($routers != 'radius') {
|
||||
$mikrotik = Mikrotik::info($routers);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::addPool($client, $name, $ip_address);
|
||||
(new MikrotikPppoe())->add_pool($pool);
|
||||
}
|
||||
|
||||
$b = ORM::for_table('tbl_pool')->create();
|
||||
@ -138,22 +127,20 @@ switch ($action) {
|
||||
|
||||
$id = _post('id');
|
||||
$d = ORM::for_table('tbl_pool')->find_one($id);
|
||||
if ($d) {
|
||||
} else {
|
||||
$old = ORM::for_table('tbl_pool')->find_one($id);
|
||||
if (!$d) {
|
||||
$msg .= Lang::T('Data Not Found') . '<br>';
|
||||
}
|
||||
|
||||
if ($msg == '') {
|
||||
if ($routers != 'radius') {
|
||||
$mikrotik = Mikrotik::info($routers);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::setPool($client, $d['pool_name'], $ip_address);
|
||||
}
|
||||
|
||||
$d->range_ip = $ip_address;
|
||||
$d->routers = $routers;
|
||||
$d->save();
|
||||
|
||||
if ($routers != 'radius') {
|
||||
(new MikrotikPppoe())->update_pool($old, $d);
|
||||
}
|
||||
|
||||
r2(U . 'pool/list', 's', Lang::T('Data Updated Successfully'));
|
||||
} else {
|
||||
r2(U . 'pool/edit/' . $id, 'e', $msg);
|
||||
|
@ -27,43 +27,20 @@ switch ($action) {
|
||||
$log = '';
|
||||
$router = '';
|
||||
foreach ($plans as $plan) {
|
||||
if ($plan['is_radius']) {
|
||||
if ($b['rate_down_unit'] == 'Kbps') {
|
||||
$raddown = '000';
|
||||
} else {
|
||||
$raddown = '000000';
|
||||
}
|
||||
if ($b['rate_up_unit'] == 'Kbps') {
|
||||
$radup = '000';
|
||||
} else {
|
||||
$radup = '000000';
|
||||
}
|
||||
$radiusRate = $plan['rate_up'] . $radup . '/' . $plan['rate_down'] . $raddown . '/' . $plan['burst'];
|
||||
Radius::planUpSert($plan['id'], $radiusRate);
|
||||
$log .= "DONE : Radius $plan[name_plan], $plan[shared_users], $radiusRate<br>";
|
||||
} else {
|
||||
if ($router != $plan['routers']) {
|
||||
$mikrotik = Mikrotik::info($plan['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$router = $plan['routers'];
|
||||
}
|
||||
if ($plan['rate_down_unit'] == 'Kbps') {
|
||||
$unitdown = 'K';
|
||||
} else {
|
||||
$unitdown = 'M';
|
||||
}
|
||||
if ($plan['rate_up_unit'] == 'Kbps') {
|
||||
$unitup = 'K';
|
||||
} else {
|
||||
$unitup = 'M';
|
||||
}
|
||||
$rate = $plan['rate_up'] . $unitup . "/" . $plan['rate_down'] . $unitdown;
|
||||
Mikrotik::addHotspotPlan($client, $plan['name_plan'], $plan['shared_users'], $rate);
|
||||
$log .= "DONE : $plan[name_plan], $plan[shared_users], $rate<br>";
|
||||
$dvc = Package::getDevice($plan);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->add_plan($plan);
|
||||
if (!empty($plan['pool_expired'])) {
|
||||
Mikrotik::setHotspotExpiredPlan($client, 'EXPIRED NUXBILL ' . $plan['pool_expired'], $plan['pool_expired']);
|
||||
$log .= "DONE Expired : EXPIRED NUXBILL $plan[pool_expired]<br>";
|
||||
$plan->name_plan = 'EXPIRED NUXBILL ' . $pool_expired;
|
||||
$plan->rate_down_unit = "Kbps";
|
||||
$plan->rate_up_unit == 'Kbps';
|
||||
$plan->rate_up = '512';
|
||||
$plan->rate_down = '512';
|
||||
new $p['device']->add_plan($plan);
|
||||
}
|
||||
} else {
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
}
|
||||
r2(U . 'services/hotspot', 's', $log);
|
||||
@ -72,43 +49,20 @@ switch ($action) {
|
||||
$log = '';
|
||||
$router = '';
|
||||
foreach ($plans as $plan) {
|
||||
if ($plan['is_radius']) {
|
||||
if ($b['rate_down_unit'] == 'Kbps') {
|
||||
$raddown = '000';
|
||||
} else {
|
||||
$raddown = '000000';
|
||||
}
|
||||
if ($b['rate_up_unit'] == 'Kbps') {
|
||||
$radup = '000';
|
||||
} else {
|
||||
$radup = '000000';
|
||||
}
|
||||
$radiusRate = $plan['rate_up'] . $radup . '/' . $plan['rate_down'] . $raddown . '/' . $plan['burst'];
|
||||
Radius::planUpSert($plan['id'], $radiusRate, $plan['pool']);
|
||||
$log .= "DONE : RADIUS $plan[name_plan], $plan[pool], $rate<br>";
|
||||
} else {
|
||||
if ($router != $plan['routers']) {
|
||||
$mikrotik = Mikrotik::info($plan['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$router = $plan['routers'];
|
||||
}
|
||||
if ($plan['rate_down_unit'] == 'Kbps') {
|
||||
$unitdown = 'K';
|
||||
} else {
|
||||
$unitdown = 'M';
|
||||
}
|
||||
if ($plan['rate_up_unit'] == 'Kbps') {
|
||||
$unitup = 'K';
|
||||
} else {
|
||||
$unitup = 'M';
|
||||
}
|
||||
$rate = $plan['rate_up'] . $unitup . "/" . $plan['rate_down'] . $unitdown;
|
||||
Mikrotik::addPpoePlan($client, $plan['name_plan'], $plan['pool'], $rate);
|
||||
$log .= "DONE : $plan[name_plan], $plan[pool], $rate<br>";
|
||||
$dvc = Package::getDevice($plan);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->add_plan($plan);
|
||||
if (!empty($plan['pool_expired'])) {
|
||||
Mikrotik::setPpoePlan($client, 'EXPIRED NUXBILL ' . $plan['pool_expired'], $plan['pool_expired'], '512K/512K');
|
||||
$log .= "DONE Expired : EXPIRED NUXBILL $plan[pool_expired]<br>";
|
||||
$plan->name_plan = 'EXPIRED NUXBILL ' . $pool_expired;
|
||||
$plan->rate_down_unit = "Kbps";
|
||||
$plan->rate_up_unit == 'Kbps';
|
||||
$plan->rate_up = '512';
|
||||
$plan->rate_down = '512';
|
||||
new $p['device']->add_plan($plan);
|
||||
}
|
||||
} else {
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
}
|
||||
r2(U . 'services/pppoe', 's', $log);
|
||||
@ -162,20 +116,13 @@ switch ($action) {
|
||||
$d = ORM::for_table('tbl_plans')->find_one($id);
|
||||
if ($d) {
|
||||
run_hook('delete_plan'); #HOOK
|
||||
if ($d['is_radius']) {
|
||||
Radius::planDelete($d['id']);
|
||||
$dvc = Package::getDevice($d);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->remove_plan($d);
|
||||
} else {
|
||||
try {
|
||||
$mikrotik = Mikrotik::info($d['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removeHotspotPlan($client, $d['name_plan']);
|
||||
} catch (Exception $e) {
|
||||
//ignore exception, it means router has already deleted
|
||||
} catch (Throwable $e) {
|
||||
//ignore exception, it means router has already deleted
|
||||
}
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
|
||||
$d->delete();
|
||||
|
||||
r2(U . 'services/hotspot', 's', Lang::T('Data Deleted Successfully'));
|
||||
@ -272,20 +219,23 @@ switch ($action) {
|
||||
$d->enabled = $enabled;
|
||||
$d->prepaid = $prepaid;
|
||||
$d->save();
|
||||
$plan_id = $d->id();
|
||||
|
||||
if ($d['is_radius']) {
|
||||
Radius::planUpSert($plan_id, $radiusRate);
|
||||
} else {
|
||||
$mikrotik = Mikrotik::info($routers);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::addHotspotPlan($client, $name, $sharedusers, $rate);
|
||||
$dvc = Package::getDevice($d);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->add_plan($d);
|
||||
if (!empty($pool_expired)) {
|
||||
Mikrotik::setHotspotExpiredPlan($client, 'EXPIRED NUXBILL ' . $pool_expired, $pool_expired);
|
||||
$d->name_plan = 'EXPIRED NUXBILL ' . $pool_expired;
|
||||
$d->rate_down_unit = "Kbps";
|
||||
$d->rate_up_unit == 'Kbps';
|
||||
$d->rate_up = '512';
|
||||
$d->rate_down = '512';
|
||||
new $p['device']->add_plan($d);
|
||||
}
|
||||
} else {
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
|
||||
|
||||
r2(U . 'services/hotspot', 's', Lang::T('Data Created Successfully'));
|
||||
} else {
|
||||
r2(U . 'services/add', 'e', $msg);
|
||||
@ -324,6 +274,7 @@ switch ($action) {
|
||||
$msg .= Lang::T('All field is required') . '<br>';
|
||||
}
|
||||
$d = ORM::for_table('tbl_plans')->where('id', $id)->find_one();
|
||||
$old = ORM::for_table('tbl_plans')->where('id', $id)->find_one();
|
||||
if ($d) {
|
||||
} else {
|
||||
$msg .= Lang::T('Data Not Found') . '<br>';
|
||||
@ -350,16 +301,6 @@ switch ($action) {
|
||||
|
||||
$rate = trim($rate . " " . $b['burst']);
|
||||
|
||||
if ($d['is_radius']) {
|
||||
Radius::planUpSert($id, $radiusRate);
|
||||
} else {
|
||||
$mikrotik = Mikrotik::info($routers);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::setHotspotPlan($client, $name, $sharedusers, $rate);
|
||||
if (!empty($pool_expired)) {
|
||||
Mikrotik::setHotspotExpiredPlan($client, 'EXPIRED NUXBILL ' . $pool_expired, $pool_expired);
|
||||
}
|
||||
}
|
||||
$d->name_plan = $name;
|
||||
$d->id_bw = $id_bw;
|
||||
$d->price = $price; // Set price with or without tax based on configuration
|
||||
@ -379,6 +320,23 @@ switch ($action) {
|
||||
$d->prepaid = $prepaid;
|
||||
$d->save();
|
||||
|
||||
$dvc = Package::getDevice($d);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $d['device']->update_plan($old, $d);
|
||||
if (!empty($pool_expired)) {
|
||||
$old->name_plan = 'EXPIRED NUXBILL ' . $old['pool_expired'];
|
||||
$d->name_plan = 'EXPIRED NUXBILL ' . $pool_expired;
|
||||
$d->rate_down_unit = "Kbps";
|
||||
$d->rate_up_unit == 'Kbps';
|
||||
$d->rate_up = '512';
|
||||
$d->rate_down = '512';
|
||||
new $d['device']->update_plan($old, $d);
|
||||
}
|
||||
} else {
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
|
||||
r2(U . 'services/hotspot', 's', Lang::T('Data Updated Successfully'));
|
||||
} else {
|
||||
r2(U . 'services/edit/' . $id, 'e', $msg);
|
||||
@ -441,18 +399,13 @@ switch ($action) {
|
||||
$d = ORM::for_table('tbl_plans')->find_one($id);
|
||||
if ($d) {
|
||||
run_hook('delete_ppoe'); #HOOK
|
||||
if ($d['is_radius']) {
|
||||
Radius::planDelete($d['id']);
|
||||
|
||||
$dvc = Package::getDevice($d);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->remove_plan($d);
|
||||
} else {
|
||||
try {
|
||||
$mikrotik = Mikrotik::info($d['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removePpoePlan($client, $d['name_plan']);
|
||||
} catch (Exception $e) {
|
||||
//ignore exception, it means router has already deleted
|
||||
} catch (Throwable $e) {
|
||||
//ignore exception, it means router has already deleted
|
||||
}
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
$d->delete();
|
||||
|
||||
@ -537,17 +490,21 @@ switch ($action) {
|
||||
$d->enabled = $enabled;
|
||||
$d->prepaid = $prepaid;
|
||||
$d->save();
|
||||
$plan_id = $d->id();
|
||||
|
||||
if ($d['is_radius']) {
|
||||
Radius::planUpSert($plan_id, $radiusRate, $pool);
|
||||
} else {
|
||||
$mikrotik = Mikrotik::info($routers);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::addPpoePlan($client, $name, $pool, $rate);
|
||||
$dvc = Package::getDevice($d);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->add_plan($d);
|
||||
if (!empty($pool_expired)) {
|
||||
Mikrotik::setPpoePlan($client, 'EXPIRED NUXBILL ' . $pool_expired, $pool_expired, '512K/512K');
|
||||
$d->name_plan = 'EXPIRED NUXBILL ' . $pool_expired;
|
||||
$d->rate_down_unit = "Kbps";
|
||||
$d->rate_up_unit == 'Kbps';
|
||||
$d->rate_up = '512';
|
||||
$d->rate_down = '512';
|
||||
new $p['device']->add_plan($d);
|
||||
}
|
||||
} else {
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
|
||||
r2(U . 'services/pppoe', 's', Lang::T('Data Created Successfully'));
|
||||
@ -583,6 +540,7 @@ switch ($action) {
|
||||
}
|
||||
|
||||
$d = ORM::for_table('tbl_plans')->where('id', $id)->find_one();
|
||||
$old = ORM::for_table('tbl_plans')->where('id', $id)->find_one();
|
||||
if ($d) {
|
||||
} else {
|
||||
$msg .= Lang::T('Data Not Found') . '<br>';
|
||||
@ -608,16 +566,6 @@ switch ($action) {
|
||||
$radiusRate = $b['rate_up'] . $radup . '/' . $b['rate_down'] . $raddown . '/' . $b['burst'];
|
||||
$rate = trim($rate . " " . $b['burst']);
|
||||
|
||||
if ($d['is_radius']) {
|
||||
Radius::planUpSert($id, $radiusRate, $pool);
|
||||
} else {
|
||||
$mikrotik = Mikrotik::info($routers);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::setPpoePlan($client, $name, $pool, $rate);
|
||||
if (!empty($pool_expired)) {
|
||||
Mikrotik::setPpoePlan($client, 'EXPIRED NUXBILL ' . $pool_expired, $pool_expired, '512K/512K');
|
||||
}
|
||||
}
|
||||
$d->name_plan = $name;
|
||||
$d->id_bw = $id_bw;
|
||||
$d->price = $price;
|
||||
@ -632,6 +580,23 @@ switch ($action) {
|
||||
$d->prepaid = $prepaid;
|
||||
$d->save();
|
||||
|
||||
$dvc = Package::getDevice($d);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $d['device']->update_plan($old, $d);
|
||||
if (!empty($pool_expired)) {
|
||||
$old->name_plan = 'EXPIRED NUXBILL ' . $old['pool_expired'];
|
||||
$d->name_plan = 'EXPIRED NUXBILL ' . $pool_expired;
|
||||
$d->rate_down_unit = "Kbps";
|
||||
$d->rate_up_unit == 'Kbps';
|
||||
$d->rate_up = '512';
|
||||
$d->rate_down = '512';
|
||||
new $d['device']->update_plan($old, $d);
|
||||
}
|
||||
} else {
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
|
||||
r2(U . 'services/pppoe', 's', Lang::T('Data Updated Successfully'));
|
||||
} else {
|
||||
r2(U . 'services/pppoe-edit/' . $id, 'e', $msg);
|
||||
|
@ -32,33 +32,14 @@ foreach ($d as $ds) {
|
||||
$u = ORM::for_table('tbl_user_recharges')->where('id', $ds['id'])->find_one();
|
||||
$c = ORM::for_table('tbl_customers')->where('id', $ds['customer_id'])->find_one();
|
||||
$p = ORM::for_table('tbl_plans')->where('id', $u['plan_id'])->find_one();
|
||||
$dvc = $DEVICE_PATH . DIRECTORY_SEPARATOR . $p['device'].'.php';
|
||||
if(file_exists($dvc)){
|
||||
include $dvc;
|
||||
new $p['device']->disconnect_customer($ds['routers'], $c, $p);
|
||||
}else{
|
||||
$dvc = Package::getDevice($p);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->remove_customer($ds['routers'], $c, $p);
|
||||
} else {
|
||||
echo "Cron error Devices $p[device] not found, cannot disconnect $c[username]";
|
||||
Message::sendTelegram("Cron error Devices $p[device] not found, cannot disconnect $c[username]");
|
||||
}
|
||||
// if ($p['is_radius']) {
|
||||
// if (empty($p['pool_expired'])) {
|
||||
// print_r(Radius::customerDeactivate($c['username']));
|
||||
// } else {
|
||||
// Radius::upsertCustomerAttr($c['username'], 'Framed-Pool', $p['pool_expired'], ':=');
|
||||
// print_r(Radius::disconnectCustomer($c['username']));
|
||||
// }
|
||||
// } else {
|
||||
// $client = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']);
|
||||
// if (!empty($p['pool_expired'])) {
|
||||
// Mikrotik::setHotspotUserPackage($client, $c['username'], 'EXPIRED NUXBILL ' . $p['pool_expired']);
|
||||
// // }if (!empty($p['list_expired'])) {
|
||||
// // $ip = Mikrotik::getIpHotspotUser($client, $ds['username']);
|
||||
// // Mikrotik::addIpToAddressList($client, $ip, $p['list_expired'], $c['username']);
|
||||
// } else {
|
||||
// Mikrotik::removeHotspotUser($client, $c['username']);
|
||||
// }
|
||||
// Mikrotik::removeHotspotActiveUser($client, $c['username']);
|
||||
// }
|
||||
echo Message::sendPackageNotification($c, $u['namebp'], $p['price'], $textExpired, $config['user_notification_expired']) . "\n";
|
||||
//update database user dengan status off
|
||||
$u->status = 'off';
|
||||
@ -91,7 +72,7 @@ foreach ($d as $ds) {
|
||||
} else {
|
||||
echo "no renewall | balance $config[enable_balance] auto_renewal $c[auto_renewal]\n";
|
||||
}
|
||||
} else{
|
||||
} else {
|
||||
echo " : ACTIVE \r\n";
|
||||
}
|
||||
}
|
||||
|
@ -13,46 +13,46 @@ use PEAR2\Net\RouterOS;
|
||||
class MikrotikHotspot
|
||||
{
|
||||
|
||||
function connect_customer($customer, $plan)
|
||||
function add_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::removeHotspotUser($client, $customer['username']);
|
||||
Mikrotik::removeHotspotActiveUser($client, $customer['username']);
|
||||
Mikrotik::addHotspotUser($client, $plan, $customer);
|
||||
$client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$this->removeHotspotUser($client, $customer['username']);
|
||||
$this->removeHotspotActiveUser($client, $customer['username']);
|
||||
$this->addHotspotUser($client, $plan, $customer);
|
||||
}
|
||||
|
||||
function disconnect_customer($customer, $plan)
|
||||
function remove_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']);
|
||||
if (!empty($p['pool_expired'])) {
|
||||
Mikrotik::setHotspotUserPackage($client, $customer['username'], 'EXPIRED NUXBILL ' . $p['pool_expired']);
|
||||
$client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
if (!empty($plan['pool_expired'])) {
|
||||
$this->setHotspotUserPackage($client, $customer['username'], 'EXPIRED NUXBILL ' . $plan['pool_expired']);
|
||||
} else {
|
||||
Mikrotik::removeHotspotUser($client, $customer['username']);
|
||||
$this->removeHotspotUser($client, $customer['username']);
|
||||
}
|
||||
Mikrotik::removeHotspotActiveUser($client, $customer['username']);
|
||||
$this->removeHotspotActiveUser($client, $customer['username']);
|
||||
}
|
||||
|
||||
function change_customer($tur, $customer, $plan)
|
||||
function change_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::removeHotspotUser($client, $customer['username']);
|
||||
Mikrotik::removeHotspotActiveUser($client, $customer['username']);
|
||||
Mikrotik::addHotspotUser($client, $plan, $customer);
|
||||
$client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$this->removeHotspotUser($client, $customer['username']);
|
||||
$this->removeHotspotActiveUser($client, $customer['username']);
|
||||
$this->addHotspotUser($client, $plan, $customer);
|
||||
}
|
||||
|
||||
function add_plan($plan)
|
||||
@ -62,7 +62,7 @@ class MikrotikHotspot
|
||||
return;
|
||||
}
|
||||
$mikrotik = $this->info($plan['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
if ($plan['rate_down_unit'] == 'Kbps') {
|
||||
$unitdown = 'K';
|
||||
} else {
|
||||
@ -83,6 +83,60 @@ class MikrotikHotspot
|
||||
);
|
||||
}
|
||||
|
||||
function online_customer($customer, $router_name)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
return;
|
||||
}
|
||||
$mikrotik = $this->info($router_name);
|
||||
$client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$printRequest = new RouterOS\Request(
|
||||
'/ip hotspot active print',
|
||||
RouterOS\Query::where('user', $customer['username'])
|
||||
);
|
||||
return $client->sendSync($printRequest)->getProperty('.id');
|
||||
}
|
||||
|
||||
function connect_customer($customer, $ip, $mac_address, $router_name)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
return;
|
||||
}
|
||||
$mikrotik = $this->info($router_name);
|
||||
$client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$addRequest = new RouterOS\Request('/ip/hotspot/active/login');
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
->setArgument('user', $customer['username'])
|
||||
->setArgument('password', $customer['password'])
|
||||
->setArgument('ip', $ip)
|
||||
->setArgument('mac-address', $mac_address)
|
||||
);
|
||||
}
|
||||
|
||||
function disconnect_customer($customer, $router_name)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
return;
|
||||
}
|
||||
$mikrotik = $this->info($router_name);
|
||||
$client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$printRequest = new RouterOS\Request(
|
||||
'/ip hotspot active print',
|
||||
RouterOS\Query::where('user', $customer['username'])
|
||||
);
|
||||
$id = $client->sendSync($printRequest)->getProperty('.id');
|
||||
$removeRequest = new RouterOS\Request('/ip/hotspot/active/remove');
|
||||
$client->sendSync(
|
||||
$removeRequest
|
||||
->setArgument('numbers', $id)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function update_plan($old_plan, $new_plan)
|
||||
{
|
||||
global $_app_stage;
|
||||
@ -90,26 +144,27 @@ class MikrotikHotspot
|
||||
return;
|
||||
}
|
||||
$mikrotik = $this->info($new_plan['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
if ($new_plan['rate_down_unit'] == 'Kbps') {
|
||||
$unitdown = 'K';
|
||||
} else {
|
||||
$unitdown = 'M';
|
||||
}
|
||||
if ($new_plan['rate_up_unit'] == 'Kbps') {
|
||||
$unitup = 'K';
|
||||
} else {
|
||||
$unitup = 'M';
|
||||
}
|
||||
$rate = $new_plan['rate_up'] . $unitup . "/" . $new_plan['rate_down'] . $unitdown;
|
||||
$client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
|
||||
$printRequest = new RouterOS\Request(
|
||||
'/ip hotspot user profile print .proplist=.id',
|
||||
RouterOS\Query::where('name', $old_plan['name_plan'])
|
||||
);
|
||||
$profileID = $client->sendSync($printRequest)->getProperty('.id');
|
||||
if (empty($profileID)) {
|
||||
Mikrotik::addHotspotPlan($client, $new_plan['name_plan'], $new_plan['shared_users'], $rate);
|
||||
$this->add_plan($new_plan);
|
||||
} else {
|
||||
if ($new_plan['rate_down_unit'] == 'Kbps') {
|
||||
$unitdown = 'K';
|
||||
} else {
|
||||
$unitdown = 'M';
|
||||
}
|
||||
if ($new_plan['rate_up_unit'] == 'Kbps') {
|
||||
$unitup = 'K';
|
||||
} else {
|
||||
$unitup = 'M';
|
||||
}
|
||||
$rate = $new_plan['rate_up'] . $unitup . "/" . $new_plan['rate_down'] . $unitdown;
|
||||
$setRequest = new RouterOS\Request('/ip/hotspot/user/profile/set');
|
||||
$client->sendSync(
|
||||
$setRequest
|
||||
@ -128,7 +183,7 @@ class MikrotikHotspot
|
||||
return;
|
||||
}
|
||||
$mikrotik = $this->info($plan['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$printRequest = new RouterOS\Request(
|
||||
'/ip hotspot user profile print .proplist=.id',
|
||||
RouterOS\Query::where('name', $plan['name_plan'])
|
||||
@ -141,18 +196,6 @@ class MikrotikHotspot
|
||||
);
|
||||
}
|
||||
|
||||
function add_pool($pool){
|
||||
// Hotspot no need pool
|
||||
}
|
||||
|
||||
function update_pool($old_pool, $new_pool){
|
||||
// Hotspot no need pool
|
||||
}
|
||||
|
||||
function remove_pool($pool){
|
||||
// Hotspot no need pool
|
||||
}
|
||||
|
||||
function info($name)
|
||||
{
|
||||
return ORM::for_table('tbl_routers')->where('name', $name)->find_one();
|
||||
@ -168,53 +211,6 @@ class MikrotikHotspot
|
||||
return new RouterOS\Client($iport[0], $user, $pass, ($iport[1]) ? $iport[1] : null);
|
||||
}
|
||||
|
||||
function isUserLogin($client, $username)
|
||||
{
|
||||
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('.id');
|
||||
}
|
||||
|
||||
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)
|
||||
);
|
||||
}
|
||||
|
||||
function logMeOut($client, $user)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
return null;
|
||||
}
|
||||
$printRequest = new RouterOS\Request(
|
||||
'/ip hotspot active print',
|
||||
RouterOS\Query::where('user', $user)
|
||||
);
|
||||
$id = $client->sendSync($printRequest)->getProperty('.id');
|
||||
$removeRequest = new RouterOS\Request('/ip/hotspot/active/remove');
|
||||
$client->sendSync(
|
||||
$removeRequest
|
||||
->setArgument('numbers', $id)
|
||||
);
|
||||
}
|
||||
|
||||
function removeHotspotUser($client, $username)
|
||||
{
|
||||
global $_app_stage;
|
||||
@ -351,19 +347,6 @@ class MikrotikHotspot
|
||||
$client->sendSync($removeRequest);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
function getIpHotspotUser($client, $username)
|
||||
{
|
||||
global $_app_stage;
|
||||
|
@ -10,73 +10,49 @@
|
||||
|
||||
use PEAR2\Net\RouterOS;
|
||||
|
||||
class MikrotikHotspot
|
||||
class MikrotikPppoe
|
||||
{
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
function connect_customer($customer, $plan)
|
||||
function add_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);
|
||||
$client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$this->removePpoeUser($client, $customer['username']);
|
||||
$this->removePpoeActive($client, $customer['username']);
|
||||
$this->addPpoeUser($client, $plan, $customer);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
function disconnect_customer($customer, $plan)
|
||||
function remove_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']);
|
||||
if (!empty($p['pool_expired'])) {
|
||||
Mikrotik::setPpoeUserPlan($client, $customer['username'], 'EXPIRED NUXBILL ' . $p['pool_expired']);
|
||||
$client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
if (!empty($plan['pool_expired'])) {
|
||||
$this->setPpoeUserPlan($client, $customer['username'], 'EXPIRED NUXBILL ' . $plan['pool_expired']);
|
||||
} else {
|
||||
Mikrotik::removePpoeUser($client, $customer['username']);
|
||||
$this->removePpoeUser($client, $customer['username']);
|
||||
}
|
||||
Mikrotik::removePpoeActive($client, $customer['username']);
|
||||
$this->removePpoeActive($client, $customer['username']);
|
||||
}
|
||||
|
||||
function change_customer($tur, $customer, $plan)
|
||||
function change_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);
|
||||
$client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$this->removePpoeUser($client, $customer['username']);
|
||||
$this->removePpoeActive($client, $customer['username']);
|
||||
$this->addPpoeUser($client, $plan, $customer);
|
||||
}
|
||||
|
||||
|
||||
@ -87,7 +63,10 @@ class MikrotikHotspot
|
||||
return;
|
||||
}
|
||||
$mikrotik = $this->info($plan['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
|
||||
//Add Pool
|
||||
|
||||
if ($plan['rate_down_unit'] == 'Kbps') {
|
||||
$unitdown = 'K';
|
||||
} else {
|
||||
@ -99,48 +78,51 @@ class MikrotikHotspot
|
||||
$unitup = 'M';
|
||||
}
|
||||
$rate = $plan['rate_up'] . $unitup . "/" . $plan['rate_down'] . $unitdown;
|
||||
$addRequest = new RouterOS\Request('/ip/hotspot/user/profile/add');
|
||||
$addRequest = new RouterOS\Request('/ppp/profile/add');
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
->setArgument('name', $plan['name_plan'])
|
||||
->setArgument('shared-users', $plan['shared_users'])
|
||||
->setArgument('local-address', $plan['pool'])
|
||||
->setArgument('remote-address', $plan['pool'])
|
||||
->setArgument('rate-limit', $rate)
|
||||
);
|
||||
}
|
||||
|
||||
function update_plan($old_name, $plan)
|
||||
function update_plan($old_name, $new_plan)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
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';
|
||||
}
|
||||
if ($plan['rate_up_unit'] == 'Kbps') {
|
||||
$unitup = 'K';
|
||||
} else {
|
||||
$unitup = 'M';
|
||||
}
|
||||
$rate = $plan['rate_up'] . $unitup . "/" . $plan['rate_down'] . $unitdown;
|
||||
$mikrotik = $this->info($new_plan['routers']);
|
||||
$client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
|
||||
$printRequest = new RouterOS\Request(
|
||||
'/ip hotspot user profile print .proplist=.id',
|
||||
RouterOS\Query::where('name', $old_name)
|
||||
'/ppp profile print .proplist=.id',
|
||||
RouterOS\Query::where('name', $old_name['name_plan'])
|
||||
);
|
||||
$profileID = $client->sendSync($printRequest)->getProperty('.id');
|
||||
if (empty($profileID)) {
|
||||
Mikrotik::addHotspotPlan($client, $plan['name_plan'], $plan['shared_users'], $rate);
|
||||
$this->add_plan($new_plan);
|
||||
} else {
|
||||
$setRequest = new RouterOS\Request('/ip/hotspot/user/profile/set');
|
||||
if ($new_plan['rate_down_unit'] == 'Kbps') {
|
||||
$unitdown = 'K';
|
||||
} else {
|
||||
$unitdown = 'M';
|
||||
}
|
||||
if ($new_plan['rate_up_unit'] == 'Kbps') {
|
||||
$unitup = 'K';
|
||||
} else {
|
||||
$unitup = 'M';
|
||||
}
|
||||
$rate = $new_plan['rate_up'] . $unitup . "/" . $new_plan['rate_down'] . $unitdown;
|
||||
|
||||
$setRequest = new RouterOS\Request('/ppp/profile/set');
|
||||
$client->sendSync(
|
||||
$setRequest
|
||||
->setArgument('numbers', $profileID)
|
||||
->setArgument('name', $plan['name_plan'])
|
||||
->setArgument('shared-users', $plan['shared_users'])
|
||||
->setArgument('local-address', $new_plan['pool'])
|
||||
->setArgument('remote-address', $new_plan['pool'])
|
||||
->setArgument('rate-limit', $rate)
|
||||
);
|
||||
}
|
||||
@ -153,13 +135,14 @@ class MikrotikHotspot
|
||||
return;
|
||||
}
|
||||
$mikrotik = $this->info($plan['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$printRequest = new RouterOS\Request(
|
||||
'/ip hotspot user profile print .proplist=.id',
|
||||
'/ppp profile print .proplist=.id',
|
||||
RouterOS\Query::where('name', $plan['name_plan'])
|
||||
);
|
||||
$profileID = $client->sendSync($printRequest)->getProperty('.id');
|
||||
$removeRequest = new RouterOS\Request('/ip/hotspot/user/profile/remove');
|
||||
|
||||
$removeRequest = new RouterOS\Request('/ppp/profile/remove');
|
||||
$client->sendSync(
|
||||
$removeRequest
|
||||
->setArgument('numbers', $profileID)
|
||||
@ -172,7 +155,7 @@ class MikrotikHotspot
|
||||
return null;
|
||||
}
|
||||
$mikrotik = $this->info($pool['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$addRequest = new RouterOS\Request('/ip/pool/add');
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
@ -187,7 +170,7 @@ class MikrotikHotspot
|
||||
return null;
|
||||
}
|
||||
$mikrotik = $this->info($new_pool['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$client = $this->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'])
|
||||
@ -212,7 +195,7 @@ class MikrotikHotspot
|
||||
return null;
|
||||
}
|
||||
$mikrotik = $this->info($pool['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$printRequest = new RouterOS\Request(
|
||||
'/ip pool print .proplist=.id',
|
||||
RouterOS\Query::where('name', $pool['pool_name'])
|
||||
@ -225,6 +208,22 @@ class MikrotikHotspot
|
||||
);
|
||||
}
|
||||
|
||||
function connect_customer($customer, $ip, $mac_address, $router_name)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function disconnect_customer($customer, $router_name)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function info($name)
|
||||
{
|
||||
return ORM::for_table('tbl_routers')->where('name', $name)->find_one();
|
||||
@ -240,34 +239,6 @@ class MikrotikHotspot
|
||||
return new RouterOS\Client($iport[0], $user, $pass, ($iport[1]) ? $iport[1] : null);
|
||||
}
|
||||
|
||||
function isUserLogin($client, $username)
|
||||
{
|
||||
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('.id');
|
||||
}
|
||||
|
||||
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)
|
||||
);
|
||||
}
|
||||
function removePpoeUser($client, $username)
|
||||
{
|
||||
global $_app_stage;
|
||||
@ -355,79 +326,6 @@ class MikrotikHotspot
|
||||
$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);
|
||||
}
|
||||
|
||||
function getIpHotspotUser($client, $username)
|
||||
{
|
||||
global $_app_stage;
|
||||
|
@ -1,37 +1,417 @@
|
||||
<?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
|
||||
**/
|
||||
|
||||
class Radius {
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
function connect_customer($routers, $customer){
|
||||
function add_customer($customer, $plan)
|
||||
{
|
||||
global $b;
|
||||
$this->customerAddPlan($customer, $plan, $b['expiration'] . '' . $b['time']);
|
||||
}
|
||||
|
||||
function remove_customer($customer, $plan)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
return;
|
||||
}
|
||||
if (empty($plan['pool_expired'])) {
|
||||
$this->customerDeactivate($customer['username']);
|
||||
} else {
|
||||
$this->upsertCustomerAttr($customer['username'], 'Framed-Pool', $plan['pool_expired'], ':=');
|
||||
$this->disconnectCustomer($customer['username']);
|
||||
}
|
||||
}
|
||||
|
||||
function change_customer($customer, $plan)
|
||||
{
|
||||
$this->customerUpsert($customer, $plan);
|
||||
}
|
||||
|
||||
function add_plan($plan)
|
||||
{
|
||||
if ($plan['rate_down_unit'] == 'Kbps') {
|
||||
$unitdown = 'K';
|
||||
} else {
|
||||
$unitdown = 'M';
|
||||
}
|
||||
if ($plan['rate_up_unit'] == 'Kbps') {
|
||||
$unitup = 'K';
|
||||
} else {
|
||||
$unitup = 'M';
|
||||
}
|
||||
$rate = $plan['rate_up'] . $unitup . "/" . $plan['rate_down'] . $unitdown;
|
||||
|
||||
$rates = explode('/', $rate);
|
||||
##burst fixed
|
||||
if (strpos($rate, ' ')) {
|
||||
$ratos = $rates[0] . '/' . $rates[1] . ' ' . $rates[2] . '/' . $rates[3] . '/' . $rates[4] . '/' . $rates[5] . '/' . $rates[6];
|
||||
} else {
|
||||
$ratos = $rates[0] . '/' . $rates[1];
|
||||
}
|
||||
|
||||
$this->upsertPackage($plan['id'], 'Ascend-Data-Rate', $rates[1], ':=');
|
||||
$this->upsertPackage($plan['id'], 'Ascend-Xmit-Rate', $rates[0], ':=');
|
||||
$this->upsertPackage($plan['id'], 'Mikrotik-Rate-Limit', $ratos, ':=');
|
||||
}
|
||||
|
||||
function update_plan($old_name, $plan)
|
||||
{
|
||||
$this->add_plan($plan);
|
||||
}
|
||||
|
||||
function remove_plan($plan)
|
||||
{
|
||||
// Delete Plan
|
||||
$this->getTablePackage()->where_equal('plan_id', "plan_" . $plan['id'])->delete_many();
|
||||
// Reset User Plan
|
||||
$c = $this->getTableUserPackage()->where_equal('groupname', "plan_" . $plan['id'])->findMany();
|
||||
if ($c) {
|
||||
foreach ($c as $u) {
|
||||
$u->groupname = '';
|
||||
$u->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function online_customer($customer, $router_name)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function connect_customer($customer, $ip, $mac_address, $router_name)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function disconnect_customer($customer, $router_name)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTableNas()
|
||||
{
|
||||
return ORM::for_table('nas', 'radius');
|
||||
}
|
||||
public function getTableAcct()
|
||||
{
|
||||
return ORM::for_table('radacct', 'radius');
|
||||
}
|
||||
public function getTableCustomer()
|
||||
{
|
||||
return ORM::for_table('radcheck', 'radius');
|
||||
}
|
||||
|
||||
public function getTableCustomerAttr()
|
||||
{
|
||||
return ORM::for_table('radreply', 'radius');
|
||||
}
|
||||
|
||||
public function getTablePackage()
|
||||
{
|
||||
return ORM::for_table('radgroupreply', 'radius');
|
||||
}
|
||||
|
||||
public function getTableUserPackage()
|
||||
{
|
||||
return ORM::for_table('radusergroup', 'radius');
|
||||
}
|
||||
|
||||
public function nasAdd($name, $ip, $ports, $secret, $routers = "", $description = "", $type = 'other', $server = null, $community = null)
|
||||
{
|
||||
$n = $this->getTableNas()->create();
|
||||
$n->nasname = $ip;
|
||||
$n->shortname = $name;
|
||||
$n->type = $type;
|
||||
$n->ports = $ports;
|
||||
$n->secret = $secret;
|
||||
$n->description = $description;
|
||||
$n->server = $server;
|
||||
$n->community = $community;
|
||||
$n->routers = $routers;
|
||||
$n->save();
|
||||
return $n->id();
|
||||
}
|
||||
|
||||
public function nasUpdate($id, $name, $ip, $ports, $secret, $routers = "", $description = "", $type = 'other', $server = null, $community = null)
|
||||
{
|
||||
$n = $this->getTableNas()->find_one($id);
|
||||
if (empty($n)) {
|
||||
return false;
|
||||
}
|
||||
$n->nasname = $ip;
|
||||
$n->shortname = $name;
|
||||
$n->type = $type;
|
||||
$n->ports = $ports;
|
||||
$n->secret = $secret;
|
||||
$n->description = $description;
|
||||
$n->server = $server;
|
||||
$n->community = $community;
|
||||
$n->routers = $routers;
|
||||
return $n->save();
|
||||
}
|
||||
|
||||
public function planUpSert($plan_id, $rate, $pool = null)
|
||||
{
|
||||
$rates = explode('/', $rate);
|
||||
##burst fixed
|
||||
if (strpos($rate, ' ')) {
|
||||
$ratos = $rates[0] . '/' . $rates[1] . ' ' . $rates[2] . '/' . $rates[3] . '/' . $rates[4] . '/' . $rates[5] . '/' . $rates[6];
|
||||
} else {
|
||||
$ratos = $rates[0] . '/' . $rates[1];
|
||||
}
|
||||
|
||||
$this->upsertPackage($plan_id, 'Ascend-Data-Rate', $rates[1], ':=');
|
||||
$this->upsertPackage($plan_id, 'Ascend-Xmit-Rate', $rates[0], ':=');
|
||||
$this->upsertPackage($plan_id, 'Mikrotik-Rate-Limit', $ratos, ':=');
|
||||
// if ($pool != null) {
|
||||
// $this->upsertPackage($plan_id, 'Framed-Pool', $pool, ':=');
|
||||
// }
|
||||
}
|
||||
|
||||
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;
|
||||
$r = $this->getTableCustomer()->where_equal('username', $username)->whereEqual('attribute', 'Cleartext-Password')->findOne();
|
||||
if ($r) {
|
||||
// no need to delete, because it will make ID got higher
|
||||
// we just change the password
|
||||
$r->value = md5(time() . $username . $radius_pass);
|
||||
$r->save();
|
||||
if ($radiusDisconnect)
|
||||
return $this->disconnectCustomer($username);
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public function customerDelete($username)
|
||||
{
|
||||
$this->getTableCustomer()->where_equal('username', $username)->delete_many();
|
||||
$this->getTableUserPackage()->where_equal('username', $username)->delete_many();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* When add a plan to Customer, use this
|
||||
*/
|
||||
function disconnect_customer($routers, $customer){
|
||||
public function customerAddPlan($customer, $plan, $expired = null)
|
||||
{
|
||||
global $config;
|
||||
if ($this->customerUpsert($customer, $plan)) {
|
||||
$p = $this->getTableUserPackage()->where_equal('username', $customer['username'])->findOne();
|
||||
if ($p) {
|
||||
// if exists
|
||||
$this->delAtribute($this->getTableCustomer(), 'Max-All-Session', 'username', $customer['username']);
|
||||
//$this->delAtribute($this->getTableCustomer(), 'Max-Volume', 'username', $customer['username']);
|
||||
$this->delAtribute($this->getTableCustomer(), 'Max-Data', 'username', $customer['username']);
|
||||
$p->groupname = "plan_" . $plan['id'];
|
||||
$p->save();
|
||||
} else {
|
||||
$p = $this->getTableUserPackage()->create();
|
||||
$p->username = $customer['username'];
|
||||
$p->groupname = "plan_" . $plan['id'];
|
||||
$p->priority = 1;
|
||||
$p->save();
|
||||
}
|
||||
if ($plan['type'] == 'Hotspot' && $plan['typebp'] == "Limited") {
|
||||
if ($plan['limit_type'] == "Time_Limit") {
|
||||
if ($plan['time_unit'] == 'Hrs')
|
||||
$timelimit = $plan['time_limit'] * 60 * 60;
|
||||
else
|
||||
$timelimit = $plan['time_limit'] * 60;
|
||||
$this->upsertCustomer($customer['username'], 'Max-All-Session', $timelimit);
|
||||
//$this->upsertCustomer($customer['username'], 'Expire-After', $timelimit);
|
||||
} else if ($plan['limit_type'] == "Data_Limit") {
|
||||
if ($plan['data_unit'] == 'GB')
|
||||
$datalimit = $plan['data_limit'] . "000000000";
|
||||
else
|
||||
$datalimit = $plan['data_limit'] . "000000";
|
||||
//$this->upsertCustomer($customer['username'], 'Max-Volume', $datalimit);
|
||||
// Mikrotik Spesific
|
||||
$this->upsertCustomer($customer['username'], 'Max-Data', $datalimit);
|
||||
//$this->upsertCustomer($customer['username'], 'Mikrotik-Total-Limit', $datalimit);
|
||||
} else if ($plan['limit_type'] == "Both_Limit") {
|
||||
if ($plan['time_unit'] == 'Hrs')
|
||||
$timelimit = $plan['time_limit'] * 60 * 60;
|
||||
else
|
||||
$timelimit = $plan['time_limit'] * 60;
|
||||
if ($plan['data_unit'] == 'GB')
|
||||
$datalimit = $plan['data_limit'] . "000000000";
|
||||
else
|
||||
$datalimit = $plan['data_limit'] . "000000";
|
||||
//$this->upsertCustomer($customer['username'], 'Max-Volume', $datalimit);
|
||||
$this->upsertCustomer($customer['username'], 'Max-All-Session', $timelimit);
|
||||
// Mikrotik Spesific
|
||||
$this->upsertCustomer($customer['username'], 'Max-Data', $datalimit);
|
||||
//$this->upsertCustomer($customer['username'], 'Mikrotik-Total-Limit', $datalimit);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
} else {
|
||||
//$this->delAtribute($this->getTableCustomer(), 'Max-Volume', 'username', $customer['username']);
|
||||
$this->delAtribute($this->getTableCustomer(), 'Max-All-Session', 'username', $customer['username']);
|
||||
$this->delAtribute($this->getTableCustomer(), 'Max-Data', 'username', $customer['username']);
|
||||
}
|
||||
|
||||
$this->disconnectCustomer($customer['username']);
|
||||
$this->getTableAcct()->where_equal('username', $customer['username'])->delete_many();
|
||||
|
||||
|
||||
// expired user
|
||||
if ($expired != null) {
|
||||
//$this->upsertCustomer($customer['username'], 'access-period', strtotime($expired) - time());
|
||||
$this->upsertCustomer($customer['username'], 'Max-All-Session', strtotime($expired) - time());
|
||||
//$this->upsertCustomer($customer['username'], 'expiration', date('d M Y H:i:s', strtotime($expired)));
|
||||
// Mikrotik Spesific
|
||||
$this->upsertCustomer(
|
||||
$customer['username'],
|
||||
'WISPr-Session-Terminate-Time',
|
||||
date('Y-m-d', strtotime($expired)) . 'T' . date('H:i:s', strtotime($expired)) . Timezone::getTimeOffset($config['timezone'])
|
||||
);
|
||||
} else {
|
||||
$this->delAtribute($this->getTableCustomer(), 'Max-All-Session', 'username', $customer['username']);
|
||||
//$this->delAtribute($this->getTableCustomer(), 'access-period', 'username', $customer['username']);
|
||||
//$this->delAtribute($this->getTableCustomer(), 'expiration', 'username', $customer['username']);
|
||||
}
|
||||
|
||||
if ($plan['type'] == 'PPPOE') {
|
||||
$this->upsertCustomerAttr($customer['username'], 'Framed-Pool', $plan['pool'], ':=');
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function customerUpsert($customer, $plan)
|
||||
{
|
||||
if ($plan['type'] == 'PPPOE') {
|
||||
$this->upsertCustomer($customer['username'], 'Cleartext-Password', (empty($customer['pppoe_password'])) ? $customer['password'] : $customer['pppoe_password']);
|
||||
} else {
|
||||
$this->upsertCustomer($customer['username'], 'Cleartext-Password', $customer['password']);
|
||||
}
|
||||
$this->upsertCustomer($customer['username'], 'Simultaneous-Use', ($plan['type'] == 'PPPOE') ? 1 : $plan['shared_users']);
|
||||
// Mikrotik Spesific
|
||||
$this->upsertCustomer($customer['username'], 'Port-Limit', ($plan['type'] == 'PPPOE') ? 1 : $plan['shared_users']);
|
||||
$this->upsertCustomer($customer['username'], 'Mikrotik-Wireless-Comment', $customer['fullname']);
|
||||
return true;
|
||||
}
|
||||
|
||||
private function delAtribute($tabel, $attribute, $key, $value)
|
||||
{
|
||||
$r = $tabel->where_equal($key, $value)->whereEqual('attribute', $attribute)->findOne();
|
||||
if ($r) $r->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* To insert or update existing plan
|
||||
*/
|
||||
private function upsertPackage($plan_id, $attr, $value, $op = ':=')
|
||||
{
|
||||
$r = $this->getTablePackage()->where_equal('plan_id', $plan_id)->whereEqual('attribute', $attr)->find_one();
|
||||
if (!$r) {
|
||||
$r = $this->getTablePackage()->create();
|
||||
$r->groupname = "plan_" . $plan_id;
|
||||
$r->plan_id = $plan_id;
|
||||
}
|
||||
$r->attribute = $attr;
|
||||
$r->op = $op;
|
||||
$r->value = $value;
|
||||
return $r->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* To insert or update existing customer
|
||||
*/
|
||||
public function upsertCustomer($username, $attr, $value, $op = ':=')
|
||||
{
|
||||
$r = $this->getTableCustomer()->where_equal('username', $username)->whereEqual('attribute', $attr)->find_one();
|
||||
if (!$r) {
|
||||
$r = $this->getTableCustomer()->create();
|
||||
$r->username = $username;
|
||||
}
|
||||
$r->attribute = $attr;
|
||||
$r->op = $op;
|
||||
$r->value = $value;
|
||||
return $r->save();
|
||||
}
|
||||
/**
|
||||
* To insert or update existing customer Attribute
|
||||
*/
|
||||
public function upsertCustomerAttr($username, $attr, $value, $op = ':=')
|
||||
{
|
||||
$r = $this->getTableCustomerAttr()->where_equal('username', $username)->whereEqual('attribute', $attr)->find_one();
|
||||
if (!$r) {
|
||||
$r = $this->getTableCustomerAttr()->create();
|
||||
$r->username = $username;
|
||||
}
|
||||
$r->attribute = $attr;
|
||||
$r->op = $op;
|
||||
$r->value = $value;
|
||||
return $r->save();
|
||||
}
|
||||
|
||||
public function disconnectCustomer($username)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Fix loop to all Nas but still detecting Hotspot Multylogin from other Nas
|
||||
*/
|
||||
$act = ORM::for_table('radacct')->where_raw("acctstoptime IS NULL")->where('username', $username)->find_one();
|
||||
$nas = $this->getTableNas()->where('nasname', $act['nasipaddress'])->find_many();
|
||||
$count = count($nas) * 15;
|
||||
set_time_limit($count);
|
||||
$result = [];
|
||||
foreach ($nas as $n) {
|
||||
$port = 3799;
|
||||
if (!empty($n['ports'])) {
|
||||
$port = $n['ports'];
|
||||
}
|
||||
$result[] = $n['nasname'] . ': ' . @shell_exec("echo 'User-Name = $username,Framed-IP-Address = " . $act['framedipaddress'] . "' | radclient -x " . trim($n['nasname']) . ":$port disconnect '" . $n['secret'] . "'");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -7,7 +7,7 @@ just follow the template
|
||||
|
||||
class FileName {
|
||||
|
||||
function connect_customer($customer, $plan)
|
||||
function add_customer($customer, $plan)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
@ -15,7 +15,7 @@ class FileName {
|
||||
}
|
||||
}
|
||||
|
||||
function disconnect_customer($customer, $plan)
|
||||
function remove_customer($customer, $plan)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
@ -23,7 +23,7 @@ class FileName {
|
||||
}
|
||||
}
|
||||
|
||||
function change_customer($tur, $customer, $plan)
|
||||
function change_customer($customer, $plan)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
@ -55,25 +55,29 @@ class FileName {
|
||||
}
|
||||
}
|
||||
|
||||
function add_pool($pool){
|
||||
function online_customer($customer, $router_name)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function update_pool($old_pool, $new_pool){
|
||||
function connect_customer($customer, $ip, $mac_address, $router_name)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function remove_pool($pool){
|
||||
function disconnect_customer($customer, $router_name)
|
||||
{
|
||||
global $_app_stage;
|
||||
if ($_app_stage == 'demo') {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
```
|
@ -102,5 +102,9 @@
|
||||
],
|
||||
"2024.5.20" : [
|
||||
"ALTER TABLE `tbl_customers` ADD `city` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci AFTER `address`, ADD `district` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci AFTER `city`, ADD `state` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci AFTER `district`, ADD `zip` VARCHAR(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci AFTER `state`;"
|
||||
],
|
||||
"2024.6.5" : [
|
||||
"ALTER TABLE `tbl_plans` ADD `price_old` VARCHAR(40) NOT NULL DEFAULT '' AFTER `price`;",
|
||||
"ALTER TABLE `tbl_plans` ADD `device` VARCHAR(32) NOT NULL DEFAULT '' AFTER `plan_type`;"
|
||||
]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user