Project

General

Profile

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

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

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

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

    
80
	/* begin rcfile logic */
81
	$towrite .= "case \$1 in\n\tstart)\n\t\trc_start\n\t\t;;\n\tstop)\n\t\trc_stop\n\t\t;;\n\trestart)\n\t\trc_stop\n\t\trc_start\n\t\t;;\nesac\n\n";
82

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

    
87
	return;
88
}
89

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

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

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

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

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

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

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

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

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

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

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

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

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

    
172
function is_dhcp_running($interface) {
173
	$status = find_dhclient_process($interface);
174
	if($status != 0)
175
		return true;
176
	return false;
177
}
178

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

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

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

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

    
215
				return false;
216
			}
217
		}
218
	}
219

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

    
223
	return false;
224
}
225

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
412
function get_service_status($service) {
413
	global $g;
414
	switch ($service['name']) {
415
		case "openvpn":
416
			$running = is_pid_running("{$g['varrun_path']}/openvpn_{$service['mode']}{$service['vpnid']}.pid");
417
			break;
418
		case "captiveportal":
419
			$running = is_pid_running("{$g['varrun_path']}/lighty-{$service['zone']}-CaptivePortal.pid");
420
			if (isset($config['captiveportal'][$service['zone']]['httpslogin']))
421
				$running = $running && is_pid_running("{$g['varrun_path']}/lighty-{$service['zone']}-CaptivePortal-SSL.pid");
422
			break;
423
		case "vhosts-http":
424
			$running = is_pid_running("{$g['varrun_path']}/vhosts-http.pid");
425
			break;
426
		case "dhcrelay6":
427
			$running = is_pid_running("{$g['varrun_path']}/dhcrelay6.pid");
428
			break;
429
		case 'ipsec':
430
			$running = is_pid_running("{$g['varrun_path']}/charon.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 = htmlspecialchars($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 'unbound':
537
			services_unbound_configure();
538
			break;
539
		case 'dhcpd':
540
			services_dhcpd_configure();
541
			break;
542
		case 'igmpproxy':
543
			services_igmpproxy_configure();
544
			break;
545
		case 'miniupnpd':
546
			upnp_action('start');
547
			break;
548
		case 'ipsec':
549
			vpn_ipsec_force_reload();
550
			break;
551
		case 'sshd':
552
			send_event("service restart sshd");
553
			break;
554
		case 'openvpn':
555
			$vpnmode = isset($extras['vpnmode']) ? htmlspecialchars($extras['vpnmode']) : htmlspecialchars($extras['mode']);
556
			if (($vpnmode == "server") || ($vpnmode == "client")) {
557
				$id = isset($extras['vpnid']) ? htmlspecialchars($extras['vpnid']) : htmlspecialchars($extras['id']);
558
				$configfile = "{$g['varetc_path']}/openvpn/{$vpnmode}{$id}.conf";
559
				if (file_exists($configfile))
560
					openvpn_restart_by_vpnid($vpnmode, $id);
561
			}
562
			break;
563
		case 'relayd':
564
			relayd_configure();
565
			break;
566
		default:
567
			start_service($name);
568
			break;
569
	}
570
	return sprintf(gettext("%s has been started."),htmlspecialchars($name));
571
}
572
function service_control_stop($name, $extras) {
573
	global $g;
574
	switch($name) {
575
		case 'radvd':
576
			killbypid("{$g['varrun_path']}/radvd.pid");
577
			break;
578
		case 'captiveportal':
579
			$zone = htmlspecialchars($extras['zone']);
580
			killbypid("{$g['varrun_path']}/lighty-{$zone}-CaptivePortal.pid");
581
			killbypid("{$g['varrun_path']}/lighty-{$zone}-CaptivePortal-SSL.pid");
582
			break;
583
		case 'ntpd':
584
			killbyname("ntpd");
585
			break;
586
		case 'openntpd':
587
			killbyname("openntpd");
588
			break;
589
		case 'apinger':
590
			killbypid("{$g['varrun_path']}/apinger.pid");
591
			break;
592
		case 'bsnmpd':
593
			killbypid("{$g['varrun_path']}/snmpd.pid");
594
			break;
595
		case 'choparp':
596
			killbyname("choparp");
597
			break;
598
		case 'dhcpd':
599
			killbyname("dhcpd");
600
			break;
601
		case 'dhcrelay':
602
			killbypid("{$g['varrun_path']}/dhcrelay.pid");
603
			break;
604
		case 'dhcrelay6':
605
			killbypid("{$g['varrun_path']}/dhcrelay6.pid");
606
			break;
607
		case 'dnsmasq':
608
			killbypid("{$g['varrun_path']}/dnsmasq.pid");
609
			break;
610
		case 'unbound':
611
			killbypid("{$g['varrun_path']}/unbound.pid");
612
			break;
613
		case 'igmpproxy':
614
			killbyname("igmpproxy");
615
			break;
616
		case 'miniupnpd':
617
			upnp_action('stop');
618
			break;
619
		case 'sshd':
620
			killbyname("sshd");
621
			break;
622
		case 'ipsec':
623
			exec("/usr/local/sbin/ipsec stop");
624
			break;
625
		case 'openvpn':
626
			$vpnmode = htmlspecialchars($extras['vpnmode']);
627
			if (($vpnmode == "server") or ($vpnmode == "client")) {
628
				$id = htmlspecialchars($extras['id']);
629
				$pidfile = "{$g['varrun_path']}/openvpn_{$vpnmode}{$id}.pid";
630
				killbypid($pidfile);
631
			}
632
			break;
633
		case 'relayd':
634
			mwexec('pkill relayd');
635
			break;
636
		default:
637
			stop_service($name);
638
			break;
639
	}
640
	return sprintf(gettext("%s has been stopped."), htmlspecialchars($name));
641
}
642

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

    
712
?>
(49-49/68)