Fix cron can move plan

This commit is contained in:
Ibnu Maksum 2023-09-06 10:48:52 +07:00
parent e23abc1377
commit 910be1946b
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
7 changed files with 119 additions and 111 deletions

View File

@ -72,7 +72,7 @@ class Mikrotik
public static function setHotspotPlan($client, $name, $sharedusers, $rate)
{
$printRequest = new RouterOS\Request(
'/ip hotspot user profile print .proplist=name',
'/ip hotspot user profile print .proplist=.id',
RouterOS\Query::where('name', $name)
);
$profileID = $client->sendSync($printRequest)->getProperty('.id');
@ -92,7 +92,7 @@ class Mikrotik
public static function setHotspotExpiredPlan($client, $name, $pool)
{
$printRequest = new RouterOS\Request(
'/ip hotspot user profile print .proplist=name',
'/ip hotspot user profile print .proplist=.id',
RouterOS\Query::where('name', $name)
);
$profileID = $client->sendSync($printRequest)->getProperty('.id');
@ -120,7 +120,7 @@ class Mikrotik
public static function removeHotspotPlan($client, $name)
{
$printRequest = new RouterOS\Request(
'/ip hotspot user profile print .proplist=name',
'/ip hotspot user profile print .proplist=.id',
RouterOS\Query::where('name', $name)
);
$profileID = $client->sendSync($printRequest)->getProperty('.id');
@ -135,7 +135,7 @@ class Mikrotik
public static function removeHotspotUser($client, $username)
{
$printRequest = new RouterOS\Request(
'/ip hotspot user print .proplist=name',
'/ip hotspot user print .proplist=.id',
RouterOS\Query::where('name', $username)
);
$userID = $client->sendSync($printRequest)->getProperty('.id');
@ -322,7 +322,7 @@ class Mikrotik
public static function removePool($client, $name)
{
$printRequest = new RouterOS\Request(
'/ip pool print .proplist=name',
'/ip pool print .proplist=.id',
RouterOS\Query::where('name', $name)
);
$poolID = $client->sendSync($printRequest)->getProperty('.id');
@ -347,7 +347,7 @@ class Mikrotik
public static function setPool($client, $name, $ip_address)
{
$printRequest = new RouterOS\Request(
'/ip pool print .proplist=name',
'/ip pool print .proplist=.id',
RouterOS\Query::where('name', $name)
);
$poolID = $client->sendSync($printRequest)->getProperty('id');
@ -380,7 +380,7 @@ class Mikrotik
public static function setPpoePlan($client, $name, $pool, $rate)
{
$printRequest = new RouterOS\Request(
'/ppp profile print .proplist=name',
'/ppp profile print .proplist=.id',
RouterOS\Query::where('name', $name)
);
$profileID = $client->sendSync($printRequest)->getProperty('.id');
@ -401,7 +401,7 @@ class Mikrotik
public static function removePpoePlan($client, $name)
{
$printRequest = new RouterOS\Request(
'/ppp profile print .proplist=name',
'/ppp profile print .proplist=.id',
RouterOS\Query::where('name', $name)
);
$profileID = $client->sendSync($printRequest)->getProperty('.id');

View File

@ -106,8 +106,10 @@ class Package
// if it same internet plan, expired will extend
if ($p['validity_unit'] == 'Months') {
$date_exp = date("Y-m-d", strtotime($b['expiration'] . ' +' . $p['validity'] . ' months'));
$time = $b['time'];
} else if ($p['validity_unit'] == 'Days') {
$date_exp = date("Y-m-d", strtotime($b['expiration'] . ' +' . $p['validity'] . ' days'));
$time = $b['time'];
} else if ($p['validity_unit'] == 'Hrs') {
$datetime = explode(' ', date("Y-m-d H:i:s", strtotime($b['expiration'] . ' ' . $b['time'] . ' +' . $p['validity'] . ' hours')));
$date_exp = $datetime[0];
@ -150,6 +152,7 @@ class Package
} else {
if (!$_c['radius_mode']) {
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::removeHotspotUser($client, $c['username']);
Mikrotik::removePpoeUser($client, $c['username']);
Mikrotik::addHotspotUser($client, $p, $c);
}

View File

@ -4,6 +4,33 @@
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
**/
// on some server, it getting error because of slash is backwards
function _autoloader($class)
{
if (strpos($class, '_') !== false) {
$class = str_replace('_', DIRECTORY_SEPARATOR, $class);
if (file_exists('autoload' . DIRECTORY_SEPARATOR . $class . '.php')) {
include 'autoload' . DIRECTORY_SEPARATOR . $class . '.php';
} else {
$class = str_replace("\\", DIRECTORY_SEPARATOR, $class);
if (file_exists(__DIR__ . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . $class . '.php'))
include __DIR__ . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . $class . '.php';
}
} else {
if (file_exists('autoload' . DIRECTORY_SEPARATOR . $class . '.php')) {
include 'autoload' . DIRECTORY_SEPARATOR . $class . '.php';
} else {
$class = str_replace("\\", DIRECTORY_SEPARATOR, $class);
if (file_exists(__DIR__ . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . $class . '.php'))
include __DIR__ . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . $class . '.php';
}
}
}
spl_autoload_register('_autoloader');
function r2($to, $ntype = 'e', $msg = '')
{
if ($msg == '') {
@ -47,8 +74,7 @@ function _get($param, $defvalue = '')
}
}
require('system/orm.php');
require_once File::pathFixer('system/orm.php');
ORM::configure("mysql:host=$db_host;dbname=$db_name");
ORM::configure('username', $db_user);
@ -81,15 +107,15 @@ function _notify($msg, $type = 'e')
$_SESSION['notify'] = $msg;
}
$lan_file = 'system/lan/' . $config['language'] . '/common.lan.php';
$lan_file = File::pathFixer('system/lan/' . $config['language'] . '/common.lan.php');
require($lan_file);
$ui = new Smarty();
$ui->setTemplateDir(['custom' => 'ui/ui_custom/', 'default' => 'ui/ui/']);
$ui->addTemplateDir('system/paymentgateway/ui/', 'pg');
$ui->addTemplateDir('system/plugin/ui/', 'plugin');
$ui->setCompileDir('ui/compiled/');
$ui->setConfigDir('ui/conf/');
$ui->setCacheDir('ui/cache/');
$ui->setTemplateDir(['custom' => File::pathFixer('ui/ui_custom/'), 'default' => File::pathFixer('ui/ui/')]);
$ui->addTemplateDir(File::pathFixer('system/paymentgateway/ui/'), 'pg');
$ui->addTemplateDir(File::pathFixer('system/plugin/ui/'), 'plugin');
$ui->setCompileDir(File::pathFixer('ui/compiled/'));
$ui->setConfigDir(File::pathFixer('ui/conf/'));
$ui->setCacheDir(File::pathFixer('ui/cache/'));
$ui->assign('app_url', APP_URL);
$ui->assign('_domain', str_replace('www.', '', parse_url(APP_URL, PHP_URL_HOST)));
define('U', APP_URL . '/index.php?_route=');
@ -129,40 +155,16 @@ if (isset($_SESSION['notify'])) {
include "autoload/Hookers.php";
// notification message
if(file_exists("system/uploads/notifications.json")){
$_notifmsg =json_decode(file_get_contents('system/uploads/notifications.json'), true);
if (file_exists(File::pathFixer("system/uploads/notifications.json"))) {
$_notifmsg = json_decode(file_get_contents(File::pathFixer('system/uploads/notifications.json')), true);
}
$_notifmsg_default = json_decode(file_get_contents('system/uploads/notifications.default.json'), true);
$_notifmsg_default = json_decode(file_get_contents(File::pathFixer('system/uploads/notifications.default.json')), true);
//register all plugin
foreach (glob("system/plugin/*.php") as $filename) {
foreach (glob(File::pathFixer("system/plugin/*.php")) as $filename) {
include $filename;
}
// on some server, it getting error because of slash is backwards
function _autoloader($class)
{
if (strpos($class, '_') !== false) {
$class = str_replace('_', DIRECTORY_SEPARATOR, $class);
if (file_exists('autoload' . DIRECTORY_SEPARATOR . $class . '.php')) {
include 'autoload' . DIRECTORY_SEPARATOR . $class . '.php';
} else {
$class = str_replace("\\", DIRECTORY_SEPARATOR, $class);
if (file_exists(__DIR__ . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . $class . '.php'))
include __DIR__ . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . $class . '.php';
}
} else {
if (file_exists('autoload' . DIRECTORY_SEPARATOR . $class . '.php')) {
include 'autoload' . DIRECTORY_SEPARATOR . $class . '.php';
} else {
$class = str_replace("\\", DIRECTORY_SEPARATOR, $class);
if (file_exists(__DIR__ . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . $class . '.php'))
include __DIR__ . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . $class . '.php';
}
}
}
spl_autoload_register('_autoloader');
function _auth($login = true)
{
@ -281,7 +283,7 @@ $handler = $routes[0];
if ($handler == '') {
$handler = 'default';
}
$sys_render = 'system/controllers/' . $handler . '.php';
$sys_render = File::pathFixer('system/controllers/' . $handler . '.php');
if (file_exists($sys_render)) {
$menus = array();
// "name" => $name,

View File

@ -4,10 +4,34 @@
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
**/
require('../config.php');
require('orm.php');
// on some server, it getting error because of slash is backwards
function _autoloader($class)
{
if (strpos($class, '_') !== false) {
$class = str_replace('_', DIRECTORY_SEPARATOR, $class);
if (file_exists(__DIR__.DIRECTORY_SEPARATOR.'autoload' . DIRECTORY_SEPARATOR . $class . '.php')) {
include __DIR__.DIRECTORY_SEPARATOR.'autoload' . DIRECTORY_SEPARATOR . $class . '.php';
} else {
$class = str_replace("\\", DIRECTORY_SEPARATOR, $class);
if (file_exists(__DIR__ . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . $class . '.php'))
include __DIR__ . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . $class . '.php';
}
} else {
if (file_exists(__DIR__.DIRECTORY_SEPARATOR.'autoload' . DIRECTORY_SEPARATOR . $class . '.php')) {
include __DIR__.DIRECTORY_SEPARATOR.'autoload' . DIRECTORY_SEPARATOR . $class . '.php';
} else {
$class = str_replace("\\", DIRECTORY_SEPARATOR, $class);
if (file_exists(__DIR__ . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . $class . '.php'))
include __DIR__ . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . $class . '.php';
}
}
}
spl_autoload_register('_autoloader');
require_once 'autoload/PEAR2/Autoload.php';
require_once __DIR__.File::pathFixer('/../config.php');
require_once 'orm.php';
require_once __DIR__.File::pathFixer('/autoload/PEAR2/Autoload.php');
include __DIR__.File::pathFixer("/autoload/Hookers.php");
ORM::configure("mysql:host=$db_host;dbname=$db_name");
ORM::configure('username', $db_user);
@ -16,44 +40,17 @@ ORM::configure('return_result_sets', true);
ORM::configure('logging', true);
include "autoload/Hookers.php";
// notification message
if (file_exists("uploads/notifications.json")) {
$_notifmsg = json_decode(file_get_contents('uploads/notifications.json'), true);
if (file_exists(__DIR__.File::pathFixer("uploads/notifications.json"))) {
$_notifmsg = json_decode(file_get_contents(__DIR__.File::pathFixer('uploads/notifications.json')), true);
}
$_notifmsg_default = json_decode(file_get_contents('uploads/notifications.default.json'), true);
$_notifmsg_default = json_decode(file_get_contents(__DIR__.File::pathFixer('uploads/notifications.default.json')), true);
//register all plugin
foreach (glob("plugin/*.php") as $filename) {
foreach (glob(File::pathFixer("plugin/*.php")) as $filename) {
include $filename;
}
// on some server, it getting error because of slash is backwards
function _autoloader($class)
{
if (strpos($class, '_') !== false) {
$class = str_replace('_', DIRECTORY_SEPARATOR, $class);
if (file_exists('autoload' . DIRECTORY_SEPARATOR . $class . '.php')) {
include 'autoload' . DIRECTORY_SEPARATOR . $class . '.php';
} else {
$class = str_replace("\\", DIRECTORY_SEPARATOR, $class);
if (file_exists(__DIR__ . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . $class . '.php'))
include __DIR__ . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . $class . '.php';
}
} else {
if (file_exists('autoload' . DIRECTORY_SEPARATOR . $class . '.php')) {
include 'autoload' . DIRECTORY_SEPARATOR . $class . '.php';
} else {
$class = str_replace("\\", DIRECTORY_SEPARATOR, $class);
if (file_exists(__DIR__ . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . $class . '.php'))
include __DIR__ . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . $class . '.php';
}
}
}
spl_autoload_register('_autoloader');
$result = ORM::for_table('tbl_appconfig')->find_many();
foreach ($result as $value) {
$config[$value['setting']] = $value['value'];
@ -83,10 +80,10 @@ foreach ($d as $ds) {
if (!$_c['radius_mode']) {
$client = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']);
Mikrotik::removeHotspotActiveUser($client, $c['username']);
if(!empty($p['pool_expired'])){
Mikrotik::setHotspotUserPackage($client, $c['username'], 'EXPIRED NUXBILL '.$p['pool_expired']);
}else{
Mikrotik::removeHotspotActiveUser($client, $c['username']);
Mikrotik::removeHotspotUser($client, $c['username']);
}
Message::sendPackageNotification($c['phonenumber'], $c['fullname'], $u['namebp'], $textExpired, $config['user_notification_expired']);
@ -130,10 +127,10 @@ foreach ($d as $ds) {
if (!$_c['radius_mode']) {
$client = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']);
Mikrotik::removePpoeActive($client, $c['username']);
if(!empty($p['pool_expired'])){
Mikrotik::setPpoeUserPlan($client, $c['username'], 'EXPIRED NUXBILL '.$p['pool_expired']);
}else{
Mikrotik::removePpoeActive($client, $c['username']);
Mikrotik::removePpoeUser($client, $c['username']);
}
Message::sendPackageNotification($c['phonenumber'], $c['fullname'], $u['namebp'], $textExpired, $config['user_notification_expired']);

View File

@ -7,30 +7,6 @@
* 0 7 * * * /usr/bin/php /var/www/system/cron_reminder.php
**/
require('../config.php');
require('orm.php');
require_once 'autoload/PEAR2/Autoload.php';
ORM::configure("mysql:host=$db_host;dbname=$db_name");
ORM::configure('username', $db_user);
ORM::configure('password', $db_password);
ORM::configure('return_result_sets', true);
ORM::configure('logging', true);
include "autoload/Hookers.php";
// notification message
if(file_exists("uploads/notifications.json")){
$_notifmsg =json_decode(file_get_contents('uploads/notifications.json'), true);
}
$_notifmsg_default = json_decode(file_get_contents('uploads/notifications.default.json'), true);
//register all plugin
foreach (glob("plugin/*.php") as $filename) {
include $filename;
}
// on some server, it getting error because of slash is backwards
function _autoloader($class)
@ -38,7 +14,7 @@ function _autoloader($class)
if (strpos($class, '_') !== false) {
$class = str_replace('_', DIRECTORY_SEPARATOR, $class);
if (file_exists('autoload' . DIRECTORY_SEPARATOR . $class . '.php')) {
include 'autoload' . DIRECTORY_SEPARATOR . $class . '.php';
include __DIR__.DIRECTORY_SEPARATOR.'autoload' . DIRECTORY_SEPARATOR . $class . '.php';
} else {
$class = str_replace("\\", DIRECTORY_SEPARATOR, $class);
if (file_exists(__DIR__ . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . $class . '.php'))
@ -46,7 +22,7 @@ function _autoloader($class)
}
} else {
if (file_exists('autoload' . DIRECTORY_SEPARATOR . $class . '.php')) {
include 'autoload' . DIRECTORY_SEPARATOR . $class . '.php';
include __DIR__.DIRECTORY_SEPARATOR.'autoload' . DIRECTORY_SEPARATOR . $class . '.php';
} else {
$class = str_replace("\\", DIRECTORY_SEPARATOR, $class);
if (file_exists(__DIR__ . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . $class . '.php'))
@ -57,6 +33,30 @@ function _autoloader($class)
spl_autoload_register('_autoloader');
require_once __DIR__.File::pathFixer('/../config.php');
require_once __DIR__.File::pathFixer('orm.php');
require_once __DIR__.File::pathFixer('/autoload/PEAR2/Autoload.php');
include __DIR__.File::pathFixer("/autoload/Hookers.php");
ORM::configure("mysql:host=$db_host;dbname=$db_name");
ORM::configure('username', $db_user);
ORM::configure('password', $db_password);
ORM::configure('return_result_sets', true);
ORM::configure('logging', true);
// notification message
if (file_exists(__DIR__.File::pathFixer("uploads/notifications.json"))) {
$_notifmsg = json_decode(file_get_contents(__DIR__.File::pathFixer('uploads/notifications.json')), true);
}
$_notifmsg_default = json_decode(file_get_contents(__DIR__.File::pathFixer('uploads/notifications.default.json')), true);
//register all plugin
foreach (glob(File::pathFixer("plugin/*.php")) as $filename) {
include $filename;
}
$result = ORM::for_table('tbl_appconfig')->find_many();
foreach ($result as $value) {
$config[$value['setting']] = $value['value'];

View File

@ -341,3 +341,8 @@ $_L['Allow_balance_transfer_between_customers'] = 'Bolehkan transfer saldo antar
$_L['Refill_Balance'] = 'Refill Balance';
$_L['Balance_Plans'] = 'Balance Plans';
$_L['Expired_IP_Pool'] = 'Expired IP Pool';
$_L['Company_Logo'] = 'Company Logo';
$_L['Disable_Voucher'] = 'Disable Voucher';
$_L['Minimum_Balance_Transfer'] = 'Minimum Balance Transfer';
$_L['Reminder_Notification'] = 'Reminder Notification';
$_L['Invoice_Footer'] = 'Invoice Footer';

View File

@ -7,11 +7,12 @@ if(php_sapi_name() !== 'cli'){
die("RUN ON COMMAND LINE ONLY BY RADIUS ENGINE");
}
require(__DIR__.'/../config.php');
require(__DIR__.'/orm.php');
require_once __DIR__.File::pathFixer('/../config.php');
require_once __DIR__.File::pathFixer('orm.php');
require_once __DIR__.File::pathFixer('/autoload/PEAR2/Autoload.php');
include __DIR__.File::pathFixer("/autoload/Hookers.php");
use PEAR2\Net\RouterOS;
require_once 'autoload/PEAR2/Autoload.php';
ORM::configure("mysql:host=$db_host;dbname=$db_name");
ORM::configure('username', $db_user);