Project

General

Profile

Download (15.3 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
require_once("gwlb.inc");
42
$output_path = "/tmp/status_output/";
43
$output_file = "/tmp/status_output.tgz";
44

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

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

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

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

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

    
121
	print('</pre>');
122
	print('</div>');
123
	print('</div>');
124
}
125

    
126
/* Define a command, with a title, to be executed later. */
127
function defCmdT($title, $command, $method = "exec") {
128
	global $commands;
129
	$title = htmlspecialchars($title, ENT_NOQUOTES);
130
	$commands[] = array($title, $command, $method);
131
}
132

    
133
/* List all of the commands as an index. */
134
function listCmds() {
135
	global $currentDate;
136
	global $commands;
137

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

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

    
150
	print("</ul>\n");
151
	print('	       </div>');
152
	print('	   </div>');
153
	print('</div>');
154
}
155

    
156
/* Execute all of the commands which were defined by a call to defCmd. */
157
function execCmds() {
158
	global $commands;
159
	for ($i = 0; isset($commands[$i]); $i++) {
160
		doCmdT($commands[$i][0], $commands[$i][1], $commands[$i][2]);
161
	}
162
}
163

    
164
function get_firewall_info() {
165
	global $g, $output_path;
166
	/* Firewall Platform/Serial */
167
	$firewall_info = "Product Name: " . htmlspecialchars($g['product_name']);
168
	$platform = system_identify_specific_platform();
169
	if (!empty($platform['descr'])) {
170
		$firewall_info .= "<br/>Platform: " . htmlspecialchars($platform['descr']);
171
	}
172
	$serial = system_get_serial();
173
	if (!empty($serial)) {
174
		$firewall_info .= "<br/>SN/UUID: " . htmlspecialchars($serial);
175
	}
176

    
177
	if (!empty($g['product_version_string'])) {
178
		$firewall_info .= "<br/>" . htmlspecialchars($g['product_name']) .
179
		    " version: " . htmlspecialchars($g['product_version_string']);
180
	}
181

    
182
	if (file_exists('/etc/version.buildtime')) {
183
		$build_time = file_get_contents('/etc/version.buildtime');
184
		if (!empty($build_time)) {
185
			$firewall_info .= "<br/>Built On: " . htmlspecialchars($build_time);
186
		}
187
	}
188
	if (file_exists('/etc/version.lastcommit')) {
189
		$build_commit = file_get_contents('/etc/version.lastcommit');
190
		if (!empty($build_commit)) {
191
			$firewall_info .= "<br/>Last Commit: " . htmlspecialchars($build_commit);
192
		}
193
	}
194

    
195
	if (file_exists('/etc/version.gitsync')) {
196
		$gitsync = file_get_contents('/etc/version.gitsync');
197
		if (!empty($gitsync)) {
198
			$firewall_info .= "<br/>A gitsync was performed at " .
199
			    date("D M j G:i:s T Y", filemtime('/etc/version.gitsync')) .
200
			    " to commit " . htmlspecialchars($gitsync);
201
		}
202
	}
203

    
204
	file_put_contents("{$output_path}/Product Info.txt", str_replace("<br/>", "\n", $firewall_info) . "\n");
205
	return $firewall_info;
206
}
207

    
208
function get_gateway_status() {
209
	return return_gateways_status_text(true, false);
210
}
211

    
212
global $g, $config;
213

    
214
/* Set up all of the commands we want to execute. */
215

    
216
/* OS stats/info */
217
defCmdT("OS-Uptime", "/usr/bin/uptime");
218
defCmdT("Network-Interfaces", "/sbin/ifconfig -a");
219
defCmdT("Network-Interface Statistics", "/usr/bin/netstat -nWi");
220
defCmdT("Process-Top Usage", "/usr/bin/top | /usr/bin/head -n5");
221
defCmdT("Process-List", "/bin/ps xauwwd");
222
defCmdT("Disk-Mounted Filesystems", "/sbin/mount");
223
defCmdT("Disk-Free Space", "/bin/df -hi");
224
defCmdT("Network-Routing tables", "/usr/bin/netstat -nWr");
225
defCmdT("Network-Gateway Status", 'get_gateway_status', "php_func");
226
defCmdT("Network-Mbuf Usage", "/usr/bin/netstat -mb");
227
defCmdT("Network-Protocol Statistics", "/usr/bin/netstat -s");
228
defCmdT("Network-Sockets", "/usr/bin/sockstat");
229
defCmdT("Network-ARP Table", "/usr/sbin/arp -an");
230
defCmdT("Network-NDP Table", "/usr/sbin/ndp -na");
231
defCmdT("OS-Kernel VMStat", "/usr/bin/vmstat -afimsz");
232

    
233
/* Firewall rules and info */
234
defCmdT("Firewall-Generated Ruleset", "/bin/cat {$g['tmp_path']}/rules.debug");
235
defCmdT("Firewall-Generated Ruleset Limiters", "/bin/cat {$g['tmp_path']}/rules.limiter");
236
defCmdT("Firewall-Generated Ruleset Limits", "/bin/cat {$g['tmp_path']}/rules.limits");
237
defCmdT("Firewall-pf NAT Rules", "/sbin/pfctl -vvsn");
238
defCmdT("Firewall-pf Firewall Rules", "/sbin/pfctl -vvsr");
239
defCmdT("Firewall-pf Tables", "/sbin/pfctl -vs Tables");
240
defCmdT("Firewall-pf State Table Contents", "/sbin/pfctl -vvss");
241
defCmdT("Firewall-pf Info", "/sbin/pfctl -si");
242
defCmdT("Firewall-pf Show All", "/sbin/pfctl -sa");
243
defCmdT("Firewall-pf Queues", "/sbin/pfctl -s queue -v");
244
defCmdT("Firewall-pf OSFP", "/sbin/pfctl -s osfp");
245
defCmdT("Firewall-pftop Default", "/usr/local/sbin/pftop -a -b");
246
defCmdT("Firewall-pftop Long", "/usr/local/sbin/pftop -w 150 -a -b -v long");
247
defCmdT("Firewall-pftop Queue", "/usr/local/sbin/pftop -w 150 -a -b -v queue");
248
defCmdT("Firewall-pftop Rules", "/usr/local/sbin/pftop -w 150 -a -b -v rules");
249
defCmdT("Firewall-pftop Size", "/usr/local/sbin/pftop -w 150 -a -b -v size");
250
defCmdT("Firewall-pftop Speed", "/usr/local/sbin/pftop -w 150 -a -b -v speed");
251
defCmdT("Firewall-IPFW Rules for Captive Portal", "/sbin/ipfw show");
252
defCmdT("Firewall-IPFW Limiter Info", "/sbin/ipfw pipe show");
253
defCmdT("Firewall-IPFW Queue Info", "/sbin/ipfw queue show");
254

    
255
if (is_array($config['load_balancer']['lbpool']) && is_array($config['load_balancer']['virtual_server'])) {
256
	defCmdT("Load Balancer-Redirects", "/usr/local/sbin/relayctl show redirects");
257
	defCmdT("Load Balancer-Relays", "/usr/local/sbin/relayctl show relays");
258
	defCmdT("Load Balancer-Summary", "/usr/local/sbin/relayctl show summary");
259
}
260

    
261
/* Configuration Files */
262
defCmdT("Disk-Contents of var run", "/bin/ls /var/run");
263
defCmdT("Disk-Contents of conf", "/bin/ls /conf");
264
defCmdT("config.xml", "dumpconfigxml");
265
defCmdT("DNS-Resolution Configuration", "/bin/cat /etc/resolv.conf");
266
defCmdT("DHCP-IPv4 Configuration", "/bin/cat /var/dhcpd/etc/dhcpd.conf");
267
defCmdT("DHCP-IPv6-Configuration", "/bin/cat /var/dhcpd/etc/dhcpdv6.conf");
268
defCmdT("IPsec-strongSwan Configuration", "/bin/cat /var/etc/ipsec/strongswan.conf");
269
defCmdT("IPsec-Configuration", "/bin/cat /var/etc/ipsec/ipsec.conf");
270
defCmdT("IPsec-Status", "/usr/local/sbin/ipsec statusall");
271
defCmdT("IPsec-SPD", "/sbin/setkey -DP");
272
defCmdT("IPsec-SAD", "/sbin/setkey -D");
273
if (file_exists("/cf/conf/upgrade_log.txt")) {
274
	defCmdT("OS-Upgrade Log", "/bin/cat /cf/conf/upgrade_log.txt");
275
}
276
if (file_exists("/boot/loader.conf")) {
277
	defCmdT("OS-Boot Loader Configuration", "/bin/cat /boot/loader.conf");
278
}
279
if (file_exists("/boot/loader.conf.local")) {
280
	defCmdT("OS-Boot Loader Configuration (Local)", "/bin/cat /boot/loader.conf.local");
281
}
282
if (file_exists("/var/etc/filterdns.conf")) {
283
	defCmdT("DNS-filterdns Daemon Configuration", "/bin/cat /var/etc/filterdns.conf");
284
}
285

    
286
/* Logs */
287
defCmdT("Log-System-Last 1000 entries", "/usr/local/sbin/clog /var/log/system.log 2>&1 | tail -n 1000");
288
defCmdT("Log-DHCP-Last 1000 entries", "/usr/local/sbin/clog /var/log/dhcpd.log 2>&1 | tail -n 1000");
289
defCmdT("Log-Filter-Last 500 entries", "/usr/local/sbin/clog /var/log/filter.log 2>&1 | tail -n 500");
290
defCmdT("Log-Gateways-Last 1000 entries", "/usr/local/sbin/clog /var/log/gateways.log 2>&1 | tail -n 1000");
291
defCmdT("Log-IPsec-Last 1000 entries", "/usr/local/sbin/clog /var/log/ipsec.log 2>&1 | tail -n 1000");
292
defCmdT("Log-L2TP-Last 1000 entries", "/usr/local/sbin/clog /var/log/l2tps.log 2>&1 | tail -n 1000");
293
defCmdT("Log-NTP-Last 1000 entries", "/usr/local/sbin/clog /var/log/ntpd.log 2>&1 | tail -n 1000");
294
defCmdT("Log-OpenVPN-Last 1000 entries", "/usr/local/sbin/clog /var/log/openvpn.log 2>&1 | tail -n 1000");
295
defCmdT("Log-Captive Portal Authentication-Last 1000 entries", "/usr/local/sbin/clog /var/log/portalauth.log 2>&1 | tail -n 1000");
296
defCmdT("Log-PPP-Last 1000 entries", "/usr/local/sbin/clog /var/log/poes.log 2>&1 | tail -n 1000");
297
defCmdT("Log-relayd-Last 1000 entries", "/usr/local/sbin/clog /var/log/relayd.log 2>&1 | tail -n 1000");
298
defCmdT("Log-DNS-Last 1000 entries", "/usr/local/sbin/clog /var/log/resolver.log 2>&1 | tail -n 1000");
299
defCmdT("Log-Routing-Last 1000 entries", "/usr/local/sbin/clog /var/log/routing.log 2>&1 | tail -n 1000");
300
defCmdT("Log-Wireless-Last 1000 entries", "/usr/local/sbin/clog /var/log/wireless.log 2>&1 | tail -n 1000");
301
if (file_exists("/tmp/PHP_errors.log")) {
302
	defCmdT("Log-PHP Errors", "/bin/cat /tmp/PHP_errors.log");
303
}
304
defCmdT("OS-Message Buffer", "/sbin/dmesg -a");
305
defCmdT("OS-Message Buffer (Boot)", "/bin/cat /var/log/dmesg.boot");
306

    
307
/* OS/Hardware Status */
308
defCmdT("OS-sysctl values", "/sbin/sysctl -a");
309
defCmdT("OS-Kernel Environment", "/bin/kenv");
310
defCmdT("OS-Installed Packages", "/usr/sbin/pkg info");
311
defCmdT("Hardware-PCI Devices", "/usr/sbin/pciconf -lvb");
312
defCmdT("Hardware-USB Devices", "/usr/sbin/usbconfig dump_device_desc");
313

    
314
if (is_module_loaded("zfs.ko")) {
315
	defCmdT("Disk-ZFS List", "/sbin/zfs list");
316
	defCmdT("Disk-ZFS Properties", "/sbin/zfs get all");
317
	defCmdT("Disk-ZFS Pool List", "/sbin/zpool list");
318
	defCmdT("Disk-ZFS Pool Status", "/sbin/zpool status");
319
}
320
defCmdT("Disk-GEOM Mirror Status", "/sbin/gmirror status");
321

    
322
exec("/bin/date", $dateOutput, $dateStatus);
323
$currentDate = $dateOutput[0];
324

    
325
$pgtitle = array($g['product_name'], "Status");
326
include("head.inc");
327

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

    
334
print_info_box(get_firewall_info(), 'info', false);
335

    
336
listCmds();
337
execCmds();
338

    
339
print(gettext("Saving output to archive..."));
340

    
341
if (is_dir($output_path)) {
342
	mwexec("/usr/bin/tar czpf " . escapeshellarg($output_file) . " -C " . escapeshellarg(dirname($output_path)) . " " . escapeshellarg(basename($output_path)));
343
	unlink_if_exists("{$output_path}/*");
344
	@rmdir($output_path);
345
}
346

    
347
print(gettext("Done."));
348

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