Projet

Général

Profil

Télécharger (21 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / etc / inc / service-utils.inc @ 762e8cf9

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 (is_array($config['installedpackages'])) {
191
		if (isset($config['installedpackages'][$service_name]['config'][0]['enable']) &&
192
			((empty($config['installedpackages'][$service_name]['config'][0]['enable'])) ||
193
			($config['installedpackages'][$service_name]['config'][0]['enable'] === 'off'))) {
194
			return false;
195
		}
196
	}
197
	return true;
198
}
199

    
200
function is_service_running($service, $ps = "") {
201
	global $config;
202

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

    
215
				return false;
216
			}
217
		}
218
	}
219

    
220
	if (is_process_running($service))
221
		return true;
222

    
223
	return false;
224
}
225

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

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

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

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

    
257
	$pconfig = array();
258
	$pconfig['name'] = "ntpd";
259
	$pconfig['description'] = gettext("NTP clock sync");
260
	$services[] = $pconfig;
261

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
386
function find_service_by_openvpn_vpnid($vpnid) {
387
	$services = get_services();
388
	foreach ($services as $service)
389
		if (($service["name"] == "openvpn") && isset($service["vpnid"]) && ($service["vpnid"] == $vpnid))
390
			return $service;
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
	return array();
400
}
401

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

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

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

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

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

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

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

    
716
?>
(49-49/68)