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