Project

General

Profile

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