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