Project

General

Profile

Download (21.2 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/****h* pfSense/service-utils
3
	NAME
4
		service-utils.inc - Service facility
5
	DESCRIPTION
6
		This file contains various functions used by the pfSense service facility.
7
	HISTORY
8
	$Id$
9

    
10
	Copyright (C) 2005-2006 Colin Smith (ethethlay@gmail.com)
11
	All rights reserved.
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14

    
15
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17

    
18
	2. Redistributions in binary form must reproduce the above copyright
19
	   notice, this list of conditions and the following disclaimer in the
20
	   documentation and/or other materials provided with the distribution.
21

    
22
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
	RISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
	POSSIBILITY OF SUCH DAMAGE.
32

    
33
 */
34

    
35
/*
36
	pfSense_BUILDER_BINARIES:	/bin/pgrep /bin/sh /usr/bin/killall
37
	pfSense_MODULE:	utils
38
*/
39
require_once("globals.inc");
40
require_once("captiveportal.inc");
41
require_once("openvpn.inc");
42
require_once("ipsec.inc");
43
require_once("vpn.inc");
44
require_once("vslb.inc");
45
require_once("gwlb.inc");
46

    
47
define("RCFILEPREFIX", "/usr/local/etc/rc.d/");
48
function write_rcfile($params) {
49
	global $g;
50

    
51
	safe_mkdir(RCFILEPREFIX);
52
	$rcfile_fullname = RCFILEPREFIX . $params['file'];
53
	if (!file_exists($rcfile_fullname) && !is_link($rcfile_fullname) && !touch($rcfile_fullname)) {
54
		return false;
55
	}
56

    
57
	if (!is_writable($rcfile_fullname) || empty($params['start'])) {
58
		return false;
59
	}
60

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

    
64
	/* write our rc functions */
65
	$towrite .= "rc_start() {\n";
66
	$towrite .= "\t{$params['start']}\n";
67
	$towrite .= "}\n\n";
68
	if (!empty($params['stop'])) {
69
		$tokill =& $params['stop'];
70
	} else if (!empty($params['executable'])) {
71
		/* just nuke the executable */
72
		$tokill = "/usr/bin/killall " . escapeshellarg($params['executable']);
73
	} else {
74
		/* make an educated guess (bad) */
75
		$tokill = array_pop(explode('/', array_shift(explode(' ', $params['start']))));
76
	}
77
	$towrite .= "rc_stop() {\n";
78
	$towrite .= "\t{$tokill}\n";
79
	$towrite .= "}\n\n";
80

    
81
	/* begin rcfile logic */
82
	$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";
83

    
84
	@file_put_contents($rcfile_fullname, $towrite);
85
	unset($towrite);
86
	@chmod("{$rcfile_fullname}", 0755);
87

    
88
	return;
89
}
90

    
91
function start_service($name) {
92
	global $config;
93

    
94
	if (empty($name)) {
95
		return;
96
	}
97

    
98
	if (is_array($config['installedpackages']) && is_array($config['installedpackages']['service'])) {
99
		foreach ($config['installedpackages']['service'] as $service) {
100
			if (strtolower($service['name']) == strtolower($name)) {
101
				if ($service['rcfile']) {
102
					$prefix = RCFILEPREFIX;
103
					if (!empty($service['prefix'])) {
104
						$prefix =& $service['prefix'];
105
					}
106
					if (file_exists("{$prefix}{$service['rcfile']}") || is_link("{$prefix}{$service['rcfile']}")) {
107
						mwexec_bg("{$prefix}{$service['rcfile']} start");
108
					}
109
				}
110
				if (!empty($service['startcmd'])) {
111
					eval($service['startcmd']);
112
				}
113
				break;
114
			}
115
		}
116
	}
117
}
118

    
119
function stop_service($name) {
120
	global $config;
121

    
122
	if (empty($name)) {
123
		return;
124
	}
125

    
126
	if (is_array($config['installedpackages']) && is_array($config['installedpackages']['service'])) {
127
		foreach ($config['installedpackages']['service'] as $service) {
128
			if (strtolower($service['name']) == strtolower($name)) {
129
				if ($service['rcfile']) {
130
					$prefix = RCFILEPREFIX;
131
					if (!empty($service['prefix'])) {
132
						$prefix =& $service['prefix'];
133
					}
134
					if (file_exists("{$prefix}{$service['rcfile']}") || is_link("{$prefix}{$service['rcfile']}")) {
135
						mwexec("{$prefix}{$service['rcfile']} stop");
136
					}
137
					return;
138
				}
139
				if (!empty($service['stopcmd'])) {
140
					eval($service['stopcmd']);
141
				}
142

    
143
				break;
144
			}
145
		}
146
	}
147
}
148

    
149
function restart_service($name) {
150
	global $config;
151

    
152
	if (empty($name)) {
153
		return;
154
	}
155

    
156
	stop_service($name);
157
	start_service($name);
158

    
159
	if (is_array($config['installedpackages']) && is_array($config['installedpackages']['service'])) {
160
		foreach ($config['installedpackages']['service'] as $service) {
161
			if (strtolower($service['name']) == strtolower($name)) {
162
				if ($service['restartcmd']) {
163
					eval($service['restartcmd']);
164
				}
165
				break;
166
			}
167
		}
168
	}
169
}
170

    
171
function is_pid_running($pidfile) {
172
	if (!file_exists($pidfile)) {
173
		return false;
174
	}
175

    
176
	return (isvalidpid($pidfile));
177
}
178

    
179
function is_dhcp_running($interface) {
180
	$status = find_dhclient_process($interface);
181
	if ($status != 0) {
182
		return true;
183
	}
184
	return false;
185
}
186

    
187
function restart_service_if_running($service) {
188
	global $config;
189
	if (is_service_running($service)) {
190
		restart_service($service);
191
	}
192
	return;
193
}
194

    
195
function is_service_enabled($service_name) {
196
	global $config;
197
	if ($service_name == "") {
198
		return false;
199
	}
200
	if (is_array($config['installedpackages'])) {
201
		if (isset($config['installedpackages'][$service_name]['config'][0]['enable']) &&
202
		    ((empty($config['installedpackages'][$service_name]['config'][0]['enable'])) ||
203
		    ($config['installedpackages'][$service_name]['config'][0]['enable'] === 'off'))) {
204
			return false;
205
		}
206
	}
207
	return true;
208
}
209

    
210
function is_service_running($service, $ps = "") {
211
	global $config;
212

    
213
	if (is_array($config['installedpackages']['service'])) {
214
		foreach ($config['installedpackages']['service'] as $aservice) {
215
			if (strtolower($service) == strtolower($aservice['name'])) {
216
				if ($aservice['custom_php_service_status_command'] <> "") {
217
					eval("\$rc={$aservice['custom_php_service_status_command']};");
218
					return $rc;
219
				}
220
				if (empty($aservice['executable'])) {
221
					return false;
222
				}
223
				if (is_process_running($aservice['executable'])) {
224
					return true;
225
				}
226

    
227
				return false;
228
			}
229
		}
230
	}
231

    
232
	if (is_process_running($service)) {
233
		return true;
234
	}
235

    
236
	return false;
237
}
238

    
239
function get_services() {
240
	global $config;
241
	if (is_array($config['installedpackages']['service'])) {
242
		$services = $config['installedpackages']['service'];
243
	} else {
244
		$services = array();
245
	}
246

    
247
	/*
248
	 * Add services that are in the base.
249
	 */
250
	if (is_radvd_enabled()) {
251
		$pconfig = array();
252
		$pconfig['name'] = "radvd";
253
		$pconfig['description'] = gettext("Router Advertisement Daemon");
254
		$services[] = $pconfig;
255
	}
256

    
257
	if (isset($config['dnsmasq']['enable'])) {
258
		$pconfig = array();
259
		$pconfig['name'] = "dnsmasq";
260
		$pconfig['description'] = gettext("DNS Forwarder");
261
		$services[] = $pconfig;
262
	}
263

    
264
	if (isset($config['unbound']['enable'])) {
265
		$pconfig = array();
266
		$pconfig['name'] = "unbound";
267
		$pconfig['description'] = gettext("DNS Resolver");
268
		$services[] = $pconfig;
269
	}
270

    
271
	$pconfig = array();
272
	$pconfig['name'] = "ntpd";
273
	$pconfig['description'] = gettext("NTP clock sync");
274
	$services[] = $pconfig;
275

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

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

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

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

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

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

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

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

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

    
347
	if (isset($config['installedpackages']['routed']) && $config['installedpackages']['routed']['config'][0]['enable']) {
348
		$pconfig = array();
349
		$pconfig['name'] = "routed";
350
		$pconfig['description'] = gettext("RIP Daemon");
351
		$services[] = $pconfig;
352
	}
353

    
354
	if (isset($config['ipsec']['enable'])) {
355
		$pconfig = array();
356
		$pconfig['name'] = "ipsec";
357
		$pconfig['description'] = gettext("IPsec VPN");
358
		$services[] = $pconfig;
359
	}
360

    
361
	if (isset($config['system']['enablesshd'])) {
362
		$pconfig = array();
363
		$pconfig['name'] = "sshd";
364
		$pconfig['description'] = gettext("Secure Shell Daemon");
365
		$services[] = $pconfig;
366
	}
367

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

    
384
	if (count($config['load_balancer']['virtual_server']) && count($config['load_balancer']['lbpool'])) {
385
		$pconfig = array();
386
		$pconfig['name'] = "relayd";
387
		$pconfig['description'] = gettext("Server load balancing daemon");
388
		$services[] = $pconfig;
389
	}
390
	return $services;
391
}
392

    
393
function find_service_by_name($name) {
394
	$services = get_services();
395
	foreach ($services as $service) {
396
		if ($service["name"] == $name) {
397
			return $service;
398
		}
399
	}
400
	return array();
401
}
402

    
403
function find_service_by_openvpn_vpnid($vpnid) {
404
	$services = get_services();
405
	foreach ($services as $service) {
406
		if (($service["name"] == "openvpn") && isset($service["vpnid"]) && ($service["vpnid"] == $vpnid)) {
407
			return $service;
408
		}
409
	}
410
	return array();
411
}
412

    
413
function find_service_by_cp_zone($zone) {
414
	$services = get_services();
415
	foreach ($services as $service) {
416
		if (($service["name"] == "captiveportal") && isset($service["zone"]) && ($service["zone"] == $zone)) {
417
			return $service;
418
		}
419
	}
420
	return array();
421
}
422

    
423
function service_name_compare($a, $b) {
424
	if (strtolower($a['name']) == strtolower($b['name'])) {
425
		return 0;
426
	}
427
	return (strtolower($a['name']) < strtolower($b['name'])) ? -1 : 1;
428
}
429

    
430
function get_pkg_descr($package_name) {
431
	global $config;
432
	if (is_array($config['installedpackages']['package'])) {
433
		foreach ($config['installedpackages']['package'] as $pkg) {
434
			if ($pkg['name'] == $package_name) {
435
				return $pkg['descr'];
436
			}
437
		}
438
	}
439
	return gettext("Not available.");
440
}
441

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

    
469
function get_service_status_icon($service, $withtext = true, $smallicon = false) {
470
	global $g;
471
	$output = "";
472
	if (get_service_status($service)) {
473
		$statustext = gettext("Running");
474
		$output .= "<img style=\"vertical-align:middle\" title=\"" . sprintf(gettext("%s Service is"), $service["name"]) . " {$statustext}\" src=\"/themes/" . $g["theme"] . "/images/icons/";
475
		$output .= ($smallicon) ? "icon_pass.gif" : "icon_service_running.gif";
476
		$output .= "\" alt=\"status\" />&nbsp;";
477
		if ($withtext) {
478
			$output .= "&nbsp;" . $statustext;
479
		}
480
	} else {
481
		$service_enabled = is_service_enabled($service['name']);
482
		$statustext = ($service_enabled) ? gettext("Stopped") : gettext("Disabled");
483
		$output .= "<img style=\"vertical-align:middle\" title=\"" . sprintf(gettext("%s Service is"), $service["name"]) . " {$statustext}\" src=\"/themes/" . $g["theme"] . "/images/icons/";
484
		$output .= ($smallicon) ? "icon_block.gif" : "icon_service_stopped.gif";
485
		$output .= "\" alt=\"status\" />&nbsp;";
486
		if ($withtext) {
487
			$output .= "&nbsp;<font color=\"white\">{$statustext}</font>";
488
		}
489
	}
490
	return $output;
491
}
492

    
493
function get_service_control_links($service, $addname = false) {
494
	global $g;
495
	$output = "";
496
	$stitle = ($addname) ? $service['name'] . " " : "";
497
	if (get_service_status($service)) {
498
		switch ($service['name']) {
499
			case "openvpn":
500
				$output .= "<a href='status_services.php?mode=restartservice&amp;service={$service['name']}&amp;vpnmode={$service['mode']}&amp;id={$service['vpnid']}'>";
501
				break;
502
			case "captiveportal":
503
				$output .= "<a href='status_services.php?mode=restartservice&amp;service={$service['name']}&amp;zone={$service['zone']}'>";
504
				break;
505
			default:
506
				$output .= "<a href='status_services.php?mode=restartservice&amp;service={$service['name']}'>";
507
		}
508
		$output .= "<img style=\"vertical-align:middle\" title='" . sprintf(gettext("Restart %sService"), $stitle) . "' border='0' src='/themes/".$g['theme']."/images/icons/icon_service_restart.gif' alt='restart' /></a>\n";
509
		switch ($service['name']) {
510
			case "openvpn":
511
				$output .= "<a href='status_services.php?mode=stopservice&amp;service={$service['name']}&amp;vpnmode={$service['mode']}&amp;id={$service['vpnid']}'>";
512
				break;
513
			case "captiveportal":
514
				$output .= "<a href='status_services.php?mode=stopservice&amp;service={$service['name']}&amp;zone={$service['zone']}'>";
515
				break;
516
			default:
517
				$output .= "<a href='status_services.php?mode=stopservice&amp;service={$service['name']}'>";
518
		}
519
		$output .= "<img style=\"vertical-align:middle\" title='" . sprintf(gettext("Stop %sService"), $stitle) . "' border='0' src='/themes/".$g['theme']."/images/icons/icon_service_stop.gif' alt='stop' />";
520
		$output .= "</a>";
521
	} else {
522
		$service_enabled = is_service_enabled($service['name']);
523
		switch ($service['name']) {
524
			case "openvpn":
525
				$output .= "<a href='status_services.php?mode=startservice&amp;service={$service['name']}&amp;vpnmode={$service['mode']}&amp;id={$service['vpnid']}'>";
526
				break;
527
			case "captiveportal":
528
				$output .= "<a href='status_services.php?mode=startservice&amp;service={$service['name']}&amp;zone={$service['zone']}'>";
529
				break;
530
			default:
531
				if ($service_enabled) {
532
					$output .= "<a href='status_services.php?mode=startservice&amp;service={$service['name']}'>";
533
				}
534
		}
535
		if ($service_enabled) {
536
			$output .= "<img style=\"vertical-align:middle\" title='" . sprintf(gettext("Start %sService"), $stitle) . "' border='0' src='/themes/".$g['theme']."/images/icons/icon_service_start.gif' alt='start' /></a>\n";
537
		}
538
	}
539
	return $output;
540
}
541

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

    
679
function service_control_restart($name, $extras) {
680
	global $g;
681
	switch ($name) {
682
		case 'radvd':
683
			services_radvd_configure();
684
			break;
685
		case 'captiveportal':
686
			$zone = htmlspecialchars($extras['zone']);
687
			killbypid("{$g['varrun_path']}/lighty-{$zone}-CaptivePortal.pid");
688
			killbypid("{$g['varrun_path']}/lighty-{$zone}-CaptivePortal-SSL.pid");
689
			captiveportal_init_webgui_zonename($zone);
690
			break;
691
		case 'ntpd':
692
		case 'openntpd':
693
			system_ntp_configure();
694
			break;
695
		case 'apinger':
696
			killbypid("{$g['varrun_path']}/apinger.pid");
697
			setup_gateways_monitor();
698
			break;
699
		case 'bsnmpd':
700
			services_snmpd_configure();
701
			break;
702
		case 'dhcrelay':
703
			services_dhcrelay_configure();
704
			break;
705
		case 'dhcrelay6':
706
			services_dhcrelay6_configure();
707
			break;
708
		case 'dnsmasq':
709
			services_dnsmasq_configure();
710
			break;
711
		case 'unbound':
712
			services_unbound_configure();
713
			break;
714
		case 'dhcpd':
715
			services_dhcpd_configure();
716
			break;
717
		case 'igmpproxy':
718
			services_igmpproxy_configure();
719
			break;
720
		case 'miniupnpd':
721
			upnp_action('restart');
722
			break;
723
		case 'ipsec':
724
			vpn_ipsec_force_reload();
725
			break;
726
		case 'sshd':
727
			send_event("service restart sshd");
728
			break;
729
		case 'openvpn':
730
			$vpnmode = htmlspecialchars($extras['vpnmode']);
731
			if ($vpnmode == "server" || $vpnmode == "client") {
732
				$id = htmlspecialchars($extras['id']);
733
				$configfile = "{$g['varetc_path']}/openvpn/{$vpnmode}{$id}.conf";
734
				if (file_exists($configfile)) {
735
					openvpn_restart_by_vpnid($vpnmode, $id);
736
				}
737
			}
738
			break;
739
		case 'relayd':
740
			relayd_configure(true);
741
			break;
742
		default:
743
			restart_service($name);
744
			break;
745
	}
746
	return sprintf(gettext("%s has been restarted."), htmlspecialchars($name));
747
}
748

    
749
?>
(49-49/68)