update acctOutputOctets for limiting data usage
This commit is contained in:
parent
8c00496a5b
commit
668c7af1e9
23
radius.php
23
radius.php
@ -156,7 +156,7 @@ try {
|
|||||||
if ($acctOutputOctets !== false && $acctInputOctets !== false) {
|
if ($acctOutputOctets !== false && $acctInputOctets !== false) {
|
||||||
$d->acctOutputOctets += $acctOutputOctets;
|
$d->acctOutputOctets += $acctOutputOctets;
|
||||||
$d->acctInputOctets += $acctInputOctets;
|
$d->acctInputOctets += $acctInputOctets;
|
||||||
}else{
|
} else {
|
||||||
$d->acctOutputOctets = 0;
|
$d->acctOutputOctets = 0;
|
||||||
$d->acctInputOctets = 0;
|
$d->acctInputOctets = 0;
|
||||||
}
|
}
|
||||||
@ -172,6 +172,18 @@ try {
|
|||||||
$d->macaddr = _post('macAddr');
|
$d->macaddr = _post('macAddr');
|
||||||
$d->dateAdded = date('Y-m-d H:i:s');
|
$d->dateAdded = date('Y-m-d H:i:s');
|
||||||
$d->save();
|
$d->save();
|
||||||
|
if($d->acctstatustype == 'Start'){
|
||||||
|
$tur = ORM::for_table('tbl_user_recharges')->where('username', $username)->where('status', 'on')->where('routers', 'radius')->find_one();
|
||||||
|
$plan = ORM::for_table('tbl_plans')->where('id', $tur['plan_id'])->find_one();
|
||||||
|
if ($plan['limit_type'] == "Data_Limit" || $plan['limit_type'] == "Both_Limit") {
|
||||||
|
$totalUsage = $d['acctOutputOctets'] + $d['acctInputOctets'];
|
||||||
|
$attrs['reply:Mikrotik-Total-Limit'] = Text::convertDataUnit($plan['data_limit'], $plan['data_unit']) - $totalUsage;
|
||||||
|
if ($attrs['reply:Mikrotik-Total-Limit'] < 0) {
|
||||||
|
$attrs['reply:Mikrotik-Total-Limit'] = 0;
|
||||||
|
show_radius_result(["control:Auth-Type" => "Accept", 'Reply-Message' => 'You have exceeded your data limit.'], 401);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
show_radius_result([
|
show_radius_result([
|
||||||
"control:Auth-Type" => "Accept",
|
"control:Auth-Type" => "Accept",
|
||||||
"reply:Reply-Message" => 'Saved'
|
"reply:Reply-Message" => 'Saved'
|
||||||
@ -239,6 +251,15 @@ function process_radiust_rest($tur, $code)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($plan['typebp'] == "Limited") {
|
if ($plan['typebp'] == "Limited") {
|
||||||
|
if ($plan['limit_type'] == "Data_Limit" || $plan['limit_type'] == "Both_Limit") {
|
||||||
|
$raddact = ORM::for_table('rad_acct')->where('username', $tur['username'])->find_one();
|
||||||
|
$totalUsage = $raddact['acctOutputOctets'] + $raddact['acctInputOctets'];
|
||||||
|
$attrs['reply:Mikrotik-Total-Limit'] = Text::convertDataUnit($plan['data_limit'], $plan['data_unit']) - $totalUsage;
|
||||||
|
if ($attrs['reply:Mikrotik-Total-Limit'] < 0) {
|
||||||
|
$attrs['reply:Mikrotik-Total-Limit'] = 0;
|
||||||
|
show_radius_result(["control:Auth-Type" => "Accept", 'Reply-Message' => 'You have exceeded your data limit.'], 401);
|
||||||
|
}
|
||||||
|
}
|
||||||
if ($plan['limit_type'] == "Time_Limit") {
|
if ($plan['limit_type'] == "Time_Limit") {
|
||||||
if ($plan['time_unit'] == 'Hrs')
|
if ($plan['time_unit'] == 'Hrs')
|
||||||
$timelimit = $plan['time_limit'] * 60 * 60;
|
$timelimit = $plan['time_limit'] * 60 * 60;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user