Disconnect radius user
This commit is contained in:
parent
113d4ce6b1
commit
0b7408f5b9
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Radius Class
|
* Radius Class
|
||||||
* based https://gist.github.com/nasirhafeez/6669b24aab0bda545f60f9da5ed14f25
|
* based https://gist.github.com/nasirhafeez/6669b24aab0bda545f60f9da5ed14f25
|
||||||
@ -6,6 +7,12 @@
|
|||||||
class Radius
|
class Radius
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public static function getClient()
|
||||||
|
{
|
||||||
|
global $config;
|
||||||
|
return (empty($config['radius_client'])) ? shell_exec('which radclient') : $config['radius_client'];
|
||||||
|
}
|
||||||
|
|
||||||
public static function getTableNas()
|
public static function getTableNas()
|
||||||
{
|
{
|
||||||
return ORM::for_table('nas', 'radius');
|
return ORM::for_table('nas', 'radius');
|
||||||
@ -123,6 +130,7 @@ class Radius
|
|||||||
// we just change the password
|
// we just change the password
|
||||||
$r->value = md5(time() . $username . $radius_pass);
|
$r->value = md5(time() . $username . $radius_pass);
|
||||||
$r->save();
|
$r->save();
|
||||||
|
Radius::disconnectCustomer($username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,7 +170,7 @@ class Radius
|
|||||||
$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);
|
||||||
} 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;
|
||||||
@ -172,17 +180,17 @@ class Radius
|
|||||||
$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'], 'Expire-After', $timelimit);
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
Radius::getTableCustomer()->where_equal('username', $customer['username'])->whereEqual('attribute', 'Max-Volume')->delete();
|
Radius::getTableCustomer()->where_equal('username', $customer['username'])->whereEqual('attribute', 'Max-Volume')->delete();
|
||||||
Radius::getTableCustomer()->where_equal('username', $customer['username'])->whereEqual('attribute', 'Expire-After')->delete();
|
Radius::getTableCustomer()->where_equal('username', $customer['username'])->whereEqual('attribute', 'Expire-After')->delete();
|
||||||
}
|
}
|
||||||
// expired user
|
// expired user
|
||||||
if($expired!=null){
|
if ($expired != null) {
|
||||||
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)));
|
||||||
}else{
|
} else {
|
||||||
Radius::getTableCustomer()->where_equal('username', $customer['username'])->whereEqual('attribute', 'expiration')->delete();
|
Radius::getTableCustomer()->where_equal('username', $customer['username'])->whereEqual('attribute', 'expiration')->delete();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -233,4 +241,17 @@ class Radius
|
|||||||
$r->value = $value;
|
$r->value = $value;
|
||||||
return $r->save();
|
return $r->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function disconnectCustomer($username){
|
||||||
|
$nas = Radius::getTableNas()->findMany();
|
||||||
|
$count = count($nas)*15;
|
||||||
|
set_time_limit($count);
|
||||||
|
foreach ($nas as $n){
|
||||||
|
$port = 3799;
|
||||||
|
if(!empty($n['ports'])){
|
||||||
|
$port = $n['ports'];
|
||||||
|
}
|
||||||
|
shell_exec("echo 'User-Name = $username' | ".Radius::getClient()." ".trim($n['nasname']).":$port disconnect '".$n['secret']."'");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,6 @@ switch ($action) {
|
|||||||
$p = ORM::for_table('tbl_plans')->where('id', $b['plan_id'])->where('enabled', '1')->find_one();
|
$p = ORM::for_table('tbl_plans')->where('id', $b['plan_id'])->where('enabled', '1')->find_one();
|
||||||
if ($p) {
|
if ($p) {
|
||||||
if ($p['is_radius']) {
|
if ($p['is_radius']) {
|
||||||
//TODO: disconnect using radius
|
|
||||||
Radius::customerDeactivate($b['username']);
|
Radius::customerDeactivate($b['username']);
|
||||||
} else {
|
} else {
|
||||||
$mikrotik = Mikrotik::info($b['routers']);
|
$mikrotik = Mikrotik::info($b['routers']);
|
||||||
|
@ -166,7 +166,6 @@ switch ($action) {
|
|||||||
run_hook('delete_customer_active_plan'); #HOOK
|
run_hook('delete_customer_active_plan'); #HOOK
|
||||||
$p = ORM::for_table('tbl_plans')->find_one($d['plan_id']);
|
$p = ORM::for_table('tbl_plans')->find_one($d['plan_id']);
|
||||||
if ($p['is_radius']) {
|
if ($p['is_radius']) {
|
||||||
//TODO: disconnect using radius
|
|
||||||
Radius::customerDeactivate($d['username']);
|
Radius::customerDeactivate($d['username']);
|
||||||
} else {
|
} else {
|
||||||
$mikrotik = Mikrotik::info($d['routers']);
|
$mikrotik = Mikrotik::info($d['routers']);
|
||||||
|
@ -25,7 +25,7 @@ switch ($action) {
|
|||||||
$ui->assign('logo', $logo);
|
$ui->assign('logo', $logo);
|
||||||
if(empty($_c['radius_client'])){
|
if(empty($_c['radius_client'])){
|
||||||
try{
|
try{
|
||||||
$_c['radius_client'] = shell_exec('which radclient');
|
$_c['radius_client'] = Radius::getClient();
|
||||||
$ui->assign('_c', $_c);
|
$ui->assign('_c', $_c);
|
||||||
}catch(Exception $e){
|
}catch(Exception $e){
|
||||||
//ignore
|
//ignore
|
||||||
|
@ -150,7 +150,6 @@ foreach ($d as $ds) {
|
|||||||
$p = ORM::for_table('tbl_plans')->where('id', $u['plan_id'])->find_one();
|
$p = ORM::for_table('tbl_plans')->where('id', $u['plan_id'])->find_one();
|
||||||
|
|
||||||
if ($p['is_radius']) {
|
if ($p['is_radius']) {
|
||||||
//TODO: disconnect using radius
|
|
||||||
Radius::customerDeactivate($c['username']);
|
Radius::customerDeactivate($c['username']);
|
||||||
}else{
|
}else{
|
||||||
$client = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']);
|
$client = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user