Project

General

Profile

Download (20.2 KB) Statistics
| Branch: | Tag: | Revision:
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 {$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
						mwexec("/usr/bin/killall {$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("{$name}"))
156
		mwexec("/usr/bin/killall {$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\" />&nbsp;";
448
		if ($withtext)
449
			$output .= "&nbsp;" . $statustext;
450
	} else {
451
		$service_enabled = is_service_enabled($service['name']);
452
		$statustext = ($service_enabled) ? gettext("Stopped") : gettext("Disabled");
453
		$output .= "<img style=\"vertical-align:middle\" title=\"" . sprintf(gettext("%s Service is"),$service["name"]) . " {$statustext}\" src=\"/themes/" . $g["theme"] . "/images/icons/";
454
		$output .= ($smallicon) ? "icon_block.gif" : "icon_service_stopped.gif";
455
		$output .= "\" alt=\"status\" />&nbsp;";
456
		if ($withtext)
457
			$output .= "&nbsp;<font color=\"white\">{$statustext}</font>";
458
	}
459
	return $output;
460
}
461

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

    
509
function service_control_start($name, $extras) {
510
	global $g;
511
	switch($name) {
512
		case 'radvd':
513
			services_radvd_configure();
514
			break;
515
		case 'captiveportal':
516
			$zone = $extras['zone'];
517
			captiveportal_init_webgui_zonename($zone);
518
			break;
519
		case 'ntpd':
520
		case 'openntpd':
521
			system_ntp_configure();
522
			break;
523
		case 'apinger':
524
			setup_gateways_monitor();
525
			break;
526
		case 'bsnmpd':
527
			services_snmpd_configure();
528
			break;
529
		case 'dhcrelay':
530
			services_dhcrelay_configure();
531
			break;
532
		case 'dhcrelay6':
533
			services_dhcrelay6_configure();
534
			break;
535
		case 'dnsmasq':
536
			services_dnsmasq_configure();
537
			break;
538
		case 'dhcpd':
539
			services_dhcpd_configure();
540
			break;
541
		case 'igmpproxy':
542
			services_igmpproxy_configure();
543
			break;
544
		case 'miniupnpd':
545
			upnp_action('start');
546
			break;
547
		case 'racoon':
548
			vpn_ipsec_force_reload();
549
			break;
550
		case 'openvpn':
551
			$vpnmode = isset($extras['vpnmode']) ? $extras['vpnmode'] : $extras['mode'];
552
			if (($vpnmode == "server") || ($vpnmode == "client")) {
553
				$id = isset($extras['vpnid']) ? $extras['vpnid'] : $extras['id'];
554
				$configfile = "{$g['varetc_path']}/openvpn/{$vpnmode}{$id}.conf";
555
				if (file_exists($configfile))
556
					openvpn_restart_by_vpnid($vpnmode, $id);
557
			}
558
			break;
559
		case 'relayd':
560
			relayd_configure();
561
			break;
562
		default:
563
			start_service($name);
564
			break;
565
	}
566
	return sprintf(gettext("%s has been started."),htmlspecialchars($name));
567
}
568
function service_control_stop($name, $extras) {
569
	global $g;
570
	switch($name) {
571
		case 'radvd':
572
			killbypid("{$g['varrun_path']}/radvd.pid");
573
			break;
574
		case 'captiveportal':
575
			$zone = $extras['zone'];
576
			killbypid("{$g['varrun_path']}/lighty-{$zone}-CaptivePortal.pid");
577
			killbypid("{$g['varrun_path']}/lighty-{$zone}-CaptivePortal-SSL.pid");
578
			break;
579
		case 'ntpd':
580
			killbyname("ntpd");
581
			break;
582
		case 'openntpd':
583
			killbyname("openntpd");
584
			break;
585
		case 'apinger':
586
			killbypid("{$g['varrun_path']}/apinger.pid");
587
			break;
588
		case 'bsnmpd':
589
			killbypid("{$g['varrun_path']}/snmpd.pid");
590
			break;
591
		case 'choparp':
592
			killbyname("choparp");
593
			break;
594
		case 'dhcpd':
595
			killbyname("dhcpd");
596
			break;
597
		case 'dhcrelay':
598
			killbypid("{$g['varrun_path']}/dhcrelay.pid");
599
			break;
600
		case 'dhcrelay6':
601
			killbypid("{$g['varrun_path']}/dhcrelay6.pid");
602
			break;
603
		case 'dnsmasq':
604
			killbypid("{$g['varrun_path']}/dnsmasq.pid");
605
			break;
606
		case 'igmpproxy':
607
			killbyname("igmpproxy");
608
			break;
609
		case 'miniupnpd':
610
			upnp_action('stop');
611
			break;
612
		case 'sshd':
613
			killbyname("sshd");
614
			break;
615
		case 'racoon':
616
			exec("killall -9 racoon");
617
			break;
618
		case 'openvpn':
619
			$vpnmode = $extras['vpnmode'];
620
			if (($vpnmode == "server") or ($vpnmode == "client")) {
621
				$id = $extras['id'];
622
				$pidfile = "{$g['varrun_path']}/openvpn_{$vpnmode}{$id}.pid";
623
				killbypid($pidfile);
624
			}
625
			break;
626
		case 'relayd':
627
			mwexec('pkill relayd');
628
			break;
629
		default:
630
			stop_service($name);
631
			break;
632
	}
633
	return sprintf(gettext("%s has been stopped."), htmlspecialchars($name));
634
}
635
function service_control_restart($name, $extras) {
636
	global $g;
637
	switch($name) {
638
		case 'radvd':
639
			services_radvd_configure();
640
			break;
641
		case 'captiveportal':
642
			$zone = $extras['zone'];
643
			killbypid("{$g['varrun_path']}/lighty-{$zone}-CaptivePortal.pid");
644
			killbypid("{$g['varrun_path']}/lighty-{$zone}-CaptivePortal-SSL.pid");
645
			captiveportal_init_webgui_zonename($zone);
646
			break;
647
		case 'ntpd':
648
		case 'openntpd':
649
			system_ntp_configure();
650
			break;
651
		case 'apinger':
652
			killbypid("{$g['varrun_path']}/apinger.pid");
653
			setup_gateways_monitor();
654
			break;
655
		case 'bsnmpd':
656
			services_snmpd_configure();
657
			break;
658
		case 'dhcrelay':
659
			services_dhcrelay_configure();
660
			break;
661
		case 'dhcrelay6':
662
			services_dhcrelay6_configure();
663
			break;
664
		case 'dnsmasq':
665
			services_dnsmasq_configure();
666
			break;
667
		case 'dhcpd':
668
			services_dhcpd_configure();
669
			break;
670
		case 'igmpproxy':
671
			services_igmpproxy_configure();
672
			break;
673
		case 'miniupnpd':
674
			upnp_action('restart');
675
			break;
676
		case 'racoon':
677
			vpn_ipsec_force_reload();
678
			break;
679
		case 'openvpn':
680
			$vpnmode = $extras['vpnmode'];
681
			if ($vpnmode == "server" || $vpnmode == "client") {
682
				$id = $extras['id'];
683
				$configfile = "{$g['varetc_path']}/openvpn/{$vpnmode}{$id}.conf";
684
				if (file_exists($configfile))
685
					openvpn_restart_by_vpnid($vpnmode, $id);
686
			}
687
			break;
688
		case 'relayd':
689
			relayd_configure(true);
690
			break;
691
		default:
692
			restart_service($name);
693
			break;
694
	}
695
	return sprintf(gettext("%s has been restarted."),htmlspecialchars($name));
696
}
697

    
698
?>
(48-48/66)