Projet

Général

Profil

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

univnautes / etc / inc / service-utils.inc @ ad03afb6

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
	$rcfile_fullname = RCFILEPREFIX . $params['file'];
53
	if (!file_exists($rcfile_fullname) && !touch($rcfile_fullname))
54
		return false;
55

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

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

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

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

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

    
85
	return;
86
}
87

    
88
function start_service($name) {
89
	global $config;
90

    
91
	if (empty($name))
92
		return;
93

    
94
	/* make sure service is stopped before starting */
95
	stop_service($name);
96
	sleep(2);
97

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

    
123
function stop_service($name) {
124
	global $config;
125

    
126
	if (empty($name))
127
		return;
128

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

    
145
				if(!($service['rcfile'] or $service['stopcmd'])) {
146
					if(is_process_running("{$service['executable']}"))
147
						killbyname($service['executable']);
148
					return;
149
				}
150
				break;
151
			}
152
		}
153
	}
154
	/* finally if we get here lets simply kill the service name */
155
	if(is_process_running(escapeshellarg($name)))
156
		killbyname(escapeshellarg($name));
157
}
158

    
159
function restart_service($name) {
160
	global $config;
161

    
162
	if (empty($name))
163
		return;
164

    
165
	stop_service($name);
166
	start_service($name);
167

    
168
	if($config['installedpackages']['service']) {
169
		foreach($config['installedpackages']['service'] as $service) {
170
			if(strtolower($service['name']) == strtolower($name)) {
171
				if($service['restartcmd']) {
172
					eval($service['restartcmd']);
173
				}
174
				break;
175
			}
176
		}
177
	}
178
}
179

    
180
function is_pid_running($pidfile) {
181
	if (!file_exists($pidfile))
182
		return false;
183

    
184
	return (isvalidpid($pidfile));
185
}
186

    
187
function is_dhcp_running($interface) {
188
	$status = find_dhclient_process($interface);
189
	if($status <> "")
190
		return true;
191
	return false;
192
}
193

    
194
function restart_service_if_running($service) {
195
	global $config;
196
	if(is_service_running($service))
197
		restart_service($service);
198
	return;
199
}
200

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

    
212
function is_service_running($service, $ps = "") {
213
	global $config;
214

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

    
227
				return false;
228
			}
229
		}
230
	}
231

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

    
235
	return false;
236
}
237

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

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

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

    
262
	$pconfig = array();
263
	$pconfig['name'] = "ntpd";
264
	$pconfig['description'] = gettext("NTP clock sync");
265
	$services[] = $pconfig;
266

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

    
279
	$iflist = array();
280
	$ifdescrs = get_configured_interface_list();
281
	foreach ($ifdescrs as $if) {
282
		$oc = $config['interfaces'][$if];
283
		if ($oc['if'] && (!link_interface_to_bridge($if)))
284
			$iflist[$if] = $if;
285
	}
286

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

    
294
	if(isset($config['dhcrelay6']['enable'])) {
295
		$pconfig = array();
296
		$pconfig['name'] = "dhcrelay6";
297
		$pconfig['description'] = gettext("DHCPv6 Relay");
298
		$services[] = $pconfig;
299
	}
300

    
301
	if(is_dhcp_server_enabled()) {
302
		$pconfig = array();
303
		$pconfig['name'] = "dhcpd";
304
		$pconfig['description'] = gettext("DHCP Service");
305
		$services[] = $pconfig;
306
	}
307

    
308
	$gateways_arr = return_gateways_array();
309
	if (is_array($gateways_arr)) {
310
		$pconfig = array();
311
		$pconfig['name'] = "apinger";
312
		$pconfig['description'] = gettext("Gateway Monitoring Daemon");
313
		$services[] = $pconfig;
314
	}
315

    
316
	if(isset($config['snmpd']['enable'])) {
317
		$pconfig = array();
318
		$pconfig['name'] = "bsnmpd";
319
		$pconfig['description'] = gettext("SNMP Service");
320
		$services[] = $pconfig;
321
	}
322

    
323
	if (is_array($config['igmpproxy']['igmpentry']) && (count($config['igmpproxy']['igmpentry']) > 0)) {
324
		$pconfig = array();
325
		$pconfig['name'] = "igmpproxy";
326
		$pconfig['description'] = gettext("IGMP proxy");
327
		$services[] = $pconfig;
328
	}
329

    
330
	if (isset($config['installedpackages']['miniupnpd']) && $config['installedpackages']['miniupnpd']['config'][0]['enable']) {
331
		$pconfig = array();
332
		$pconfig['name'] = "miniupnpd";
333
		$pconfig['description'] = gettext("UPnP Service");
334
		$services[] = $pconfig;
335
	}
336

    
337
	if (isset($config['installedpackages']['routed']) && $config['installedpackages']['routed']['config'][0]['enable']) {
338
		$pconfig = array();
339
		$pconfig['name'] = "routed";
340
		$pconfig['description'] = gettext("RIP Daemon");
341
		$services[] = $pconfig;
342
	}
343

    
344
	if (isset($config['ipsec']['enable'])) {
345
		$pconfig = array();
346
		$pconfig['name'] = "racoon";
347
		$pconfig['description'] = gettext("IPsec VPN");
348
		$services[] = $pconfig;
349
	}
350

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

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

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

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

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

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

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

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

    
440
function get_service_status_icon($service, $withtext = true, $smallicon = false) {
441
	global $g;
442
	$output = "";
443
	if(get_service_status($service)) {
444
		$statustext = gettext("Running");
445
		$output .= "<img style=\"vertical-align:middle\" title=\"" . sprintf(gettext("%s Service is"),$service["name"]) . " {$statustext}\" src=\"/themes/" . $g["theme"] . "/images/icons/";
446
		$output .= ($smallicon) ? "icon_pass.gif" : "icon_service_running.gif";
447
		$output .= "\" alt=\"status\" />";
448
		if ($withtext)
449
			$output .= "&nbsp;&nbsp;" . $statustext;
450
		$output .= "\n";
451
	} else {
452
		$service_enabled = is_service_enabled($service['name']);
453
		$statustext = ($service_enabled) ? gettext("Stopped") : gettext("Disabled");
454
		$output .= "<img style=\"vertical-align:middle\" title=\"" . sprintf(gettext("%s Service is"),$service["name"]) . " {$statustext}\" src=\"/themes/" . $g["theme"] . "/images/icons/";
455
		$output .= ($smallicon) ? "icon_block.gif" : "icon_service_stopped.gif";
456
		$output .= "\" alt=\"status\" />";
457
		if ($withtext)
458
			$output .= "&nbsp;&nbsp;" . "<font color=\"white\">{$statustext}</font>";
459
		$output .= "\n";
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 'racoon':
550
			vpn_ipsec_force_reload();
551
			break;
552
		case 'openvpn':
553
			$vpnmode = isset($extras['vpnmode']) ? htmlspecialchars($extras['vpnmode']) : htmlspecialchars($extras['mode']);
554
			if (($vpnmode == "server") || ($vpnmode == "client")) {
555
				$id = isset($extras['vpnid']) ? htmlspecialchars($extras['vpnid']) : htmlspecialchars($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 = htmlspecialchars($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 'igmpproxy':
609
			killbyname("igmpproxy");
610
			break;
611
		case 'miniupnpd':
612
			upnp_action('stop');
613
			break;
614
		case 'sshd':
615
			killbyname("sshd");
616
			break;
617
		case 'racoon':
618
			exec("killall -9 racoon");
619
			break;
620
		case 'openvpn':
621
			$vpnmode = htmlspecialchars($extras['vpnmode']);
622
			if (($vpnmode == "server") or ($vpnmode == "client")) {
623
				$id = htmlspecialchars($extras['id']);
624
				$pidfile = "{$g['varrun_path']}/openvpn_{$vpnmode}{$id}.pid";
625
				killbypid($pidfile);
626
			}
627
			break;
628
		case 'relayd':
629
			mwexec('pkill relayd');
630
			break;
631
		default:
632
			stop_service($name);
633
			break;
634
	}
635
	return sprintf(gettext("%s has been stopped."), htmlspecialchars($name));
636
}
637
function service_control_restart($name, $extras) {
638
	global $g;
639
	switch($name) {
640
		case 'radvd':
641
			services_radvd_configure();
642
			break;
643
		case 'captiveportal':
644
			$zone = htmlspecialchars($extras['zone']);
645
			killbypid("{$g['varrun_path']}/lighty-{$zone}-CaptivePortal.pid");
646
			killbypid("{$g['varrun_path']}/lighty-{$zone}-CaptivePortal-SSL.pid");
647
			captiveportal_init_webgui_zonename($zone);
648
			break;
649
		case 'ntpd':
650
		case 'openntpd':
651
			system_ntp_configure();
652
			break;
653
		case 'apinger':
654
			killbypid("{$g['varrun_path']}/apinger.pid");
655
			setup_gateways_monitor();
656
			break;
657
		case 'bsnmpd':
658
			services_snmpd_configure();
659
			break;
660
		case 'dhcrelay':
661
			services_dhcrelay_configure();
662
			break;
663
		case 'dhcrelay6':
664
			services_dhcrelay6_configure();
665
			break;
666
		case 'dnsmasq':
667
			services_dnsmasq_configure();
668
			break;
669
		case 'dhcpd':
670
			services_dhcpd_configure();
671
			break;
672
		case 'igmpproxy':
673
			services_igmpproxy_configure();
674
			break;
675
		case 'miniupnpd':
676
			upnp_action('restart');
677
			break;
678
		case 'racoon':
679
			vpn_ipsec_force_reload();
680
			break;
681
		case 'openvpn':
682
			$vpnmode = htmlspecialchars($extras['vpnmode']);
683
			if ($vpnmode == "server" || $vpnmode == "client") {
684
				$id = htmlspecialchars($extras['id']);
685
				$configfile = "{$g['varetc_path']}/openvpn/{$vpnmode}{$id}.conf";
686
				if (file_exists($configfile))
687
					openvpn_restart_by_vpnid($vpnmode, $id);
688
			}
689
			break;
690
		case 'relayd':
691
			relayd_configure(true);
692
			break;
693
		default:
694
			restart_service($name);
695
			break;
696
	}
697
	return sprintf(gettext("%s has been restarted."),htmlspecialchars($name));
698
}
699

    
700
?>
(48-48/66)