services: cleanups, preparations

This commit is contained in:
Franco Fichtner 2019-04-23 14:04:15 +02:00
parent 607cc1bcc3
commit b788ea24bd
6 changed files with 108 additions and 114 deletions

View File

@ -1,7 +1,7 @@
<?php
/*
* Copyright (C) 2014-2018 Franco Fichtner <franco@opnsense.org>
* Copyright (C) 2014-2019 Franco Fichtner <franco@opnsense.org>
* Copyright (C) 2010 Ermal Luçi
* Copyright (C) 2005-2006 Colin Smith <ethethlay@gmail.com>
* Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>
@ -30,18 +30,13 @@
*/
/*
* Base services are slowly being converted into plugins,
* hooks are created and expanded to accomodate for their
* feature set, which allows us to build a better plugin
* system in general.
* XXX OpenVPN is the last base plugin that is not gracefully registering
* its functionality to core. With it being gone we can assume all
* plugins even if core functionality must adhere to this idiom.
*
* Ideally this may allow us to remove all service-relevant
* parts from system.inc and services.inc so that the latter
* will eventually become obsolete.
*
* The goal may not be to remove all of the base system
* as plugins, but the things listed below are viable
* targets in the future:
* This will allow us to remove all service-relevant parts from system.inc
* and services.inc so that the latter does become obsolete. For this to
* succeed DHCP functionality needs to be put into a plugin as well.
*/
require_once('plugins.inc.d/openvpn.inc');
@ -1758,6 +1753,27 @@ function get_dyndns_ip($int, $ipver = 4)
return $ip_address;
}
function is_radvd_enabled()
{
global $config;
/* handle manually configured DHCP6 server settings first */
foreach (config_read_array('dhcpdv6') as $dhcpv6if => $dhcpv6ifconf) {
if (isset($config['interfaces'][$dhcpv6if]['enable']) && isset($dhcpv6ifconf['ramode']) && $dhcpv6ifconf['ramode'] != 'disabled') {
return true;
}
}
/* handle DHCP-PD prefixes and 6RD dynamic interfaces */
foreach (legacy_config_get_interfaces(array('virtual' => false)) as $ifcfg) {
if (isset($ifcfg['enable']) && !empty($ifcfg['track6-interface']) && !isset($ifcfg['dhcpd6track6allowoverride'])) {
return true;
}
}
return false;
}
function services_get()
{
$services = array();
@ -1773,7 +1789,7 @@ function services_get()
return $services;
}
function find_service_by_name($name, $filter = array())
function service_by_name($name, $filter = array())
{
$services = services_get();
@ -1795,7 +1811,7 @@ function find_service_by_name($name, $filter = array())
return array();
}
function get_service_status($service)
function service_status($service)
{
if (!empty($service['nocheck'])) {
return true;
@ -1808,12 +1824,11 @@ function get_service_status($service)
return is_process_running($service['name']);
}
function get_service_status_icon($service, $xs = false)
function service_control_icon($service, $xs = false)
{
$output = '';
if (get_service_status($service)) {
if (service_status($service)) {
$output .= '<span class="label label-opnsense label-opnsense-%s label-success"><i class="fa fa-play fa-fw"></i></span>' . PHP_EOL;
} else {
$output .= '<span class="label label-opnsense label-opnsense-%s label-danger"><i class="fa fa-stop fa-fw"></i></span>' . PHP_EOL;
@ -1822,7 +1837,7 @@ function get_service_status_icon($service, $xs = false)
return sprintf($output, $xs ? 'xs' : 'sm');
}
function get_service_control_links($service, $xs = false)
function service_control_links($service, $xs = false)
{
$service_id = isset($service['id']) ? $service['id'] : '';
@ -1831,7 +1846,7 @@ function get_service_control_links($service, $xs = false)
$output = '';
if (get_service_status($service)) {
if (service_status($service)) {
$output .= sprintf(
$template,
$service_id,
@ -1867,27 +1882,6 @@ function get_service_control_links($service, $xs = false)
return $output;
}
function is_radvd_enabled()
{
global $config;
/* handle manually configured DHCP6 server settings first */
foreach (config_read_array('dhcpdv6') as $dhcpv6if => $dhcpv6ifconf) {
if (isset($config['interfaces'][$dhcpv6if]['enable']) && isset($dhcpv6ifconf['ramode']) && $dhcpv6ifconf['ramode'] != 'disabled') {
return true;
}
}
/* handle DHCP-PD prefixes and 6RD dynamic interfaces */
foreach (legacy_config_get_interfaces(array('virtual' => false)) as $ifcfg) {
if (isset($ifcfg['enable']) && !empty($ifcfg['track6-interface']) && !isset($ifcfg['dhcpd6track6allowoverride'])) {
return true;
}
}
return false;
}
function service_control_start($name, $extras)
{
$filter = array();
@ -1896,7 +1890,7 @@ function service_control_start($name, $extras)
$filter['id'] = $extras['id'];
}
$service = find_service_by_name($name, $filter);
$service = service_by_name($name, $filter);
if (!isset($service['name'])) {
return sprintf(gettext("Could not start unknown service `%s'"), htmlspecialchars($name));
}
@ -1934,7 +1928,7 @@ function service_control_stop($name, $extras)
$filter['id'] = $extras['id'];
}
$service = find_service_by_name($name, $filter);
$service = service_by_name($name, $filter);
if (!isset($service['name'])) {
return sprintf(gettext("Could not stop unknown service `%s'"), htmlspecialchars($name));
}
@ -1969,7 +1963,7 @@ function service_control_restart($name, $extras)
$filter['id'] = $extras['id'];
}
$service = find_service_by_name($name, $filter);
$service = service_by_name($name, $filter);
if (!isset($service['name'])) {
return sprintf(gettext("Could not restart unknown service `%s'"), htmlspecialchars($name));
}

View File

@ -53,7 +53,7 @@ function list_services_xmlrpc()
$services = services_get();
foreach ($services as &$service) {
$service['status'] = get_service_status($service);
$service['status'] = service_status($service);
}
return $services;

View File

@ -184,10 +184,10 @@ if($need_alert_display == true) {
<form action="<?=$_SERVER['REQUEST_URI'];?>" method="post">
<?php
if (isset($service_hook)) {
$ssvc = find_service_by_name($service_hook);
$ssvc = service_by_name($service_hook);
if (!empty($ssvc)) {
echo get_service_status_icon($ssvc);
echo get_service_control_links($ssvc);
echo service_control_icon($ssvc);
echo service_control_links($ssvc);
}
} ?>
<?php if (!empty($main_buttons)): foreach ($main_buttons as $button): ?>

View File

@ -1,34 +1,34 @@
<?php
/*
Copyright (C) 2014-2015 Deciso B.V.
Copyright (C) 2010 Jim Pingle <jimp@pfsense.org>
Copyright (C) 2008 Shrew Soft Inc. <mgrooms@shrew.net>
Copyright (C) 2005 Scott Ullrich <sullrich@gmail.com>
Copyright (C) 2005 Colin Smith <ethethlay@gmail.com>
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.
*/
* Copyright (C) 2014-2015 Deciso B.V.
* Copyright (C) 2010 Jim Pingle <jimp@pfsense.org>
* Copyright (C) 2008 Shrew Soft Inc. <mgrooms@shrew.net>
* Copyright (C) 2005 Scott Ullrich <sullrich@gmail.com>
* Copyright (C) 2005 Colin Smith <ethethlay@gmail.com>
* 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.
*/
require_once("guiconfig.inc");
require_once("plugins.inc.d/openvpn.inc");
@ -174,9 +174,9 @@ include("head.inc"); ?>
endforeach; ?>
<tr>
<td colspan="2">
<?php $ssvc = find_service_by_name('openvpn', array('id' => $server['vpnid'])); ?>
<?= get_service_status_icon($ssvc, true); ?>
<?= get_service_control_links($ssvc, true); ?>
<?php $ssvc = service_by_name('openvpn', array('id' => $server['vpnid'])); ?>
<?= service_control_icon($ssvc, true); ?>
<?= service_control_links($ssvc, true); ?>
</td>
<td colspan="6">&nbsp;</td>
</tr>
@ -253,9 +253,9 @@ include("head.inc"); ?>
<td><?= $sk_server['status']; ?></td>
<td>
<div>
<?php $ssvc = find_service_by_name('openvpn', array('id' => $sk_server['vpnid'])); ?>
<?= get_service_status_icon($ssvc, true); ?>
<?= get_service_control_links($ssvc, true); ?>
<?php $ssvc = service_by_name('openvpn', array('id' => $sk_server['vpnid'])); ?>
<?= service_control_icon($ssvc, true); ?>
<?= service_control_links($ssvc, true); ?>
</div>
</td>
</tr>
@ -291,9 +291,9 @@ include("head.inc"); ?>
<td><?= $client['status']; ?></td>
<td>
<div>
<?php $ssvc = find_service_by_name('openvpn', array('id' => $client['vpnid'])); ?>
<?= get_service_status_icon($ssvc, true); ?>
<?= get_service_control_links($ssvc, true); ?>
<?php $ssvc = service_by_name('openvpn', array('id' => $client['vpnid'])); ?>
<?= service_control_icon($ssvc, true); ?>
<?= service_control_links($ssvc, true); ?>
</div>
</td>
</tr>

View File

@ -1,32 +1,32 @@
<?php
/*
Copyright (C) 2014-2015 Deciso B.V.
Copyright (C) 2005-2006 Colin Smith <ethethlay@gmail.com>
Copyright (C) 2004-2005 Scott Ullrich <sullrich@gmail.com>
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.
*/
* Copyright (C) 2014-2015 Deciso B.V.
* Copyright (C) 2005-2006 Colin Smith <ethethlay@gmail.com>
* Copyright (C) 2004-2005 Scott Ullrich <sullrich@gmail.com>
* 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.
*/
require_once("guiconfig.inc");
require_once("services.inc");
@ -83,8 +83,8 @@ include("head.inc");
<td><?=$service['name'];?></td>
<td><?=$service['description'];?></td>
<td>
<?=get_service_status_icon($service);?>
<?=get_service_control_links($service);?>
<?= service_control_icon($service); ?>
<?= service_control_links($service); ?>
</td>
</tr>
<?php

View File

@ -86,8 +86,8 @@ if (isset($_POST['servicestatusfilter'])) {
<td><?=$service['name'];?></td>
<td><?=$service['description'];?></td>
<td style="white-space: nowrap;">
<?= get_service_status_icon($service, true) ?>
<?= get_service_control_links($service, true) ?>
<?= service_control_icon($service, true); ?>
<?= service_control_links($service, true); ?>
</td>
</tr>
<?php