Project

General

Profile

Download (7.51 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("PF OSFP","/sbin/pfctl -s osfp");
146

    
147

    
148
defCmdT("netstat -s -ppfsync","netstat -s -ppfsync");
149

    
150
defCmdT("pfctl -vsq","/sbin/pfctl -vsq");
151

    
152
defCmdT("pfctl -vs Tables","pfctl -vs Tables");
153

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

    
156
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

    
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
defCmdT("SPD","/sbin/setkey -DP");
173
defCmdT("SAD","/sbin/setkey -D");
174

    
175
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
defCmd("ls /conf");
184
defCmd("ls /var/run");
185

    
186
defCmd("/sbin/mount");
187

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

    
190
defCmdT("VMStat", "vmstat -afimsz");
191

    
192
defCmdT("config.xml","dumpconfigxml");
193

    
194
defCmdT("DMESG","/sbin/dmesg -a");
195

    
196
defCmdT("netstat -mb","netstat -mb");
197
defCmdT("vmstat -z","vmstat -z");
198

    
199
exec("/bin/date", $dateOutput, $dateStatus);
200
$currentDate = $dateOutput[0];
201

    
202
$pgtitle = array("{$g['product_name']}","status");
203
include("head.inc");
204

    
205
?>
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
<?php include("fbegin.inc"); ?>
219
<strong><?=$currentDate;?></strong>
220
<p><span class="red"><strong>Note: make sure to remove any sensitive information
221
(passwords, maybe also IP addresses) before posting
222
information from this page in public places (like mailing lists)!</strong></span><br>
223
Passwords in config.xml have been automatically removed.
224

    
225
<div id="cmdspace" style="width:700px">
226
<?php listCmds(); ?>
227

    
228
<?php execCmds(); ?>
229
</div>
230

    
231
<?php include("fend.inc"); ?>
232
</body>
233
</html>
(147-147/216)