forked from kevinowino869/mitrobill
Update Radius.php
Fix radius plan base *uptime limit *burst bw profile limit *data limit *user can't login after recharge radius plan base please add this variable in "mods-available/sqlcounter" for freeradius installation wiki sqlcounter uptimelimit { counter_name = 'Max-All-Session-Time' check_name = 'Max-All-Session' sql_module_instance = sql key = 'User-Name' reset = never query = "SELECT SUM(AcctSessionTime) FROM radacct WHERE UserName='%{${key}}'" } and this variable in "sites-enabled/default" authorize { expiration quotalimit accessperiod uptimelimit }
This commit is contained in:
parent
3c2ca66b48
commit
f766393e52
@ -30,7 +30,10 @@ class Radius
|
|||||||
{
|
{
|
||||||
return ORM::for_table('nas', 'radius');
|
return ORM::for_table('nas', 'radius');
|
||||||
}
|
}
|
||||||
|
public static function getTableAcct()
|
||||||
|
{
|
||||||
|
return ORM::for_table('radacct', 'radius');
|
||||||
|
}
|
||||||
public static function getTableCustomer()
|
public static function getTableCustomer()
|
||||||
{
|
{
|
||||||
return ORM::for_table('radcheck', 'radius');
|
return ORM::for_table('radcheck', 'radius');
|
||||||
@ -88,9 +91,16 @@ class Radius
|
|||||||
public static function planUpSert($plan_id, $rate, $pool = null)
|
public static function planUpSert($plan_id, $rate, $pool = null)
|
||||||
{
|
{
|
||||||
$rates = explode('/', $rate);
|
$rates = explode('/', $rate);
|
||||||
|
##burst fixed
|
||||||
|
if (str_contains($rate, ' ')) {
|
||||||
|
$ratos = $rates[0].'/'.$rates[1].' '.$rates[2].'/'.$rates[3].'/'.$rates[4].'/'.$rates[5].'/'.$rates[6];
|
||||||
|
} else {
|
||||||
|
$ratos = $rates[0].'/'.$rates[1];
|
||||||
|
}
|
||||||
|
|
||||||
Radius::upsertPackage($plan_id, 'Ascend-Data-Rate', $rates[1], ':=');
|
Radius::upsertPackage($plan_id, 'Ascend-Data-Rate', $rates[1], ':=');
|
||||||
Radius::upsertPackage($plan_id, 'Ascend-Xmit-Rate', $rates[0], ':=');
|
Radius::upsertPackage($plan_id, 'Ascend-Xmit-Rate', $rates[0], ':=');
|
||||||
Radius::upsertPackage($plan_id, 'Mikrotik-Rate-Limit', $rate, ':=');
|
Radius::upsertPackage($plan_id, 'Mikrotik-Rate-Limit', $ratos, ':=');
|
||||||
// if ($pool != null) {
|
// if ($pool != null) {
|
||||||
// Radius::upsertPackage($plan_id, 'Framed-Pool', $pool, ':=');
|
// Radius::upsertPackage($plan_id, 'Framed-Pool', $pool, ':=');
|
||||||
// }
|
// }
|
||||||
@ -161,6 +171,8 @@ class Radius
|
|||||||
$p = Radius::getTableUserPackage()->where_equal('username', $customer['username'])->findOne();
|
$p = Radius::getTableUserPackage()->where_equal('username', $customer['username'])->findOne();
|
||||||
if ($p) {
|
if ($p) {
|
||||||
// if exists
|
// if exists
|
||||||
|
Radius::delAtribute(Radius::getTableCustomer(), 'Max-All-Session', 'username', $customer['username']);
|
||||||
|
Radius::delAtribute(Radius::getTableCustomer(), 'Max-Data', 'username', $customer['username']);
|
||||||
$p->groupname = "plan_" . $plan['id'];
|
$p->groupname = "plan_" . $plan['id'];
|
||||||
$p->save();
|
$p->save();
|
||||||
} else {
|
} else {
|
||||||
@ -176,7 +188,7 @@ class Radius
|
|||||||
$timelimit = $plan['time_limit'] * 60 * 60;
|
$timelimit = $plan['time_limit'] * 60 * 60;
|
||||||
else
|
else
|
||||||
$timelimit = $plan['time_limit'] * 60;
|
$timelimit = $plan['time_limit'] * 60;
|
||||||
Radius::upsertCustomer($customer['username'], 'Expire-After', $timelimit);
|
Radius::upsertCustomer($customer['username'], 'Max-All-Session', $timelimit);
|
||||||
} else if ($plan['limit_type'] == "Data_Limit") {
|
} else if ($plan['limit_type'] == "Data_Limit") {
|
||||||
if ($plan['data_unit'] == 'GB')
|
if ($plan['data_unit'] == 'GB')
|
||||||
$datalimit = $plan['data_limit'] . "000000000";
|
$datalimit = $plan['data_limit'] . "000000000";
|
||||||
@ -184,29 +196,40 @@ class Radius
|
|||||||
$datalimit = $plan['data_limit'] . "000000";
|
$datalimit = $plan['data_limit'] . "000000";
|
||||||
//Radius::upsertCustomer($customer['username'], 'Max-Volume', $datalimit);
|
//Radius::upsertCustomer($customer['username'], 'Max-Volume', $datalimit);
|
||||||
// Mikrotik Spesific
|
// Mikrotik Spesific
|
||||||
Radius::upsertCustomer($customer['username'], 'Mikrotik-Total-Limit', $datalimit);
|
Radius::upsertCustomer($customer['username'], 'Max-Data', $datalimit);
|
||||||
} else if ($plan['limit_type'] == "Both_Limit") {
|
} else if ($plan['limit_type'] == "Both_Limit") {
|
||||||
if ($plan['time_unit'] == 'Hrs')
|
if ($plan['time_unit'] == 'Hrs')
|
||||||
$timelimit = $plan['time_limit'] * 60 * 60;
|
$timelimit = $plan['time_limit'] * 60 * 60;
|
||||||
else
|
else
|
||||||
$timelimit = $plan['time_limit'] . ":00";
|
$timelimit = $plan['time_limit'] * 60;
|
||||||
if ($plan['data_unit'] == 'GB')
|
if ($plan['data_unit'] == 'GB')
|
||||||
$datalimit = $plan['data_limit'] . "000000000";
|
$datalimit = $plan['data_limit'] . "000000000";
|
||||||
else
|
else
|
||||||
$datalimit = $plan['data_limit'] . "000000";
|
$datalimit = $plan['data_limit'] . "000000";
|
||||||
//Radius::upsertCustomer($customer['username'], 'Max-Volume', $datalimit);
|
//Radius::upsertCustomer($customer['username'], 'Max-Volume', $datalimit);
|
||||||
Radius::upsertCustomer($customer['username'], 'Expire-After', $timelimit);
|
Radius::upsertCustomer($customer['username'], 'Max-All-Session', $timelimit);
|
||||||
// Mikrotik Spesific
|
// Mikrotik Spesific
|
||||||
Radius::upsertCustomer($customer['username'], 'Mikrotik-Total-Limit', $datalimit);
|
Radius::upsertCustomer($customer['username'], 'Max-Data', $datalimit);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//Radius::delAtribute(Radius::getTableCustomer(), 'Max-Volume', 'username', $customer['username']);
|
//Radius::delAtribute(Radius::getTableCustomer(), 'Max-Volume', 'username', $customer['username']);
|
||||||
Radius::delAtribute(Radius::getTableCustomer(), 'Expire-After', 'username', $customer['username']);
|
Radius::delAtribute(Radius::getTableCustomer(), 'Max-All-Session', 'username', $customer['username']);
|
||||||
Radius::delAtribute(Radius::getTableCustomer(), 'Mikrotik-Total-Limit', 'username', $customer['username']);
|
Radius::delAtribute(Radius::getTableCustomer(), 'Max-Data', 'username', $customer['username']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Radius::disconnectCustomer($customer['username']);
|
||||||
|
Radius::getTableAcct()->where_equal('username', $customer['username'])->delete_many();
|
||||||
|
|
||||||
|
|
||||||
// expired user
|
// expired user
|
||||||
if ($expired != null) {
|
if ($expired != null) {
|
||||||
//Radius::upsertCustomer($customer['username'], 'access-period', strtotime($expired) - time());
|
//Radius::upsertCustomer($customer['username'], 'Max-All-Session', strtotime($expired) - time());
|
||||||
Radius::upsertCustomer($customer['username'], 'expiration', date('d M Y H:i:s', strtotime($expired)));
|
Radius::upsertCustomer($customer['username'], 'expiration', date('d M Y H:i:s', strtotime($expired)));
|
||||||
// Mikrotik Spesific
|
// Mikrotik Spesific
|
||||||
Radius::upsertCustomer(
|
Radius::upsertCustomer(
|
||||||
@ -215,13 +238,15 @@ class Radius
|
|||||||
date('Y-m-d', strtotime($expired)) . 'T' . date('H:i:s', strtotime($expired)) . Timezone::getTimeOffset($config['timezone'])
|
date('Y-m-d', strtotime($expired)) . 'T' . date('H:i:s', strtotime($expired)) . Timezone::getTimeOffset($config['timezone'])
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
//Radius::delAtribute(Radius::getTableCustomer(), 'access-period', 'username', $customer['username']);
|
//Radius::delAtribute(Radius::getTableCustomer(), 'Max-All-Session', 'username', $customer['username']);
|
||||||
Radius::delAtribute(Radius::getTableCustomer(), 'expiration', 'username', $customer['username']);
|
Radius::delAtribute(Radius::getTableCustomer(), 'expiration', 'username', $customer['username']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($plan['type'] == 'PPPOE') {
|
if ($plan['type'] == 'PPPOE') {
|
||||||
Radius::upsertCustomerAttr($customer['username'], 'Framed-Pool', $plan['pool'], ':=');
|
Radius::upsertCustomerAttr($customer['username'], 'Framed-Pool', $plan['pool'], ':=');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -267,7 +292,7 @@ class Radius
|
|||||||
/**
|
/**
|
||||||
* To insert or update existing customer
|
* To insert or update existing customer
|
||||||
*/
|
*/
|
||||||
private static function upsertCustomer($username, $attr, $value, $op = ':=')
|
public static function upsertCustomer($username, $attr, $value, $op = ':=')
|
||||||
{
|
{
|
||||||
$r = Radius::getTableCustomer()->where_equal('username', $username)->whereEqual('attribute', $attr)->find_one();
|
$r = Radius::getTableCustomer()->where_equal('username', $username)->whereEqual('attribute', $attr)->find_one();
|
||||||
if (!$r) {
|
if (!$r) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user