Project

General

Profile

Download (5.39 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/* $Id$ */
4
/* Run various commands and collect their output into HTML tables.
5
 * Jim McBeath <jimmc@macrovision.com> Nov 2003
6
 *
7
 * (modified for m0n0wall by Manuel Kasper <mk@neon1.net>)
8
 * (modified for pfSense by Scott Ullrich geekgod@pfsense.com)
9
 */
10

    
11
/* Execute a command, with a title, and generate an HTML table
12
 * showing the results.
13
 */
14

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

    
19
function doCmdT($title, $command) {
20
    echo "<p>\n";
21
    echo "<a name=\"" . $title . "\">\n";
22
    echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
23
    echo "<tr><td class=\"listtopic\">" . $title . "</td></tr>\n";
24
    echo "<tr><td class=\"listlr\"><pre>";		/* no newline after pre */
25

    
26
	if ($command == "dumpconfigxml") {
27
		$fd = @fopen("/conf/config.xml", "r");
28
		if ($fd) {
29
			while (!feof($fd)) {
30
				$line = fgets($fd);
31
				/* remove sensitive contents */
32
				$line = preg_replace("/<password>.*?<\\/password>/", "<password>xxxxx</password>", $line);
33
				$line = preg_replace("/<pre-shared-key>.*?<\\/pre-shared-key>/", "<pre-shared-key>xxxxx</pre-shared-key>", $line);
34
				$line = preg_replace("/<rocommunity>.*?<\\/rocommunity>/", "<rocommunity>xxxxx</rocommunity>", $line);
35
				$line = str_replace("\t", "    ", $line);
36
				echo htmlspecialchars($line,ENT_NOQUOTES);
37
			}
38
		}
39
		fclose($fd);
40
	} else {
41
		exec ($command . " 2>&1", $execOutput, $execStatus);
42
		for ($i = 0; isset($execOutput[$i]); $i++) {
43
			if ($i > 0) {
44
				echo "\n";
45
			}
46
			echo htmlspecialchars($execOutput[$i],ENT_NOQUOTES);
47
		}
48
	}
49
    echo "</pre></tr>\n";
50
    echo "</table>\n";
51
}
52

    
53
/* Execute a command, giving it a title which is the same as the command. */
54
function doCmd($command) {
55
    doCmdT($command,$command);
56
}
57

    
58
/* Define a command, with a title, to be executed later. */
59
function defCmdT($title, $command) {
60
    global $commands;
61
    $title = htmlspecialchars($title,ENT_NOQUOTES);
62
    $commands[] = array($title, $command);
63
}
64

    
65
/* Define a command, with a title which is the same as the command,
66
 * to be executed later.
67
 */
68
function defCmd($command) {
69
    defCmdT($command,$command);
70
}
71

    
72
/* List all of the commands as an index. */
73
function listCmds() {
74
    global $commands;
75
    echo "<p>This status page includes the following information:\n";
76
    echo "<ul width=\"700\">\n";
77
    for ($i = 0; isset($commands[$i]); $i++ ) {
78
        echo "<li><strong><a href=\"#" . $commands[$i][0] . "\">" . $commands[$i][0] . "</a></strong>\n";
79
    }
80
    echo "</ul>\n";
81
}
82

    
83
/* Execute all of the commands which were defined by a call to defCmd. */
84
function execCmds() {
85
    global $commands;
86
    for ($i = 0; isset($commands[$i]); $i++ ) {
87
        doCmdT($commands[$i][0], $commands[$i][1]);
88
    }
89
}
90

    
91
global $g;
92

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

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

    
99
defCmdT("ipfw show", "/sbin/ipfw show");
100
defCmdT("pfctl -sn", "/sbin/pfctl -sn");
101
defCmdT("pfctl -sr", "/sbin/pfctl -sr");
102
defCmdT("pfctl -ss", "/sbin/pfctl -ss");
103
defCmdT("pfctl -si", "/sbin/pfctl -si");
104
defCmdT("pfctl -sa"," /sbin/pfctl -sa");
105
defCmdT("pfctl -s rules -vv","/sbin/pfctl -s rules -vv");
106
defCmdT("pfctl -s queue -vv","/sbin/pfctl -s queue -vv");
107
defCmdT("pfctl -vsq","/sbin/pfctl -vsq");
108

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

    
111
defCmdT("pftop -w 150 -a -b","/usr/local/sbin/pftop -a -b");
112
defCmdT("pftop -w 150 -a -b -v long","/usr/local/sbin/pftop -w 150 -a -b -v long");
113
defCmdT("pftop -w 150 -a -b -v queue","/usr/local/sbin/pftop -w 150 -a -b -v queue");
114
defCmdT("pftop -w 150 -a -b -v rules","/usr/local/sbin/pftop -w 150 -a -b -v rules");
115
defCmdT("pftop -w 150 -a -b -v size","/usr/local/sbin/pftop -w 150 -a -b -v size");
116
defCmdT("pftop -w 150 -a -b -v speed","/usr/local/sbin/pftop -w 150 -a -b -v speed");
117

    
118
defCmdT("resolv.conf","cat /etc/resolv.conf");
119

    
120
defCmdT("Processes","ps xauww");
121
defCmdT("dhcpd.conf","cat /var/etc/dhcpd.conf");
122
defCmdT("ez-ipupdate.cache","cat /conf/ez-ipupdate.cache");
123

    
124
defCmdT("df","/bin/df");
125

    
126
defCmdT("racoon.conf","cat /var/etc/racoon.conf");
127
defCmdT("SPD","/usr/sbin/setkey -DP");
128
defCmdT("SAD","/usr/sbin/setkey -D");
129

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

    
133
defCmd("ls /conf");
134
defCmd("ls /var/run");
135

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

    
138
defCmdT("config.xml","dumpconfigxml");
139

    
140
defCmdT("Interrupts", "vmstat -i");
141

    
142
exec("/bin/date", $dateOutput, $dateStatus);
143
$currentDate = $dateOutput[0];
144

    
145
$pgtitle = "pfSense: status";
146
include("head.inc");
147

    
148
?>
149
<style type="text/css">
150
<!--
151
pre {
152
   margin: 0px;
153
   font-family: courier new, courier;
154
   font-weight: normal;
155
   font-size: 9pt;
156
}
157
-->
158
</style>
159

    
160
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
161
<?php include("fbegin.inc"); ?>
162
<p><span class="pgtitle"><?=$pgtitle;?></span><br>
163
<strong><?=$currentDate;?></strong>
164
<p><span class="red"><strong>Note: make sure to remove any sensitive information
165
(passwords, maybe also IP addresses) before posting
166
information from this page in public places (like mailing lists)!</strong></span><br>
167
Passwords in config.xml have been automatically removed.
168

    
169
<div id="cmdspace" style="width:700px">
170
<?php listCmds(); ?>
171

    
172
<?php execCmds(); ?>
173
</div>
174

    
175
<?php include("fend.inc"); ?>
176
</body>
177
</html>
(107-107/144)