phpnuxbill/system/cron.php

99 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
2024-02-19 15:24:34 +08:00
include "../init.php";
$isCli = (php_sapi_name() !== 'cli') ? false : true;
if (!$isCli) {
2023-09-07 10:35:00 +08:00
echo "<pre>";
}
2023-09-07 10:35:00 +08:00
echo "PHP Time\t" . date('Y-m-d H:i:s') . "\n";
$res = ORM::raw_execute('SELECT NOW() AS WAKTU;');
$statement = ORM::get_last_statement();
$rows = [];
2023-09-07 10:35:00 +08:00
while ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
echo "MYSQL Time\t" . $row['WAKTU'] . "\n";
}
2023-08-24 12:35:23 +08:00
$textExpired = Lang::getNotifText('expired');
2023-03-06 15:49:44 +08:00
$recharges = ORM::for_table('tbl_user_recharges')
->where('status', 'on')
->where_lte('expiration', date("Y-m-d"))
->find_many();
2022-09-21 15:15:00 +08:00
echo "Found " . count($recharges) . " user(s)\n";
run_hook('cronjob'); // HOOK
2023-08-15 11:17:28 +08:00
foreach ($recharges as $recharge) {
$dateNow = strtotime(date("Y-m-d H:i:s"));
$expiration = strtotime($recharge['expiration'] . ' ' . $recharge['time']);
echo $recharge['expiration'] . " : " . (($isCli) ? $recharge['username'] : Lang::maskText($recharge['username']));
if ($dateNow >= $expiration) {
echo " : EXPIRED \r\n";
2024-04-16 14:53:29 +08:00
$user_recharge = ORM::for_table('tbl_user_recharges')->where('id', $recharge['id'])->find_one();
$customer = ORM::for_table('tbl_customers')->where('id', $recharge['customer_id'])->find_one();
2024-04-16 14:53:29 +08:00
$plan = ORM::for_table('tbl_plans')->where('id', $user_recharge['plan_id'])->find_one();
$router = ($recharge['type'] == 'Hotspot') ? Mikrotik::info($recharge['routers']) : ORM::for_table('tbl_routers')->where('name', $recharge['routers'])->find_one();
if ($plan['is_radius']) {
if (empty($plan['pool_expired'])) {
print_r(Radius::customerDeactivate($customer['username']));
2023-09-01 14:40:26 +08:00
} else {
Radius::upsertCustomerAttr($customer['username'], 'Framed-Pool', $plan['pool_expired'], ':=');
print_r(Radius::disconnectCustomer($customer['username']));
2023-08-15 11:17:28 +08:00
}
} else {
$client = Mikrotik::getClient($router['ip_address'], $router['username'], $router['password']);
if (!empty($plan['pool_expired'])) {
if ($recharge['type'] == 'Hotspot') {
Mikrotik::setHotspotUserPackage($client, $customer['username'], 'EXPIRED NUXBILL ' . $plan['pool_expired']);
2023-10-16 11:15:45 +08:00
} else {
Mikrotik::setPpoeUserPlan($client, $customer['username'], 'EXPIRED NUXBILL ' . $plan['pool_expired']);
2023-10-16 11:15:45 +08:00
}
} else {
if ($recharge['type'] == 'Hotspot') {
Mikrotik::removeHotspotUser($client, $customer['username']);
Mikrotik::removeHotspotActiveUser($client, $customer['username']);
2023-10-04 16:07:38 +08:00
} else {
Mikrotik::removePpoeUser($client, $customer['username']);
Mikrotik::removePpoeActive($client, $customer['username']);
}
2022-09-07 17:11:35 +08:00
}
}
2022-04-23 02:13:17 +08:00
2024-04-16 14:53:29 +08:00
echo Message::sendPackageNotification($customer, $user_recharge['namebp'], $plan['price'], $textExpired, $config['user_notification_expired']) . "\n";
2023-08-15 11:17:28 +08:00
2024-04-16 14:53:29 +08:00
$user_recharge->status = 'off';
$user_recharge->save();
if ($config['enable_balance'] == 'yes' && $customer['auto_renewal']) {
list($bills, $add_cost) = User::getBills($recharge['customer_id']);
if ($add_cost > 0) {
$plan['price'] += $add_cost;
}
if ($plan && $plan['enabled'] && $customer['balance'] >= $plan['price']) {
if (Package::rechargeUser($recharge['customer_id'], $plan['routers'], $plan['id'], 'Customer', 'Balance')) {
Balance::min($recharge['customer_id'], $plan['price']);
echo "Plan enabled: $plan[enabled] | User balance: $customer[balance] | Price: $plan[price]\n";
echo "Autorenewal Success\n";
} else {
echo "Plan enabled: $plan[enabled] | User balance: $customer[balance] | Price: $plan[price]\n";
echo "Autorenewal Failed\n";
Message::sendTelegram("FAILED RENEWAL #cron\n\n#u$customer[username] #buy #" . (($recharge['type'] == 'Hotspot') ? 'Hotspot' : 'PPPOE') . " \n" . $plan['name_plan'] .
"\nRouter: " . $plan['routers'] .
"\nPrice: " . $plan['price']);
2023-08-15 11:17:28 +08:00
}
} else {
echo "No renewal | Plan enabled: $plan[enabled] | User balance: $customer[balance] | Price: $plan[price]\n";
2023-08-15 11:17:28 +08:00
}
} else {
echo "No renewal | Balance: $config[enable_balance] Auto-renewal: $customer[auto_renewal]\n";
}
} else {
echo " : ACTIVE \r\n";
2023-03-06 15:49:44 +08:00
}
}