Project

General

Profile

Download (7.2 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
    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

    
39
/* Execute a command, with a title, and generate an HTML table
40
 * showing the results.
41
 */
42

    
43
/* include all configuration functions */
44
require_once("guiconfig.inc");
45
require_once("functions.inc");
46

    
47
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

    
54
	if ($command == "dumpconfigxml") {
55
		$fd = @fopen("/conf/config.xml", "r");
56
		if ($fd) {
57
			while (!feof($fd)) {
58
				$line = fgets($fd);
59
				/* remove sensitive contents */
60
				$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
				$line = preg_replace("/<rocommunity>.*?<\\/rocommunity>/", "<rocommunity>xxxxx</rocommunity>", $line);
63
				$line = str_replace("\t", "    ", $line);
64
				echo htmlspecialchars($line,ENT_NOQUOTES);
65
			}
66
		}
67
		fclose($fd);
68
	} else {
69
		$execOutput = "";
70
		$execStatus = "";
71
		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
    echo "<ul width=\"700\">\n";
107
    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
global $g;
122

    
123
/* Set up all of the commands we want to execute. */
124
defCmdT("System uptime","uptime");
125
defCmdT("Interfaces","/sbin/ifconfig -a");
126

    
127
defCmdT("PF Info","pfctl -s info");
128

    
129
defCmdT("Routing tables","netstat -nr");
130

    
131
defCmdT("top | head -n5", "/usr/bin/top | /usr/bin/head -n5");
132

    
133
defCmdT("sysctl hw.physmem","/sbin/sysctl hw.physmem");
134

    
135
defCmdT("ipfw show", "/sbin/ipfw show");
136
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
defCmdT("pfctl -sa"," /sbin/pfctl -sa");
141
defCmdT("pfctl -s rules -vv","/sbin/pfctl -s rules -vv");
142
defCmdT("pfctl -s queue -v","/sbin/pfctl -s queue -v");
143
defCmdT("pfctl -s nat -v","/sbin/pfctl -s nat -v");
144

    
145
defCmdT("netstat -s -ppfsync","netstat -s -ppfsync");
146

    
147
defCmdT("pfctl -vsq","/sbin/pfctl -vsq");
148

    
149
defCmdT("pfctl -vs Tables","pfctl -vs Tables");
150

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

    
153
defCmdT("pftop -w 150 -a -b","/usr/local/sbin/pftop -a -b");
154
defCmdT("pftop -w 150 -a -b -v long","/usr/local/sbin/pftop -w 150 -a -b -v long");
155
defCmdT("pftop -w 150 -a -b -v queue","/usr/local/sbin/pftop -w 150 -a -b -v queue");
156
defCmdT("pftop -w 150 -a -b -v rules","/usr/local/sbin/pftop -w 150 -a -b -v rules");
157
defCmdT("pftop -w 150 -a -b -v size","/usr/local/sbin/pftop -w 150 -a -b -v size");
158
defCmdT("pftop -w 150 -a -b -v speed","/usr/local/sbin/pftop -w 150 -a -b -v speed");
159

    
160
defCmdT("resolv.conf","cat /etc/resolv.conf");
161

    
162
defCmdT("Processes","ps xauww");
163
defCmdT("dhcpd.conf","cat /var/etc/dhcpd.conf");
164
defCmdT("ez-ipupdate.cache","cat /conf/ez-ipupdate.cache");
165

    
166
defCmdT("df","/bin/df");
167

    
168
defCmdT("racoon.conf","cat /var/etc/racoon.conf");
169
defCmdT("SPD","/sbin/setkey -DP");
170
defCmdT("SAD","/sbin/setkey -D");
171

    
172
defCmdT("last 200 system log entries","/usr/sbin/clog /var/log/system.log 2>&1 | tail -n 200");
173
defCmdT("last 50 filter log entries","/usr/sbin/clog /var/log/filter.log 2>&1 | tail -n 50");
174

    
175
defCmd("ls /conf");
176
defCmd("ls /var/run");
177

    
178
defCmd("/sbin/mount");
179

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

    
182
defCmdT("VMStat", "vmstat -afimsz");
183

    
184
defCmdT("config.xml","dumpconfigxml");
185

    
186
defCmdT("DMESG","/sbin/dmesg -a");
187

    
188
defCmdT("netstat -mb","netstat -mb");
189
defCmdT("vmstat -z","vmstat -z");
190

    
191
exec("/bin/date", $dateOutput, $dateStatus);
192
$currentDate = $dateOutput[0];
193

    
194
$pgtitle = array("{$g['product_name']}","status");
195
include("head.inc");
196

    
197
?>
198
<style type="text/css">
199
<!--
200
pre {
201
   margin: 0px;
202
   font-family: courier new, courier;
203
   font-weight: normal;
204
   font-size: 9pt;
205
}
206
-->
207
</style>
208

    
209
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
210
<?php include("fbegin.inc"); ?>
211
<strong><?=$currentDate;?></strong>
212
<p><span class="red"><strong>Note: make sure to remove any sensitive information
213
(passwords, maybe also IP addresses) before posting
214
information from this page in public places (like mailing lists)!</strong></span><br>
215
Passwords in config.xml have been automatically removed.
216

    
217
<div id="cmdspace" style="width:700px">
218
<?php listCmds(); ?>
219

    
220
<?php execCmds(); ?>
221
</div>
222

    
223
<?php include("fend.inc"); ?>
224
</body>
225
</html>
(145-145/210)