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