Project

General

Profile

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