1
|
<?php
|
2
|
/*
|
3
|
* service-utils.inc
|
4
|
*
|
5
|
* part of pfSense (https://www.pfsense.org)
|
6
|
* Copyright (c) 2005-2013 BSD Perimeter
|
7
|
* Copyright (c) 2013-2016 Electric Sheep Fencing
|
8
|
* Copyright (c) 2014-2020 Rubicon Communications, LLC (Netgate)
|
9
|
* Copyright (c) 2005-2006 Colin Smith (ethethlay@gmail.com)
|
10
|
* All rights reserved.
|
11
|
*
|
12
|
* 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
|
*
|
16
|
* http://www.apache.org/licenses/LICENSE-2.0
|
17
|
*
|
18
|
* 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
|
*/
|
24
|
|
25
|
require_once("captiveportal.inc");
|
26
|
require_once("globals.inc");
|
27
|
require_once("gwlb.inc");
|
28
|
require_once("ipsec.inc");
|
29
|
require_once("openvpn.inc");
|
30
|
require_once("system.inc");
|
31
|
require_once("util.inc");
|
32
|
require_once("vpn.inc");
|
33
|
|
34
|
define("RCFILEPREFIX", "/usr/local/etc/rc.d/");
|
35
|
function write_rcfile($params) {
|
36
|
global $g;
|
37
|
|
38
|
safe_mkdir(RCFILEPREFIX);
|
39
|
$rcfile_fullname = RCFILEPREFIX . $params['file'];
|
40
|
if (!file_exists($rcfile_fullname) && !is_link($rcfile_fullname) && !touch($rcfile_fullname)) {
|
41
|
return false;
|
42
|
}
|
43
|
|
44
|
if (!is_writable($rcfile_fullname) || empty($params['start'])) {
|
45
|
return false;
|
46
|
}
|
47
|
|
48
|
$towrite = "#!/bin/sh\n";
|
49
|
$towrite .= "# This file was automatically generated\n# by the {$g['product_name']} service handler.\n\n";
|
50
|
|
51
|
/* write our rc functions */
|
52
|
$towrite .= "rc_start() {\n";
|
53
|
$towrite .= "\t{$params['start']}\n";
|
54
|
$towrite .= "}\n\n";
|
55
|
if (!empty($params['stop'])) {
|
56
|
$tokill = &$params['stop'];
|
57
|
} else if (!empty($params['executable'])) {
|
58
|
/* just nuke the executable */
|
59
|
$tokill = "/usr/bin/killall " . escapeshellarg($params['executable']);
|
60
|
} else {
|
61
|
/* make an educated guess (bad) */
|
62
|
$tokill = array_pop(explode('/', array_shift(explode(' ', $params['start']))));
|
63
|
}
|
64
|
$towrite .= "rc_stop() {\n";
|
65
|
$towrite .= "\t{$tokill}\n";
|
66
|
$towrite .= "}\n\n";
|
67
|
|
68
|
/* begin rcfile logic */
|
69
|
$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_stop\n\t\trc_start\n\t\t;;\nesac\n\n";
|
70
|
|
71
|
@file_put_contents($rcfile_fullname, $towrite);
|
72
|
unset($towrite);
|
73
|
@chmod("{$rcfile_fullname}", 0755);
|
74
|
|
75
|
return;
|
76
|
}
|
77
|
|
78
|
function start_service($name, $after_sync = false) {
|
79
|
global $config;
|
80
|
|
81
|
if (empty($name)) {
|
82
|
return;
|
83
|
}
|
84
|
|
85
|
if (is_array($config['installedpackages']) && is_array($config['installedpackages']['service'])) {
|
86
|
foreach ($config['installedpackages']['service'] as $service) {
|
87
|
if (isset($service['name']) && (strtolower($service['name']) == strtolower($name))) {
|
88
|
/* Avoid starting twice if this is called just after a
|
89
|
* package sync which starts the service itself. */
|
90
|
if ($after_sync && isset($service['starts_on_sync'])) {
|
91
|
break;
|
92
|
}
|
93
|
if ($service['rcfile']) {
|
94
|
$prefix = RCFILEPREFIX;
|
95
|
if (!empty($service['prefix'])) {
|
96
|
$prefix = &$service['prefix'];
|
97
|
}
|
98
|
if (file_exists("{$prefix}{$service['rcfile']}") || is_link("{$prefix}{$service['rcfile']}")) {
|
99
|
mwexec_bg("{$prefix}{$service['rcfile']} start");
|
100
|
}
|
101
|
}
|
102
|
if (!empty($service['startcmd'])) {
|
103
|
eval($service['startcmd']);
|
104
|
}
|
105
|
break;
|
106
|
}
|
107
|
}
|
108
|
}
|
109
|
}
|
110
|
|
111
|
function stop_service($name) {
|
112
|
global $config;
|
113
|
|
114
|
if (empty($name)) {
|
115
|
return;
|
116
|
}
|
117
|
|
118
|
if (is_array($config['installedpackages']) && is_array($config['installedpackages']['service'])) {
|
119
|
foreach ($config['installedpackages']['service'] as $service) {
|
120
|
if (strtolower($service['name']) == strtolower($name)) {
|
121
|
if ($service['rcfile']) {
|
122
|
$prefix = RCFILEPREFIX;
|
123
|
if (!empty($service['prefix'])) {
|
124
|
$prefix = &$service['prefix'];
|
125
|
}
|
126
|
if (file_exists("{$prefix}{$service['rcfile']}") || is_link("{$prefix}{$service['rcfile']}")) {
|
127
|
mwexec("{$prefix}{$service['rcfile']} stop");
|
128
|
}
|
129
|
return;
|
130
|
}
|
131
|
if (!empty($service['stopcmd'])) {
|
132
|
eval($service['stopcmd']);
|
133
|
} elseif (!empty($service['executable'])) {
|
134
|
mwexec("/usr/bin/killall " . escapeshellarg($service['executable']));
|
135
|
}
|
136
|
|
137
|
break;
|
138
|
}
|
139
|
}
|
140
|
}
|
141
|
}
|
142
|
|
143
|
function restart_service($name) {
|
144
|
global $config;
|
145
|
|
146
|
if (empty($name)) {
|
147
|
return;
|
148
|
}
|
149
|
|
150
|
if (is_service_running($name)) {
|
151
|
stop_service($name);
|
152
|
}
|
153
|
start_service($name);
|
154
|
|
155
|
if (is_array($config['installedpackages']) && is_array($config['installedpackages']['service'])) {
|
156
|
foreach ($config['installedpackages']['service'] as $service) {
|
157
|
if (strtolower($service['name']) == strtolower($name)) {
|
158
|
if ($service['restartcmd']) {
|
159
|
eval($service['restartcmd']);
|
160
|
}
|
161
|
break;
|
162
|
}
|
163
|
}
|
164
|
}
|
165
|
}
|
166
|
|
167
|
function is_pid_running($pidfile) {
|
168
|
if (!file_exists($pidfile)) {
|
169
|
return false;
|
170
|
}
|
171
|
|
172
|
return (isvalidpid($pidfile));
|
173
|
}
|
174
|
|
175
|
function is_dhcp_running($interface) {
|
176
|
$status = find_dhclient_process($interface);
|
177
|
if ($status != 0) {
|
178
|
return true;
|
179
|
}
|
180
|
return false;
|
181
|
}
|
182
|
|
183
|
function restart_service_if_running($service) {
|
184
|
global $config;
|
185
|
if (is_service_running($service)) {
|
186
|
restart_service($service);
|
187
|
}
|
188
|
return;
|
189
|
}
|
190
|
|
191
|
function is_service_enabled($service_name) {
|
192
|
global $config;
|
193
|
if ($service_name == "") {
|
194
|
return false;
|
195
|
}
|
196
|
if (is_array($config['installedpackages'])) {
|
197
|
if (isset($config['installedpackages'][$service_name]['config'][0]['enable']) &&
|
198
|
((empty($config['installedpackages'][$service_name]['config'][0]['enable'])) ||
|
199
|
($config['installedpackages'][$service_name]['config'][0]['enable'] === 'off'))) {
|
200
|
return false;
|
201
|
}
|
202
|
}
|
203
|
return true;
|
204
|
}
|
205
|
|
206
|
function is_service_running($service, $ps = "") {
|
207
|
global $config;
|
208
|
|
209
|
if (is_array($config['installedpackages']['service'])) {
|
210
|
foreach ($config['installedpackages']['service'] as $aservice) {
|
211
|
if (isset($aservice['name']) && (strtolower($service) == strtolower($aservice['name']))) {
|
212
|
if ($aservice['custom_php_service_status_command'] <> "") {
|
213
|
eval("\$rc={$aservice['custom_php_service_status_command']};");
|
214
|
return $rc;
|
215
|
}
|
216
|
if (empty($aservice['executable'])) {
|
217
|
return false;
|
218
|
}
|
219
|
if (is_process_running($aservice['executable'])) {
|
220
|
return true;
|
221
|
}
|
222
|
|
223
|
return false;
|
224
|
}
|
225
|
}
|
226
|
}
|
227
|
|
228
|
if (is_process_running($service)) {
|
229
|
return true;
|
230
|
}
|
231
|
|
232
|
return false;
|
233
|
}
|
234
|
|
235
|
function get_services() {
|
236
|
global $config;
|
237
|
if (is_array($config['installedpackages']['service'])) {
|
238
|
$services = $config['installedpackages']['service'];
|
239
|
} else {
|
240
|
$services = array();
|
241
|
}
|
242
|
|
243
|
/*
|
244
|
* Add services that are in the base.
|
245
|
*/
|
246
|
if (is_radvd_enabled()) {
|
247
|
$pconfig = array();
|
248
|
$pconfig['name'] = "radvd";
|
249
|
$pconfig['description'] = gettext("Router Advertisement Daemon");
|
250
|
$services[] = $pconfig;
|
251
|
}
|
252
|
|
253
|
if (isset($config['dnsmasq']['enable'])) {
|
254
|
$pconfig = array();
|
255
|
$pconfig['name'] = "dnsmasq";
|
256
|
$pconfig['description'] = gettext("DNS Forwarder");
|
257
|
$services[] = $pconfig;
|
258
|
}
|
259
|
|
260
|
if (isset($config['unbound']['enable'])) {
|
261
|
$pconfig = array();
|
262
|
$pconfig['name'] = "unbound";
|
263
|
$pconfig['description'] = gettext("DNS Resolver");
|
264
|
$services[] = $pconfig;
|
265
|
}
|
266
|
|
267
|
$pconfig = array();
|
268
|
$pconfig['name'] = "pcscd";
|
269
|
$pconfig['description'] = gettext("PC/SC Smart Card Daemon");
|
270
|
$services[] = $pconfig;
|
271
|
|
272
|
if (is_array($config['ntpd']) && ($config['ntpd']['enable'] != 'disabled')) {
|
273
|
$pconfig = array();
|
274
|
$pconfig['name'] = "ntpd";
|
275
|
$pconfig['description'] = gettext("NTP clock sync");
|
276
|
$services[] = $pconfig;
|
277
|
}
|
278
|
|
279
|
$pconfig = array();
|
280
|
$pconfig['name'] = "syslogd";
|
281
|
$pconfig['description'] = gettext("System Logger Daemon");
|
282
|
$services[] = $pconfig;
|
283
|
|
284
|
if (is_array($config['captiveportal'])) {
|
285
|
foreach ($config['captiveportal'] as $zone => $setting) {
|
286
|
if (isset($setting['enable'])) {
|
287
|
$pconfig = array();
|
288
|
$pconfig['name'] = "captiveportal";
|
289
|
$pconfig['zone'] = $zone;
|
290
|
$pconfig['description'] = gettext("Captive Portal") . ": " . htmlspecialchars($setting['zone']);
|
291
|
$services[] = $pconfig;
|
292
|
}
|
293
|
}
|
294
|
}
|
295
|
|
296
|
$iflist = array();
|
297
|
$ifdescrs = get_configured_interface_list();
|
298
|
foreach ($ifdescrs as $if) {
|
299
|
$oc = $config['interfaces'][$if];
|
300
|
if ($oc['if'] && (!link_interface_to_bridge($if))) {
|
301
|
$iflist[$if] = $if;
|
302
|
}
|
303
|
}
|
304
|
|
305
|
if (isset($config['dhcrelay']['enable'])) {
|
306
|
$pconfig = array();
|
307
|
$pconfig['name'] = "dhcrelay";
|
308
|
$pconfig['description'] = gettext("DHCP Relay");
|
309
|
$services[] = $pconfig;
|
310
|
}
|
311
|
|
312
|
if (isset($config['dhcrelay6']['enable'])) {
|
313
|
$pconfig = array();
|
314
|
$pconfig['name'] = "dhcrelay6";
|
315
|
$pconfig['description'] = gettext("DHCPv6 Relay");
|
316
|
$services[] = $pconfig;
|
317
|
}
|
318
|
|
319
|
if (is_dhcp_server_enabled()) {
|
320
|
$pconfig = array();
|
321
|
$pconfig['name'] = "dhcpd";
|
322
|
$pconfig['description'] = gettext("DHCP Service");
|
323
|
$services[] = $pconfig;
|
324
|
}
|
325
|
|
326
|
$gateways_arr = return_gateways_array();
|
327
|
if (is_array($gateways_arr)) {
|
328
|
$pconfig = array();
|
329
|
$pconfig['name'] = "dpinger";
|
330
|
$pconfig['description'] = gettext("Gateway Monitoring Daemon");
|
331
|
$services[] = $pconfig;
|
332
|
}
|
333
|
|
334
|
if (isset($config['snmpd']['enable'])) {
|
335
|
$pconfig = array();
|
336
|
$pconfig['name'] = "bsnmpd";
|
337
|
$pconfig['description'] = gettext("SNMP Service");
|
338
|
$services[] = $pconfig;
|
339
|
}
|
340
|
|
341
|
if (is_array($config['igmpproxy']['igmpentry']) && (count($config['igmpproxy']['igmpentry']) > 0)) {
|
342
|
$pconfig = array();
|
343
|
$pconfig['name'] = "igmpproxy";
|
344
|
$pconfig['description'] = gettext("IGMP proxy");
|
345
|
$services[] = $pconfig;
|
346
|
}
|
347
|
|
348
|
if (isset($config['installedpackages']['miniupnpd']) && $config['installedpackages']['miniupnpd']['config'][0]['enable']) {
|
349
|
$pconfig = array();
|
350
|
$pconfig['name'] = "miniupnpd";
|
351
|
$pconfig['description'] = gettext("UPnP Service");
|
352
|
$services[] = $pconfig;
|
353
|
}
|
354
|
|
355
|
if (ipsec_enabled()) {
|
356
|
$pconfig = array();
|
357
|
$pconfig['name'] = "ipsec";
|
358
|
$pconfig['description'] = gettext("IPsec VPN");
|
359
|
$services[] = $pconfig;
|
360
|
}
|
361
|
|
362
|
if (isset($config['system']['ssh']['enable'])) {
|
363
|
$pconfig = array();
|
364
|
$pconfig['name'] = "sshd";
|
365
|
$pconfig['description'] = gettext("Secure Shell Daemon");
|
366
|
$services[] = $pconfig;
|
367
|
}
|
368
|
|
369
|
foreach (array('server', 'client') as $mode) {
|
370
|
if (is_array($config['openvpn']["openvpn-{$mode}"])) {
|
371
|
foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) {
|
372
|
if (!isset($setting['disable'])) {
|
373
|
$pconfig = array();
|
374
|
$pconfig['name'] = "openvpn";
|
375
|
$pconfig['mode'] = $mode;
|
376
|
$pconfig['id'] = $id;
|
377
|
$pconfig['vpnid'] = $setting['vpnid'];
|
378
|
$pconfig['description'] = gettext("OpenVPN") . " " . $mode . ": " . htmlspecialchars($setting['description']);
|
379
|
$services[] = $pconfig;
|
380
|
}
|
381
|
}
|
382
|
}
|
383
|
}
|
384
|
|
385
|
return $services;
|
386
|
}
|
387
|
|
388
|
function find_service_by_name($name) {
|
389
|
$services = get_services();
|
390
|
foreach ($services as $service) {
|
391
|
if (isset($service["name"]) && ($service["name"] == $name)) {
|
392
|
return $service;
|
393
|
}
|
394
|
}
|
395
|
return array();
|
396
|
}
|
397
|
|
398
|
function find_service_by_openvpn_vpnid($vpnid) {
|
399
|
$services = get_services();
|
400
|
foreach ($services as $service) {
|
401
|
if (isset($service["name"]) && ($service["name"] == "openvpn") && isset($service["vpnid"]) && ($service["vpnid"] == $vpnid)) {
|
402
|
return $service;
|
403
|
}
|
404
|
}
|
405
|
return array();
|
406
|
}
|
407
|
|
408
|
function find_service_by_cp_zone($zone) {
|
409
|
$services = get_services();
|
410
|
foreach ($services as $service) {
|
411
|
if (isset($service["name"]) && ($service["name"] == "captiveportal") && isset($service["zone"]) && ($service["zone"] == $zone)) {
|
412
|
return $service;
|
413
|
}
|
414
|
}
|
415
|
return array();
|
416
|
}
|
417
|
|
418
|
function service_description_compare($a, $b) {
|
419
|
if (strtolower($a['description']) == strtolower($b['description'])) {
|
420
|
return 0;
|
421
|
}
|
422
|
return (strtolower($a['description']) < strtolower($b['description'])) ? -1 : 1;
|
423
|
}
|
424
|
|
425
|
function service_name_compare($a, $b) {
|
426
|
if (!isset($a['name']) || !isset($b['name'])) {
|
427
|
return -1;
|
428
|
}
|
429
|
/* If the names are equal, fall back to sorting by description */
|
430
|
if (strtolower($a['name']) == strtolower($b['name'])) {
|
431
|
return service_description_compare($a, $b);
|
432
|
}
|
433
|
return (strtolower($a['name']) < strtolower($b['name'])) ? -1 : 1;
|
434
|
}
|
435
|
|
436
|
function service_dispname_compare($a, $b) {
|
437
|
/* If two items have an instance suffix, perform an integer comparison to avoid awkward sorting */
|
438
|
if ((strpos($a['dispname'], '_') > 0) && (strpos($b['dispname'], '_') > 0)) {
|
439
|
list($adn1, $adn2) = explode('_', $a['dispname'], 2);
|
440
|
list($bdn1, $bdn2) = explode('_', $b['dispname'], 2);
|
441
|
if (($adn1 == $bdn1) && is_numeric($adn2) && is_numeric($bdn2)) {
|
442
|
if ($adn2 == $bdn2) {
|
443
|
return 0;
|
444
|
}
|
445
|
return ((int)$adn2 < (int)$bdn2) ? -1 : 1;
|
446
|
}
|
447
|
}
|
448
|
/* If the display names are equal, compare the internal name */
|
449
|
if (strtolower($a['dispname']) == strtolower($b['dispname'])) {
|
450
|
return service_name_compare($a, $b);
|
451
|
}
|
452
|
return (strtolower($a['dispname']) < strtolower($b['dispname'])) ? -1 : 1;
|
453
|
}
|
454
|
|
455
|
function get_pkg_descr($package_name) {
|
456
|
global $config;
|
457
|
if (is_array($config['installedpackages']['package'])) {
|
458
|
foreach ($config['installedpackages']['package'] as $pkg) {
|
459
|
if ($pkg['name'] == $package_name) {
|
460
|
return $pkg['descr'];
|
461
|
}
|
462
|
}
|
463
|
}
|
464
|
return gettext("Not available.");
|
465
|
}
|
466
|
|
467
|
function get_service_status($service) {
|
468
|
global $g;
|
469
|
switch ($service['name']) {
|
470
|
case "openvpn":
|
471
|
$running = is_pid_running("{$g['varrun_path']}/openvpn_{$service['mode']}{$service['vpnid']}.pid");
|
472
|
break;
|
473
|
case "captiveportal":
|
474
|
$running = is_pid_running("{$g['varrun_path']}/nginx-{$service['zone']}-CaptivePortal.pid");
|
475
|
if (isset($config['captiveportal'][$service['zone']]['httpslogin'])) {
|
476
|
$running = $running && is_pid_running("{$g['varrun_path']}/nginx-{$service['zone']}-CaptivePortal-SSL.pid");
|
477
|
}
|
478
|
break;
|
479
|
case "vhosts-http":
|
480
|
$running = is_pid_running("{$g['varrun_path']}/vhosts-http.pid");
|
481
|
break;
|
482
|
case "dhcrelay6":
|
483
|
$running = is_pid_running("{$g['varrun_path']}/dhcrelay6.pid");
|
484
|
break;
|
485
|
case 'ipsec':
|
486
|
$running = (is_pid_running("{$g['varrun_path']}/charon.pid") || is_process_running('charon'));
|
487
|
break;
|
488
|
default:
|
489
|
$running = is_service_running($service['name']);
|
490
|
}
|
491
|
return $running;
|
492
|
}
|
493
|
|
494
|
function get_service_status_icon($service, $withtext = true, $smallicon = false, $withthumbs = false, $title = "service_state") {
|
495
|
$output = "";
|
496
|
|
497
|
if (get_service_status($service)) {
|
498
|
$statustext = gettext("Running");
|
499
|
$text_class = "text-success";
|
500
|
$fa_class = "fa fa-check-circle";
|
501
|
$fa_class_thumbs = "fa fa-thumbs-o-up";
|
502
|
$Thumbs_UpDown = "Thumbs up";
|
503
|
} else {
|
504
|
if (is_service_enabled($service['name'])) {
|
505
|
$statustext = gettext("Stopped");
|
506
|
$text_class = "text-danger";
|
507
|
$fa_class = "fa fa-times-circle";
|
508
|
} else {
|
509
|
$statustext = gettext("Disabled");
|
510
|
$text_class = "text-warning";
|
511
|
$fa_class = "fa fa-ban";
|
512
|
}
|
513
|
$fa_class_thumbs = "fa fa-thumbs-o-down";
|
514
|
$Thumbs_UpDown = "Thumbs down";
|
515
|
}
|
516
|
$fa_size = ($smallicon) ? "fa-1x" : "fa-lg";
|
517
|
|
518
|
if ($title == "state") {
|
519
|
$title = $statustext;
|
520
|
} elseif ($title == "service_state") {
|
521
|
$title = sprintf(gettext('%1$s Service is %2$s'), $service["name"], $statustext);
|
522
|
} elseif ($title == "description_state") {
|
523
|
$title = sprintf(gettext('%1$s Service is %2$s'), $service["description"], $statustext);
|
524
|
} elseif ($title == "description_service_state") {
|
525
|
$title = sprintf(gettext('%1$s, %2$s Service is %3$s'), $service["description"], $service["name"], $statustext);
|
526
|
}
|
527
|
|
528
|
$spacer = ($withthumbs || $withtext) ? " " : "";
|
529
|
|
530
|
$output = "<i class=\"{$text_class} {$fa_class} {$fa_size}\" title=\"{$title}\"><span style=\"display: none\">{$statustext}</span></i>{$spacer}";
|
531
|
|
532
|
$spacer = ($withtext) ? " " : "";
|
533
|
if ($withthumbs) {
|
534
|
$output .= "<i class=\"{$text_class} {$fa_class_thumbs} {$fa_size}\" title=\"{$Thumbs_UpDown}\"></i>{$spacer}";
|
535
|
}
|
536
|
|
537
|
if ($withtext) {
|
538
|
$output .= "<span class=\"" . $text_class . "\">" . $statustext . "</span>";
|
539
|
}
|
540
|
|
541
|
return $output;
|
542
|
}
|
543
|
|
544
|
function get_service_control_links($service, $addname = false) {
|
545
|
global $g;
|
546
|
$output = "";
|
547
|
$stitle = ($addname) ? $service['name'] . " " : "";
|
548
|
|
549
|
switch ($service['name']) {
|
550
|
case "openvpn":
|
551
|
$link = '<a title="%s" href="#" id="openvpn-%s-' . $service['mode'] . '-' . $service['vpnid'] . '" >';
|
552
|
break;
|
553
|
case "captiveportal":
|
554
|
$link = '<a title="%s" href="#" id="captiveportal-%s-' . $service['zone'] . '">';
|
555
|
break;
|
556
|
default:
|
557
|
$link = '<a title="%s" href="#" id="%s-' . $service['name'] . '">';
|
558
|
}
|
559
|
|
560
|
if (get_service_status($service)) {
|
561
|
switch ($service['name']) {
|
562
|
case "openvpn":
|
563
|
$output .= '<a href="#" id="openvpn-restartservice-' . $service['mode'] . '-' . $service['vpnid'] . '" >';
|
564
|
break;
|
565
|
case "captiveportal":
|
566
|
$output .= '<a href="#" id="captiveportal-restartservice-' . $service['zone'] . '">';
|
567
|
break;
|
568
|
default:
|
569
|
$output .= '<a href="#" id="restartservice-' . $service['name'] . '" >';
|
570
|
}
|
571
|
|
572
|
$output .= "<i class=\"fa fa-repeat\" title=\"" . sprintf(gettext("Restart %sService"), $stitle) . "\"></i></a>\n";
|
573
|
|
574
|
switch ($service['name']) {
|
575
|
case "openvpn":
|
576
|
$output .= '<a href="#" id="openvpn-stopservice-' . $service['mode'] . '-' . $service['vpnid'] . '" >';
|
577
|
break;
|
578
|
case "captiveportal":
|
579
|
$output .= '<a href="#" id="captiveportal-stopservice-' . $service['zone'] . '">';
|
580
|
break;
|
581
|
default:
|
582
|
$output .= '<a href="#" id="stopservice-' . $service['name'] . '">';
|
583
|
}
|
584
|
|
585
|
$output .= "<i class=\"fa fa-stop-circle-o\" title=\"" . sprintf(gettext("Stop %sService"), $stitle) . "\"></i></a>";
|
586
|
|
587
|
} else {
|
588
|
$service_enabled = is_service_enabled($service['name']);
|
589
|
|
590
|
if ($service['name'] == 'openvpn' || $service['name'] == 'captiveportal' || $service_enabled) {
|
591
|
$output .= sprintf($link, sprintf(gettext("Start %sService"), $stitle), 'startservice');
|
592
|
$output .= '<i class="fa fa-play-circle"></i></a> ';
|
593
|
}
|
594
|
}
|
595
|
|
596
|
return $output;
|
597
|
}
|
598
|
|
599
|
function service_control_start($name, $extras) {
|
600
|
global $g;
|
601
|
switch ($name) {
|
602
|
case 'radvd':
|
603
|
services_radvd_configure();
|
604
|
break;
|
605
|
case 'captiveportal':
|
606
|
$zone = htmlspecialchars($extras['zone']);
|
607
|
captiveportal_init_webgui_zonename($zone);
|
608
|
break;
|
609
|
case 'ntpd':
|
610
|
system_ntp_configure();
|
611
|
break;
|
612
|
case 'dpinger':
|
613
|
setup_gateways_monitor();
|
614
|
break;
|
615
|
case 'bsnmpd':
|
616
|
services_snmpd_configure();
|
617
|
break;
|
618
|
case 'dhcrelay':
|
619
|
services_dhcrelay_configure();
|
620
|
break;
|
621
|
case 'dhcrelay6':
|
622
|
services_dhcrelay6_configure();
|
623
|
break;
|
624
|
case 'dnsmasq':
|
625
|
services_dnsmasq_configure();
|
626
|
break;
|
627
|
case 'unbound':
|
628
|
services_unbound_configure();
|
629
|
break;
|
630
|
case 'dhcpd':
|
631
|
services_dhcpd_configure();
|
632
|
break;
|
633
|
case 'igmpproxy':
|
634
|
services_igmpproxy_configure();
|
635
|
break;
|
636
|
case 'miniupnpd':
|
637
|
upnp_action('start');
|
638
|
break;
|
639
|
case 'ipsec':
|
640
|
ipsec_force_reload();
|
641
|
break;
|
642
|
case 'sshd':
|
643
|
send_event("service restart sshd");
|
644
|
break;
|
645
|
case 'openvpn':
|
646
|
$vpnmode = isset($extras['vpnmode']) ? htmlspecialchars($extras['vpnmode']) : htmlspecialchars($extras['mode']);
|
647
|
if (($vpnmode == "server") || ($vpnmode == "client")) {
|
648
|
$id = isset($extras['vpnid']) ? htmlspecialchars($extras['vpnid']) : htmlspecialchars($extras['id']);
|
649
|
$configfile = "{$g['openvpn_base']}/{$vpnmode}{$id}/config.ovpn";
|
650
|
if (file_exists($configfile)) {
|
651
|
openvpn_restart_by_vpnid($vpnmode, $id);
|
652
|
}
|
653
|
}
|
654
|
break;
|
655
|
case 'syslogd':
|
656
|
system_syslogd_start();
|
657
|
break;
|
658
|
case 'pcscd':
|
659
|
mwexec_bg("service pcscd onestart");
|
660
|
break;
|
661
|
default:
|
662
|
start_service($name);
|
663
|
break;
|
664
|
}
|
665
|
return sprintf(gettext("%s has been started."), htmlspecialchars($name));
|
666
|
}
|
667
|
function service_control_stop($name, $extras) {
|
668
|
global $g;
|
669
|
switch ($name) {
|
670
|
case 'radvd':
|
671
|
killbypid("{$g['varrun_path']}/radvd.pid");
|
672
|
break;
|
673
|
case 'captiveportal':
|
674
|
$zone = htmlspecialchars($extras['zone']);
|
675
|
killbypid("{$g['varrun_path']}/nginx-{$zone}-CaptivePortal.pid");
|
676
|
killbypid("{$g['varrun_path']}/nginx-{$zone}-CaptivePortal-SSL.pid");
|
677
|
break;
|
678
|
case 'ntpd':
|
679
|
killbyname("ntpd");
|
680
|
break;
|
681
|
case 'openntpd':
|
682
|
killbyname("openntpd");
|
683
|
break;
|
684
|
case 'dpinger':
|
685
|
stop_dpinger();
|
686
|
break;
|
687
|
case 'bsnmpd':
|
688
|
killbypid("{$g['varrun_path']}/snmpd.pid");
|
689
|
break;
|
690
|
case 'choparp':
|
691
|
killbyname("choparp");
|
692
|
break;
|
693
|
case 'dhcpd':
|
694
|
killbyname("dhcpd");
|
695
|
break;
|
696
|
case 'dhcrelay':
|
697
|
killbypid("{$g['varrun_path']}/dhcrelay.pid");
|
698
|
break;
|
699
|
case 'dhcrelay6':
|
700
|
killbypid("{$g['varrun_path']}/dhcrelay6.pid");
|
701
|
break;
|
702
|
case 'dnsmasq':
|
703
|
killbypid("{$g['varrun_path']}/dnsmasq.pid");
|
704
|
break;
|
705
|
case 'unbound':
|
706
|
killbypid("{$g['varrun_path']}/unbound.pid");
|
707
|
break;
|
708
|
case 'igmpproxy':
|
709
|
killbyname("igmpproxy");
|
710
|
break;
|
711
|
case 'miniupnpd':
|
712
|
upnp_action('stop');
|
713
|
break;
|
714
|
case 'sshd':
|
715
|
killbyname("sshd");
|
716
|
break;
|
717
|
case 'ipsec':
|
718
|
exec("/usr/local/sbin/strongswanrc stop");
|
719
|
break;
|
720
|
case 'openvpn':
|
721
|
$vpnmode = htmlspecialchars($extras['vpnmode']);
|
722
|
if (($vpnmode == "server") or ($vpnmode == "client")) {
|
723
|
$id = htmlspecialchars($extras['id']);
|
724
|
$pidfile = "{$g['varrun_path']}/openvpn_{$vpnmode}{$id}.pid";
|
725
|
killbypid($pidfile);
|
726
|
}
|
727
|
break;
|
728
|
case 'syslogd':
|
729
|
if (isvalidpid("{$g['varrun_path']}/syslog.pid")) {
|
730
|
sigkillbypid("{$g['varrun_path']}/syslog.pid", "TERM");
|
731
|
usleep(100000);
|
732
|
}
|
733
|
if (isvalidpid("{$g['varrun_path']}/syslog.pid")) {
|
734
|
sigkillbypid("{$g['varrun_path']}/syslog.pid", "KILL");
|
735
|
usleep(100000);
|
736
|
}
|
737
|
/* Make sure sshguard stops as well */
|
738
|
sigkillbyname("sshguard", "TERM");
|
739
|
break;
|
740
|
case 'pcscd':
|
741
|
mwexec_bg("service pcscd onestop");
|
742
|
break;
|
743
|
default:
|
744
|
stop_service($name);
|
745
|
break;
|
746
|
}
|
747
|
return sprintf(gettext("%s has been stopped."), htmlspecialchars($name));
|
748
|
}
|
749
|
|
750
|
function service_control_restart($name, $extras) {
|
751
|
global $g;
|
752
|
switch ($name) {
|
753
|
case 'radvd':
|
754
|
services_radvd_configure();
|
755
|
break;
|
756
|
case 'captiveportal':
|
757
|
$zone = htmlspecialchars($extras['zone']);
|
758
|
killbypid("{$g['varrun_path']}/nginx-{$zone}-CaptivePortal.pid");
|
759
|
killbypid("{$g['varrun_path']}/nginx-{$zone}-CaptivePortal-SSL.pid");
|
760
|
captiveportal_init_webgui_zonename($zone);
|
761
|
break;
|
762
|
case 'ntpd':
|
763
|
case 'openntpd':
|
764
|
system_ntp_configure();
|
765
|
break;
|
766
|
case 'dpinger':
|
767
|
setup_gateways_monitor();
|
768
|
break;
|
769
|
case 'bsnmpd':
|
770
|
services_snmpd_configure();
|
771
|
break;
|
772
|
case 'dhcrelay':
|
773
|
services_dhcrelay_configure();
|
774
|
break;
|
775
|
case 'dhcrelay6':
|
776
|
services_dhcrelay6_configure();
|
777
|
break;
|
778
|
case 'dnsmasq':
|
779
|
services_dnsmasq_configure();
|
780
|
break;
|
781
|
case 'unbound':
|
782
|
services_unbound_configure();
|
783
|
break;
|
784
|
case 'dhcpd':
|
785
|
services_dhcpd_configure();
|
786
|
break;
|
787
|
case 'igmpproxy':
|
788
|
services_igmpproxy_configure();
|
789
|
break;
|
790
|
case 'miniupnpd':
|
791
|
upnp_action('restart');
|
792
|
break;
|
793
|
case 'ipsec':
|
794
|
ipsec_force_reload();
|
795
|
break;
|
796
|
case 'sshd':
|
797
|
send_event("service restart sshd");
|
798
|
break;
|
799
|
case 'openvpn':
|
800
|
$vpnmode = htmlspecialchars($extras['vpnmode']);
|
801
|
if ($vpnmode == "server" || $vpnmode == "client") {
|
802
|
$id = htmlspecialchars($extras['id']);
|
803
|
$configfile = "{$g['openvpn_base']}/{$vpnmode}{$id}/config.ovpn";
|
804
|
if (file_exists($configfile)) {
|
805
|
openvpn_restart_by_vpnid($vpnmode, $id);
|
806
|
}
|
807
|
}
|
808
|
break;
|
809
|
case 'syslogd':
|
810
|
system_syslogd_start();
|
811
|
break;
|
812
|
default:
|
813
|
restart_service($name);
|
814
|
break;
|
815
|
}
|
816
|
return sprintf(gettext("%s has been restarted."), htmlspecialchars($name));
|
817
|
}
|
818
|
|
819
|
?>
|