2017-03-11 03:51:06 +08:00
|
|
|
<?php
|
|
|
|
/**
|
2017-03-24 14:26:14 +08:00
|
|
|
* PHP Mikrotik Billing (https://ibnux.github.io/phpmixbill/)
|
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');
|
|
|
|
|
|
|
|
use PEAR2\Net\RouterOS;
|
|
|
|
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);
|
|
|
|
|
|
|
|
$result = ORM::for_table('tbl_appconfig')->find_many();
|
|
|
|
foreach($result as $value){
|
|
|
|
$config[$value['setting']]=$value['value'];
|
|
|
|
}
|
|
|
|
date_default_timezone_set($config['timezone']);
|
|
|
|
|
|
|
|
$d = ORM::for_table('tbl_user_recharges')->where('status','on')->find_many();
|
|
|
|
|
|
|
|
foreach ($d as $ds){
|
|
|
|
if($ds['type'] == 'Hotspot'){
|
|
|
|
$date_now = strtotime(date("Y-m-d H:i:s"));
|
|
|
|
$expiration = strtotime($ds['expiration'].' '.$ds['time']);
|
2017-03-11 06:22:27 +08:00
|
|
|
echo $ds['expiration']." : ".$ds['username'];
|
2017-03-11 03:51:06 +08:00
|
|
|
if ($date_now >= $expiration){
|
2017-03-11 06:22:27 +08:00
|
|
|
echo " : EXPIRED \r\n";
|
2017-03-11 03:51:06 +08:00
|
|
|
$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();
|
2022-04-23 02:13:17 +08:00
|
|
|
|
2022-09-07 17:11:35 +08:00
|
|
|
if(!$_c['radius_mode']){
|
2022-09-18 01:52:39 +08:00
|
|
|
$client = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']);
|
|
|
|
Mikrotik::setHotspotLimitUptime($client,$c['username']);
|
|
|
|
Mikrotik::removeHotspotActiveUser($client,$c['username']);
|
2022-09-07 17:11:35 +08:00
|
|
|
}
|
2022-04-23 02:13:17 +08:00
|
|
|
|
2017-03-11 03:51:06 +08:00
|
|
|
//update database user dengan status off
|
|
|
|
$u->status = 'off';
|
|
|
|
$u->save();
|
2022-09-07 17:11:35 +08:00
|
|
|
}else echo " : ACTIVE \r\n";
|
2017-03-11 03:51:06 +08:00
|
|
|
}else{
|
|
|
|
$date_now = strtotime(date("Y-m-d H:i:s"));
|
|
|
|
$expiration = strtotime($ds['expiration'].' '.$ds['time']);
|
2017-03-11 06:22:27 +08:00
|
|
|
echo $ds['expiration']." : ".$ds['username'];
|
2017-03-11 03:51:06 +08:00
|
|
|
if ($date_now >= $expiration){
|
2017-03-11 06:22:27 +08:00
|
|
|
echo " : EXPIRED \r\n";
|
2017-03-11 03:51:06 +08:00
|
|
|
$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();
|
|
|
|
|
2022-09-07 17:11:35 +08:00
|
|
|
if(!$_c['radius_mode']){
|
2022-09-18 01:52:39 +08:00
|
|
|
$client = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']);
|
|
|
|
Mikrotik::disablePpoeUser($client,$c['username']);
|
|
|
|
Mikrotik::removePpoeActive($client,$c['username']);
|
2022-09-07 17:11:35 +08:00
|
|
|
}
|
2022-04-23 02:13:17 +08:00
|
|
|
|
2017-03-11 03:51:06 +08:00
|
|
|
$u->status = 'off';
|
|
|
|
$u->save();
|
2022-09-05 16:12:00 +08:00
|
|
|
}else echo " : ACTIVE \r\n";
|
2017-03-11 03:51:06 +08:00
|
|
|
}
|
|
|
|
}
|