Project

General

Profile

Download (8.31 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 5b237745 Scott Ullrich
 */
9 6b07c15a Matthew Grooms
/*
10 2151894c Colin Fleming
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12
13
	1.	Redistributions of source code must retain the above copyright notice,
14
		this list of conditions and the following disclaimer.
15
16
	2.	Redistributions in binary form must reproduce the above copyright
17
		notice, this list of conditions and the following disclaimer in the
18
		documentation and/or other materials provided with the distribution.
19
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30 6b07c15a Matthew Grooms
*/
31 1d333258 Scott Ullrich
/*
32
	pfSense_BUILDER_BINARIES:	/usr/bin/vmstat	/usr/bin/netstat	/sbin/dmesg	/sbin/mount	/usr/local/sbin/setkey	/usr/local/sbin/pftop	
33
	pfSense_BUILDER_BINARIES:	/sbin/pfctl	/sbin/sysctl	/usr/bin/top	/usr/bin/netstat	/sbin/pfctl	/sbin/ifconfig
34
	pfSense_MODULE:	support
35
*/
36 6b07c15a Matthew Grooms
37
##|+PRIV
38
##|*IDENT=page-hidden-detailedstatus
39
##|*NAME=Hidden: Detailed Status page
40
##|*DESCR=Allow access to the 'Hidden: Detailed Status' page.
41
##|*MATCH=status.php*
42
##|-PRIV
43 5b237745 Scott Ullrich
44
/* Execute a command, with a title, and generate an HTML table
45
 * showing the results.
46
 */
47 1d169baa Bill Marquette
48
/* include all configuration functions */
49 f977ac60 Bill Marquette
require_once("guiconfig.inc");
50 1d169baa Bill Marquette
require_once("functions.inc");
51
52 5b237745 Scott Ullrich
function doCmdT($title, $command) {
53 2151894c Colin Fleming
	$rubbish = array('|', '-', '/', '.', ' ');  /* fixes the <a> tag to be W3C compliant */
54
	echo "\n<a name=\"" . str_replace($rubbish,'',$title) . "\" id=\"" . str_replace($rubbish,'',$title) . "\"></a>\n";
55
	echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" summary=\"" . $title . "\">\n";
56
	echo "\t<tr><td class=\"listtopic\">" . $title . "</td></tr>\n";
57
	echo "\t<tr>\n\t\t<td class=\"listlr\">\n\t\t\t<pre>";		/* no newline after pre */
58 f997992b Scott Ullrich
59 5b237745 Scott Ullrich
	if ($command == "dumpconfigxml") {
60
		$fd = @fopen("/conf/config.xml", "r");
61
		if ($fd) {
62
			while (!feof($fd)) {
63
				$line = fgets($fd);
64 70069758 Bill Marquette
				/* remove sensitive contents */
65 5b237745 Scott Ullrich
				$line = preg_replace("/<password>.*?<\\/password>/", "<password>xxxxx</password>", $line);
66
				$line = preg_replace("/<pre-shared-key>.*?<\\/pre-shared-key>/", "<pre-shared-key>xxxxx</pre-shared-key>", $line);
67 70069758 Bill Marquette
				$line = preg_replace("/<rocommunity>.*?<\\/rocommunity>/", "<rocommunity>xxxxx</rocommunity>", $line);
68 5b237745 Scott Ullrich
				$line = str_replace("\t", "    ", $line);
69
				echo htmlspecialchars($line,ENT_NOQUOTES);
70
			}
71
		}
72
		fclose($fd);
73
	} else {
74 767a716e Scott Ullrich
		$execOutput = "";
75
		$execStatus = "";
76 5b237745 Scott Ullrich
		exec ($command . " 2>&1", $execOutput, $execStatus);
77
		for ($i = 0; isset($execOutput[$i]); $i++) {
78
			if ($i > 0) {
79
				echo "\n";
80
			}
81
			echo htmlspecialchars($execOutput[$i],ENT_NOQUOTES);
82
		}
83
	}
84 2151894c Colin Fleming
    echo "\n\t\t\t</pre>\n\t\t</td>\n\t</tr>\n";
85 5b237745 Scott Ullrich
    echo "</table>\n";
86
}
87
88
/* Execute a command, giving it a title which is the same as the command. */
89
function doCmd($command) {
90 2151894c Colin Fleming
	doCmdT($command,$command);
91 5b237745 Scott Ullrich
}
92
93
/* Define a command, with a title, to be executed later. */
94
function defCmdT($title, $command) {
95 2151894c Colin Fleming
	global $commands;
96
	$title = htmlspecialchars($title,ENT_NOQUOTES);
97
	$commands[] = array($title, $command);
98 5b237745 Scott Ullrich
}
99
100
/* Define a command, with a title which is the same as the command,
101
 * to be executed later.
102
 */
103
function defCmd($command) {
104 2151894c Colin Fleming
	defCmdT($command,$command);
105 5b237745 Scott Ullrich
}
106
107
/* List all of the commands as an index. */
108
function listCmds() {
109 2151894c Colin Fleming
	global $commands;
110
	$rubbish = array('|', '-', '/', '.', ' ');  /* fixes the <a> tag to be W3C compliant */
111
	echo "\n<p>" . gettext("This status page includes the following information") . ":\n";
112
	echo "<ul>\n";
113
	for ($i = 0; isset($commands[$i]); $i++ ) {
114
		echo "\t<li><strong><a href=\"#" . str_replace($rubbish,'',$commands[$i][0]) . "\">" . $commands[$i][0] . "</a></strong></li>\n";
115
	}
116
	echo "</ul>\n";
117 5b237745 Scott Ullrich
}
118
119
/* Execute all of the commands which were defined by a call to defCmd. */
120
function execCmds() {
121 2151894c Colin Fleming
	global $commands;
122
	for ($i = 0; isset($commands[$i]); $i++ ) {
123
		doCmdT($commands[$i][0], $commands[$i][1]);
124
	}
125 5b237745 Scott Ullrich
}
126
127 58f2f42a Renato Botelho
global $g, $config;
128 1d169baa Bill Marquette
129 5b237745 Scott Ullrich
/* Set up all of the commands we want to execute. */
130
defCmdT("System uptime","uptime");
131
defCmdT("Interfaces","/sbin/ifconfig -a");
132
133 1d333258 Scott Ullrich
defCmdT("PF Info","/sbin/pfctl -s info");
134 48e07930 Scott Ullrich
135 5b237745 Scott Ullrich
defCmdT("Routing tables","netstat -nr");
136
137 37502a4a Scott Ullrich
defCmdT("top | head -n5", "/usr/bin/top | /usr/bin/head -n5");
138
139
defCmdT("sysctl hw.physmem","/sbin/sysctl hw.physmem");
140
141 baec2b00 Ermal
if (isset($config['captiveportal']) && is_array($config['captiveportal'])) {
142
	foreach ($config['captiveportal'] as $cpZone => $cpdata) {
143 58f2f42a Renato Botelho
		if (isset($cpdata['enable']))
144 baec2b00 Ermal
			defCmdT("ipfw -x {$cpdata['zoneid']} show", "/sbin/ipfw -x {$cpdata['zoneid']} show");
145
	}
146
}
147 58f2f42a Renato Botelho
148 fd69ff6e Scott Ullrich
defCmdT("pfctl -sn", "/sbin/pfctl -sn");
149
defCmdT("pfctl -sr", "/sbin/pfctl -sr");
150
defCmdT("pfctl -ss", "/sbin/pfctl -ss");
151
defCmdT("pfctl -si", "/sbin/pfctl -si");
152 3ea11e7d Scott Ullrich
defCmdT("pfctl -sa", "/sbin/pfctl -sa");
153 135c91d5 Scott Ullrich
defCmdT("pfctl -s rules -vv","/sbin/pfctl -s rules -vv");
154 ef278e47 Scott Ullrich
defCmdT("pfctl -s queue -v","/sbin/pfctl -s queue -v");
155 ebd9c6d8 Scott Ullrich
defCmdT("pfctl -s nat -v","/sbin/pfctl -s nat -v");
156 18b272e6 Scott Ullrich
157 3ea11e7d Scott Ullrich
defCmdT("PF OSFP","/sbin/pfctl -s osfp");
158
159
160 f8b5ef5c Scott Ullrich
defCmdT("netstat -s -ppfsync","netstat -s -ppfsync");
161
162 a88fe761 Scott Ullrich
defCmdT("pfctl -vsq","/sbin/pfctl -vsq");
163
164 1d333258 Scott Ullrich
defCmdT("pfctl -vs Tables","/sbin/pfctl -vs Tables");
165 18b272e6 Scott Ullrich
166 a4fb527f Scott Ullrich
defCmdT("Load Balancer","/sbin/pfctl -a slb -s nat");
167 557228e4 Scott Ullrich
168 b6f87f46 Scott Ullrich
defCmdT("pftop -w 150 -a -b","/usr/local/sbin/pftop -a -b");
169
defCmdT("pftop -w 150 -a -b -v long","/usr/local/sbin/pftop -w 150 -a -b -v long");
170
defCmdT("pftop -w 150 -a -b -v queue","/usr/local/sbin/pftop -w 150 -a -b -v queue");
171
defCmdT("pftop -w 150 -a -b -v rules","/usr/local/sbin/pftop -w 150 -a -b -v rules");
172
defCmdT("pftop -w 150 -a -b -v size","/usr/local/sbin/pftop -w 150 -a -b -v size");
173
defCmdT("pftop -w 150 -a -b -v speed","/usr/local/sbin/pftop -w 150 -a -b -v speed");
174 5b237745 Scott Ullrich
175
defCmdT("resolv.conf","cat /etc/resolv.conf");
176
177
defCmdT("Processes","ps xauww");
178 09fec59d jim-p
defCmdT("dhcpd.conf","cat /var/dhcpd/etc/dhcpd.conf");
179 5b237745 Scott Ullrich
defCmdT("ez-ipupdate.cache","cat /conf/ez-ipupdate.cache");
180
181
defCmdT("df","/bin/df");
182
183
defCmdT("racoon.conf","cat /var/etc/racoon.conf");
184 1d333258 Scott Ullrich
defCmdT("SPD","/usr/local/sbin/setkey -DP");
185
defCmdT("SAD","/usr/local/sbin/setkey -D");
186 5b237745 Scott Ullrich
187 568f30c2 Scott Ullrich
if(isset($config['system']['usefifolog']))  {
188
	defCmdT("last 200 system log entries","/usr/sbin/fifolog_reader /var/log/system.log 2>&1 | tail -n 200");
189
	defCmdT("last 50 filter log entries","/usr/sbin/fifolog_reader /var/log/filter.log 2>&1 | tail -n 50");
190
} else {
191
	defCmdT("last 200 system log entries","/usr/sbin/clog /var/log/system.log 2>&1 | tail -n 200");
192
	defCmdT("last 50 filter log entries","/usr/sbin/clog /var/log/filter.log 2>&1 | tail -n 50");
193
}
194
	
195 5b237745 Scott Ullrich
defCmd("ls /conf");
196
defCmd("ls /var/run");
197 8002c538 Scott Ullrich
198 99d907f1 Scott Ullrich
defCmd("/sbin/mount");
199
200 1d169baa Bill Marquette
defCmdT("cat {$g['tmp_path']}/rules.debug","cat {$g['tmp_path']}/rules.debug");
201 8002c538 Scott Ullrich
202 99d907f1 Scott Ullrich
defCmdT("VMStat", "vmstat -afimsz");
203 5b237745 Scott Ullrich
204 99d907f1 Scott Ullrich
defCmdT("config.xml","dumpconfigxml");
205 89a9d56b Scott Ullrich
206 c69f4c25 Scott Ullrich
defCmdT("DMESG","/sbin/dmesg -a");
207
208 9cd0b618 Scott Ullrich
defCmdT("netstat -mb","netstat -mb");
209
defCmdT("vmstat -z","vmstat -z");
210
211 5b237745 Scott Ullrich
exec("/bin/date", $dateOutput, $dateStatus);
212
$currentDate = $dateOutput[0];
213
214 36d0358b Scott Ullrich
$pgtitle = array("{$g['product_name']}","status");
215 4df96eff Scott Ullrich
include("head.inc");
216
217 5b237745 Scott Ullrich
?>
218
<style type="text/css">
219 2151894c Colin Fleming
/*<![CDATA[*/
220 5b237745 Scott Ullrich
pre {
221 2151894c Colin Fleming
	margin: 0px;
222
	font-family: courier new, courier;
223
	font-weight: normal;
224
	font-size: 9pt;
225 5b237745 Scott Ullrich
}
226 2151894c Colin Fleming
/*]]>*/
227 5b237745 Scott Ullrich
</style>
228
229
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
230 7173af6e Scott Ullrich
<?php include("fbegin.inc"); ?>
231 5b237745 Scott Ullrich
<strong><?=$currentDate;?></strong>
232 0dd3b04f Carlos Eduardo Ramos
<p><span class="red"><strong><?=gettext("Note: make sure to remove any sensitive information " .
233
"(passwords, maybe also IP addresses) before posting " .
234 2151894c Colin Fleming
"information from this page in public places (like mailing lists)"); ?>!</strong></span><br />
235 0dd3b04f Carlos Eduardo Ramos
<?=gettext("Passwords in config.xml have been automatically removed"); ?>.
236 5b237745 Scott Ullrich
237 0774ed52 Scott Ullrich
<div id="cmdspace" style="width:700px">
238 5b237745 Scott Ullrich
<?php listCmds(); ?>
239
240
<?php execCmds(); ?>
241 0774ed52 Scott Ullrich
</div>
242 5b237745 Scott Ullrich
243 7173af6e Scott Ullrich
<?php include("fend.inc"); ?>
244 5b237745 Scott Ullrich
</body>
245
</html>