Project

General

Profile

Download (21.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-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("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 (count($config['load_balancer']['virtual_server']) && count($config['load_balancer']['lbpool'])) {
373
		$pconfig = array();
374
		$pconfig['name'] = "relayd";
375
		$pconfig['description'] = gettext("Server load balancing daemon");
376
		$services[] = $pconfig;
377
	}
378
	return $services;
379
}
380

    
381
function find_service_by_name($name) {
382
	$services = get_services();
383
	foreach ($services as $service) {
384
		if ($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 (($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 (($service["name"] == "captiveportal") && isset($service["zone"]) && ($service["zone"] == $zone)) {
405
			return $service;
406
		}
407
	}
408
	return array();
409
}
410

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

    
418
function service_dispname_compare($a, $b) {
419
	if (strtolower($a['dispname']) == strtolower($b['dispname'])) {
420
		return 0;
421
	}
422
	return (strtolower($a['name']) < strtolower($b['name'])) ? -1 : 1;
423
}
424

    
425
function get_pkg_descr($package_name) {
426
	global $config;
427
	if (is_array($config['installedpackages']['package'])) {
428
		foreach ($config['installedpackages']['package'] as $pkg) {
429
			if ($pkg['name'] == $package_name) {
430
				return $pkg['descr'];
431
			}
432
		}
433
	}
434
	return gettext("Not available.");
435
}
436

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

    
464
function get_service_status_icon($service, $withtext = true, $smallicon = false, $withthumbs = false, $title = "service_state") {
465
	$output = "";
466

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

    
488
	if ($title == "state") {
489
		$title = $statustext;
490
	} elseif ($title == "service_state") {
491
		$title = sprintf(gettext('%1$s Service is %2$s'), $service["name"], $statustext);
492
	} elseif ($title == "description_state") {
493
		$title = sprintf(gettext('%1$s Service is %2$s'), $service["description"], $statustext);
494
	} elseif ($title == "description_service_state") {
495
		$title = sprintf(gettext('%1$s, %2$s Service is %3$s'), $service["description"], $service["name"], $statustext);
496
	}
497

    
498
	$spacer = ($withthumbs || $withtext) ? " " : "";
499

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

    
502
	$spacer = ($withtext) ? " " : "";
503
	if ($withthumbs) {
504
		$output .= "<i class=\"{$text_class} {$fa_class_thumbs} {$fa_size}\" title=\"{$Thumbs_UpDown}\"></i>{$spacer}";
505
	}
506

    
507
	if ($withtext) {
508
		$output .= "<span class=\"" . $text_class . "\">" . $statustext . "</span>";
509
	}
510

    
511
	return $output;
512
}
513

    
514
function get_service_control_links($service, $addname = false) {
515
	global $g;
516
	$output = "";
517
	$stitle = ($addname) ? $service['name'] . " " : "";
518

    
519
	switch ($service['name']) {
520
		case "openvpn":
521
			$link = '<a title="%s" href="#" id="openvpn-%s-' . $service['mode'] . '-' . $service['vpnid'] . '" >';
522
		break;
523
		case "captiveportal":
524
			$link = '<a title="%s" href="#" id="captiveportal-%s-' . $service['zone'] . '">';
525
		break;
526
		default:
527
			$link = '<a title="%s" href="#" id="%s-' . $service['name'] . '">';
528
	}
529

    
530
	if (get_service_status($service)) {
531
		switch ($service['name']) {
532
			case "openvpn":
533
				$output .= '<a href="#" id="openvpn-restartservice-' . $service['mode'] . '-' . $service['vpnid'] . '" >';
534
				break;
535
			case "captiveportal":
536
				$output .= '<a href="#" id="captiveportal-restartservice-' . $service['zone'] . '">';
537
				break;
538
			default:
539
				$output .= '<a href="#" id="restartservice-' . $service['name'] . '" >';
540
		}
541

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

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

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

    
557
	} else {
558
		$service_enabled = is_service_enabled($service['name']);
559

    
560
		if ($service['name'] == 'openvpn' || $service['name'] == 'captiveportal' || $service_enabled) {
561
			$output .= sprintf($link, sprintf(gettext("Start %sService"), $stitle), 'startservice');
562
			$output .= '<i class="fa fa-play-circle"></i></a> ';
563
		}
564
	}
565

    
566
	return $output;
567
}
568

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

    
720
function service_control_restart($name, $extras) {
721
	global $g;
722
	switch ($name) {
723
		case 'radvd':
724
			services_radvd_configure();
725
			break;
726
		case 'captiveportal':
727
			$zone = htmlspecialchars($extras['zone']);
728
			killbypid("{$g['varrun_path']}/nginx-{$zone}-CaptivePortal.pid");
729
			killbypid("{$g['varrun_path']}/nginx-{$zone}-CaptivePortal-SSL.pid");
730
			captiveportal_init_webgui_zonename($zone);
731
			break;
732
		case 'ntpd':
733
		case 'openntpd':
734
			system_ntp_configure();
735
			break;
736
		case 'dpinger':
737
			setup_gateways_monitor();
738
			break;
739
		case 'bsnmpd':
740
			services_snmpd_configure();
741
			break;
742
		case 'dhcrelay':
743
			services_dhcrelay_configure();
744
			break;
745
		case 'dhcrelay6':
746
			services_dhcrelay6_configure();
747
			break;
748
		case 'dnsmasq':
749
			services_dnsmasq_configure();
750
			break;
751
		case 'unbound':
752
			services_unbound_configure();
753
			break;
754
		case 'dhcpd':
755
			services_dhcpd_configure();
756
			break;
757
		case 'igmpproxy':
758
			services_igmpproxy_configure();
759
			break;
760
		case 'miniupnpd':
761
			upnp_action('restart');
762
			break;
763
		case 'ipsec':
764
			vpn_ipsec_force_reload();
765
			break;
766
		case 'sshd':
767
			send_event("service restart sshd");
768
			break;
769
		case 'openvpn':
770
			$vpnmode = htmlspecialchars($extras['vpnmode']);
771
			if ($vpnmode == "server" || $vpnmode == "client") {
772
				$id = htmlspecialchars($extras['id']);
773
				$configfile = "{$g['varetc_path']}/openvpn/{$vpnmode}{$id}.conf";
774
				if (file_exists($configfile)) {
775
					openvpn_restart_by_vpnid($vpnmode, $id);
776
				}
777
			}
778
			break;
779
		case 'relayd':
780
			relayd_configure(true);
781
			filter_configure();
782
			break;
783
		case 'syslogd':
784
			system_syslogd_start();
785
			break;
786
		default:
787
			restart_service($name);
788
			break;
789
	}
790
	return sprintf(gettext("%s has been restarted."), htmlspecialchars($name));
791
}
792

    
793
?>
(50-50/67)