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
|
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
|
*/
|
31
|
/*
|
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
|
|
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
|
|
44
|
/* Execute a command, with a title, and generate an HTML table
|
45
|
* showing the results.
|
46
|
*/
|
47
|
|
48
|
/* include all configuration functions */
|
49
|
require_once("guiconfig.inc");
|
50
|
require_once("functions.inc");
|
51
|
|
52
|
function doCmdT($title, $command) {
|
53
|
echo "<p>\n";
|
54
|
echo "<a name=\"" . $title . "\">\n";
|
55
|
echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
|
56
|
echo "<tr><td class=\"listtopic\">" . $title . "</td></tr>\n";
|
57
|
echo "<tr><td class=\"listlr\"><pre>"; /* no newline after pre */
|
58
|
|
59
|
if ($command == "dumpconfigxml") {
|
60
|
$fd = @fopen("/conf/config.xml", "r");
|
61
|
if ($fd) {
|
62
|
while (!feof($fd)) {
|
63
|
$line = fgets($fd);
|
64
|
/* remove sensitive contents */
|
65
|
$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
|
$line = preg_replace("/<rocommunity>.*?<\\/rocommunity>/", "<rocommunity>xxxxx</rocommunity>", $line);
|
68
|
$line = str_replace("\t", " ", $line);
|
69
|
echo htmlspecialchars($line,ENT_NOQUOTES);
|
70
|
}
|
71
|
}
|
72
|
fclose($fd);
|
73
|
} else {
|
74
|
$execOutput = "";
|
75
|
$execStatus = "";
|
76
|
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
|
echo "</pre></tr>\n";
|
85
|
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
|
doCmdT($command,$command);
|
91
|
}
|
92
|
|
93
|
/* Define a command, with a title, to be executed later. */
|
94
|
function defCmdT($title, $command) {
|
95
|
global $commands;
|
96
|
$title = htmlspecialchars($title,ENT_NOQUOTES);
|
97
|
$commands[] = array($title, $command);
|
98
|
}
|
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
|
defCmdT($command,$command);
|
105
|
}
|
106
|
|
107
|
/* List all of the commands as an index. */
|
108
|
function listCmds() {
|
109
|
global $commands;
|
110
|
echo "<p>This status page includes the following information:\n";
|
111
|
echo "<ul width=\"700\">\n";
|
112
|
for ($i = 0; isset($commands[$i]); $i++ ) {
|
113
|
echo "<li><strong><a href=\"#" . $commands[$i][0] . "\">" . $commands[$i][0] . "</a></strong>\n";
|
114
|
}
|
115
|
echo "</ul>\n";
|
116
|
}
|
117
|
|
118
|
/* Execute all of the commands which were defined by a call to defCmd. */
|
119
|
function execCmds() {
|
120
|
global $commands;
|
121
|
for ($i = 0; isset($commands[$i]); $i++ ) {
|
122
|
doCmdT($commands[$i][0], $commands[$i][1]);
|
123
|
}
|
124
|
}
|
125
|
|
126
|
global $g;
|
127
|
|
128
|
/* Set up all of the commands we want to execute. */
|
129
|
defCmdT("System uptime","uptime");
|
130
|
defCmdT("Interfaces","/sbin/ifconfig -a");
|
131
|
|
132
|
defCmdT("PF Info","/sbin/pfctl -s info");
|
133
|
|
134
|
defCmdT("Routing tables","netstat -nr");
|
135
|
|
136
|
defCmdT("top | head -n5", "/usr/bin/top | /usr/bin/head -n5");
|
137
|
|
138
|
defCmdT("sysctl hw.physmem","/sbin/sysctl hw.physmem");
|
139
|
|
140
|
defCmdT("ipfw show", "/sbin/ipfw show");
|
141
|
defCmdT("pfctl -sn", "/sbin/pfctl -sn");
|
142
|
defCmdT("pfctl -sr", "/sbin/pfctl -sr");
|
143
|
defCmdT("pfctl -ss", "/sbin/pfctl -ss");
|
144
|
defCmdT("pfctl -si", "/sbin/pfctl -si");
|
145
|
defCmdT("pfctl -sa", "/sbin/pfctl -sa");
|
146
|
defCmdT("pfctl -s rules -vv","/sbin/pfctl -s rules -vv");
|
147
|
defCmdT("pfctl -s queue -v","/sbin/pfctl -s queue -v");
|
148
|
defCmdT("pfctl -s nat -v","/sbin/pfctl -s nat -v");
|
149
|
|
150
|
defCmdT("PF OSFP","/sbin/pfctl -s osfp");
|
151
|
|
152
|
|
153
|
defCmdT("netstat -s -ppfsync","netstat -s -ppfsync");
|
154
|
|
155
|
defCmdT("pfctl -vsq","/sbin/pfctl -vsq");
|
156
|
|
157
|
defCmdT("pfctl -vs Tables","/sbin/pfctl -vs Tables");
|
158
|
|
159
|
defCmdT("Load Balancer","/sbin/pfctl -a slb -s nat");
|
160
|
|
161
|
defCmdT("pftop -w 150 -a -b","/usr/local/sbin/pftop -a -b");
|
162
|
defCmdT("pftop -w 150 -a -b -v long","/usr/local/sbin/pftop -w 150 -a -b -v long");
|
163
|
defCmdT("pftop -w 150 -a -b -v queue","/usr/local/sbin/pftop -w 150 -a -b -v queue");
|
164
|
defCmdT("pftop -w 150 -a -b -v rules","/usr/local/sbin/pftop -w 150 -a -b -v rules");
|
165
|
defCmdT("pftop -w 150 -a -b -v size","/usr/local/sbin/pftop -w 150 -a -b -v size");
|
166
|
defCmdT("pftop -w 150 -a -b -v speed","/usr/local/sbin/pftop -w 150 -a -b -v speed");
|
167
|
|
168
|
defCmdT("resolv.conf","cat /etc/resolv.conf");
|
169
|
|
170
|
defCmdT("Processes","ps xauww");
|
171
|
defCmdT("dhcpd.conf","cat /var/etc/dhcpd.conf");
|
172
|
defCmdT("ez-ipupdate.cache","cat /conf/ez-ipupdate.cache");
|
173
|
|
174
|
defCmdT("df","/bin/df");
|
175
|
|
176
|
defCmdT("racoon.conf","cat /var/etc/racoon.conf");
|
177
|
defCmdT("SPD","/usr/local/sbin/setkey -DP");
|
178
|
defCmdT("SAD","/usr/local/sbin/setkey -D");
|
179
|
|
180
|
if(isset($config['system']['usefifolog'])) {
|
181
|
defCmdT("last 200 system log entries","/usr/sbin/fifolog_reader /var/log/system.log 2>&1 | tail -n 200");
|
182
|
defCmdT("last 50 filter log entries","/usr/sbin/fifolog_reader /var/log/filter.log 2>&1 | tail -n 50");
|
183
|
} else {
|
184
|
defCmdT("last 200 system log entries","/usr/sbin/clog /var/log/system.log 2>&1 | tail -n 200");
|
185
|
defCmdT("last 50 filter log entries","/usr/sbin/clog /var/log/filter.log 2>&1 | tail -n 50");
|
186
|
}
|
187
|
|
188
|
defCmd("ls /conf");
|
189
|
defCmd("ls /var/run");
|
190
|
|
191
|
defCmd("/sbin/mount");
|
192
|
|
193
|
defCmdT("cat {$g['tmp_path']}/rules.debug","cat {$g['tmp_path']}/rules.debug");
|
194
|
|
195
|
defCmdT("VMStat", "vmstat -afimsz");
|
196
|
|
197
|
defCmdT("config.xml","dumpconfigxml");
|
198
|
|
199
|
defCmdT("DMESG","/sbin/dmesg -a");
|
200
|
|
201
|
defCmdT("netstat -mb","netstat -mb");
|
202
|
defCmdT("vmstat -z","vmstat -z");
|
203
|
|
204
|
exec("/bin/date", $dateOutput, $dateStatus);
|
205
|
$currentDate = $dateOutput[0];
|
206
|
|
207
|
$pgtitle = array("{$g['product_name']}","status");
|
208
|
include("head.inc");
|
209
|
|
210
|
?>
|
211
|
<style type="text/css">
|
212
|
<!--
|
213
|
pre {
|
214
|
margin: 0px;
|
215
|
font-family: courier new, courier;
|
216
|
font-weight: normal;
|
217
|
font-size: 9pt;
|
218
|
}
|
219
|
-->
|
220
|
</style>
|
221
|
|
222
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
223
|
<?php include("fbegin.inc"); ?>
|
224
|
<strong><?=$currentDate;?></strong>
|
225
|
<p><span class="red"><strong>Note: make sure to remove any sensitive information
|
226
|
(passwords, maybe also IP addresses) before posting
|
227
|
information from this page in public places (like mailing lists)!</strong></span><br>
|
228
|
Passwords in config.xml have been automatically removed.
|
229
|
|
230
|
<div id="cmdspace" style="width:700px">
|
231
|
<?php listCmds(); ?>
|
232
|
|
233
|
<?php execCmds(); ?>
|
234
|
</div>
|
235
|
|
236
|
<?php include("fend.inc"); ?>
|
237
|
</body>
|
238
|
</html>
|