PPPOE Radius Plan

This commit is contained in:
Ibnu Maksum 2023-10-04 11:37:32 +07:00
parent efc0ba93b6
commit 78cbb105aa
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
8 changed files with 389 additions and 272 deletions

View File

@ -105,6 +105,7 @@ class Radius
public static function planUpdate($plan_id, $plan_name, $rate, $pool = null) public static function planUpdate($plan_id, $plan_name, $rate, $pool = null)
{ {
$rates = explode('/', $rate); $rates = explode('/', $rate);
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 = Radius::getTablePackage()->where_equal('plan_id', $plan_id)->whereEqual('attribute', 'Ascend-Data-Rate')->findOne();
$r->groupname = $plan_name; $r->groupname = $plan_name;
$r->value = $rates[1]; $r->value = $rates[1];
@ -125,6 +126,11 @@ class Radius
} }
} }
} }
}else{
if(!empty($plan_id)){
return Radius::planAdd($plan_id, $plan_name, $rate, $pool);
}
}
return false; return false;
} }
} }

View File

@ -29,7 +29,6 @@ switch ($action) {
$router = ''; $router = '';
foreach ($plans as $plan) { foreach ($plans as $plan) {
if ($plan['is_radius']) { if ($plan['is_radius']) {
} else { } else {
if ($router != $plan['routers']) { if ($router != $plan['routers']) {
$mikrotik = Mikrotik::info($plan['routers']); $mikrotik = Mikrotik::info($plan['routers']);
@ -372,11 +371,14 @@ switch ($action) {
$d = ORM::for_table('tbl_plans')->find_one($id); $d = ORM::for_table('tbl_plans')->find_one($id);
if ($d) { if ($d) {
$ui->assign('d', $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); $ui->assign('p', $p);
$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 = [];
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);
run_hook('view_edit_ppoe'); #HOOK run_hook('view_edit_ppoe'); #HOOK
$ui->display('pppoe-edit.tpl'); $ui->display('pppoe-edit.tpl');
@ -404,6 +406,7 @@ switch ($action) {
case 'pppoe-add-post': case 'pppoe-add-post':
$name = _post('name_plan'); $name = _post('name_plan');
$radius = _post('radius');
$id_bw = _post('id_bw'); $id_bw = _post('id_bw');
$price = _post('price'); $price = _post('price');
$validity = _post('validity'); $validity = _post('validity');
@ -420,9 +423,14 @@ switch ($action) {
if (Validator::UnsignedNumber($price) == false) { if (Validator::UnsignedNumber($price) == false) {
$msg .= 'The price must be a number' . '<br>'; $msg .= 'The price must be a number' . '<br>';
} }
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'] . '<br>'; $msg .= $_L['All_field_is_required'] . '<br>';
} }
if (empty($radius)) {
if ($routers == '') {
$msg .= $_L['All_field_is_required'] . '<br>';
}
}
$d = ORM::for_table('tbl_plans')->where('name_plan', $name)->find_one(); $d = ORM::for_table('tbl_plans')->where('name_plan', $name)->find_one();
if ($d) { if ($d) {
@ -433,24 +441,20 @@ switch ($action) {
$b = ORM::for_table('tbl_bandwidth')->where('id', $id_bw)->find_one(); $b = ORM::for_table('tbl_bandwidth')->where('id', $id_bw)->find_one();
if ($b['rate_down_unit'] == 'Kbps') { if ($b['rate_down_unit'] == 'Kbps') {
$unitdown = 'K'; $unitdown = 'K';
$raddown = '000';
} else { } else {
$unitdown = 'M'; $unitdown = 'M';
$raddown = '000000';
} }
if ($b['rate_up_unit'] == 'Kbps') { if ($b['rate_up_unit'] == 'Kbps') {
$unitup = 'K'; $unitup = 'K';
$radup = '000';
} else { } else {
$unitup = 'M'; $unitup = 'M';
$radup = '000000';
} }
$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;
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');
}
}
$d = ORM::for_table('tbl_plans')->create(); $d = ORM::for_table('tbl_plans')->create();
$d->type = 'PPPOE'; $d->type = 'PPPOE';
@ -459,11 +463,29 @@ switch ($action) {
$d->price = $price; $d->price = $price;
$d->validity = $validity; $d->validity = $validity;
$d->validity_unit = $validity_unit; $d->validity_unit = $validity_unit;
$d->routers = $routers;
$d->pool = $pool; $d->pool = $pool;
if (!empty($radius)) {
$d->is_radius = 1;
$d->routers = '';
} else {
$d->is_radius = 0;
$d->routers = $routers;
$d->pool_expired = $pool_expired; $d->pool_expired = $pool_expired;
}
$d->enabled = $enabled; $d->enabled = $enabled;
$d->save(); $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']); r2(U . 'services/pppoe', 's', $_L['Created_Successfully']);
} else { } else {
@ -490,7 +512,7 @@ switch ($action) {
if (Validator::UnsignedNumber($price) == false) { if (Validator::UnsignedNumber($price) == false) {
$msg .= 'The price must be a number' . '<br>'; $msg .= 'The price must be a number' . '<br>';
} }
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'] . '<br>'; $msg .= $_L['All_field_is_required'] . '<br>';
} }
@ -504,17 +526,24 @@ switch ($action) {
$b = ORM::for_table('tbl_bandwidth')->where('id', $id_bw)->find_one(); $b = ORM::for_table('tbl_bandwidth')->where('id', $id_bw)->find_one();
if ($b['rate_down_unit'] == 'Kbps') { if ($b['rate_down_unit'] == 'Kbps') {
$unitdown = 'K'; $unitdown = 'K';
$raddown = '000';
} else { } else {
$unitdown = 'M'; $unitdown = 'M';
$raddown = '000000';
} }
if ($b['rate_up_unit'] == 'Kbps') { if ($b['rate_up_unit'] == 'Kbps') {
$unitup = 'K'; $unitup = 'K';
$radup = '000';
} else { } else {
$unitup = 'M'; $unitup = 'M';
$radup = '000000';
} }
$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;
if (!$config['radius_enable']) { if ($config['radius_enable']) {
Radius::planUpdate($id, $name, $radiusRate, $pool);
} else {
$mikrotik = Mikrotik::info($routers); $mikrotik = Mikrotik::info($routers);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::setPpoePlan($client, $name, $pool, $rate); Mikrotik::setPpoePlan($client, $name, $pool, $rate);

View File

@ -1,4 +1,4 @@
<option value=''>{$_L['Select_Pool']}</option> <option value=''>{$_L['Select_Pool']}</option>
{foreach $d as $ds} {foreach $d as $ds}
<option value="{$ds['pool_name']}">{$ds['pool_name']}</option> <option value="{$ds['pool_name']}">{$ds['pool_name']}{if $routers==''} - {$ds['routers']}{/if}</option>
{/foreach} {/foreach}

View File

@ -20,11 +20,12 @@
{if $_c['radius_enable']} {if $_c['radius_enable']}
<div class="form-group"> <div class="form-group">
<label class="col-md-2 control-label">Radius</label> <label class="col-md-2 control-label">Radius</label>
<div class="col-md-10"> <div class="col-md-6">
<label class="radio-inline"> <label class="radio-inline">
<input type="checkbox" name="radius" onclick="isRadius(this)" value="1"> Radius Plan <input type="checkbox" name="radius" onclick="isRadius(this)" value="1"> Radius Plan
</label> </label>
</div> </div>
<p class="help-block col-md-4">{Lang::T('Cannot be change after saved')}</p>
</div> </div>
{/if} {/if}
<div class="form-group"> <div class="form-group">
@ -164,7 +165,7 @@
</div> </div>
</div> </div>
</div> </div>
{if $_c['radius_enable']}
{literal} {literal}
<script> <script>
function isRadius(cek) { function isRadius(cek) {
@ -185,5 +186,6 @@
} }
</script> </script>
{/literal} {/literal}
{/if}
{include file="sections/footer.tpl"} {include file="sections/footer.tpl"}

View File

@ -39,8 +39,9 @@
<div class="col-md-10"> <div class="col-md-10">
<input type="radio" id="Unlimited" name="typebp" value="Unlimited" <input type="radio" id="Unlimited" name="typebp" value="Unlimited"
{if $d['typebp'] eq 'Unlimited'} checked {/if}> {$_L['Unlimited']} {if $d['typebp'] eq 'Unlimited'} checked {/if}> {$_L['Unlimited']}
<input type="radio" id="Limited" {if $_c['radius_enable'] and $d['is_radius']}disabled{/if} name="typebp" value="Limited" <input type="radio" id="Limited" {if $_c['radius_enable'] and $d['is_radius']}disabled{/if}
{if $d['typebp'] eq 'Limited'} checked {/if}> {$_L['Limited']} name="typebp" value="Limited" {if $d['typebp'] eq 'Limited'} checked {/if}>
{$_L['Limited']}
</div> </div>
</div> </div>
<div {if $d['typebp'] eq 'Unlimited'} style="display:none;" {/if} id="Type"> <div {if $d['typebp'] eq 'Unlimited'} style="display:none;" {/if} id="Type">
@ -176,6 +177,7 @@
</div> </div>
</div> </div>
{if $_c['radius_enable']}
{literal} {literal}
<script> <script>
function isRadius(cek) { function isRadius(cek) {
@ -191,4 +193,5 @@
} }
</script> </script>
{/literal} {/literal}
{/if}
{include file="sections/footer.tpl"} {include file="sections/footer.tpl"}

View File

@ -17,6 +17,17 @@
</label> </label>
</div> </div>
</div> </div>
{if $_c['radius_enable']}
<div class="form-group">
<label class="col-md-2 control-label">Radius</label>
<div class="col-md-6">
<label class="radio-inline">
<input type="checkbox" name="radius" onclick="isRadius(this)" value="1"> Radius Plan
</label>
</div>
<p class="help-block col-md-4">{Lang::T('Cannot be change after saved')}</p>
</div>
{/if}
<div class="form-group"> <div class="form-group">
<label class="col-md-2 control-label">{$_L['Plan_Name']}</label> <label class="col-md-2 control-label">{$_L['Plan_Name']}</label>
<div class="col-md-6"> <div class="col-md-6">
@ -24,7 +35,8 @@
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-md-2 control-label"><a href="{$_url}bandwidth/add">{$_L['BW_Name']}</a></label> <label class="col-md-2 control-label"><a
href="{$_url}bandwidth/add">{$_L['BW_Name']}</a></label>
<div class="col-md-6"> <div class="col-md-6">
<select id="id_bw" name="id_bw" class="form-control select2"> <select id="id_bw" name="id_bw" class="form-control select2">
<option value="">{$_L['Select_BW']}...</option> <option value="">{$_L['Select_BW']}...</option>
@ -58,7 +70,8 @@
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-md-2 control-label"><a href="{$_url}routers/add">{$_L['Router_Name']}</a></label> <label class="col-md-2 control-label"><a
href="{$_url}routers/add">{$_L['Router_Name']}</a></label>
<div class="col-md-6"> <div class="col-md-6">
<select id="routers" name="routers" required class="form-control select2"> <select id="routers" name="routers" required class="form-control select2">
<option value=''>{$_L['Select_Routers']}</option> <option value=''>{$_L['Select_Routers']}</option>
@ -78,7 +91,8 @@
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-md-2 control-label"><a href="{$_url}pool/add">{Lang::T('Expired IP Pool')}</a></label> <label class="col-md-2 control-label"><a
href="{$_url}pool/add">{Lang::T('Expired IP Pool')}</a></label>
<div class="col-md-6"> <div class="col-md-6">
<select id="pool_expired" name="pool_expired" class="form-control select2"> <select id="pool_expired" name="pool_expired" class="form-control select2">
<option value=''>{$_L['Select_Pool']}</option> <option value=''>{$_L['Select_Pool']}</option>
@ -87,7 +101,8 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<div class="col-md-offset-2 col-md-10"> <div class="col-md-offset-2 col-md-10">
<button class="btn btn-primary waves-effect waves-light" type="submit">{$_L['Save']}</button> <button class="btn btn-primary waves-effect waves-light"
type="submit">{$_L['Save']}</button>
Or <a href="{$_url}services/pppoe">{$_L['Cancel']}</a> Or <a href="{$_url}services/pppoe">{$_L['Cancel']}</a>
</div> </div>
</div> </div>
@ -96,5 +111,29 @@
</div> </div>
</div> </div>
</div> </div>
{if $_c['radius_enable']}
{literal}
<script>
function isRadius(cek) {
if (cek.checked) {
document.getElementById("routers").required = false;
document.getElementById("routers").disabled = true;
document.getElementById("pool_expired").disabled = true;
$.ajax({
url: "index.php?_route=autoload/pool",
data: "routers=radius",
cache: false,
success: function(msg) {
$("#pool_name").html(msg);
}
});
} else {
document.getElementById("routers").required = true;
document.getElementById("routers").disabled = false;
document.getElementById("pool_expired").disabled = false;
}
}
</script>
{/literal}
{/if}
{include file="sections/footer.tpl"} {include file="sections/footer.tpl"}

View File

@ -14,22 +14,34 @@
<input type="radio" {if $d['enabled'] == 1}checked{/if} name="enabled" value="1"> Enable <input type="radio" {if $d['enabled'] == 1}checked{/if} name="enabled" value="1"> Enable
</label> </label>
<label class="radio-inline"> <label class="radio-inline">
<input type="radio" {if $d['enabled'] == 0}checked{/if} name="enabled" value="0"> Disable <input type="radio" {if $d['enabled'] == 0}checked{/if} name="enabled" value="0">
Disable
</label> </label>
</div> </div>
</div> </div>
{if $_c['radius_enable'] and $d['is_radius']}
<div class="form-group">
<label class="col-md-2 control-label">Radius</label>
<div class="col-md-10">
<label class="label label-primary">RADIUS</label>
</div>
</div>
{/if}
<div class="form-group"> <div class="form-group">
<label class="col-md-2 control-label">{$_L['Plan_Name']}</label> <label class="col-md-2 control-label">{$_L['Plan_Name']}</label>
<div class="col-md-6"> <div class="col-md-6">
<input type="text" class="form-control" id="name_plan" maxlength="40" name="name_plan" value="{$d['name_plan']}"> <input type="text" class="form-control" id="name_plan" maxlength="40" name="name_plan"
value="{$d['name_plan']}">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-md-2 control-label"><a href="{$_url}bandwidth/add">{$_L['BW_Name']}</a></label> <label class="col-md-2 control-label"><a
href="{$_url}bandwidth/add">{$_L['BW_Name']}</a></label>
<div class="col-md-6"> <div class="col-md-6">
<select id="id_bw" name="id_bw" class="form-control select2"> <select id="id_bw" name="id_bw" class="form-control select2">
{foreach $b as $bs} {foreach $b as $bs}
<option value="{$bs['id']}" {if $d['id_bw'] eq $bs['id']} selected {/if}>{$bs['name_bw']}</option> <option value="{$bs['id']}" {if $d['id_bw'] eq $bs['id']} selected {/if}>
{$bs['name_bw']}</option>
{/foreach} {/foreach}
</select> </select>
</div> </div>
@ -46,14 +58,19 @@
<div class="form-group"> <div class="form-group">
<label class="col-md-2 control-label">{$_L['Plan_Validity']}</label> <label class="col-md-2 control-label">{$_L['Plan_Validity']}</label>
<div class="col-md-4"> <div class="col-md-4">
<input type="text" class="form-control" id="validity" name="validity" value="{$d['validity']}"> <input type="text" class="form-control" id="validity" name="validity"
value="{$d['validity']}">
</div> </div>
<div class="col-md-2"> <div class="col-md-2">
<select class="form-control" id="validity_unit" name="validity_unit"> <select class="form-control" id="validity_unit" name="validity_unit">
<option value="Mins" {if $d['validity_unit'] eq 'Mins'} selected {/if}>{$_L['Mins']}</option> <option value="Mins" {if $d['validity_unit'] eq 'Mins'} selected {/if}>{$_L['Mins']}
<option value="Hrs" {if $d['validity_unit'] eq 'Hrs'} selected {/if}>{$_L['Hrs']}</option> </option>
<option value="Days" {if $d['validity_unit'] eq 'Days'} selected {/if}>{$_L['Days']}</option> <option value="Hrs" {if $d['validity_unit'] eq 'Hrs'} selected {/if}>{$_L['Hrs']}
<option value="Months" {if $d['validity_unit'] eq 'Months'} selected {/if}>{$_L['Months']}</option> </option>
<option value="Days" {if $d['validity_unit'] eq 'Days'} selected {/if}>{$_L['Days']}
</option>
<option value="Months" {if $d['validity_unit'] eq 'Months'} selected {/if}>
{$_L['Months']}</option>
</select> </select>
</div> </div>
</div> </div>
@ -62,18 +79,21 @@
<div class="col-md-6"> <div class="col-md-6">
<select id="pool_name" name="pool_name" required class="form-control select2"> <select id="pool_name" name="pool_name" required class="form-control select2">
{foreach $p as $ps} {foreach $p as $ps}
<option value="{$ps['pool_name']}" {if $d['pool'] eq $ps['pool_name']} selected {/if}>{$ps['pool_name']}</option> <option value="{$ps['pool_name']}" {if $d['pool'] eq $ps['pool_name']} selected {/if}>
{$ps['pool_name']}</option>
{/foreach} {/foreach}
</select> </select>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-md-2 control-label"><a href="{$_url}pool/add">{Lang::T('Expired IP Pool')}</a></label> <label class="col-md-2 control-label"><a
href="{$_url}pool/add">{Lang::T('Expired IP Pool')}</a></label>
<div class="col-md-6"> <div class="col-md-6">
<select id="pool_expired" name="pool_expired" class="form-control select2"> <select id="pool_expired" name="pool_expired" class="form-control select2">
<option value=''>{$_L['Select_Pool']}</option> <option value=''>{$_L['Select_Pool']}</option>
{foreach $p as $ps} {foreach $p as $ps}
<option value="{$ps['pool_name']}" {if $d['pool_expired'] eq $ps['pool_name']} selected {/if}>{$ps['pool_name']}</option> <option value="{$ps['pool_name']}" {if $d['pool_expired'] eq $ps['pool_name']} selected
{/if}>{$ps['pool_name']}</option>
{/foreach} {/foreach}
</select> </select>
</div> </div>
@ -81,13 +101,15 @@
<div class="form-group"> <div class="form-group">
<label class="col-md-2 control-label">{$_L['Router_Name']}</label> <label class="col-md-2 control-label">{$_L['Router_Name']}</label>
<div class="col-md-6"> <div class="col-md-6">
<input type="text" class="form-control" id="routers" name="routers" value="{$d['routers']}" readonly> <input type="text" class="form-control" id="routers" name="routers" value="{$d['routers']}"
readonly>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<div class="col-lg-offset-2 col-lg-10"> <div class="col-lg-offset-2 col-lg-10">
<button class="btn btn-success waves-effect waves-light" type="submit">{$_L['Save']}</button> <button class="btn btn-success waves-effect waves-light"
type="submit">{$_L['Save']}</button>
Or <a href="{$_url}services/pppoe">{$_L['Cancel']}</a> Or <a href="{$_url}services/pppoe">{$_L['Cancel']}</a>
</div> </div>
</div> </div>
@ -97,4 +119,13 @@
</div> </div>
</div> </div>
{if $_c['radius_enable'] and $d['is_radius']}
{literal}
<script>
document.getElementById("routers").required = false;
document.getElementById("routers").disabled = true;
document.getElementById("pool_expired").disabled = true;
</script>
{/literal}
{/if}
{include file="sections/footer.tpl"} {include file="sections/footer.tpl"}

View File

@ -54,7 +54,14 @@
<td>{$ds['validity']} {$ds['validity_unit']}</td> <td>{$ds['validity']} {$ds['validity_unit']}</td>
<td>{$ds['pool']}</td> <td>{$ds['pool']}</td>
<td>{$ds['pool_expired']}</td> <td>{$ds['pool_expired']}</td>
<td>{$ds['routers']}</td> <td>
{if $ds['is_radius']}
<span class="label label-primary">RADIUS</span>
{else}
{if $ds['routers']!=''}
<a href="{$_url}routers/edit/0&name={$ds['routers']}">{$ds['routers']}</a>
{/if}
{/if}</td>
<td> <td>
<a href="{$_url}services/pppoe-edit/{$ds['id']}" <a href="{$_url}services/pppoe-edit/{$ds['id']}"
class="btn btn-info btn-xs">{$_L['Edit']}</a> class="btn btn-info btn-xs">{$_L['Edit']}</a>