Project

General

Profile

Download (23.3 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	service-utils.inc
4

    
5
	part of pfSense (https://www.pfsense.org)
6
	Copyright (C) 2005-2006 Colin Smith (ethethlay@gmail.com)
7
	Copyright (c) 2005-2016 Electric Sheep Fencing, LLC.
8
	All rights reserved.
9

    
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12

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

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

    
21
	3. All advertising materials mentioning features or use of this software
22
	   must display the following acknowledgment:
23
	   "This product includes software developed by the pfSense Project
24
	   for use in the pfSense® software distribution. (http://www.pfsense.org/).
25

    
26
	4. The names "pfSense" and "pfSense Project" must not be used to
27
	   endorse or promote products derived from this software without
28
	   prior written permission. For written permission, please contact
29
	   coreteam@pfsense.org.
30

    
31
	5. Products derived from this software may not be called "pfSense"
32
	   nor may "pfSense" appear in their names without prior written
33
	   permission of the Electric Sheep Fencing, LLC.
34

    
35
	6. Redistributions of any form whatsoever must retain the following
36
	   acknowledgment:
37

    
38
	"This product includes software developed by the pfSense Project
39
	for use in the pfSense software distribution (http://www.pfsense.org/).
40

    
41
	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
42
	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43
	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
44
	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
45
	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46
	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
47
	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
48
	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49
	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
50
	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
52
	OF THE POSSIBILITY OF SUCH DAMAGE.
53
*/
54

    
55
require_once("globals.inc");
56
require_once("captiveportal.inc");
57
require_once("openvpn.inc");
58
require_once("ipsec.inc");
59
require_once("vpn.inc");
60
require_once("vslb.inc");
61
require_once("gwlb.inc");
62

    
63
define("RCFILEPREFIX", "/usr/local/etc/rc.d/");
64
function write_rcfile($params) {
65
	global $g;
66

    
67
	safe_mkdir(RCFILEPREFIX);
68
	$rcfile_fullname = RCFILEPREFIX . $params['file'];
69
	if (!file_exists($rcfile_fullname) && !is_link($rcfile_fullname) && !touch($rcfile_fullname)) {
70
		return false;
71
	}
72

    
73
	if (!is_writable($rcfile_fullname) || empty($params['start'])) {
74
		return false;
75
	}
76

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

    
80
	/* write our rc functions */
81
	$towrite .= "rc_start() {\n";
82
	$towrite .= "\t{$params['start']}\n";
83
	$towrite .= "}\n\n";
84
	if (!empty($params['stop'])) {
85
		$tokill =& $params['stop'];
86
	} else if (!empty($params['executable'])) {
87
		/* just nuke the executable */
88
		$tokill = "/usr/bin/killall " . escapeshellarg($params['executable']);
89
	} else {
90
		/* make an educated guess (bad) */
91
		$tokill = array_pop(explode('/', array_shift(explode(' ', $params['start']))));
92
	}
93
	$towrite .= "rc_stop() {\n";
94
	$towrite .= "\t{$tokill}\n";
95
	$towrite .= "}\n\n";
96

    
97
	/* begin rcfile logic */
98
	$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";
99

    
100
	@file_put_contents($rcfile_fullname, $towrite);
101
	unset($towrite);
102
	@chmod("{$rcfile_fullname}", 0755);
103

    
104
	return;
105
}
106

    
107
function start_service($name) {
108
	global $config;
109

    
110
	if (empty($name)) {
111
		return;
112
	}
113

    
114
	if (is_array($config['installedpackages']) && is_array($config['installedpackages']['service'])) {
115
		foreach ($config['installedpackages']['service'] as $service) {
116
			if (strtolower($service['name']) == strtolower($name)) {
117
				if ($service['rcfile']) {
118
					$prefix = RCFILEPREFIX;
119
					if (!empty($service['prefix'])) {
120
						$prefix =& $service['prefix'];
121
					}
122
					if (file_exists("{$prefix}{$service['rcfile']}") || is_link("{$prefix}{$service['rcfile']}")) {
123
						mwexec_bg("{$prefix}{$service['rcfile']} start");
124
					}
125
				}
126
				if (!empty($service['startcmd'])) {
127
					eval($service['startcmd']);
128
				}
129
				break;
130
			}
131
		}
132
	}
133
}
134

    
135
function stop_service($name) {
136
	global $config;
137

    
138
	if (empty($name)) {
139
		return;
140
	}
141

    
142
	if (is_array($config['installedpackages']) && is_array($config['installedpackages']['service'])) {
143
		foreach ($config['installedpackages']['service'] as $service) {
144
			if (strtolower($service['name']) == strtolower($name)) {
145
				if ($service['rcfile']) {
146
					$prefix = RCFILEPREFIX;
147
					if (!empty($service['prefix'])) {
148
						$prefix =& $service['prefix'];
149
					}
150
					if (file_exists("{$prefix}{$service['rcfile']}") || is_link("{$prefix}{$service['rcfile']}")) {
151
						mwexec("{$prefix}{$service['rcfile']} stop");
152
					}
153
					return;
154
				}
155
				if (!empty($service['stopcmd'])) {
156
					eval($service['stopcmd']);
157
				} elseif (!empty($service['executable'])) {
158
					mwexec("/usr/bin/killall " . escapeshellarg($service['executable']));
159
				}
160

    
161
				break;
162
			}
163
		}
164
	}
165
}
166

    
167
function restart_service($name) {
168
	global $config;
169

    
170
	if (empty($name)) {
171
		return;
172
	}
173

    
174
	if (is_service_running($name)) {
175
		stop_service($name);
176
	}
177
	start_service($name);
178

    
179
	if (is_array($config['installedpackages']) && is_array($config['installedpackages']['service'])) {
180
		foreach ($config['installedpackages']['service'] as $service) {
181
			if (strtolower($service['name']) == strtolower($name)) {
182
				if ($service['restartcmd']) {
183
					eval($service['restartcmd']);
184
				}
185
				break;
186
			}
187
		}
188
	}
189
}
190

    
191
function is_pid_running($pidfile) {
192
	if (!file_exists($pidfile)) {
193
		return false;
194
	}
195

    
196
	return (isvalidpid($pidfile));
197
}
198

    
199
function is_dhcp_running($interface) {
200
	$status = find_dhclient_process($interface);
201
	if ($status != 0) {
202
		return true;
203
	}
204
	return false;
205
}
206

    
207
function restart_service_if_running($service) {
208
	global $config;
209
	if (is_service_running($service)) {
210
		restart_service($service);
211
	}
212
	return;
213
}
214

    
215
function is_service_enabled($service_name) {
216
	global $config;
217
	if ($service_name == "") {
218
		return false;
219
	}
220
	if (is_array($config['installedpackages'])) {
221
		if (isset($config['installedpackages'][$service_name]['config'][0]['enable']) &&
222
		    ((empty($config['installedpackages'][$service_name]['config'][0]['enable'])) ||
223
		    ($config['installedpackages'][$service_name]['config'][0]['enable'] === 'off'))) {
224
			return false;
225
		}
226
	}
227
	return true;
228
}
229

    
230
function is_service_running($service, $ps = "") {
231
	global $config;
232

    
233
	if (is_array($config['installedpackages']['service'])) {
234
		foreach ($config['installedpackages']['service'] as $aservice) {
235
			if (strtolower($service) == strtolower($aservice['name'])) {
236
				if ($aservice['custom_php_service_status_command'] <> "") {
237
					eval("\$rc={$aservice['custom_php_service_status_command']};");
238
					return $rc;
239
				}
240
				if (empty($aservice['executable'])) {
241
					return false;
242
				}
243
				if (is_process_running($aservice['executable'])) {
244
					return true;
245
				}
246

    
247
				return false;
248
			}
249
		}
250
	}
251

    
252
	if (is_process_running($service)) {
253
		return true;
254
	}
255

    
256
	return false;
257
}
258

    
259
function get_services() {
260
	global $config;
261
	if (is_array($config['installedpackages']['service'])) {
262
		$services = $config['installedpackages']['service'];
263
	} else {
264
		$services = array();
265
	}
266

    
267
	/*
268
	 * Add services that are in the base.
269
	 */
270
	if (is_radvd_enabled()) {
271
		$pconfig = array();
272
		$pconfig['name'] = "radvd";
273
		$pconfig['description'] = gettext("Router Advertisement Daemon");
274
		$services[] = $pconfig;
275
	}
276

    
277
	if (isset($config['dnsmasq']['enable'])) {
278
		$pconfig = array();
279
		$pconfig['name'] = "dnsmasq";
280
		$pconfig['description'] = gettext("DNS Forwarder");
281
		$services[] = $pconfig;
282
	}
283

    
284
	if (isset($config['unbound']['enable'])) {
285
		$pconfig = array();
286
		$pconfig['name'] = "unbound";
287
		$pconfig['description'] = gettext("DNS Resolver");
288
		$services[] = $pconfig;
289
	}
290

    
291
	$pconfig = array();
292
	$pconfig['name'] = "ntpd";
293
	$pconfig['description'] = gettext("NTP clock sync");
294
	$services[] = $pconfig;
295

    
296
	if (is_array($config['captiveportal'])) {
297
		foreach ($config['captiveportal'] as $zone => $setting) {
298
			if (isset($setting['enable'])) {
299
				$pconfig = array();
300
				$pconfig['name'] = "captiveportal";
301
				$pconfig['zone'] = $zone;
302
				$pconfig['description'] = gettext("Captive Portal") . ": ".htmlspecialchars($setting['zone']);
303
				$services[] = $pconfig;
304
			}
305
		}
306
	}
307

    
308
	$iflist = array();
309
	$ifdescrs = get_configured_interface_list();
310
	foreach ($ifdescrs as $if) {
311
		$oc = $config['interfaces'][$if];
312
		if ($oc['if'] && (!link_interface_to_bridge($if))) {
313
			$iflist[$if] = $if;
314
		}
315
	}
316

    
317
	if (isset($config['dhcrelay']['enable'])) {
318
		$pconfig = array();
319
		$pconfig['name'] = "dhcrelay";
320
		$pconfig['description'] = gettext("DHCP Relay");
321
		$services[] = $pconfig;
322
	}
323

    
324
	if (isset($config['dhcrelay6']['enable'])) {
325
		$pconfig = array();
326
		$pconfig['name'] = "dhcrelay6";
327
		$pconfig['description'] = gettext("DHCPv6 Relay");
328
		$services[] = $pconfig;
329
	}
330

    
331
	if (is_dhcp_server_enabled()) {
332
		$pconfig = array();
333
		$pconfig['name'] = "dhcpd";
334
		$pconfig['description'] = gettext("DHCP Service");
335
		$services[] = $pconfig;
336
	}
337

    
338
	$gateways_arr = return_gateways_array();
339
	if (is_array($gateways_arr)) {
340
		$pconfig = array();
341
		$pconfig['name'] = "dpinger";
342
		$pconfig['description'] = gettext("Gateway Monitoring Daemon");
343
		$services[] = $pconfig;
344
	}
345

    
346
	if (isset($config['snmpd']['enable'])) {
347
		$pconfig = array();
348
		$pconfig['name'] = "bsnmpd";
349
		$pconfig['description'] = gettext("SNMP Service");
350
		$services[] = $pconfig;
351
	}
352

    
353
	if (is_array($config['igmpproxy']['igmpentry']) && (count($config['igmpproxy']['igmpentry']) > 0)) {
354
		$pconfig = array();
355
		$pconfig['name'] = "igmpproxy";
356
		$pconfig['description'] = gettext("IGMP proxy");
357
		$services[] = $pconfig;
358
	}
359

    
360
	if (isset($config['installedpackages']['miniupnpd']) && $config['installedpackages']['miniupnpd']['config'][0]['enable']) {
361
		$pconfig = array();
362
		$pconfig['name'] = "miniupnpd";
363
		$pconfig['description'] = gettext("UPnP Service");
364
		$services[] = $pconfig;
365
	}
366

    
367
	if (ipsec_enabled()) {
368
		$pconfig = array();
369
		$pconfig['name'] = "ipsec";
370
		$pconfig['description'] = gettext("IPsec VPN");
371
		$services[] = $pconfig;
372
	}
373

    
374
	if (isset($config['system']['enablesshd'])) {
375
		$pconfig = array();
376
		$pconfig['name'] = "sshd";
377
		$pconfig['description'] = gettext("Secure Shell Daemon");
378
		$services[] = $pconfig;
379
	}
380

    
381
	foreach (array('server', 'client') as $mode) {
382
		if (is_array($config['openvpn']["openvpn-{$mode}"])) {
383
			foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) {
384
				if (!isset($setting['disable'])) {
385
					$pconfig = array();
386
					$pconfig['name'] = "openvpn";
387
					$pconfig['mode'] = $mode;
388
					$pconfig['id'] = $id;
389
					$pconfig['vpnid'] = $setting['vpnid'];
390
					$pconfig['description'] = gettext("OpenVPN") . " ".$mode.": ".htmlspecialchars($setting['description']);
391
					$services[] = $pconfig;
392
				}
393
			}
394
		}
395
	}
396

    
397
	if (count($config['load_balancer']['virtual_server']) && count($config['load_balancer']['lbpool'])) {
398
		$pconfig = array();
399
		$pconfig['name'] = "relayd";
400
		$pconfig['description'] = gettext("Server load balancing daemon");
401
		$services[] = $pconfig;
402
	}
403
	return $services;
404
}
405

    
406
function find_service_by_name($name) {
407
	$services = get_services();
408
	foreach ($services as $service) {
409
		if ($service["name"] == $name) {
410
			return $service;
411
		}
412
	}
413
	return array();
414
}
415

    
416
function find_service_by_openvpn_vpnid($vpnid) {
417
	$services = get_services();
418
	foreach ($services as $service) {
419
		if (($service["name"] == "openvpn") && isset($service["vpnid"]) && ($service["vpnid"] == $vpnid)) {
420
			return $service;
421
		}
422
	}
423
	return array();
424
}
425

    
426
function find_service_by_cp_zone($zone) {
427
	$services = get_services();
428
	foreach ($services as $service) {
429
		if (($service["name"] == "captiveportal") && isset($service["zone"]) && ($service["zone"] == $zone)) {
430
			return $service;
431
		}
432
	}
433
	return array();
434
}
435

    
436
function service_name_compare($a, $b) {
437
	if (strtolower($a['name']) == strtolower($b['name'])) {
438
		return 0;
439
	}
440
	return (strtolower($a['name']) < strtolower($b['name'])) ? -1 : 1;
441
}
442

    
443
function get_pkg_descr($package_name) {
444
	global $config;
445
	if (is_array($config['installedpackages']['package'])) {
446
		foreach ($config['installedpackages']['package'] as $pkg) {
447
			if ($pkg['name'] == $package_name) {
448
				return $pkg['descr'];
449
			}
450
		}
451
	}
452
	return gettext("Not available.");
453
}
454

    
455
function get_service_status($service) {
456
	global $g;
457
	switch ($service['name']) {
458
		case "openvpn":
459
			$running = is_pid_running("{$g['varrun_path']}/openvpn_{$service['mode']}{$service['vpnid']}.pid");
460
			break;
461
		case "captiveportal":
462
			$running = is_pid_running("{$g['varrun_path']}/nginx-{$service['zone']}-CaptivePortal.pid");
463
			if (isset($config['captiveportal'][$service['zone']]['httpslogin'])) {
464
				$running = $running && is_pid_running("{$g['varrun_path']}/nginx-{$service['zone']}-CaptivePortal-SSL.pid");
465
			}
466
			break;
467
		case "vhosts-http":
468
			$running = is_pid_running("{$g['varrun_path']}/vhosts-http.pid");
469
			break;
470
		case "dhcrelay6":
471
			$running = is_pid_running("{$g['varrun_path']}/dhcrelay6.pid");
472
			break;
473
		case 'ipsec':
474
			$running = is_pid_running("{$g['varrun_path']}/charon.pid");
475
			break;
476
		default:
477
			$running = is_service_running($service['name']);
478
	}
479
	return $running;
480
}
481

    
482
function get_service_status_icon($service, $withtext = true, $smallicon = false) {
483
	global $g;
484
	$output = "";
485
	if (get_service_status($service)) {
486
		$statustext = gettext("Running");
487
		$output .= "<a title=\"" . sprintf(gettext("%s Service is"), $service["name"]) . " {$statustext}\" ><i class=\"";
488
		$output .= ($smallicon) ? "fa fa-play" : "fa fa-lg fa-play";
489
		$output .= "\" ></i></a>";
490
		if ($withtext) {
491
			$output .= "&nbsp;" . $statustext;
492
		}
493
	} else {
494
		$service_enabled = is_service_enabled($service['name']);
495
		$statustext = ($service_enabled) ? gettext("Stopped") : gettext("Disabled");
496
		$output .= "<a title=\"" . sprintf(gettext("%s Service is"), $service["name"]) . " {$statustext}\" ><i class=\"";
497
		$output .= ($smallicon) ? "fa fa-times" : "fa fa-lg fa-times";
498
		$output .= "\" ></i></a>";
499
		if ($withtext) {
500
			$output .= "&nbsp;" . $statustext;
501
		}
502
	}
503
	return $output;
504
}
505

    
506

    
507
// This version proved GET formatted links
508
function get_service_control_GET_links($service, $addname = false) {
509
	global $g;
510
	$output = "";
511
	$stitle = ($addname) ? $service['name'] . " " : "";
512

    
513
	switch ($service['name']) {
514
		case "openvpn":
515
			$link = '<a title="%s" href="status_services.php?mode=%s&amp;service='.$service['name'] . '&amp;vpnmode=' . $service['mode'] . '&amp;id=' . $service['vpnid'] . '">';
516
		break;
517
		case "captiveportal":
518
			$link = '<a title="%s" href="status_services.php?mode=%s&amp;service=' . $service['name'] . '&amp;zone=' . $service['zone'] . '">';
519
		break;
520
		default:
521
			$link = '<a title="%s" href="/status_services.php?mode=%s&amp;service=' . $service['name'] . '">';
522
	}
523

    
524
	if (get_service_status($service)) {
525
		switch ($service['name']) {
526
			case "openvpn":
527
				$output .= "<a href=\"status_services.php?mode=restartservice&amp;service={$service['name']}&amp;vpnmode={$service['mode']}&amp;id={$service['vpnid']}\">";
528
				break;
529
			case "captiveportal":
530
				$output .= "<a href=\"status_services.php?mode=restartservice&amp;service={$service['name']}&amp;zone={$service['zone']}\">";
531
				break;
532
			default:
533
				$output .= "<a href=\"/status_services.php?mode=restartservice&amp;service={$service['name']}\">";
534
		}
535
		$output .= "<i class=\"fa fa-repeat\" title=\"" . sprintf(gettext("Restart %sService"), $stitle) . "\"></i></a>\n";
536
		switch ($service['name']) {
537
			case "openvpn":
538
				$output .= "<a href=\"status_services.php?mode=stopservice&amp;service={$service['name']}&amp;vpnmode={$service['mode']}&amp;id={$service['vpnid']}\">";
539
				break;
540
			case "captiveportal":
541
				$output .= "<a href=\"status_services.php?mode=stopservice&amp;service={$service['name']}&amp;zone={$service['zone']}\">";
542
				break;
543
			default:
544
				$output .= "<a href=\"/status_services.php?mode=stopservice&amp;service={$service['name']}\">";
545
		}
546
		$output .= "<i class=\"fa fa-stop-circle-o\" title=\"" . sprintf(gettext("Stop %sService"), $stitle) . "\"></i></a>";
547
	} else {
548
		$service_enabled = is_service_enabled($service['name']);
549

    
550
		if ($service['name'] == 'openvpn' || $service['name'] == 'captiveportal' || $service_enabled) {
551
			$output .= sprintf($link, sprintf(gettext("Start %sService"), $stitle), 'startservice');
552
			$output .= '<i class="fa fa-play-circle"></i></a> ';
553
		}
554
	}
555

    
556
	return $output;
557
}
558

    
559
function get_service_control_links($service, $addname = false) {
560
	global $g;
561
	$output = "";
562
	$stitle = ($addname) ? $service['name'] . " " : "";
563

    
564
	switch ($service['name']) {
565
		case "openvpn":
566
			$link = '<a title="%s" href="#" id="openvpn-%s-' . $service['mode'] . '-' . $service['vpnid'] . '" >';
567
		break;
568
		case "captiveportal":
569
			$link = '<a title="%s" href="#" id="captiveportal-%s-' . $service['zone'] . '">';
570
		break;
571
		default:
572
			$link = '<a title="%s" href="#" id="%s-' . $service['name'] . '">';
573
	}
574

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

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

    
589
		switch ($service['name']) {
590
			case "openvpn":
591
				$output .= '<a href="#" id="openvpn-stopservice-' . $service['mode'] . '-' . $service['vpnid'] . '" >';
592
				break;
593
			case "captiveportal":
594
				$output .= '<a href="#" id="captiveportal-stopservice-' . $service['zone'] . '">';
595
				break;
596
			default:
597
				$output .= '<a href="#" id="stopservice-' . $service['name'] . '">';
598
		}
599

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

    
602
	} else {
603
		$service_enabled = is_service_enabled($service['name']);
604

    
605
		if ($service['name'] == 'openvpn' || $service['name'] == 'captiveportal' || $service_enabled) {
606
			$output .= sprintf($link, sprintf(gettext("Start %sService"), $stitle), 'startservice');
607
			$output .= '<i class="fa fa-play-circle"></i></a> ';
608
		}
609
	}
610

    
611
	return $output;
612
}
613

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

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

    
820
?>
(48-48/65)