mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-16 01:24:38 +00:00
(traffic shaper) work in progress
This commit is contained in:
parent
ceda9d08dd
commit
6735d533ec
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2015 Deciso B.V.
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
namespace OPNsense\Proxy\TrafficShaper;
|
||||
|
||||
use \OPNsense\Base\ApiControllerBase;
|
||||
use \OPNsense\Core\Backend;
|
||||
|
||||
/**
|
||||
* Class ServiceController
|
||||
* @package OPNsense\TrafficShaper
|
||||
*/
|
||||
class ServiceController extends ApiControllerBase
|
||||
{
|
||||
|
||||
/**
|
||||
* reconfigure ipfw, generate config and reload
|
||||
*/
|
||||
public function reconfigureAction()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
// close session for long running action
|
||||
$this->sessionClose();
|
||||
|
||||
return array("status" => "ok");
|
||||
} else {
|
||||
return array("status" => "failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,134 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2015 Deciso B.V.
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
namespace OPNsense\TrafficShaper\Api;
|
||||
|
||||
use \OPNsense\Base\ApiControllerBase;
|
||||
use \OPNsense\Core\Config;
|
||||
use \OPNsense\TrafficShaper\TrafficShaper;
|
||||
|
||||
/**
|
||||
* Class SettingsController
|
||||
* @package OPNsense\Proxy
|
||||
*/
|
||||
class SettingsController extends ApiControllerBase
|
||||
{
|
||||
/**
|
||||
* retrieve settings
|
||||
* @return array
|
||||
*/
|
||||
public function getAction()
|
||||
{
|
||||
$result = array('rows'=>array());
|
||||
|
||||
for ($i=1; $i<100; $i++) {
|
||||
$result['rows'][] = array('id'=>$i,'sender'=>$i.'xyz','receiver'=>'xxx'.$i);
|
||||
}
|
||||
|
||||
$result['rowCount'] = count($result['rows']);
|
||||
$result['current'] = 1;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve settings
|
||||
* @return array
|
||||
*/
|
||||
public function searchPipesAction()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$mdlShaper = new TrafficShaper();
|
||||
|
||||
// parse search parameters
|
||||
if ($this->request->hasPost('rowCount')) {
|
||||
$itemsPerPage = $this->request->getPost('rowCount');
|
||||
} else {
|
||||
$itemsPerPage = 9999;
|
||||
}
|
||||
if ($this->request->hasPost('current')) {
|
||||
$currentPage = $this->request->getPost('current');
|
||||
} else {
|
||||
$currentPage = 1;
|
||||
}
|
||||
|
||||
if ($this->request->hasPost('sort')) {
|
||||
$sortBy = array_keys($this->request->getPost("sort"));
|
||||
if ($this->request->getPost("sort")[$sortBy[0]] == "desc") {
|
||||
$sortDescending = true;
|
||||
} else {
|
||||
$sortDescending = false;
|
||||
}
|
||||
} else {
|
||||
$sortBy = array("number");
|
||||
$sortDescending = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//searchPhrase
|
||||
//sort
|
||||
|
||||
//$mdlShaper
|
||||
|
||||
$result = array('rows'=>array());
|
||||
|
||||
$fields = array("number", "bandwidth","bandwidthMetric");
|
||||
$recordIndex = 0;
|
||||
foreach ($mdlShaper->pipes->pipe->sortedBy($sortBy, $sortDescending) as $pipe) {
|
||||
if (count($result['rows']) < $itemsPerPage &&
|
||||
$recordIndex >= ($itemsPerPage*($currentPage-1))
|
||||
) {
|
||||
$row = array();
|
||||
$row['uuid'] = $pipe->getAttributes()['uuid'];
|
||||
foreach ($fields as $fieldname) {
|
||||
$row[$fieldname] = $pipe->$fieldname->getNodeData();
|
||||
if (is_array($row[$fieldname])) {
|
||||
foreach ($row[$fieldname] as $fieldKey => $fieldValue) {
|
||||
if ($fieldValue['selected'] == 1) {
|
||||
$row[$fieldname] = $fieldValue['value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$result['rows'][] = $row;
|
||||
}
|
||||
$recordIndex++;
|
||||
}
|
||||
|
||||
|
||||
$result['rowCount'] = count($result['rows']);
|
||||
$result['total'] = $recordIndex;
|
||||
$result['current'] = (int)$currentPage;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2015 Deciso B.V.
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
namespace OPNsense\TrafficShaper;
|
||||
|
||||
/**
|
||||
* Class IndexController
|
||||
* @package OPNsense\TrafficShaper
|
||||
*/
|
||||
class IndexController extends \OPNsense\Base\IndexController
|
||||
{
|
||||
public function indexAction()
|
||||
{
|
||||
$this->view->title = "Traffic Shaper";
|
||||
$this->view->pick('OPNsense/TrafficShaper/index');
|
||||
}
|
||||
}
|
||||
@ -40,10 +40,39 @@
|
||||
<Mbit>Mbit/s</Mbit>
|
||||
</OptionValues>
|
||||
</queueMetric>
|
||||
<origin type="TextField">
|
||||
<Required>N</Required>
|
||||
</origin>
|
||||
<description type="TextField">
|
||||
<Required>N</Required>
|
||||
</description>
|
||||
</pipe>
|
||||
</pipes>
|
||||
<rules>
|
||||
<rule type="ArrayField">
|
||||
<pipe type="IntegerField">
|
||||
<MinimumValue>1</MinimumValue>
|
||||
<MaximumValue>65535</MaximumValue>
|
||||
<ValidationMessage></ValidationMessage>
|
||||
<Required>Y</Required>
|
||||
</pipe>
|
||||
<proto type="OptionField">
|
||||
<Required>Y</Required>
|
||||
<default>ip</default>
|
||||
<OptionValues>
|
||||
<ip>ip</ip>
|
||||
<udp>udp</udp>
|
||||
<tcp>tcp</tcp>
|
||||
</OptionValues>
|
||||
</proto>
|
||||
<interface type="TextField">
|
||||
<Required>Y</Required>
|
||||
<default>wan</default>
|
||||
</interface>
|
||||
<description type="TextField">
|
||||
<Required>N</Required>
|
||||
</description>
|
||||
</rule>
|
||||
</rules>
|
||||
</items>
|
||||
</model>
|
||||
|
||||
105
src/opnsense/mvc/app/views/OPNsense/TrafficShaper/index.volt
Normal file
105
src/opnsense/mvc/app/views/OPNsense/TrafficShaper/index.volt
Normal file
@ -0,0 +1,105 @@
|
||||
{#
|
||||
|
||||
OPNsense® is Copyright © 2014 – 2015 by Deciso B.V.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#}
|
||||
<style>
|
||||
.hidden {
|
||||
display:none;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
|
||||
$( document ).ready(function() {
|
||||
|
||||
|
||||
var grid =$("#grid-basic").bootgrid({
|
||||
ajax: true,
|
||||
selection: true,
|
||||
multiSelect: true,
|
||||
url: '/api/trafficshaper/settings/searchPipes',
|
||||
formatters: {
|
||||
"commands": function(column, row)
|
||||
{
|
||||
return "<button type=\"button\" class=\"btn btn-xs btn-default command-edit\" data-row-id=\"" + row.uuid + "\"><span class=\"fa fa-pencil\"></span></button> " +
|
||||
"<button type=\"button\" class=\"btn btn-xs btn-default command-delete\" data-row-id=\"" + row.uuid + "\"><span class=\"fa fa-trash-o\"></span></button>";
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
grid.on("loaded.rs.jquery.bootgrid", function(){
|
||||
/* Executes after data is loaded and rendered */
|
||||
grid.find(".command-edit").on("click", function(e)
|
||||
{
|
||||
alert("You pressed edit on row: " + $(this).data("row-id"));
|
||||
}).end().find(".command-delete").on("click", function(e)
|
||||
{
|
||||
alert("You pressed delete on row: " + $(this).data("row-id"));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
$("#test").click(function(){
|
||||
var rows =$("#grid-basic").bootgrid('getSelectedRows');
|
||||
alert(rows);
|
||||
$("#grid-basic").bootgrid("reload")
|
||||
// var rowIds = [];
|
||||
// for (var i = 0; i < rows.length; i++)
|
||||
// {
|
||||
// rowIds.push(rows[i]);
|
||||
// }
|
||||
// alert("Select: " + rowIds.join(","));
|
||||
|
||||
//alert(JSON.stringify($("#grid-basic").bootgrid('getSelectedRows')));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
<table id="grid-basic" class="table table-condensed table-hover table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-column-id="number" data-type="number">Number</th>
|
||||
<th data-column-id="bandwidth" data-type="number">Bandwidth</th>
|
||||
<th data-column-id="bandwidthMetric" data-type="string">BandwidthMetric</th>
|
||||
<th data-column-id="commands" data-formatter="commands" data-sortable="false">Commands</th>
|
||||
<th data-column-id="uuid" data-type="string" data-identifier="true" data-visible="false">ID</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th><button id="test">test</button></th>
|
||||
</tfoot>
|
||||
</table>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user