Projet

Général

Profil

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

univnautes / etc / inc / service-utils.inc @ 36de334e

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
		default:
434
			$running = is_service_running($service['name']);
435
	}
436
	return $running;
437
}
438

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

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

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

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

    
710
?>
(48-48/67)