From ce244e804c0d14a0940cf374566ea02504ac182f Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Tue, 26 May 2015 21:54:22 +0200 Subject: [PATCH] (trafficshaper) work in progress traffic shaper, add initial rule configuration --- .../TrafficShaper/Api/SettingsController.php | 33 +++++ .../TrafficShaper/forms/dialogPipe.xml | 24 +++- .../OPNsense/TrafficShaper/TrafficShaper.xml | 52 ++++--- .../views/OPNsense/TrafficShaper/index.volt | 134 ++++++++++++++---- 4 files changed, 195 insertions(+), 48 deletions(-) diff --git a/src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/SettingsController.php b/src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/SettingsController.php index 8a23be063..993fc9a0a 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/SettingsController.php +++ b/src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/SettingsController.php @@ -189,4 +189,37 @@ class SettingsController extends ApiControllerBase } } + + /** + * search traffic shaper rules + * @return array + */ + public function searchRulesAction() + { + if ($this->request->isPost()) { + // fetch query parameters + $itemsPerPage = $this->request->getPost('rowCount', 'int', 9999); + $currentPage = $this->request->getPost('current', 'int', 1); + $sortBy = array("number"); + $sortDescending = false; + + if ($this->request->hasPost('sort') && is_array($this->request->getPost("sort"))) { + $sortBy = array_keys($this->request->getPost("sort")); + if ($this->request->getPost("sort")[$sortBy[0]] == "desc") { + $sortDescending = true; + } + } + + $searchPhrase = $this->request->getPost('searchPhrase', 'string', ''); + + // create model and fetch query resuls + $fields = array("interface", "proto","source","destination","description","origin"); + $mdlShaper = new TrafficShaper(); + $grid = new UIModelGrid($mdlShaper->rules->rule); + return $grid->fetch($fields, $itemsPerPage, $currentPage, $sortBy, $sortDescending, $searchPhrase); + } else { + return array(); + } + + } } diff --git a/src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/forms/dialogPipe.xml b/src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/forms/dialogPipe.xml index 81298b0dd..b48d47650 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/forms/dialogPipe.xml +++ b/src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/forms/dialogPipe.xml @@ -3,13 +3,29 @@ pipe.bandwidth text - test - + Total bandwidth for this pipe pipe.bandwidthMetric - + dropdown - + + pipe.queue + + text + test + + + pipe.mask + + dropdown + + + + pipe.description + + text + + \ No newline at end of file diff --git a/src/opnsense/mvc/app/models/OPNsense/TrafficShaper/TrafficShaper.xml b/src/opnsense/mvc/app/models/OPNsense/TrafficShaper/TrafficShaper.xml index 163c6b50c..acfdfed63 100644 --- a/src/opnsense/mvc/app/models/OPNsense/TrafficShaper/TrafficShaper.xml +++ b/src/opnsense/mvc/app/models/OPNsense/TrafficShaper/TrafficShaper.xml @@ -9,13 +9,14 @@ 1 65535 - + Pipe number must be between 1...65535 Y Y 1 899795 + Bandwidth out of range Y @@ -29,19 +30,23 @@ N + 2 + 100 + queue size should be between 2...100 - - N - slots + + Y + none - Slots - bit/s - Kbit/s - Mbit/s + + source + destination - + N + /^([a-z,A-Z,1-9]){0,30}$/ + origin should be regular text of max 30 characters N @@ -50,12 +55,10 @@ - - 1 - 65535 - + Y - + wan + Y ip @@ -65,13 +68,28 @@ tcp - + Y - wan - + any + + + Y + any + + + 1 + 65535 + + Y + N + + N + /^([a-z,A-Z,1-9]){0,30}$/ + origin should be regular text of max 30 characters + diff --git a/src/opnsense/mvc/app/views/OPNsense/TrafficShaper/index.volt b/src/opnsense/mvc/app/views/OPNsense/TrafficShaper/index.volt index f340a76de..d010c8490 100644 --- a/src/opnsense/mvc/app/views/OPNsense/TrafficShaper/index.volt +++ b/src/opnsense/mvc/app/views/OPNsense/TrafficShaper/index.volt @@ -34,6 +34,10 @@ POSSIBILITY OF SUCH DAMAGE. $( document ).ready(function() { + /************************************************************************************************************* + * manage bandwidth pipes + *************************************************************************************************************/ + /** * Render pipe grid using searchPipes api */ @@ -41,6 +45,7 @@ POSSIBILITY OF SUCH DAMAGE. ajax: true, selection: true, multiSelect: true, + rowCount:[7,14,20,-1], url: '/api/trafficshaper/settings/searchPipes', formatters: { "commands": function(column, row) @@ -167,38 +172,113 @@ POSSIBILITY OF SUCH DAMAGE. }); + /************************************************************************************************************* + * + *************************************************************************************************************/ + + /** + * Render rules grid using searchPipes api + */ + var gridRules =$("#grid-rules").bootgrid({ + ajax: true, + selection: true, + multiSelect: true, + rowCount:[7,14,20,-1], + url: '/api/trafficshaper/settings/searchRules', + formatters: { + "commands": function(column, row) + { + return " " + + ""; + } + } + }); + }); - - - - - - - - - - - - - - - - - - - - - - - -
NumberBandwidthBandwidthMetricdescriptionCommandsID
- - -
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
OriginNumberBandwidthBandwidthMetricmaskdescriptionCommandsID
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
OriginInterfaceProtocolSourceDestinationDescriptionCommandsID
+ + +
+
+
+
+
+
{# include dialogs #}