add expired notification

This commit is contained in:
Ibnu Maksum 2023-03-06 14:49:44 +07:00
parent 3130310d9c
commit b10cfa2a8e
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5

View File

@ -1,7 +1,8 @@
<?php <?php
/** /**
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/) * PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
**/ **/
require('../config.php'); require('../config.php');
require('orm.php'); require('orm.php');
@ -19,8 +20,7 @@ include "autoload/Hookers.php";
//register all plugin //register all plugin
foreach (glob("system/plugin/*.php") as $filename) foreach (glob("system/plugin/*.php") as $filename) {
{
include $filename; include $filename;
} }
@ -50,54 +50,57 @@ function _autoloader($class)
spl_autoload_register('_autoloader'); spl_autoload_register('_autoloader');
$result = ORM::for_table('tbl_appconfig')->find_many(); $result = ORM::for_table('tbl_appconfig')->find_many();
foreach($result as $value){ foreach ($result as $value) {
$config[$value['setting']]=$value['value']; $config[$value['setting']] = $value['value'];
} }
date_default_timezone_set($config['timezone']); date_default_timezone_set($config['timezone']);
$d = ORM::for_table('tbl_user_recharges')->where('status','on')->find_many(); $textExpired = $config['user_notification_expired_text'];
$d = ORM::for_table('tbl_user_recharges')->where('status', 'on')->find_many();
run_hook('cronjob'); #HOOK run_hook('cronjob'); #HOOK
foreach ($d as $ds){ foreach ($d as $ds) {
if($ds['type'] == 'Hotspot'){ if ($ds['type'] == 'Hotspot') {
$date_now = strtotime(date("Y-m-d H:i:s")); $date_now = strtotime(date("Y-m-d H:i:s"));
$expiration = strtotime($ds['expiration'].' '.$ds['time']); $expiration = strtotime($ds['expiration'] . ' ' . $ds['time']);
echo $ds['expiration']." : ".$ds['username']; echo $ds['expiration'] . " : " . $ds['username'];
if ($date_now >= $expiration){ if ($date_now >= $expiration) {
echo " : EXPIRED \r\n"; echo " : EXPIRED \r\n";
$u = ORM::for_table('tbl_user_recharges')->where('id',$ds['id'])->find_one(); $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(); $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(); $m = ORM::for_table('tbl_routers')->where('name', $ds['routers'])->find_one();
if(!$_c['radius_mode']){ if (!$_c['radius_mode']) {
$client = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']); $client = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']);
Mikrotik::setHotspotLimitUptime($client,$c['username']); Mikrotik::setHotspotLimitUptime($client, $c['username']);
Mikrotik::removeHotspotActiveUser($client,$c['username']); Mikrotik::removeHotspotActiveUser($client, $c['username']);
Message::sendExpiredNotification($c['phonenumber'], $c['fullname'], $u['namebp'], $textExpired, $config['user_notification_expired']);
}
//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']) {
$client = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']);
Mikrotik::disablePpoeUser($client, $c['username']);
Mikrotik::removePpoeActive($client, $c['username']);
Message::sendExpiredNotification($c['phonenumber'], $c['fullname'], $u['namebp'], $textExpired, $config['user_notification_expired']);
} }
//update database user dengan status off $u->status = 'off';
$u->status = 'off'; $u->save();
$u->save(); } else echo " : ACTIVE \r\n";
}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']){
$client = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']);
Mikrotik::disablePpoeUser($client,$c['username']);
Mikrotik::removePpoeActive($client,$c['username']);
}
$u->status = 'off';
$u->save();
}else echo " : ACTIVE \r\n";
}
} }