Projet

Général

Profil

Télécharger (20,9 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / etc / inc / service-utils.inc @ 2f9951fe

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
 *
11
 * Copyright (C) 2005-2006 Colin Smith (ethethlay@gmail.com)
12
 * All rights reserved.
13
 * Redistribution and use in source and binary forms, with or without
14
 * modification, are permitted provided that the following conditions are met:
15
 *
16
 * 1. Redistributions of source code must retain the above copyright notice,
17
 * this list of conditions and the following disclaimer.
18
 *
19
 * 2. Redistributions in binary form must reproduce the above copyright
20
 * notice, this list of conditions and the following disclaimer in the
21
 * documentation and/or other materials provided with the distribution.
22
 *
23
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
 * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27
 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
 * RISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
 * POSSIBILITY OF SUCH DAMAGE.
33
 *
34
 */
35

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

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

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

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

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

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

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

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

    
87
	return;
88
}
89

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

    
93
	if (empty($name))
94
		return;
95

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

    
116
function stop_service($name) {
117
	global $config;
118

    
119
	if (empty($name))
120
		return;
121

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

    
138
				break;
139
			}
140
		}
141
	}
142
}
143

    
144
function restart_service($name) {
145
	global $config;
146

    
147
	if (empty($name))
148
		return;
149

    
150
	stop_service($name);
151
	start_service($name);
152

    
153
	if (is_array($config['installedpackages']) && is_array($config['installedpackages']['service'])) {
154
		foreach($config['installedpackages']['service'] as $service) {
155
			if(strtolower($service['name']) == strtolower($name)) {
156
				if($service['restartcmd']) {
157
					eval($service['restartcmd']);
158
				}
159
				break;
160
			}
161
		}
162
	}
163
}
164

    
165
function is_pid_running($pidfile) {
166
	if (!file_exists($pidfile))
167
		return false;
168

    
169
	return (isvalidpid($pidfile));
170
}
171

    
172
function is_dhcp_running($interface) {
173
	$status = find_dhclient_process($interface);
174
	if($status <> "")
175
		return true;
176
	return false;
177
}
178

    
179
function restart_service_if_running($service) {
180
	global $config;
181
	if(is_service_running($service))
182
		restart_service($service);
183
	return;
184
}
185

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

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

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

    
212
				return false;
213
			}
214
		}
215
	}
216

    
217
	if (is_process_running($service))
218
		return true;
219

    
220
	return false;
221
}
222

    
223
function get_services() {
224
	global $config;
225
	if (is_array($config['installedpackages']['service']))
226
		$services = $config['installedpackages']['service'];
227
	else
228
		$services = array();
229

    
230
	/*    Add services that are in the base.
231
	 *
232
	 */
233
	if (is_radvd_enabled()) {
234
		$pconfig = array();
235
		$pconfig['name'] = "radvd";
236
		$pconfig['description'] = gettext("Router Advertisement Daemon");
237
		$services[] = $pconfig;
238
	}
239

    
240
	if (isset($config['dnsmasq']['enable'])) {
241
		$pconfig = array();
242
		$pconfig['name'] = "dnsmasq";
243
		$pconfig['description'] = gettext("DNS Forwarder");
244
		$services[] = $pconfig;
245
	}
246

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

    
254
	$pconfig = array();
255
	$pconfig['name'] = "ntpd";
256
	$pconfig['description'] = gettext("NTP clock sync");
257
	$services[] = $pconfig;
258

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

    
271
	$iflist = array();
272
	$ifdescrs = get_configured_interface_list();
273
	foreach ($ifdescrs as $if) {
274
		$oc = $config['interfaces'][$if];
275
		if ($oc['if'] && (!link_interface_to_bridge($if)))
276
			$iflist[$if] = $if;
277
	}
278

    
279
	if (isset($config['dhcrelay']['enable'])) {
280
		$pconfig = array();
281
		$pconfig['name'] = "dhcrelay";
282
		$pconfig['description'] = gettext("DHCP Relay");
283
		$services[] = $pconfig;
284
	}
285

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

    
293
	if (is_dhcp_server_enabled()) {
294
		$pconfig = array();
295
		$pconfig['name'] = "dhcpd";
296
		$pconfig['description'] = gettext("DHCP Service");
297
		$services[] = $pconfig;
298
	}
299

    
300
	$gateways_arr = return_gateways_array();
301
	if (is_array($gateways_arr)) {
302
		$pconfig = array();
303
		$pconfig['name'] = "apinger";
304
		$pconfig['description'] = gettext("Gateway Monitoring Daemon");
305
		$services[] = $pconfig;
306
	}
307

    
308
	if (isset($config['snmpd']['enable'])) {
309
		$pconfig = array();
310
		$pconfig['name'] = "bsnmpd";
311
		$pconfig['description'] = gettext("SNMP Service");
312
		$services[] = $pconfig;
313
	}
314

    
315
	if (is_array($config['igmpproxy']['igmpentry']) && (count($config['igmpproxy']['igmpentry']) > 0)) {
316
		$pconfig = array();
317
		$pconfig['name'] = "igmpproxy";
318
		$pconfig['description'] = gettext("IGMP proxy");
319
		$services[] = $pconfig;
320
	}
321

    
322
	if (isset($config['installedpackages']['miniupnpd']) && $config['installedpackages']['miniupnpd']['config'][0]['enable']) {
323
		$pconfig = array();
324
		$pconfig['name'] = "miniupnpd";
325
		$pconfig['description'] = gettext("UPnP Service");
326
		$services[] = $pconfig;
327
	}
328

    
329
	if (isset($config['installedpackages']['routed']) && $config['installedpackages']['routed']['config'][0]['enable']) {
330
		$pconfig = array();
331
		$pconfig['name'] = "routed";
332
		$pconfig['description'] = gettext("RIP Daemon");
333
		$services[] = $pconfig;
334
	}
335

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

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

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

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

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

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

    
391
function find_service_by_cp_zone($zone) {
392
	$services = get_services();
393
	foreach ($services as $service)
394
		if (($service["name"] == "captiveportal") && isset($service["zone"]) && ($service["zone"] == $zone))
395
			return $service;
396
	return array();
397
}
398

    
399
function service_name_compare($a, $b) {
400
	if (strtolower($a['name']) == strtolower($b['name']))
401
		return 0;
402
	return (strtolower($a['name']) < strtolower($b['name'])) ? -1 : 1;
403
}
404

    
405
function get_pkg_descr($package_name) {
406
	global $config;
407
	if (is_array($config['installedpackages']['package'])) {
408
		foreach($config['installedpackages']['package'] as $pkg) {
409
			if($pkg['name'] == $package_name)
410
				return $pkg['descr'];
411
		}
412
	}
413
	return gettext("Not available.");
414
}
415

    
416
function get_service_status($service) {
417
	global $g;
418
	switch ($service['name']) {
419
		case "openvpn":
420
			$running = is_pid_running("{$g['varrun_path']}/openvpn_{$service['mode']}{$service['vpnid']}.pid");
421
			break;
422
		case "captiveportal":
423
			$running = is_pid_running("{$g['varrun_path']}/lighty-{$service['zone']}-CaptivePortal.pid");
424
			if (isset($config['captiveportal'][$service['zone']]['httpslogin']))
425
				$running = $running && is_pid_running("{$g['varrun_path']}/lighty-{$service['zone']}-CaptivePortal-SSL.pid");
426
			break;
427
		case "vhosts-http":
428
			$running = is_pid_running("{$g['varrun_path']}/vhosts-http.pid");
429
			break;
430
		case "dhcrelay6":
431
			$running = is_pid_running("{$g['varrun_path']}/dhcrelay6.pid");
432
			break;
433
		case 'ipsec':
434
			$running = is_pid_running("{$g['varrun_path']}/charon.pid");
435
			break;
436
		default:
437
			$running = is_service_running($service['name']);
438
	}
439
	return $running;
440
}
441

    
442
function get_service_status_icon($service, $withtext = true, $smallicon = false) {
443
	global $g;
444
	$output = "";
445
	if(get_service_status($service)) {
446
		$statustext = gettext("Running");
447
		$output .= "<img style=\"vertical-align:middle\" title=\"" . sprintf(gettext("%s Service is"),$service["name"]) . " {$statustext}\" src=\"/themes/" . $g["theme"] . "/images/icons/";
448
		$output .= ($smallicon) ? "icon_pass.gif" : "icon_service_running.gif";
449
		$output .= "\" alt=\"status\" />&nbsp;";
450
		if ($withtext)
451
			$output .= "&nbsp;" . $statustext;
452
	} else {
453
		$service_enabled = is_service_enabled($service['name']);
454
		$statustext = ($service_enabled) ? gettext("Stopped") : gettext("Disabled");
455
		$output .= "<img style=\"vertical-align:middle\" title=\"" . sprintf(gettext("%s Service is"),$service["name"]) . " {$statustext}\" src=\"/themes/" . $g["theme"] . "/images/icons/";
456
		$output .= ($smallicon) ? "icon_block.gif" : "icon_service_stopped.gif";
457
		$output .= "\" alt=\"status\" />&nbsp;";
458
		if ($withtext)
459
			$output .= "&nbsp;<font color=\"white\">{$statustext}</font>";
460
	}
461
	return $output;
462
}
463

    
464
function get_service_control_links($service, $addname = false) {
465
	global $g;
466
	$output = "";
467
	$stitle = ($addname) ? $service['name'] . " " : "";
468
	if(get_service_status($service)) {
469
		switch ($service['name']) {
470
			case "openvpn":
471
				$output .= "<a href='status_services.php?mode=restartservice&amp;service={$service['name']}&amp;vpnmode={$service['mode']}&amp;id={$service['vpnid']}'>";
472
				break;
473
			case "captiveportal":
474
				$output .= "<a href='status_services.php?mode=restartservice&amp;service={$service['name']}&amp;zone={$service['zone']}'>";
475
				break;
476
			default:
477
				$output .= "<a href='status_services.php?mode=restartservice&amp;service={$service['name']}'>";
478
		}
479
		$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";
480
		switch ($service['name']) {
481
			case "openvpn":
482
				$output .= "<a href='status_services.php?mode=stopservice&amp;service={$service['name']}&amp;vpnmode={$service['mode']}&amp;id={$service['vpnid']}'>";
483
				break;
484
			case "captiveportal":
485
				$output .= "<a href='status_services.php?mode=stopservice&amp;service={$service['name']}&amp;zone={$service['zone']}'>";
486
				break;
487
			default:
488
				$output .= "<a href='status_services.php?mode=stopservice&amp;service={$service['name']}'>";
489
		}
490
		$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' />";
491
		$output .= "</a>";
492
	} else {
493
		$service_enabled = is_service_enabled($service['name']);
494
		switch ($service['name']) {
495
			case "openvpn":
496
				$output .= "<a href='status_services.php?mode=startservice&amp;service={$service['name']}&amp;vpnmode={$service['mode']}&amp;id={$service['vpnid']}'>";
497
				break;
498
			case "captiveportal":
499
				$output .= "<a href='status_services.php?mode=startservice&amp;service={$service['name']}&amp;zone={$service['zone']}'>";
500
				break;
501
			default:
502
				if ($service_enabled)
503
					$output .= "<a href='status_services.php?mode=startservice&amp;service={$service['name']}'>";
504
		}
505
		if ($service_enabled)
506
			$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";
507
	}
508
	return $output;
509
}
510

    
511
function service_control_start($name, $extras) {
512
	global $g;
513
	switch($name) {
514
		case 'radvd':
515
			services_radvd_configure();
516
			break;
517
		case 'captiveportal':
518
			$zone = htmlspecialchars($extras['zone']);
519
			captiveportal_init_webgui_zonename($zone);
520
			break;
521
		case 'ntpd':
522
		case 'openntpd':
523
			system_ntp_configure();
524
			break;
525
		case 'apinger':
526
			setup_gateways_monitor();
527
			break;
528
		case 'bsnmpd':
529
			services_snmpd_configure();
530
			break;
531
		case 'dhcrelay':
532
			services_dhcrelay_configure();
533
			break;
534
		case 'dhcrelay6':
535
			services_dhcrelay6_configure();
536
			break;
537
		case 'dnsmasq':
538
			services_dnsmasq_configure();
539
			break;
540
		case 'dhcpd':
541
			services_dhcpd_configure();
542
			break;
543
		case 'igmpproxy':
544
			services_igmpproxy_configure();
545
			break;
546
		case 'miniupnpd':
547
			upnp_action('start');
548
			break;
549
		case 'ipsec':
550
			vpn_ipsec_force_reload();
551
			break;
552
		case 'sshd':
553
			send_event("service restart sshd");
554
			break;
555
		case 'openvpn':
556
			$vpnmode = isset($extras['vpnmode']) ? htmlspecialchars($extras['vpnmode']) : htmlspecialchars($extras['mode']);
557
			if (($vpnmode == "server") || ($vpnmode == "client")) {
558
				$id = isset($extras['vpnid']) ? htmlspecialchars($extras['vpnid']) : htmlspecialchars($extras['id']);
559
				$configfile = "{$g['varetc_path']}/openvpn/{$vpnmode}{$id}.conf";
560
				if (file_exists($configfile))
561
					openvpn_restart_by_vpnid($vpnmode, $id);
562
			}
563
			break;
564
		case 'relayd':
565
			relayd_configure();
566
			break;
567
		default:
568
			start_service($name);
569
			break;
570
	}
571
	return sprintf(gettext("%s has been started."),htmlspecialchars($name));
572
}
573
function service_control_stop($name, $extras) {
574
	global $g;
575
	switch($name) {
576
		case 'radvd':
577
			killbypid("{$g['varrun_path']}/radvd.pid");
578
			break;
579
		case 'captiveportal':
580
			$zone = htmlspecialchars($extras['zone']);
581
			killbypid("{$g['varrun_path']}/lighty-{$zone}-CaptivePortal.pid");
582
			killbypid("{$g['varrun_path']}/lighty-{$zone}-CaptivePortal-SSL.pid");
583
			break;
584
		case 'ntpd':
585
			killbyname("ntpd");
586
			break;
587
		case 'openntpd':
588
			killbyname("openntpd");
589
			break;
590
		case 'apinger':
591
			killbypid("{$g['varrun_path']}/apinger.pid");
592
			break;
593
		case 'bsnmpd':
594
			killbypid("{$g['varrun_path']}/snmpd.pid");
595
			break;
596
		case 'choparp':
597
			killbyname("choparp");
598
			break;
599
		case 'dhcpd':
600
			killbyname("dhcpd");
601
			break;
602
		case 'dhcrelay':
603
			killbypid("{$g['varrun_path']}/dhcrelay.pid");
604
			break;
605
		case 'dhcrelay6':
606
			killbypid("{$g['varrun_path']}/dhcrelay6.pid");
607
			break;
608
		case 'dnsmasq':
609
			killbypid("{$g['varrun_path']}/dnsmasq.pid");
610
			break;
611
		case 'unbound':
612
			killbypid("{$g['varrun_path']}/unbound.pid");
613
			break;
614
		case 'igmpproxy':
615
			killbyname("igmpproxy");
616
			break;
617
		case 'miniupnpd':
618
			upnp_action('stop');
619
			break;
620
		case 'sshd':
621
			killbyname("sshd");
622
			break;
623
		case 'ipsec':
624
			exec("/usr/local/sbin/ipsec stop");
625
			break;
626
		case 'openvpn':
627
			$vpnmode = htmlspecialchars($extras['vpnmode']);
628
			if (($vpnmode == "server") or ($vpnmode == "client")) {
629
				$id = htmlspecialchars($extras['id']);
630
				$pidfile = "{$g['varrun_path']}/openvpn_{$vpnmode}{$id}.pid";
631
				killbypid($pidfile);
632
			}
633
			break;
634
		case 'relayd':
635
			mwexec('pkill relayd');
636
			break;
637
		default:
638
			stop_service($name);
639
			break;
640
	}
641
	return sprintf(gettext("%s has been stopped."), htmlspecialchars($name));
642
}
643

    
644
function service_control_restart($name, $extras) {
645
	global $g;
646
	switch($name) {
647
		case 'radvd':
648
			services_radvd_configure();
649
			break;
650
		case 'captiveportal':
651
			$zone = htmlspecialchars($extras['zone']);
652
			killbypid("{$g['varrun_path']}/lighty-{$zone}-CaptivePortal.pid");
653
			killbypid("{$g['varrun_path']}/lighty-{$zone}-CaptivePortal-SSL.pid");
654
			captiveportal_init_webgui_zonename($zone);
655
			break;
656
		case 'ntpd':
657
		case 'openntpd':
658
			system_ntp_configure();
659
			break;
660
		case 'apinger':
661
			killbypid("{$g['varrun_path']}/apinger.pid");
662
			setup_gateways_monitor();
663
			break;
664
		case 'bsnmpd':
665
			services_snmpd_configure();
666
			break;
667
		case 'dhcrelay':
668
			services_dhcrelay_configure();
669
			break;
670
		case 'dhcrelay6':
671
			services_dhcrelay6_configure();
672
			break;
673
		case 'dnsmasq':
674
			services_dnsmasq_configure();
675
			break;
676
		case 'unbound':
677
			services_unbound_configure();
678
			break;
679
		case 'dhcpd':
680
			services_dhcpd_configure();
681
			break;
682
		case 'igmpproxy':
683
			services_igmpproxy_configure();
684
			break;
685
		case 'miniupnpd':
686
			upnp_action('restart');
687
			break;
688
		case 'ipsec':
689
			vpn_ipsec_force_reload();
690
			break;
691
		case 'sshd':
692
			send_event("service restart sshd");
693
			break;
694
		case 'openvpn':
695
			$vpnmode = htmlspecialchars($extras['vpnmode']);
696
			if ($vpnmode == "server" || $vpnmode == "client") {
697
				$id = htmlspecialchars($extras['id']);
698
				$configfile = "{$g['varetc_path']}/openvpn/{$vpnmode}{$id}.conf";
699
				if (file_exists($configfile))
700
					openvpn_restart_by_vpnid($vpnmode, $id);
701
			}
702
			break;
703
		case 'relayd':
704
			relayd_configure(true);
705
			break;
706
		default:
707
			restart_service($name);
708
			break;
709
	}
710
	return sprintf(gettext("%s has been restarted."),htmlspecialchars($name));
711
}
712

    
713
?>
(49-49/68)