Project

General

Profile

Download (14.8 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/* 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
 * (modified for pfSense by Scott Ullrich geekgod@pfsense.com)
8
 *
9
 */
10
/* ====================================================================
11
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
12
 *
13
 *  Some or all of this file is based on the m0n0wall project which is
14
 *  Copyright (c)  2004 Manuel Kasper (BSD 2 clause)
15
 *
16
 *	Redistribution and use in source and binary forms, with or without modification,
17
 *	are permitted provided that the following conditions are met:
18
 *
19
 *	1. Redistributions of source code must retain the above copyright notice,
20
 *		this list of conditions and the following disclaimer.
21
 *
22
 *	2. Redistributions in binary form must reproduce the above copyright
23
 *		notice, this list of conditions and the following disclaimer in
24
 *		the documentation and/or other materials provided with the
25
 *		distribution.
26
 *
27
 *	3. All advertising materials mentioning features or use of this software
28
 *		must display the following acknowledgment:
29
 *		"This product includes software developed by the pfSense Project
30
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
31
 *
32
 *	4. The names "pfSense" and "pfSense Project" must not be used to
33
 *		 endorse or promote products derived from this software without
34
 *		 prior written permission. For written permission, please contact
35
 *		 coreteam@pfsense.org.
36
 *
37
 *	5. Products derived from this software may not be called "pfSense"
38
 *		nor may "pfSense" appear in their names without prior written
39
 *		permission of the Electric Sheep Fencing, LLC.
40
 *
41
 *	6. Redistributions of any form whatsoever must retain the following
42
 *		acknowledgment:
43
 *
44
 *	"This product includes software developed by the pfSense Project
45
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
46
 *
47
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
48
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
50
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
51
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
52
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
53
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
54
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
56
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
57
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
58
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
59
 *
60
 *	====================================================================
61
 *
62
 */
63
/*
64
	pfSense_BUILDER_BINARIES:	/usr/bin/vmstat	/usr/bin/netstat	/sbin/dmesg	/sbin/mount	/sbin/setkey	/usr/local/sbin/pftop
65
	pfSense_BUILDER_BINARIES:	/sbin/pfctl	/sbin/sysctl	/usr/bin/top	/usr/bin/netstat	/sbin/pfctl	/sbin/ifconfig
66
	pfSense_MODULE:	support
67
*/
68

    
69
##|+PRIV
70
##|*IDENT=page-hidden-detailedstatus
71
##|*NAME=Hidden: Detailed Status page
72
##|*DESCR=Allow access to the 'Hidden: Detailed Status' page.
73
##|*MATCH=status.php*
74
##|-PRIV
75

    
76
/* Execute a command, with a title, and generate an HTML table
77
 * showing the results.
78
 */
79

    
80
/* include all configuration functions */
81
require_once("guiconfig.inc");
82
require_once("functions.inc");
83
$output_path = "/tmp/status_output/";
84
$output_file = "/tmp/status_output.tgz";
85

    
86
if (is_dir($output_path)) {
87
	unlink_if_exists("{$output_path}/*");
88
	@rmdir($output_path);
89
}
90
unlink_if_exists($output_file);
91
mkdir($output_path);
92

    
93
function doCmdT($title, $command) {
94
	global $output_path, $output_file;
95
	/* Fixup output directory */
96

    
97
	$rubbish = array('|', '-', '/', '.', ' ');  /* fixes the <a> tag to be W3C compliant */
98
	echo "\n<a name=\"" . str_replace($rubbish, '', $title) . "\" id=\"" . str_replace($rubbish, '', $title) . "\"></a>\n";
99

    
100
	print('<div class="panel panel-default">');
101
	print(	  '<div class="panel-heading">' . $title . '</div>');
102
	print(	  '<div class="panel-body">');
103
	print(		  '<pre>');
104

    
105
	if ($command == "dumpconfigxml") {
106
		$ofd = @fopen("{$output_path}/config-sanitized.xml", "w");
107
		$fd = @fopen("/conf/config.xml", "r");
108
		if ($fd) {
109
			while (!feof($fd)) {
110
				$line = fgets($fd);
111
				/* remove sensitive contents */
112
				$line = preg_replace("/<password>.*?<\\/password>/", "<password>xxxxx</password>", $line);
113
				$line = preg_replace("/<pre-shared-key>.*?<\\/pre-shared-key>/", "<pre-shared-key>xxxxx</pre-shared-key>", $line);
114
				$line = preg_replace("/<rocommunity>.*?<\\/rocommunity>/", "<rocommunity>xxxxx</rocommunity>", $line);
115
				$line = preg_replace("/<prv>.*?<\\/prv>/", "<prv>xxxxx</prv>", $line);
116
				$line = preg_replace("/<shared_key>.*?<\\/shared_key>/", "<shared_key>xxxxx</shared_key>", $line);
117
				$line = preg_replace("/<tls>.*?<\\/tls>/", "<tls>xxxxx</tls>", $line);
118
				$line = preg_replace("/<ipsecpsk>.*?<\\/ipsecpsk>/", "<ipsecpsk>xxxxx</ipsecpsk>", $line);
119
				$line = preg_replace("/<md5-hash>.*?<\\/md5-hash>/", "<md5-hash>xxxxx</md5-hash>", $line);
120
				$line = preg_replace("/<md5password>.*?<\\/md5password>/", "<md5password>xxxxx</md5password>", $line);
121
				$line = preg_replace("/<nt-hash>.*?<\\/nt-hash>/", "<nt-hash>xxxxx</nt-hash>", $line);
122
				$line = preg_replace("/<radius_secret>.*?<\\/radius_secret>/", "<radius_secret>xxxxx</radius_secret>", $line);
123
				$line = preg_replace("/<ldap_bindpw>.*?<\\/ldap_bindpw>/", "<ldap_bindpw>xxxxx</ldap_bindpw>", $line);
124
				$line = preg_replace("/<passwordagain>.*?<\\/passwordagain>/", "<passwordagain>xxxxx</passwordagain>", $line);
125
				$line = preg_replace("/<crypto_password>.*?<\\/crypto_password>/", "<crypto_password>xxxxx</crypto_password>", $line);
126
				$line = preg_replace("/<crypto_password2>.*?<\\/crypto_password2>/", "<crypto_password2>xxxxx</crypto_password2>", $line);
127
				$line = str_replace("\t", "    ", $line);
128
				echo htmlspecialchars($line, ENT_NOQUOTES);
129
				fwrite($ofd, $line);
130
			}
131
		}
132
		fclose($fd);
133
		fclose($ofd);
134
	} else {
135
		$ofd = @fopen("{$output_path}/{$title}.txt", "w");
136
		$execOutput = "";
137
		$execStatus = "";
138
		exec ($command . " 2>&1", $execOutput, $execStatus);
139
		for ($i = 0; isset($execOutput[$i]); $i++) {
140
			if ($i > 0) {
141
				echo "\n";
142
			}
143
			echo htmlspecialchars($execOutput[$i], ENT_NOQUOTES);
144
			fwrite($ofd, $execOutput[$i] . "\n");
145
		}
146
		fclose($ofd);
147
	}
148

    
149
	print(		  '</pre>');
150
	print(	  '</div>');
151
	print('</div>');
152
}
153

    
154
/* Define a command, with a title, to be executed later. */
155
function defCmdT($title, $command) {
156
	global $commands;
157
	$title = htmlspecialchars($title, ENT_NOQUOTES);
158
	$commands[] = array($title, $command);
159
}
160

    
161
/* List all of the commands as an index. */
162
function listCmds() {
163
	global $currentDate;
164
	global $commands;
165

    
166
	$rubbish = array('|', '-', '/', '.', ' ');	/* fixes the <a> tag to be W3C compliant */
167

    
168
	print('<div class="panel panel-default">');
169
	print(	  '<div class="panel-heading">' . gettext("System status on ") . $currentDate . '</div>');
170
	print(	  '<div class="panel-body">');
171
	print(	  '    <div class="content">');
172
	print("\n<p>" . gettext("This status page includes the following information") . ":\n");
173
	print("<ul>\n");
174
	for ($i = 0; isset($commands[$i]); $i++ ) {
175
		print("\t<li><strong><a href=\"#" . str_replace($rubbish,'',$commands[$i][0]) . "\">" . $commands[$i][0] . "</a></strong></li>\n");
176
	}
177

    
178
	print("</ul>\n");
179
	print('	       </div>');
180
	print('	   </div>');
181
	print('</div>');
182
}
183

    
184
/* Execute all of the commands which were defined by a call to defCmd. */
185
function execCmds() {
186
	global $commands;
187
	for ($i = 0; isset($commands[$i]); $i++) {
188
		doCmdT($commands[$i][0], $commands[$i][1]);
189
	}
190
}
191

    
192
global $g, $config;
193

    
194
/* Set up all of the commands we want to execute. */
195

    
196
/* System stats/info */
197
defCmdT("System uptime","/usr/bin/uptime");
198
defCmdT("Interfaces","/sbin/ifconfig -a");
199
defCmdT("Interface Statistics","/usr/bin/netstat -ni");
200
defCmdT("Top Process Info", "/usr/bin/top | /usr/bin/head -n5");
201
defCmdT("Processes","/bin/ps xauww");
202
defCmdT("Mounted Filesystems", "/sbin/mount");
203
defCmdT("Free Disk Space","/bin/df -hi");
204
defCmdT("Routing tables","/usr/bin/netstat -nWr");
205
defCmdT("Mbuf Usage","/usr/bin/netstat -mb");
206
defCmdT("VMStat", "/usr/bin/vmstat -afimsz");
207
defCmdT("Sockets", "/usr/bin/sockstat");
208

    
209
/* Firewall rules and info */
210
defCmdT("Generated Ruleset","/bin/cat {$g['tmp_path']}/rules.debug");
211
defCmdT("Generated Ruleset Limiters","/bin/cat {$g['tmp_path']}/rules.limiter");
212
defCmdT("Generated Ruleset Limits","/bin/cat {$g['tmp_path']}/rules.limits");
213
defCmdT("pf NAT Rules", "/sbin/pfctl -vvsn");
214
defCmdT("pf Firewall Rules", "/sbin/pfctl -vvsr");
215
defCmdT("pf Tables","/sbin/pfctl -vs Tables");
216
defCmdT("pf State Table Contents", "/sbin/pfctl -ss");
217
defCmdT("pf Info", "/sbin/pfctl -si");
218
defCmdT("pf Show All", "/sbin/pfctl -sa");
219
defCmdT("pf Queues","/sbin/pfctl -s queue -v");
220
defCmdT("pf OSFP","/sbin/pfctl -s osfp");
221
defCmdT("pfsync stats","/usr/bin/netstat -s -ppfsync");
222
defCmdT("pftop Default","/usr/local/sbin/pftop -a -b");
223
defCmdT("pftop Long","/usr/local/sbin/pftop -w 150 -a -b -v long");
224
defCmdT("pftop Queue","/usr/local/sbin/pftop -w 150 -a -b -v queue");
225
defCmdT("pftop Rules","/usr/local/sbin/pftop -w 150 -a -b -v rules");
226
defCmdT("pftop Size","/usr/local/sbin/pftop -w 150 -a -b -v size");
227
defCmdT("pftop Speed","/usr/local/sbin/pftop -w 150 -a -b -v speed");
228
if (isset($config['captiveportal']) && is_array($config['captiveportal'])) {
229
	foreach ($config['captiveportal'] as $cpZone => $cpdata) {
230
		if (isset($cpdata['enable']))
231
			defCmdT("IPFW rules for {$cpdata['zone']}", "/sbin/ipfw -x " . escapeshellarg($cpdata['zoneid']) . " show");
232
	}
233
}
234

    
235
/* Configuration Files */
236
defCmdT("Contents of var run", "/bin/ls /var/run");
237
defCmdT("Contents of conf", "/bin/ls /conf");
238
defCmdT("config.xml","dumpconfigxml");
239
defCmdT("resolv.conf","/bin/cat /etc/resolv.conf");
240
defCmdT("DHCP Configuration","/bin/cat /var/dhcpd/etc/dhcpd.conf");
241
defCmdT("DHCPv6 Configuration","/bin/cat /var/dhcpd/etc/dhcpdv6.conf");
242
defCmdT("strongSwan config","/bin/cat /var/etc/ipsec/strongswan.conf");
243
defCmdT("IPsec config","/bin/cat /var/etc/ipsec/ipsec.conf");
244
defCmdT("IPsec Status","/usr/local/sbin/ipsec statusall");
245
defCmdT("SPD","/sbin/setkey -DP");
246
defCmdT("SAD","/sbin/setkey -D");
247
if (file_exists("/cf/conf/upgrade_log.txt")) {
248
	defCmdT("Upgrade Log", "/bin/cat /cf/conf/upgrade_log.txt");
249
}
250
if (file_exists("/boot/loader.conf")) {
251
	defCmdT("Loader Configuration", "/bin/cat /boot/loader.conf");
252
}
253
if (file_exists("/boot/loader.conf.local")) {
254
	defCmdT("Loader Configuration (Local)", "/bin/cat /boot/loader.conf.local");
255
}
256
if (file_exists("/var/run/apinger.status")) {
257
	defCmdT("Gateway Status", "/bin/cat /var/run/apinger.status");
258
}
259
if (file_exists("/var/etc/apinger.conf")) {
260
	defCmdT("Gateway Monitoring Config", "/bin/cat /var/etc/apinger.conf");
261
}
262
if (file_exists("/var/etc/filterdns.conf")) {
263
	defCmdT("Filter DNS Daemon Config", "/bin/cat /var/etc/filterdns.conf");
264
}
265
if(isset($config['system']['usefifolog']))  {
266
	defCmdT("last 1000 system log entries","/usr/sbin/fifolog_reader /var/log/system.log 2>&1 | tail -n 1000");
267
	defCmdT("last 1000 DHCP log entries","/usr/sbin/fifolog_reader /var/log/dhcpd.log 2>&1 | tail -n 1000");
268
	defCmdT("last 500 filter log entries","/usr/sbin/fifolog_reader /var/log/filter.log 2>&1 | tail -n 500");
269
	defCmdT("last 1000 gateways log entries","/usr/sbin/fifolog_reader /var/log/gateways.log 2>&1 | tail -n 1000");
270
	defCmdT("last 1000 IPsec log entries","/usr/sbin/fifolog_reader /var/log/ipsec.log 2>&1 | tail -n 1000");
271
	defCmdT("last 1000 L2TP log entries","/usr/sbin/fifolog_reader /var/log/l2tps.log 2>&1 | tail -n 1000");
272
	defCmdT("last 1000 NTP log entries","/usr/sbin/fifolog_reader /var/log/ntpd.log 2>&1 | tail -n 1000");
273
	defCmdT("last 1000 OpenVPN log entries","/usr/sbin/fifolog_reader /var/log/openvpn.log 2>&1 | tail -n 1000");
274
	defCmdT("last 1000 Captive Portal auth log entries","/usr/sbin/fifolog_reader /var/log/portalauth.log 2>&1 | tail -n 1000");
275
	defCmdT("last 1000 PPP log entries","/usr/sbin/fifolog_reader /var/log/poes.log 2>&1 | tail -n 1000");
276
	defCmdT("last 1000 relayd log entries","/usr/sbin/fifolog_reader /var/log/relayd.log 2>&1 | tail -n 1000");
277
	defCmdT("last 1000 resolver log entries","/usr/sbin/fifolog_reader /var/log/resolver.log 2>&1 | tail -n 1000");
278
	defCmdT("last 1000 routing log entries","/usr/sbin/fifolog_reader /var/log/routing.log 2>&1 | tail -n 1000");
279
	defCmdT("last 1000 wireless log entries","/usr/sbin/fifolog_reader /var/log/wireless.log 2>&1 | tail -n 1000");
280
} else {
281
	defCmdT("last 1000 system log entries","/usr/local/sbin/clog /var/log/system.log 2>&1 | tail -n 1000");
282
	defCmdT("last 1000 DHCP log entries","/usr/local/sbin/clog /var/log/dhcpd.log 2>&1 | tail -n 1000");
283
	defCmdT("last 500 filter log entries","/usr/local/sbin/clog /var/log/filter.log 2>&1 | tail -n 500");
284
	defCmdT("last 1000 gateways log entries","/usr/local/sbin/clog /var/log/gateways.log 2>&1 | tail -n 1000");
285
	defCmdT("last 1000 IPsec log entries","/usr/local/sbin/clog /var/log/ipsec.log 2>&1 | tail -n 1000");
286
	defCmdT("last 1000 L2TP log entries","/usr/local/sbin/clog /var/log/l2tps.log 2>&1 | tail -n 1000");
287
	defCmdT("last 1000 NTP log entries","/usr/local/sbin/clog /var/log/ntpd.log 2>&1 | tail -n 1000");
288
	defCmdT("last 1000 OpenVPN log entries","/usr/local/sbin/clog /var/log/openvpn.log 2>&1 | tail -n 1000");
289
	defCmdT("last 1000 Captive Portal auth log entries","/usr/local/sbin/clog /var/log/portalauth.log 2>&1 | tail -n 1000");
290
	defCmdT("last 1000 PPP log entries","/usr/local/sbin/clog /var/log/poes.log 2>&1 | tail -n 1000");
291
	defCmdT("last 1000 relayd log entries","/usr/local/sbin/clog /var/log/relayd.log 2>&1 | tail -n 1000");
292
	defCmdT("last 1000 resolver log entries","/usr/local/sbin/clog /var/log/resolver.log 2>&1 | tail -n 1000");
293
	defCmdT("last 1000 routing log entries","/usr/local/sbin/clog /var/log/routing.log 2>&1 | tail -n 1000");
294
	defCmdT("last 1000 wireless log entries","/usr/local/sbin/clog /var/log/wireless.log 2>&1 | tail -n 1000");
295
}
296
if (file_exists("/tmp/PHP_errors.log")) {
297
	defCmdT("PHP Error Log", "/bin/cat /tmp/PHP_errors.log");
298
}
299
defCmdT("System Message Buffer","/sbin/dmesg -a");
300
defCmdT("System Message Buffer (Boot)","/bin/cat /var/log/dmesg.boot");
301
defCmdT("sysctl values","/sbin/sysctl -a");
302

    
303
exec("/bin/date", $dateOutput, $dateStatus);
304
$currentDate = $dateOutput[0];
305

    
306
$pgtitle = array("{$g['product_name']}", "status");
307
include("head.inc");
308

    
309
print_info_box(gettext("Make sure all sensitive information is removed! (Passwords, etc.) before posting " .
310
			   "information from this page in public places (like mailing lists)") . '<br />' .
311
		gettext("Common password fields in config.xml have been automatically redacted.") . '<br />' .
312
		gettext("When the page has finished loading, the output will be stored in {$output_file}. It may be downloaded via scp or ") .
313
		"<a href=\"/exec.php?dlPath={$output_file}\">" . gettext("Diagnostics > Command Prompt") . '</a>');
314

    
315
listCmds();
316
execCmds();
317

    
318
include("foot.inc");
(161-161/234)