phpnuxbill/system/cron.php

113 lines
4.6 KiB
PHP
Raw Normal View History

2017-03-11 03:51:06 +08:00
<?php
2023-03-06 15:49:44 +08:00
2017-03-11 03:51:06 +08:00
/**
2023-03-06 15:49:44 +08:00
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
**/
2017-03-11 03:51:06 +08:00
2022-09-19 10:31:35 +08:00
require('../config.php');
2017-03-11 03:51:06 +08:00
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);
2022-09-21 15:15:00 +08:00
include "autoload/Hookers.php";
2023-08-14 12:24:27 +08:00
// notification message
if(file_exists("uploads/notifications.json")){
$_notifmsg =json_decode(file_get_contents('uploads/notifications.json'), true);
}else{
$_notifmsg = json_decode(file_get_contents('uploads/notifications.default.json'), true);
}
2022-09-21 15:15:00 +08:00
//register all plugin
2023-08-14 12:24:27 +08:00
foreach (glob("plugin/*.php") as $filename) {
2022-09-21 15:15:00 +08:00
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');
2017-03-11 03:51:06 +08:00
$result = ORM::for_table('tbl_appconfig')->find_many();
2023-03-06 15:49:44 +08:00
foreach ($result as $value) {
$config[$value['setting']] = $value['value'];
2017-03-11 03:51:06 +08:00
}
date_default_timezone_set($config['timezone']);
2023-08-14 12:24:27 +08:00
$textExpired = $_notifmsg['expired'];
2023-03-06 15:49:44 +08:00
$d = ORM::for_table('tbl_user_recharges')->where('status', 'on')->find_many();
2017-03-11 03:51:06 +08:00
2022-09-21 15:15:00 +08:00
run_hook('cronjob'); #HOOK
2023-03-06 15:49:44 +08:00
foreach ($d as $ds) {
if ($ds['type'] == 'Hotspot') {
$date_now = strtotime(date("Y-m-d H:i:s"));
$expiration = strtotime($ds['expiration'] . ' ' . $ds['time']);
echo $ds['expiration'] . " : " . $ds['username'];
if ($date_now >= $expiration) {
echo " : EXPIRED \r\n";
$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();
$m = ORM::for_table('tbl_routers')->where('name', $ds['routers'])->find_one();
if (!$_c['radius_mode']) {
2022-09-18 01:52:39 +08:00
$client = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']);
2023-03-06 15:49:44 +08:00
Mikrotik::setHotspotLimitUptime($client, $c['username']);
Mikrotik::removeHotspotActiveUser($client, $c['username']);
2023-08-14 15:15:15 +08:00
Message::sendPackageNotification($c['phonenumber'], $c['fullname'], $u['namebp'], $textExpired, $config['user_notification_expired']);
2022-09-07 17:11:35 +08:00
}
2023-03-06 15:49:44 +08:00
//update database user dengan status off
$u->status = 'off';
$u->save();
} else echo " : ACTIVE \r\n";
} else {
$date_now = strtotime(date("Y-m-d H:i:s"));
$expiration = strtotime($ds['expiration'] . ' ' . $ds['time']);
echo $ds['expiration'] . " : " . $ds['username'];
if ($date_now >= $expiration) {
echo " : EXPIRED \r\n";
$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();
$m = ORM::for_table('tbl_routers')->where('name', $ds['routers'])->find_one();
if (!$_c['radius_mode']) {
2022-09-18 01:52:39 +08:00
$client = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']);
2023-03-06 15:49:44 +08:00
Mikrotik::disablePpoeUser($client, $c['username']);
Mikrotik::removePpoeActive($client, $c['username']);
2023-08-14 15:15:15 +08:00
Message::sendPackageNotification($c['phonenumber'], $c['fullname'], $u['namebp'], $textExpired, $config['user_notification_expired']);
2022-09-07 17:11:35 +08:00
}
2022-04-23 02:13:17 +08:00
2023-03-06 15:49:44 +08:00
$u->status = 'off';
$u->save();
} else echo " : ACTIVE \r\n";
}
2017-03-11 03:51:06 +08:00
}