From 78cbb105aa90c1a219642691f95bbe198260c6c7 Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Wed, 4 Oct 2023 11:37:32 +0700 Subject: [PATCH] PPPOE Radius Plan --- system/autoload/Radius.php | 32 +++-- system/controllers/services.php | 83 ++++++++---- ui/ui/autoload-pool.tpl | 2 +- ui/ui/hotspot-add.tpl | 46 ++++--- ui/ui/hotspot-edit.tpl | 35 ++--- ui/ui/pppoe-add.tpl | 233 +++++++++++++++++++------------- ui/ui/pppoe-edit.tpl | 221 +++++++++++++++++------------- ui/ui/pppoe.tpl | 9 +- 8 files changed, 389 insertions(+), 272 deletions(-) diff --git a/system/autoload/Radius.php b/system/autoload/Radius.php index f90f2e13..29e0c0a6 100644 --- a/system/autoload/Radius.php +++ b/system/autoload/Radius.php @@ -105,25 +105,31 @@ class Radius public static function planUpdate($plan_id, $plan_name, $rate, $pool = null) { $rates = explode('/', $rate); - $r = Radius::getTablePackage()->where_equal('plan_id', $plan_id)->whereEqual('attribute', 'Ascend-Data-Rate')->findOne(); - $r->groupname = $plan_name; - $r->value = $rates[1]; - if ($r->save()) { - $r = Radius::getTablePackage()->where_equal('plan_id', $plan_id)->whereEqual('attribute', 'Ascend-Xmit-Rate')->findOne(); + if(Radius::getTablePackage()->where_equal('plan_id', $plan_id)->find_one()){ + $r = Radius::getTablePackage()->where_equal('plan_id', $plan_id)->whereEqual('attribute', 'Ascend-Data-Rate')->findOne(); $r->groupname = $plan_name; - $r->value = $rates[0]; + $r->value = $rates[1]; if ($r->save()) { - if ($pool != null) { - $r = Radius::getTablePackage()->where_equal('plan_id', $plan_id)->whereEqual('attribute', 'Framed-Pool')->findOne(); - $r->groupname = $plan_name; - $r->value = $pool; - if ($r->save()) { + $r = Radius::getTablePackage()->where_equal('plan_id', $plan_id)->whereEqual('attribute', 'Ascend-Xmit-Rate')->findOne(); + $r->groupname = $plan_name; + $r->value = $rates[0]; + if ($r->save()) { + if ($pool != null) { + $r = Radius::getTablePackage()->where_equal('plan_id', $plan_id)->whereEqual('attribute', 'Framed-Pool')->findOne(); + $r->groupname = $plan_name; + $r->value = $pool; + if ($r->save()) { + return true; + } + } else { return true; } - } else { - return true; } } + }else{ + if(!empty($plan_id)){ + return Radius::planAdd($plan_id, $plan_name, $rate, $pool); + } } return false; } diff --git a/system/controllers/services.php b/system/controllers/services.php index 16a0faec..3b8f4879 100644 --- a/system/controllers/services.php +++ b/system/controllers/services.php @@ -28,9 +28,8 @@ switch ($action) { $log = ''; $router = ''; foreach ($plans as $plan) { - if($plan['is_radius']){ - - }else{ + if ($plan['is_radius']) { + } else { if ($router != $plan['routers']) { $mikrotik = Mikrotik::info($plan['routers']); $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); @@ -56,7 +55,7 @@ switch ($action) { } } r2(U . 'services/hotspot', 's', $log); - }else if ($routes['2'] == 'pppoe') { + } else if ($routes['2'] == 'pppoe') { $plans = ORM::for_table('tbl_bandwidth')->join('tbl_plans', array('tbl_bandwidth.id', '=', 'tbl_plans.id_bw'))->where('tbl_plans.type', 'PPPOE')->where('tbl_plans.enabled', '1')->find_many(); $log = ''; $router = ''; @@ -176,7 +175,7 @@ switch ($action) { if ($name == '' or $id_bw == '' or $price == '' or $validity == '') { $msg .= $_L['All_field_is_required'] . '
'; } - if(empty($radius)){ + if (empty($radius)) { if ($routers == '') { $msg .= $_L['All_field_is_required'] . '
'; } @@ -205,7 +204,7 @@ switch ($action) { $radup = '000000'; } $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; $d = ORM::for_table('tbl_plans')->create(); $d->name_plan = $name; @@ -221,10 +220,10 @@ switch ($action) { $d->validity = $validity; $d->validity_unit = $validity_unit; $d->shared_users = $sharedusers; - if(!empty($radius)){ + if (!empty($radius)) { $d->is_radius = 1; $d->routers = ''; - }else{ + } else { $d->is_radius = 0; $d->routers = $routers; $d->pool_expired = $pool_expired; @@ -235,7 +234,7 @@ switch ($action) { if ($config['radius_enable']) { Radius::planAdd($plan_id, $name, $radiusRate); - }else{ + } else { $mikrotik = Mikrotik::info($routers); $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::addHotspotPlan($client, $name, $sharedusers, $rate); @@ -302,11 +301,11 @@ switch ($action) { $radup = '000000'; } $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']) { Radius::planUpdate($id, $name, $radiusRate); - }else{ + } else { $mikrotik = Mikrotik::info($routers); $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::setHotspotPlan($client, $name, $sharedusers, $rate); @@ -372,11 +371,14 @@ switch ($action) { $d = ORM::for_table('tbl_plans')->find_one($id); if ($d) { $ui->assign('d', $d); - $p = ORM::for_table('tbl_pool')->where('routers', $d['routers'])->find_many(); + $p = ORM::for_table('tbl_pool')->where('routers', ($d['is_radius']) ? 'radius' : $d['routers'])->find_many(); $ui->assign('p', $p); $b = ORM::for_table('tbl_bandwidth')->find_many(); $ui->assign('b', $b); - $r = ORM::for_table('tbl_routers')->find_many(); + $r = []; + if (($d['is_radius'])) { + $r = ORM::for_table('tbl_routers')->find_many(); + } $ui->assign('r', $r); run_hook('view_edit_ppoe'); #HOOK $ui->display('pppoe-edit.tpl'); @@ -404,6 +406,7 @@ switch ($action) { case 'pppoe-add-post': $name = _post('name_plan'); + $radius = _post('radius'); $id_bw = _post('id_bw'); $price = _post('price'); $validity = _post('validity'); @@ -420,9 +423,14 @@ switch ($action) { if (Validator::UnsignedNumber($price) == false) { $msg .= 'The price must be a number' . '
'; } - if ($name == '' or $id_bw == '' or $price == '' or $validity == '' or $routers == '' or $pool == '') { + if ($name == '' or $id_bw == '' or $price == '' or $validity == '' or $pool == '') { $msg .= $_L['All_field_is_required'] . '
'; } + if (empty($radius)) { + if ($routers == '') { + $msg .= $_L['All_field_is_required'] . '
'; + } + } $d = ORM::for_table('tbl_plans')->where('name_plan', $name)->find_one(); if ($d) { @@ -433,24 +441,20 @@ switch ($action) { $b = ORM::for_table('tbl_bandwidth')->where('id', $id_bw)->find_one(); if ($b['rate_down_unit'] == 'Kbps') { $unitdown = 'K'; + $raddown = '000'; } else { $unitdown = 'M'; + $raddown = '000000'; } if ($b['rate_up_unit'] == 'Kbps') { $unitup = 'K'; + $radup = '000'; } else { $unitup = 'M'; + $radup = '000000'; } $rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown; - - if (!$config['radius_enable']) { - $mikrotik = Mikrotik::info($routers); - $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); - Mikrotik::addPpoePlan($client, $name, $pool, $rate); - if (!empty($pool_expired)) { - Mikrotik::setPpoePlan($client, 'EXPIRED NUXBILL ' . $pool_expired, $pool_expired, '512K/512K'); - } - } + $radiusRate = $b['rate_up'] . $radup . '/' . $b['rate_down'] . $raddown; $d = ORM::for_table('tbl_plans')->create(); $d->type = 'PPPOE'; @@ -459,11 +463,29 @@ switch ($action) { $d->price = $price; $d->validity = $validity; $d->validity_unit = $validity_unit; - $d->routers = $routers; $d->pool = $pool; - $d->pool_expired = $pool_expired; + if (!empty($radius)) { + $d->is_radius = 1; + $d->routers = ''; + } else { + $d->is_radius = 0; + $d->routers = $routers; + $d->pool_expired = $pool_expired; + } $d->enabled = $enabled; $d->save(); + $plan_id = $d->id(); + + if ($config['radius_enable']) { + Radius::planAdd($plan_id, $name, $radiusRate, $pool); + } else { + $mikrotik = Mikrotik::info($routers); + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + Mikrotik::addPpoePlan($client, $name, $pool, $rate); + if (!empty($pool_expired)) { + Mikrotik::setPpoePlan($client, 'EXPIRED NUXBILL ' . $pool_expired, $pool_expired, '512K/512K'); + } + } r2(U . 'services/pppoe', 's', $_L['Created_Successfully']); } else { @@ -490,7 +512,7 @@ switch ($action) { if (Validator::UnsignedNumber($price) == false) { $msg .= 'The price must be a number' . '
'; } - if ($name == '' or $id_bw == '' or $price == '' or $validity == '' or $routers == '' or $pool == '') { + if ($name == '' or $id_bw == '' or $price == '' or $validity == '' or $pool == '') { $msg .= $_L['All_field_is_required'] . '
'; } @@ -504,17 +526,24 @@ switch ($action) { $b = ORM::for_table('tbl_bandwidth')->where('id', $id_bw)->find_one(); if ($b['rate_down_unit'] == 'Kbps') { $unitdown = 'K'; + $raddown = '000'; } else { $unitdown = 'M'; + $raddown = '000000'; } if ($b['rate_up_unit'] == 'Kbps') { $unitup = 'K'; + $radup = '000'; } else { $unitup = 'M'; + $radup = '000000'; } $rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown; + $radiusRate = $b['rate_up'] . $radup . '/' . $b['rate_down'] . $raddown; - if (!$config['radius_enable']) { + if ($config['radius_enable']) { + Radius::planUpdate($id, $name, $radiusRate, $pool); + } else { $mikrotik = Mikrotik::info($routers); $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::setPpoePlan($client, $name, $pool, $rate); diff --git a/ui/ui/autoload-pool.tpl b/ui/ui/autoload-pool.tpl index c4f825de..09ce2de7 100644 --- a/ui/ui/autoload-pool.tpl +++ b/ui/ui/autoload-pool.tpl @@ -1,4 +1,4 @@ {foreach $d as $ds} - + {/foreach} \ No newline at end of file diff --git a/ui/ui/hotspot-add.tpl b/ui/ui/hotspot-add.tpl index 4cfe1686..ff031758 100644 --- a/ui/ui/hotspot-add.tpl +++ b/ui/ui/hotspot-add.tpl @@ -20,11 +20,12 @@ {if $_c['radius_enable']}
-
+
+

{Lang::T('Cannot be change after saved')}

{/if}
@@ -164,26 +165,27 @@
- -{literal} - -{/literal} +{if $_c['radius_enable']} + {literal} + + {/literal} +{/if} {include file="sections/footer.tpl"} \ No newline at end of file diff --git a/ui/ui/hotspot-edit.tpl b/ui/ui/hotspot-edit.tpl index b25151df..a0d9f669 100644 --- a/ui/ui/hotspot-edit.tpl +++ b/ui/ui/hotspot-edit.tpl @@ -39,8 +39,9 @@
{$_L['Unlimited']} - {$_L['Limited']} + + {$_L['Limited']}
-{literal} - -{/literal} + + {/literal} +{/if} {include file="sections/footer.tpl"} \ No newline at end of file diff --git a/ui/ui/pppoe-add.tpl b/ui/ui/pppoe-add.tpl index f3c0716b..32e045da 100644 --- a/ui/ui/pppoe-add.tpl +++ b/ui/ui/pppoe-add.tpl @@ -1,100 +1,139 @@ {include file="sections/header.tpl"} -
-
-
-
{$_L['Add_Plan']}
-
-
-
- -
- - -
+
+
+
+
{$_L['Add_Plan']}
+
+ +
+ +
+ + +
+
+ {if $_c['radius_enable']} +
+ +
+
-
- -
- -
-
-
- -
- -
-
-
- -
-
- {$_c['currency_code']} - -
-
-
-
- -
- -
-
- -
-
-
- -
- -

{Lang::T('Cannot be change after saved')}

-
-
-
- -
- -
-
-
- -
- -
-
-
-
- - Or {$_L['Cancel']} -
-
- -
-
-
-
- -{include file="sections/footer.tpl"} +

{Lang::T('Cannot be change after saved')}

+
+ {/if} +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ {$_c['currency_code']} + +
+
+
+
+ +
+ +
+
+ +
+
+
+ +
+ +

{Lang::T('Cannot be change after saved')}

+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ + Or {$_L['Cancel']} +
+
+ +
+
+
+
+{if $_c['radius_enable']} + {literal} + + {/literal} +{/if} +{include file="sections/footer.tpl"} \ No newline at end of file diff --git a/ui/ui/pppoe-edit.tpl b/ui/ui/pppoe-edit.tpl index 10958805..b963c964 100644 --- a/ui/ui/pppoe-edit.tpl +++ b/ui/ui/pppoe-edit.tpl @@ -1,100 +1,131 @@ {include file="sections/header.tpl"} -
-
-
-
{$_L['Edit_Plan']}
-
-
- -
- -
- - -
+
+
+
+
{$_L['Edit_Plan']}
+
+ + +
+ +
+ + +
+
+ {if $_c['radius_enable'] and $d['is_radius']} +
+ +
+
-
- -
- -
-
-
- -
- -
-
-
- -
-
- {$_c['currency_code']} - -
-
-
-
- -
- -
-
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
+
+ {/if} +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ {$_c['currency_code']} + +
+
+
+
+ +
+ +
+
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
-
-
- - Or {$_L['Cancel']} -
-
- -
-
-
-
+
+
+ + Or {$_L['Cancel']} +
+
+ +
+
+
+
-{include file="sections/footer.tpl"} +{if $_c['radius_enable'] and $d['is_radius']} + {literal} + + {/literal} +{/if} +{include file="sections/footer.tpl"} \ No newline at end of file diff --git a/ui/ui/pppoe.tpl b/ui/ui/pppoe.tpl index e6e34d79..5fe10771 100644 --- a/ui/ui/pppoe.tpl +++ b/ui/ui/pppoe.tpl @@ -54,7 +54,14 @@ {$ds['validity']} {$ds['validity_unit']} {$ds['pool']} {$ds['pool_expired']} - {$ds['routers']} + + {if $ds['is_radius']} + RADIUS + {else} + {if $ds['routers']!=''} + {$ds['routers']} + {/if} + {/if} {$_L['Edit']}