Project

General

Profile

Download (20.5 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
	if ($title == "state") {
482
		$title = $statustext;
483
	} elseif ($title == "service_state") {
484
		$title = sprintf(gettext('%1$s Service is %2$s'), $service["name"], $statustext);
485
	} elseif ($title == "description_state") {
486
		$title = sprintf(gettext('%1$s Service is %2$s'), $service["description"], $statustext);
487
	} elseif ($title == "description_service_state") {
488
		$title = sprintf(gettext('%1$s, %2$s Service is %3$s'), $service["description"], $service["name"], $statustext);
489
	}
490

    
491
	$spacer = ($withthumbs || $withtext) ? " " : "";
492

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

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

    
500
	if ($withtext) {
501
		$output .= "<span class=\"" . $text_class . "\">" . $statustext . "</span>";
502
	}
503

    
504
	return $output;
505
}
506

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

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

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

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

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

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

    
550
	} else {
551
		$service_enabled = is_service_enabled($service['name']);
552

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

    
559
	return $output;
560
}
561

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

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

    
770
?>
(48-48/65)