Commit 3b34f51f authored by Franco Fichtner's avatar Franco Fichtner

plugins: add firewall reload button, inline service_name_compare()

parent b30940b5
<?php
/*
Copyright (C) 2016 Franco Fichtner <franco@opnsense.org>
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;
}
......@@ -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']);
......
......@@ -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;
}
......
......@@ -56,14 +56,9 @@ if (!empty($_POST['service'])) {
$services = services_get();
if (count($services) > 0) {
uasort($services, "service_name_compare");
}
include("head.inc");
?>
<body>
<?php include("fbegin.inc"); ?>
......
......@@ -79,7 +79,6 @@ if (isset($_POST['servicestatusfilter'])) {
<?php
$skipservices = explode(",", $config['widgets']['servicestatusfilter']);
if (count($services) > 0):
uasort($services, "service_name_compare");
foreach ($services as $service):
if (!$service['name'] || in_array($service['name'], $skipservices)) {
continue;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment