Project

General

Profile

Download (20.7 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-2016 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("globals.inc");
24
require_once("captiveportal.inc");
25
require_once("openvpn.inc");
26
require_once("ipsec.inc");
27
require_once("vpn.inc");
28
require_once("vslb.inc");
29
require_once("gwlb.inc");
30

    
31
define("RCFILEPREFIX", "/usr/local/etc/rc.d/");
32
function write_rcfile($params) {
33
	global $g;
34

    
35
	safe_mkdir(RCFILEPREFIX);
36
	$rcfile_fullname = RCFILEPREFIX . $params['file'];
37
	if (!file_exists($rcfile_fullname) && !is_link($rcfile_fullname) && !touch($rcfile_fullname)) {
38
		return false;
39
	}
40

    
41
	if (!is_writable($rcfile_fullname) || empty($params['start'])) {
42
		return false;
43
	}
44

    
45
	$towrite = "#!/bin/sh\n";
46
	$towrite .= "# This file was automatically generated\n# by the {$g['product_name']} service handler.\n\n";
47

    
48
	/* write our rc functions */
49
	$towrite .= "rc_start() {\n";
50
	$towrite .= "\t{$params['start']}\n";
51
	$towrite .= "}\n\n";
52
	if (!empty($params['stop'])) {
53
		$tokill =& $params['stop'];
54
	} else if (!empty($params['executable'])) {
55
		/* just nuke the executable */
56
		$tokill = "/usr/bin/killall " . escapeshellarg($params['executable']);
57
	} else {
58
		/* make an educated guess (bad) */
59
		$tokill = array_pop(explode('/', array_shift(explode(' ', $params['start']))));
60
	}
61
	$towrite .= "rc_stop() {\n";
62
	$towrite .= "\t{$tokill}\n";
63
	$towrite .= "}\n\n";
64

    
65
	/* begin rcfile logic */
66
	$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";
67

    
68
	@file_put_contents($rcfile_fullname, $towrite);
69
	unset($towrite);
70
	@chmod("{$rcfile_fullname}", 0755);
71

    
72
	return;
73
}
74

    
75
function start_service($name) {
76
	global $config;
77

    
78
	if (empty($name)) {
79
		return;
80
	}
81

    
82
	if (is_array($config['installedpackages']) && is_array($config['installedpackages']['service'])) {
83
		foreach ($config['installedpackages']['service'] as $service) {
84
			if (strtolower($service['name']) == strtolower($name)) {
85
				if ($service['rcfile']) {
86
					$prefix = RCFILEPREFIX;
87
					if (!empty($service['prefix'])) {
88
						$prefix =& $service['prefix'];
89
					}
90
					if (file_exists("{$prefix}{$service['rcfile']}") || is_link("{$prefix}{$service['rcfile']}")) {
91
						mwexec_bg("{$prefix}{$service['rcfile']} start");
92
					}
93
				}
94
				if (!empty($service['startcmd'])) {
95
					eval($service['startcmd']);
96
				}
97
				break;
98
			}
99
		}
100
	}
101
}
102

    
103
function stop_service($name) {
104
	global $config;
105

    
106
	if (empty($name)) {
107
		return;
108
	}
109

    
110
	if (is_array($config['installedpackages']) && is_array($config['installedpackages']['service'])) {
111
		foreach ($config['installedpackages']['service'] as $service) {
112
			if (strtolower($service['name']) == strtolower($name)) {
113
				if ($service['rcfile']) {
114
					$prefix = RCFILEPREFIX;
115
					if (!empty($service['prefix'])) {
116
						$prefix =& $service['prefix'];
117
					}
118
					if (file_exists("{$prefix}{$service['rcfile']}") || is_link("{$prefix}{$service['rcfile']}")) {
119
						mwexec("{$prefix}{$service['rcfile']} stop");
120
					}
121
					return;
122
				}
123
				if (!empty($service['stopcmd'])) {
124
					eval($service['stopcmd']);
125
				} elseif (!empty($service['executable'])) {
126
					mwexec("/usr/bin/killall " . escapeshellarg($service['executable']));
127
				}
128

    
129
				break;
130
			}
131
		}
132
	}
133
}
134

    
135
function restart_service($name) {
136
	global $config;
137

    
138
	if (empty($name)) {
139
		return;
140
	}
141

    
142
	if (is_service_running($name)) {
143
		stop_service($name);
144
	}
145
	start_service($name);
146

    
147
	if (is_array($config['installedpackages']) && is_array($config['installedpackages']['service'])) {
148
		foreach ($config['installedpackages']['service'] as $service) {
149
			if (strtolower($service['name']) == strtolower($name)) {
150
				if ($service['restartcmd']) {
151
					eval($service['restartcmd']);
152
				}
153
				break;
154
			}
155
		}
156
	}
157
}
158

    
159
function is_pid_running($pidfile) {
160
	if (!file_exists($pidfile)) {
161
		return false;
162
	}
163

    
164
	return (isvalidpid($pidfile));
165
}
166

    
167
function is_dhcp_running($interface) {
168
	$status = find_dhclient_process($interface);
169
	if ($status != 0) {
170
		return true;
171
	}
172
	return false;
173
}
174

    
175
function restart_service_if_running($service) {
176
	global $config;
177
	if (is_service_running($service)) {
178
		restart_service($service);
179
	}
180
	return;
181
}
182

    
183
function is_service_enabled($service_name) {
184
	global $config;
185
	if ($service_name == "") {
186
		return false;
187
	}
188
	if (is_array($config['installedpackages'])) {
189
		if (isset($config['installedpackages'][$service_name]['config'][0]['enable']) &&
190
		    ((empty($config['installedpackages'][$service_name]['config'][0]['enable'])) ||
191
		    ($config['installedpackages'][$service_name]['config'][0]['enable'] === 'off'))) {
192
			return false;
193
		}
194
	}
195
	return true;
196
}
197

    
198
function is_service_running($service, $ps = "") {
199
	global $config;
200

    
201
	if (is_array($config['installedpackages']['service'])) {
202
		foreach ($config['installedpackages']['service'] as $aservice) {
203
			if (strtolower($service) == strtolower($aservice['name'])) {
204
				if ($aservice['custom_php_service_status_command'] <> "") {
205
					eval("\$rc={$aservice['custom_php_service_status_command']};");
206
					return $rc;
207
				}
208
				if (empty($aservice['executable'])) {
209
					return false;
210
				}
211
				if (is_process_running($aservice['executable'])) {
212
					return true;
213
				}
214

    
215
				return false;
216
			}
217
		}
218
	}
219

    
220
	if (is_process_running($service)) {
221
		return true;
222
	}
223

    
224
	return false;
225
}
226

    
227
function get_services() {
228
	global $config;
229
	if (is_array($config['installedpackages']['service'])) {
230
		$services = $config['installedpackages']['service'];
231
	} else {
232
		$services = array();
233
	}
234

    
235
	/*
236
	 * Add services that are in the base.
237
	 */
238
	if (is_radvd_enabled()) {
239
		$pconfig = array();
240
		$pconfig['name'] = "radvd";
241
		$pconfig['description'] = gettext("Router Advertisement Daemon");
242
		$services[] = $pconfig;
243
	}
244

    
245
	if (isset($config['dnsmasq']['enable'])) {
246
		$pconfig = array();
247
		$pconfig['name'] = "dnsmasq";
248
		$pconfig['description'] = gettext("DNS Forwarder");
249
		$services[] = $pconfig;
250
	}
251

    
252
	if (isset($config['unbound']['enable'])) {
253
		$pconfig = array();
254
		$pconfig['name'] = "unbound";
255
		$pconfig['description'] = gettext("DNS Resolver");
256
		$services[] = $pconfig;
257
	}
258

    
259
	$pconfig = array();
260
	$pconfig['name'] = "ntpd";
261
	$pconfig['description'] = gettext("NTP clock sync");
262
	$services[] = $pconfig;
263

    
264
	if (is_array($config['captiveportal'])) {
265
		foreach ($config['captiveportal'] as $zone => $setting) {
266
			if (isset($setting['enable'])) {
267
				$pconfig = array();
268
				$pconfig['name'] = "captiveportal";
269
				$pconfig['zone'] = $zone;
270
				$pconfig['description'] = gettext("Captive Portal") . ": " . htmlspecialchars($setting['zone']);
271
				$services[] = $pconfig;
272
			}
273
		}
274
	}
275

    
276
	$iflist = array();
277
	$ifdescrs = get_configured_interface_list();
278
	foreach ($ifdescrs as $if) {
279
		$oc = $config['interfaces'][$if];
280
		if ($oc['if'] && (!link_interface_to_bridge($if))) {
281
			$iflist[$if] = $if;
282
		}
283
	}
284

    
285
	if (isset($config['dhcrelay']['enable'])) {
286
		$pconfig = array();
287
		$pconfig['name'] = "dhcrelay";
288
		$pconfig['description'] = gettext("DHCP Relay");
289
		$services[] = $pconfig;
290
	}
291

    
292
	if (isset($config['dhcrelay6']['enable'])) {
293
		$pconfig = array();
294
		$pconfig['name'] = "dhcrelay6";
295
		$pconfig['description'] = gettext("DHCPv6 Relay");
296
		$services[] = $pconfig;
297
	}
298

    
299
	if (is_dhcp_server_enabled()) {
300
		$pconfig = array();
301
		$pconfig['name'] = "dhcpd";
302
		$pconfig['description'] = gettext("DHCP Service");
303
		$services[] = $pconfig;
304
	}
305

    
306
	$gateways_arr = return_gateways_array();
307
	if (is_array($gateways_arr)) {
308
		$pconfig = array();
309
		$pconfig['name'] = "dpinger";
310
		$pconfig['description'] = gettext("Gateway Monitoring Daemon");
311
		$services[] = $pconfig;
312
	}
313

    
314
	if (isset($config['snmpd']['enable'])) {
315
		$pconfig = array();
316
		$pconfig['name'] = "bsnmpd";
317
		$pconfig['description'] = gettext("SNMP Service");
318
		$services[] = $pconfig;
319
	}
320

    
321
	if (is_array($config['igmpproxy']['igmpentry']) && (count($config['igmpproxy']['igmpentry']) > 0)) {
322
		$pconfig = array();
323
		$pconfig['name'] = "igmpproxy";
324
		$pconfig['description'] = gettext("IGMP proxy");
325
		$services[] = $pconfig;
326
	}
327

    
328
	if (isset($config['installedpackages']['miniupnpd']) && $config['installedpackages']['miniupnpd']['config'][0]['enable']) {
329
		$pconfig = array();
330
		$pconfig['name'] = "miniupnpd";
331
		$pconfig['description'] = gettext("UPnP Service");
332
		$services[] = $pconfig;
333
	}
334

    
335
	if (ipsec_enabled()) {
336
		$pconfig = array();
337
		$pconfig['name'] = "ipsec";
338
		$pconfig['description'] = gettext("IPsec VPN");
339
		$services[] = $pconfig;
340
	}
341

    
342
	if (isset($config['system']['enablesshd'])) {
343
		$pconfig = array();
344
		$pconfig['name'] = "sshd";
345
		$pconfig['description'] = gettext("Secure Shell Daemon");
346
		$services[] = $pconfig;
347
	}
348

    
349
	foreach (array('server', 'client') as $mode) {
350
		if (is_array($config['openvpn']["openvpn-{$mode}"])) {
351
			foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) {
352
				if (!isset($setting['disable'])) {
353
					$pconfig = array();
354
					$pconfig['name'] = "openvpn";
355
					$pconfig['mode'] = $mode;
356
					$pconfig['id'] = $id;
357
					$pconfig['vpnid'] = $setting['vpnid'];
358
					$pconfig['description'] = gettext("OpenVPN") . " " . $mode . ": " . htmlspecialchars($setting['description']);
359
					$services[] = $pconfig;
360
				}
361
			}
362
		}
363
	}
364

    
365
	if (count($config['load_balancer']['virtual_server']) && count($config['load_balancer']['lbpool'])) {
366
		$pconfig = array();
367
		$pconfig['name'] = "relayd";
368
		$pconfig['description'] = gettext("Server load balancing daemon");
369
		$services[] = $pconfig;
370
	}
371
	return $services;
372
}
373

    
374
function find_service_by_name($name) {
375
	$services = get_services();
376
	foreach ($services as $service) {
377
		if ($service["name"] == $name) {
378
			return $service;
379
		}
380
	}
381
	return array();
382
}
383

    
384
function find_service_by_openvpn_vpnid($vpnid) {
385
	$services = get_services();
386
	foreach ($services as $service) {
387
		if (($service["name"] == "openvpn") && isset($service["vpnid"]) && ($service["vpnid"] == $vpnid)) {
388
			return $service;
389
		}
390
	}
391
	return array();
392
}
393

    
394
function find_service_by_cp_zone($zone) {
395
	$services = get_services();
396
	foreach ($services as $service) {
397
		if (($service["name"] == "captiveportal") && isset($service["zone"]) && ($service["zone"] == $zone)) {
398
			return $service;
399
		}
400
	}
401
	return array();
402
}
403

    
404
function service_name_compare($a, $b) {
405
	if (strtolower($a['name']) == strtolower($b['name'])) {
406
		return 0;
407
	}
408
	return (strtolower($a['name']) < strtolower($b['name'])) ? -1 : 1;
409
}
410

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

    
418
function get_pkg_descr($package_name) {
419
	global $config;
420
	if (is_array($config['installedpackages']['package'])) {
421
		foreach ($config['installedpackages']['package'] as $pkg) {
422
			if ($pkg['name'] == $package_name) {
423
				return $pkg['descr'];
424
			}
425
		}
426
	}
427
	return gettext("Not available.");
428
}
429

    
430
function get_service_status($service) {
431
	global $g;
432
	switch ($service['name']) {
433
		case "openvpn":
434
			$running = is_pid_running("{$g['varrun_path']}/openvpn_{$service['mode']}{$service['vpnid']}.pid");
435
			break;
436
		case "captiveportal":
437
			$running = is_pid_running("{$g['varrun_path']}/nginx-{$service['zone']}-CaptivePortal.pid");
438
			if (isset($config['captiveportal'][$service['zone']]['httpslogin'])) {
439
				$running = $running && is_pid_running("{$g['varrun_path']}/nginx-{$service['zone']}-CaptivePortal-SSL.pid");
440
			}
441
			break;
442
		case "vhosts-http":
443
			$running = is_pid_running("{$g['varrun_path']}/vhosts-http.pid");
444
			break;
445
		case "dhcrelay6":
446
			$running = is_pid_running("{$g['varrun_path']}/dhcrelay6.pid");
447
			break;
448
		case 'ipsec':
449
			$running = is_pid_running("{$g['varrun_path']}/charon.pid");
450
			break;
451
		default:
452
			$running = is_service_running($service['name']);
453
	}
454
	return $running;
455
}
456

    
457
function get_service_status_icon($service, $withtext = true, $smallicon = false, $withthumbs = false, $title = "service_state") {
458
	$output = "";
459

    
460
	if (get_service_status($service)) {
461
		$statustext = gettext("Running");
462
		$text_class = "text-success";
463
		$fa_class = "fa fa-check-circle";
464
		$fa_class_thumbs = "fa fa-thumbs-o-up";
465
		$Thumbs_UpDown = "Thumbs up";
466
	} else {
467
		if (is_service_enabled($service['name'])) {
468
			$statustext = gettext("Stopped");
469
			$text_class = "text-danger";
470
			$fa_class = "fa fa-times-circle";
471
		} else {
472
			$statustext = gettext("Disabled");
473
			$text_class = "text-warning";
474
			$fa_class = "fa fa-ban";
475
		}
476
		$fa_class_thumbs = "fa fa-thumbs-o-down";
477
		$Thumbs_UpDown = "Thumbs down";
478
	}
479
	$fa_size = ($smallicon) ? "fa-1x" : "fa-lg";
480

    
481
	$spacer = ($withthumbs || $withtext) ? " " : "";
482
	if ($title == "state") {
483
		$output = "<i class=\"{$text_class} {$fa_class} {$fa_size}\" title=\"{$statustext}\"></i>{$spacer}";
484
	} elseif ($title == "service_state") {
485
		$output = "<i class=\"{$text_class} {$fa_class} {$fa_size}\" title=\"" . sprintf(gettext('%1$s Service is %2$s'), $service["name"], $statustext) . "\"></i>{$spacer}";
486
	} elseif ($title == "description_state") {
487
		$output = "<i class=\"{$text_class} {$fa_class} {$fa_size}\" title=\"" . sprintf(gettext('%1$s Service is %2$s'), $service["description"], $statustext) . "\"></i>{$spacer}";
488
	} elseif ($title == "description_service_state") {
489
		$output = "<i class=\"{$text_class} {$fa_class} {$fa_size}\" title=\"" . sprintf(gettext('%1$s, %2$s Service is %3$s'), $service["description"], $service["name"], $statustext) . "\"></i>{$spacer}";
490
	}
491

    
492
	$spacer = ($withtext) ? " " : "";
493
	if ($withthumbs) {
494
		$output .= "<i class=\"{$text_class} {$fa_class_thumbs} {$fa_size}\" title=\"{$Thumbs_UpDown}\"></i>{$spacer}";
495
	}
496

    
497
	if ($withtext) {
498
		$output .= "<span class=\"" . $text_class . "\">" . $statustext . "</span>";
499
	}
500

    
501
	return $output;
502
}
503

    
504
function get_service_control_links($service, $addname = false) {
505
	global $g;
506
	$output = "";
507
	$stitle = ($addname) ? $service['name'] . " " : "";
508

    
509
	switch ($service['name']) {
510
		case "openvpn":
511
			$link = '<a title="%s" href="#" id="openvpn-%s-' . $service['mode'] . '-' . $service['vpnid'] . '" >';
512
		break;
513
		case "captiveportal":
514
			$link = '<a title="%s" href="#" id="captiveportal-%s-' . $service['zone'] . '">';
515
		break;
516
		default:
517
			$link = '<a title="%s" href="#" id="%s-' . $service['name'] . '">';
518
	}
519

    
520
	if (get_service_status($service)) {
521
		switch ($service['name']) {
522
			case "openvpn":
523
				$output .= '<a href="#" id="openvpn-restartservice-' . $service['mode'] . '-' . $service['vpnid'] . '" >';
524
				break;
525
			case "captiveportal":
526
				$output .= '<a href="#" id="captiveportal-restartservice-' . $service['zone'] . '">';
527
				break;
528
			default:
529
				$output .= '<a href="#" id="restartservice-' . $service['name'] . '" >';
530
		}
531

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

    
534
		switch ($service['name']) {
535
			case "openvpn":
536
				$output .= '<a href="#" id="openvpn-stopservice-' . $service['mode'] . '-' . $service['vpnid'] . '" >';
537
				break;
538
			case "captiveportal":
539
				$output .= '<a href="#" id="captiveportal-stopservice-' . $service['zone'] . '">';
540
				break;
541
			default:
542
				$output .= '<a href="#" id="stopservice-' . $service['name'] . '">';
543
		}
544

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

    
547
	} else {
548
		$service_enabled = is_service_enabled($service['name']);
549

    
550
		if ($service['name'] == 'openvpn' || $service['name'] == 'captiveportal' || $service_enabled) {
551
			$output .= sprintf($link, sprintf(gettext("Start %sService"), $stitle), 'startservice');
552
			$output .= '<i class="fa fa-play-circle"></i></a> ';
553
		}
554
	}
555

    
556
	return $output;
557
}
558

    
559
function service_control_start($name, $extras) {
560
	global $g;
561
	switch ($name) {
562
		case 'radvd':
563
			services_radvd_configure();
564
			break;
565
		case 'captiveportal':
566
			$zone = htmlspecialchars($extras['zone']);
567
			captiveportal_init_webgui_zonename($zone);
568
			break;
569
		case 'ntpd':
570
		case 'openntpd':
571
			system_ntp_configure();
572
			break;
573
		case 'dpinger':
574
			setup_gateways_monitor();
575
			break;
576
		case 'bsnmpd':
577
			services_snmpd_configure();
578
			break;
579
		case 'dhcrelay':
580
			services_dhcrelay_configure();
581
			break;
582
		case 'dhcrelay6':
583
			services_dhcrelay6_configure();
584
			break;
585
		case 'dnsmasq':
586
			services_dnsmasq_configure();
587
			break;
588
		case 'unbound':
589
			services_unbound_configure();
590
			break;
591
		case 'dhcpd':
592
			services_dhcpd_configure();
593
			break;
594
		case 'igmpproxy':
595
			services_igmpproxy_configure();
596
			break;
597
		case 'miniupnpd':
598
			upnp_action('start');
599
			break;
600
		case 'ipsec':
601
			vpn_ipsec_force_reload();
602
			break;
603
		case 'sshd':
604
			send_event("service restart sshd");
605
			break;
606
		case 'openvpn':
607
			$vpnmode = isset($extras['vpnmode']) ? htmlspecialchars($extras['vpnmode']) : htmlspecialchars($extras['mode']);
608
			if (($vpnmode == "server") || ($vpnmode == "client")) {
609
				$id = isset($extras['vpnid']) ? htmlspecialchars($extras['vpnid']) : htmlspecialchars($extras['id']);
610
				$configfile = "{$g['varetc_path']}/openvpn/{$vpnmode}{$id}.conf";
611
				if (file_exists($configfile)) {
612
					openvpn_restart_by_vpnid($vpnmode, $id);
613
				}
614
			}
615
			break;
616
		case 'relayd':
617
			relayd_configure();
618
			break;
619
		default:
620
			start_service($name);
621
			break;
622
	}
623
	return sprintf(gettext("%s has been started."), htmlspecialchars($name));
624
}
625
function service_control_stop($name, $extras) {
626
	global $g;
627
	switch ($name) {
628
		case 'radvd':
629
			killbypid("{$g['varrun_path']}/radvd.pid");
630
			break;
631
		case 'captiveportal':
632
			$zone = htmlspecialchars($extras['zone']);
633
			killbypid("{$g['varrun_path']}/nginx-{$zone}-CaptivePortal.pid");
634
			killbypid("{$g['varrun_path']}/nginx-{$zone}-CaptivePortal-SSL.pid");
635
			break;
636
		case 'ntpd':
637
			killbyname("ntpd");
638
			break;
639
		case 'openntpd':
640
			killbyname("openntpd");
641
			break;
642
		case 'dpinger':
643
			stop_dpinger();
644
			break;
645
		case 'bsnmpd':
646
			killbypid("{$g['varrun_path']}/snmpd.pid");
647
			break;
648
		case 'choparp':
649
			killbyname("choparp");
650
			break;
651
		case 'dhcpd':
652
			killbyname("dhcpd");
653
			break;
654
		case 'dhcrelay':
655
			killbypid("{$g['varrun_path']}/dhcrelay.pid");
656
			break;
657
		case 'dhcrelay6':
658
			killbypid("{$g['varrun_path']}/dhcrelay6.pid");
659
			break;
660
		case 'dnsmasq':
661
			killbypid("{$g['varrun_path']}/dnsmasq.pid");
662
			break;
663
		case 'unbound':
664
			killbypid("{$g['varrun_path']}/unbound.pid");
665
			break;
666
		case 'igmpproxy':
667
			killbyname("igmpproxy");
668
			break;
669
		case 'miniupnpd':
670
			upnp_action('stop');
671
			break;
672
		case 'sshd':
673
			killbyname("sshd");
674
			break;
675
		case 'ipsec':
676
			exec("/usr/local/sbin/ipsec stop");
677
			break;
678
		case 'openvpn':
679
			$vpnmode = htmlspecialchars($extras['vpnmode']);
680
			if (($vpnmode == "server") or ($vpnmode == "client")) {
681
				$id = htmlspecialchars($extras['id']);
682
				$pidfile = "{$g['varrun_path']}/openvpn_{$vpnmode}{$id}.pid";
683
				killbypid($pidfile);
684
			}
685
			break;
686
		case 'relayd':
687
			mwexec('pkill relayd');
688
			break;
689
		default:
690
			stop_service($name);
691
			break;
692
	}
693
	return sprintf(gettext("%s has been stopped."), htmlspecialchars($name));
694
}
695

    
696
function service_control_restart($name, $extras) {
697
	global $g;
698
	switch ($name) {
699
		case 'radvd':
700
			services_radvd_configure();
701
			break;
702
		case 'captiveportal':
703
			$zone = htmlspecialchars($extras['zone']);
704
			killbypid("{$g['varrun_path']}/nginx-{$zone}-CaptivePortal.pid");
705
			killbypid("{$g['varrun_path']}/nginx-{$zone}-CaptivePortal-SSL.pid");
706
			captiveportal_init_webgui_zonename($zone);
707
			break;
708
		case 'ntpd':
709
		case 'openntpd':
710
			system_ntp_configure();
711
			break;
712
		case 'dpinger':
713
			setup_gateways_monitor();
714
			break;
715
		case 'bsnmpd':
716
			services_snmpd_configure();
717
			break;
718
		case 'dhcrelay':
719
			services_dhcrelay_configure();
720
			break;
721
		case 'dhcrelay6':
722
			services_dhcrelay6_configure();
723
			break;
724
		case 'dnsmasq':
725
			services_dnsmasq_configure();
726
			break;
727
		case 'unbound':
728
			services_unbound_configure();
729
			break;
730
		case 'dhcpd':
731
			services_dhcpd_configure();
732
			break;
733
		case 'igmpproxy':
734
			services_igmpproxy_configure();
735
			break;
736
		case 'miniupnpd':
737
			upnp_action('restart');
738
			break;
739
		case 'ipsec':
740
			vpn_ipsec_force_reload();
741
			break;
742
		case 'sshd':
743
			send_event("service restart sshd");
744
			break;
745
		case 'openvpn':
746
			$vpnmode = htmlspecialchars($extras['vpnmode']);
747
			if ($vpnmode == "server" || $vpnmode == "client") {
748
				$id = htmlspecialchars($extras['id']);
749
				$configfile = "{$g['varetc_path']}/openvpn/{$vpnmode}{$id}.conf";
750
				if (file_exists($configfile)) {
751
					openvpn_restart_by_vpnid($vpnmode, $id);
752
				}
753
			}
754
			break;
755
		case 'relayd':
756
			relayd_configure(true);
757
			break;
758
		default:
759
			restart_service($name);
760
			break;
761
	}
762
	return sprintf(gettext("%s has been restarted."), htmlspecialchars($name));
763
}
764

    
765
?>
(37-37/51)