1 |
c83068f6
|
Colin Smith
|
<?php
|
2 |
09221bc3
|
Renato Botelho
|
/*
|
3 |
ac24dc24
|
Renato Botelho
|
* service-utils.inc
|
4 |
|
|
*
|
5 |
|
|
* part of pfSense (https://www.pfsense.org)
|
6 |
38809d47
|
Renato Botelho do Couto
|
* Copyright (c) 2005-2013 BSD Perimeter
|
7 |
|
|
* Copyright (c) 2013-2016 Electric Sheep Fencing
|
8 |
37d60e23
|
Luiz Souza
|
* Copyright (c) 2014-2025 Rubicon Communications, LLC (Netgate)
|
9 |
c5d81585
|
Renato Botelho
|
* Copyright (c) 2005-2006 Colin Smith (ethethlay@gmail.com)
|
10 |
ac24dc24
|
Renato Botelho
|
* All rights reserved.
|
11 |
|
|
*
|
12 |
b12ea3fb
|
Renato Botelho
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
13 |
|
|
* you may not use this file except in compliance with the License.
|
14 |
|
|
* You may obtain a copy of the License at
|
15 |
ac24dc24
|
Renato Botelho
|
*
|
16 |
b12ea3fb
|
Renato Botelho
|
* http://www.apache.org/licenses/LICENSE-2.0
|
17 |
ac24dc24
|
Renato Botelho
|
*
|
18 |
b12ea3fb
|
Renato Botelho
|
* Unless required by applicable law or agreed to in writing, software
|
19 |
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
20 |
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
21 |
|
|
* See the License for the specific language governing permissions and
|
22 |
|
|
* limitations under the License.
|
23 |
ac24dc24
|
Renato Botelho
|
*/
|
24 |
c83068f6
|
Colin Smith
|
|
25 |
ee6e6011
|
jim-p
|
require_once("captiveportal.inc");
|
26 |
e3f68ab9
|
doktornotor
|
require_once("globals.inc");
|
27 |
|
|
require_once("gwlb.inc");
|
28 |
ee6e6011
|
jim-p
|
require_once("ipsec.inc");
|
29 |
e3f68ab9
|
doktornotor
|
require_once("openvpn.inc");
|
30 |
|
|
require_once("system.inc");
|
31 |
|
|
require_once("util.inc");
|
32 |
ee6e6011
|
jim-p
|
require_once("vpn.inc");
|
33 |
523855b0
|
Scott Ullrich
|
|
34 |
e9d66ed4
|
phildd
|
define("RCFILEPREFIX", "/usr/local/etc/rc.d/");
|
35 |
c83068f6
|
Colin Smith
|
function write_rcfile($params) {
|
36 |
c2151973
|
Ermal
|
global $g;
|
37 |
af799b48
|
Renato Botelho
|
|
38 |
6f931ad2
|
Phil Davis
|
safe_mkdir(RCFILEPREFIX);
|
39 |
e9d66ed4
|
phildd
|
$rcfile_fullname = RCFILEPREFIX . $params['file'];
|
40 |
61e047a5
|
Phil Davis
|
if (!file_exists($rcfile_fullname) && !is_link($rcfile_fullname) && !touch($rcfile_fullname)) {
|
41 |
af799b48
|
Renato Botelho
|
return false;
|
42 |
61e047a5
|
Phil Davis
|
}
|
43 |
c2151973
|
Ermal
|
|
44 |
61e047a5
|
Phil Davis
|
if (!is_writable($rcfile_fullname) || empty($params['start'])) {
|
45 |
ba8495f0
|
Ermal
|
return false;
|
46 |
61e047a5
|
Phil Davis
|
}
|
47 |
af799b48
|
Renato Botelho
|
|
48 |
ba8495f0
|
Ermal
|
$towrite = "#!/bin/sh\n";
|
49 |
573ec19d
|
Renato Botelho do Couto
|
$towrite .= "# This file was automatically generated\n# by the {$g['product_label']} service handler.\n\n";
|
50 |
ba8495f0
|
Ermal
|
|
51 |
c83068f6
|
Colin Smith
|
/* write our rc functions */
|
52 |
ba8495f0
|
Ermal
|
$towrite .= "rc_start() {\n";
|
53 |
|
|
$towrite .= "\t{$params['start']}\n";
|
54 |
|
|
$towrite .= "}\n\n";
|
55 |
61e047a5
|
Phil Davis
|
if (!empty($params['stop'])) {
|
56 |
c6c398c6
|
jim-p
|
$tokill = &$params['stop'];
|
57 |
61e047a5
|
Phil Davis
|
} else if (!empty($params['executable'])) {
|
58 |
a8dbad89
|
Colin Smith
|
/* just nuke the executable */
|
59 |
873c1701
|
Renato Botelho
|
$tokill = "/usr/bin/killall " . escapeshellarg($params['executable']);
|
60 |
c83068f6
|
Colin Smith
|
} else {
|
61 |
a8dbad89
|
Colin Smith
|
/* make an educated guess (bad) */
|
62 |
d900b9d4
|
Marcos Mendoza
|
$tokill = explode(' ', $params['start']);
|
63 |
|
|
$tokill = array_pop(explode('/', array_shift($tokill)));
|
64 |
c83068f6
|
Colin Smith
|
}
|
65 |
ba8495f0
|
Ermal
|
$towrite .= "rc_stop() {\n";
|
66 |
|
|
$towrite .= "\t{$tokill}\n";
|
67 |
|
|
$towrite .= "}\n\n";
|
68 |
4e2a765a
|
Viktor G
|
if (!empty($params['restart'])) {
|
69 |
|
|
$torestart = &$params['restart'];
|
70 |
|
|
} else {
|
71 |
bfa801a6
|
Viktor G
|
$torestart = "\trc_stop\n";
|
72 |
|
|
$torestart .= "\trc_start\n";
|
73 |
4e2a765a
|
Viktor G
|
}
|
74 |
|
|
$towrite .= "rc_restart() {\n";
|
75 |
bfa801a6
|
Viktor G
|
$towrite .= "{$torestart}\n";
|
76 |
4e2a765a
|
Viktor G
|
$towrite .= "}\n\n";
|
77 |
4685e464
|
Scott Ullrich
|
|
78 |
c83068f6
|
Colin Smith
|
/* begin rcfile logic */
|
79 |
4e2a765a
|
Viktor G
|
$towrite .= "case \$1 in\n\tstart)\n\t\trc_start\n\t\t;;\n\tstop)\n\t\trc_stop\n\t\t;;\n\trestart)\n\t\trc_restart\n\t\t;;\nesac\n\n";
|
80 |
ba8495f0
|
Ermal
|
|
81 |
44b19298
|
Ermal
|
@file_put_contents($rcfile_fullname, $towrite);
|
82 |
|
|
unset($towrite);
|
83 |
e9d66ed4
|
phildd
|
@chmod("{$rcfile_fullname}", 0755);
|
84 |
ba8495f0
|
Ermal
|
|
85 |
c83068f6
|
Colin Smith
|
return;
|
86 |
|
|
}
|
87 |
31f346a8
|
Colin Smith
|
|
88 |
880107d2
|
jim-p
|
function start_service($name, $after_sync = false) {
|
89 |
61e047a5
|
Phil Davis
|
if (empty($name)) {
|
90 |
b27ade8e
|
Ermal
|
return;
|
91 |
61e047a5
|
Phil Davis
|
}
|
92 |
b27ade8e
|
Ermal
|
|
93 |
d2e806c4
|
jim-p
|
foreach (config_get_path('installedpackages/service', []) as $service) {
|
94 |
|
|
if (empty($service)) {
|
95 |
|
|
continue;
|
96 |
|
|
}
|
97 |
|
|
if (isset($service['name']) && (strtolower($service['name']) == strtolower($name))) {
|
98 |
|
|
/* Avoid starting twice if this is called just after a
|
99 |
|
|
* package sync which starts the service itself. */
|
100 |
|
|
if ($after_sync && isset($service['starts_on_sync'])) {
|
101 |
|
|
break;
|
102 |
|
|
}
|
103 |
|
|
if ($service['rcfile']) {
|
104 |
|
|
$prefix = RCFILEPREFIX;
|
105 |
|
|
if (!empty($service['prefix'])) {
|
106 |
|
|
$prefix = &$service['prefix'];
|
107 |
31f346a8
|
Colin Smith
|
}
|
108 |
d2e806c4
|
jim-p
|
if (file_exists("{$prefix}{$service['rcfile']}") || is_link("{$prefix}{$service['rcfile']}")) {
|
109 |
|
|
mwexec_bg("{$prefix}{$service['rcfile']} start");
|
110 |
61e047a5
|
Phil Davis
|
}
|
111 |
31f346a8
|
Colin Smith
|
}
|
112 |
d2e806c4
|
jim-p
|
if (!empty($service['startcmd'])) {
|
113 |
|
|
eval($service['startcmd']);
|
114 |
|
|
}
|
115 |
|
|
break;
|
116 |
31f346a8
|
Colin Smith
|
}
|
117 |
|
|
}
|
118 |
|
|
}
|
119 |
|
|
|
120 |
58826c73
|
Colin Smith
|
function stop_service($name) {
|
121 |
61e047a5
|
Phil Davis
|
if (empty($name)) {
|
122 |
8bf2e9e5
|
Ermal
|
return;
|
123 |
61e047a5
|
Phil Davis
|
}
|
124 |
8bf2e9e5
|
Ermal
|
|
125 |
d2e806c4
|
jim-p
|
foreach (config_get_path('installedpackages/service', []) as $service) {
|
126 |
|
|
if (empty($service)) {
|
127 |
|
|
continue;
|
128 |
|
|
}
|
129 |
|
|
if (strtolower($service['name']) == strtolower($name)) {
|
130 |
|
|
if ($service['rcfile']) {
|
131 |
|
|
$prefix = RCFILEPREFIX;
|
132 |
|
|
if (!empty($service['prefix'])) {
|
133 |
|
|
$prefix = &$service['prefix'];
|
134 |
cd72ded3
|
Timo Boettcher
|
}
|
135 |
d2e806c4
|
jim-p
|
if (file_exists("{$prefix}{$service['rcfile']}") || is_link("{$prefix}{$service['rcfile']}")) {
|
136 |
|
|
mwexec("{$prefix}{$service['rcfile']} stop");
|
137 |
61e047a5
|
Phil Davis
|
}
|
138 |
d2e806c4
|
jim-p
|
return;
|
139 |
cd72ded3
|
Timo Boettcher
|
}
|
140 |
d2e806c4
|
jim-p
|
if (!empty($service['stopcmd'])) {
|
141 |
|
|
eval($service['stopcmd']);
|
142 |
|
|
} elseif (!empty($service['executable'])) {
|
143 |
|
|
mwexec("/usr/bin/killall " . escapeshellarg($service['executable']));
|
144 |
|
|
}
|
145 |
|
|
|
146 |
|
|
break;
|
147 |
cd72ded3
|
Timo Boettcher
|
}
|
148 |
|
|
}
|
149 |
31f346a8
|
Colin Smith
|
}
|
150 |
|
|
|
151 |
58826c73
|
Colin Smith
|
function restart_service($name) {
|
152 |
61e047a5
|
Phil Davis
|
if (empty($name)) {
|
153 |
8bf2e9e5
|
Ermal
|
return;
|
154 |
61e047a5
|
Phil Davis
|
}
|
155 |
8bf2e9e5
|
Ermal
|
|
156 |
6855f25d
|
doktornotor
|
if (is_service_running($name)) {
|
157 |
|
|
stop_service($name);
|
158 |
|
|
}
|
159 |
636ab238
|
Colin Smith
|
start_service($name);
|
160 |
ba8495f0
|
Ermal
|
|
161 |
d2e806c4
|
jim-p
|
foreach (config_get_path('installedpackages/service', []) as $service) {
|
162 |
|
|
if (empty($service)) {
|
163 |
|
|
continue;
|
164 |
|
|
}
|
165 |
|
|
if (strtolower($service['name']) == strtolower($name)) {
|
166 |
|
|
if ($service['restartcmd']) {
|
167 |
|
|
eval($service['restartcmd']);
|
168 |
cd72ded3
|
Timo Boettcher
|
}
|
169 |
d2e806c4
|
jim-p
|
break;
|
170 |
cd72ded3
|
Timo Boettcher
|
}
|
171 |
|
|
}
|
172 |
31f346a8
|
Colin Smith
|
}
|
173 |
ec4e071a
|
Colin Smith
|
|
174 |
cd72ded3
|
Timo Boettcher
|
function is_pid_running($pidfile) {
|
175 |
61e047a5
|
Phil Davis
|
if (!file_exists($pidfile)) {
|
176 |
ba8495f0
|
Ermal
|
return false;
|
177 |
61e047a5
|
Phil Davis
|
}
|
178 |
ba8495f0
|
Ermal
|
|
179 |
17098641
|
Ermal
|
return (isvalidpid($pidfile));
|
180 |
cd72ded3
|
Timo Boettcher
|
}
|
181 |
|
|
|
182 |
8ff8520f
|
Scott Ullrich
|
function is_dhcp_running($interface) {
|
183 |
fda8dc28
|
Seth Mos
|
$status = find_dhclient_process($interface);
|
184 |
61e047a5
|
Phil Davis
|
if ($status != 0) {
|
185 |
ca88e48f
|
Scott Ullrich
|
return true;
|
186 |
61e047a5
|
Phil Davis
|
}
|
187 |
ca88e48f
|
Scott Ullrich
|
return false;
|
188 |
8ff8520f
|
Scott Ullrich
|
}
|
189 |
|
|
|
190 |
0661a033
|
Colin Smith
|
function restart_service_if_running($service) {
|
191 |
61e047a5
|
Phil Davis
|
if (is_service_running($service)) {
|
192 |
0661a033
|
Colin Smith
|
restart_service($service);
|
193 |
61e047a5
|
Phil Davis
|
}
|
194 |
0661a033
|
Colin Smith
|
return;
|
195 |
|
|
}
|
196 |
|
|
|
197 |
ccfc0269
|
phildd
|
function is_service_enabled($service_name) {
|
198 |
7d7315fb
|
jim-p
|
switch ($service_name) {
|
199 |
|
|
case 'bsnmpd':
|
200 |
|
|
return config_path_enabled('snmpd');
|
201 |
|
|
break;
|
202 |
|
|
case 'dhcrelay':
|
203 |
|
|
return config_path_enabled('dhcrelay');
|
204 |
|
|
break;
|
205 |
|
|
case 'dhcrelay6':
|
206 |
|
|
return config_path_enabled('dhcrelay6');
|
207 |
|
|
break;
|
208 |
|
|
case 'dhcpd':
|
209 |
9bd56e9d
|
Christian McDonald
|
return (dhcp_is_backend('isc') && is_dhcp_server_enabled());
|
210 |
|
|
break;
|
211 |
|
|
case 'kea-dhcp4':
|
212 |
|
|
return (dhcp_is_backend('kea') && is_dhcp_server_enabled());
|
213 |
|
|
break;
|
214 |
|
|
case 'kea-dhcp6':
|
215 |
|
|
return (dhcp_is_backend('kea') && is_dhcpv6_server_enabled());
|
216 |
7d7315fb
|
jim-p
|
break;
|
217 |
|
|
case 'dnsmasq':
|
218 |
|
|
return config_path_enabled('dnsmasq');
|
219 |
|
|
break;
|
220 |
|
|
case 'dpinger':
|
221 |
|
|
/* TODO: Should loop through gateways and check to make
|
222 |
|
|
* sure they don't all have monitoring disabled. */
|
223 |
4bbbcc36
|
Marcos Mendoza
|
return !empty(get_gateways());
|
224 |
7d7315fb
|
jim-p
|
break;
|
225 |
|
|
case 'igmpproxy':
|
226 |
|
|
return (config_path_enabled('igmpproxy') && !empty(config_get_path('igmpproxy/igmpentry', [])));
|
227 |
|
|
break;
|
228 |
|
|
case 'ipsec':
|
229 |
|
|
return ipsec_enabled();
|
230 |
|
|
break;
|
231 |
|
|
case 'miniupnpd':
|
232 |
b573f119
|
jim-p
|
return (config_get_path('installedpackages/miniupnpd/config/0/enable') == 'on');
|
233 |
7d7315fb
|
jim-p
|
break;
|
234 |
|
|
case 'ntpd':
|
235 |
|
|
return (config_get_path('ntpd/enable') != 'disabled');
|
236 |
|
|
break;
|
237 |
|
|
case 'pcscd':
|
238 |
|
|
return config_path_enabled('ipsec', 'pkcs11support');
|
239 |
|
|
break;
|
240 |
|
|
case 'radvd':
|
241 |
|
|
return is_radvd_enabled();
|
242 |
|
|
break;
|
243 |
|
|
case 'sshd':
|
244 |
|
|
return config_path_enabled('system/ssh');
|
245 |
|
|
break;
|
246 |
|
|
case 'syslogd':
|
247 |
|
|
$local_enabled = !config_path_enabled('syslog', 'disablelocallogging');
|
248 |
|
|
$remote_enabled = !empty(system_syslogd_get_remote_servers(config_get_path('syslog', [])));
|
249 |
|
|
return ($local_enabled || $remote_enabled);
|
250 |
|
|
break;
|
251 |
|
|
case 'unbound':
|
252 |
|
|
return config_path_enabled('unbound');
|
253 |
|
|
break;
|
254 |
|
|
default:
|
255 |
5ee97acf
|
jim-p
|
/* Do nothing since we can't determine for certain. */
|
256 |
61e047a5
|
Phil Davis
|
}
|
257 |
7d7315fb
|
jim-p
|
/* TODO: The service name isn't likely to match the config tag,
|
258 |
|
|
* needs better logic or pkg plugin to probe */
|
259 |
|
|
$pkg_enabled = config_get_path("installedpackages/{$service_name}/config/0/enable", null);
|
260 |
|
|
if (($pkg_enabled !== null) &&
|
261 |
|
|
(empty($pkg_enabled) || ($pkg_enabled === 'off'))) {
|
262 |
5ee97acf
|
jim-p
|
/* Only return false for cases where the config area exists and
|
263 |
|
|
* appears to be disabled. */
|
264 |
d2e806c4
|
jim-p
|
return false;
|
265 |
762e8cf9
|
jim-p
|
}
|
266 |
7d7315fb
|
jim-p
|
|
267 |
|
|
/* Unknown service, for compatibility reasons, return true. */
|
268 |
ccfc0269
|
phildd
|
return true;
|
269 |
|
|
}
|
270 |
|
|
|
271 |
fbeb6d02
|
Colin Smith
|
function is_service_running($service, $ps = "") {
|
272 |
d2e806c4
|
jim-p
|
foreach (config_get_path('installedpackages/service', []) as $aservice) {
|
273 |
|
|
if (empty($aservice)) {
|
274 |
|
|
continue;
|
275 |
|
|
}
|
276 |
|
|
if (isset($aservice['name']) && (strtolower($service) == strtolower($aservice['name']))) {
|
277 |
|
|
if ($aservice['custom_php_service_status_command'] <> "") {
|
278 |
|
|
eval("\$rc={$aservice['custom_php_service_status_command']};");
|
279 |
|
|
return $rc;
|
280 |
|
|
}
|
281 |
|
|
if (empty($aservice['executable'])) {
|
282 |
ba8495f0
|
Ermal
|
return false;
|
283 |
cd72ded3
|
Timo Boettcher
|
}
|
284 |
d2e806c4
|
jim-p
|
if (is_process_running($aservice['executable'])) {
|
285 |
|
|
return true;
|
286 |
|
|
}
|
287 |
|
|
return false;
|
288 |
cd72ded3
|
Timo Boettcher
|
}
|
289 |
|
|
}
|
290 |
61e047a5
|
Phil Davis
|
if (is_process_running($service)) {
|
291 |
ba8495f0
|
Ermal
|
return true;
|
292 |
61e047a5
|
Phil Davis
|
}
|
293 |
ba8495f0
|
Ermal
|
return false;
|
294 |
ec4e071a
|
Colin Smith
|
}
|
295 |
ff074bf9
|
Scott Ullrich
|
|
296 |
e48cdc01
|
jim-p
|
function get_services() {
|
297 |
d2e806c4
|
jim-p
|
$services = config_get_path('installedpackages/service', []);
|
298 |
|
|
|
299 |
|
|
/* Clean up any empty services */
|
300 |
|
|
foreach ($services as $k => &$s) {
|
301 |
|
|
if (empty($s)) {
|
302 |
|
|
config_del_path('installedpackages/services/' . $k);
|
303 |
|
|
unset($s);
|
304 |
|
|
}
|
305 |
61e047a5
|
Phil Davis
|
}
|
306 |
e48cdc01
|
jim-p
|
|
307 |
61e047a5
|
Phil Davis
|
/*
|
308 |
|
|
* Add services that are in the base.
|
309 |
e48cdc01
|
jim-p
|
*/
|
310 |
33232486
|
Warren Baker
|
if (is_radvd_enabled()) {
|
311 |
e48cdc01
|
jim-p
|
$pconfig = array();
|
312 |
|
|
$pconfig['name'] = "radvd";
|
313 |
|
|
$pconfig['description'] = gettext("Router Advertisement Daemon");
|
314 |
7d7315fb
|
jim-p
|
$pconfig['enabled'] = true;
|
315 |
f2b9ea9a
|
Steve Beaver
|
$pconfig['status'] = get_service_status($pconfig);
|
316 |
e48cdc01
|
jim-p
|
$services[] = $pconfig;
|
317 |
|
|
}
|
318 |
|
|
|
319 |
d2e806c4
|
jim-p
|
if (config_path_enabled('dnsmasq')) {
|
320 |
e48cdc01
|
jim-p
|
$pconfig = array();
|
321 |
|
|
$pconfig['name'] = "dnsmasq";
|
322 |
|
|
$pconfig['description'] = gettext("DNS Forwarder");
|
323 |
7d7315fb
|
jim-p
|
$pconfig['enabled'] = true;
|
324 |
f2b9ea9a
|
Steve Beaver
|
$pconfig['status'] = get_service_status($pconfig);
|
325 |
e48cdc01
|
jim-p
|
$services[] = $pconfig;
|
326 |
|
|
}
|
327 |
|
|
|
328 |
d2e806c4
|
jim-p
|
if (config_path_enabled('unbound')) {
|
329 |
33232486
|
Warren Baker
|
$pconfig = array();
|
330 |
|
|
$pconfig['name'] = "unbound";
|
331 |
a3fb1412
|
Phil Davis
|
$pconfig['description'] = gettext("DNS Resolver");
|
332 |
7d7315fb
|
jim-p
|
$pconfig['enabled'] = true;
|
333 |
f2b9ea9a
|
Steve Beaver
|
$pconfig['status'] = get_service_status($pconfig);
|
334 |
33232486
|
Warren Baker
|
$services[] = $pconfig;
|
335 |
|
|
}
|
336 |
|
|
|
337 |
d2e806c4
|
jim-p
|
if (config_path_enabled('ipsec', 'pkcs11support')) {
|
338 |
013cbaaa
|
Viktor G
|
$pconfig = array();
|
339 |
|
|
$pconfig['name'] = "pcscd";
|
340 |
|
|
$pconfig['description'] = gettext("PC/SC Smart Card Daemon");
|
341 |
7d7315fb
|
jim-p
|
$pconfig['enabled'] = true;
|
342 |
013cbaaa
|
Viktor G
|
$pconfig['status'] = get_service_status($pconfig);
|
343 |
|
|
$services[] = $pconfig;
|
344 |
|
|
}
|
345 |
e881843a
|
Viktor Gurov
|
|
346 |
d2e806c4
|
jim-p
|
if (config_get_path('ntpd/enable') != 'disabled') {
|
347 |
b5d5da0c
|
Viktor Gurov
|
$pconfig = array();
|
348 |
|
|
$pconfig['name'] = "ntpd";
|
349 |
|
|
$pconfig['description'] = gettext("NTP clock sync");
|
350 |
7d7315fb
|
jim-p
|
$pconfig['enabled'] = true;
|
351 |
f2b9ea9a
|
Steve Beaver
|
$pconfig['status'] = get_service_status($pconfig);
|
352 |
b5d5da0c
|
Viktor Gurov
|
$services[] = $pconfig;
|
353 |
|
|
}
|
354 |
e48cdc01
|
jim-p
|
|
355 |
e3f68ab9
|
doktornotor
|
$pconfig = array();
|
356 |
|
|
$pconfig['name'] = "syslogd";
|
357 |
|
|
$pconfig['description'] = gettext("System Logger Daemon");
|
358 |
f2b9ea9a
|
Steve Beaver
|
$pconfig['enabled'] = is_service_enabled("syslogd");
|
359 |
|
|
$pconfig['status'] = get_service_status($pconfig);
|
360 |
e3f68ab9
|
doktornotor
|
$services[] = $pconfig;
|
361 |
|
|
|
362 |
d2e806c4
|
jim-p
|
foreach (config_get_path('captiveportal', []) as $zone => $setting) {
|
363 |
|
|
if (empty($setting)) {
|
364 |
|
|
continue;
|
365 |
|
|
}
|
366 |
|
|
if (isset($setting['enable'])) {
|
367 |
|
|
$pconfig = array();
|
368 |
|
|
$pconfig['name'] = "captiveportal";
|
369 |
|
|
$pconfig['zone'] = $zone;
|
370 |
7d7315fb
|
jim-p
|
$pconfig['enabled'] = true;
|
371 |
68ef1115
|
Marcos Mendoza
|
$pconfig['description'] = gettext("Captive Portal") . ": " . htmlspecialchars($zone . ($setting['descr'] ? " ({$setting['descr']})" : ''));
|
372 |
d2e806c4
|
jim-p
|
$services[] = $pconfig;
|
373 |
e48cdc01
|
jim-p
|
}
|
374 |
|
|
}
|
375 |
|
|
|
376 |
|
|
$iflist = array();
|
377 |
|
|
$ifdescrs = get_configured_interface_list();
|
378 |
|
|
foreach ($ifdescrs as $if) {
|
379 |
d2e806c4
|
jim-p
|
if (config_get_path("interfaces/{$if}/if") &&
|
380 |
|
|
!link_interface_to_bridge($if)) {
|
381 |
e48cdc01
|
jim-p
|
$iflist[$if] = $if;
|
382 |
61e047a5
|
Phil Davis
|
}
|
383 |
e48cdc01
|
jim-p
|
}
|
384 |
|
|
|
385 |
d2e806c4
|
jim-p
|
if (config_path_enabled('dhcrelay')) {
|
386 |
e48cdc01
|
jim-p
|
$pconfig = array();
|
387 |
|
|
$pconfig['name'] = "dhcrelay";
|
388 |
9bd56e9d
|
Christian McDonald
|
$pconfig['description'] = gettext('ISC DHCP Relay');
|
389 |
7d7315fb
|
jim-p
|
$pconfig['enabled'] = true;
|
390 |
f2b9ea9a
|
Steve Beaver
|
$pconfig['status'] = get_service_status($pconfig);
|
391 |
e48cdc01
|
jim-p
|
$services[] = $pconfig;
|
392 |
|
|
}
|
393 |
|
|
|
394 |
d2e806c4
|
jim-p
|
if (config_path_enabled('dhcrelay6')) {
|
395 |
9590e0de
|
Phil Davis
|
$pconfig = array();
|
396 |
|
|
$pconfig['name'] = "dhcrelay6";
|
397 |
9bd56e9d
|
Christian McDonald
|
$pconfig['description'] = gettext('ISC DHCPv6 Relay');
|
398 |
7d7315fb
|
jim-p
|
$pconfig['enabled'] = true;
|
399 |
f2b9ea9a
|
Steve Beaver
|
$pconfig['status'] = get_service_status($pconfig);
|
400 |
9590e0de
|
Phil Davis
|
$services[] = $pconfig;
|
401 |
|
|
}
|
402 |
|
|
|
403 |
9bd56e9d
|
Christian McDonald
|
if (dhcp_is_backend('isc') && is_dhcp_server_enabled()) {
|
404 |
e48cdc01
|
jim-p
|
$pconfig = array();
|
405 |
|
|
$pconfig['name'] = "dhcpd";
|
406 |
9bd56e9d
|
Christian McDonald
|
$pconfig['description'] = gettext('ISC DHCP Server');
|
407 |
|
|
$pconfig['enabled'] = true;
|
408 |
|
|
$pconfig['status'] = get_service_status($pconfig);
|
409 |
|
|
$services[] = $pconfig;
|
410 |
|
|
}
|
411 |
|
|
|
412 |
|
|
if (dhcp_is_backend('kea') && is_dhcp_server_enabled()) {
|
413 |
|
|
$pconfig = array();
|
414 |
|
|
$pconfig['name'] = 'kea-dhcp4';
|
415 |
|
|
$pconfig['description'] = gettext('Kea DHCP Server');
|
416 |
|
|
$pconfig['enabled'] = true;
|
417 |
|
|
$pconfig['status'] = get_service_status($pconfig);
|
418 |
|
|
$services[] = $pconfig;
|
419 |
|
|
}
|
420 |
|
|
|
421 |
|
|
if (dhcp_is_backend('kea') && is_dhcpv6_server_enabled()) {
|
422 |
|
|
$pconfig = array();
|
423 |
|
|
$pconfig['name'] = 'kea-dhcp6';
|
424 |
|
|
$pconfig['description'] = gettext('Kea DHCPv6 Server');
|
425 |
7d7315fb
|
jim-p
|
$pconfig['enabled'] = true;
|
426 |
f2b9ea9a
|
Steve Beaver
|
$pconfig['status'] = get_service_status($pconfig);
|
427 |
e48cdc01
|
jim-p
|
$services[] = $pconfig;
|
428 |
|
|
}
|
429 |
|
|
|
430 |
4bbbcc36
|
Marcos Mendoza
|
if (!empty(get_gateways())) {
|
431 |
b05a8f35
|
jim-p
|
$pconfig = array();
|
432 |
69eefb50
|
Renato Botelho
|
$pconfig['name'] = "dpinger";
|
433 |
b05a8f35
|
jim-p
|
$pconfig['description'] = gettext("Gateway Monitoring Daemon");
|
434 |
f2b9ea9a
|
Steve Beaver
|
$pconfig['enabled'] = is_service_enabled("dpinger");
|
435 |
|
|
$pconfig['status'] = get_service_status($pconfig);
|
436 |
b05a8f35
|
jim-p
|
$services[] = $pconfig;
|
437 |
|
|
}
|
438 |
|
|
|
439 |
d2e806c4
|
jim-p
|
if (config_path_enabled('snmpd')) {
|
440 |
e48cdc01
|
jim-p
|
$pconfig = array();
|
441 |
|
|
$pconfig['name'] = "bsnmpd";
|
442 |
|
|
$pconfig['description'] = gettext("SNMP Service");
|
443 |
7d7315fb
|
jim-p
|
$pconfig['enabled'] = true;
|
444 |
f2b9ea9a
|
Steve Beaver
|
$pconfig['status'] = get_service_status($pconfig);
|
445 |
e48cdc01
|
jim-p
|
$services[] = $pconfig;
|
446 |
|
|
}
|
447 |
|
|
|
448 |
d2e806c4
|
jim-p
|
if (!empty(config_get_path('igmpproxy/igmpentry', []))) {
|
449 |
e48cdc01
|
jim-p
|
$pconfig = array();
|
450 |
|
|
$pconfig['name'] = "igmpproxy";
|
451 |
|
|
$pconfig['description'] = gettext("IGMP proxy");
|
452 |
f2b9ea9a
|
Steve Beaver
|
$pconfig['enabled'] = is_service_enabled("igmpproxy");
|
453 |
|
|
$pconfig['status'] = get_service_status($pconfig);
|
454 |
e48cdc01
|
jim-p
|
$services[] = $pconfig;
|
455 |
|
|
}
|
456 |
|
|
|
457 |
b573f119
|
jim-p
|
if (config_get_path('installedpackages/miniupnpd/config/0/enable') == 'on') {
|
458 |
e48cdc01
|
jim-p
|
$pconfig = array();
|
459 |
|
|
$pconfig['name'] = "miniupnpd";
|
460 |
ada8c696
|
Self-Hosting-Group
|
$pconfig['description'] = gettext("UPnP IGD & PCP Service");
|
461 |
7d7315fb
|
jim-p
|
$pconfig['enabled'] = true;
|
462 |
f2b9ea9a
|
Steve Beaver
|
$pconfig['status'] = get_service_status($pconfig);
|
463 |
e48cdc01
|
jim-p
|
$services[] = $pconfig;
|
464 |
|
|
}
|
465 |
|
|
|
466 |
dc0f709e
|
Luiz Otavio O Souza
|
if (ipsec_enabled()) {
|
467 |
e48cdc01
|
jim-p
|
$pconfig = array();
|
468 |
8b4abd59
|
Ermal
|
$pconfig['name'] = "ipsec";
|
469 |
e48cdc01
|
jim-p
|
$pconfig['description'] = gettext("IPsec VPN");
|
470 |
7d7315fb
|
jim-p
|
$pconfig['enabled'] = true;
|
471 |
f2b9ea9a
|
Steve Beaver
|
$pconfig['status'] = get_service_status($pconfig);
|
472 |
e48cdc01
|
jim-p
|
$services[] = $pconfig;
|
473 |
|
|
}
|
474 |
|
|
|
475 |
d2e806c4
|
jim-p
|
if (config_path_enabled('system/ssh')) {
|
476 |
aaa78416
|
jim-p
|
$pconfig = array();
|
477 |
|
|
$pconfig['name'] = "sshd";
|
478 |
|
|
$pconfig['description'] = gettext("Secure Shell Daemon");
|
479 |
7d7315fb
|
jim-p
|
$pconfig['enabled'] = true;
|
480 |
f2b9ea9a
|
Steve Beaver
|
$pconfig['status'] = get_service_status($pconfig);
|
481 |
aaa78416
|
jim-p
|
$services[] = $pconfig;
|
482 |
|
|
}
|
483 |
|
|
|
484 |
e48cdc01
|
jim-p
|
foreach (array('server', 'client') as $mode) {
|
485 |
d2e806c4
|
jim-p
|
foreach (config_get_path("openvpn/openvpn-{$mode}", []) as $id => $setting) {
|
486 |
|
|
if (!isset($setting['disable'])) {
|
487 |
|
|
$pconfig = array();
|
488 |
|
|
$pconfig['name'] = "openvpn";
|
489 |
|
|
$pconfig['mode'] = $mode;
|
490 |
|
|
$pconfig['id'] = $id;
|
491 |
|
|
$pconfig['vpnid'] = $setting['vpnid'];
|
492 |
|
|
$pconfig['description'] = gettext("OpenVPN") . " " . $mode . ": " . htmlspecialchars($setting['description']);
|
493 |
7d7315fb
|
jim-p
|
$pconfig['enabled'] = true;
|
494 |
d2e806c4
|
jim-p
|
$pconfig['status'] = get_service_status($pconfig);
|
495 |
|
|
$services[] = $pconfig;
|
496 |
e48cdc01
|
jim-p
|
}
|
497 |
|
|
}
|
498 |
|
|
}
|
499 |
|
|
|
500 |
|
|
return $services;
|
501 |
|
|
}
|
502 |
|
|
|
503 |
76692ad2
|
jim-p
|
function find_service_by_name($name) {
|
504 |
|
|
$services = get_services();
|
505 |
61e047a5
|
Phil Davis
|
foreach ($services as $service) {
|
506 |
144863e3
|
jim-p
|
if (isset($service["name"]) && ($service["name"] == $name)) {
|
507 |
76692ad2
|
jim-p
|
return $service;
|
508 |
61e047a5
|
Phil Davis
|
}
|
509 |
|
|
}
|
510 |
76692ad2
|
jim-p
|
return array();
|
511 |
|
|
}
|
512 |
|
|
|
513 |
6d9b1074
|
jim-p
|
function find_service_by_openvpn_vpnid($vpnid) {
|
514 |
|
|
$services = get_services();
|
515 |
61e047a5
|
Phil Davis
|
foreach ($services as $service) {
|
516 |
144863e3
|
jim-p
|
if (isset($service["name"]) && ($service["name"] == "openvpn") && isset($service["vpnid"]) && ($service["vpnid"] == $vpnid)) {
|
517 |
6d9b1074
|
jim-p
|
return $service;
|
518 |
61e047a5
|
Phil Davis
|
}
|
519 |
|
|
}
|
520 |
6d9b1074
|
jim-p
|
return array();
|
521 |
|
|
}
|
522 |
|
|
|
523 |
|
|
function find_service_by_cp_zone($zone) {
|
524 |
|
|
$services = get_services();
|
525 |
61e047a5
|
Phil Davis
|
foreach ($services as $service) {
|
526 |
144863e3
|
jim-p
|
if (isset($service["name"]) && ($service["name"] == "captiveportal") && isset($service["zone"]) && ($service["zone"] == $zone)) {
|
527 |
6d9b1074
|
jim-p
|
return $service;
|
528 |
61e047a5
|
Phil Davis
|
}
|
529 |
|
|
}
|
530 |
6d9b1074
|
jim-p
|
return array();
|
531 |
|
|
}
|
532 |
|
|
|
533 |
258fc75b
|
jim-p
|
function service_description_compare($a, $b) {
|
534 |
|
|
if (strtolower($a['description']) == strtolower($b['description'])) {
|
535 |
|
|
return 0;
|
536 |
|
|
}
|
537 |
|
|
return (strtolower($a['description']) < strtolower($b['description'])) ? -1 : 1;
|
538 |
|
|
}
|
539 |
|
|
|
540 |
e48cdc01
|
jim-p
|
function service_name_compare($a, $b) {
|
541 |
144863e3
|
jim-p
|
if (!isset($a['name']) || !isset($b['name'])) {
|
542 |
|
|
return -1;
|
543 |
|
|
}
|
544 |
258fc75b
|
jim-p
|
/* If the names are equal, fall back to sorting by description */
|
545 |
61e047a5
|
Phil Davis
|
if (strtolower($a['name']) == strtolower($b['name'])) {
|
546 |
258fc75b
|
jim-p
|
return service_description_compare($a, $b);
|
547 |
61e047a5
|
Phil Davis
|
}
|
548 |
e48cdc01
|
jim-p
|
return (strtolower($a['name']) < strtolower($b['name'])) ? -1 : 1;
|
549 |
|
|
}
|
550 |
|
|
|
551 |
095edfeb
|
Stephen Beaver
|
function service_dispname_compare($a, $b) {
|
552 |
258fc75b
|
jim-p
|
/* If two items have an instance suffix, perform an integer comparison to avoid awkward sorting */
|
553 |
|
|
if ((strpos($a['dispname'], '_') > 0) && (strpos($b['dispname'], '_') > 0)) {
|
554 |
|
|
list($adn1, $adn2) = explode('_', $a['dispname'], 2);
|
555 |
|
|
list($bdn1, $bdn2) = explode('_', $b['dispname'], 2);
|
556 |
|
|
if (($adn1 == $bdn1) && is_numeric($adn2) && is_numeric($bdn2)) {
|
557 |
|
|
if ($adn2 == $bdn2) {
|
558 |
|
|
return 0;
|
559 |
|
|
}
|
560 |
|
|
return ((int)$adn2 < (int)$bdn2) ? -1 : 1;
|
561 |
|
|
}
|
562 |
|
|
}
|
563 |
|
|
/* If the display names are equal, compare the internal name */
|
564 |
095edfeb
|
Stephen Beaver
|
if (strtolower($a['dispname']) == strtolower($b['dispname'])) {
|
565 |
258fc75b
|
jim-p
|
return service_name_compare($a, $b);
|
566 |
095edfeb
|
Stephen Beaver
|
}
|
567 |
258fc75b
|
jim-p
|
return (strtolower($a['dispname']) < strtolower($b['dispname'])) ? -1 : 1;
|
568 |
095edfeb
|
Stephen Beaver
|
}
|
569 |
|
|
|
570 |
e48cdc01
|
jim-p
|
function get_pkg_descr($package_name) {
|
571 |
d2e806c4
|
jim-p
|
foreach (config_get_path('installedpackages/package', []) as $pkg) {
|
572 |
|
|
if ($pkg['name'] == $package_name) {
|
573 |
|
|
return $pkg['descr'];
|
574 |
e48cdc01
|
jim-p
|
}
|
575 |
|
|
}
|
576 |
|
|
return gettext("Not available.");
|
577 |
|
|
}
|
578 |
|
|
|
579 |
|
|
function get_service_status($service) {
|
580 |
|
|
global $g;
|
581 |
|
|
switch ($service['name']) {
|
582 |
|
|
case "openvpn":
|
583 |
|
|
$running = is_pid_running("{$g['varrun_path']}/openvpn_{$service['mode']}{$service['vpnid']}.pid");
|
584 |
|
|
break;
|
585 |
|
|
case "captiveportal":
|
586 |
cd41643d
|
Renato Botelho
|
$running = is_pid_running("{$g['varrun_path']}/nginx-{$service['zone']}-CaptivePortal.pid");
|
587 |
d2e806c4
|
jim-p
|
if (config_path_enabled("captiveportal/{$service['zone']}", 'httpslogin')) {
|
588 |
cd41643d
|
Renato Botelho
|
$running = $running && is_pid_running("{$g['varrun_path']}/nginx-{$service['zone']}-CaptivePortal-SSL.pid");
|
589 |
61e047a5
|
Phil Davis
|
}
|
590 |
e48cdc01
|
jim-p
|
break;
|
591 |
18725085
|
Ermal
|
case "vhosts-http":
|
592 |
|
|
$running = is_pid_running("{$g['varrun_path']}/vhosts-http.pid");
|
593 |
|
|
break;
|
594 |
9590e0de
|
Phil Davis
|
case "dhcrelay6":
|
595 |
|
|
$running = is_pid_running("{$g['varrun_path']}/dhcrelay6.pid");
|
596 |
|
|
break;
|
597 |
e381cc01
|
Ermal
|
case 'ipsec':
|
598 |
60e34dde
|
Viktor G
|
$running = (is_pid_running("{$g['varrun_path']}/charon.pid") || is_process_running('charon'));
|
599 |
e381cc01
|
Ermal
|
break;
|
600 |
9bd56e9d
|
Christian McDonald
|
case 'kea-dhcp4':
|
601 |
|
|
$running = is_pid_running('/var/run/kea/kea-dhcp4.kea-dhcp4.pid');
|
602 |
|
|
break;
|
603 |
|
|
case 'kea-dhcp6':
|
604 |
|
|
$running = is_pid_running('/var/run/kea/kea-dhcp6.kea-dhcp6.pid');
|
605 |
|
|
break;
|
606 |
e48cdc01
|
jim-p
|
default:
|
607 |
|
|
$running = is_service_running($service['name']);
|
608 |
|
|
}
|
609 |
|
|
return $running;
|
610 |
|
|
}
|
611 |
|
|
|
612 |
0a9d81fb
|
NOYB
|
function get_service_status_icon($service, $withtext = true, $smallicon = false, $withthumbs = false, $title = "service_state") {
|
613 |
e48cdc01
|
jim-p
|
$output = "";
|
614 |
0a9d81fb
|
NOYB
|
|
615 |
61e047a5
|
Phil Davis
|
if (get_service_status($service)) {
|
616 |
92421710
|
jim-p
|
$statustext = gettext("Running");
|
617 |
0a9d81fb
|
NOYB
|
$text_class = "text-success";
|
618 |
e0cb987c
|
Marcos Mendoza
|
$fa_class = "fa-solid fa-check-circle";
|
619 |
c1d304b3
|
Marcos Mendoza
|
$fa_class_thumbs = "fa-regular fa-thumbs-up";
|
620 |
0a9d81fb
|
NOYB
|
$Thumbs_UpDown = "Thumbs up";
|
621 |
e48cdc01
|
jim-p
|
} else {
|
622 |
0a9d81fb
|
NOYB
|
if (is_service_enabled($service['name'])) {
|
623 |
|
|
$statustext = gettext("Stopped");
|
624 |
|
|
$text_class = "text-danger";
|
625 |
e0cb987c
|
Marcos Mendoza
|
$fa_class = "fa-solid fa-times-circle";
|
626 |
0a9d81fb
|
NOYB
|
} else {
|
627 |
|
|
$statustext = gettext("Disabled");
|
628 |
|
|
$text_class = "text-warning";
|
629 |
e0cb987c
|
Marcos Mendoza
|
$fa_class = "fa-solid fa-ban";
|
630 |
61e047a5
|
Phil Davis
|
}
|
631 |
c1d304b3
|
Marcos Mendoza
|
$fa_class_thumbs = "fa-regular fa-thumbs-down";
|
632 |
0a9d81fb
|
NOYB
|
$Thumbs_UpDown = "Thumbs down";
|
633 |
|
|
}
|
634 |
|
|
$fa_size = ($smallicon) ? "fa-1x" : "fa-lg";
|
635 |
|
|
|
636 |
|
|
if ($title == "state") {
|
637 |
446505a9
|
NOYB
|
$title = $statustext;
|
638 |
0a9d81fb
|
NOYB
|
} elseif ($title == "service_state") {
|
639 |
446505a9
|
NOYB
|
$title = sprintf(gettext('%1$s Service is %2$s'), $service["name"], $statustext);
|
640 |
0a9d81fb
|
NOYB
|
} elseif ($title == "description_state") {
|
641 |
446505a9
|
NOYB
|
$title = sprintf(gettext('%1$s Service is %2$s'), $service["description"], $statustext);
|
642 |
0a9d81fb
|
NOYB
|
} elseif ($title == "description_service_state") {
|
643 |
446505a9
|
NOYB
|
$title = sprintf(gettext('%1$s, %2$s Service is %3$s'), $service["description"], $service["name"], $statustext);
|
644 |
e48cdc01
|
jim-p
|
}
|
645 |
0a9d81fb
|
NOYB
|
|
646 |
446505a9
|
NOYB
|
$spacer = ($withthumbs || $withtext) ? " " : "";
|
647 |
|
|
|
648 |
|
|
$output = "<i class=\"{$text_class} {$fa_class} {$fa_size}\" title=\"{$title}\"><span style=\"display: none\">{$statustext}</span></i>{$spacer}";
|
649 |
|
|
|
650 |
0a9d81fb
|
NOYB
|
$spacer = ($withtext) ? " " : "";
|
651 |
|
|
if ($withthumbs) {
|
652 |
|
|
$output .= "<i class=\"{$text_class} {$fa_class_thumbs} {$fa_size}\" title=\"{$Thumbs_UpDown}\"></i>{$spacer}";
|
653 |
|
|
}
|
654 |
|
|
|
655 |
|
|
if ($withtext) {
|
656 |
|
|
$output .= "<span class=\"" . $text_class . "\">" . $statustext . "</span>";
|
657 |
|
|
}
|
658 |
|
|
|
659 |
e48cdc01
|
jim-p
|
return $output;
|
660 |
|
|
}
|
661 |
|
|
|
662 |
f4daf025
|
jim-p
|
function get_service_control_links($service, $addname = false) {
|
663 |
49840447
|
PiBa-NL
|
global $g;
|
664 |
e48cdc01
|
jim-p
|
$output = "";
|
665 |
f4daf025
|
jim-p
|
$stitle = ($addname) ? $service['name'] . " " : "";
|
666 |
1180e4f0
|
Sjon Hortensius
|
|
667 |
|
|
switch ($service['name']) {
|
668 |
|
|
case "openvpn":
|
669 |
74b0f23e
|
Stephen Beaver
|
$link = '<a title="%s" href="#" id="openvpn-%s-' . $service['mode'] . '-' . $service['vpnid'] . '" >';
|
670 |
1180e4f0
|
Sjon Hortensius
|
break;
|
671 |
|
|
case "captiveportal":
|
672 |
74b0f23e
|
Stephen Beaver
|
$link = '<a title="%s" href="#" id="captiveportal-%s-' . $service['zone'] . '">';
|
673 |
1180e4f0
|
Sjon Hortensius
|
break;
|
674 |
|
|
default:
|
675 |
ab7e04c7
|
Colin Fleming
|
$link = '<a title="%s" href="#" id="%s-' . $service['name'] . '">';
|
676 |
1180e4f0
|
Sjon Hortensius
|
}
|
677 |
|
|
|
678 |
61e047a5
|
Phil Davis
|
if (get_service_status($service)) {
|
679 |
e48cdc01
|
jim-p
|
switch ($service['name']) {
|
680 |
|
|
case "openvpn":
|
681 |
74b0f23e
|
Stephen Beaver
|
$output .= '<a href="#" id="openvpn-restartservice-' . $service['mode'] . '-' . $service['vpnid'] . '" >';
|
682 |
e48cdc01
|
jim-p
|
break;
|
683 |
|
|
case "captiveportal":
|
684 |
ab7e04c7
|
Colin Fleming
|
$output .= '<a href="#" id="captiveportal-restartservice-' . $service['zone'] . '">';
|
685 |
e48cdc01
|
jim-p
|
break;
|
686 |
|
|
default:
|
687 |
74b0f23e
|
Stephen Beaver
|
$output .= '<a href="#" id="restartservice-' . $service['name'] . '" >';
|
688 |
e48cdc01
|
jim-p
|
}
|
689 |
74b0f23e
|
Stephen Beaver
|
|
690 |
c1d304b3
|
Marcos Mendoza
|
$output .= "<i class=\"fa-solid fa-arrow-rotate-right\" title=\"" . sprintf(gettext("Restart %sService"), $stitle) . "\"></i></a>\n";
|
691 |
74b0f23e
|
Stephen Beaver
|
|
692 |
e48cdc01
|
jim-p
|
switch ($service['name']) {
|
693 |
|
|
case "openvpn":
|
694 |
74b0f23e
|
Stephen Beaver
|
$output .= '<a href="#" id="openvpn-stopservice-' . $service['mode'] . '-' . $service['vpnid'] . '" >';
|
695 |
e48cdc01
|
jim-p
|
break;
|
696 |
|
|
case "captiveportal":
|
697 |
ab7e04c7
|
Colin Fleming
|
$output .= '<a href="#" id="captiveportal-stopservice-' . $service['zone'] . '">';
|
698 |
e48cdc01
|
jim-p
|
break;
|
699 |
|
|
default:
|
700 |
74b0f23e
|
Stephen Beaver
|
$output .= '<a href="#" id="stopservice-' . $service['name'] . '">';
|
701 |
e48cdc01
|
jim-p
|
}
|
702 |
74b0f23e
|
Stephen Beaver
|
|
703 |
c1d304b3
|
Marcos Mendoza
|
$output .= "<i class=\"fa-regular fa-circle-stop\" title=\"" . sprintf(gettext("Stop %sService"), $stitle) . "\"></i></a>";
|
704 |
74b0f23e
|
Stephen Beaver
|
|
705 |
e48cdc01
|
jim-p
|
} else {
|
706 |
ccfc0269
|
phildd
|
$service_enabled = is_service_enabled($service['name']);
|
707 |
1180e4f0
|
Sjon Hortensius
|
|
708 |
46bb8a0b
|
Sjon Hortensius
|
if ($service['name'] == 'openvpn' || $service['name'] == 'captiveportal' || $service_enabled) {
|
709 |
1180e4f0
|
Sjon Hortensius
|
$output .= sprintf($link, sprintf(gettext("Start %sService"), $stitle), 'startservice');
|
710 |
e0cb987c
|
Marcos Mendoza
|
$output .= '<i class="fa-solid fa-play-circle"></i></a> ';
|
711 |
e48cdc01
|
jim-p
|
}
|
712 |
|
|
}
|
713 |
1180e4f0
|
Sjon Hortensius
|
|
714 |
e48cdc01
|
jim-p
|
return $output;
|
715 |
|
|
}
|
716 |
ee6e6011
|
jim-p
|
|
717 |
|
|
function service_control_start($name, $extras) {
|
718 |
|
|
global $g;
|
719 |
61e047a5
|
Phil Davis
|
switch ($name) {
|
720 |
ee6e6011
|
jim-p
|
case 'radvd':
|
721 |
|
|
services_radvd_configure();
|
722 |
|
|
break;
|
723 |
|
|
case 'captiveportal':
|
724 |
2f9951fe
|
Renato Botelho
|
$zone = htmlspecialchars($extras['zone']);
|
725 |
ee6e6011
|
jim-p
|
captiveportal_init_webgui_zonename($zone);
|
726 |
|
|
break;
|
727 |
|
|
case 'ntpd':
|
728 |
|
|
system_ntp_configure();
|
729 |
|
|
break;
|
730 |
69eefb50
|
Renato Botelho
|
case 'dpinger':
|
731 |
b05a8f35
|
jim-p
|
setup_gateways_monitor();
|
732 |
|
|
break;
|
733 |
ee6e6011
|
jim-p
|
case 'bsnmpd':
|
734 |
|
|
services_snmpd_configure();
|
735 |
|
|
break;
|
736 |
9590e0de
|
Phil Davis
|
case 'dhcrelay':
|
737 |
|
|
services_dhcrelay_configure();
|
738 |
|
|
break;
|
739 |
|
|
case 'dhcrelay6':
|
740 |
|
|
services_dhcrelay6_configure();
|
741 |
|
|
break;
|
742 |
ee6e6011
|
jim-p
|
case 'dnsmasq':
|
743 |
|
|
services_dnsmasq_configure();
|
744 |
|
|
break;
|
745 |
a8604dc6
|
Phil Davis
|
case 'unbound':
|
746 |
|
|
services_unbound_configure();
|
747 |
|
|
break;
|
748 |
9bd56e9d
|
Christian McDonald
|
case 'kea-dhcp4':
|
749 |
|
|
case 'kea-dhcp6':
|
750 |
ee6e6011
|
jim-p
|
case 'dhcpd':
|
751 |
|
|
services_dhcpd_configure();
|
752 |
|
|
break;
|
753 |
|
|
case 'igmpproxy':
|
754 |
|
|
services_igmpproxy_configure();
|
755 |
|
|
break;
|
756 |
|
|
case 'miniupnpd':
|
757 |
|
|
upnp_action('start');
|
758 |
|
|
break;
|
759 |
8b4abd59
|
Ermal
|
case 'ipsec':
|
760 |
c6220dcf
|
jim-p
|
ipsec_force_reload();
|
761 |
ee6e6011
|
jim-p
|
break;
|
762 |
aaa78416
|
jim-p
|
case 'sshd':
|
763 |
|
|
send_event("service restart sshd");
|
764 |
|
|
break;
|
765 |
2c702751
|
Viktor G
|
case 'pcscd':
|
766 |
|
|
ipsec_force_reload();
|
767 |
|
|
break;
|
768 |
ee6e6011
|
jim-p
|
case 'openvpn':
|
769 |
2f9951fe
|
Renato Botelho
|
$vpnmode = isset($extras['vpnmode']) ? htmlspecialchars($extras['vpnmode']) : htmlspecialchars($extras['mode']);
|
770 |
ee6e6011
|
jim-p
|
if (($vpnmode == "server") || ($vpnmode == "client")) {
|
771 |
2f9951fe
|
Renato Botelho
|
$id = isset($extras['vpnid']) ? htmlspecialchars($extras['vpnid']) : htmlspecialchars($extras['id']);
|
772 |
348c2af1
|
jim-p
|
$configfile = "{$g['openvpn_base']}/{$vpnmode}{$id}/config.ovpn";
|
773 |
61e047a5
|
Phil Davis
|
if (file_exists($configfile)) {
|
774 |
ee6e6011
|
jim-p
|
openvpn_restart_by_vpnid($vpnmode, $id);
|
775 |
61e047a5
|
Phil Davis
|
}
|
776 |
ee6e6011
|
jim-p
|
}
|
777 |
|
|
break;
|
778 |
e3f68ab9
|
doktornotor
|
case 'syslogd':
|
779 |
|
|
system_syslogd_start();
|
780 |
|
|
break;
|
781 |
ee6e6011
|
jim-p
|
default:
|
782 |
|
|
start_service($name);
|
783 |
|
|
break;
|
784 |
|
|
}
|
785 |
086cf944
|
Phil Davis
|
return sprintf(gettext("%s has been started."), htmlspecialchars($name));
|
786 |
ee6e6011
|
jim-p
|
}
|
787 |
|
|
function service_control_stop($name, $extras) {
|
788 |
|
|
global $g;
|
789 |
61e047a5
|
Phil Davis
|
switch ($name) {
|
790 |
ee6e6011
|
jim-p
|
case 'radvd':
|
791 |
|
|
killbypid("{$g['varrun_path']}/radvd.pid");
|
792 |
|
|
break;
|
793 |
|
|
case 'captiveportal':
|
794 |
2f9951fe
|
Renato Botelho
|
$zone = htmlspecialchars($extras['zone']);
|
795 |
cd41643d
|
Renato Botelho
|
killbypid("{$g['varrun_path']}/nginx-{$zone}-CaptivePortal.pid");
|
796 |
|
|
killbypid("{$g['varrun_path']}/nginx-{$zone}-CaptivePortal-SSL.pid");
|
797 |
ee6e6011
|
jim-p
|
break;
|
798 |
|
|
case 'ntpd':
|
799 |
|
|
killbyname("ntpd");
|
800 |
|
|
break;
|
801 |
|
|
case 'openntpd':
|
802 |
|
|
killbyname("openntpd");
|
803 |
|
|
break;
|
804 |
69eefb50
|
Renato Botelho
|
case 'dpinger':
|
805 |
|
|
stop_dpinger();
|
806 |
b05a8f35
|
jim-p
|
break;
|
807 |
ee6e6011
|
jim-p
|
case 'bsnmpd':
|
808 |
|
|
killbypid("{$g['varrun_path']}/snmpd.pid");
|
809 |
|
|
break;
|
810 |
|
|
case 'choparp':
|
811 |
|
|
killbyname("choparp");
|
812 |
|
|
break;
|
813 |
9bd56e9d
|
Christian McDonald
|
case 'kea-dhcp4':
|
814 |
|
|
killbypid('/var/run/kea/kea-dhcp4.kea-dhcp4.pid');
|
815 |
|
|
break;
|
816 |
|
|
case 'kea-dhcp6':
|
817 |
|
|
killbypid('/var/run/kea/kea-dhcp6.kea-dhcp6.pid');
|
818 |
|
|
break;
|
819 |
ee6e6011
|
jim-p
|
case 'dhcpd':
|
820 |
|
|
killbyname("dhcpd");
|
821 |
|
|
break;
|
822 |
|
|
case 'dhcrelay':
|
823 |
|
|
killbypid("{$g['varrun_path']}/dhcrelay.pid");
|
824 |
|
|
break;
|
825 |
9590e0de
|
Phil Davis
|
case 'dhcrelay6':
|
826 |
|
|
killbypid("{$g['varrun_path']}/dhcrelay6.pid");
|
827 |
|
|
break;
|
828 |
ee6e6011
|
jim-p
|
case 'dnsmasq':
|
829 |
|
|
killbypid("{$g['varrun_path']}/dnsmasq.pid");
|
830 |
|
|
break;
|
831 |
33232486
|
Warren Baker
|
case 'unbound':
|
832 |
|
|
killbypid("{$g['varrun_path']}/unbound.pid");
|
833 |
|
|
break;
|
834 |
ee6e6011
|
jim-p
|
case 'igmpproxy':
|
835 |
|
|
killbyname("igmpproxy");
|
836 |
|
|
break;
|
837 |
|
|
case 'miniupnpd':
|
838 |
|
|
upnp_action('stop');
|
839 |
|
|
break;
|
840 |
|
|
case 'sshd':
|
841 |
|
|
killbyname("sshd");
|
842 |
|
|
break;
|
843 |
2c702751
|
Viktor G
|
case 'pcscd':
|
844 |
8b4abd59
|
Ermal
|
case 'ipsec':
|
845 |
c6220dcf
|
jim-p
|
exec("/usr/local/sbin/strongswanrc stop");
|
846 |
2c702751
|
Viktor G
|
if (isvalidproc("pcscd")) {
|
847 |
|
|
killbyname("pcscd");
|
848 |
|
|
}
|
849 |
ee6e6011
|
jim-p
|
break;
|
850 |
|
|
case 'openvpn':
|
851 |
2f9951fe
|
Renato Botelho
|
$vpnmode = htmlspecialchars($extras['vpnmode']);
|
852 |
ee6e6011
|
jim-p
|
if (($vpnmode == "server") or ($vpnmode == "client")) {
|
853 |
2f9951fe
|
Renato Botelho
|
$id = htmlspecialchars($extras['id']);
|
854 |
ee6e6011
|
jim-p
|
$pidfile = "{$g['varrun_path']}/openvpn_{$vpnmode}{$id}.pid";
|
855 |
|
|
killbypid($pidfile);
|
856 |
acb0c154
|
Marcos Mendoza
|
openvpn_delete_tmp($vpnmode, $id);
|
857 |
ee6e6011
|
jim-p
|
}
|
858 |
|
|
break;
|
859 |
e3f68ab9
|
doktornotor
|
case 'syslogd':
|
860 |
|
|
if (isvalidpid("{$g['varrun_path']}/syslog.pid")) {
|
861 |
|
|
sigkillbypid("{$g['varrun_path']}/syslog.pid", "TERM");
|
862 |
|
|
usleep(100000);
|
863 |
|
|
}
|
864 |
|
|
if (isvalidpid("{$g['varrun_path']}/syslog.pid")) {
|
865 |
|
|
sigkillbypid("{$g['varrun_path']}/syslog.pid", "KILL");
|
866 |
726b889b
|
doktornotor
|
usleep(100000);
|
867 |
e3f68ab9
|
doktornotor
|
}
|
868 |
b89270b7
|
Renato Botelho
|
/* Make sure sshguard stops as well */
|
869 |
f32dca24
|
Marcos Mendoza
|
system_sshguard_stop();
|
870 |
ee6e6011
|
jim-p
|
break;
|
871 |
|
|
default:
|
872 |
|
|
stop_service($name);
|
873 |
|
|
break;
|
874 |
|
|
}
|
875 |
|
|
return sprintf(gettext("%s has been stopped."), htmlspecialchars($name));
|
876 |
|
|
}
|
877 |
33232486
|
Warren Baker
|
|
878 |
ee6e6011
|
jim-p
|
function service_control_restart($name, $extras) {
|
879 |
|
|
global $g;
|
880 |
61e047a5
|
Phil Davis
|
switch ($name) {
|
881 |
ee6e6011
|
jim-p
|
case 'radvd':
|
882 |
|
|
services_radvd_configure();
|
883 |
|
|
break;
|
884 |
|
|
case 'captiveportal':
|
885 |
2f9951fe
|
Renato Botelho
|
$zone = htmlspecialchars($extras['zone']);
|
886 |
cd41643d
|
Renato Botelho
|
killbypid("{$g['varrun_path']}/nginx-{$zone}-CaptivePortal.pid");
|
887 |
|
|
killbypid("{$g['varrun_path']}/nginx-{$zone}-CaptivePortal-SSL.pid");
|
888 |
7c2468c5
|
Viktor G
|
/* see https://redmine.pfsense.org/issues/12651 */
|
889 |
|
|
sleep(1);
|
890 |
ee6e6011
|
jim-p
|
captiveportal_init_webgui_zonename($zone);
|
891 |
|
|
break;
|
892 |
|
|
case 'ntpd':
|
893 |
|
|
case 'openntpd':
|
894 |
|
|
system_ntp_configure();
|
895 |
|
|
break;
|
896 |
69eefb50
|
Renato Botelho
|
case 'dpinger':
|
897 |
b05a8f35
|
jim-p
|
setup_gateways_monitor();
|
898 |
|
|
break;
|
899 |
ee6e6011
|
jim-p
|
case 'bsnmpd':
|
900 |
|
|
services_snmpd_configure();
|
901 |
|
|
break;
|
902 |
9590e0de
|
Phil Davis
|
case 'dhcrelay':
|
903 |
|
|
services_dhcrelay_configure();
|
904 |
|
|
break;
|
905 |
|
|
case 'dhcrelay6':
|
906 |
|
|
services_dhcrelay6_configure();
|
907 |
|
|
break;
|
908 |
ee6e6011
|
jim-p
|
case 'dnsmasq':
|
909 |
|
|
services_dnsmasq_configure();
|
910 |
|
|
break;
|
911 |
33232486
|
Warren Baker
|
case 'unbound':
|
912 |
|
|
services_unbound_configure();
|
913 |
|
|
break;
|
914 |
fb79f9b0
|
R. Christian McDonald
|
case 'kea-dhcp4':
|
915 |
|
|
case 'kea-dhcp6':
|
916 |
ee6e6011
|
jim-p
|
case 'dhcpd':
|
917 |
|
|
services_dhcpd_configure();
|
918 |
|
|
break;
|
919 |
|
|
case 'igmpproxy':
|
920 |
|
|
services_igmpproxy_configure();
|
921 |
|
|
break;
|
922 |
|
|
case 'miniupnpd':
|
923 |
|
|
upnp_action('restart');
|
924 |
|
|
break;
|
925 |
8b4abd59
|
Ermal
|
case 'ipsec':
|
926 |
c6220dcf
|
jim-p
|
ipsec_force_reload();
|
927 |
ee6e6011
|
jim-p
|
break;
|
928 |
aaa78416
|
jim-p
|
case 'sshd':
|
929 |
|
|
send_event("service restart sshd");
|
930 |
|
|
break;
|
931 |
2c702751
|
Viktor G
|
case 'pcscd':
|
932 |
|
|
exec("/usr/local/sbin/strongswanrc stop");
|
933 |
|
|
if (isvalidproc("pcscd")) {
|
934 |
|
|
killbyname("pcscd");
|
935 |
|
|
}
|
936 |
|
|
ipsec_force_reload();
|
937 |
|
|
break;
|
938 |
ee6e6011
|
jim-p
|
case 'openvpn':
|
939 |
2f9951fe
|
Renato Botelho
|
$vpnmode = htmlspecialchars($extras['vpnmode']);
|
940 |
d2e806c4
|
jim-p
|
if (($vpnmode == "server") || ($vpnmode == "client")) {
|
941 |
2f9951fe
|
Renato Botelho
|
$id = htmlspecialchars($extras['id']);
|
942 |
348c2af1
|
jim-p
|
$configfile = "{$g['openvpn_base']}/{$vpnmode}{$id}/config.ovpn";
|
943 |
61e047a5
|
Phil Davis
|
if (file_exists($configfile)) {
|
944 |
ee6e6011
|
jim-p
|
openvpn_restart_by_vpnid($vpnmode, $id);
|
945 |
61e047a5
|
Phil Davis
|
}
|
946 |
ee6e6011
|
jim-p
|
}
|
947 |
|
|
break;
|
948 |
e3f68ab9
|
doktornotor
|
case 'syslogd':
|
949 |
|
|
system_syslogd_start();
|
950 |
|
|
break;
|
951 |
ee6e6011
|
jim-p
|
default:
|
952 |
|
|
restart_service($name);
|
953 |
|
|
break;
|
954 |
|
|
}
|
955 |
086cf944
|
Phil Davis
|
return sprintf(gettext("%s has been restarted."), htmlspecialchars($name));
|
956 |
ee6e6011
|
jim-p
|
}
|