Project

General

Profile

Download (9.35 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) 2013-2014 Electric Sheep Fencing, LP
12
	All rights reserved.
13

    
14
	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
*/
35
/*
36
	pfSense_BUILDER_BINARIES:	/usr/bin/vmstat	/usr/bin/netstat	/sbin/dmesg	/sbin/mount	/sbin/setkey	/usr/local/sbin/pftop	
37
	pfSense_BUILDER_BINARIES:	/sbin/pfctl	/sbin/sysctl	/usr/bin/top	/usr/bin/netstat	/sbin/pfctl	/sbin/ifconfig
38
	pfSense_MODULE:	support
39
*/
40

    
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

    
48
/* Execute a command, with a title, and generate an HTML table
49
 * showing the results.
50
 */
51

    
52
/* include all configuration functions */
53
require_once("guiconfig.inc");
54
require_once("functions.inc");
55

    
56
function doCmdT($title, $command) {
57
	$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

    
63
	if ($command == "dumpconfigxml") {
64
		$fd = @fopen("/conf/config.xml", "r");
65
		if ($fd) {
66
			while (!feof($fd)) {
67
				$line = fgets($fd);
68
				/* remove sensitive contents */
69
				$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
				$line = preg_replace("/<rocommunity>.*?<\\/rocommunity>/", "<rocommunity>xxxxx</rocommunity>", $line);
72
				$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
				$line = str_replace("\t", "    ", $line);
83
				echo htmlspecialchars($line,ENT_NOQUOTES);
84
			}
85
		}
86
		fclose($fd);
87
	} else {
88
		$execOutput = "";
89
		$execStatus = "";
90
		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
    echo "\n\t\t\t</pre>\n\t\t</td>\n\t</tr>\n";
99
    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
	doCmdT($command,$command);
105
}
106

    
107
/* Define a command, with a title, to be executed later. */
108
function defCmdT($title, $command) {
109
	global $commands;
110
	$title = htmlspecialchars($title,ENT_NOQUOTES);
111
	$commands[] = array($title, $command);
112
}
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
	defCmdT($command,$command);
119
}
120

    
121
/* List all of the commands as an index. */
122
function listCmds() {
123
	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
}
132

    
133
/* Execute all of the commands which were defined by a call to defCmd. */
134
function execCmds() {
135
	global $commands;
136
	for ($i = 0; isset($commands[$i]); $i++ ) {
137
		doCmdT($commands[$i][0], $commands[$i][1]);
138
	}
139
}
140

    
141
global $g, $config;
142

    
143
/* Set up all of the commands we want to execute. */
144
defCmdT("System uptime","uptime");
145
defCmdT("Interfaces","/sbin/ifconfig -a");
146

    
147
defCmdT("PF Info","/sbin/pfctl -s info");
148

    
149
defCmdT("Routing tables","netstat -nr");
150

    
151
defCmdT("top | head -n5", "/usr/bin/top | /usr/bin/head -n5");
152

    
153
defCmdT("sysctl hw.physmem","/sbin/sysctl hw.physmem");
154

    
155
if (isset($config['captiveportal']) && is_array($config['captiveportal'])) {
156
	foreach ($config['captiveportal'] as $cpZone => $cpdata) {
157
		if (isset($cpdata['enable']))
158
			defCmdT("ipfw -x {$cpdata['zoneid']} show", "/sbin/ipfw -x {$cpdata['zoneid']} show");
159
	}
160
}
161

    
162
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
defCmdT("pfctl -sa", "/sbin/pfctl -sa");
167
defCmdT("pfctl -s rules -vv","/sbin/pfctl -s rules -vv");
168
defCmdT("pfctl -s queue -v","/sbin/pfctl -s queue -v");
169
defCmdT("pfctl -s nat -v","/sbin/pfctl -s nat -v");
170

    
171
defCmdT("PF OSFP","/sbin/pfctl -s osfp");
172

    
173

    
174
defCmdT("netstat -s -ppfsync","netstat -s -ppfsync");
175

    
176
defCmdT("pfctl -vsq","/sbin/pfctl -vsq");
177

    
178
defCmdT("pfctl -vs Tables","/sbin/pfctl -vs Tables");
179

    
180
defCmdT("Load Balancer","/sbin/pfctl -a slb -s nat");
181

    
182
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

    
189
defCmdT("resolv.conf","cat /etc/resolv.conf");
190

    
191
defCmdT("Processes","ps xauww");
192
defCmdT("dhcpd.conf","cat /var/dhcpd/etc/dhcpd.conf");
193

    
194
defCmdT("df","/bin/df");
195

    
196
defCmdT("ipsec.conf","cat /var/etc/ipsec/ipsec.conf");
197
defCmdT("SPD","/sbin/setkey -DP");
198
defCmdT("SAD","/sbin/setkey -D");
199

    
200
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
	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
}
207
	
208
defCmd("ls /conf");
209
defCmd("ls /var/run");
210

    
211
defCmd("/sbin/mount");
212

    
213
defCmdT("cat {$g['tmp_path']}/rules.debug","cat {$g['tmp_path']}/rules.debug");
214

    
215
defCmdT("VMStat", "vmstat -afimsz");
216

    
217
defCmdT("config.xml","dumpconfigxml");
218

    
219
defCmdT("DMESG","/sbin/dmesg -a");
220

    
221
defCmdT("netstat -mb","netstat -mb");
222
defCmdT("vmstat -z","vmstat -z");
223

    
224
exec("/bin/date", $dateOutput, $dateStatus);
225
$currentDate = $dateOutput[0];
226

    
227
$pgtitle = array("{$g['product_name']}","status");
228
include("head.inc");
229

    
230
?>
231
<style type="text/css">
232
/*<![CDATA[*/
233
pre {
234
	margin: 0px;
235
	font-family: courier new, courier;
236
	font-weight: normal;
237
	font-size: 9pt;
238
}
239
/*]]>*/
240
</style>
241

    
242
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
243
<?php include("fbegin.inc"); ?>
244
<strong><?=$currentDate;?></strong>
245
<p><span class="red"><strong><?=gettext("Note: make sure to remove any sensitive information " .
246
"(passwords, maybe also IP addresses) before posting " .
247
"information from this page in public places (like mailing lists)"); ?>!</strong></span><br />
248
<?=gettext("Passwords in config.xml have been automatically removed"); ?>.
249

    
250
<div id="cmdspace" style="width:700px">
251
<?php listCmds(); ?>
252

    
253
<?php execCmds(); ?>
254
</div>
255

    
256
<?php include("fend.inc"); ?>
257
</body>
258
</html>
(179-179/256)