From ec4458d18127425005262e2b2dc76a5cfc9fa257 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Wed, 7 Dec 2016 15:16:46 +0100 Subject: [PATCH] (traffic shaper) add flush all and reload action, closes https://github.com/opnsense/core/issues/1297 --- src/etc/rc.ipfw.flush_all | 31 +++++++++++++++++++ .../TrafficShaper/Api/ServiceController.php | 20 +++++++++++- .../views/OPNsense/TrafficShaper/index.volt | 29 ++++++++++++++++- .../service/conf/actions.d/actions_ipfw.conf | 6 ++++ 4 files changed, 84 insertions(+), 2 deletions(-) create mode 100755 src/etc/rc.ipfw.flush_all diff --git a/src/etc/rc.ipfw.flush_all b/src/etc/rc.ipfw.flush_all new file mode 100755 index 000000000..800004131 --- /dev/null +++ b/src/etc/rc.ipfw.flush_all @@ -0,0 +1,31 @@ +#!/bin/sh +# Copyright (c) 2016 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. + +# flush ipfw rules, pipes, queues + +/sbin/ipfw -f flush +/sbin/ipfw -f pipe flush +/sbin/ipfw -f queue flush + diff --git a/src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/ServiceController.php b/src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/ServiceController.php index a8c39537c..8b6995cdf 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/ServiceController.php +++ b/src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/ServiceController.php @@ -1,6 +1,6 @@ "failed"); } } + + /** + * flush all ipfw rules + */ + public function flushreloadAction() + { + if ($this->request->isPost()) { + // close session for long running action + $this->sessionClose(); + + $backend = new Backend(); + $status = trim($backend->configdRun("ipfw flush")); + $status = trim($backend->configdRun("ipfw reload")); + return array("status" => $status); + } else { + return array("status" => "failed"); + } + } } diff --git a/src/opnsense/mvc/app/views/OPNsense/TrafficShaper/index.volt b/src/opnsense/mvc/app/views/OPNsense/TrafficShaper/index.volt index bf0431c06..2af08c124 100644 --- a/src/opnsense/mvc/app/views/OPNsense/TrafficShaper/index.volt +++ b/src/opnsense/mvc/app/views/OPNsense/TrafficShaper/index.volt @@ -1,6 +1,6 @@ {# -OPNsense® is Copyright © 2014 – 2015 by Deciso B.V. +OPNsense® is Copyright © 2014 – 2016 by Deciso B.V. All rights reserved. Redistribution and use in source and binary forms, with or without modification, @@ -93,6 +93,32 @@ POSSIBILITY OF SUCH DAMAGE. }); }); + $("#flushAct").click(function(){ + // Ask user if it's ok to flush all of ipfw + BootstrapDialog.show({ + type:BootstrapDialog.TYPE_WARNING, + title: 'Flush', + message: "{{ lang._('Are you sure you want to flush and reload all? this might have impact on other services using the same technology underneath (such as Captive portal)') }}", + buttons: [{ + label: 'Yes', + action: function(dialogRef){ + dialogRef.close(); + $("#flushAct_progress").addClass("fa fa-spinner fa-pulse"); + ajaxCall(url="/api/trafficshaper/service/flushreload", sendData={}, callback=function(data,status) { + // when done, disable progress animation. + $("#flushAct_progress").removeClass("fa fa-spinner fa-pulse"); + }); + + } + },{ + label: 'No', + action: function(dialogRef){ + dialogRef.close(); + } + }] + }); + }); + // update history on tab state and implement navigation if (window.location.hash != "") { $('a[href="' + window.location.hash + '"]').click() @@ -202,6 +228,7 @@ POSSIBILITY OF SUCH DAMAGE.

+

diff --git a/src/opnsense/service/conf/actions.d/actions_ipfw.conf b/src/opnsense/service/conf/actions.d/actions_ipfw.conf index ae9f575da..2d2025fd9 100644 --- a/src/opnsense/service/conf/actions.d/actions_ipfw.conf +++ b/src/opnsense/service/conf/actions.d/actions_ipfw.conf @@ -3,3 +3,9 @@ command:/etc/rc.d/ipfw onestart; /usr/local/etc/rc.ipfw.postload parameters: type:script message:restarting ipfw + +[flush] +command:/usr/local/etc/rc.ipfw.flush_all +parameters: +type:script +message:flush all ipfw rules