diff --git a/system/autoload/Radius.php b/system/autoload/Radius.php index 11862658..7b2d278c 100644 --- a/system/autoload/Radius.php +++ b/system/autoload/Radius.php @@ -1,4 +1,5 @@ value = md5(time() . $username . $radius_pass); $r->save(); + Radius::disconnectCustomer($username); } } @@ -162,7 +170,7 @@ class Radius $datalimit = $plan['data_limit'] . "000000000"; else $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") { if ($plan['time_unit'] == 'Hrs') $timelimit = $plan['time_limit'] * 60 * 60; @@ -172,17 +180,17 @@ class Radius $datalimit = $plan['data_limit'] . "000000000"; else $datalimit = $plan['data_limit'] . "000000"; - Radius::upsertCustomer($customer['username'], 'Max-Volume', $datalimit); - Radius::upsertCustomer($customer['username'], 'Expire-After', $timelimit); + 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']."'"); + } + } } diff --git a/system/controllers/customers.php b/system/controllers/customers.php index 013b620a..fe965f67 100644 --- a/system/controllers/customers.php +++ b/system/controllers/customers.php @@ -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']); diff --git a/system/controllers/prepaid.php b/system/controllers/prepaid.php index 9944b2bf..b6094d1d 100644 --- a/system/controllers/prepaid.php +++ b/system/controllers/prepaid.php @@ -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']); diff --git a/system/controllers/settings.php b/system/controllers/settings.php index eb6ce970..74e99df3 100644 --- a/system/controllers/settings.php +++ b/system/controllers/settings.php @@ -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 diff --git a/system/cron.php b/system/cron.php index f173bcbd..a1435385 100644 --- a/system/cron.php +++ b/system/cron.php @@ -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']);