Project

General

Profile

Download (12.4 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * status.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7
 * All rights reserved.
8
 *
9
 * originally based on m0n0wall (http://neon1.net/m0n0wall)
10
 * Copyright (c) 2003 Jim McBeath <jimmc@macrovision.com>
11
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
12
 * All rights reserved.
13
 *
14
 * Licensed under the Apache License, Version 2.0 (the "License");
15
 * you may not use this file except in compliance with the License.
16
 * You may obtain a copy of the License at
17
 *
18
 * http://www.apache.org/licenses/LICENSE-2.0
19
 *
20
 * Unless required by applicable law or agreed to in writing, software
21
 * distributed under the License is distributed on an "AS IS" BASIS,
22
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
 * See the License for the specific language governing permissions and
24
 * limitations under the License.
25
 */
26

    
27
##|+PRIV
28
##|*IDENT=page-hidden-detailedstatus
29
##|*NAME=Hidden: Detailed Status
30
##|*DESCR=Allow access to the 'Hidden: Detailed Status' page.
31
##|*MATCH=status.php*
32
##|-PRIV
33

    
34
/* Execute a command, with a title, and generate an HTML table
35
 * showing the results.
36
 */
37

    
38
/* include all configuration functions */
39
require_once("guiconfig.inc");
40
require_once("functions.inc");
41
$output_path = "/tmp/status_output/";
42
$output_file = "/tmp/status_output.tgz";
43

    
44
if (is_dir($output_path)) {
45
	unlink_if_exists("{$output_path}/*");
46
	@rmdir($output_path);
47
}
48
unlink_if_exists($output_file);
49
mkdir($output_path);
50

    
51
function doCmdT($title, $command) {
52
	global $output_path, $output_file;
53
	/* Fixup output directory */
54

    
55
	$rubbish = array('|', '-', '/', '.', ' ');  /* fixes the <a> tag to be W3C compliant */
56
	echo "\n<a name=\"" . str_replace($rubbish, '', $title) . "\" id=\"" . str_replace($rubbish, '', $title) . "\"></a>\n";
57

    
58
	print('<div class="panel panel-default">');
59
	print('<div class="panel-heading"><h2 class="panel-title">' . $title . '</h2></div>');
60
	print('<div class="panel-body">');
61
	print('<pre>');
62

    
63
	if ($command == "dumpconfigxml") {
64
		$ofd = @fopen("{$output_path}/config-sanitized.xml", "w");
65
		$fd = @fopen("/conf/config.xml", "r");
66
		if ($fd) {
67
			while (!feof($fd)) {
68
				$line = fgets($fd);
69
				/* remove sensitive contents */
70
				$line = preg_replace("/<authorizedkeys>.*?<\\/authorizedkeys>/", "<authorizedkeys>xxxxx</authorizedkeys>", $line);
71
				$line = preg_replace("/<secret>.*?<\\/secret>/", "<secret>xxxxx</secret>", $line);
72
				$line = preg_replace("/<bcrypt-hash>.*?<\\/bcrypt-hash>/", "<bcrypt-hash>xxxxx</bcrypt-hash>", $line);
73
				$line = preg_replace("/<password>.*?<\\/password>/", "<password>xxxxx</password>", $line);
74
				$line = preg_replace("/<auth_user>.*?<\\/auth_user>/", "<auth_user>xxxxx</auth_user>", $line);
75
				$line = preg_replace("/<auth_pass>.*?<\\/auth_pass>/", "<auth_pass>xxxxx</auth_pass>", $line);
76
				$line = preg_replace("/<proxy_user>.*?<\\/proxy_user>/", "<proxy_user>xxxxx</proxy_user>", $line);
77
				$line = preg_replace("/<proxy_passwd>.*?<\\/proxy_passwd>/", "<proxy_passwd>xxxxx</proxy_passwd>", $line);
78
				$line = preg_replace("/<proxyuser>.*?<\\/proxyuser>/", "<proxyuser>xxxxx</proxyuser>", $line);
79
				$line = preg_replace("/<proxypass>.*?<\\/proxypass>/", "<proxypass>xxxxx</proxypass>", $line);
80
				$line = preg_replace("/<pre-shared-key>.*?<\\/pre-shared-key>/", "<pre-shared-key>xxxxx</pre-shared-key>", $line);
81
				$line = preg_replace("/<rocommunity>.*?<\\/rocommunity>/", "<rocommunity>xxxxx</rocommunity>", $line);
82
				$line = preg_replace("/<prv>.*?<\\/prv>/", "<prv>xxxxx</prv>", $line);
83
				$line = preg_replace("/<shared_key>.*?<\\/shared_key>/", "<shared_key>xxxxx</shared_key>", $line);
84
				$line = preg_replace("/<tls>.*?<\\/tls>/", "<tls>xxxxx</tls>", $line);
85
				$line = preg_replace("/<ipsecpsk>.*?<\\/ipsecpsk>/", "<ipsecpsk>xxxxx</ipsecpsk>", $line);
86
				$line = preg_replace("/<md5-hash>.*?<\\/md5-hash>/", "<md5-hash>xxxxx</md5-hash>", $line);
87
				$line = preg_replace("/<md5password>.*?<\\/md5password>/", "<md5password>xxxxx</md5password>", $line);
88
				$line = preg_replace("/<nt-hash>.*?<\\/nt-hash>/", "<nt-hash>xxxxx</nt-hash>", $line);
89
				$line = preg_replace("/<radius_secret>.*?<\\/radius_secret>/", "<radius_secret>xxxxx</radius_secret>", $line);
90
				$line = preg_replace("/<ldap_bindpw>.*?<\\/ldap_bindpw>/", "<ldap_bindpw>xxxxx</ldap_bindpw>", $line);
91
				$line = preg_replace("/<passwordagain>.*?<\\/passwordagain>/", "<passwordagain>xxxxx</passwordagain>", $line);
92
				$line = preg_replace("/<crypto_password>.*?<\\/crypto_password>/", "<crypto_password>xxxxx</crypto_password>", $line);
93
				$line = preg_replace("/<crypto_password2>.*?<\\/crypto_password2>/", "<crypto_password2>xxxxx</crypto_password2>", $line);
94
				$line = str_replace("\t", "    ", $line);
95
				echo htmlspecialchars($line, ENT_NOQUOTES);
96
				fwrite($ofd, $line);
97
			}
98
		}
99
		fclose($fd);
100
		fclose($ofd);
101
	} else {
102
		$ofd = @fopen("{$output_path}/{$title}.txt", "w");
103
		$execOutput = "";
104
		$execStatus = "";
105
		exec ($command . " 2>&1", $execOutput, $execStatus);
106
		for ($i = 0; isset($execOutput[$i]); $i++) {
107
			if ($i > 0) {
108
				echo "\n";
109
			}
110
			echo htmlspecialchars($execOutput[$i], ENT_NOQUOTES);
111
			fwrite($ofd, $execOutput[$i] . "\n");
112
		}
113
		fclose($ofd);
114
	}
115

    
116
	print('</pre>');
117
	print('</div>');
118
	print('</div>');
119
}
120

    
121
/* Define a command, with a title, to be executed later. */
122
function defCmdT($title, $command) {
123
	global $commands;
124
	$title = htmlspecialchars($title, ENT_NOQUOTES);
125
	$commands[] = array($title, $command);
126
}
127

    
128
/* List all of the commands as an index. */
129
function listCmds() {
130
	global $currentDate;
131
	global $commands;
132

    
133
	$rubbish = array('|', '-', '/', '.', ' ');	/* fixes the <a> tag to be W3C compliant */
134

    
135
	print('<div class="panel panel-default">');
136
	print('<div class="panel-heading"><h2 class="panel-title">' . gettext("System Status on ") . $currentDate . '</h2></div>');
137
	print('<div class="panel-body">');
138
	print('    <div class="content">');
139
	print("\n<p>" . gettext("This status page includes the following information") . ":\n");
140
	print("<ul>\n");
141
	for ($i = 0; isset($commands[$i]); $i++) {
142
		print("\t<li><strong><a href=\"#" . str_replace($rubbish, '', $commands[$i][0]) . "\">" . $commands[$i][0] . "</a></strong></li>\n");
143
	}
144

    
145
	print("</ul>\n");
146
	print('	       </div>');
147
	print('	   </div>');
148
	print('</div>');
149
}
150

    
151
/* Execute all of the commands which were defined by a call to defCmd. */
152
function execCmds() {
153
	global $commands;
154
	for ($i = 0; isset($commands[$i]); $i++) {
155
		doCmdT($commands[$i][0], $commands[$i][1]);
156
	}
157
}
158

    
159
global $g, $config;
160

    
161
/* Set up all of the commands we want to execute. */
162

    
163
/* System stats/info */
164
defCmdT("System Uptime", "/usr/bin/uptime");
165
defCmdT("Interfaces", "/sbin/ifconfig -a");
166
defCmdT("Interface Statistics", "/usr/bin/netstat -nWi");
167
defCmdT("Top Process Info", "/usr/bin/top | /usr/bin/head -n5");
168
defCmdT("Processes", "/bin/ps xauwwd");
169
defCmdT("Mounted Filesystems", "/sbin/mount");
170
defCmdT("Free Disk Space", "/bin/df -hi");
171
defCmdT("Routing tables", "/usr/bin/netstat -nWr");
172
defCmdT("Mbuf Usage", "/usr/bin/netstat -mb");
173
defCmdT("VMStat", "/usr/bin/vmstat -afimsz");
174
defCmdT("Sockets", "/usr/bin/sockstat");
175

    
176
/* Firewall rules and info */
177
defCmdT("Generated Ruleset", "/bin/cat {$g['tmp_path']}/rules.debug");
178
defCmdT("Generated Ruleset Limiters", "/bin/cat {$g['tmp_path']}/rules.limiter");
179
defCmdT("Generated Ruleset Limits", "/bin/cat {$g['tmp_path']}/rules.limits");
180
defCmdT("pf NAT Rules", "/sbin/pfctl -vvsn");
181
defCmdT("pf Firewall Rules", "/sbin/pfctl -vvsr");
182
defCmdT("pf Tables", "/sbin/pfctl -vs Tables");
183
defCmdT("pf State Table Contents", "/sbin/pfctl -vvss");
184
defCmdT("pf Info", "/sbin/pfctl -si");
185
defCmdT("pf Show All", "/sbin/pfctl -sa");
186
defCmdT("pf Queues", "/sbin/pfctl -s queue -v");
187
defCmdT("pf OSFP", "/sbin/pfctl -s osfp");
188
defCmdT("Network Protocol Statistics", "/usr/bin/netstat -s");
189
defCmdT("pftop Default", "/usr/local/sbin/pftop -a -b");
190
defCmdT("pftop Long", "/usr/local/sbin/pftop -w 150 -a -b -v long");
191
defCmdT("pftop Queue", "/usr/local/sbin/pftop -w 150 -a -b -v queue");
192
defCmdT("pftop Rules", "/usr/local/sbin/pftop -w 150 -a -b -v rules");
193
defCmdT("pftop Size", "/usr/local/sbin/pftop -w 150 -a -b -v size");
194
defCmdT("pftop Speed", "/usr/local/sbin/pftop -w 150 -a -b -v speed");
195
if (isset($config['captiveportal']) && is_array($config['captiveportal'])) {
196
	foreach ($config['captiveportal'] as $cpZone => $cpdata) {
197
		if (isset($cpdata['enable'])) {
198
			defCmdT("IPFW Rules for {$cpdata['zone']}", "/sbin/ipfw -x " . escapeshellarg($cpdata['zoneid']) . " show");
199
		}
200
	}
201
}
202

    
203
/* Configuration Files */
204
defCmdT("Contents of var run", "/bin/ls /var/run");
205
defCmdT("Contents of conf", "/bin/ls /conf");
206
defCmdT("config.xml", "dumpconfigxml");
207
defCmdT("resolv.conf", "/bin/cat /etc/resolv.conf");
208
defCmdT("DHCP Configuration", "/bin/cat /var/dhcpd/etc/dhcpd.conf");
209
defCmdT("DHCPv6 Configuration", "/bin/cat /var/dhcpd/etc/dhcpdv6.conf");
210
defCmdT("strongSwan Configuration", "/bin/cat /var/etc/ipsec/strongswan.conf");
211
defCmdT("IPsec Configuration", "/bin/cat /var/etc/ipsec/ipsec.conf");
212
defCmdT("IPsec Status", "/usr/local/sbin/ipsec statusall");
213
defCmdT("SPD", "/sbin/setkey -DP");
214
defCmdT("SAD", "/sbin/setkey -D");
215
if (file_exists("/cf/conf/upgrade_log.txt")) {
216
	defCmdT("Upgrade Log", "/bin/cat /cf/conf/upgrade_log.txt");
217
}
218
if (file_exists("/boot/loader.conf")) {
219
	defCmdT("Loader Configuration", "/bin/cat /boot/loader.conf");
220
}
221
if (file_exists("/boot/loader.conf.local")) {
222
	defCmdT("Loader Configuration (Local)", "/bin/cat /boot/loader.conf.local");
223
}
224
if (file_exists("/var/etc/filterdns.conf")) {
225
	defCmdT("Filter DNS Daemon Configuration", "/bin/cat /var/etc/filterdns.conf");
226
}
227
defCmdT("last 1000 system log entries", "/usr/local/sbin/clog /var/log/system.log 2>&1 | tail -n 1000");
228
defCmdT("last 1000 DHCP log entries", "/usr/local/sbin/clog /var/log/dhcpd.log 2>&1 | tail -n 1000");
229
defCmdT("last 500 filter log entries", "/usr/local/sbin/clog /var/log/filter.log 2>&1 | tail -n 500");
230
defCmdT("last 1000 gateways log entries", "/usr/local/sbin/clog /var/log/gateways.log 2>&1 | tail -n 1000");
231
defCmdT("last 1000 IPsec log entries", "/usr/local/sbin/clog /var/log/ipsec.log 2>&1 | tail -n 1000");
232
defCmdT("last 1000 L2TP log entries", "/usr/local/sbin/clog /var/log/l2tps.log 2>&1 | tail -n 1000");
233
defCmdT("last 1000 NTP log entries", "/usr/local/sbin/clog /var/log/ntpd.log 2>&1 | tail -n 1000");
234
defCmdT("last 1000 OpenVPN log entries", "/usr/local/sbin/clog /var/log/openvpn.log 2>&1 | tail -n 1000");
235
defCmdT("last 1000 Captive Portal auth log entries", "/usr/local/sbin/clog /var/log/portalauth.log 2>&1 | tail -n 1000");
236
defCmdT("last 1000 PPP log entries", "/usr/local/sbin/clog /var/log/poes.log 2>&1 | tail -n 1000");
237
defCmdT("last 1000 relayd log entries", "/usr/local/sbin/clog /var/log/relayd.log 2>&1 | tail -n 1000");
238
defCmdT("last 1000 resolver log entries", "/usr/local/sbin/clog /var/log/resolver.log 2>&1 | tail -n 1000");
239
defCmdT("last 1000 routing log entries", "/usr/local/sbin/clog /var/log/routing.log 2>&1 | tail -n 1000");
240
defCmdT("last 1000 wireless log entries", "/usr/local/sbin/clog /var/log/wireless.log 2>&1 | tail -n 1000");
241
if (file_exists("/tmp/PHP_errors.log")) {
242
	defCmdT("PHP Error Log", "/bin/cat /tmp/PHP_errors.log");
243
}
244
defCmdT("System Message Buffer", "/sbin/dmesg -a");
245
defCmdT("System Message Buffer (Boot)", "/bin/cat /var/log/dmesg.boot");
246
defCmdT("sysctl values", "/sbin/sysctl -a");
247
defCmdT("Kernel Environment", "/bin/kenv");
248
defCmdT("Installed OS Packages", "/usr/sbin/pkg info");
249
defCmdT("System Devices-PCI", "/usr/sbin/pciconf -lvb");
250
defCmdT("System Devices-USB", "/usr/sbin/usbconfig dump_device_desc");
251

    
252
exec("/bin/date", $dateOutput, $dateStatus);
253
$currentDate = $dateOutput[0];
254

    
255
$pgtitle = array("{$g['product_name']}", "Status");
256
include("head.inc");
257

    
258
print_info_box(gettext("Make sure all sensitive information is removed! (Passwords, etc.) before posting " .
259
			   "information from this page in public places (like mailing lists).") . '<br />' .
260
		gettext("Common password fields in config.xml have been automatically redacted.") . '<br />' .
261
		gettext("When the page has finished loading, the output will be stored in {$output_file}. It may be downloaded via scp or ") .
262
		"<a href=\"/diag_command.php?dlPath={$output_file}\">" . gettext("Diagnostics > Command Prompt.") . '</a>');
263

    
264
listCmds();
265
execCmds();
266

    
267
print(gettext("Saving output to archive..."));
268

    
269
if (is_dir($output_path)) {
270
	mwexec("/usr/bin/tar czpf " . escapeshellarg($output_file) . " -C " . escapeshellarg(dirname($output_path)) . " " . escapeshellarg(basename($output_path)));
271
	unlink_if_exists("{$output_path}/*");
272
	@rmdir($output_path);
273
}
274

    
275
print(gettext("Done."));
276

    
277
include("foot.inc");
(149-149/225)