Project

General

Profile

Download (11.7 KB) Statistics
| Branch: | Tag: | Revision:
1 a0e4cea2 Scott Ullrich
<?php
2
/*
3 ef09107d Colin Smith
    services_status.php
4
    Copyright (C) 2004, 2005 Scott Ullrich
5 a0e4cea2 Scott Ullrich
    All rights reserved.
6
7
    Redistribution and use in source and binary forms, with or without
8
    modification, are permitted provided that the following conditions are met:
9
10
    1. Redistributions of source code must retain the above copyright notice,
11
       this list of conditions and the following disclaimer.
12
13
    2. Redistributions in binary form must reproduce the above copyright
14
       notice, this list of conditions and the following disclaimer in the
15
       documentation and/or other materials provided with the distribution.
16
17
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 ef09107d Colin Smith
    INClUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19 a0e4cea2 Scott Ullrich
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
    POSSIBILITY OF SUCH DAMAGE.
27
*/
28 1d333258 Scott Ullrich
/*	
29
	pfSense_BUILDER_BINARIES:	/usr/local/sbin/openvpn	/usr/bin/killall	/bin/ps
30
	pfSense_MODULE:	services
31
*/
32 a0e4cea2 Scott Ullrich
33 6b07c15a Matthew Grooms
##|+PRIV
34
##|*IDENT=page-status-services
35
##|*NAME=Status: Services page
36
##|*DESCR=Allow access to the 'Status: Services' page.
37
##|*MATCH=status_services.php*
38
##|-PRIV
39
40 e3c88b77 Ermal
require_once("guiconfig.inc");
41 01d4b621 Ermal
require_once("captiveportal.inc");
42 44173def Ermal Lu?i
require_once("service-utils.inc");
43 9a76a52a Ermal Lu?i
require_once("ipsec.inc");
44 1ac7a864 Chris Buechler
require_once("vpn.inc");
45 a0e4cea2 Scott Ullrich
46
function gentitle_pkg($pgname) {
47
	global $config;
48
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
49
}
50
51 5d8bcb27 Scott Ullrich
function get_pkg_descr($package_name) {
52
	global $config;
53 c9359d05 Ermal Lu?i
	if (is_array($config['installedpackages']['package'])) {
54
		foreach($config['installedpackages']['package'] as $pkg) {
55
			if($pkg['name'] == $package_name)
56
				return $pkg['descr'];
57
		}
58 5d8bcb27 Scott Ullrich
	}
59 7f6ea91f Carlos Eduardo Ramos
	return gettext("Not available.");
60 5d8bcb27 Scott Ullrich
}
61
62 246a887a Ermal
if($_GET['mode'] == "restartservice" and !empty($_GET['service'])) {
63 6c3e2b19 Scott Ullrich
	switch($_GET['service']) {
64 01d4b621 Ermal
		case 'captiveportal':
65
			killbypid("{$g['varrun_path']}/lighty-CaptivePortal.pid");
66
			captiveportal_init_webgui();
67
			break;
68 96155ce4 Scott Ullrich
		case 'ntpd':
69 c8960970 Ermal
		case 'openntpd':
70 96155ce4 Scott Ullrich
			system_ntp_configure();
71
			break;
72 6c3e2b19 Scott Ullrich
		case 'bsnmpd':
73
			services_snmpd_configure();
74
			break;
75
		case 'dnsmasq':
76
			services_dnsmasq_configure();
77
			break;
78
		case 'dhcpd':
79
			services_dhcpd_configure();
80 422e039b Scott Ullrich
			break;
81 41997fbb Ermal Luci
		case 'igmpproxy':
82
			services_igmpproxy_configure();
83
			break;
84 422e039b Scott Ullrich
		case 'miniupnpd':
85 431484c8 Ryan Wagoner
			upnp_action('restart');	
86 6c3e2b19 Scott Ullrich
			break;
87 cd72ded3 Timo Boettcher
		case 'racoon':
88
			vpn_ipsec_force_reload();
89
			break;
90
		case 'openvpn':         
91
			$vpnmode = $_GET['vpnmode'];
92 0349e09d Ermal
			if ($vpnmode == "server" || $vpnmode == "client") {
93 cd72ded3 Timo Boettcher
				$id = $_GET['id'];
94 45611d02 Ermal
				$configfile = "{$g['varetc_path']}/openvpn/{$vpnmode}{$id}.conf";
95
				$pidfile = $g['varrun_path'] . "/openvpn_{$vpnmode}{$id}.pid";
96
				if (file_exists($configfile)) {
97 cd72ded3 Timo Boettcher
					killbypid($pidfile);
98
					sleep(1);
99 45611d02 Ermal
					mwexec_bg("/usr/local/sbin/openvpn --config {$configfile}");
100 cd72ded3 Timo Boettcher
				}
101
			}
102
			break;
103 6c3e2b19 Scott Ullrich
		default:
104
			restart_service($_GET['service']);
105
			break;
106
	}
107 daab67a1 Scott Ullrich
	$savemsg = sprintf(gettext("%s has been restarted."),htmlspecialchars($_GET['service']));
108 422e039b Scott Ullrich
	sleep(5);
109 a0e4cea2 Scott Ullrich
}
110
111 246a887a Ermal
if($_GET['mode'] == "startservice" and !empty($_GET['service'])) {
112 3e32a807 Scott Ullrich
	switch($_GET['service']) {
113 01d4b621 Ermal
		case 'captiveportal':
114
			captiveportal_init_webgui();
115
			break;
116 96155ce4 Scott Ullrich
		case 'ntpd':
117 c8960970 Ermal
		case 'openntpd':
118 96155ce4 Scott Ullrich
			system_ntp_configure();
119
			break;		
120 3e32a807 Scott Ullrich
		case 'bsnmpd':
121 3af54e48 Scott Ullrich
			services_snmpd_configure();
122 3e32a807 Scott Ullrich
			break;
123
		case 'dnsmasq':
124
			services_dnsmasq_configure();
125
			break;
126
		case 'dhcpd':
127
			services_dhcpd_configure();
128 422e039b Scott Ullrich
			break;
129 41997fbb Ermal Luci
		case 'igmpproxy':
130
			services_igmpproxy_configure();
131
			break;
132 422e039b Scott Ullrich
		case 'miniupnpd':
133 431484c8 Ryan Wagoner
			upnp_action('start');
134 3e32a807 Scott Ullrich
			break;
135 cd72ded3 Timo Boettcher
		case 'racoon':
136
			vpn_ipsec_force_reload();
137
			break;
138
		case 'openvpn':
139
			$vpnmode = $_GET['vpnmode'];
140 aa79a721 Ermal
			if (($vpnmode == "server") || ($vpnmode == "client")) {
141 cd72ded3 Timo Boettcher
				$id = $_GET['id'];
142 45611d02 Ermal
				$configfile = "{$g['varetc_path']}/openvpn/{$vpnmode}{$id}.conf";
143
				if (file_exists($configfile))
144 aa79a721 Ermal
					mwexec_bg("/usr/local/sbin/openvpn --config {$configfile}");
145 cd72ded3 Timo Boettcher
			}
146
			break;
147 3e32a807 Scott Ullrich
		default:
148
			start_service($_GET['service']);
149
			break;
150
	}
151 daab67a1 Scott Ullrich
	$savemsg = sprintf(gettext("%s has been started."),htmlspecialchars($_GET['service']));
152 422e039b Scott Ullrich
	sleep(5);
153 a0e4cea2 Scott Ullrich
}
154
155 25b66ec5 Scott Ullrich
/* stop service */
156 246a887a Ermal
if($_GET['mode'] == "stopservice" && !empty($_GET['service'])) {
157 422e039b Scott Ullrich
	switch($_GET['service']) {
158 01d4b621 Ermal
		case 'captiveportal':
159
			killbypid("{$g['varrun_path']}/lighty-CaptivePortal.pid");
160
			break;
161 96155ce4 Scott Ullrich
		case 'ntpd':
162
			killbyname("ntpd");
163
			break;		
164 c8960970 Ermal
		case 'openntpd':
165
			killbyname("openntpd");
166
			break;
167 25b66ec5 Scott Ullrich
		case 'bsnmpd':
168
			killbypid("{$g['varrun_path']}/snmpd.pid");
169
			break;
170
		case 'choparp':
171
			killbyname("choparp");
172
			break;
173 cd72ded3 Timo Boettcher
		case 'dhcpd':
174 25b66ec5 Scott Ullrich
			killbyname("dhcpd");
175 cd72ded3 Timo Boettcher
			break;
176
		case 'dhcrelay':
177
			killbypid("{$g['varrun_path']}/dhcrelay.pid");
178
			break;
179
		case 'dnsmasq':
180 25b66ec5 Scott Ullrich
			killbypid("{$g['varrun_path']}/dnsmasq.pid");
181
			break;
182 41997fbb Ermal Luci
		case 'igmpproxy':
183
			killbyname("igmpproxy");
184
			break;
185 422e039b Scott Ullrich
		case 'miniupnpd':
186 431484c8 Ryan Wagoner
			upnp_action('stop');
187 25b66ec5 Scott Ullrich
			break;
188 cd72ded3 Timo Boettcher
		case 'sshd':
189 25b66ec5 Scott Ullrich
			killbyname("sshd");
190 cd72ded3 Timo Boettcher
			break;
191
		case 'racoon':
192
			exec("killall -9 racoon");
193
			break;
194
		case 'openvpn':         
195
			$vpnmode = $_GET['vpnmode'];
196
			if (($vpnmode == "server") or ($vpnmode == "client")) {
197
				$id = $_GET['id'];
198 45611d02 Ermal
				$pidfile = "{$g['varrun_path']}/openvpn_{$vpnmode}{$id}.pid";
199
				killbypid($pidfile);
200 cd72ded3 Timo Boettcher
			}
201
			break;
202 422e039b Scott Ullrich
		default:
203 cd72ded3 Timo Boettcher
			stop_service($_GET['service']);
204 422e039b Scott Ullrich
			break;
205
	}
206 daab67a1 Scott Ullrich
	$savemsg = sprintf(gettext("%s has been stopped."), htmlspecialchars($_GET['service']));
207 cd72ded3 Timo Boettcher
	sleep(5);
208 a0e4cea2 Scott Ullrich
}
209
210
/* batch mode, allow other scripts to call this script */
211 246a887a Ermal
if($_GET['batch'])
212
	exit;
213 b9eadc0c Colin Smith
214 7f6ea91f Carlos Eduardo Ramos
$pgtitle = array(gettext("Status"),gettext("Services"));
215 4df96eff Scott Ullrich
include("head.inc");
216
217 a0e4cea2 Scott Ullrich
?>
218
219
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
220
<?php
221
include("fbegin.inc");
222
?>
223
<form action="status_services.php" method="post">
224
<?php if ($savemsg) print_info_box($savemsg); ?>
225
226
<p>
227
228 0f10aee4 Bill Marquette
<div id="boxarea">
229 3473bb6a Scott Ullrich
<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
230 a0995b8d jim-p
	<thead>
231 a9bc3b82 Scott Ullrich
	<tr>
232 a0995b8d jim-p
		<td class="listhdrr" align="center"><?=gettext("Service");?></td>
233
		<td class="listhdrr" align="center"><?=gettext("Description");?></td>
234
		<td class="listhdrr" align="center"><?=gettext("Status");?></td>
235 a9bc3b82 Scott Ullrich
	</tr>
236 a0995b8d jim-p
	</thead>
237
	<tbody>
238 a0e4cea2 Scott Ullrich
<?php
239
240 9eda7259 Ermal
if (is_array($config['installedpackages']['service']))
241
	$services = $config['installedpackages']['service'];
242
else
243
	$services = array();
244 25d3fbd5 Scott Ullrich
245
/*    Add services that are in the base.
246
 *
247
 */
248
if(isset($config['dnsmasq']['enable'])) {
249 246a887a Ermal
	$pconfig = array();
250 25d3fbd5 Scott Ullrich
	$pconfig['name'] = "dnsmasq";
251 e1953c3f Rafael Lucas
	$pconfig['description'] = gettext("DNS Forwarder");
252 25d3fbd5 Scott Ullrich
	$services[] = $pconfig;
253
}
254
255 246a887a Ermal
$pconfig = array();
256 f4c155cd Scott Ullrich
$pconfig['name'] = "ntpd";
257 e1953c3f Rafael Lucas
$pconfig['description'] = gettext("NTP clock sync");
258 9e226d16 Scott Ullrich
$services[] = $pconfig;
259
260 25d3fbd5 Scott Ullrich
if(isset($config['captiveportal']['enable'])) {
261 246a887a Ermal
	$pconfig = array();
262 01d4b621 Ermal
	$pconfig['name'] = "captiveportal";
263 e1953c3f Rafael Lucas
	$pconfig['description'] = gettext("Captive Portal");
264 25d3fbd5 Scott Ullrich
	$services[] = $pconfig;
265
}
266
267 3e321df2 Ermal Luçi
$iflist = array();
268
$ifdescrs = get_configured_interface_list();
269
foreach ($ifdescrs as $if) {
270
	$oc = $config['interfaces'][$if];
271 7ec05d27 Ermal Luçi
	if ($oc['if'] && (!link_interface_to_bridge($if)))
272 3e321df2 Ermal Luçi
		$iflist[$if] = $if;
273 51bb9b94 Scott Ullrich
}
274
$show_dhcprelay = false;
275
foreach($iflist as $if) {
276
	if(isset($config['dhcrelay'][$if]['enable']))
277
		$show_dhcprelay = true;
278
}
279
280
if($show_dhcprelay == true) {
281 246a887a Ermal
	$pconfig = array();
282 c214e575 Scott Ullrich
	$pconfig['name'] = "dhcrelay";
283 e1953c3f Rafael Lucas
	$pconfig['description'] = gettext("DHCP Relay");
284 25d3fbd5 Scott Ullrich
	$services[] = $pconfig;
285
}
286
287 3af54e48 Scott Ullrich
if(is_dhcp_server_enabled()) {
288 246a887a Ermal
	$pconfig = array();
289 25d3fbd5 Scott Ullrich
	$pconfig['name'] = "dhcpd";
290 e1953c3f Rafael Lucas
	$pconfig['description'] = gettext("DHCP Service");
291 25d3fbd5 Scott Ullrich
	$services[] = $pconfig;
292
}
293
294
if(isset($config['snmpd']['enable'])) {
295 246a887a Ermal
	$pconfig = array();
296 25d3fbd5 Scott Ullrich
	$pconfig['name'] = "bsnmpd";
297 e1953c3f Rafael Lucas
	$pconfig['description'] = gettext("SNMP Service");
298 25d3fbd5 Scott Ullrich
	$services[] = $pconfig;
299
}
300
301 41997fbb Ermal Luci
if (count($config['igmpproxy']['igmpentry']) > 0) {
302 246a887a Ermal
	$pconfig = array();
303 41997fbb Ermal Luci
	$pconfig['name'] = "igmpproxy";
304 e1953c3f Rafael Lucas
	$pconfig['descritption'] = gettext("IGMP proxy");
305 41997fbb Ermal Luci
	$services[] = $pconfig;
306
}
307
308 422e039b Scott Ullrich
if($config['installedpackages']['miniupnpd']['config'][0]['enable']) {
309 246a887a Ermal
	$pconfig = array();
310 cd72ded3 Timo Boettcher
	$pconfig['name'] = "miniupnpd";
311
	$pconfig['description'] = gettext("UPnP Service");
312
	$services[] = $pconfig;
313 422e039b Scott Ullrich
}
314
315 25b66ec5 Scott Ullrich
if (isset($config['ipsec']['enable'])) {
316 246a887a Ermal
	$pconfig = array();
317 cd72ded3 Timo Boettcher
	$pconfig['name'] = "racoon";
318 0f266b2e Chris Buechler
	$pconfig['description'] = gettext("IPsec VPN");
319 cd72ded3 Timo Boettcher
	$services[] = $pconfig;
320 25b66ec5 Scott Ullrich
}
321
322 cd72ded3 Timo Boettcher
foreach (array('server', 'client') as $mode) {
323 246a887a Ermal
	if (is_array($config['openvpn']["openvpn-{$mode}"])) {
324 c8960970 Ermal
		foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) {
325 246a887a Ermal
			if (!isset($setting['disable'])) {
326
				$pconfig = array();
327 cd72ded3 Timo Boettcher
				$pconfig['name'] = "openvpn";
328
				$pconfig['mode'] = $mode;
329
				$pconfig['id'] = $id;
330 22d323b3 Erik Fonnesbeck
				$pconfig['vpnid'] = $setting['vpnid'];
331 7f6ea91f Carlos Eduardo Ramos
				$pconfig['description'] = gettext("OpenVPN") . " ".$mode.": ".htmlspecialchars($setting['description']);
332 cd72ded3 Timo Boettcher
				$services[] = $pconfig;
333
			}
334
		}
335
	}
336
}
337 b2254c7f jim-p
338
function service_name_compare($a, $b) {
339
	if (strtolower($a['name']) == strtolower($b['name']))
340
		return 0;
341
	return (strtolower($a['name']) < strtolower($b['name'])) ? -1 : 1;
342
}
343
344 246a887a Ermal
if (count($services) > 0) {
345 b2254c7f jim-p
	uasort($services, "service_name_compare");
346 25d3fbd5 Scott Ullrich
	foreach($services as $service) {
347 246a887a Ermal
		if (empty($service['name']))
348
			continue;
349
		if (empty($service['description']))
350
			$service['description'] = get_pkg_descr($service['name']);
351 a0995b8d jim-p
		echo '<tr><td class="listlr">' . $service['name'] . '</td>' . "\n";
352
		echo '<td class="listr">' . $service['description'] . '</td>' . "\n";
353 01d4b621 Ermal
		if ($service['name'] == "openvpn")
354 246a887a Ermal
			$running = is_pid_running("{$g['varrun_path']}/openvpn_{$service['mode']}{$service['vpnid']}.pid");
355 01d4b621 Ermal
		else if ($service['name'] == "captiveportal")
356
			$running = is_pid_running("{$g['varrun_path']}/lighty-CaptivePortal.pid");
357
		else
358 9eda7259 Ermal
			$running = is_service_running($service['name']);
359 cd72ded3 Timo Boettcher
		if($running) {
360 a0995b8d jim-p
			echo '<td class="listr"><center>' . "\n";
361
			echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_pass.gif\"> " . gettext("Running") . "</td>\n";
362 b9eadc0c Colin Smith
		} else {
363 a0995b8d jim-p
			echo '<td class="listbg"><center>' . "\n";
364
			echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_block.gif\"> <font color=\"white\">" . gettext("Stopped") . "</td>\n";
365 b9eadc0c Colin Smith
		}
366 ef09107d Colin Smith
		echo '<td valign="middle" class="list" nowrap>';
367 b9eadc0c Colin Smith
		if($running) {
368 cd72ded3 Timo Boettcher
			if ($service['name'] == "openvpn") {
369 0349e09d Ermal
				echo "<a href='status_services.php?mode=restartservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['vpnid']}'>";
370 cd72ded3 Timo Boettcher
			} else {
371
				echo "<a href='status_services.php?mode=restartservice&service={$service['name']}'>";
372
			}
373 a0995b8d jim-p
			echo "<img title='" . gettext("Restart Service") . "' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_restart.gif'></a>\n";
374 cd72ded3 Timo Boettcher
			if ($service['name'] == "openvpn") {
375 0349e09d Ermal
				echo "<a href='status_services.php?mode=stopservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['vpnid']}'>";
376 cd72ded3 Timo Boettcher
			} else {
377 a0995b8d jim-p
				echo "<a href='status_services.php?mode=stopservice&service={$service['name']}'>";
378 cd72ded3 Timo Boettcher
			}
379 a0995b8d jim-p
			echo "<img title='" . gettext("Stop Service") . "' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_stop.gif'>";
380 b9eadc0c Colin Smith
			echo "</a>";
381 a0e4cea2 Scott Ullrich
		} else {
382 cd72ded3 Timo Boettcher
			if ($service['name'] == "openvpn") {
383 0349e09d Ermal
				echo "<a href='status_services.php?mode=startservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['vpnid']}'>";
384 cd72ded3 Timo Boettcher
			} else { 
385
				echo "<a href='status_services.php?mode=startservice&service={$service['name']}'> ";
386
			}
387
			
388 a0995b8d jim-p
			echo "<img title='" . gettext("Start Service") . "' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_start.gif'></a>\n";
389 a0e4cea2 Scott Ullrich
		}
390 a0995b8d jim-p
		echo "</td></tr>\n";
391 a0e4cea2 Scott Ullrich
	}
392 b9eadc0c Colin Smith
} else {
393 a0995b8d jim-p
	echo "<tr><td colspan=\"3\"><center>" . gettext("No services found") . ".</td></tr>\n";
394 b9eadc0c Colin Smith
}
395 cd72ded3 Timo Boettcher
396 a0e4cea2 Scott Ullrich
?>
397 a0995b8d jim-p
</tbody>
398 a0e4cea2 Scott Ullrich
</table>
399 12af52d9 Scott Ullrich
</div>
400 01d4b621 Ermal
</p>
401
</form>
402 a0e4cea2 Scott Ullrich
<?php include("fend.inc"); ?>
403
</body>
404
</html>