Project

General

Profile

Download (14.8 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php
2 919d91f9 Phil Davis
/*
3
	status.php
4
*/
5 5b237745 Scott Ullrich
/* Run various commands and collect their output into HTML tables.
6
 * Jim McBeath <jimmc@macrovision.com> Nov 2003
7
 *
8
 * (modified for m0n0wall by Manuel Kasper <mk@neon1.net>)
9 878f7270 Scott Ullrich
 * (modified for pfSense by Scott Ullrich geekgod@pfsense.com)
10 29aef6c4 Jim Thompson
 *
11 5b237745 Scott Ullrich
 */
12 191cb31d Stephen Beaver
/* ====================================================================
13
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
14
 *
15 cb41dd63 Renato Botelho
 *	Some or all of this file is based on the m0n0wall project which is
16
 *	Copyright (c)  2004 Manuel Kasper (BSD 2 clause)
17 191cb31d Stephen Beaver
 *
18
 *	Redistribution and use in source and binary forms, with or without modification,
19
 *	are permitted provided that the following conditions are met:
20
 *
21
 *	1. Redistributions of source code must retain the above copyright notice,
22
 *		this list of conditions and the following disclaimer.
23
 *
24
 *	2. Redistributions in binary form must reproduce the above copyright
25
 *		notice, this list of conditions and the following disclaimer in
26
 *		the documentation and/or other materials provided with the
27
 *		distribution.
28
 *
29
 *	3. All advertising materials mentioning features or use of this software
30
 *		must display the following acknowledgment:
31
 *		"This product includes software developed by the pfSense Project
32
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
33
 *
34
 *	4. The names "pfSense" and "pfSense Project" must not be used to
35
 *		 endorse or promote products derived from this software without
36
 *		 prior written permission. For written permission, please contact
37
 *		 coreteam@pfsense.org.
38
 *
39
 *	5. Products derived from this software may not be called "pfSense"
40
 *		nor may "pfSense" appear in their names without prior written
41
 *		permission of the Electric Sheep Fencing, LLC.
42
 *
43
 *	6. Redistributions of any form whatsoever must retain the following
44
 *		acknowledgment:
45
 *
46
 *	"This product includes software developed by the pfSense Project
47
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
48
 *
49
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
50
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
52
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
53
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
54
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
55
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
56
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
58
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
59
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
60
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
61
 *
62
 *	====================================================================
63
 *
64
 */
65 1d333258 Scott Ullrich
/*
66 45b4ffc6 Phil Davis
	pfSense_BUILDER_BINARIES:	/usr/bin/vmstat	/usr/bin/netstat	/sbin/dmesg	/sbin/mount	/sbin/setkey	/usr/local/sbin/pftop
67 1d333258 Scott Ullrich
	pfSense_BUILDER_BINARIES:	/sbin/pfctl	/sbin/sysctl	/usr/bin/top	/usr/bin/netstat	/sbin/pfctl	/sbin/ifconfig
68
	pfSense_MODULE:	support
69
*/
70 6b07c15a Matthew Grooms
71
##|+PRIV
72
##|*IDENT=page-hidden-detailedstatus
73
##|*NAME=Hidden: Detailed Status page
74
##|*DESCR=Allow access to the 'Hidden: Detailed Status' page.
75
##|*MATCH=status.php*
76
##|-PRIV
77 5b237745 Scott Ullrich
78
/* Execute a command, with a title, and generate an HTML table
79
 * showing the results.
80
 */
81 1d169baa Bill Marquette
82
/* include all configuration functions */
83 f977ac60 Bill Marquette
require_once("guiconfig.inc");
84 1d169baa Bill Marquette
require_once("functions.inc");
85 6f62e89f jim-p
$output_path = "/tmp/status_output/";
86
$output_file = "/tmp/status_output.tgz";
87 1d169baa Bill Marquette
88 289b91c8 jim-p
if (is_dir($output_path)) {
89
	unlink_if_exists("{$output_path}/*");
90
	@rmdir($output_path);
91
}
92
unlink_if_exists($output_file);
93
mkdir($output_path);
94
95 5b237745 Scott Ullrich
function doCmdT($title, $command) {
96 6f62e89f jim-p
	global $output_path, $output_file;
97
	/* Fixup output directory */
98
99 2151894c Colin Fleming
	$rubbish = array('|', '-', '/', '.', ' ');  /* fixes the <a> tag to be W3C compliant */
100 6c07db48 Phil Davis
	echo "\n<a name=\"" . str_replace($rubbish, '', $title) . "\" id=\"" . str_replace($rubbish, '', $title) . "\"></a>\n";
101 454cec57 sbeaver
102
	print('<div class="panel panel-default">');
103
	print(	  '<div class="panel-heading">' . $title . '</div>');
104
	print(	  '<div class="panel-body">');
105
	print(		  '<pre>');
106 f997992b Scott Ullrich
107 5b237745 Scott Ullrich
	if ($command == "dumpconfigxml") {
108 6f62e89f jim-p
		$ofd = @fopen("{$output_path}/config-sanitized.xml", "w");
109 5b237745 Scott Ullrich
		$fd = @fopen("/conf/config.xml", "r");
110
		if ($fd) {
111
			while (!feof($fd)) {
112
				$line = fgets($fd);
113 70069758 Bill Marquette
				/* remove sensitive contents */
114 5b237745 Scott Ullrich
				$line = preg_replace("/<password>.*?<\\/password>/", "<password>xxxxx</password>", $line);
115
				$line = preg_replace("/<pre-shared-key>.*?<\\/pre-shared-key>/", "<pre-shared-key>xxxxx</pre-shared-key>", $line);
116 70069758 Bill Marquette
				$line = preg_replace("/<rocommunity>.*?<\\/rocommunity>/", "<rocommunity>xxxxx</rocommunity>", $line);
117 8a2229e3 jim-p
				$line = preg_replace("/<prv>.*?<\\/prv>/", "<prv>xxxxx</prv>", $line);
118 fd192dbc jim-p
				$line = preg_replace("/<shared_key>.*?<\\/shared_key>/", "<shared_key>xxxxx</shared_key>", $line);
119
				$line = preg_replace("/<tls>.*?<\\/tls>/", "<tls>xxxxx</tls>", $line);
120 8a2229e3 jim-p
				$line = preg_replace("/<ipsecpsk>.*?<\\/ipsecpsk>/", "<ipsecpsk>xxxxx</ipsecpsk>", $line);
121
				$line = preg_replace("/<md5-hash>.*?<\\/md5-hash>/", "<md5-hash>xxxxx</md5-hash>", $line);
122
				$line = preg_replace("/<md5password>.*?<\\/md5password>/", "<md5password>xxxxx</md5password>", $line);
123 289b91c8 jim-p
				$line = preg_replace("/<nt-hash>.*?<\\/nt-hash>/", "<nt-hash>xxxxx</nt-hash>", $line);
124 8a2229e3 jim-p
				$line = preg_replace("/<radius_secret>.*?<\\/radius_secret>/", "<radius_secret>xxxxx</radius_secret>", $line);
125
				$line = preg_replace("/<ldap_bindpw>.*?<\\/ldap_bindpw>/", "<ldap_bindpw>xxxxx</ldap_bindpw>", $line);
126
				$line = preg_replace("/<passwordagain>.*?<\\/passwordagain>/", "<passwordagain>xxxxx</passwordagain>", $line);
127
				$line = preg_replace("/<crypto_password>.*?<\\/crypto_password>/", "<crypto_password>xxxxx</crypto_password>", $line);
128
				$line = preg_replace("/<crypto_password2>.*?<\\/crypto_password2>/", "<crypto_password2>xxxxx</crypto_password2>", $line);
129 5b237745 Scott Ullrich
				$line = str_replace("\t", "    ", $line);
130 6c07db48 Phil Davis
				echo htmlspecialchars($line, ENT_NOQUOTES);
131 6f62e89f jim-p
				fwrite($ofd, $line);
132 5b237745 Scott Ullrich
			}
133
		}
134
		fclose($fd);
135 6f62e89f jim-p
		fclose($ofd);
136 5b237745 Scott Ullrich
	} else {
137 6f62e89f jim-p
		$ofd = @fopen("{$output_path}/{$title}.txt", "w");
138 767a716e Scott Ullrich
		$execOutput = "";
139
		$execStatus = "";
140 5b237745 Scott Ullrich
		exec ($command . " 2>&1", $execOutput, $execStatus);
141
		for ($i = 0; isset($execOutput[$i]); $i++) {
142
			if ($i > 0) {
143
				echo "\n";
144
			}
145 6c07db48 Phil Davis
			echo htmlspecialchars($execOutput[$i], ENT_NOQUOTES);
146 6f62e89f jim-p
			fwrite($ofd, $execOutput[$i] . "\n");
147 5b237745 Scott Ullrich
		}
148 6f62e89f jim-p
		fclose($ofd);
149 5b237745 Scott Ullrich
	}
150 454cec57 sbeaver
151
	print(		  '</pre>');
152
	print(	  '</div>');
153
	print('</div>');
154 5b237745 Scott Ullrich
}
155
156
/* Define a command, with a title, to be executed later. */
157
function defCmdT($title, $command) {
158 2151894c Colin Fleming
	global $commands;
159 6c07db48 Phil Davis
	$title = htmlspecialchars($title, ENT_NOQUOTES);
160 2151894c Colin Fleming
	$commands[] = array($title, $command);
161 5b237745 Scott Ullrich
}
162
163
/* List all of the commands as an index. */
164
function listCmds() {
165 454cec57 sbeaver
	global $currentDate;
166 2151894c Colin Fleming
	global $commands;
167 454cec57 sbeaver
168
	$rubbish = array('|', '-', '/', '.', ' ');	/* fixes the <a> tag to be W3C compliant */
169
170
	print('<div class="panel panel-default">');
171
	print(	  '<div class="panel-heading">' . gettext("System status on ") . $currentDate . '</div>');
172
	print(	  '<div class="panel-body">');
173 2ca4eec2 Jared Dillard
	print(	  '    <div class="content">');
174 454cec57 sbeaver
	print("\n<p>" . gettext("This status page includes the following information") . ":\n");
175
	print("<ul>\n");
176 2151894c Colin Fleming
	for ($i = 0; isset($commands[$i]); $i++ ) {
177 454cec57 sbeaver
		print("\t<li><strong><a href=\"#" . str_replace($rubbish,'',$commands[$i][0]) . "\">" . $commands[$i][0] . "</a></strong></li>\n");
178 2151894c Colin Fleming
	}
179 454cec57 sbeaver
180
	print("</ul>\n");
181 2ca4eec2 Jared Dillard
	print('	       </div>');
182 454cec57 sbeaver
	print('	   </div>');
183
	print('</div>');
184 5b237745 Scott Ullrich
}
185
186
/* Execute all of the commands which were defined by a call to defCmd. */
187
function execCmds() {
188 2151894c Colin Fleming
	global $commands;
189 6c07db48 Phil Davis
	for ($i = 0; isset($commands[$i]); $i++) {
190 2151894c Colin Fleming
		doCmdT($commands[$i][0], $commands[$i][1]);
191
	}
192 5b237745 Scott Ullrich
}
193
194 58f2f42a Renato Botelho
global $g, $config;
195 1d169baa Bill Marquette
196 5b237745 Scott Ullrich
/* Set up all of the commands we want to execute. */
197 289b91c8 jim-p
198
/* System stats/info */
199
defCmdT("System uptime","/usr/bin/uptime");
200 5b237745 Scott Ullrich
defCmdT("Interfaces","/sbin/ifconfig -a");
201 289b91c8 jim-p
defCmdT("Interface Statistics","/usr/bin/netstat -ni");
202
defCmdT("Top Process Info", "/usr/bin/top | /usr/bin/head -n5");
203
defCmdT("Processes","/bin/ps xauww");
204
defCmdT("Mounted Filesystems", "/sbin/mount");
205
defCmdT("Free Disk Space","/bin/df -hi");
206
defCmdT("Routing tables","/usr/bin/netstat -nWr");
207
defCmdT("Mbuf Usage","/usr/bin/netstat -mb");
208
defCmdT("VMStat", "/usr/bin/vmstat -afimsz");
209
defCmdT("Sockets", "/usr/bin/sockstat");
210 37502a4a Scott Ullrich
211 289b91c8 jim-p
/* Firewall rules and info */
212
defCmdT("Generated Ruleset","/bin/cat {$g['tmp_path']}/rules.debug");
213
defCmdT("Generated Ruleset Limiters","/bin/cat {$g['tmp_path']}/rules.limiter");
214
defCmdT("Generated Ruleset Limits","/bin/cat {$g['tmp_path']}/rules.limits");
215
defCmdT("pf NAT Rules", "/sbin/pfctl -vvsn");
216
defCmdT("pf Firewall Rules", "/sbin/pfctl -vvsr");
217
defCmdT("pf Tables","/sbin/pfctl -vs Tables");
218
defCmdT("pf State Table Contents", "/sbin/pfctl -ss");
219
defCmdT("pf Info", "/sbin/pfctl -si");
220
defCmdT("pf Show All", "/sbin/pfctl -sa");
221
defCmdT("pf Queues","/sbin/pfctl -s queue -v");
222
defCmdT("pf OSFP","/sbin/pfctl -s osfp");
223
defCmdT("pfsync stats","/usr/bin/netstat -s -ppfsync");
224
defCmdT("pftop Default","/usr/local/sbin/pftop -a -b");
225
defCmdT("pftop Long","/usr/local/sbin/pftop -w 150 -a -b -v long");
226
defCmdT("pftop Queue","/usr/local/sbin/pftop -w 150 -a -b -v queue");
227
defCmdT("pftop Rules","/usr/local/sbin/pftop -w 150 -a -b -v rules");
228
defCmdT("pftop Size","/usr/local/sbin/pftop -w 150 -a -b -v size");
229
defCmdT("pftop Speed","/usr/local/sbin/pftop -w 150 -a -b -v speed");
230 baec2b00 Ermal
if (isset($config['captiveportal']) && is_array($config['captiveportal'])) {
231
	foreach ($config['captiveportal'] as $cpZone => $cpdata) {
232 289b91c8 jim-p
		if (isset($cpdata['enable']))
233
			defCmdT("IPFW rules for {$cpdata['zone']}", "/sbin/ipfw -x " . escapeshellarg($cpdata['zoneid']) . " show");
234 baec2b00 Ermal
	}
235
}
236 58f2f42a Renato Botelho
237 6f62e89f jim-p
/* Configuration Files */
238 289b91c8 jim-p
defCmdT("Contents of var run", "/bin/ls /var/run");
239
defCmdT("Contents of conf", "/bin/ls /conf");
240
defCmdT("config.xml","dumpconfigxml");
241
defCmdT("resolv.conf","/bin/cat /etc/resolv.conf");
242
defCmdT("DHCP Configuration","/bin/cat /var/dhcpd/etc/dhcpd.conf");
243
defCmdT("DHCPv6 Configuration","/bin/cat /var/dhcpd/etc/dhcpdv6.conf");
244
defCmdT("strongSwan config","/bin/cat /var/etc/ipsec/strongswan.conf");
245
defCmdT("IPsec config","/bin/cat /var/etc/ipsec/ipsec.conf");
246
defCmdT("IPsec Status","/usr/local/sbin/ipsec statusall");
247
defCmdT("SPD","/sbin/setkey -DP");
248
defCmdT("SAD","/sbin/setkey -D");
249 6f62e89f jim-p
if (file_exists("/cf/conf/upgrade_log.txt")) {
250
	defCmdT("Upgrade Log", "/bin/cat /cf/conf/upgrade_log.txt");
251
}
252
if (file_exists("/boot/loader.conf")) {
253
	defCmdT("Loader Configuration", "/bin/cat /boot/loader.conf");
254
}
255
if (file_exists("/boot/loader.conf.local")) {
256
	defCmdT("Loader Configuration (Local)", "/bin/cat /boot/loader.conf.local");
257
}
258
if (file_exists("/var/run/apinger.status")) {
259
	defCmdT("Gateway Status", "/bin/cat /var/run/apinger.status");
260
}
261
if (file_exists("/var/etc/apinger.conf")) {
262
	defCmdT("Gateway Monitoring Config", "/bin/cat /var/etc/apinger.conf");
263
}
264
if (file_exists("/var/etc/filterdns.conf")) {
265
	defCmdT("Filter DNS Daemon Config", "/bin/cat /var/etc/filterdns.conf");
266
}
267 289b91c8 jim-p
if(isset($config['system']['usefifolog']))  {
268 0bccadcc Chris Buechler
	defCmdT("last 1000 system log entries","/usr/sbin/fifolog_reader /var/log/system.log 2>&1 | tail -n 1000");
269
	defCmdT("last 1000 DHCP log entries","/usr/sbin/fifolog_reader /var/log/dhcpd.log 2>&1 | tail -n 1000");
270
	defCmdT("last 500 filter log entries","/usr/sbin/fifolog_reader /var/log/filter.log 2>&1 | tail -n 500");
271
	defCmdT("last 1000 gateways log entries","/usr/sbin/fifolog_reader /var/log/gateways.log 2>&1 | tail -n 1000");
272
	defCmdT("last 1000 IPsec log entries","/usr/sbin/fifolog_reader /var/log/ipsec.log 2>&1 | tail -n 1000");
273
	defCmdT("last 1000 L2TP log entries","/usr/sbin/fifolog_reader /var/log/l2tps.log 2>&1 | tail -n 1000");
274
	defCmdT("last 1000 NTP log entries","/usr/sbin/fifolog_reader /var/log/ntpd.log 2>&1 | tail -n 1000");
275
	defCmdT("last 1000 OpenVPN log entries","/usr/sbin/fifolog_reader /var/log/openvpn.log 2>&1 | tail -n 1000");
276
	defCmdT("last 1000 Captive Portal auth log entries","/usr/sbin/fifolog_reader /var/log/portalauth.log 2>&1 | tail -n 1000");
277
	defCmdT("last 1000 PPP log entries","/usr/sbin/fifolog_reader /var/log/poes.log 2>&1 | tail -n 1000");
278
	defCmdT("last 1000 relayd log entries","/usr/sbin/fifolog_reader /var/log/relayd.log 2>&1 | tail -n 1000");
279
	defCmdT("last 1000 resolver log entries","/usr/sbin/fifolog_reader /var/log/resolver.log 2>&1 | tail -n 1000");
280
	defCmdT("last 1000 routing log entries","/usr/sbin/fifolog_reader /var/log/routing.log 2>&1 | tail -n 1000");
281
	defCmdT("last 1000 wireless log entries","/usr/sbin/fifolog_reader /var/log/wireless.log 2>&1 | tail -n 1000");
282 568f30c2 Scott Ullrich
} else {
283 0bccadcc Chris Buechler
	defCmdT("last 1000 system log entries","/usr/local/sbin/clog /var/log/system.log 2>&1 | tail -n 1000");
284
	defCmdT("last 1000 DHCP log entries","/usr/local/sbin/clog /var/log/dhcpd.log 2>&1 | tail -n 1000");
285
	defCmdT("last 500 filter log entries","/usr/local/sbin/clog /var/log/filter.log 2>&1 | tail -n 500");
286
	defCmdT("last 1000 gateways log entries","/usr/local/sbin/clog /var/log/gateways.log 2>&1 | tail -n 1000");
287
	defCmdT("last 1000 IPsec log entries","/usr/local/sbin/clog /var/log/ipsec.log 2>&1 | tail -n 1000");
288
	defCmdT("last 1000 L2TP log entries","/usr/local/sbin/clog /var/log/l2tps.log 2>&1 | tail -n 1000");
289
	defCmdT("last 1000 NTP log entries","/usr/local/sbin/clog /var/log/ntpd.log 2>&1 | tail -n 1000");
290
	defCmdT("last 1000 OpenVPN log entries","/usr/local/sbin/clog /var/log/openvpn.log 2>&1 | tail -n 1000");
291
	defCmdT("last 1000 Captive Portal auth log entries","/usr/local/sbin/clog /var/log/portalauth.log 2>&1 | tail -n 1000");
292
	defCmdT("last 1000 PPP log entries","/usr/local/sbin/clog /var/log/poes.log 2>&1 | tail -n 1000");
293
	defCmdT("last 1000 relayd log entries","/usr/local/sbin/clog /var/log/relayd.log 2>&1 | tail -n 1000");
294
	defCmdT("last 1000 resolver log entries","/usr/local/sbin/clog /var/log/resolver.log 2>&1 | tail -n 1000");
295
	defCmdT("last 1000 routing log entries","/usr/local/sbin/clog /var/log/routing.log 2>&1 | tail -n 1000");
296
	defCmdT("last 1000 wireless log entries","/usr/local/sbin/clog /var/log/wireless.log 2>&1 | tail -n 1000");
297 568f30c2 Scott Ullrich
}
298 6f62e89f jim-p
if (file_exists("/tmp/PHP_errors.log")) {
299
	defCmdT("PHP Error Log", "/bin/cat /tmp/PHP_errors.log");
300
}
301 289b91c8 jim-p
defCmdT("System Message Buffer","/sbin/dmesg -a");
302
defCmdT("System Message Buffer (Boot)","/bin/cat /var/log/dmesg.boot");
303
defCmdT("sysctl values","/sbin/sysctl -a");
304 9cd0b618 Scott Ullrich
305 5b237745 Scott Ullrich
exec("/bin/date", $dateOutput, $dateStatus);
306
$currentDate = $dateOutput[0];
307
308 6c07db48 Phil Davis
$pgtitle = array("{$g['product_name']}", "status");
309 4df96eff Scott Ullrich
include("head.inc");
310
311 289b91c8 jim-p
print_info_box(gettext("Make sure all sensitive information is removed! (Passwords, etc.) before posting " .
312
			   "information from this page in public places (like mailing lists)") . '<br />' .
313
		gettext("Common password fields in config.xml have been automatically redacted.") . '<br />' .
314
		gettext("When the page has finished loading, the output will be stored in {$output_file}. It may be downloaded via scp or ") .
315
		"<a href=\"/exec.php?dlPath={$output_file}\">" . gettext("Diagnostics > Command Prompt") . '</a>');
316 5b237745 Scott Ullrich
317 454cec57 sbeaver
listCmds();
318
execCmds();
319 5b237745 Scott Ullrich
320 56bd1847 Chris Buechler
include("foot.inc");