Project

General

Profile

Download (22.1 KB) Statistics
| Branch: | Tag: | Revision:
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-2019 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'] = "ntpd";
269
	$pconfig['description'] = gettext("NTP clock sync");
270
	$services[] = $pconfig;
271

    
272
	$pconfig = array();
273
	$pconfig['name'] = "syslogd";
274
	$pconfig['description'] = gettext("System Logger Daemon");
275
	$services[] = $pconfig;
276

    
277
	if (is_array($config['captiveportal'])) {
278
		foreach ($config['captiveportal'] as $zone => $setting) {
279
			if (isset($setting['enable'])) {
280
				$pconfig = array();
281
				$pconfig['name'] = "captiveportal";
282
				$pconfig['zone'] = $zone;
283
				$pconfig['description'] = gettext("Captive Portal") . ": " . htmlspecialchars($setting['zone']);
284
				$services[] = $pconfig;
285
			}
286
		}
287
	}
288

    
289
	$iflist = array();
290
	$ifdescrs = get_configured_interface_list();
291
	foreach ($ifdescrs as $if) {
292
		$oc = $config['interfaces'][$if];
293
		if ($oc['if'] && (!link_interface_to_bridge($if))) {
294
			$iflist[$if] = $if;
295
		}
296
	}
297

    
298
	if (isset($config['dhcrelay']['enable'])) {
299
		$pconfig = array();
300
		$pconfig['name'] = "dhcrelay";
301
		$pconfig['description'] = gettext("DHCP Relay");
302
		$services[] = $pconfig;
303
	}
304

    
305
	if (isset($config['dhcrelay6']['enable'])) {
306
		$pconfig = array();
307
		$pconfig['name'] = "dhcrelay6";
308
		$pconfig['description'] = gettext("DHCPv6 Relay");
309
		$services[] = $pconfig;
310
	}
311

    
312
	if (is_dhcp_server_enabled()) {
313
		$pconfig = array();
314
		$pconfig['name'] = "dhcpd";
315
		$pconfig['description'] = gettext("DHCP Service");
316
		$services[] = $pconfig;
317
	}
318

    
319
	$gateways_arr = return_gateways_array();
320
	if (is_array($gateways_arr)) {
321
		$pconfig = array();
322
		$pconfig['name'] = "dpinger";
323
		$pconfig['description'] = gettext("Gateway Monitoring Daemon");
324
		$services[] = $pconfig;
325
	}
326

    
327
	if (isset($config['snmpd']['enable'])) {
328
		$pconfig = array();
329
		$pconfig['name'] = "bsnmpd";
330
		$pconfig['description'] = gettext("SNMP Service");
331
		$services[] = $pconfig;
332
	}
333

    
334
	if (is_array($config['igmpproxy']['igmpentry']) && (count($config['igmpproxy']['igmpentry']) > 0)) {
335
		$pconfig = array();
336
		$pconfig['name'] = "igmpproxy";
337
		$pconfig['description'] = gettext("IGMP proxy");
338
		$services[] = $pconfig;
339
	}
340

    
341
	if (isset($config['installedpackages']['miniupnpd']) && $config['installedpackages']['miniupnpd']['config'][0]['enable']) {
342
		$pconfig = array();
343
		$pconfig['name'] = "miniupnpd";
344
		$pconfig['description'] = gettext("UPnP Service");
345
		$services[] = $pconfig;
346
	}
347

    
348
	if (ipsec_enabled()) {
349
		$pconfig = array();
350
		$pconfig['name'] = "ipsec";
351
		$pconfig['description'] = gettext("IPsec VPN");
352
		$services[] = $pconfig;
353
	}
354

    
355
	if (isset($config['system']['ssh']['enable'])) {
356
		$pconfig = array();
357
		$pconfig['name'] = "sshd";
358
		$pconfig['description'] = gettext("Secure Shell Daemon");
359
		$services[] = $pconfig;
360
	}
361

    
362
	foreach (array('server', 'client') as $mode) {
363
		if (is_array($config['openvpn']["openvpn-{$mode}"])) {
364
			foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) {
365
				if (!isset($setting['disable'])) {
366
					$pconfig = array();
367
					$pconfig['name'] = "openvpn";
368
					$pconfig['mode'] = $mode;
369
					$pconfig['id'] = $id;
370
					$pconfig['vpnid'] = $setting['vpnid'];
371
					$pconfig['description'] = gettext("OpenVPN") . " " . $mode . ": " . htmlspecialchars($setting['description']);
372
					$services[] = $pconfig;
373
				}
374
			}
375
		}
376
	}
377

    
378
	return $services;
379
}
380

    
381
function find_service_by_name($name) {
382
	$services = get_services();
383
	foreach ($services as $service) {
384
		if (isset($service["name"]) && ($service["name"] == $name)) {
385
			return $service;
386
		}
387
	}
388
	return array();
389
}
390

    
391
function find_service_by_openvpn_vpnid($vpnid) {
392
	$services = get_services();
393
	foreach ($services as $service) {
394
		if (isset($service["name"]) && ($service["name"] == "openvpn") && isset($service["vpnid"]) && ($service["vpnid"] == $vpnid)) {
395
			return $service;
396
		}
397
	}
398
	return array();
399
}
400

    
401
function find_service_by_cp_zone($zone) {
402
	$services = get_services();
403
	foreach ($services as $service) {
404
		if (isset($service["name"]) && ($service["name"] == "captiveportal") && isset($service["zone"]) && ($service["zone"] == $zone)) {
405
			return $service;
406
		}
407
	}
408
	return array();
409
}
410

    
411
function service_description_compare($a, $b) {
412
	if (strtolower($a['description']) == strtolower($b['description'])) {
413
		return 0;
414
	}
415
	return (strtolower($a['description']) < strtolower($b['description'])) ? -1 : 1;
416
}
417

    
418
function service_name_compare($a, $b) {
419
	if (!isset($a['name']) || !isset($b['name'])) {
420
		return -1;
421
	}
422
	/* If the names are equal, fall back to sorting by description */
423
	if (strtolower($a['name']) == strtolower($b['name'])) {
424
		return service_description_compare($a, $b);
425
	}
426
	return (strtolower($a['name']) < strtolower($b['name'])) ? -1 : 1;
427
}
428

    
429
function service_dispname_compare($a, $b) {
430
	/* If two items have an instance suffix, perform an integer comparison to avoid awkward sorting */
431
	if ((strpos($a['dispname'], '_') > 0) && (strpos($b['dispname'], '_') > 0)) {
432
		list($adn1, $adn2) = explode('_', $a['dispname'], 2);
433
		list($bdn1, $bdn2) = explode('_', $b['dispname'], 2);
434
		if (($adn1 == $bdn1) && is_numeric($adn2) && is_numeric($bdn2)) {
435
			if ($adn2 == $bdn2) {
436
				return 0;
437
			}
438
			return ((int)$adn2 < (int)$bdn2) ? -1 : 1;
439
		}
440
	}
441
	/* If the display names are equal, compare the internal name */
442
	if (strtolower($a['dispname']) == strtolower($b['dispname'])) {
443
		return service_name_compare($a, $b);
444
	}
445
	return (strtolower($a['dispname']) < strtolower($b['dispname'])) ? -1 : 1;
446
}
447

    
448
function get_pkg_descr($package_name) {
449
	global $config;
450
	if (is_array($config['installedpackages']['package'])) {
451
		foreach ($config['installedpackages']['package'] as $pkg) {
452
			if ($pkg['name'] == $package_name) {
453
				return $pkg['descr'];
454
			}
455
		}
456
	}
457
	return gettext("Not available.");
458
}
459

    
460
function get_service_status($service) {
461
	global $g;
462
	switch ($service['name']) {
463
		case "openvpn":
464
			$running = is_pid_running("{$g['varrun_path']}/openvpn_{$service['mode']}{$service['vpnid']}.pid");
465
			break;
466
		case "captiveportal":
467
			$running = is_pid_running("{$g['varrun_path']}/nginx-{$service['zone']}-CaptivePortal.pid");
468
			if (isset($config['captiveportal'][$service['zone']]['httpslogin'])) {
469
				$running = $running && is_pid_running("{$g['varrun_path']}/nginx-{$service['zone']}-CaptivePortal-SSL.pid");
470
			}
471
			break;
472
		case "vhosts-http":
473
			$running = is_pid_running("{$g['varrun_path']}/vhosts-http.pid");
474
			break;
475
		case "dhcrelay6":
476
			$running = is_pid_running("{$g['varrun_path']}/dhcrelay6.pid");
477
			break;
478
		case 'ipsec':
479
			$running = is_pid_running("{$g['varrun_path']}/charon.pid");
480
			break;
481
		default:
482
			$running = is_service_running($service['name']);
483
	}
484
	return $running;
485
}
486

    
487
function get_service_status_icon($service, $withtext = true, $smallicon = false, $withthumbs = false, $title = "service_state") {
488
	$output = "";
489

    
490
	if (get_service_status($service)) {
491
		$statustext = gettext("Running");
492
		$text_class = "text-success";
493
		$fa_class = "fa fa-check-circle";
494
		$fa_class_thumbs = "fa fa-thumbs-o-up";
495
		$Thumbs_UpDown = "Thumbs up";
496
	} else {
497
		if (is_service_enabled($service['name'])) {
498
			$statustext = gettext("Stopped");
499
			$text_class = "text-danger";
500
			$fa_class = "fa fa-times-circle";
501
		} else {
502
			$statustext = gettext("Disabled");
503
			$text_class = "text-warning";
504
			$fa_class = "fa fa-ban";
505
		}
506
		$fa_class_thumbs = "fa fa-thumbs-o-down";
507
		$Thumbs_UpDown = "Thumbs down";
508
	}
509
	$fa_size = ($smallicon) ? "fa-1x" : "fa-lg";
510

    
511
	if ($title == "state") {
512
		$title = $statustext;
513
	} elseif ($title == "service_state") {
514
		$title = sprintf(gettext('%1$s Service is %2$s'), $service["name"], $statustext);
515
	} elseif ($title == "description_state") {
516
		$title = sprintf(gettext('%1$s Service is %2$s'), $service["description"], $statustext);
517
	} elseif ($title == "description_service_state") {
518
		$title = sprintf(gettext('%1$s, %2$s Service is %3$s'), $service["description"], $service["name"], $statustext);
519
	}
520

    
521
	$spacer = ($withthumbs || $withtext) ? " " : "";
522

    
523
	$output = "<i class=\"{$text_class} {$fa_class} {$fa_size}\" title=\"{$title}\"><span style=\"display: none\">{$statustext}</span></i>{$spacer}";
524

    
525
	$spacer = ($withtext) ? " " : "";
526
	if ($withthumbs) {
527
		$output .= "<i class=\"{$text_class} {$fa_class_thumbs} {$fa_size}\" title=\"{$Thumbs_UpDown}\"></i>{$spacer}";
528
	}
529

    
530
	if ($withtext) {
531
		$output .= "<span class=\"" . $text_class . "\">" . $statustext . "</span>";
532
	}
533

    
534
	return $output;
535
}
536

    
537
function get_service_control_links($service, $addname = false) {
538
	global $g;
539
	$output = "";
540
	$stitle = ($addname) ? $service['name'] . " " : "";
541

    
542
	switch ($service['name']) {
543
		case "openvpn":
544
			$link = '<a title="%s" href="#" id="openvpn-%s-' . $service['mode'] . '-' . $service['vpnid'] . '" >';
545
		break;
546
		case "captiveportal":
547
			$link = '<a title="%s" href="#" id="captiveportal-%s-' . $service['zone'] . '">';
548
		break;
549
		default:
550
			$link = '<a title="%s" href="#" id="%s-' . $service['name'] . '">';
551
	}
552

    
553
	if (get_service_status($service)) {
554
		switch ($service['name']) {
555
			case "openvpn":
556
				$output .= '<a href="#" id="openvpn-restartservice-' . $service['mode'] . '-' . $service['vpnid'] . '" >';
557
				break;
558
			case "captiveportal":
559
				$output .= '<a href="#" id="captiveportal-restartservice-' . $service['zone'] . '">';
560
				break;
561
			default:
562
				$output .= '<a href="#" id="restartservice-' . $service['name'] . '" >';
563
		}
564

    
565
		$output .= "<i class=\"fa fa-repeat\" title=\"" . sprintf(gettext("Restart %sService"), $stitle) . "\"></i></a>\n";
566

    
567
		switch ($service['name']) {
568
			case "openvpn":
569
				$output .= '<a href="#" id="openvpn-stopservice-' . $service['mode'] . '-' . $service['vpnid'] . '" >';
570
				break;
571
			case "captiveportal":
572
				$output .= '<a href="#" id="captiveportal-stopservice-' . $service['zone'] . '">';
573
				break;
574
			default:
575
				$output .= '<a href="#" id="stopservice-' . $service['name'] . '">';
576
		}
577

    
578
		$output .= "<i class=\"fa fa-stop-circle-o\" title=\"" . sprintf(gettext("Stop %sService"), $stitle) . "\"></i></a>";
579

    
580
	} else {
581
		$service_enabled = is_service_enabled($service['name']);
582

    
583
		if ($service['name'] == 'openvpn' || $service['name'] == 'captiveportal' || $service_enabled) {
584
			$output .= sprintf($link, sprintf(gettext("Start %sService"), $stitle), 'startservice');
585
			$output .= '<i class="fa fa-play-circle"></i></a> ';
586
		}
587
	}
588

    
589
	return $output;
590
}
591

    
592
function service_control_start($name, $extras) {
593
	global $g;
594
	switch ($name) {
595
		case 'radvd':
596
			services_radvd_configure();
597
			break;
598
		case 'captiveportal':
599
			$zone = htmlspecialchars($extras['zone']);
600
			captiveportal_init_webgui_zonename($zone);
601
			break;
602
		case 'ntpd':
603
			system_ntp_configure();
604
			break;
605
		case 'dpinger':
606
			setup_gateways_monitor();
607
			break;
608
		case 'bsnmpd':
609
			services_snmpd_configure();
610
			break;
611
		case 'dhcrelay':
612
			services_dhcrelay_configure();
613
			break;
614
		case 'dhcrelay6':
615
			services_dhcrelay6_configure();
616
			break;
617
		case 'dnsmasq':
618
			services_dnsmasq_configure();
619
			break;
620
		case 'unbound':
621
			services_unbound_configure();
622
			break;
623
		case 'dhcpd':
624
			services_dhcpd_configure();
625
			break;
626
		case 'igmpproxy':
627
			services_igmpproxy_configure();
628
			break;
629
		case 'miniupnpd':
630
			upnp_action('start');
631
			break;
632
		case 'ipsec':
633
			vpn_ipsec_force_reload();
634
			break;
635
		case 'sshd':
636
			send_event("service restart sshd");
637
			break;
638
		case 'openvpn':
639
			$vpnmode = isset($extras['vpnmode']) ? htmlspecialchars($extras['vpnmode']) : htmlspecialchars($extras['mode']);
640
			if (($vpnmode == "server") || ($vpnmode == "client")) {
641
				$id = isset($extras['vpnid']) ? htmlspecialchars($extras['vpnid']) : htmlspecialchars($extras['id']);
642
				$configfile = "{$g['openvpn_base']}/{$vpnmode}{$id}/config.ovpn";
643
				if (file_exists($configfile)) {
644
					openvpn_restart_by_vpnid($vpnmode, $id);
645
				}
646
			}
647
			break;
648
		case 'syslogd':
649
			system_syslogd_start();
650
			break;
651
		default:
652
			start_service($name);
653
			break;
654
	}
655
	return sprintf(gettext("%s has been started."), htmlspecialchars($name));
656
}
657
function service_control_stop($name, $extras) {
658
	global $g;
659
	switch ($name) {
660
		case 'radvd':
661
			killbypid("{$g['varrun_path']}/radvd.pid");
662
			break;
663
		case 'captiveportal':
664
			$zone = htmlspecialchars($extras['zone']);
665
			killbypid("{$g['varrun_path']}/nginx-{$zone}-CaptivePortal.pid");
666
			killbypid("{$g['varrun_path']}/nginx-{$zone}-CaptivePortal-SSL.pid");
667
			break;
668
		case 'ntpd':
669
			killbyname("ntpd");
670
			break;
671
		case 'openntpd':
672
			killbyname("openntpd");
673
			break;
674
		case 'dpinger':
675
			stop_dpinger();
676
			break;
677
		case 'bsnmpd':
678
			killbypid("{$g['varrun_path']}/snmpd.pid");
679
			break;
680
		case 'choparp':
681
			killbyname("choparp");
682
			break;
683
		case 'dhcpd':
684
			killbyname("dhcpd");
685
			break;
686
		case 'dhcrelay':
687
			killbypid("{$g['varrun_path']}/dhcrelay.pid");
688
			break;
689
		case 'dhcrelay6':
690
			killbypid("{$g['varrun_path']}/dhcrelay6.pid");
691
			break;
692
		case 'dnsmasq':
693
			killbypid("{$g['varrun_path']}/dnsmasq.pid");
694
			break;
695
		case 'unbound':
696
			killbypid("{$g['varrun_path']}/unbound.pid");
697
			break;
698
		case 'igmpproxy':
699
			killbyname("igmpproxy");
700
			break;
701
		case 'miniupnpd':
702
			upnp_action('stop');
703
			break;
704
		case 'sshd':
705
			killbyname("sshd");
706
			break;
707
		case 'ipsec':
708
			exec("/usr/local/sbin/ipsec stop");
709
			break;
710
		case 'openvpn':
711
			$vpnmode = htmlspecialchars($extras['vpnmode']);
712
			if (($vpnmode == "server") or ($vpnmode == "client")) {
713
				$id = htmlspecialchars($extras['id']);
714
				$pidfile = "{$g['varrun_path']}/openvpn_{$vpnmode}{$id}.pid";
715
				killbypid($pidfile);
716
			}
717
			break;
718
		case 'syslogd':
719
			if (isvalidpid("{$g['varrun_path']}/syslog.pid")) {
720
				sigkillbypid("{$g['varrun_path']}/syslog.pid", "TERM");
721
				usleep(100000);
722
			}
723
			if (isvalidpid("{$g['varrun_path']}/syslog.pid")) {
724
				sigkillbypid("{$g['varrun_path']}/syslog.pid", "KILL");
725
				usleep(100000);
726
			}
727
			/* Make sure sshguard stops as well */
728
			sigkillbyname("sshguard", "TERM");
729
			break;
730
		default:
731
			stop_service($name);
732
			break;
733
	}
734
	return sprintf(gettext("%s has been stopped."), htmlspecialchars($name));
735
}
736

    
737
function service_control_restart($name, $extras) {
738
	global $g;
739
	switch ($name) {
740
		case 'radvd':
741
			services_radvd_configure();
742
			break;
743
		case 'captiveportal':
744
			$zone = htmlspecialchars($extras['zone']);
745
			killbypid("{$g['varrun_path']}/nginx-{$zone}-CaptivePortal.pid");
746
			killbypid("{$g['varrun_path']}/nginx-{$zone}-CaptivePortal-SSL.pid");
747
			captiveportal_init_webgui_zonename($zone);
748
			break;
749
		case 'ntpd':
750
		case 'openntpd':
751
			system_ntp_configure();
752
			break;
753
		case 'dpinger':
754
			setup_gateways_monitor();
755
			break;
756
		case 'bsnmpd':
757
			services_snmpd_configure();
758
			break;
759
		case 'dhcrelay':
760
			services_dhcrelay_configure();
761
			break;
762
		case 'dhcrelay6':
763
			services_dhcrelay6_configure();
764
			break;
765
		case 'dnsmasq':
766
			services_dnsmasq_configure();
767
			break;
768
		case 'unbound':
769
			services_unbound_configure();
770
			break;
771
		case 'dhcpd':
772
			services_dhcpd_configure();
773
			break;
774
		case 'igmpproxy':
775
			services_igmpproxy_configure();
776
			break;
777
		case 'miniupnpd':
778
			upnp_action('restart');
779
			break;
780
		case 'ipsec':
781
			vpn_ipsec_force_reload();
782
			break;
783
		case 'sshd':
784
			send_event("service restart sshd");
785
			break;
786
		case 'openvpn':
787
			$vpnmode = htmlspecialchars($extras['vpnmode']);
788
			if ($vpnmode == "server" || $vpnmode == "client") {
789
				$id = htmlspecialchars($extras['id']);
790
				$configfile = "{$g['openvpn_base']}/{$vpnmode}{$id}/config.ovpn";
791
				if (file_exists($configfile)) {
792
					openvpn_restart_by_vpnid($vpnmode, $id);
793
				}
794
			}
795
			break;
796
		case 'syslogd':
797
			system_syslogd_start();
798
			break;
799
		default:
800
			restart_service($name);
801
			break;
802
	}
803
	return sprintf(gettext("%s has been restarted."), htmlspecialchars($name));
804
}
805

    
806
?>
(45-45/60)