Projet

Général

Profil

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

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

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 (is_array($config['installedpackages'])) {
206
		if (isset($config['installedpackages'][$service_name]['config'][0]['enable']) &&
207
			((empty($config['installedpackages'][$service_name]['config'][0]['enable'])) ||
208
			($config['installedpackages'][$service_name]['config'][0]['enable'] === 'off'))) {
209
			return false;
210
		}
211
	}
212
	return true;
213
}
214

    
215
function is_service_running($service, $ps = "") {
216
	global $config;
217

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

    
230
				return false;
231
			}
232
		}
233
	}
234

    
235
	if (is_process_running($service))
236
		return true;
237

    
238
	return false;
239
}
240

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

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

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

    
265
	$pconfig = array();
266
	$pconfig['name'] = "ntpd";
267
	$pconfig['description'] = gettext("NTP clock sync");
268
	$services[] = $pconfig;
269

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
703
?>
(48-48/66)