Project

General

Profile

Download (22.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
	Copyright (C) 2005-2006 Colin Smith (ethethlay@gmail.com)
11
	All rights reserved.
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14

    
15
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17

    
18
	2. Redistributions in binary form must reproduce the above copyright
19
	   notice, this list of conditions and the following disclaimer in the
20
	   documentation and/or other materials provided with the distribution.
21

    
22
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
	RISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
	POSSIBILITY OF SUCH DAMAGE.
32

    
33
 */
34

    
35
/*
36
	pfSense_BUILDER_BINARIES:	/bin/pgrep /bin/sh /usr/bin/killall
37
	pfSense_MODULE:	utils
38
*/
39
require_once("globals.inc");
40
require_once("captiveportal.inc");
41
require_once("openvpn.inc");
42
require_once("ipsec.inc");
43
require_once("vpn.inc");
44
require_once("vslb.inc");
45
require_once("gwlb.inc");
46

    
47
define("RCFILEPREFIX", "/usr/local/etc/rc.d/");
48
function write_rcfile($params) {
49
	global $g;
50

    
51
	safe_mkdir(RCFILEPREFIX);
52
	$rcfile_fullname = RCFILEPREFIX . $params['file'];
53
	if (!file_exists($rcfile_fullname) && !is_link($rcfile_fullname) && !touch($rcfile_fullname)) {
54
		return false;
55
	}
56

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

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

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

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

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

    
88
	return;
89
}
90

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

    
94
	if (empty($name)) {
95
		return;
96
	}
97

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

    
119
function stop_service($name) {
120
	global $config;
121

    
122
	if (empty($name)) {
123
		return;
124
	}
125

    
126
	if (is_array($config['installedpackages']) && is_array($config['installedpackages']['service'])) {
127
		foreach ($config['installedpackages']['service'] as $service) {
128
			if (strtolower($service['name']) == strtolower($name)) {
129
				if ($service['rcfile']) {
130
					$prefix = RCFILEPREFIX;
131
					if (!empty($service['prefix'])) {
132
						$prefix =& $service['prefix'];
133
					}
134
					if (file_exists("{$prefix}{$service['rcfile']}") || is_link("{$prefix}{$service['rcfile']}")) {
135
						mwexec("{$prefix}{$service['rcfile']} stop");
136
					}
137
					return;
138
				}
139
				if (!empty($service['stopcmd'])) {
140
					eval($service['stopcmd']);
141
				} elseif (!empty($service['executable'])) {
142
					mwexec("/usr/bin/killall " . escapeshellarg($service['executable']));
143
				}
144

    
145
				break;
146
			}
147
		}
148
	}
149
}
150

    
151
function restart_service($name) {
152
	global $config;
153

    
154
	if (empty($name)) {
155
		return;
156
	}
157

    
158
	if (is_service_running($name)) {
159
		stop_service($name);
160
	}
161
	start_service($name);
162

    
163
	if (is_array($config['installedpackages']) && is_array($config['installedpackages']['service'])) {
164
		foreach ($config['installedpackages']['service'] as $service) {
165
			if (strtolower($service['name']) == strtolower($name)) {
166
				if ($service['restartcmd']) {
167
					eval($service['restartcmd']);
168
				}
169
				break;
170
			}
171
		}
172
	}
173
}
174

    
175
function is_pid_running($pidfile) {
176
	if (!file_exists($pidfile)) {
177
		return false;
178
	}
179

    
180
	return (isvalidpid($pidfile));
181
}
182

    
183
function is_dhcp_running($interface) {
184
	$status = find_dhclient_process($interface);
185
	if ($status != 0) {
186
		return true;
187
	}
188
	return false;
189
}
190

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

    
199
function is_service_enabled($service_name) {
200
	global $config;
201
	if ($service_name == "") {
202
		return false;
203
	}
204
	if (is_array($config['installedpackages'])) {
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
		}
210
	}
211
	return true;
212
}
213

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

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

    
231
				return false;
232
			}
233
		}
234
	}
235

    
236
	if (is_process_running($service)) {
237
		return true;
238
	}
239

    
240
	return false;
241
}
242

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

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

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

    
268
	if (isset($config['unbound']['enable'])) {
269
		$pconfig = array();
270
		$pconfig['name'] = "unbound";
271
		$pconfig['description'] = gettext("DNS Resolver");
272
		$services[] = $pconfig;
273
	}
274

    
275
	$pconfig = array();
276
	$pconfig['name'] = "ntpd";
277
	$pconfig['description'] = gettext("NTP clock sync");
278
	$services[] = $pconfig;
279

    
280
	if (is_array($config['captiveportal'])) {
281
		foreach ($config['captiveportal'] as $zone => $setting) {
282
			if (isset($setting['enable'])) {
283
				$pconfig = array();
284
				$pconfig['name'] = "captiveportal";
285
				$pconfig['zone'] = $zone;
286
				$pconfig['description'] = gettext("Captive Portal") . ": ".htmlspecialchars($setting['zone']);
287
				$services[] = $pconfig;
288
			}
289
		}
290
	}
291

    
292
	$iflist = array();
293
	$ifdescrs = get_configured_interface_list();
294
	foreach ($ifdescrs as $if) {
295
		$oc = $config['interfaces'][$if];
296
		if ($oc['if'] && (!link_interface_to_bridge($if))) {
297
			$iflist[$if] = $if;
298
		}
299
	}
300

    
301
	if (isset($config['dhcrelay']['enable'])) {
302
		$pconfig = array();
303
		$pconfig['name'] = "dhcrelay";
304
		$pconfig['description'] = gettext("DHCP Relay");
305
		$services[] = $pconfig;
306
	}
307

    
308
	if (isset($config['dhcrelay6']['enable'])) {
309
		$pconfig = array();
310
		$pconfig['name'] = "dhcrelay6";
311
		$pconfig['description'] = gettext("DHCPv6 Relay");
312
		$services[] = $pconfig;
313
	}
314

    
315
	if (is_dhcp_server_enabled()) {
316
		$pconfig = array();
317
		$pconfig['name'] = "dhcpd";
318
		$pconfig['description'] = gettext("DHCP Service");
319
		$services[] = $pconfig;
320
	}
321

    
322
	$gateways_arr = return_gateways_array();
323
	if (is_array($gateways_arr)) {
324
		$pconfig = array();
325
		$pconfig['name'] = "dpinger";
326
		$pconfig['description'] = gettext("Gateway Monitoring Daemon");
327
		$services[] = $pconfig;
328
	}
329

    
330
	if (isset($config['snmpd']['enable'])) {
331
		$pconfig = array();
332
		$pconfig['name'] = "bsnmpd";
333
		$pconfig['description'] = gettext("SNMP Service");
334
		$services[] = $pconfig;
335
	}
336

    
337
	if (is_array($config['igmpproxy']['igmpentry']) && (count($config['igmpproxy']['igmpentry']) > 0)) {
338
		$pconfig = array();
339
		$pconfig['name'] = "igmpproxy";
340
		$pconfig['description'] = gettext("IGMP proxy");
341
		$services[] = $pconfig;
342
	}
343

    
344
	if (isset($config['installedpackages']['miniupnpd']) && $config['installedpackages']['miniupnpd']['config'][0]['enable']) {
345
		$pconfig = array();
346
		$pconfig['name'] = "miniupnpd";
347
		$pconfig['description'] = gettext("UPnP Service");
348
		$services[] = $pconfig;
349
	}
350

    
351
	if (ipsec_enabled()) {
352
		$pconfig = array();
353
		$pconfig['name'] = "ipsec";
354
		$pconfig['description'] = gettext("IPsec VPN");
355
		$services[] = $pconfig;
356
	}
357

    
358
	if (isset($config['system']['enablesshd'])) {
359
		$pconfig = array();
360
		$pconfig['name'] = "sshd";
361
		$pconfig['description'] = gettext("Secure Shell Daemon");
362
		$services[] = $pconfig;
363
	}
364

    
365
	foreach (array('server', 'client') as $mode) {
366
		if (is_array($config['openvpn']["openvpn-{$mode}"])) {
367
			foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) {
368
				if (!isset($setting['disable'])) {
369
					$pconfig = array();
370
					$pconfig['name'] = "openvpn";
371
					$pconfig['mode'] = $mode;
372
					$pconfig['id'] = $id;
373
					$pconfig['vpnid'] = $setting['vpnid'];
374
					$pconfig['description'] = gettext("OpenVPN") . " ".$mode.": ".htmlspecialchars($setting['description']);
375
					$services[] = $pconfig;
376
				}
377
			}
378
		}
379
	}
380

    
381
	if (count($config['load_balancer']['virtual_server']) && count($config['load_balancer']['lbpool'])) {
382
		$pconfig = array();
383
		$pconfig['name'] = "relayd";
384
		$pconfig['description'] = gettext("Server load balancing daemon");
385
		$services[] = $pconfig;
386
	}
387
	return $services;
388
}
389

    
390
function find_service_by_name($name) {
391
	$services = get_services();
392
	foreach ($services as $service) {
393
		if ($service["name"] == $name) {
394
			return $service;
395
		}
396
	}
397
	return array();
398
}
399

    
400
function find_service_by_openvpn_vpnid($vpnid) {
401
	$services = get_services();
402
	foreach ($services as $service) {
403
		if (($service["name"] == "openvpn") && isset($service["vpnid"]) && ($service["vpnid"] == $vpnid)) {
404
			return $service;
405
		}
406
	}
407
	return array();
408
}
409

    
410
function find_service_by_cp_zone($zone) {
411
	$services = get_services();
412
	foreach ($services as $service) {
413
		if (($service["name"] == "captiveportal") && isset($service["zone"]) && ($service["zone"] == $zone)) {
414
			return $service;
415
		}
416
	}
417
	return array();
418
}
419

    
420
function service_name_compare($a, $b) {
421
	if (strtolower($a['name']) == strtolower($b['name'])) {
422
		return 0;
423
	}
424
	return (strtolower($a['name']) < strtolower($b['name'])) ? -1 : 1;
425
}
426

    
427
function get_pkg_descr($package_name) {
428
	global $config;
429
	if (is_array($config['installedpackages']['package'])) {
430
		foreach ($config['installedpackages']['package'] as $pkg) {
431
			if ($pkg['name'] == $package_name) {
432
				return $pkg['descr'];
433
			}
434
		}
435
	}
436
	return gettext("Not available.");
437
}
438

    
439
function get_service_status($service) {
440
	global $g;
441
	switch ($service['name']) {
442
		case "openvpn":
443
			$running = is_pid_running("{$g['varrun_path']}/openvpn_{$service['mode']}{$service['vpnid']}.pid");
444
			break;
445
		case "captiveportal":
446
			$running = is_pid_running("{$g['varrun_path']}/lighty-{$service['zone']}-CaptivePortal.pid");
447
			if (isset($config['captiveportal'][$service['zone']]['httpslogin'])) {
448
				$running = $running && is_pid_running("{$g['varrun_path']}/lighty-{$service['zone']}-CaptivePortal-SSL.pid");
449
			}
450
			break;
451
		case "vhosts-http":
452
			$running = is_pid_running("{$g['varrun_path']}/vhosts-http.pid");
453
			break;
454
		case "dhcrelay6":
455
			$running = is_pid_running("{$g['varrun_path']}/dhcrelay6.pid");
456
			break;
457
		case 'ipsec':
458
			$running = is_pid_running("{$g['varrun_path']}/charon.pid");
459
			break;
460
		default:
461
			$running = is_service_running($service['name']);
462
	}
463
	return $running;
464
}
465

    
466
function get_service_status_icon($service, $withtext = true, $smallicon = false) {
467
	global $g;
468
	$output = "";
469
	if (get_service_status($service)) {
470
		$statustext = gettext("Running");
471
		$output .= "<a title=\"" . sprintf(gettext("%s Service is"), $service["name"]) . " {$statustext}\" ><i class=\"";
472
		$output .= ($smallicon) ? "fa fa-play" : "fa fa-lg fa-play";
473
		$output .= "\" ></i></a>";
474
		if ($withtext) {
475
			$output .= "&nbsp;" . $statustext;
476
		}
477
	} else {
478
		$service_enabled = is_service_enabled($service['name']);
479
		$statustext = ($service_enabled) ? gettext("Stopped") : gettext("Disabled");
480
		$output .= "<a title=\"" . sprintf(gettext("%s Service is"), $service["name"]) . " {$statustext}\" ><i class=\"";
481
		$output .= ($smallicon) ? "fa fa-times" : "fa fa-lg fa-times";
482
		$output .= "\" ></i></a>";
483
		if ($withtext) {
484
			$output .= "&nbsp;" . $statustext;
485
		}
486
	}
487
	return $output;
488
}
489

    
490

    
491
// This version proved GET formatted links
492
function get_service_control_GET_links($service, $addname = false) {
493
	global $g;
494
	$output = "";
495
	$stitle = ($addname) ? $service['name'] . " " : "";
496

    
497
	switch ($service['name']) {
498
		case "openvpn":
499
			$link = '<a title="%s" href="status_services.php?mode=%s&amp;service='.$service['name'] . '&amp;vpnmode=' . $service['mode'] . '&amp;id=' . $service['vpnid'] . '">';
500
		break;
501
		case "captiveportal":
502
			$link = '<a title="%s" href="status_services.php?mode=%s&amp;service=' . $service['name'] . '&amp;zone=' . $service['zone'] . '">';
503
		break;
504
		default:
505
			$link = '<a title="%s" href="status_services.php?mode=%s&amp;service=' . $service['name'] . '">';
506
	}
507

    
508
	if (get_service_status($service)) {
509
		switch ($service['name']) {
510
			case "openvpn":
511
				$output .= "<a href=\"status_services.php?mode=restartservice&amp;service={$service['name']}&amp;vpnmode={$service['mode']}&amp;id={$service['vpnid']}\">";
512
				break;
513
			case "captiveportal":
514
				$output .= "<a href=\"status_services.php?mode=restartservice&amp;service={$service['name']}&amp;zone={$service['zone']}\">";
515
				break;
516
			default:
517
				$output .= "<a href=\"status_services.php?mode=restartservice&amp;service={$service['name']}\">";
518
		}
519
		$output .= "<i class=\"fa fa-repeat\" title=\"" . sprintf(gettext("Restart %sService"), $stitle) . "\"></i></a>\n";
520
		switch ($service['name']) {
521
			case "openvpn":
522
				$output .= "<a href=\"status_services.php?mode=stopservice&amp;service={$service['name']}&amp;vpnmode={$service['mode']}&amp;id={$service['vpnid']}\">";
523
				break;
524
			case "captiveportal":
525
				$output .= "<a href=\"status_services.php?mode=stopservice&amp;service={$service['name']}&amp;zone={$service['zone']}\">";
526
				break;
527
			default:
528
				$output .= "<a href=\"status_services.php?mode=stopservice&amp;service={$service['name']}\">";
529
		}
530
		$output .= "<i class=\"fa fa-stop\" title=\"" . sprintf(gettext("Stop %sService"), $stitle) . "\"></i></a>";
531
	} else {
532
		$service_enabled = is_service_enabled($service['name']);
533

    
534
		if ($service['name'] == 'openvpn' || $service['name'] == 'captiveportal' || $service_enabled) {
535
			$output .= sprintf($link, sprintf(gettext("Start %sService"), $stitle), 'startservice');
536
			$output .= '<i class="fa fa-play-circle"></i></a> ';
537
		}
538
	}
539

    
540
	return $output;
541
}
542

    
543
function get_service_control_links($service, $addname = false) {
544
	global $g;
545
	$output = "";
546
	$stitle = ($addname) ? $service['name'] . " " : "";
547

    
548
	switch ($service['name']) {
549
		case "openvpn":
550
			$link = '<a title="%s" href="#" id="openvpn-%s-' . $service['mode'] . '-' . $service['vpnid'] . '" >';
551
		break;
552
		case "captiveportal":
553
			$link = '<a title="%s" href="#" id="captiveportal-%s-' . $service['zone'] . '">';
554
		break;
555
		default:
556
			$link = '<a title="%s" href="#" id="%s-' . $service['name'] . '">';
557
	}
558

    
559
	if (get_service_status($service)) {
560
		switch ($service['name']) {
561
			case "openvpn":
562
				$output .= '<a href="#" id="openvpn-restartservice-' . $service['mode'] . '-' . $service['vpnid'] . '" >';
563
				break;
564
			case "captiveportal":
565
				$output .= '<a href="#" id="captiveportal-restartservice-' . $service['zone'] . '">';
566
				break;
567
			default:
568
				$output .= '<a href="#" id="restartservice-' . $service['name'] . '" >';
569
		}
570

    
571
		$output .= "<i class=\"fa fa-repeat\" title=\"" . sprintf(gettext("Restart %sService"), $stitle) . "\"></i></a>\n";
572

    
573
		switch ($service['name']) {
574
			case "openvpn":
575
				$output .= '<a href="#" id="openvpn-stopservice-' . $service['mode'] . '-' . $service['vpnid'] . '" >';
576
				break;
577
			case "captiveportal":
578
				$output .= '<a href="#" id="captiveportal-stopservice-' . $service['zone'] . '">';
579
				break;
580
			default:
581
				$output .= '<a href="#" id="stopservice-' . $service['name'] . '">';
582
		}
583

    
584
		$output .= "<i class=\"fa fa-stop\" title=\"" . sprintf(gettext("Stop %sService"), $stitle) . "\"></i></a>";
585

    
586
	} else {
587
		$service_enabled = is_service_enabled($service['name']);
588

    
589
		if ($service['name'] == 'openvpn' || $service['name'] == 'captiveportal' || $service_enabled) {
590
			$output .= sprintf($link, sprintf(gettext("Start %sService"), $stitle), 'startservice');
591
			$output .= '<i class="fa fa-play-circle"></i></a> ';
592
		}
593
	}
594

    
595
	return $output;
596
}
597

    
598
function service_control_start($name, $extras) {
599
	global $g;
600
	switch ($name) {
601
		case 'radvd':
602
			services_radvd_configure();
603
			break;
604
		case 'captiveportal':
605
			$zone = htmlspecialchars($extras['zone']);
606
			captiveportal_init_webgui_zonename($zone);
607
			break;
608
		case 'ntpd':
609
		case 'openntpd':
610
			system_ntp_configure();
611
			break;
612
		case 'dpinger':
613
			setup_gateways_monitor();
614
			break;
615
		case 'bsnmpd':
616
			services_snmpd_configure();
617
			break;
618
		case 'dhcrelay':
619
			services_dhcrelay_configure();
620
			break;
621
		case 'dhcrelay6':
622
			services_dhcrelay6_configure();
623
			break;
624
		case 'dnsmasq':
625
			services_dnsmasq_configure();
626
			break;
627
		case 'unbound':
628
			services_unbound_configure();
629
			break;
630
		case 'dhcpd':
631
			services_dhcpd_configure();
632
			break;
633
		case 'igmpproxy':
634
			services_igmpproxy_configure();
635
			break;
636
		case 'miniupnpd':
637
			upnp_action('start');
638
			break;
639
		case 'ipsec':
640
			vpn_ipsec_force_reload();
641
			break;
642
		case 'sshd':
643
			send_event("service restart sshd");
644
			break;
645
		case 'openvpn':
646
			$vpnmode = isset($extras['vpnmode']) ? htmlspecialchars($extras['vpnmode']) : htmlspecialchars($extras['mode']);
647
			if (($vpnmode == "server") || ($vpnmode == "client")) {
648
				$id = isset($extras['vpnid']) ? htmlspecialchars($extras['vpnid']) : htmlspecialchars($extras['id']);
649
				$configfile = "{$g['varetc_path']}/openvpn/{$vpnmode}{$id}.conf";
650
				if (file_exists($configfile)) {
651
					openvpn_restart_by_vpnid($vpnmode, $id);
652
				}
653
			}
654
			break;
655
		case 'relayd':
656
			relayd_configure();
657
			break;
658
		default:
659
			start_service($name);
660
			break;
661
	}
662
	return sprintf(gettext("%s has been started."), htmlspecialchars($name));
663
}
664
function service_control_stop($name, $extras) {
665
	global $g;
666
	switch ($name) {
667
		case 'radvd':
668
			killbypid("{$g['varrun_path']}/radvd.pid");
669
			break;
670
		case 'captiveportal':
671
			$zone = htmlspecialchars($extras['zone']);
672
			killbypid("{$g['varrun_path']}/lighty-{$zone}-CaptivePortal.pid");
673
			killbypid("{$g['varrun_path']}/lighty-{$zone}-CaptivePortal-SSL.pid");
674
			break;
675
		case 'ntpd':
676
			killbyname("ntpd");
677
			break;
678
		case 'openntpd':
679
			killbyname("openntpd");
680
			break;
681
		case 'dpinger':
682
			stop_dpinger();
683
			break;
684
		case 'bsnmpd':
685
			killbypid("{$g['varrun_path']}/snmpd.pid");
686
			break;
687
		case 'choparp':
688
			killbyname("choparp");
689
			break;
690
		case 'dhcpd':
691
			killbyname("dhcpd");
692
			break;
693
		case 'dhcrelay':
694
			killbypid("{$g['varrun_path']}/dhcrelay.pid");
695
			break;
696
		case 'dhcrelay6':
697
			killbypid("{$g['varrun_path']}/dhcrelay6.pid");
698
			break;
699
		case 'dnsmasq':
700
			killbypid("{$g['varrun_path']}/dnsmasq.pid");
701
			break;
702
		case 'unbound':
703
			killbypid("{$g['varrun_path']}/unbound.pid");
704
			break;
705
		case 'igmpproxy':
706
			killbyname("igmpproxy");
707
			break;
708
		case 'miniupnpd':
709
			upnp_action('stop');
710
			break;
711
		case 'sshd':
712
			killbyname("sshd");
713
			break;
714
		case 'ipsec':
715
			exec("/usr/local/sbin/ipsec stop");
716
			break;
717
		case 'openvpn':
718
			$vpnmode = htmlspecialchars($extras['vpnmode']);
719
			if (($vpnmode == "server") or ($vpnmode == "client")) {
720
				$id = htmlspecialchars($extras['id']);
721
				$pidfile = "{$g['varrun_path']}/openvpn_{$vpnmode}{$id}.pid";
722
				killbypid($pidfile);
723
			}
724
			break;
725
		case 'relayd':
726
			mwexec('pkill relayd');
727
			break;
728
		default:
729
			stop_service($name);
730
			break;
731
	}
732
	return sprintf(gettext("%s has been stopped."), htmlspecialchars($name));
733
}
734

    
735
function service_control_restart($name, $extras) {
736
	global $g;
737
	switch ($name) {
738
		case 'radvd':
739
			services_radvd_configure();
740
			break;
741
		case 'captiveportal':
742
			$zone = htmlspecialchars($extras['zone']);
743
			killbypid("{$g['varrun_path']}/lighty-{$zone}-CaptivePortal.pid");
744
			killbypid("{$g['varrun_path']}/lighty-{$zone}-CaptivePortal-SSL.pid");
745
			captiveportal_init_webgui_zonename($zone);
746
			break;
747
		case 'ntpd':
748
		case 'openntpd':
749
			system_ntp_configure();
750
			break;
751
		case 'dpinger':
752
			setup_gateways_monitor();
753
			break;
754
		case 'bsnmpd':
755
			services_snmpd_configure();
756
			break;
757
		case 'dhcrelay':
758
			services_dhcrelay_configure();
759
			break;
760
		case 'dhcrelay6':
761
			services_dhcrelay6_configure();
762
			break;
763
		case 'dnsmasq':
764
			services_dnsmasq_configure();
765
			break;
766
		case 'unbound':
767
			services_unbound_configure();
768
			break;
769
		case 'dhcpd':
770
			services_dhcpd_configure();
771
			break;
772
		case 'igmpproxy':
773
			services_igmpproxy_configure();
774
			break;
775
		case 'miniupnpd':
776
			upnp_action('restart');
777
			break;
778
		case 'ipsec':
779
			vpn_ipsec_force_reload();
780
			break;
781
		case 'sshd':
782
			send_event("service restart sshd");
783
			break;
784
		case 'openvpn':
785
			$vpnmode = htmlspecialchars($extras['vpnmode']);
786
			if ($vpnmode == "server" || $vpnmode == "client") {
787
				$id = htmlspecialchars($extras['id']);
788
				$configfile = "{$g['varetc_path']}/openvpn/{$vpnmode}{$id}.conf";
789
				if (file_exists($configfile)) {
790
					openvpn_restart_by_vpnid($vpnmode, $id);
791
				}
792
			}
793
			break;
794
		case 'relayd':
795
			relayd_configure(true);
796
			break;
797
		default:
798
			restart_service($name);
799
			break;
800
	}
801
	return sprintf(gettext("%s has been restarted."), htmlspecialchars($name));
802
}
803

    
804
?>
(48-48/65)