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>\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 -v","/sbin/pfctl -s rules -v");
|
106
|
defCmdT("pfctl -s queue -v","/sbin/pfctl -s queue -v");
|
107
|
defCmdT("pfctl -vsq","/sbin/pfctl -vsq");
|
108
|
|
109
|
defCmdT("pftop -w 150 -a -b","/usr/local/sbin/pftop -a -b");
|
110
|
defCmdT("pftop -w 150 -a -b -v long","/usr/local/sbin/pftop -w 150 -a -b -v long");
|
111
|
defCmdT("pftop -w 150 -a -b -v queue","/usr/local/sbin/pftop -w 150 -a -b -v queue");
|
112
|
defCmdT("pftop -w 150 -a -b -v rules","/usr/local/sbin/pftop -w 150 -a -b -v rules");
|
113
|
defCmdT("pftop -w 150 -a -b -v size","/usr/local/sbin/pftop -w 150 -a -b -v size");
|
114
|
defCmdT("pftop -w 150 -a -b -v speed","/usr/local/sbin/pftop -w 150 -a -b -v speed");
|
115
|
|
116
|
defCmdT("resolv.conf","cat /etc/resolv.conf");
|
117
|
|
118
|
defCmdT("Processes","ps xauww");
|
119
|
defCmdT("dhcpd.conf","cat /var/etc/dhcpd.conf");
|
120
|
defCmdT("ez-ipupdate.cache","cat /conf/ez-ipupdate.cache");
|
121
|
|
122
|
defCmdT("df","/bin/df");
|
123
|
|
124
|
defCmdT("racoon.conf","cat /var/etc/racoon.conf");
|
125
|
defCmdT("SPD","/usr/sbin/setkey -DP");
|
126
|
defCmdT("SAD","/usr/sbin/setkey -D");
|
127
|
|
128
|
defCmdT("last 200 system log entries","/usr/sbin/clog /var/log/system.log 2>&1 | tail -n 200");
|
129
|
defCmdT("last 50 filter log entries","/usr/sbin/clog /var/log/filter.log 2>&1 | tail -n 50");
|
130
|
|
131
|
defCmd("ls /conf");
|
132
|
defCmd("ls /var/run");
|
133
|
|
134
|
defCmdT("cat {$g['tmp_path']}/rules.debug","cat {$g['tmp_path']}/rules.debug");
|
135
|
|
136
|
defCmdT("config.xml","dumpconfigxml");
|
137
|
|
138
|
$pageTitle = "pfSense: status";
|
139
|
|
140
|
exec("/bin/date", $dateOutput, $dateStatus);
|
141
|
$currentDate = $dateOutput[0];
|
142
|
|
143
|
?>
|
144
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
145
|
<html>
|
146
|
<head>
|
147
|
<title><?=$pageTitle;?></title>
|
148
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
149
|
<link href="gui.css" rel="stylesheet" type="text/css">
|
150
|
<style type="text/css">
|
151
|
<!--
|
152
|
pre {
|
153
|
margin: 0px;
|
154
|
font-family: courier new, courier;
|
155
|
font-weight: normal;
|
156
|
font-size: 9pt;
|
157
|
}
|
158
|
-->
|
159
|
</style>
|
160
|
</head>
|
161
|
|
162
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
163
|
<p><span class="pgtitle"><?=$pageTitle;?></span><br>
|
164
|
<strong><?=$currentDate;?></strong>
|
165
|
<p><span class="red"><strong>Note: make sure to remove any sensitive information
|
166
|
(passwords, maybe also IP addresses) before posting
|
167
|
information from this page in public places (like mailing lists)!</strong></span><br>
|
168
|
Passwords in config.xml have been automatically removed.
|
169
|
|
170
|
<?php listCmds(); ?>
|
171
|
|
172
|
<?php execCmds(); ?>
|
173
|
|
174
|
</body>
|
175
|
</html>
|