Fix is_radius
This commit is contained in:
parent
087c5ab515
commit
b2a99def98
@ -6,8 +6,7 @@ class Mikrotik
|
||||
{
|
||||
public static function info($name)
|
||||
{
|
||||
$d = ORM::for_table('tbl_routers')->where('name', $name)->find_one();
|
||||
return $d;
|
||||
return ORM::for_table('tbl_routers')->where('name', $name)->find_one();
|
||||
}
|
||||
|
||||
public static function getClient($ip, $user, $pass)
|
||||
|
@ -138,8 +138,14 @@ class Radius
|
||||
public static function planDelete($plan_id){
|
||||
// Delete Plan
|
||||
Radius::getTablePackage()->where_equal('plan_id', "plan_".$plan_id)->delete_many();
|
||||
// Delete User Plan
|
||||
Radius::getTableUserPackage()->where_equal('groupname', "plan_".$plan_id)->delete_many();
|
||||
// Reset User Plan
|
||||
$c = Radius::getTableUserPackage()->where_equal('groupname', "plan_".$plan_id)->findMany();
|
||||
if ($c) {
|
||||
foreach($c as $u){
|
||||
$u->groupname = '';
|
||||
$u->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function customerChangeUsername($from, $to){
|
||||
@ -159,13 +165,13 @@ class Radius
|
||||
}
|
||||
}
|
||||
|
||||
public static function customerDeactivate($customer){
|
||||
public static function customerDeactivate($username){
|
||||
global $radius_pass;
|
||||
$r = Radius::getTableCustomer()->where_equal('username', $customer['username'])->whereEqual('attribute', 'Cleartext-Password')->findOne();
|
||||
$r = Radius::getTableCustomer()->where_equal('username', $username)->whereEqual('attribute', 'Cleartext-Password')->findOne();
|
||||
if($r){
|
||||
// no need to delete, because it will make ID got higher
|
||||
// we just change the password
|
||||
$r->value = md5(time().$customer['username'].$radius_pass);
|
||||
$r->value = md5(time().$username.$radius_pass);
|
||||
$r->save();
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ switch ($action) {
|
||||
if ($p) {
|
||||
if ($p['is_radius']) {
|
||||
//TODO: disconnect using radius
|
||||
Radius::customerDeactivate(ORM::for_table('tbl_customers')->find_one($id_customer));
|
||||
Radius::customerDeactivate($b['username']);
|
||||
} else {
|
||||
$mikrotik = Mikrotik::info($b['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
|
@ -137,7 +137,7 @@ switch ($action) {
|
||||
|
||||
$mikrotik = Mikrotik::info($routers);
|
||||
if ($msg == '') {
|
||||
if (!$config['radius_enable']) {
|
||||
if ($routers != 'radius') {
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::setPool($client, $d['pool_name'], $ip_address);
|
||||
}
|
||||
|
@ -161,27 +161,26 @@ switch ($action) {
|
||||
|
||||
case 'delete':
|
||||
$id = $routes['2'];
|
||||
|
||||
$d = ORM::for_table('tbl_user_recharges')->find_one($id);
|
||||
$mikrotik = Mikrotik::info($d['routers']);
|
||||
if ($d) {
|
||||
run_hook('delete_customer_active_plan'); #HOOK
|
||||
if ($d['type'] == 'Hotspot') {
|
||||
if (!$config['radius_enable']) {
|
||||
$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']);
|
||||
if ($d['type'] == 'Hotspot') {
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removeHotspotUser($client, $d['username']);
|
||||
Mikrotik::removeHotspotActiveUser($client, $d['username']);
|
||||
}
|
||||
|
||||
$d->delete();
|
||||
} else {
|
||||
if (!$config['radius_enable']) {
|
||||
} else {
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removePpoeUser($client, $d['username']);
|
||||
Mikrotik::removePpoeActive($client, $d['username']);
|
||||
}
|
||||
$d->delete();
|
||||
}
|
||||
$d->delete();
|
||||
_log('[' . $admin['username'] . ']: ' . 'Delete Plan for Customer ' . $c['username'] . ' [' . $in['plan_name'] . '][' . Lang::moneyFormat($in['price']) . ']', 'Admin', $admin['id']);
|
||||
r2(U . 'prepaid/list', 's', $_L['Delete_Successfully']);
|
||||
}
|
||||
|
@ -135,7 +135,9 @@ switch ($action) {
|
||||
$d = ORM::for_table('tbl_plans')->find_one($id);
|
||||
if ($d) {
|
||||
run_hook('delete_plan'); #HOOK
|
||||
if (!$config['radius_enable']) {
|
||||
if ($d['is_radius']) {
|
||||
Radius::planDelete($d['id']);
|
||||
}else{
|
||||
$mikrotik = Mikrotik::info($d['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removeHotspotPlan($client, $d['name_plan']);
|
||||
@ -232,7 +234,7 @@ switch ($action) {
|
||||
$d->save();
|
||||
$plan_id = $d->id();
|
||||
|
||||
if ($config['radius_enable']) {
|
||||
if ($d['is_radius']) {
|
||||
Radius::planAdd($plan_id, $radiusRate);
|
||||
} else {
|
||||
$mikrotik = Mikrotik::info($routers);
|
||||
@ -303,7 +305,7 @@ switch ($action) {
|
||||
$rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown;
|
||||
$radiusRate = $b['rate_up'] . $radup . '/' . $b['rate_down'] . $raddown;
|
||||
|
||||
if ($config['radius_enable']) {
|
||||
if ($d['is_radius']) {
|
||||
Radius::planUpdate($id, $radiusRate);
|
||||
} else {
|
||||
$mikrotik = Mikrotik::info($routers);
|
||||
@ -376,7 +378,7 @@ switch ($action) {
|
||||
$b = ORM::for_table('tbl_bandwidth')->find_many();
|
||||
$ui->assign('b', $b);
|
||||
$r = [];
|
||||
if (($d['is_radius'])) {
|
||||
if ($d['is_radius']) {
|
||||
$r = ORM::for_table('tbl_routers')->find_many();
|
||||
}
|
||||
$ui->assign('r', $r);
|
||||
@ -393,7 +395,9 @@ switch ($action) {
|
||||
$d = ORM::for_table('tbl_plans')->find_one($id);
|
||||
if ($d) {
|
||||
run_hook('delete_ppoe'); #HOOK
|
||||
if (!$config['radius_enable']) {
|
||||
if ($d['is_radius']) {
|
||||
Radius::planDelete($d['id']);
|
||||
}else{
|
||||
$mikrotik = Mikrotik::info($d['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removePpoePlan($client, $d['name_plan']);
|
||||
@ -476,7 +480,7 @@ switch ($action) {
|
||||
$d->save();
|
||||
$plan_id = $d->id();
|
||||
|
||||
if ($config['radius_enable']) {
|
||||
if ($d['is_radius']) {
|
||||
Radius::planAdd($plan_id, $radiusRate, $pool);
|
||||
} else {
|
||||
$mikrotik = Mikrotik::info($routers);
|
||||
@ -541,7 +545,7 @@ switch ($action) {
|
||||
$rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown;
|
||||
$radiusRate = $b['rate_up'] . $radup . '/' . $b['rate_down'] . $raddown;
|
||||
|
||||
if ($config['radius_enable']) {
|
||||
if ($d['is_radius']) {
|
||||
Radius::planUpdate($id, $radiusRate, $pool);
|
||||
} else {
|
||||
$mikrotik = Mikrotik::info($routers);
|
||||
|
@ -100,9 +100,8 @@ foreach ($d as $ds) {
|
||||
$m = ORM::for_table('tbl_routers')->where('name', $ds['routers'])->find_one();
|
||||
$p = ORM::for_table('tbl_plans')->where('id', $u['plan_id'])->find_one();
|
||||
|
||||
if ($_c['radius_enable']) {
|
||||
//TODO: disconnect using radius
|
||||
Radius::customerDeactivate($c);
|
||||
if ($p['is_radius']) {
|
||||
Radius::customerDeactivate($c['username']);
|
||||
}else{
|
||||
$client = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']);
|
||||
if (!empty($p['pool_expired'])) {
|
||||
@ -150,9 +149,9 @@ foreach ($d as $ds) {
|
||||
$m = ORM::for_table('tbl_routers')->where('name', $ds['routers'])->find_one();
|
||||
$p = ORM::for_table('tbl_plans')->where('id', $u['plan_id'])->find_one();
|
||||
|
||||
if ($_c['radius_enable']) {
|
||||
if ($p['is_radius']) {
|
||||
//TODO: disconnect using radius
|
||||
Radius::customerDeactivate($c);
|
||||
Radius::customerDeactivate($c['username']);
|
||||
}else{
|
||||
$client = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']);
|
||||
if (!empty($p['pool_expired'])) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user