by mac and nasid

This commit is contained in:
iBNu Maksum 2024-12-30 09:53:40 +07:00
parent 357b7932e9
commit b1e145f0dc
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5

View File

@ -274,7 +274,7 @@ try {
} }
header("HTTP/1.1 200 ok"); header("HTTP/1.1 200 ok");
$d = ORM::for_table('rad_acct') $d = ORM::for_table('rad_acct')
->whereRaw("BINARY username = '$username' AND acctsessionid = '"._post('acctSessionId')."'") ->whereRaw("BINARY username = '$username' AND macaddr = '"._post('macAddr')."' AND nasid = '"._post('nasid')."'")
->findOne(); ->findOne();
if (!$d) { if (!$d) {
$d = ORM::for_table('rad_acct')->create(); $d = ORM::for_table('rad_acct')->create();
@ -296,23 +296,24 @@ try {
$d->nasportid = _post('nasPortId'); $d->nasportid = _post('nasPortId');
$d->nasporttype = _post('nasPortType'); $d->nasporttype = _post('nasPortType');
$d->framedipaddress = _post('framedIPAddress'); $d->framedipaddress = _post('framedIPAddress');
if (_post('acctStatusType') == 'Start') { if(in_array(_post('acctStatusType'), ['Start', 'Stop'])){
$d->acctstatustype = 'Interim-Update'; $d->acctstatustype = _post('acctStatusType');
} else { }
$d->acctstatustype = _post('acctStatusType');
}
$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(); // pastikan data akunting yang disimpan memang customer aktif phpnuxbill
if (_post('acctStatusType') == 'Start') { $tur = ORM::for_table('tbl_user_recharges')->whereRaw("BINARY username = '$username' AND `status` = 'on' AND `routers` = 'radius'")->find_one();
$tur = ORM::for_table('tbl_user_recharges')->whereRaw("BINARY username = '$username' AND `status` = 'on' AND `routers` = 'radius'")->find_one(); if($tur){
$plan = ORM::for_table('tbl_plans')->where('id', $tur['plan_id'])->find_one(); $d->save();
if ($plan['limit_type'] == "Data_Limit" || $plan['limit_type'] == "Both_Limit") { if (_post('acctStatusType') == 'Start') {
$totalUsage = $d['acctOutputOctets'] + $d['acctInputOctets']; $plan = ORM::for_table('tbl_plans')->where('id', $tur['plan_id'])->find_one();
$attrs['reply:Mikrotik-Total-Limit'] = Text::convertDataUnit($plan['data_limit'], $plan['data_unit']) - $totalUsage; if ($plan['limit_type'] == "Data_Limit" || $plan['limit_type'] == "Both_Limit") {
if ($attrs['reply:Mikrotik-Total-Limit'] < 0) { $totalUsage = $d['acctOutputOctets'] + $d['acctInputOctets'];
$attrs['reply:Mikrotik-Total-Limit'] = 0; $attrs['reply:Mikrotik-Total-Limit'] = Text::convertDataUnit($plan['data_limit'], $plan['data_unit']) - $totalUsage;
show_radius_result(["control:Auth-Type" => "Accept", 'Reply-Message' => 'You have exceeded your data limit.'], 401); 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);
}
} }
} }
} }
@ -347,10 +348,12 @@ function process_radiust_rest($tur, $code)
$bw = ORM::for_table("tbl_bandwidth")->find_one($plan['id_bw']); $bw = ORM::for_table("tbl_bandwidth")->find_one($plan['id_bw']);
// Count User Onlines // Count User Onlines
$USRon = ORM::for_table('rad_acct') $USRon = ORM::for_table('rad_acct')
->whereRaw("BINARY username = '".$tur['username']."'") ->whereRaw("BINARY username = '".$tur['username']."' AND acctStatusType = 'Start'")
->where("acctStatusType", 'Interim-Update') ->find_array();
->count(); // get all the IP
if ($USRon >= $plan['shared_users'] && $plan['type'] == 'Hotspot') { $ips = array_column($USRon, 'framedipaddress');
// check if user reach shared_users limit but IP is not in the list active
if (count($USRon) >= $plan['shared_users'] && $plan['type'] == 'Hotspot' && !in_array(_post('framedIPAddress'), $ips)) {
show_radius_result(["control:Auth-Type" => "Accept", 'Reply-Message' => 'You are already logged in - access denied ('.$USRon.')'], 401); show_radius_result(["control:Auth-Type" => "Accept", 'Reply-Message' => 'You are already logged in - access denied ('.$USRon.')'], 401);
} }
if ($bw['rate_down_unit'] == 'Kbps') { if ($bw['rate_down_unit'] == 'Kbps') {