From 3b34f51f633abd54d00ed35f2ebc5c19ac2be156 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Mon, 21 Nov 2016 00:02:41 +0100 Subject: [PATCH] plugins: add firewall reload button, inline service_name_compare() --- src/etc/inc/plugins.inc.d/firewall.inc | 49 +++++++++++++++++++ src/etc/inc/services.inc | 18 +++---- src/etc/inc/xmlrpc/service.inc | 5 +- src/www/status_services.php | 5 -- .../widgets/services_status.widget.php | 1 - 5 files changed, 59 insertions(+), 19 deletions(-) create mode 100644 src/etc/inc/plugins.inc.d/firewall.inc diff --git a/src/etc/inc/plugins.inc.d/firewall.inc b/src/etc/inc/plugins.inc.d/firewall.inc new file mode 100644 index 000000000..c7c8196b3 --- /dev/null +++ b/src/etc/inc/plugins.inc.d/firewall.inc @@ -0,0 +1,49 @@ + + 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. +*/ + +function firewall_services() +{ + global $config; + + $services = array(); + + if (!isset($config['system']['disablefilter'])) { + $services[] = array( + 'description' => gettext('Packet Filter'), + 'configd' => array( + 'restart' => array('filter reload'), + 'start' => array('filter reload'), + 'stop' => array('filter reload'), + ), + 'nocheck' => true, + 'name' => 'pf', + ); + } + + return $services; +} diff --git a/src/etc/inc/services.inc b/src/etc/inc/services.inc index 342495d9e..79b239217 100644 --- a/src/etc/inc/services.inc +++ b/src/etc/inc/services.inc @@ -1961,6 +1961,10 @@ function services_get() } } + uasort($services, function ($a, $b) { + return strcasecmp($a['name'], $b['name']); + }); + return $services; } @@ -1997,20 +2001,14 @@ function find_service_by_name($names, $filter = array()) return array(); } -function service_name_compare($a, $b) { - if (strtolower($a['name']) == strtolower($b['name'])) { - return 0; - } - return (strtolower($a['name']) < strtolower($b['name'])) ? -1 : 1; -} - - function get_service_status($service) { + if (!empty($service['nocheck'])) { + return true; + } + if (isset($service['pidfile'])) { return isvalidpid($service['pidfile']); - } elseif (!empty($service['nocheck'])) { - return true; } return is_process_running($service['name']); diff --git a/src/etc/inc/xmlrpc/service.inc b/src/etc/inc/xmlrpc/service.inc index a98db4060..d6188cd57 100644 --- a/src/etc/inc/xmlrpc/service.inc +++ b/src/etc/inc/xmlrpc/service.inc @@ -53,12 +53,11 @@ function xmlrpc_publishable_service() function list_services_xmlrpc() { $services = services_get(); - if (count($services) > 0) { - uasort($services, "service_name_compare"); - } + foreach ($services as &$service) { $service['status'] = get_service_status($service); } + return $services; } diff --git a/src/www/status_services.php b/src/www/status_services.php index 307e60c6b..2201ba3df 100644 --- a/src/www/status_services.php +++ b/src/www/status_services.php @@ -56,14 +56,9 @@ if (!empty($_POST['service'])) { $services = services_get(); -if (count($services) > 0) { - uasort($services, "service_name_compare"); -} - include("head.inc"); ?> - diff --git a/src/www/widgets/widgets/services_status.widget.php b/src/www/widgets/widgets/services_status.widget.php index 7fd9fbea8..7e560f84f 100644 --- a/src/www/widgets/widgets/services_status.widget.php +++ b/src/www/widgets/widgets/services_status.widget.php @@ -79,7 +79,6 @@ if (isset($_POST['servicestatusfilter'])) { 0): - uasort($services, "service_name_compare"); foreach ($services as $service): if (!$service['name'] || in_array($service['name'], $skipservices)) { continue;