sync hotspot to mikrotik

This commit is contained in:
Ibnu Maksum 2023-09-15 14:03:23 +07:00
parent 50ab20e68e
commit f69885d358
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
2 changed files with 147 additions and 74 deletions

View File

@ -21,6 +21,68 @@ use PEAR2\Net\RouterOS;
require_once 'system/autoload/PEAR2/Autoload.php'; require_once 'system/autoload/PEAR2/Autoload.php';
switch ($action) { switch ($action) {
case 'sync':
set_time_limit(-1);
if ($routes['2'] == 'hotspot') {
$plans = ORM::for_table('tbl_bandwidth')->join('tbl_plans', array('tbl_bandwidth.id', '=', 'tbl_plans.id_bw'))->where('tbl_plans.type', 'Hotspot')->where('tbl_plans.enabled', '1')->find_many();
$log = '';
$router = '';
foreach ($plans as $plan) {
if ($router != $plan['routers']) {
$mikrotik = Mikrotik::info($plan['routers']);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
$router = $plan['routers'];
}
if ($plan['rate_down_unit'] == 'Kbps') {
$unitdown = 'K';
} else {
$unitdown = 'M';
}
if ($plan['rate_up_unit'] == 'Kbps') {
$unitup = 'K';
} else {
$unitup = 'M';
}
$rate = $plan['rate_up'] . $unitup . "/" . $plan['rate_down'] . $unitdown;
Mikrotik::addHotspotPlan($client, $plan['name_plan'], $plan['shared_users'], $rate);
$log .= "DONE : $plan[name_plan], $plan[shared_users], $rate<br>";
if (!empty($plan['pool_expired'])) {
Mikrotik::setHotspotExpiredPlan($client, 'EXPIRED NUXBILL ' . $plan['pool_expired'], $plan['pool_expired']);
$log .= "DONE Expired : EXPIRED NUXBILL $plan[pool_expired]<br>";
}
}
r2(U . 'services/hotspot', 's', $log);
}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 = '';
foreach ($plans as $plan) {
if ($router != $plan['routers']) {
$mikrotik = Mikrotik::info($plan['routers']);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
$router = $plan['routers'];
}
if ($plan['rate_down_unit'] == 'Kbps') {
$unitdown = 'K';
} else {
$unitdown = 'M';
}
if ($plan['rate_up_unit'] == 'Kbps') {
$unitup = 'K';
} else {
$unitup = 'M';
}
$rate = $plan['rate_up'] . $unitup . "/" . $plan['rate_down'] . $unitdown;
Mikrotik::addPpoePlan($client, $plan['name_plan'], $plan['pool'], $rate);
$log .= "DONE : $plan[name_plan], $plan[pool], $rate<br>";
if (!empty($plan['pool_expired'])) {
Mikrotik::setPpoePlan($client, 'EXPIRED NUXBILL ' . $plan['pool_expired'], $plan['pool_expired'], '512K/512K');
$log .= "DONE Expired : EXPIRED NUXBILL $plan[pool_expired]<br>";
}
}
r2(U . 'services/pppoe', 's', $log);
}
r2(U . 'services/hotspot', 'w', 'Unknown command');
case 'hotspot': case 'hotspot':
$ui->assign('xfooter', '<script type="text/javascript" src="ui/lib/c/hotspot.js"></script>'); $ui->assign('xfooter', '<script type="text/javascript" src="ui/lib/c/hotspot.js"></script>');
@ -135,8 +197,8 @@ switch ($action) {
$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::addHotspotPlan($client, $name, $sharedusers, $rate); Mikrotik::addHotspotPlan($client, $name, $sharedusers, $rate);
if(!empty($pool_expired)){ if (!empty($pool_expired)) {
Mikrotik::setHotspotExpiredPlan($client, 'EXPIRED NUXBILL '.$pool_expired, $pool_expired); Mikrotik::setHotspotExpiredPlan($client, 'EXPIRED NUXBILL ' . $pool_expired, $pool_expired);
} }
} }
@ -220,8 +282,8 @@ switch ($action) {
$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::setHotspotPlan($client, $name, $sharedusers, $rate); Mikrotik::setHotspotPlan($client, $name, $sharedusers, $rate);
if(!empty($pool_expired)){ if (!empty($pool_expired)) {
Mikrotik::setHotspotExpiredPlan($client, 'EXPIRED NUXBILL '.$pool_expired, $pool_expired); Mikrotik::setHotspotExpiredPlan($client, 'EXPIRED NUXBILL ' . $pool_expired, $pool_expired);
} }
} }
@ -358,8 +420,8 @@ switch ($action) {
$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::addPpoePlan($client, $name, $pool, $rate); Mikrotik::addPpoePlan($client, $name, $pool, $rate);
if(!empty($pool_expired)){ if (!empty($pool_expired)) {
Mikrotik::setPpoePlan($client, 'EXPIRED NUXBILL '.$pool_expired, $pool_expired, '512K/512K'); Mikrotik::setPpoePlan($client, 'EXPIRED NUXBILL ' . $pool_expired, $pool_expired, '512K/512K');
} }
} }
@ -429,8 +491,8 @@ switch ($action) {
$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);
if(!empty($pool_expired)){ if (!empty($pool_expired)) {
Mikrotik::setPpoePlan($client, 'EXPIRED NUXBILL '.$pool_expired, $pool_expired, '512K/512K'); Mikrotik::setPpoePlan($client, 'EXPIRED NUXBILL ' . $pool_expired, $pool_expired, '512K/512K');
} }
} }

View File

@ -1,70 +1,81 @@
{include file="sections/header.tpl"} {include file="sections/header.tpl"}
<div class="row"> <div class="row">
<div class="col-sm-12"> <div class="col-sm-12">
<div class="panel panel-hovered mb20 panel-primary"> <div class="panel panel-hovered mb20 panel-primary">
<div class="panel-heading">{$_L['Hotspot_Plans']}</div> <div class="panel-heading">
<div class="panel-body"> <div class="btn-group pull-right">
<div class="md-whiteframe-z1 mb20 text-center" style="padding: 15px"> <a class="btn btn-primary btn-xs" title="save" href="{$_url}services/sync/hotspot"
<div class="col-md-8"> onclick="return confirm('This will sync/send hotspot plan to Mikrotik?')"><span
<form id="site-search" method="post" action="{$_url}services/hotspot/"> class="glyphicon glyphicon-refresh" aria-hidden="true"></span> sync</a>
<div class="input-group"> </div>{$_L['Hotspot_Plans']}
<div class="input-group-addon"> </div>
<span class="fa fa-search"></span> <div class="panel-body">
</div> <div class="md-whiteframe-z1 mb20 text-center" style="padding: 15px">
<input type="text" name="name" class="form-control" placeholder="{$_L['Search_by_Name']}..."> <div class="col-md-8">
<div class="input-group-btn"> <form id="site-search" method="post" action="{$_url}services/hotspot/">
<button class="btn btn-success" type="submit">{$_L['Search']}</button> <div class="input-group">
</div> <div class="input-group-addon">
</div> <span class="fa fa-search"></span>
</form> </div>
</div> <input type="text" name="name" class="form-control"
<div class="col-md-4"> placeholder="{$_L['Search_by_Name']}...">
<a href="{$_url}services/add" class="btn btn-primary btn-block waves-effect"><i class="ion ion-android-add"> </i> {$_L['New_Plan']}</a> <div class="input-group-btn">
</div>&nbsp; <button class="btn btn-success" type="submit">{$_L['Search']}</button>
</div> </div>
<div class="table-responsive"> </div>
<table class="table table-bordered table-striped table-condensed"> </form>
<thead> </div>
<tr> <div class="col-md-4">
<th>{$_L['Plan_Name']}</th> <a href="{$_url}services/add" class="btn btn-primary btn-block waves-effect"><i
<th>{$_L['Plan_Type']}</th> class="ion ion-android-add"> </i> {$_L['New_Plan']}</a>
<th>{$_L['Bandwidth_Plans']}</th> </div>&nbsp;
<th>{$_L['Plan_Price']}</th> </div>
<th>{$_L['Time_Limit']}</th> <div class="table-responsive">
<th>{$_L['Data_Limit']}</th> <table class="table table-bordered table-striped table-condensed">
<th>{$_L['Plan_Validity']}</th> <thead>
<th>{$_L['Routers']}</th> <tr>
<th>{Lang::T('Expired IP Pool')}</th> <th>{$_L['Plan_Name']}</th>
<th>{$_L['Manage']}</th> <th>{$_L['Plan_Type']}</th>
</tr> <th>{$_L['Bandwidth_Plans']}</th>
</thead> <th>{$_L['Plan_Price']}</th>
<tbody> <th>{$_L['Time_Limit']}</th>
{foreach $d as $ds} <th>{$_L['Data_Limit']}</th>
<tr {if $ds['enabled'] != 1}class="danger" title="disabled"{/if}> <th>{$_L['Plan_Validity']}</th>
<td>{$ds['name_plan']}</td> <th>{$_L['Routers']}</th>
<td>{$ds['typebp']}</td> <th>{Lang::T('Expired IP Pool')}</th>
<td>{$ds['name_bw']}</td> <th>{$_L['Manage']}</th>
<td>{Lang::moneyFormat($ds['price'])}</td> </tr>
<td>{$ds['time_limit']} {$ds['time_unit']}</td> </thead>
<td>{$ds['data_limit']} {$ds['data_unit']}</td> <tbody>
<td>{$ds['validity']} {$ds['validity_unit']}</td> {foreach $d as $ds}
<td>{$ds['routers']}</td> <tr {if $ds['enabled'] != 1}class="danger" title="disabled" {/if}>
<td>{$ds['pool_expired']}</td> <td>{$ds['name_plan']}</td>
<td> <td>{$ds['typebp']}</td>
<a href="{$_url}services/edit/{$ds['id']}" class="btn btn-info btn-xs">{$_L['Edit']}</a> <td>{$ds['name_bw']}</td>
<a href="{$_url}services/delete/{$ds['id']}" id="{$ds['id']}" onclick="return confirm('{$_L['Delete']}?')" class="btn btn-danger btn-xs">{$_L['Delete']}</a> <td>{Lang::moneyFormat($ds['price'])}</td>
</td> <td>{$ds['time_limit']} {$ds['time_unit']}</td>
</tr> <td>{$ds['data_limit']} {$ds['data_unit']}</td>
{/foreach} <td>{$ds['validity']} {$ds['validity_unit']}</td>
</tbody> <td>{$ds['routers']}</td>
</table> <td>{$ds['pool_expired']}</td>
</div> <td>
{$paginator['contents']} <a href="{$_url}services/edit/{$ds['id']}"
class="btn btn-info btn-xs">{$_L['Edit']}</a>
<a href="{$_url}services/delete/{$ds['id']}" id="{$ds['id']}"
onclick="return confirm('{$_L['Delete']}?')"
class="btn btn-danger btn-xs">{$_L['Delete']}</a>
</td>
</tr>
{/foreach}
</tbody>
</table>
</div>
{$paginator['contents']}
</div> </div>
</div> </div>
</div> </div>
</div> </div>
{include file="sections/footer.tpl"} {include file="sections/footer.tpl"}