Fix Pools

This commit is contained in:
Ibnu Maksum 2022-10-03 11:03:56 +07:00
parent d7d9d9efa1
commit 89e0dd9380
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
4 changed files with 53 additions and 90 deletions

View File

@ -244,25 +244,29 @@ class Mikrotik
public static function addPool($client, $name, $ip_address){
$addRequest = new RouterOS\Request('/ip/pool/add');
$client->sendSync($addRequest
->setArgument('name', $name)
->setArgument('ranges', $ip_address)
);
$client->sendSync($addRequest
->setArgument('name', $name)
->setArgument('ranges', $ip_address)
);
}
public static function setPool($client, $oldName, $name, $ip_address){
public static function setPool($client, $name, $ip_address){
$printRequest = new RouterOS\Request(
'/ip pool print .proplist=name',
RouterOS\Query::where('name', $oldName)
RouterOS\Query::where('name', $name)
);
$poolName = $client->sendSync($printRequest)->getProperty('name');
$setRequest = new RouterOS\Request('/ip/pool/set');
$client(
$setRequest
->setArgument('numbers', $name)
->setArgument('ranges', $ip_address)
);
if(empty($poolName)){
self::addPool($client, $name, $ip_address);
}else{
$setRequest = new RouterOS\Request('/ip/pool/set');
$client(
$setRequest
->setArgument('numbers', $poolName)
->setArgument('ranges', $ip_address)
);
}
}
@ -283,15 +287,18 @@ class Mikrotik
RouterOS\Query::where('name', $name)
);
$profileName = $client->sendSync($printRequest)->getProperty('name');
$setRequest = new RouterOS\Request('/ppp/profile/set');
$client(
$setRequest
->setArgument('numbers', $profileName)
->setArgument('local-address', $pool)
->setArgument('remote-address', $pool)
->setArgument('rate-limit', $rate)
);
if(empty($profileName)){
self::addPpoePlan($client, $name, $pool, $rate);
}else{
$setRequest = new RouterOS\Request('/ppp/profile/set');
$client(
$setRequest
->setArgument('numbers', $profileName)
->setArgument('local-address', $pool)
->setArgument('remote-address', $pool)
->setArgument('rate-limit', $rate)
);
}
}
public static function removePpoePlan($client, $name){

View File

@ -1,8 +0,0 @@
<?php
/**
* PHP Mikrotik Billing (https://ibnux.github.io/phpmixbill/)
**/
Class Router{
}

View File

@ -39,50 +39,6 @@ function _post($param, $defvalue = '')
}
}
$menu_registered = array();
/**
* Register for global menu
* @param string name Name of the menu
* @param bool admin true if for admin and false for customer
* @param string function function to run after menu clicks
* @param string position position of menu, use AFTER_ for root menu |
* Admin/Sales menu: AFTER_DASHBOARD, CUSTOMERS, PREPAID, SERVICES, REPORTS, VOUCHER, AFTER_ORDER, NETWORK, SETTINGS, AFTER_PAYMENTGATEWAY
* | Customer menu: AFTER_DASHBOARD, ORDER, HISTORY, ACCOUNTS
* @param string icon from ion icon, ion-person, only for AFTER_
*/
function register_menu($name, $admin, $function, $position, $icon = '')
{
global $menu_registered;
$menu_registered[] = [
"name" => $name,
"admin" => $admin,
"position" => $position,
"icon" => $icon,
"function" => $function
];
}
$hook_registered = array();
function register_hook($action, $function){
$hook_registered[] = [
'action' => $action,
'function' => $function
];
}
function run_hook($action){
global $hook_registered;
foreach($hook_registered as $hook){
if($hook['action'] == $action){
if(function_exists($hook['function'])){
call_user_func($hook['function']);
}
}
}
}
function _get($param, $defvalue = '')
{
if (!isset($_GET[$param])) {
@ -100,7 +56,9 @@ ORM::configure('username', $db_user);
ORM::configure('password', $db_password);
ORM::configure('driver_options', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
ORM::configure('return_result_sets', true);
ORM::configure('logging', true);
if($_app_stage != 'Live'){
ORM::configure('logging', true);
}
$result = ORM::for_table('tbl_appconfig')->find_many();
foreach ($result as $value) {
@ -110,6 +68,14 @@ foreach ($result as $value) {
date_default_timezone_set($config['timezone']);
$_c = $config;
if($config['radius_mode']){
ORM::configure("mysql:host=$radius_host;dbname=$radius_name", null, 'radius');
ORM::configure('username', $radius_user, 'radius');
ORM::configure('password', $radius_password, 'radius');
ORM::configure('driver_options', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'), 'radius');
ORM::configure('return_result_sets', true, 'radius');
}
function _notify($msg, $type = 'e')
{
$_SESSION['ntype'] = $type;
@ -162,6 +128,8 @@ if (isset($_SESSION['notify'])) {
unset($_SESSION['ntype']);
}
include "autoload/Hookers.php";
//register all plugin
foreach (glob("system/plugin/*.php") as $filename)
@ -263,20 +231,20 @@ function alphanumeric($str, $tambahan = "")
function sendTelegram($txt)
{
global $_c;
global $config;
run_hook('send_telegram'); #HOOK
if (!empty($_c['telegram_bot']) && !empty($_c['telegram_target_id'])) {
file_get_contents('https://api.telegram.org/bot' . $_c['telegram_bot'] . '/sendMessage?chat_id=' . $_c['telegram_target_id'] . '&text=' . urlencode($txt));
if (!empty($config['telegram_bot']) && !empty($config['telegram_target_id'])) {
file_get_contents('https://api.telegram.org/bot' . $config['telegram_bot'] . '/sendMessage?chat_id=' . $config['telegram_target_id'] . '&text=' . urlencode($txt));
}
}
function sendSMS($phone, $txt)
{
global $_c;
global $config;
run_hook('send_sms'); #HOOK
if (!empty($_c['sms_url'])) {
$smsurl = str_replace('[number]', urlencode($phone), $_c['sms_url']);
if (!empty($config['sms_url'])) {
$smsurl = str_replace('[number]', urlencode($phone), $config['sms_url']);
$smsurl = str_replace('[text]', urlencode($txt), $smsurl);
file_get_contents($smsurl);
}
@ -284,10 +252,10 @@ function sendSMS($phone, $txt)
function sendWhatsapp($phone, $txt)
{
global $_c;
global $config;
run_hook('send_whatsapp'); #HOOK
if (!empty($_c['wa_url'])) {
$waurl = str_replace('[number]', urlencode($phone), $_c['wa_url']);
if (!empty($config['wa_url'])) {
$waurl = str_replace('[number]', urlencode($phone), $config['wa_url']);
$waurl = str_replace('[text]', urlencode($txt), $waurl);
file_get_contents($waurl);
}

View File

@ -94,7 +94,7 @@ switch ($action) {
if ($msg == '') {
if (!$config['radius_mode']) {
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::removePool($client, $name, $ip_address);
Mikrotik::addPool($client, $name, $ip_address);
}
$b = ORM::for_table('tbl_pool')->create();
@ -111,14 +111,11 @@ switch ($action) {
case 'edit-post':
$name = _post('name');
$ip_address = _post('ip_address');
$routers = _post('routers');
run_hook('edit_pool'); #HOOK
$msg = '';
if (Validator::Length($name, 30, 2) == false) {
$msg .= 'Name should be between 3 to 30 characters' . '<br>';
}
if ($ip_address == '' or $routers == '') {
$msg .= $_L['All_field_is_required'] . '<br>';
}
@ -134,10 +131,9 @@ switch ($action) {
if ($msg == '') {
if (!$config['radius_mode']) {
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::setPool($client, $name,$poolName, $ip_address);
Mikrotik::setPool($client, $d['pool_name'], $ip_address);
}
$d->pool_name = $name;
$d->range_ip = $ip_address;
$d->routers = $routers;
$d->save();