Fix radius rest for shared user online, check user online by count Start status.
This commit is contained in:
parent
f7cb6c196f
commit
695b3c7a6f
File diff suppressed because one or more lines are too long
68
radius.php
68
radius.php
@ -42,7 +42,7 @@ try {
|
|||||||
$CHAPchallenge = _req('CHAPchallenge');
|
$CHAPchallenge = _req('CHAPchallenge');
|
||||||
$isCHAP = false;
|
$isCHAP = false;
|
||||||
if (!empty($CHAPassword)) {
|
if (!empty($CHAPassword)) {
|
||||||
$c = ORM::for_table('tbl_customers')->select('password')->select('pppoe_password')->whereRaw("BINARY `username` = '$username'")->find_one();
|
$c = ORM::for_table('tbl_customers')->select('password')->select('pppoe_password')->whereRaw("BINARY username = '$username'")->find_one();
|
||||||
if ($c) {
|
if ($c) {
|
||||||
if (Password::chap_verify($c['password'], $CHAPassword, $CHAPchallenge)) {
|
if (Password::chap_verify($c['password'], $CHAPassword, $CHAPchallenge)) {
|
||||||
$password = $c['password'];
|
$password = $c['password'];
|
||||||
@ -111,7 +111,7 @@ try {
|
|||||||
$username = Text::alphanumeric($username, "-_.,");
|
$username = Text::alphanumeric($username, "-_.,");
|
||||||
$d = ORM::for_table('tbl_voucher')->whereRaw("BINARY `code` = '$username'")->find_one();
|
$d = ORM::for_table('tbl_voucher')->whereRaw("BINARY `code` = '$username'")->find_one();
|
||||||
} else {
|
} else {
|
||||||
$d = ORM::for_table('tbl_customers')->whereRaw("BINARY `username` = '$username'")->find_one();
|
$d = ORM::for_table('tbl_customers')->whereRaw("BINARY username = '$username'")->find_one();
|
||||||
if ($d['password'] != $password) {
|
if ($d['password'] != $password) {
|
||||||
if ($d['pppoe_password'] != $password) {
|
if ($d['pppoe_password'] != $password) {
|
||||||
unset($d);
|
unset($d);
|
||||||
@ -136,7 +136,7 @@ try {
|
|||||||
$CHAPchallenge = _req('CHAPchallenge');
|
$CHAPchallenge = _req('CHAPchallenge');
|
||||||
$isCHAP = false;
|
$isCHAP = false;
|
||||||
if (!empty($CHAPassword)) {
|
if (!empty($CHAPassword)) {
|
||||||
$c = ORM::for_table('tbl_customers')->select('password')->select('pppoe_password')->whereRaw("BINARY `username` = '$username'")->find_one();
|
$c = ORM::for_table('tbl_customers')->select('password')->select('pppoe_password')->whereRaw("BINARY username = '$username'")->find_one();
|
||||||
if ($c) {
|
if ($c) {
|
||||||
if (Password::chap_verify($c['password'], $CHAPassword, $CHAPchallenge)) {
|
if (Password::chap_verify($c['password'], $CHAPassword, $CHAPchallenge)) {
|
||||||
$password = $c['password'];
|
$password = $c['password'];
|
||||||
@ -201,10 +201,10 @@ try {
|
|||||||
], 401);
|
], 401);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$tur = ORM::for_table('tbl_user_recharges')->whereRaw("BINARY `username` = '$username'")->find_one();
|
$tur = ORM::for_table('tbl_user_recharges')->whereRaw("BINARY username = '$username'")->find_one();
|
||||||
if ($tur) {
|
if ($tur) {
|
||||||
if (!$isVoucher && !$isCHAP) {
|
if (!$isVoucher && !$isCHAP) {
|
||||||
$d = ORM::for_table('tbl_customers')->select('password')->select('pppoe_password')->whereRaw("BINARY `username` = '$username'")->find_one();
|
$d = ORM::for_table('tbl_customers')->select('password')->select('pppoe_password')->whereRaw("BINARY username = '$username'")->find_one();
|
||||||
if ($d) {
|
if ($d) {
|
||||||
if ($d['password'] != $password) {
|
if ($d['password'] != $password) {
|
||||||
if ($d['pppoe_password'] != $password) {
|
if ($d['pppoe_password'] != $password) {
|
||||||
@ -233,7 +233,7 @@ try {
|
|||||||
$v->status = "1";
|
$v->status = "1";
|
||||||
$v->used_date = date('Y-m-d H:i:s');
|
$v->used_date = date('Y-m-d H:i:s');
|
||||||
$v->save();
|
$v->save();
|
||||||
$tur = ORM::for_table('tbl_user_recharges')->whereRaw("BINARY `username` = '$username'")->find_one();
|
$tur = ORM::for_table('tbl_user_recharges')->whereRaw("BINARY username = '$username'")->find_one();
|
||||||
if ($tur) {
|
if ($tur) {
|
||||||
process_radiust_rest($tur, $code);
|
process_radiust_rest($tur, $code);
|
||||||
} else {
|
} else {
|
||||||
@ -264,54 +264,22 @@ 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'")
|
->whereRaw("BINARY username = '$username'")
|
||||||
->where('acctstatustype', _post('acctStatusType'))
|
->where('acctsessionid', _post('acctsessionid'))
|
||||||
->findOne();
|
->findOne();
|
||||||
if (!$d) {
|
if (!$d) {
|
||||||
$d = ORM::for_table('rad_acct')->create();
|
$d = ORM::for_table('rad_acct')->create();
|
||||||
}
|
}
|
||||||
$acctOutputOctets = _post('acctOutputOctets', 0);
|
$acctOutputOctets = _post('acctOutputOctets', 0);
|
||||||
$acctInputOctets = _post('acctInputOctets', 0);
|
$acctInputOctets = _post('acctInputOctets', 0);
|
||||||
if (_post('acctStatusType') == 'Stop') {
|
if ($acctOutputOctets !== false && $acctInputOctets !== false) {
|
||||||
// log in the Start only
|
$d->acctOutputOctets += intval($acctOutputOctets);
|
||||||
$start = ORM::for_table('rad_acct')
|
$d->acctInputOctets += intval($acctInputOctets);
|
||||||
->whereRaw("BINARY `username` = '$username'")
|
} else {
|
||||||
->where('acctstatustype', 'Start')
|
|
||||||
->findOne();
|
|
||||||
if (!$start) {
|
|
||||||
$start = ORM::for_table('rad_acct')->create();
|
|
||||||
}
|
|
||||||
if ($acctOutputOctets !== false && $acctInputOctets !== false) {
|
|
||||||
$start->acctOutputOctets += intval($acctOutputOctets);
|
|
||||||
$start->acctInputOctets += intval($acctInputOctets);
|
|
||||||
} else {
|
|
||||||
$start->acctOutputOctets = 0;
|
|
||||||
$start->acctInputOctets = 0;
|
|
||||||
}
|
|
||||||
$start->acctsessionid = _post('acctSessionId');
|
|
||||||
$start->username = $username;
|
|
||||||
$start->realm = _post('realm');
|
|
||||||
$start->nasipaddress = _post('nasip');
|
|
||||||
$start->nasid = _post('nasid');
|
|
||||||
$start->nasportid = _post('nasPortId');
|
|
||||||
$start->nasporttype = _post('nasPortType');
|
|
||||||
$start->framedipaddress = _post('framedIPAddress');
|
|
||||||
$start->acctstatustype = _post('acctStatusType');
|
|
||||||
$start->macaddr = _post('macAddr');
|
|
||||||
$start->dateAdded = date('Y-m-d H:i:s');
|
|
||||||
$start->save();
|
|
||||||
$d->acctOutputOctets = 0;
|
$d->acctOutputOctets = 0;
|
||||||
$d->acctInputOctets = 0;
|
$d->acctInputOctets = 0;
|
||||||
} else {
|
|
||||||
if ($acctOutputOctets !== false && $acctInputOctets !== false) {
|
|
||||||
$d->acctOutputOctets += intval($acctOutputOctets);
|
|
||||||
$d->acctInputOctets += intval($acctInputOctets);
|
|
||||||
} else {
|
|
||||||
$d->acctOutputOctets = 0;
|
|
||||||
$d->acctInputOctets = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$d->acctsessionid = _post('acctSessionId');
|
$d->acctSessionId = _post('acctSessionId');
|
||||||
$d->username = $username;
|
$d->username = $username;
|
||||||
$d->realm = _post('realm');
|
$d->realm = _post('realm');
|
||||||
$d->nasipaddress = _post('nasip');
|
$d->nasipaddress = _post('nasip');
|
||||||
@ -324,7 +292,7 @@ try {
|
|||||||
$d->dateAdded = date('Y-m-d H:i:s');
|
$d->dateAdded = date('Y-m-d H:i:s');
|
||||||
$d->save();
|
$d->save();
|
||||||
if (_post('acctStatusType') == 'Start') {
|
if (_post('acctStatusType') == 'Start') {
|
||||||
$tur = ORM::for_table('tbl_user_recharges')->whereRaw("BINARY `username` = '$username'")->where('status', 'on')->where('routers', 'radius')->find_one();
|
$tur = ORM::for_table('tbl_user_recharges')->whereRaw("BINARY username = '$username'")->where('status', 'on')->where('routers', 'radius')->find_one();
|
||||||
$plan = ORM::for_table('tbl_plans')->where('id', $tur['plan_id'])->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") {
|
if ($plan['limit_type'] == "Data_Limit" || $plan['limit_type'] == "Both_Limit") {
|
||||||
$totalUsage = $d['acctOutputOctets'] + $d['acctInputOctets'];
|
$totalUsage = $d['acctOutputOctets'] + $d['acctInputOctets'];
|
||||||
@ -364,7 +332,11 @@ function process_radiust_rest($tur, $code)
|
|||||||
global $config;
|
global $config;
|
||||||
$plan = ORM::for_table('tbl_plans')->where('id', $tur['plan_id'])->find_one();
|
$plan = ORM::for_table('tbl_plans')->where('id', $tur['plan_id'])->find_one();
|
||||||
$bw = ORM::for_table("tbl_bandwidth")->find_one($plan['id_bw']);
|
$bw = ORM::for_table("tbl_bandwidth")->find_one($plan['id_bw']);
|
||||||
$USRon = ORM::for_table('radacct')->where('username', $tur['username'])->where_raw("acctstoptime IS NULL")->count();
|
// Count User Onlines
|
||||||
|
$USRon = ORM::for_table('rad_acct')
|
||||||
|
->where('username', $tur['username'])
|
||||||
|
->where("acctStatusType", 'Start')
|
||||||
|
->count();
|
||||||
if ($USRon >= $plan['shared_users'] && $plan['type'] == 'Hotspot') {
|
if ($USRon >= $plan['shared_users'] && $plan['type'] == 'Hotspot') {
|
||||||
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);
|
||||||
}
|
}
|
||||||
@ -407,7 +379,7 @@ 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") {
|
if ($plan['limit_type'] == "Data_Limit" || $plan['limit_type'] == "Both_Limit") {
|
||||||
$raddact = ORM::for_table('rad_acct')->whereRaw("BINARY `username` = '$tur[username]'")->where('acctstatustype', 'Start')->find_one();
|
$raddact = ORM::for_table('rad_acct')->whereRaw("BINARY username = '$tur[username]'")->where('acctstatustype', 'Start')->find_one();
|
||||||
$totalUsage = intval($raddact['acctOutputOctets']) + intval($raddact['acctInputOctets']);
|
$totalUsage = intval($raddact['acctOutputOctets']) + intval($raddact['acctInputOctets']);
|
||||||
$attrs['reply:Mikrotik-Total-Limit'] = Text::convertDataUnit($plan['data_limit'], $plan['data_unit']) - $totalUsage;
|
$attrs['reply:Mikrotik-Total-Limit'] = Text::convertDataUnit($plan['data_limit'], $plan['data_unit']) - $totalUsage;
|
||||||
if ($attrs['reply:Mikrotik-Total-Limit'] < 0) {
|
if ($attrs['reply:Mikrotik-Total-Limit'] < 0) {
|
||||||
|
@ -725,5 +725,10 @@
|
|||||||
"Customer_will_reply_email_to_this_address__empty_if_you_want_to_use_From_Address": "Customer will reply email to this address, empty if you want to use From Address",
|
"Customer_will_reply_email_to_this_address__empty_if_you_want_to_use_From_Address": "Customer will reply email to this address, empty if you want to use From Address",
|
||||||
"You_will_get_Payment_and_Error_notification": "You will get Payment and Error notification",
|
"You_will_get_Payment_and_Error_notification": "You will get Payment and Error notification",
|
||||||
"Languge_set_to_english": "Bahasa diatur ke bahasa Inggris",
|
"Languge_set_to_english": "Bahasa diatur ke bahasa Inggris",
|
||||||
"Forgot_Password": "Forgot Password"
|
"Forgot_Password": "Forgot Password",
|
||||||
|
"_Are_You_Sure_": "Are You Sure?",
|
||||||
|
"Send_your_balance___": "Send your balance ?",
|
||||||
|
"Search_Users": "Search Users",
|
||||||
|
"Theme_Voucher": "Theme Voucher",
|
||||||
|
"Payment_Info": "Payment Info"
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user