Project

General

Profile

Download (13.5 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 45b4ffc6 Phil Davis
	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 45b4ffc6 Phil Davis
	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 6f62e89f jim-p
$output_path = "/tmp/status_output/";
56
$output_file = "/tmp/status_output.tgz";
57 1d169baa Bill Marquette
58 289b91c8 jim-p
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
65 5b237745 Scott Ullrich
function doCmdT($title, $command) {
66 6f62e89f 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 6c07db48 Phil Davis
	echo "\n<a name=\"" . str_replace($rubbish, '', $title) . "\" id=\"" . str_replace($rubbish, '', $title) . "\"></a>\n";
71 454cec57 sbeaver
72
	print('<div class="panel panel-default">');
73
	print(	  '<div class="panel-heading">' . $title . '</div>');
74
	print(	  '<div class="panel-body">');
75
	print(		  '<pre>');
76 f997992b Scott Ullrich
77 5b237745 Scott Ullrich
	if ($command == "dumpconfigxml") {
78 6f62e89f jim-p
		$ofd = @fopen("{$output_path}/config-sanitized.xml", "w");
79 5b237745 Scott Ullrich
		$fd = @fopen("/conf/config.xml", "r");
80
		if ($fd) {
81
			while (!feof($fd)) {
82
				$line = fgets($fd);
83 70069758 Bill Marquette
				/* remove sensitive contents */
84 5b237745 Scott Ullrich
				$line = preg_replace("/<password>.*?<\\/password>/", "<password>xxxxx</password>", $line);
85
				$line = preg_replace("/<pre-shared-key>.*?<\\/pre-shared-key>/", "<pre-shared-key>xxxxx</pre-shared-key>", $line);
86 70069758 Bill Marquette
				$line = preg_replace("/<rocommunity>.*?<\\/rocommunity>/", "<rocommunity>xxxxx</rocommunity>", $line);
87 8a2229e3 jim-p
				$line = preg_replace("/<prv>.*?<\\/prv>/", "<prv>xxxxx</prv>", $line);
88 fd192dbc jim-p
				$line = preg_replace("/<shared_key>.*?<\\/shared_key>/", "<shared_key>xxxxx</shared_key>", $line);
89
				$line = preg_replace("/<tls>.*?<\\/tls>/", "<tls>xxxxx</tls>", $line);
90 8a2229e3 jim-p
				$line = preg_replace("/<ipsecpsk>.*?<\\/ipsecpsk>/", "<ipsecpsk>xxxxx</ipsecpsk>", $line);
91
				$line = preg_replace("/<md5-hash>.*?<\\/md5-hash>/", "<md5-hash>xxxxx</md5-hash>", $line);
92
				$line = preg_replace("/<md5password>.*?<\\/md5password>/", "<md5password>xxxxx</md5password>", $line);
93 289b91c8 jim-p
				$line = preg_replace("/<nt-hash>.*?<\\/nt-hash>/", "<nt-hash>xxxxx</nt-hash>", $line);
94 8a2229e3 jim-p
				$line = preg_replace("/<radius_secret>.*?<\\/radius_secret>/", "<radius_secret>xxxxx</radius_secret>", $line);
95
				$line = preg_replace("/<ldap_bindpw>.*?<\\/ldap_bindpw>/", "<ldap_bindpw>xxxxx</ldap_bindpw>", $line);
96
				$line = preg_replace("/<passwordagain>.*?<\\/passwordagain>/", "<passwordagain>xxxxx</passwordagain>", $line);
97
				$line = preg_replace("/<crypto_password>.*?<\\/crypto_password>/", "<crypto_password>xxxxx</crypto_password>", $line);
98
				$line = preg_replace("/<crypto_password2>.*?<\\/crypto_password2>/", "<crypto_password2>xxxxx</crypto_password2>", $line);
99 5b237745 Scott Ullrich
				$line = str_replace("\t", "    ", $line);
100 6c07db48 Phil Davis
				echo htmlspecialchars($line, ENT_NOQUOTES);
101 6f62e89f jim-p
				fwrite($ofd, $line);
102 5b237745 Scott Ullrich
			}
103
		}
104
		fclose($fd);
105 6f62e89f jim-p
		fclose($ofd);
106 5b237745 Scott Ullrich
	} else {
107 6f62e89f jim-p
		$ofd = @fopen("{$output_path}/{$title}.txt", "w");
108 767a716e Scott Ullrich
		$execOutput = "";
109
		$execStatus = "";
110 5b237745 Scott Ullrich
		exec ($command . " 2>&1", $execOutput, $execStatus);
111
		for ($i = 0; isset($execOutput[$i]); $i++) {
112
			if ($i > 0) {
113
				echo "\n";
114
			}
115 6c07db48 Phil Davis
			echo htmlspecialchars($execOutput[$i], ENT_NOQUOTES);
116 6f62e89f jim-p
			fwrite($ofd, $execOutput[$i] . "\n");
117 5b237745 Scott Ullrich
		}
118 6f62e89f jim-p
		fclose($ofd);
119 5b237745 Scott Ullrich
	}
120 454cec57 sbeaver
121
	print(		  '</pre>');
122
	print(	  '</div>');
123
	print('</div>');
124 5b237745 Scott Ullrich
}
125
126
/* Define a command, with a title, to be executed later. */
127
function defCmdT($title, $command) {
128 2151894c Colin Fleming
	global $commands;
129 6c07db48 Phil Davis
	$title = htmlspecialchars($title, ENT_NOQUOTES);
130 2151894c Colin Fleming
	$commands[] = array($title, $command);
131 5b237745 Scott Ullrich
}
132
133
/* List all of the commands as an index. */
134
function listCmds() {
135 454cec57 sbeaver
	global $currentDate;
136 2151894c Colin Fleming
	global $commands;
137 454cec57 sbeaver
138
	$rubbish = array('|', '-', '/', '.', ' ');	/* fixes the <a> tag to be W3C compliant */
139
140
	print('<div class="panel panel-default">');
141
	print(	  '<div class="panel-heading">' . gettext("System status on ") . $currentDate . '</div>');
142
	print(	  '<div class="panel-body">');
143 2ca4eec2 Jared Dillard
	print(	  '    <div class="content">');
144 454cec57 sbeaver
	print("\n<p>" . gettext("This status page includes the following information") . ":\n");
145
	print("<ul>\n");
146 2151894c Colin Fleming
	for ($i = 0; isset($commands[$i]); $i++ ) {
147 454cec57 sbeaver
		print("\t<li><strong><a href=\"#" . str_replace($rubbish,'',$commands[$i][0]) . "\">" . $commands[$i][0] . "</a></strong></li>\n");
148 2151894c Colin Fleming
	}
149 454cec57 sbeaver
150
	print("</ul>\n");
151 2ca4eec2 Jared Dillard
	print('	       </div>');
152 454cec57 sbeaver
	print('	   </div>');
153
	print('</div>');
154 5b237745 Scott Ullrich
}
155
156
/* Execute all of the commands which were defined by a call to defCmd. */
157
function execCmds() {
158 2151894c Colin Fleming
	global $commands;
159 6c07db48 Phil Davis
	for ($i = 0; isset($commands[$i]); $i++) {
160 2151894c Colin Fleming
		doCmdT($commands[$i][0], $commands[$i][1]);
161
	}
162 5b237745 Scott Ullrich
}
163
164 58f2f42a Renato Botelho
global $g, $config;
165 1d169baa Bill Marquette
166 5b237745 Scott Ullrich
/* Set up all of the commands we want to execute. */
167 289b91c8 jim-p
168
/* System stats/info */
169
defCmdT("System uptime","/usr/bin/uptime");
170 5b237745 Scott Ullrich
defCmdT("Interfaces","/sbin/ifconfig -a");
171 289b91c8 jim-p
defCmdT("Interface Statistics","/usr/bin/netstat -ni");
172
defCmdT("Top Process Info", "/usr/bin/top | /usr/bin/head -n5");
173
defCmdT("Processes","/bin/ps xauww");
174
defCmdT("Mounted Filesystems", "/sbin/mount");
175
defCmdT("Free Disk Space","/bin/df -hi");
176
defCmdT("Routing tables","/usr/bin/netstat -nWr");
177
defCmdT("Mbuf Usage","/usr/bin/netstat -mb");
178
defCmdT("VMStat", "/usr/bin/vmstat -afimsz");
179
defCmdT("Sockets", "/usr/bin/sockstat");
180 37502a4a Scott Ullrich
181 289b91c8 jim-p
/* Firewall rules and info */
182
defCmdT("Generated Ruleset","/bin/cat {$g['tmp_path']}/rules.debug");
183
defCmdT("Generated Ruleset Limiters","/bin/cat {$g['tmp_path']}/rules.limiter");
184
defCmdT("Generated Ruleset Limits","/bin/cat {$g['tmp_path']}/rules.limits");
185
defCmdT("pf NAT Rules", "/sbin/pfctl -vvsn");
186
defCmdT("pf Firewall Rules", "/sbin/pfctl -vvsr");
187
defCmdT("pf Tables","/sbin/pfctl -vs Tables");
188
defCmdT("pf State Table Contents", "/sbin/pfctl -ss");
189
defCmdT("pf Info", "/sbin/pfctl -si");
190
defCmdT("pf Show All", "/sbin/pfctl -sa");
191
defCmdT("pf Queues","/sbin/pfctl -s queue -v");
192
defCmdT("pf OSFP","/sbin/pfctl -s osfp");
193
defCmdT("pfsync stats","/usr/bin/netstat -s -ppfsync");
194
defCmdT("pftop Default","/usr/local/sbin/pftop -a -b");
195
defCmdT("pftop Long","/usr/local/sbin/pftop -w 150 -a -b -v long");
196
defCmdT("pftop Queue","/usr/local/sbin/pftop -w 150 -a -b -v queue");
197
defCmdT("pftop Rules","/usr/local/sbin/pftop -w 150 -a -b -v rules");
198
defCmdT("pftop Size","/usr/local/sbin/pftop -w 150 -a -b -v size");
199
defCmdT("pftop Speed","/usr/local/sbin/pftop -w 150 -a -b -v speed");
200 baec2b00 Ermal
if (isset($config['captiveportal']) && is_array($config['captiveportal'])) {
201
	foreach ($config['captiveportal'] as $cpZone => $cpdata) {
202 289b91c8 jim-p
		if (isset($cpdata['enable']))
203
			defCmdT("IPFW rules for {$cpdata['zone']}", "/sbin/ipfw -x " . escapeshellarg($cpdata['zoneid']) . " show");
204 baec2b00 Ermal
	}
205
}
206 58f2f42a Renato Botelho
207 6f62e89f jim-p
/* Configuration Files */
208 289b91c8 jim-p
defCmdT("Contents of var run", "/bin/ls /var/run");
209
defCmdT("Contents of conf", "/bin/ls /conf");
210
defCmdT("config.xml","dumpconfigxml");
211
defCmdT("resolv.conf","/bin/cat /etc/resolv.conf");
212
defCmdT("DHCP Configuration","/bin/cat /var/dhcpd/etc/dhcpd.conf");
213
defCmdT("DHCPv6 Configuration","/bin/cat /var/dhcpd/etc/dhcpdv6.conf");
214
defCmdT("strongSwan config","/bin/cat /var/etc/ipsec/strongswan.conf");
215
defCmdT("IPsec config","/bin/cat /var/etc/ipsec/ipsec.conf");
216
defCmdT("IPsec Status","/usr/local/sbin/ipsec statusall");
217
defCmdT("SPD","/sbin/setkey -DP");
218
defCmdT("SAD","/sbin/setkey -D");
219 6f62e89f jim-p
if (file_exists("/cf/conf/upgrade_log.txt")) {
220
	defCmdT("Upgrade Log", "/bin/cat /cf/conf/upgrade_log.txt");
221
}
222
if (file_exists("/boot/loader.conf")) {
223
	defCmdT("Loader Configuration", "/bin/cat /boot/loader.conf");
224
}
225
if (file_exists("/boot/loader.conf.local")) {
226
	defCmdT("Loader Configuration (Local)", "/bin/cat /boot/loader.conf.local");
227
}
228
if (file_exists("/var/run/apinger.status")) {
229
	defCmdT("Gateway Status", "/bin/cat /var/run/apinger.status");
230
}
231
if (file_exists("/var/etc/apinger.conf")) {
232
	defCmdT("Gateway Monitoring Config", "/bin/cat /var/etc/apinger.conf");
233
}
234
if (file_exists("/var/etc/filterdns.conf")) {
235
	defCmdT("Filter DNS Daemon Config", "/bin/cat /var/etc/filterdns.conf");
236
}
237 289b91c8 jim-p
if(isset($config['system']['usefifolog']))  {
238 0bccadcc Chris Buechler
	defCmdT("last 1000 system log entries","/usr/sbin/fifolog_reader /var/log/system.log 2>&1 | tail -n 1000");
239
	defCmdT("last 1000 DHCP log entries","/usr/sbin/fifolog_reader /var/log/dhcpd.log 2>&1 | tail -n 1000");
240
	defCmdT("last 500 filter log entries","/usr/sbin/fifolog_reader /var/log/filter.log 2>&1 | tail -n 500");
241
	defCmdT("last 1000 gateways log entries","/usr/sbin/fifolog_reader /var/log/gateways.log 2>&1 | tail -n 1000");
242
	defCmdT("last 1000 IPsec log entries","/usr/sbin/fifolog_reader /var/log/ipsec.log 2>&1 | tail -n 1000");
243
	defCmdT("last 1000 L2TP log entries","/usr/sbin/fifolog_reader /var/log/l2tps.log 2>&1 | tail -n 1000");
244
	defCmdT("last 1000 NTP log entries","/usr/sbin/fifolog_reader /var/log/ntpd.log 2>&1 | tail -n 1000");
245
	defCmdT("last 1000 OpenVPN log entries","/usr/sbin/fifolog_reader /var/log/openvpn.log 2>&1 | tail -n 1000");
246
	defCmdT("last 1000 Captive Portal auth log entries","/usr/sbin/fifolog_reader /var/log/portalauth.log 2>&1 | tail -n 1000");
247
	defCmdT("last 1000 PPP log entries","/usr/sbin/fifolog_reader /var/log/poes.log 2>&1 | tail -n 1000");
248
	defCmdT("last 1000 relayd log entries","/usr/sbin/fifolog_reader /var/log/relayd.log 2>&1 | tail -n 1000");
249
	defCmdT("last 1000 resolver log entries","/usr/sbin/fifolog_reader /var/log/resolver.log 2>&1 | tail -n 1000");
250
	defCmdT("last 1000 routing log entries","/usr/sbin/fifolog_reader /var/log/routing.log 2>&1 | tail -n 1000");
251
	defCmdT("last 1000 wireless log entries","/usr/sbin/fifolog_reader /var/log/wireless.log 2>&1 | tail -n 1000");
252 568f30c2 Scott Ullrich
} else {
253 0bccadcc Chris Buechler
	defCmdT("last 1000 system log entries","/usr/local/sbin/clog /var/log/system.log 2>&1 | tail -n 1000");
254
	defCmdT("last 1000 DHCP log entries","/usr/local/sbin/clog /var/log/dhcpd.log 2>&1 | tail -n 1000");
255
	defCmdT("last 500 filter log entries","/usr/local/sbin/clog /var/log/filter.log 2>&1 | tail -n 500");
256
	defCmdT("last 1000 gateways log entries","/usr/local/sbin/clog /var/log/gateways.log 2>&1 | tail -n 1000");
257
	defCmdT("last 1000 IPsec log entries","/usr/local/sbin/clog /var/log/ipsec.log 2>&1 | tail -n 1000");
258
	defCmdT("last 1000 L2TP log entries","/usr/local/sbin/clog /var/log/l2tps.log 2>&1 | tail -n 1000");
259
	defCmdT("last 1000 NTP log entries","/usr/local/sbin/clog /var/log/ntpd.log 2>&1 | tail -n 1000");
260
	defCmdT("last 1000 OpenVPN log entries","/usr/local/sbin/clog /var/log/openvpn.log 2>&1 | tail -n 1000");
261
	defCmdT("last 1000 Captive Portal auth log entries","/usr/local/sbin/clog /var/log/portalauth.log 2>&1 | tail -n 1000");
262
	defCmdT("last 1000 PPP log entries","/usr/local/sbin/clog /var/log/poes.log 2>&1 | tail -n 1000");
263
	defCmdT("last 1000 relayd log entries","/usr/local/sbin/clog /var/log/relayd.log 2>&1 | tail -n 1000");
264
	defCmdT("last 1000 resolver log entries","/usr/local/sbin/clog /var/log/resolver.log 2>&1 | tail -n 1000");
265
	defCmdT("last 1000 routing log entries","/usr/local/sbin/clog /var/log/routing.log 2>&1 | tail -n 1000");
266
	defCmdT("last 1000 wireless log entries","/usr/local/sbin/clog /var/log/wireless.log 2>&1 | tail -n 1000");
267 568f30c2 Scott Ullrich
}
268 6f62e89f jim-p
if (file_exists("/tmp/PHP_errors.log")) {
269
	defCmdT("PHP Error Log", "/bin/cat /tmp/PHP_errors.log");
270
}
271 289b91c8 jim-p
defCmdT("System Message Buffer","/sbin/dmesg -a");
272
defCmdT("System Message Buffer (Boot)","/bin/cat /var/log/dmesg.boot");
273
defCmdT("sysctl values","/sbin/sysctl -a");
274 9cd0b618 Scott Ullrich
275 5b237745 Scott Ullrich
exec("/bin/date", $dateOutput, $dateStatus);
276
$currentDate = $dateOutput[0];
277
278 6c07db48 Phil Davis
$pgtitle = array("{$g['product_name']}", "status");
279 4df96eff Scott Ullrich
include("head.inc");
280
281 289b91c8 jim-p
print_info_box(gettext("Make sure all sensitive information is removed! (Passwords, etc.) before posting " .
282
			   "information from this page in public places (like mailing lists)") . '<br />' .
283
		gettext("Common password fields in config.xml have been automatically redacted.") . '<br />' .
284
		gettext("When the page has finished loading, the output will be stored in {$output_file}. It may be downloaded via scp or ") .
285
		"<a href=\"/exec.php?dlPath={$output_file}\">" . gettext("Diagnostics > Command Prompt") . '</a>');
286 5b237745 Scott Ullrich
287 454cec57 sbeaver
listCmds();
288
execCmds();
289 5b237745 Scott Ullrich
290 56bd1847 Chris Buechler
include("foot.inc");