Project

General

Profile

Download (23.5 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 service_dispname_compare($a, $b) {
444
	if (strtolower($a['dispname']) == strtolower($b['dispname'])) {
445
		return 0;
446
	}
447
	return (strtolower($a['name']) < strtolower($b['name'])) ? -1 : 1;
448
}
449

    
450
function get_pkg_descr($package_name) {
451
	global $config;
452
	if (is_array($config['installedpackages']['package'])) {
453
		foreach ($config['installedpackages']['package'] as $pkg) {
454
			if ($pkg['name'] == $package_name) {
455
				return $pkg['descr'];
456
			}
457
		}
458
	}
459
	return gettext("Not available.");
460
}
461

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

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

    
513

    
514
// This version proved GET formatted links
515
function get_service_control_GET_links($service, $addname = false) {
516
	global $g;
517
	$output = "";
518
	$stitle = ($addname) ? $service['name'] . " " : "";
519

    
520
	switch ($service['name']) {
521
		case "openvpn":
522
			$link = '<a title="%s" href="status_services.php?mode=%s&amp;service='.$service['name'] . '&amp;vpnmode=' . $service['mode'] . '&amp;id=' . $service['vpnid'] . '">';
523
		break;
524
		case "captiveportal":
525
			$link = '<a title="%s" href="status_services.php?mode=%s&amp;service=' . $service['name'] . '&amp;zone=' . $service['zone'] . '">';
526
		break;
527
		default:
528
			$link = '<a title="%s" href="/status_services.php?mode=%s&amp;service=' . $service['name'] . '">';
529
	}
530

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

    
557
		if ($service['name'] == 'openvpn' || $service['name'] == 'captiveportal' || $service_enabled) {
558
			$output .= sprintf($link, sprintf(gettext("Start %sService"), $stitle), 'startservice');
559
			$output .= '<i class="fa fa-play-circle"></i></a> ';
560
		}
561
	}
562

    
563
	return $output;
564
}
565

    
566
function get_service_control_links($service, $addname = false) {
567
	global $g;
568
	$output = "";
569
	$stitle = ($addname) ? $service['name'] . " " : "";
570

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

    
582
	if (get_service_status($service)) {
583
		switch ($service['name']) {
584
			case "openvpn":
585
				$output .= '<a href="#" id="openvpn-restartservice-' . $service['mode'] . '-' . $service['vpnid'] . '" >';
586
				break;
587
			case "captiveportal":
588
				$output .= '<a href="#" id="captiveportal-restartservice-' . $service['zone'] . '">';
589
				break;
590
			default:
591
				$output .= '<a href="#" id="restartservice-' . $service['name'] . '" >';
592
		}
593

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

    
596
		switch ($service['name']) {
597
			case "openvpn":
598
				$output .= '<a href="#" id="openvpn-stopservice-' . $service['mode'] . '-' . $service['vpnid'] . '" >';
599
				break;
600
			case "captiveportal":
601
				$output .= '<a href="#" id="captiveportal-stopservice-' . $service['zone'] . '">';
602
				break;
603
			default:
604
				$output .= '<a href="#" id="stopservice-' . $service['name'] . '">';
605
		}
606

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

    
609
	} else {
610
		$service_enabled = is_service_enabled($service['name']);
611

    
612
		if ($service['name'] == 'openvpn' || $service['name'] == 'captiveportal' || $service_enabled) {
613
			$output .= sprintf($link, sprintf(gettext("Start %sService"), $stitle), 'startservice');
614
			$output .= '<i class="fa fa-play-circle"></i></a> ';
615
		}
616
	}
617

    
618
	return $output;
619
}
620

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

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

    
827
?>
(48-48/65)