Project

General

Profile

Download (9.35 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 ed2d1343 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
56 5b237745 Scott Ullrich
function doCmdT($title, $command) {
57 2151894c Colin Fleming
	$rubbish = array('|', '-', '/', '.', ' ');  /* fixes the <a> tag to be W3C compliant */
58
	echo "\n<a name=\"" . str_replace($rubbish,'',$title) . "\" id=\"" . str_replace($rubbish,'',$title) . "\"></a>\n";
59
	echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" summary=\"" . $title . "\">\n";
60
	echo "\t<tr><td class=\"listtopic\">" . $title . "</td></tr>\n";
61
	echo "\t<tr>\n\t\t<td class=\"listlr\">\n\t\t\t<pre>";		/* no newline after pre */
62 f997992b Scott Ullrich
63 5b237745 Scott Ullrich
	if ($command == "dumpconfigxml") {
64
		$fd = @fopen("/conf/config.xml", "r");
65
		if ($fd) {
66
			while (!feof($fd)) {
67
				$line = fgets($fd);
68 70069758 Bill Marquette
				/* remove sensitive contents */
69 5b237745 Scott Ullrich
				$line = preg_replace("/<password>.*?<\\/password>/", "<password>xxxxx</password>", $line);
70
				$line = preg_replace("/<pre-shared-key>.*?<\\/pre-shared-key>/", "<pre-shared-key>xxxxx</pre-shared-key>", $line);
71 70069758 Bill Marquette
				$line = preg_replace("/<rocommunity>.*?<\\/rocommunity>/", "<rocommunity>xxxxx</rocommunity>", $line);
72 8a2229e3 jim-p
				$line = preg_replace("/<prv>.*?<\\/prv>/", "<prv>xxxxx</prv>", $line);
73
				$line = preg_replace("/<ipsecpsk>.*?<\\/ipsecpsk>/", "<ipsecpsk>xxxxx</ipsecpsk>", $line);
74
				$line = preg_replace("/<md5-hash>.*?<\\/md5-hash>/", "<md5-hash>xxxxx</md5-hash>", $line);
75
				$line = preg_replace("/<md5password>.*?<\\/md5password>/", "<md5password>xxxxx</md5password>", $line);
76
				$line = preg_replace("/<nt-hash>.*?<\\/nt-hash>/", "<nt-hash>xxxxx</nt-hash>", $line);
77
				$line = preg_replace("/<radius_secret>.*?<\\/radius_secret>/", "<radius_secret>xxxxx</radius_secret>", $line);
78
				$line = preg_replace("/<ldap_bindpw>.*?<\\/ldap_bindpw>/", "<ldap_bindpw>xxxxx</ldap_bindpw>", $line);
79
				$line = preg_replace("/<passwordagain>.*?<\\/passwordagain>/", "<passwordagain>xxxxx</passwordagain>", $line);
80
				$line = preg_replace("/<crypto_password>.*?<\\/crypto_password>/", "<crypto_password>xxxxx</crypto_password>", $line);
81
				$line = preg_replace("/<crypto_password2>.*?<\\/crypto_password2>/", "<crypto_password2>xxxxx</crypto_password2>", $line);
82 5b237745 Scott Ullrich
				$line = str_replace("\t", "    ", $line);
83
				echo htmlspecialchars($line,ENT_NOQUOTES);
84
			}
85
		}
86
		fclose($fd);
87
	} else {
88 767a716e Scott Ullrich
		$execOutput = "";
89
		$execStatus = "";
90 5b237745 Scott Ullrich
		exec ($command . " 2>&1", $execOutput, $execStatus);
91
		for ($i = 0; isset($execOutput[$i]); $i++) {
92
			if ($i > 0) {
93
				echo "\n";
94
			}
95
			echo htmlspecialchars($execOutput[$i],ENT_NOQUOTES);
96
		}
97
	}
98 2151894c Colin Fleming
    echo "\n\t\t\t</pre>\n\t\t</td>\n\t</tr>\n";
99 5b237745 Scott Ullrich
    echo "</table>\n";
100
}
101
102
/* Execute a command, giving it a title which is the same as the command. */
103
function doCmd($command) {
104 2151894c Colin Fleming
	doCmdT($command,$command);
105 5b237745 Scott Ullrich
}
106
107
/* Define a command, with a title, to be executed later. */
108
function defCmdT($title, $command) {
109 2151894c Colin Fleming
	global $commands;
110
	$title = htmlspecialchars($title,ENT_NOQUOTES);
111
	$commands[] = array($title, $command);
112 5b237745 Scott Ullrich
}
113
114
/* Define a command, with a title which is the same as the command,
115
 * to be executed later.
116
 */
117
function defCmd($command) {
118 2151894c Colin Fleming
	defCmdT($command,$command);
119 5b237745 Scott Ullrich
}
120
121
/* List all of the commands as an index. */
122
function listCmds() {
123 2151894c Colin Fleming
	global $commands;
124
	$rubbish = array('|', '-', '/', '.', ' ');  /* fixes the <a> tag to be W3C compliant */
125
	echo "\n<p>" . gettext("This status page includes the following information") . ":\n";
126
	echo "<ul>\n";
127
	for ($i = 0; isset($commands[$i]); $i++ ) {
128
		echo "\t<li><strong><a href=\"#" . str_replace($rubbish,'',$commands[$i][0]) . "\">" . $commands[$i][0] . "</a></strong></li>\n";
129
	}
130
	echo "</ul>\n";
131 5b237745 Scott Ullrich
}
132
133
/* Execute all of the commands which were defined by a call to defCmd. */
134
function execCmds() {
135 2151894c Colin Fleming
	global $commands;
136
	for ($i = 0; isset($commands[$i]); $i++ ) {
137
		doCmdT($commands[$i][0], $commands[$i][1]);
138
	}
139 5b237745 Scott Ullrich
}
140
141 58f2f42a Renato Botelho
global $g, $config;
142 1d169baa Bill Marquette
143 5b237745 Scott Ullrich
/* Set up all of the commands we want to execute. */
144
defCmdT("System uptime","uptime");
145
defCmdT("Interfaces","/sbin/ifconfig -a");
146
147 1d333258 Scott Ullrich
defCmdT("PF Info","/sbin/pfctl -s info");
148 48e07930 Scott Ullrich
149 5b237745 Scott Ullrich
defCmdT("Routing tables","netstat -nr");
150
151 37502a4a Scott Ullrich
defCmdT("top | head -n5", "/usr/bin/top | /usr/bin/head -n5");
152
153
defCmdT("sysctl hw.physmem","/sbin/sysctl hw.physmem");
154
155 baec2b00 Ermal
if (isset($config['captiveportal']) && is_array($config['captiveportal'])) {
156
	foreach ($config['captiveportal'] as $cpZone => $cpdata) {
157 58f2f42a Renato Botelho
		if (isset($cpdata['enable']))
158 baec2b00 Ermal
			defCmdT("ipfw -x {$cpdata['zoneid']} show", "/sbin/ipfw -x {$cpdata['zoneid']} show");
159
	}
160
}
161 58f2f42a Renato Botelho
162 fd69ff6e Scott Ullrich
defCmdT("pfctl -sn", "/sbin/pfctl -sn");
163
defCmdT("pfctl -sr", "/sbin/pfctl -sr");
164
defCmdT("pfctl -ss", "/sbin/pfctl -ss");
165
defCmdT("pfctl -si", "/sbin/pfctl -si");
166 3ea11e7d Scott Ullrich
defCmdT("pfctl -sa", "/sbin/pfctl -sa");
167 135c91d5 Scott Ullrich
defCmdT("pfctl -s rules -vv","/sbin/pfctl -s rules -vv");
168 ef278e47 Scott Ullrich
defCmdT("pfctl -s queue -v","/sbin/pfctl -s queue -v");
169 ebd9c6d8 Scott Ullrich
defCmdT("pfctl -s nat -v","/sbin/pfctl -s nat -v");
170 18b272e6 Scott Ullrich
171 3ea11e7d Scott Ullrich
defCmdT("PF OSFP","/sbin/pfctl -s osfp");
172
173
174 f8b5ef5c Scott Ullrich
defCmdT("netstat -s -ppfsync","netstat -s -ppfsync");
175
176 a88fe761 Scott Ullrich
defCmdT("pfctl -vsq","/sbin/pfctl -vsq");
177
178 1d333258 Scott Ullrich
defCmdT("pfctl -vs Tables","/sbin/pfctl -vs Tables");
179 18b272e6 Scott Ullrich
180 a4fb527f Scott Ullrich
defCmdT("Load Balancer","/sbin/pfctl -a slb -s nat");
181 557228e4 Scott Ullrich
182 b6f87f46 Scott Ullrich
defCmdT("pftop -w 150 -a -b","/usr/local/sbin/pftop -a -b");
183
defCmdT("pftop -w 150 -a -b -v long","/usr/local/sbin/pftop -w 150 -a -b -v long");
184
defCmdT("pftop -w 150 -a -b -v queue","/usr/local/sbin/pftop -w 150 -a -b -v queue");
185
defCmdT("pftop -w 150 -a -b -v rules","/usr/local/sbin/pftop -w 150 -a -b -v rules");
186
defCmdT("pftop -w 150 -a -b -v size","/usr/local/sbin/pftop -w 150 -a -b -v size");
187
defCmdT("pftop -w 150 -a -b -v speed","/usr/local/sbin/pftop -w 150 -a -b -v speed");
188 5b237745 Scott Ullrich
189
defCmdT("resolv.conf","cat /etc/resolv.conf");
190
191
defCmdT("Processes","ps xauww");
192 09fec59d jim-p
defCmdT("dhcpd.conf","cat /var/dhcpd/etc/dhcpd.conf");
193 5b237745 Scott Ullrich
194
defCmdT("df","/bin/df");
195
196 5f875147 Ermal
defCmdT("ipsec.conf","cat /var/etc/ipsec/ipsec.conf");
197 30c591d6 Ermal
defCmdT("SPD","/sbin/setkey -DP");
198
defCmdT("SAD","/sbin/setkey -D");
199 5b237745 Scott Ullrich
200 568f30c2 Scott Ullrich
if(isset($config['system']['usefifolog']))  {
201
	defCmdT("last 200 system log entries","/usr/sbin/fifolog_reader /var/log/system.log 2>&1 | tail -n 200");
202
	defCmdT("last 50 filter log entries","/usr/sbin/fifolog_reader /var/log/filter.log 2>&1 | tail -n 50");
203
} else {
204 2a50fd8a Renato Botelho
	defCmdT("last 200 system log entries","/usr/local/sbin/clog /var/log/system.log 2>&1 | tail -n 200");
205
	defCmdT("last 50 filter log entries","/usr/local/sbin/clog /var/log/filter.log 2>&1 | tail -n 50");
206 568f30c2 Scott Ullrich
}
207
	
208 5b237745 Scott Ullrich
defCmd("ls /conf");
209
defCmd("ls /var/run");
210 8002c538 Scott Ullrich
211 99d907f1 Scott Ullrich
defCmd("/sbin/mount");
212
213 1d169baa Bill Marquette
defCmdT("cat {$g['tmp_path']}/rules.debug","cat {$g['tmp_path']}/rules.debug");
214 8002c538 Scott Ullrich
215 99d907f1 Scott Ullrich
defCmdT("VMStat", "vmstat -afimsz");
216 5b237745 Scott Ullrich
217 99d907f1 Scott Ullrich
defCmdT("config.xml","dumpconfigxml");
218 89a9d56b Scott Ullrich
219 c69f4c25 Scott Ullrich
defCmdT("DMESG","/sbin/dmesg -a");
220
221 9cd0b618 Scott Ullrich
defCmdT("netstat -mb","netstat -mb");
222
defCmdT("vmstat -z","vmstat -z");
223
224 5b237745 Scott Ullrich
exec("/bin/date", $dateOutput, $dateStatus);
225
$currentDate = $dateOutput[0];
226
227 36d0358b Scott Ullrich
$pgtitle = array("{$g['product_name']}","status");
228 4df96eff Scott Ullrich
include("head.inc");
229
230 5b237745 Scott Ullrich
?>
231
<style type="text/css">
232 2151894c Colin Fleming
/*<![CDATA[*/
233 5b237745 Scott Ullrich
pre {
234 2151894c Colin Fleming
	margin: 0px;
235
	font-family: courier new, courier;
236
	font-weight: normal;
237
	font-size: 9pt;
238 5b237745 Scott Ullrich
}
239 2151894c Colin Fleming
/*]]>*/
240 5b237745 Scott Ullrich
</style>
241
242
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
243 7173af6e Scott Ullrich
<?php include("fbegin.inc"); ?>
244 5b237745 Scott Ullrich
<strong><?=$currentDate;?></strong>
245 0dd3b04f Carlos Eduardo Ramos
<p><span class="red"><strong><?=gettext("Note: make sure to remove any sensitive information " .
246
"(passwords, maybe also IP addresses) before posting " .
247 2151894c Colin Fleming
"information from this page in public places (like mailing lists)"); ?>!</strong></span><br />
248 0dd3b04f Carlos Eduardo Ramos
<?=gettext("Passwords in config.xml have been automatically removed"); ?>.
249 5b237745 Scott Ullrich
250 0774ed52 Scott Ullrich
<div id="cmdspace" style="width:700px">
251 5b237745 Scott Ullrich
<?php listCmds(); ?>
252
253
<?php execCmds(); ?>
254 0774ed52 Scott Ullrich
</div>
255 5b237745 Scott Ullrich
256 7173af6e Scott Ullrich
<?php include("fend.inc"); ?>
257 5b237745 Scott Ullrich
</body>
258
</html>