1
|
<?php
|
2
|
/*
|
3
|
status.php
|
4
|
*/
|
5
|
/* Run various commands and collect their output into HTML tables.
|
6
|
* Jim McBeath <jimmc@macrovision.com> Nov 2003
|
7
|
*
|
8
|
* (modified for m0n0wall by Manuel Kasper <mk@neon1.net>)
|
9
|
* (modified for pfSense by Scott Ullrich geekgod@pfsense.com)
|
10
|
*
|
11
|
*/
|
12
|
/* ====================================================================
|
13
|
* Copyright (c) 2004-2015 Electric Sheep Fencing, LLC. All rights reserved.
|
14
|
*
|
15
|
* Some or all of this file is based on the m0n0wall project which is
|
16
|
* Copyright (c) 2004 Manuel Kasper (BSD 2 clause)
|
17
|
*
|
18
|
* Redistribution and use in source and binary forms, with or without modification,
|
19
|
* are permitted provided that the following conditions are met:
|
20
|
*
|
21
|
* 1. Redistributions of source code must retain the above copyright notice,
|
22
|
* this list of conditions and the following disclaimer.
|
23
|
*
|
24
|
* 2. Redistributions in binary form must reproduce the above copyright
|
25
|
* notice, this list of conditions and the following disclaimer in
|
26
|
* the documentation and/or other materials provided with the
|
27
|
* distribution.
|
28
|
*
|
29
|
* 3. All advertising materials mentioning features or use of this software
|
30
|
* must display the following acknowledgment:
|
31
|
* "This product includes software developed by the pfSense Project
|
32
|
* for use in the pfSense software distribution. (http://www.pfsense.org/).
|
33
|
*
|
34
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
35
|
* endorse or promote products derived from this software without
|
36
|
* prior written permission. For written permission, please contact
|
37
|
* coreteam@pfsense.org.
|
38
|
*
|
39
|
* 5. Products derived from this software may not be called "pfSense"
|
40
|
* nor may "pfSense" appear in their names without prior written
|
41
|
* permission of the Electric Sheep Fencing, LLC.
|
42
|
*
|
43
|
* 6. Redistributions of any form whatsoever must retain the following
|
44
|
* acknowledgment:
|
45
|
*
|
46
|
* "This product includes software developed by the pfSense Project
|
47
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
48
|
*
|
49
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
50
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
51
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
52
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
53
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
54
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
55
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
56
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
57
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
58
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
59
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
60
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
61
|
*
|
62
|
* ====================================================================
|
63
|
*
|
64
|
*/
|
65
|
|
66
|
##|+PRIV
|
67
|
##|*IDENT=page-hidden-detailedstatus
|
68
|
##|*NAME=Hidden: Detailed Status
|
69
|
##|*DESCR=Allow access to the 'Hidden: Detailed Status' page.
|
70
|
##|*MATCH=status.php*
|
71
|
##|-PRIV
|
72
|
|
73
|
/* Execute a command, with a title, and generate an HTML table
|
74
|
* showing the results.
|
75
|
*/
|
76
|
|
77
|
/* include all configuration functions */
|
78
|
require_once("guiconfig.inc");
|
79
|
require_once("functions.inc");
|
80
|
$output_path = "/tmp/status_output/";
|
81
|
$output_file = "/tmp/status_output.tgz";
|
82
|
|
83
|
if (is_dir($output_path)) {
|
84
|
unlink_if_exists("{$output_path}/*");
|
85
|
@rmdir($output_path);
|
86
|
}
|
87
|
unlink_if_exists($output_file);
|
88
|
mkdir($output_path);
|
89
|
|
90
|
function doCmdT($title, $command) {
|
91
|
global $output_path, $output_file;
|
92
|
/* Fixup output directory */
|
93
|
|
94
|
$rubbish = array('|', '-', '/', '.', ' '); /* fixes the <a> tag to be W3C compliant */
|
95
|
echo "\n<a name=\"" . str_replace($rubbish, '', $title) . "\" id=\"" . str_replace($rubbish, '', $title) . "\"></a>\n";
|
96
|
|
97
|
print('<div class="panel panel-default">');
|
98
|
print('<div class="panel-heading"><h2 class="panel-title">' . $title . '</h2></div>');
|
99
|
print('<div class="panel-body">');
|
100
|
print('<pre>');
|
101
|
|
102
|
if ($command == "dumpconfigxml") {
|
103
|
$ofd = @fopen("{$output_path}/config-sanitized.xml", "w");
|
104
|
$fd = @fopen("/conf/config.xml", "r");
|
105
|
if ($fd) {
|
106
|
while (!feof($fd)) {
|
107
|
$line = fgets($fd);
|
108
|
/* remove sensitive contents */
|
109
|
$line = preg_replace("/<password>.*?<\\/password>/", "<password>xxxxx</password>", $line);
|
110
|
$line = preg_replace("/<pre-shared-key>.*?<\\/pre-shared-key>/", "<pre-shared-key>xxxxx</pre-shared-key>", $line);
|
111
|
$line = preg_replace("/<rocommunity>.*?<\\/rocommunity>/", "<rocommunity>xxxxx</rocommunity>", $line);
|
112
|
$line = preg_replace("/<prv>.*?<\\/prv>/", "<prv>xxxxx</prv>", $line);
|
113
|
$line = preg_replace("/<shared_key>.*?<\\/shared_key>/", "<shared_key>xxxxx</shared_key>", $line);
|
114
|
$line = preg_replace("/<tls>.*?<\\/tls>/", "<tls>xxxxx</tls>", $line);
|
115
|
$line = preg_replace("/<ipsecpsk>.*?<\\/ipsecpsk>/", "<ipsecpsk>xxxxx</ipsecpsk>", $line);
|
116
|
$line = preg_replace("/<md5-hash>.*?<\\/md5-hash>/", "<md5-hash>xxxxx</md5-hash>", $line);
|
117
|
$line = preg_replace("/<md5password>.*?<\\/md5password>/", "<md5password>xxxxx</md5password>", $line);
|
118
|
$line = preg_replace("/<nt-hash>.*?<\\/nt-hash>/", "<nt-hash>xxxxx</nt-hash>", $line);
|
119
|
$line = preg_replace("/<radius_secret>.*?<\\/radius_secret>/", "<radius_secret>xxxxx</radius_secret>", $line);
|
120
|
$line = preg_replace("/<ldap_bindpw>.*?<\\/ldap_bindpw>/", "<ldap_bindpw>xxxxx</ldap_bindpw>", $line);
|
121
|
$line = preg_replace("/<passwordagain>.*?<\\/passwordagain>/", "<passwordagain>xxxxx</passwordagain>", $line);
|
122
|
$line = preg_replace("/<crypto_password>.*?<\\/crypto_password>/", "<crypto_password>xxxxx</crypto_password>", $line);
|
123
|
$line = preg_replace("/<crypto_password2>.*?<\\/crypto_password2>/", "<crypto_password2>xxxxx</crypto_password2>", $line);
|
124
|
$line = str_replace("\t", " ", $line);
|
125
|
echo htmlspecialchars($line, ENT_NOQUOTES);
|
126
|
fwrite($ofd, $line);
|
127
|
}
|
128
|
}
|
129
|
fclose($fd);
|
130
|
fclose($ofd);
|
131
|
} else {
|
132
|
$ofd = @fopen("{$output_path}/{$title}.txt", "w");
|
133
|
$execOutput = "";
|
134
|
$execStatus = "";
|
135
|
exec ($command . " 2>&1", $execOutput, $execStatus);
|
136
|
for ($i = 0; isset($execOutput[$i]); $i++) {
|
137
|
if ($i > 0) {
|
138
|
echo "\n";
|
139
|
}
|
140
|
echo htmlspecialchars($execOutput[$i], ENT_NOQUOTES);
|
141
|
fwrite($ofd, $execOutput[$i] . "\n");
|
142
|
}
|
143
|
fclose($ofd);
|
144
|
}
|
145
|
|
146
|
print('</pre>');
|
147
|
print('</div>');
|
148
|
print('</div>');
|
149
|
}
|
150
|
|
151
|
/* Define a command, with a title, to be executed later. */
|
152
|
function defCmdT($title, $command) {
|
153
|
global $commands;
|
154
|
$title = htmlspecialchars($title, ENT_NOQUOTES);
|
155
|
$commands[] = array($title, $command);
|
156
|
}
|
157
|
|
158
|
/* List all of the commands as an index. */
|
159
|
function listCmds() {
|
160
|
global $currentDate;
|
161
|
global $commands;
|
162
|
|
163
|
$rubbish = array('|', '-', '/', '.', ' '); /* fixes the <a> tag to be W3C compliant */
|
164
|
|
165
|
print('<div class="panel panel-default">');
|
166
|
print('<div class="panel-heading"><h2 class="panel-title">' . gettext("System Status on ") . $currentDate . '</h2></div>');
|
167
|
print('<div class="panel-body">');
|
168
|
print(' <div class="content">');
|
169
|
print("\n<p>" . gettext("This status page includes the following information") . ":\n");
|
170
|
print("<ul>\n");
|
171
|
for ($i = 0; isset($commands[$i]); $i++) {
|
172
|
print("\t<li><strong><a href=\"#" . str_replace($rubbish, '', $commands[$i][0]) . "\">" . $commands[$i][0] . "</a></strong></li>\n");
|
173
|
}
|
174
|
|
175
|
print("</ul>\n");
|
176
|
print(' </div>');
|
177
|
print(' </div>');
|
178
|
print('</div>');
|
179
|
}
|
180
|
|
181
|
/* Execute all of the commands which were defined by a call to defCmd. */
|
182
|
function execCmds() {
|
183
|
global $commands;
|
184
|
for ($i = 0; isset($commands[$i]); $i++) {
|
185
|
doCmdT($commands[$i][0], $commands[$i][1]);
|
186
|
}
|
187
|
}
|
188
|
|
189
|
global $g, $config;
|
190
|
|
191
|
/* Set up all of the commands we want to execute. */
|
192
|
|
193
|
/* System stats/info */
|
194
|
defCmdT("System Uptime", "/usr/bin/uptime");
|
195
|
defCmdT("Interfaces", "/sbin/ifconfig -a");
|
196
|
defCmdT("Interface Statistics", "/usr/bin/netstat -nWi");
|
197
|
defCmdT("Top Process Info", "/usr/bin/top | /usr/bin/head -n5");
|
198
|
defCmdT("Processes", "/bin/ps xauww");
|
199
|
defCmdT("Mounted Filesystems", "/sbin/mount");
|
200
|
defCmdT("Free Disk Space", "/bin/df -hi");
|
201
|
defCmdT("Routing tables", "/usr/bin/netstat -nWr");
|
202
|
defCmdT("Mbuf Usage", "/usr/bin/netstat -mb");
|
203
|
defCmdT("VMStat", "/usr/bin/vmstat -afimsz");
|
204
|
defCmdT("Sockets", "/usr/bin/sockstat");
|
205
|
|
206
|
/* Firewall rules and info */
|
207
|
defCmdT("Generated Ruleset", "/bin/cat {$g['tmp_path']}/rules.debug");
|
208
|
defCmdT("Generated Ruleset Limiters", "/bin/cat {$g['tmp_path']}/rules.limiter");
|
209
|
defCmdT("Generated Ruleset Limits", "/bin/cat {$g['tmp_path']}/rules.limits");
|
210
|
defCmdT("pf NAT Rules", "/sbin/pfctl -vvsn");
|
211
|
defCmdT("pf Firewall Rules", "/sbin/pfctl -vvsr");
|
212
|
defCmdT("pf Tables", "/sbin/pfctl -vs Tables");
|
213
|
defCmdT("pf State Table Contents", "/sbin/pfctl -vvss");
|
214
|
defCmdT("pf Info", "/sbin/pfctl -si");
|
215
|
defCmdT("pf Show All", "/sbin/pfctl -sa");
|
216
|
defCmdT("pf Queues", "/sbin/pfctl -s queue -v");
|
217
|
defCmdT("pf OSFP", "/sbin/pfctl -s osfp");
|
218
|
defCmdT("pfsync Stats", "/usr/bin/netstat -s -ppfsync");
|
219
|
defCmdT("pftop Default", "/usr/local/sbin/pftop -a -b");
|
220
|
defCmdT("pftop Long", "/usr/local/sbin/pftop -w 150 -a -b -v long");
|
221
|
defCmdT("pftop Queue", "/usr/local/sbin/pftop -w 150 -a -b -v queue");
|
222
|
defCmdT("pftop Rules", "/usr/local/sbin/pftop -w 150 -a -b -v rules");
|
223
|
defCmdT("pftop Size", "/usr/local/sbin/pftop -w 150 -a -b -v size");
|
224
|
defCmdT("pftop Speed", "/usr/local/sbin/pftop -w 150 -a -b -v speed");
|
225
|
if (isset($config['captiveportal']) && is_array($config['captiveportal'])) {
|
226
|
foreach ($config['captiveportal'] as $cpZone => $cpdata) {
|
227
|
if (isset($cpdata['enable'])) {
|
228
|
defCmdT("IPFW Rules for {$cpdata['zone']}", "/sbin/ipfw -x " . escapeshellarg($cpdata['zoneid']) . " show");
|
229
|
}
|
230
|
}
|
231
|
}
|
232
|
|
233
|
/* Configuration Files */
|
234
|
defCmdT("Contents of var run", "/bin/ls /var/run");
|
235
|
defCmdT("Contents of conf", "/bin/ls /conf");
|
236
|
defCmdT("config.xml", "dumpconfigxml");
|
237
|
defCmdT("resolv.conf", "/bin/cat /etc/resolv.conf");
|
238
|
defCmdT("DHCP Configuration", "/bin/cat /var/dhcpd/etc/dhcpd.conf");
|
239
|
defCmdT("DHCPv6 Configuration", "/bin/cat /var/dhcpd/etc/dhcpdv6.conf");
|
240
|
defCmdT("strongSwan Configuration", "/bin/cat /var/etc/ipsec/strongswan.conf");
|
241
|
defCmdT("IPsec Configuration", "/bin/cat /var/etc/ipsec/ipsec.conf");
|
242
|
defCmdT("IPsec Status", "/usr/local/sbin/ipsec statusall");
|
243
|
defCmdT("SPD", "/sbin/setkey -DP");
|
244
|
defCmdT("SAD", "/sbin/setkey -D");
|
245
|
if (file_exists("/cf/conf/upgrade_log.txt")) {
|
246
|
defCmdT("Upgrade Log", "/bin/cat /cf/conf/upgrade_log.txt");
|
247
|
}
|
248
|
if (file_exists("/boot/loader.conf")) {
|
249
|
defCmdT("Loader Configuration", "/bin/cat /boot/loader.conf");
|
250
|
}
|
251
|
if (file_exists("/boot/loader.conf.local")) {
|
252
|
defCmdT("Loader Configuration (Local)", "/bin/cat /boot/loader.conf.local");
|
253
|
}
|
254
|
if (file_exists("/var/etc/filterdns.conf")) {
|
255
|
defCmdT("Filter DNS Daemon Configuration", "/bin/cat /var/etc/filterdns.conf");
|
256
|
}
|
257
|
defCmdT("last 1000 system log entries", "/usr/local/sbin/clog /var/log/system.log 2>&1 | tail -n 1000");
|
258
|
defCmdT("last 1000 DHCP log entries", "/usr/local/sbin/clog /var/log/dhcpd.log 2>&1 | tail -n 1000");
|
259
|
defCmdT("last 500 filter log entries", "/usr/local/sbin/clog /var/log/filter.log 2>&1 | tail -n 500");
|
260
|
defCmdT("last 1000 gateways log entries", "/usr/local/sbin/clog /var/log/gateways.log 2>&1 | tail -n 1000");
|
261
|
defCmdT("last 1000 IPsec log entries", "/usr/local/sbin/clog /var/log/ipsec.log 2>&1 | tail -n 1000");
|
262
|
defCmdT("last 1000 L2TP log entries", "/usr/local/sbin/clog /var/log/l2tps.log 2>&1 | tail -n 1000");
|
263
|
defCmdT("last 1000 NTP log entries", "/usr/local/sbin/clog /var/log/ntpd.log 2>&1 | tail -n 1000");
|
264
|
defCmdT("last 1000 OpenVPN log entries", "/usr/local/sbin/clog /var/log/openvpn.log 2>&1 | tail -n 1000");
|
265
|
defCmdT("last 1000 Captive Portal auth log entries", "/usr/local/sbin/clog /var/log/portalauth.log 2>&1 | tail -n 1000");
|
266
|
defCmdT("last 1000 PPP log entries", "/usr/local/sbin/clog /var/log/poes.log 2>&1 | tail -n 1000");
|
267
|
defCmdT("last 1000 relayd log entries", "/usr/local/sbin/clog /var/log/relayd.log 2>&1 | tail -n 1000");
|
268
|
defCmdT("last 1000 resolver log entries", "/usr/local/sbin/clog /var/log/resolver.log 2>&1 | tail -n 1000");
|
269
|
defCmdT("last 1000 routing log entries", "/usr/local/sbin/clog /var/log/routing.log 2>&1 | tail -n 1000");
|
270
|
defCmdT("last 1000 wireless log entries", "/usr/local/sbin/clog /var/log/wireless.log 2>&1 | tail -n 1000");
|
271
|
if (file_exists("/tmp/PHP_errors.log")) {
|
272
|
defCmdT("PHP Error Log", "/bin/cat /tmp/PHP_errors.log");
|
273
|
}
|
274
|
defCmdT("System Message Buffer", "/sbin/dmesg -a");
|
275
|
defCmdT("System Message Buffer (Boot)", "/bin/cat /var/log/dmesg.boot");
|
276
|
defCmdT("sysctl values", "/sbin/sysctl -a");
|
277
|
defCmdT("Kernel Environment", "/bin/kenv");
|
278
|
defCmdT("Installed OS Packages", "/usr/sbin/pkg info");
|
279
|
|
280
|
exec("/bin/date", $dateOutput, $dateStatus);
|
281
|
$currentDate = $dateOutput[0];
|
282
|
|
283
|
$pgtitle = array("{$g['product_name']}", "Status");
|
284
|
include("head.inc");
|
285
|
|
286
|
print_info_box(gettext("Make sure all sensitive information is removed! (Passwords, etc.) before posting " .
|
287
|
"information from this page in public places (like mailing lists)") . '<br />' .
|
288
|
gettext("Common password fields in config.xml have been automatically redacted.") . '<br />' .
|
289
|
gettext("When the page has finished loading, the output will be stored in {$output_file}. It may be downloaded via scp or ") .
|
290
|
"<a href=\"/exec.php?dlPath={$output_file}\">" . gettext("Diagnostics > Command Prompt") . '</a>');
|
291
|
|
292
|
listCmds();
|
293
|
execCmds();
|
294
|
|
295
|
print(gettext("Saving output to archive..."));
|
296
|
|
297
|
if (is_dir($output_path)) {
|
298
|
mwexec("/usr/bin/tar czpf " . escapeshellarg($output_file) . " -C " . escapeshellarg(dirname($output_path)) . " " . escapeshellarg(basename($output_path)));
|
299
|
unlink_if_exists("{$output_path}/*");
|
300
|
@rmdir($output_path);
|
301
|
}
|
302
|
|
303
|
print(gettext("Done."));
|
304
|
|
305
|
include("foot.inc");
|