Project

General

Profile

Download (5.83 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
/* Execute a command, with a title, and generate an HTML table
11
 * showing the results.
12
 */
13

    
14
/* include all configuration functions */
15
require_once("guiconfig.inc");
16
require_once("functions.inc");
17

    
18
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

    
25
	if ($command == "dumpconfigxml") {
26
		$fd = @fopen("/conf/config.xml", "r");
27
		if ($fd) {
28
			while (!feof($fd)) {
29
				$line = fgets($fd);
30
				/* remove sensitive contents */
31
				$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
				$line = preg_replace("/<rocommunity>.*?<\\/rocommunity>/", "<rocommunity>xxxxx</rocommunity>", $line);
34
				$line = str_replace("\t", "    ", $line);
35
				echo htmlspecialchars($line,ENT_NOQUOTES);
36
			}
37
		}
38
		fclose($fd);
39
	} else {
40
		$execOutput = "";
41
		$execStatus = "";
42
		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
    echo "<ul width=\"700\">\n";
78
    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
global $g;
93

    
94
/* Set up all of the commands we want to execute. */
95
defCmdT("System uptime","uptime");
96
defCmdT("Interfaces","/sbin/ifconfig -a");
97

    
98
defCmdT("Routing tables","netstat -nr");
99

    
100
defCmdT("top | head -n5", "/usr/bin/top | /usr/bin/head -n5");
101

    
102
defCmdT("sysctl hw.physmem","/sbin/sysctl hw.physmem");
103

    
104
defCmdT("ipfw show", "/sbin/ipfw show");
105
defCmdT("pfctl -sn", "/sbin/pfctl -sn");
106
defCmdT("pfctl -sr", "/sbin/pfctl -sr");
107
defCmdT("pfctl -ss", "/sbin/pfctl -ss");
108
defCmdT("pfctl -si", "/sbin/pfctl -si");
109
defCmdT("pfctl -sa"," /sbin/pfctl -sa");
110
defCmdT("pfctl -s rules -vv","/sbin/pfctl -s rules -vv");
111
defCmdT("pfctl -s queue -v","/sbin/pfctl -s queue -v");
112
defCmdT("pfctl -s nat -v","/sbin/pfctl -s nat -v");
113

    
114
defCmdT("netstat -s -ppfsync","netstat -s -ppfsync");
115

    
116
defCmdT("pfctl -vsq","/sbin/pfctl -vsq");
117

    
118
defCmdT("pfctl -vs Tables","pfctl -vs Tables");
119

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

    
122
defCmdT("pftop -w 150 -a -b","/usr/local/sbin/pftop -a -b");
123
defCmdT("pftop -w 150 -a -b -v long","/usr/local/sbin/pftop -w 150 -a -b -v long");
124
defCmdT("pftop -w 150 -a -b -v queue","/usr/local/sbin/pftop -w 150 -a -b -v queue");
125
defCmdT("pftop -w 150 -a -b -v rules","/usr/local/sbin/pftop -w 150 -a -b -v rules");
126
defCmdT("pftop -w 150 -a -b -v size","/usr/local/sbin/pftop -w 150 -a -b -v size");
127
defCmdT("pftop -w 150 -a -b -v speed","/usr/local/sbin/pftop -w 150 -a -b -v speed");
128

    
129
defCmdT("resolv.conf","cat /etc/resolv.conf");
130

    
131
defCmdT("Processes","ps xauww");
132
defCmdT("dhcpd.conf","cat /var/etc/dhcpd.conf");
133
defCmdT("ez-ipupdate.cache","cat /conf/ez-ipupdate.cache");
134

    
135
defCmdT("df","/bin/df");
136

    
137
defCmdT("racoon.conf","cat /var/etc/racoon.conf");
138
defCmdT("SPD","/usr/local/sbin/setkey -DP");
139
defCmdT("SAD","/usr/local/sbin/setkey -D");
140

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

    
144
defCmd("ls /conf");
145
defCmd("ls /var/run");
146

    
147
defCmd("/sbin/mount");
148

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

    
151
defCmdT("VMStat", "vmstat -afimsz");
152

    
153
defCmdT("config.xml","dumpconfigxml");
154

    
155
defCmdT("DMESG","/sbin/dmesg -a");
156

    
157
defCmdT("netstat -mb","netstat -mb");
158
defCmdT("vmstat -z","vmstat -z");
159

    
160
exec("/bin/date", $dateOutput, $dateStatus);
161
$currentDate = $dateOutput[0];
162

    
163
$pgtitle = $g['product_name'] . ": status";
164
include("head.inc");
165

    
166
?>
167
<style type="text/css">
168
<!--
169
pre {
170
   margin: 0px;
171
   font-family: courier new, courier;
172
   font-weight: normal;
173
   font-size: 9pt;
174
}
175
-->
176
</style>
177

    
178
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
179
<?php include("fbegin.inc"); ?>
180
<p><span class="pgtitle"><?=$pgtitle;?></span><br>
181
<strong><?=$currentDate;?></strong>
182
<p><span class="red"><strong>Note: make sure to remove any sensitive information
183
(passwords, maybe also IP addresses) before posting
184
information from this page in public places (like mailing lists)!</strong></span><br>
185
Passwords in config.xml have been automatically removed.
186

    
187
<div id="cmdspace" style="width:700px">
188
<?php listCmds(); ?>
189

    
190
<?php execCmds(); ?>
191
</div>
192

    
193
<?php include("fend.inc"); ?>
194
</body>
195
</html>
(124-124/175)