Project

General

Profile

Download (20.5 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 " . 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
	unset($towrite);
84
	@chmod("{$rcfile_fullname}", 0755);
85

    
86
	return;
87
}
88

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

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

    
95
	if (is_array($config['installedpackages']) && is_array($config['installedpackages']['service'])) {
96
		foreach($config['installedpackages']['service'] as $service) {
97
			if(strtolower($service['name']) == strtolower($name)) {
98
				if($service['rcfile']) {
99
					$prefix = RCFILEPREFIX;
100
					if (!empty($service['prefix'])) {
101
						$prefix =& $service['prefix'];
102
					}
103
					if(file_exists("{$prefix}{$service['rcfile']}")) {
104
						mwexec_bg("{$prefix}{$service['rcfile']} start");
105
					}
106
				}
107
				if (!empty($service['startcmd']))
108
					eval($service['startcmd']);
109
				break;
110
			}
111
		}
112
	}
113
}
114

    
115
function stop_service($name) {
116
	global $config;
117

    
118
	if (empty($name))
119
		return;
120

    
121
	if (is_array($config['installedpackages']) && is_array($config['installedpackages']['service'])) {
122
		foreach($config['installedpackages']['service'] as $service) {
123
			if(strtolower($service['name']) == strtolower($name)) {
124
				if($service['rcfile']) {
125
					$prefix = RCFILEPREFIX;
126
					if(!empty($service['prefix'])) {
127
						$prefix =& $service['prefix'];
128
					}
129
					if(file_exists("{$prefix}{$service['rcfile']}")) {
130
						mwexec("{$prefix}{$service['rcfile']} stop");
131
					}
132
					return;
133
				}
134
				if (!empty($service['stopcmd']))
135
					eval($service['stopcmd']);
136

    
137
				break;
138
			}
139
		}
140
	}
141
}
142

    
143
function restart_service($name) {
144
	global $config;
145

    
146
	if (empty($name))
147
		return;
148

    
149
	stop_service($name);
150
	start_service($name);
151

    
152
	if (is_array($config['installedpackages']) && is_array($config['installedpackages']['service'])) {
153
		foreach($config['installedpackages']['service'] as $service) {
154
			if(strtolower($service['name']) == strtolower($name)) {
155
				if($service['restartcmd']) {
156
					eval($service['restartcmd']);
157
				}
158
				break;
159
			}
160
		}
161
	}
162
}
163

    
164
function is_pid_running($pidfile) {
165
	if (!file_exists($pidfile))
166
		return false;
167

    
168
	return (isvalidpid($pidfile));
169
}
170

    
171
function is_dhcp_running($interface) {
172
	$status = find_dhclient_process($interface);
173
	if($status <> "")
174
		return true;
175
	return false;
176
}
177

    
178
function restart_service_if_running($service) {
179
	global $config;
180
	if(is_service_running($service))
181
		restart_service($service);
182
	return;
183
}
184

    
185
function is_service_enabled($service_name) {
186
	global $config;
187
	if ($service_name == "")
188
		return false;
189
	if (isset($config['installedpackages'][$service_name]['config'][0]['enable']) &&
190
		((empty($config['installedpackages'][$service_name]['config'][0]['enable'])) ||
191
		 ($config['installedpackages'][$service_name]['config'][0]['enable'] === 'off')))
192
		return false;
193
	return true;
194
}
195

    
196
function is_service_running($service, $ps = "") {
197
	global $config;
198

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

    
211
				return false;
212
			}
213
		}
214
	}
215

    
216
	if (is_process_running($service))
217
		return true;
218

    
219
	return false;
220
}
221

    
222
function get_services() {
223
	global $config;
224
	if (is_array($config['installedpackages']['service']))
225
		$services = $config['installedpackages']['service'];
226
	else
227
		$services = array();
228

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

    
239
	if (isset($config['dnsmasq']['enable'])) {
240
		$pconfig = array();
241
		$pconfig['name'] = "dnsmasq";
242
		$pconfig['description'] = gettext("DNS Forwarder");
243
		$services[] = $pconfig;
244
	}
245

    
246
	if (isset($config['unbound']['enable'])) {
247
		$pconfig = array();
248
		$pconfig['name'] = "unbound";
249
		$pconfig['description'] = gettext("Unbound DNS Forwarder");
250
		$services[] = $pconfig;
251
	}
252

    
253
	$pconfig = array();
254
	$pconfig['name'] = "ntpd";
255
	$pconfig['description'] = gettext("NTP clock sync");
256
	$services[] = $pconfig;
257

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

    
270
	$iflist = array();
271
	$ifdescrs = get_configured_interface_list();
272
	foreach ($ifdescrs as $if) {
273
		$oc = $config['interfaces'][$if];
274
		if ($oc['if'] && (!link_interface_to_bridge($if)))
275
			$iflist[$if] = $if;
276
	}
277

    
278
	if (isset($config['dhcrelay']['enable'])) {
279
		$pconfig = array();
280
		$pconfig['name'] = "dhcrelay";
281
		$pconfig['description'] = gettext("DHCP Relay");
282
		$services[] = $pconfig;
283
	}
284

    
285
	if (isset($config['dhcrelay6']['enable'])) {
286
		$pconfig = array();
287
		$pconfig['name'] = "dhcrelay6";
288
		$pconfig['description'] = gettext("DHCPv6 Relay");
289
		$services[] = $pconfig;
290
	}
291

    
292
	if (is_dhcp_server_enabled()) {
293
		$pconfig = array();
294
		$pconfig['name'] = "dhcpd";
295
		$pconfig['description'] = gettext("DHCP Service");
296
		$services[] = $pconfig;
297
	}
298

    
299
	$gateways_arr = return_gateways_array();
300
	if (is_array($gateways_arr)) {
301
		$pconfig = array();
302
		$pconfig['name'] = "apinger";
303
		$pconfig['description'] = gettext("Gateway Monitoring Daemon");
304
		$services[] = $pconfig;
305
	}
306

    
307
	if (isset($config['snmpd']['enable'])) {
308
		$pconfig = array();
309
		$pconfig['name'] = "bsnmpd";
310
		$pconfig['description'] = gettext("SNMP Service");
311
		$services[] = $pconfig;
312
	}
313

    
314
	if (is_array($config['igmpproxy']['igmpentry']) && (count($config['igmpproxy']['igmpentry']) > 0)) {
315
		$pconfig = array();
316
		$pconfig['name'] = "igmpproxy";
317
		$pconfig['description'] = gettext("IGMP proxy");
318
		$services[] = $pconfig;
319
	}
320

    
321
	if (isset($config['installedpackages']['miniupnpd']) && $config['installedpackages']['miniupnpd']['config'][0]['enable']) {
322
		$pconfig = array();
323
		$pconfig['name'] = "miniupnpd";
324
		$pconfig['description'] = gettext("UPnP Service");
325
		$services[] = $pconfig;
326
	}
327

    
328
	if (isset($config['installedpackages']['routed']) && $config['installedpackages']['routed']['config'][0]['enable']) {
329
		$pconfig = array();
330
		$pconfig['name'] = "routed";
331
		$pconfig['description'] = gettext("RIP Daemon");
332
		$services[] = $pconfig;
333
	}
334

    
335
	if (isset($config['ipsec']['enable'])) {
336
		$pconfig = array();
337
		$pconfig['name'] = "ipsec";
338
		$pconfig['description'] = gettext("IPsec VPN");
339
		$services[] = $pconfig;
340
	}
341

    
342
	if (isset($config['system']['enablesshd'])) {
343
		$pconfig = array();
344
		$pconfig['name'] = "sshd";
345
		$pconfig['description'] = gettext("Secure Shell Daemon");
346
		$services[] = $pconfig;
347
	}
348

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

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

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

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

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

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

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

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

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

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

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

    
709
?>
(48-48/67)