Project

General

Profile

Download (15 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * status.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2018 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
$filtered_tags = array(
46
	'accountkey', 'authorizedkeys', 'auth_pass', 'auth_user', 'bcrypt-hash',
47
	'crypto_password', 'crypto_password2', 'dns_nsupdatensupdate_key',
48
	'gold_encryption_password', 'gold_password', 'ipsecpsk', 'ldap_bindpw',
49
	'lighttpd_ls_password', 'lighttpd_ls_password', 'md5-hash',
50
	'md5password', 'md5sigkey', 'md5sigpass', 'nt-hash', 'passphrase',
51
	'password', 'passwordagain', 'pre-shared-key', 'proxypass',
52
	'proxy_passwd', 'proxyuser', 'proxy_user', 'prv', 'radius_secret',
53
	'redis_password', 'redis_passwordagain', 'rocommunity', 'secret',
54
	'shared_key', 'tls', 'varclientpasswordinput', 'varclientsharedsecret',
55
	'varsyncpassword', 'varusersmotpinitsecret', 'varusersmotppin'
56
);
57

    
58
if ($_POST['submit'] == "DOWNLOAD" && file_exists($output_file)) {
59
	session_cache_limiter('public');
60
	$fd = fopen($output_file, "rb");
61
	header("Content-Type: application/octet-stream");
62
	header("Content-Length: " . filesize($output_file));
63
	header("Content-Disposition: attachment; filename=\"" .
64
		trim(htmlentities(basename($output_file))) . "\"");
65
	if (isset($_SERVER['HTTPS'])) {
66
		header('Pragma: ');
67
		header('Cache-Control: ');
68
	} else {
69
		header("Pragma: private");
70
		header("Cache-Control: private, must-revalidate");
71
	}
72

    
73
	fpassthru($fd);
74
	exit;
75
}
76

    
77
if (is_dir($output_path)) {
78
	unlink_if_exists("{$output_path}/*");
79
	@rmdir($output_path);
80
}
81
unlink_if_exists($output_file);
82
mkdir($output_path);
83

    
84
function doCmdT($title, $command, $method) {
85
	global $output_path, $output_file, $filtered_tags;
86
	/* Fixup output directory */
87

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

    
91
	print('<div class="panel panel-default">');
92
	print('<div class="panel-heading"><h2 class="panel-title">' . $title . '</h2></div>');
93
	print('<div class="panel-body">');
94
	print('<pre>');
95

    
96
	if ($command == "dumpconfigxml") {
97
		$ofd = @fopen("{$output_path}/config-sanitized.xml", "w");
98
		$fd = @fopen("/conf/config.xml", "r");
99
		if ($fd) {
100
			while (!feof($fd)) {
101
				$line = fgets($fd);
102
				/* remove sensitive contents */
103
				foreach ($filtered_tags as $tag) {
104
					$line = preg_replace("/<{$tag}>.*?<\\/{$tag}>/", "<{$tag}>xxxxx</{$tag}>", $line);
105
				}
106
				$line = str_replace("\t", "    ", $line);
107
				echo htmlspecialchars($line, ENT_NOQUOTES);
108
				fwrite($ofd, $line);
109
			}
110
		}
111
		fclose($fd);
112
		fclose($ofd);
113
	} else {
114
		$ofd = @fopen("{$output_path}/{$title}.txt", "w");
115
		$execOutput = "";
116
		$execStatus = "";
117
		if ($method == "exec") {
118
			exec($command . " 2>&1", $execOutput, $execStatus);
119
		} elseif ($method == "php_func") {
120
			$execOutput = explode("\n", $command());
121
		}
122
		for ($i = 0; isset($execOutput[$i]); $i++) {
123
			if ($i > 0) {
124
				echo "\n";
125
			}
126
			echo htmlspecialchars($execOutput[$i], ENT_NOQUOTES);
127
			fwrite($ofd, $execOutput[$i] . "\n");
128
		}
129
		fclose($ofd);
130
	}
131

    
132
	print('</pre>');
133
	print('</div>');
134
	print('</div>');
135
}
136

    
137
/* Define a command, with a title, to be executed later. */
138
function defCmdT($title, $command, $method = "exec") {
139
	global $commands;
140
	$title = htmlspecialchars($title, ENT_NOQUOTES);
141
	$commands[] = array($title, $command, $method);
142
}
143

    
144
/* List all of the commands as an index. */
145
function listCmds() {
146
	global $currentDate;
147
	global $commands;
148

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

    
151
	print('<div class="panel panel-default">');
152
	print('<div class="panel-heading"><h2 class="panel-title">' . sprintf(gettext("Firewall Status on %s"), $currentDate) . '</h2></div>');
153
	print('<div class="panel-body">');
154
	print('    <div class="content">');
155
	print("\n<p>" . gettext("This status page includes the following information") . ":\n");
156
	print("<ul>\n");
157
	for ($i = 0; isset($commands[$i]); $i++) {
158
		print("\t<li><strong><a href=\"#" . str_replace($rubbish, '', $commands[$i][0]) . "\">" . $commands[$i][0] . "</a></strong></li>\n");
159
	}
160

    
161
	print("</ul>\n");
162
	print('	       </div>');
163
	print('	   </div>');
164
	print('</div>');
165
}
166

    
167
/* Execute all of the commands which were defined by a call to defCmd. */
168
function execCmds() {
169
	global $commands;
170
	for ($i = 0; isset($commands[$i]); $i++) {
171
		doCmdT($commands[$i][0], $commands[$i][1], $commands[$i][2]);
172
	}
173
}
174

    
175
function get_firewall_info() {
176
	global $g, $output_path;
177
	/* Firewall Platform/Serial */
178
	$firewall_info = "Product Name: " . htmlspecialchars($g['product_name']);
179
	$platform = system_identify_specific_platform();
180
	if (!empty($platform['descr'])) {
181
		$firewall_info .= "<br/>Platform: " . htmlspecialchars($platform['descr']);
182
	}
183

    
184
	if (file_exists('/var/db/uniqueid')) {
185
		$ngid = file_get_contents('/var/db/uniqueid');
186
		if (!empty($ngid)) {
187
			$firewall_info .= "<br/>Netgate Device ID: " . htmlspecialchars($ngid);
188
		}
189
	}
190

    
191
	$serial = system_get_serial();
192
	if (!empty($serial)) {
193
		$firewall_info .= "<br/>Serial: " . htmlspecialchars($serial);
194
	}
195

    
196
	if (!empty($g['product_version_string'])) {
197
		$firewall_info .= "<br/>" . htmlspecialchars($g['product_name']) .
198
		    " version: " . htmlspecialchars($g['product_version_string']);
199
	}
200

    
201
	if (file_exists('/etc/version.buildtime')) {
202
		$build_time = file_get_contents('/etc/version.buildtime');
203
		if (!empty($build_time)) {
204
			$firewall_info .= "<br/>Built On: " . htmlspecialchars($build_time);
205
		}
206
	}
207
	if (file_exists('/etc/version.lastcommit')) {
208
		$build_commit = file_get_contents('/etc/version.lastcommit');
209
		if (!empty($build_commit)) {
210
			$firewall_info .= "<br/>Last Commit: " . htmlspecialchars($build_commit);
211
		}
212
	}
213

    
214
	if (file_exists('/etc/version.gitsync')) {
215
		$gitsync = file_get_contents('/etc/version.gitsync');
216
		if (!empty($gitsync)) {
217
			$firewall_info .= "<br/>A gitsync was performed at " .
218
			    date("D M j G:i:s T Y", filemtime('/etc/version.gitsync')) .
219
			    " to commit " . htmlspecialchars($gitsync);
220
		}
221
	}
222

    
223
	file_put_contents("{$output_path}/Product Info.txt", str_replace("<br/>", "\n", $firewall_info) . "\n");
224
	return $firewall_info;
225
}
226

    
227
function get_gateway_status() {
228
	return return_gateways_status_text(true, false);
229
}
230

    
231
global $g, $config;
232

    
233
/* Set up all of the commands we want to execute. */
234

    
235
/* OS stats/info */
236
defCmdT("OS-Uptime", "/usr/bin/uptime");
237
defCmdT("Network-Interfaces", "/sbin/ifconfig -va");
238
defCmdT("Network-Interface Statistics", "/usr/bin/netstat -nWi");
239
defCmdT("Process-Top Usage", "/usr/bin/top | /usr/bin/head -n5");
240
defCmdT("Process-List", "/bin/ps xauwwd");
241
defCmdT("Disk-Mounted Filesystems", "/sbin/mount");
242
defCmdT("Disk-Free Space", "/bin/df -hi");
243
defCmdT("Network-Routing tables", "/usr/bin/netstat -nWr");
244
defCmdT("Network-Gateway Status", 'get_gateway_status', "php_func");
245
defCmdT("Network-Mbuf Usage", "/usr/bin/netstat -mb");
246
defCmdT("Network-Protocol Statistics", "/usr/bin/netstat -s");
247
defCmdT("Network-Buffer and Timer Statistics", "/usr/bin/netstat -nWx");
248
defCmdT("Network-Sockets", "/usr/bin/sockstat");
249
defCmdT("Network-ARP Table", "/usr/sbin/arp -an");
250
defCmdT("Network-NDP Table", "/usr/sbin/ndp -na");
251
defCmdT("OS-Kernel VMStat", "/usr/bin/vmstat -afimsz");
252

    
253
/* If a device has a switch, put the switch configuration in the status output */
254
if (file_exists("/dev/etherswitch0")) {
255
	defCmdT("Network-Switch Configuration", "/sbin/etherswitchcfg -f /dev/etherswitch0 info");
256
}
257

    
258
/* Firewall rules and info */
259
defCmdT("Firewall-Generated Ruleset", "/bin/cat {$g['tmp_path']}/rules.debug");
260
defCmdT("Firewall-Generated Ruleset Limiters", "/bin/cat {$g['tmp_path']}/rules.limiter");
261
defCmdT("Firewall-Generated Ruleset Limits", "/bin/cat {$g['tmp_path']}/rules.limits");
262
defCmdT("Firewall-pf NAT Rules", "/sbin/pfctl -vvsn");
263
defCmdT("Firewall-pf Firewall Rules", "/sbin/pfctl -vvsr");
264
defCmdT("Firewall-pf Tables", "/sbin/pfctl -vs Tables");
265
defCmdT("Firewall-pf State Table Contents", "/sbin/pfctl -vvss");
266
defCmdT("Firewall-pf Info", "/sbin/pfctl -si");
267
defCmdT("Firewall-pf Show All", "/sbin/pfctl -sa");
268
defCmdT("Firewall-pf Queues", "/sbin/pfctl -s queue -v");
269
defCmdT("Firewall-pf OSFP", "/sbin/pfctl -s osfp");
270
defCmdT("Firewall-pftop Default", "/usr/local/sbin/pftop -a -b");
271
defCmdT("Firewall-pftop Long", "/usr/local/sbin/pftop -w 150 -a -b -v long");
272
defCmdT("Firewall-pftop Queue", "/usr/local/sbin/pftop -w 150 -a -b -v queue");
273
defCmdT("Firewall-pftop Rules", "/usr/local/sbin/pftop -w 150 -a -b -v rules");
274
defCmdT("Firewall-pftop Size", "/usr/local/sbin/pftop -w 150 -a -b -v size");
275
defCmdT("Firewall-pftop Speed", "/usr/local/sbin/pftop -w 150 -a -b -v speed");
276
defCmdT("Firewall-IPFW Rules for Captive Portal", "/sbin/ipfw show");
277
defCmdT("Firewall-IPFW Limiter Info", "/sbin/ipfw pipe show");
278
defCmdT("Firewall-IPFW Queue Info", "/sbin/ipfw queue show");
279

    
280
if (is_array($config['load_balancer']['lbpool']) && is_array($config['load_balancer']['virtual_server'])) {
281
	defCmdT("Load Balancer-Redirects", "/usr/local/sbin/relayctl show redirects");
282
	defCmdT("Load Balancer-Relays", "/usr/local/sbin/relayctl show relays");
283
	defCmdT("Load Balancer-Summary", "/usr/local/sbin/relayctl show summary");
284
}
285

    
286
/* Configuration Files */
287
defCmdT("Disk-Contents of var run", "/bin/ls /var/run");
288
defCmdT("Disk-Contents of conf", "/bin/ls /conf");
289
defCmdT("config.xml", "dumpconfigxml");
290
defCmdT("DNS-Resolution Configuration", "/bin/cat /etc/resolv.conf");
291
defCmdT("DHCP-IPv4 Configuration", "/bin/cat /var/dhcpd/etc/dhcpd.conf");
292
defCmdT("DHCP-IPv6-Configuration", "/bin/cat /var/dhcpd/etc/dhcpdv6.conf");
293
defCmdT("IPsec-strongSwan Configuration", "/bin/cat /var/etc/ipsec/strongswan.conf | /usr/bin/sed 's/[[:blank:]]secret = .*//'");
294
defCmdT("IPsec-Configuration", "/bin/cat /var/etc/ipsec/ipsec.conf");
295
defCmdT("IPsec-Status", "/usr/local/sbin/ipsec statusall");
296
defCmdT("IPsec-SPD", "/sbin/setkey -DP");
297
defCmdT("IPsec-SAD", "/sbin/setkey -D");
298
if (file_exists("/cf/conf/upgrade_log.txt")) {
299
	defCmdT("OS-Upgrade Log", "/bin/cat /cf/conf/upgrade_log.txt");
300
}
301
if (file_exists("/boot/loader.conf")) {
302
	defCmdT("OS-Boot Loader Configuration", "/bin/cat /boot/loader.conf");
303
}
304
if (file_exists("/boot/loader.conf.local")) {
305
	defCmdT("OS-Boot Loader Configuration (Local)", "/bin/cat /boot/loader.conf.local");
306
}
307
if (file_exists("/var/etc/filterdns.conf")) {
308
	defCmdT("DNS-filterdns Daemon Configuration", "/bin/cat /var/etc/filterdns.conf");
309
}
310

    
311
/* Logs */
312
defCmdT("Log-System-Last 1000 entries", "/usr/local/sbin/clog /var/log/system.log 2>&1 | tail -n 1000");
313
defCmdT("Log-DHCP-Last 1000 entries", "/usr/local/sbin/clog /var/log/dhcpd.log 2>&1 | tail -n 1000");
314
defCmdT("Log-Filter-Last 500 entries", "/usr/local/sbin/clog /var/log/filter.log 2>&1 | tail -n 500");
315
defCmdT("Log-Gateways-Last 1000 entries", "/usr/local/sbin/clog /var/log/gateways.log 2>&1 | tail -n 1000");
316
defCmdT("Log-IPsec-Last 1000 entries", "/usr/local/sbin/clog /var/log/ipsec.log 2>&1 | tail -n 1000");
317
defCmdT("Log-L2TP-Last 1000 entries", "/usr/local/sbin/clog /var/log/l2tps.log 2>&1 | tail -n 1000");
318
defCmdT("Log-NTP-Last 1000 entries", "/usr/local/sbin/clog /var/log/ntpd.log 2>&1 | tail -n 1000");
319
defCmdT("Log-OpenVPN-Last 1000 entries", "/usr/local/sbin/clog /var/log/openvpn.log 2>&1 | tail -n 1000");
320
defCmdT("Log-Captive Portal Authentication-Last 1000 entries", "/usr/local/sbin/clog /var/log/portalauth.log 2>&1 | tail -n 1000");
321
defCmdT("Log-PPP-Last 1000 entries", "/usr/local/sbin/clog /var/log/ppp.log 2>&1 | tail -n 1000");
322
defCmdT("Log-PPPoE Server-Last 1000 entries", "/usr/local/sbin/clog /var/log/poes.log 2>&1 | tail -n 1000");
323
defCmdT("Log-relayd-Last 1000 entries", "/usr/local/sbin/clog /var/log/relayd.log 2>&1 | tail -n 1000");
324
defCmdT("Log-DNS-Last 1000 entries", "/usr/local/sbin/clog /var/log/resolver.log 2>&1 | tail -n 1000");
325
defCmdT("Log-Routing-Last 1000 entries", "/usr/local/sbin/clog /var/log/routing.log 2>&1 | tail -n 1000");
326
defCmdT("Log-Wireless-Last 1000 entries", "/usr/local/sbin/clog /var/log/wireless.log 2>&1 | tail -n 1000");
327
if (file_exists("/tmp/PHP_errors.log")) {
328
	defCmdT("Log-PHP Errors", "/bin/cat /tmp/PHP_errors.log");
329
}
330
defCmdT("OS-Message Buffer", "/sbin/dmesg -a");
331
defCmdT("OS-Message Buffer (Boot)", "/bin/cat /var/log/dmesg.boot");
332

    
333
/* OS/Hardware Status */
334
defCmdT("OS-sysctl values", "/sbin/sysctl -aq");
335
defCmdT("OS-Kernel Environment", "/bin/kenv");
336
defCmdT("OS-Installed Packages", "/usr/sbin/pkg info");
337
defCmdT("Hardware-PCI Devices", "/usr/sbin/pciconf -lvb");
338
defCmdT("Hardware-USB Devices", "/usr/sbin/usbconfig dump_device_desc");
339

    
340
if (is_module_loaded("zfs.ko")) {
341
	defCmdT("Disk-ZFS List", "/sbin/zfs list");
342
	defCmdT("Disk-ZFS Properties", "/sbin/zfs get all");
343
	defCmdT("Disk-ZFS Pool List", "/sbin/zpool list");
344
	defCmdT("Disk-ZFS Pool Status", "/sbin/zpool status");
345
}
346
defCmdT("Disk-GEOM Mirror Status", "/sbin/gmirror status");
347

    
348
exec("/bin/date", $dateOutput, $dateStatus);
349
$currentDate = $dateOutput[0];
350

    
351
$pgtitle = array($g['product_name'], "Status");
352
include("head.inc"); ?>
353

    
354
<form action="status.php" method="post">
355

    
356
<?php print_info_box(
357
	gettext("Make sure all sensitive information is removed! (Passwords, etc.) before posting information from this page in public places (like mailing lists).") .
358
	'<br />' .
359
	gettext("Common password fields in config.xml have been automatically redacted.") .
360
	'<br />' .
361
	sprintf(gettext('When the page has finished loading, the output is stored in %1$s. It may be downloaded via scp or using this button: '), $output_file) .
362
	' <button name="submit" type="submit" class="btn btn-primary btn-sm" id="download" value="DOWNLOAD">' .
363
	'<i class="fa fa-download icon-embed-btn"></i>' .
364
	gettext("Download") .
365
	'</button>'); ?>
366

    
367
</form>
368

    
369
<?php print_info_box(get_firewall_info(), 'info', false);
370

    
371
listCmds();
372
execCmds();
373

    
374
print(gettext("Saving output to archive..."));
375

    
376
if (is_dir($output_path)) {
377
	mwexec("/usr/bin/tar czpf " . escapeshellarg($output_file) . " -C " . escapeshellarg(dirname($output_path)) . " " . escapeshellarg(basename($output_path)));
378
	unlink_if_exists("{$output_path}/*");
379
	@rmdir($output_path);
380
}
381

    
382
print(gettext("Done."));
383

    
384
include("foot.inc");
(156-156/234)