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