diff --git a/src/etc/inc/services.inc b/src/etc/inc/services.inc
index 6f5e6d901..2e6cccd9f 100644
--- a/src/etc/inc/services.inc
+++ b/src/etc/inc/services.inc
@@ -29,208 +29,9 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-/* XXX remove this file, merging it into system.inc */
-
-function service_by_name($name, $filter = array())
-{
- $services = plugins_services();
-
- foreach ($services as $service) {
- if ($service['name'] != $name) {
- continue;
- }
- if (!count($filter)) {
- /* force match if filter wasn't set (standard behaviour) */
- $filter['name'] = $name;
- }
- foreach ($filter as $key => $value) {
- if (isset($service[$key]) && $service[$key] == $value) {
- return $service;
- }
- }
- }
-
- return array();
-}
-
-function service_status($service)
-{
- if (!empty($service['nocheck'])) {
- return true;
- }
-
- if (isset($service['pidfile'])) {
- return isvalidpid($service['pidfile']);
- }
-
- return is_process_running($service['name']);
-}
-
-function service_control_icon($service, $xs = false)
-{
- $output = '';
-
- if (service_status($service)) {
- $output .= '' . PHP_EOL;
- } else {
- $output .= '' . PHP_EOL;
- }
-
- return sprintf($output, $xs ? 'xs' : 'sm');
-}
-
-function service_control_links($service, $xs = false)
-{
- $service_id = isset($service['id']) ? $service['id'] : '';
-
- $template = '
+ * Copyright (C) 2014-2019 Franco Fichtner
+ * Copyright (C) 2010 Ermal Luçi
+ * Copyright (C) 2005-2006 Colin Smith
* Copyright (C) 2004-2007 Scott Ullrich
* Copyright (C) 2003-2004 Manuel Kasper
* All rights reserved.
@@ -93,6 +95,152 @@ function is_process_running($process)
return (intval($retval) == 0);
}
+function service_by_name($name, $filter = array())
+{
+ $services = plugins_services();
+
+ foreach ($services as $service) {
+ if ($service['name'] != $name) {
+ continue;
+ }
+ if (!count($filter)) {
+ /* force match if filter wasn't set (standard behaviour) */
+ $filter['name'] = $name;
+ }
+ foreach ($filter as $key => $value) {
+ if (isset($service[$key]) && $service[$key] == $value) {
+ return $service;
+ }
+ }
+ }
+
+ return array();
+}
+
+function service_status($service)
+{
+ if (!empty($service['nocheck'])) {
+ return true;
+ }
+
+ if (isset($service['pidfile'])) {
+ return isvalidpid($service['pidfile']);
+ }
+
+ return is_process_running($service['name']);
+}
+
+function service_control_start($name, $extras)
+{
+ $filter = array();
+
+ if (!empty($extras['id'])) {
+ $filter['id'] = $extras['id'];
+ }
+
+ $service = service_by_name($name, $filter);
+ if (!isset($service['name'])) {
+ return sprintf(gettext("Could not start unknown service `%s'"), htmlspecialchars($name));
+ }
+
+ if (isset($service['configd']['start'])) {
+ foreach ($service['configd']['start'] as $cmd) {
+ configd_run($cmd);
+ }
+ } elseif (isset($service['php']['start'])) {
+ foreach ($service['php']['start'] as $cmd) {
+ $params = array();
+ if (isset($service['php']['args'])) {
+ foreach ($service['php']['args'] as $param) {
+ $params[] = $service[$param];
+ }
+ }
+ call_user_func_array($cmd, $params);
+ }
+ } elseif (isset($service['mwexec']['start'])) {
+ foreach ($service['mwexec']['start'] as $cmd) {
+ mwexec($cmd);
+ }
+ } else {
+ return sprintf(gettext("Could not start service `%s'"), htmlspecialchars($name));
+ }
+
+ return sprintf(gettext("Service `%s' has been started."), htmlspecialchars($name));
+}
+
+function service_control_stop($name, $extras)
+{
+ $filter = array();
+
+ if (!empty($extras['id'])) {
+ $filter['id'] = $extras['id'];
+ }
+
+ $service = service_by_name($name, $filter);
+ if (!isset($service['name'])) {
+ return sprintf(gettext("Could not stop unknown service `%s'"), htmlspecialchars($name));
+ }
+
+ if (isset($service['configd']['stop'])) {
+ foreach ($service['configd']['stop'] as $cmd) {
+ configd_run($cmd);
+ }
+ } elseif (isset($service['php']['stop'])) {
+ foreach ($service['php']['stop'] as $cmd) {
+ $cmd();
+ }
+ } elseif (isset($service['mwexec']['stop'])) {
+ foreach ($service['mwexec']['stop'] as $cmd) {
+ mwexec($cmd);
+ }
+ } elseif (isset($service['pidfile'])) {
+ killbypid($service['pidfile'], 'TERM', true);
+ } else {
+ /* last resort, but not very elegant */
+ killbyname($service['name']);
+ }
+
+ return sprintf(gettext("Service `%s' has been stopped."), htmlspecialchars($name));
+}
+
+function service_control_restart($name, $extras)
+{
+ $filter = array();
+
+ if (!empty($extras['id'])) {
+ $filter['id'] = $extras['id'];
+ }
+
+ $service = service_by_name($name, $filter);
+ if (!isset($service['name'])) {
+ return sprintf(gettext("Could not restart unknown service `%s'"), htmlspecialchars($name));
+ }
+
+ if (isset($service['configd']['restart'])) {
+ foreach ($service['configd']['restart'] as $cmd) {
+ configd_run($cmd);
+ }
+ } elseif (isset($service['php']['restart'])) {
+ foreach ($service['php']['restart'] as $cmd) {
+ $params = array();
+ if (isset($service['php']['args'])) {
+ foreach ($service['php']['args'] as $param) {
+ $params[] = $service[$param];
+ }
+ }
+ call_user_func_array($cmd, $params);
+ }
+ } elseif (isset($service['mwexec']['restart'])) {
+ foreach ($service['mwexec']['restart'] as $cmd) {
+ mwexec($cmd);
+ }
+ } else {
+ return sprintf(gettext("Could not restart service `%s'"), htmlspecialchars($name));
+ }
+
+ return sprintf(gettext("Service `%s' has been restarted."), htmlspecialchars($name));
+}
+
function list_dh_parameters()
{
global $config;
diff --git a/src/etc/inc/xmlrpc/service.inc b/src/etc/inc/xmlrpc/service.inc
index cd78b62e1..ed02789f4 100644
--- a/src/etc/inc/xmlrpc/service.inc
+++ b/src/etc/inc/xmlrpc/service.inc
@@ -26,7 +26,6 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-require_once("services.inc");
require_once("system.inc");
require_once('util.inc');
require_once("filter.inc");
diff --git a/src/sbin/pluginctl b/src/sbin/pluginctl
index 371bff208..176235707 100755
--- a/src/sbin/pluginctl
+++ b/src/sbin/pluginctl
@@ -34,7 +34,6 @@ require_once 'util.inc';
require_once 'system.inc';
require_once 'interfaces.inc';
require_once 'filter.inc';
-require_once 'services.inc';
require_once 'auth.inc';
/*
diff --git a/src/www/diag_backup.php b/src/www/diag_backup.php
index 7ab41e3a3..2ffd0a632 100644
--- a/src/www/diag_backup.php
+++ b/src/www/diag_backup.php
@@ -33,7 +33,6 @@
require_once("guiconfig.inc");
require_once("interfaces.inc");
require_once("filter.inc");
-require_once("services.inc");
require_once("rrd.inc");
require_once("system.inc");
diff --git a/src/www/diag_ipsec.php b/src/www/diag_ipsec.php
index a4c8d5648..b629ab159 100644
--- a/src/www/diag_ipsec.php
+++ b/src/www/diag_ipsec.php
@@ -30,7 +30,6 @@
*/
require_once("guiconfig.inc");
-require_once("services.inc");
require_once("plugins.inc.d/ipsec.inc");
/**
diff --git a/src/www/diag_ipsec_leases.php b/src/www/diag_ipsec_leases.php
index f510b6cc7..2ce697af7 100644
--- a/src/www/diag_ipsec_leases.php
+++ b/src/www/diag_ipsec_leases.php
@@ -29,7 +29,6 @@
require_once("guiconfig.inc");
require_once("plugins.inc.d/ipsec.inc");
-require_once("services.inc");
require_once("interfaces.inc");
$service_hook = 'strongswan';
diff --git a/src/www/diag_ipsec_sad.php b/src/www/diag_ipsec_sad.php
index e614c7da6..a49fddcee 100644
--- a/src/www/diag_ipsec_sad.php
+++ b/src/www/diag_ipsec_sad.php
@@ -29,7 +29,6 @@
*/
require_once("guiconfig.inc");
-require_once("services.inc");
require_once("interfaces.inc");
require_once("plugins.inc.d/ipsec.inc");
diff --git a/src/www/diag_ipsec_spd.php b/src/www/diag_ipsec_spd.php
index 24a769d13..67391e6df 100644
--- a/src/www/diag_ipsec_spd.php
+++ b/src/www/diag_ipsec_spd.php
@@ -29,7 +29,6 @@
*/
require_once("guiconfig.inc");
-require_once("services.inc");
require_once("interfaces.inc");
require_once("plugins.inc.d/ipsec.inc");
diff --git a/src/www/diag_logs_template.inc b/src/www/diag_logs_template.inc
index 5844b2769..7cb8de113 100644
--- a/src/www/diag_logs_template.inc
+++ b/src/www/diag_logs_template.inc
@@ -1,38 +1,37 @@
- Copyright (C) 2004-2009 Scott Ullrich
- Copyright (C) 2003-2004 Manuel Kasper
- 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) 2012 Seth Mos
+ * Copyright (C) 2004-2009 Scott Ullrich
+ * Copyright (C) 2003-2004 Manuel Kasper
+ * 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("system.inc");
require_once("interfaces.inc");
-require_once("services.inc");
/* expects $logfile to point to the system path */
/* expects $logclog to be true or false */
diff --git a/src/www/guiconfig.inc b/src/www/guiconfig.inc
index 38ac08ed4..16aa5b2d6 100644
--- a/src/www/guiconfig.inc
+++ b/src/www/guiconfig.inc
@@ -1,8 +1,10 @@
+ * Copyright (C) 2014-2019 Franco Fichtner
* Copyright (C) 2014 Deciso B.V.
+ * Copyright (C) 2010 Ermal Luçi
+ * Copyright (C) 2005-2006 Colin Smith
* Copyright (C) 2004 Scott Ullrich
* Copyright (C) 2003-2004 Manuel Kasper
* All rights reserved.
@@ -82,7 +84,6 @@ function get_themed_filename($url)
return $url; // not found, return source
}
-
require_once("authgui.inc");
/* Reserved table names to avoid colision */
@@ -95,7 +96,6 @@ $reserved_table_names = array(
"webConfiguratorlockout"
);
-
$netbios_nodetypes = array(
'0' => "none",
'1' => "b-node",
@@ -562,3 +562,61 @@ function get_menu_messages()
return $menu_messages;
}
+
+function service_control_icon($service, $xs = false)
+{
+ $output = '';
+
+ if (service_status($service)) {
+ $output .= '' . PHP_EOL;
+ } else {
+ $output .= '' . PHP_EOL;
+ }
+
+ return sprintf($output, $xs ? 'xs' : 'sm');
+}
+
+function service_control_links($service, $xs = false)
+{
+ $service_id = isset($service['id']) ? $service['id'] : '';
+
+ $template = '