Project

General

Profile

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

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

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

    
40
global $console;
41
global $show_output;
42

    
43
$console = false;
44
$show_output = !isset($_GET['archiveonly']);
45

    
46
if ((php_sapi_name() == 'cli') || (defined('STDIN'))) {
47
	/* Running from console/shell, not web */
48
	$console = true;
49
	$show_output = false;
50
	parse_str($argv[1], $_GET);
51
}
52

    
53
/* include all configuration functions */
54
if ($console) {
55
	require_once("config.inc");
56
} else {
57
	require_once("guiconfig.inc");
58
}
59
require_once("functions.inc");
60
require_once("gwlb.inc");
61
$output_path = "/tmp/status_output/";
62
$output_file = "/tmp/status_output.tgz";
63

    
64
$filtered_tags = array(
65
	'accountkey', 'authorizedkeys', 'auth_pass', 'auth_user',
66
	'barnyard_dbpwd', 'bcrypt-hash', 'cert_key', 'crypto_password',
67
	'crypto_password2', 'dns_nsupdatensupdate_key', 'encryption_password',
68
	'etpro_code', 'etprocode', 'gold_encryption_password', 'gold_password',
69
	'influx_pass', 'ipsecpsk', 'ldap_bindpw', 'lighttpd_ls_password',
70
	'lighttpd_ls_password', 'md5-hash', 'md5password', 'md5sigkey',
71
	'md5sigpass', 'nt-hash', 'oinkcode', 'oinkmastercode', 'passphrase',
72
	'password', 'passwordagain', 'postgresqlpasswordenc', 'pre-shared-key',
73
	'proxypass', 'proxy_passwd', 'proxyuser', 'proxy_user', 'prv',
74
	'radius_secret', 'redis_password', 'redis_passwordagain', 'rocommunity',
75
	'secret', 'shared_key', 'tls', 'tlspskidentity', 'tlspskfile',
76
	'varclientpasswordinput', 'varclientsharedsecret', 'varsyncpassword',
77
	'varusersmotpinitsecret', 'varusersmotppin', 'pkcs11pin'
78
);
79

    
80
if ($_POST['submit'] == "DOWNLOAD" && file_exists($output_file)) {
81
	session_cache_limiter('public');
82
	send_user_download('file', $output_file);
83
}
84

    
85
if (is_dir($output_path)) {
86
	unlink_if_exists("{$output_path}/*");
87
	@rmdir($output_path);
88
}
89
unlink_if_exists($output_file);
90
mkdir($output_path);
91

    
92
function doCmdT($title, $command, $method) {
93
	global $output_path, $output_file, $filtered_tags, $show_output;
94
	/* Fixup output directory */
95

    
96
	if ($show_output) {
97
		$rubbish = array('|', '-', '/', '.', ' ');  /* fixes the <a> tag to be W3C compliant */
98
		echo "\n<a name=\"" . str_replace($rubbish, '', $title) . "\" id=\"" . str_replace($rubbish, '', $title) . "\"></a>\n";
99
		print('<div class="panel panel-default">');
100
		print('<div class="panel-heading"><h2 class="panel-title">' . $title . '</h2></div>');
101
		print('<div class="panel-body">');
102
		print('<pre>');
103
	}
104

    
105
	if ($command == "dumpconfigxml") {
106
		$ofd = @fopen("{$output_path}/config-sanitized.xml", "w");
107
		$fd = @fopen("/conf/config.xml", "r");
108
		if ($fd) {
109
			while (!feof($fd)) {
110
				$line = fgets($fd);
111
				/* remove sensitive contents */
112
				foreach ($filtered_tags as $tag) {
113
					$line = preg_replace("/<{$tag}>.*?<\\/{$tag}>/", "<{$tag}>xxxxx</{$tag}>", $line);
114
				}
115
				if ($show_output) {
116
					echo htmlspecialchars(str_replace("\t", "    ", $line), ENT_NOQUOTES);
117
				}
118
				fwrite($ofd, $line);
119
			}
120
		}
121
		fclose($fd);
122
		fclose($ofd);
123
	} else {
124
		$execOutput = "";
125
		$execStatus = "";
126
		$fn = "{$output_path}/{$title}.txt";
127
		if ($method == "exec") {
128
			exec($command . " > " . escapeshellarg($fn) . " 2>&1", $execOutput, $execStatus);
129
			if ($show_output) {
130
				$ofd = @fopen($fn, "r");
131
				if ($ofd) {
132
					while (!feof($ofd)) {
133
						echo htmlspecialchars(fgets($ofd), ENT_NOQUOTES);
134
					}
135
				}
136
				fclose($ofd);
137
			}
138
		} elseif ($method == "php_func") {
139
			$execOutput = $command();
140
			if ($show_output) {
141
				echo htmlspecialchars($execOutput, ENT_NOQUOTES);
142
			}
143
			file_put_contents($fn, $execOutput);
144
		}
145
	}
146

    
147
	if ($show_output) {
148
		print('</pre>');
149
		print('</div>');
150
		print('</div>');
151
	}
152
}
153

    
154
/* Define a command, with a title, to be executed later. */
155
function defCmdT($title, $command, $method = "exec") {
156
	global $commands;
157
	$title = htmlspecialchars($title, ENT_NOQUOTES);
158
	$commands[] = array($title, $command, $method);
159
}
160

    
161
/* List all of the commands as an index. */
162
function listCmds() {
163
	global $currentDate;
164
	global $commands;
165

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

    
168
	print('<div class="panel panel-default">');
169
	print('<div class="panel-heading"><h2 class="panel-title">' . sprintf(gettext("Firewall Status on %s"), $currentDate) . '</h2></div>');
170
	print('<div class="panel-body">');
171
	print('    <div class="content">');
172
	print("\n<p>" . gettext("This status page includes the following information") . ":\n");
173
	print("<ul>\n");
174
	for ($i = 0; isset($commands[$i]); $i++) {
175
		print("\t<li><strong><a href=\"#" . str_replace($rubbish, '', $commands[$i][0]) . "\">" . $commands[$i][0] . "</a></strong></li>\n");
176
	}
177

    
178
	print("</ul>\n");
179
	print('	       </div>');
180
	print('	   </div>');
181
	print('</div>');
182
}
183

    
184
/* Execute all of the commands which were defined by a call to defCmd. */
185
function execCmds() {
186
	global $commands;
187
	for ($i = 0; isset($commands[$i]); $i++) {
188
		doCmdT($commands[$i][0], $commands[$i][1], $commands[$i][2]);
189
	}
190
}
191

    
192
function get_firewall_info() {
193
	global $g, $output_path;
194
	/* Firewall Platform/Serial */
195
	$firewall_info = "Product Name: " . htmlspecialchars($g['product_name']);
196
	$platform = system_identify_specific_platform();
197
	if (!empty($platform['descr'])) {
198
		$firewall_info .= "<br/>Platform: " . htmlspecialchars($platform['descr']);
199
	}
200

    
201
	if (file_exists('/var/db/uniqueid')) {
202
		$ngid = file_get_contents('/var/db/uniqueid');
203
		if (!empty($ngid)) {
204
			$firewall_info .= "<br/>Netgate Device ID: " . htmlspecialchars($ngid);
205
		}
206
	}
207

    
208
	if (function_exists("system_get_thothid") &&
209
	    (php_uname("m") == "arm64")) {
210
		$thothid = system_get_thothid();
211
		if (!empty($thothid)) {
212
			$firewall_info .= "<br/>Netgate Crypto ID: " . htmlspecialchars(chop($thothid));
213
		}
214
	}
215

    
216
	$serial = system_get_serial();
217
	if (!empty($serial)) {
218
		$firewall_info .= "<br/>Serial: " . htmlspecialchars($serial);
219
	}
220

    
221
	if (!empty($g['product_version_string'])) {
222
		$firewall_info .= "<br/>" . htmlspecialchars($g['product_name']) .
223
		    " version: " . htmlspecialchars($g['product_version_string']);
224
	}
225

    
226
	if (file_exists('/etc/version.buildtime')) {
227
		$build_time = file_get_contents('/etc/version.buildtime');
228
		if (!empty($build_time)) {
229
			$firewall_info .= "<br/>Built On: " . htmlspecialchars($build_time);
230
		}
231
	}
232
	if (file_exists('/etc/version.lastcommit')) {
233
		$build_commit = file_get_contents('/etc/version.lastcommit');
234
		if (!empty($build_commit)) {
235
			$firewall_info .= "<br/>Last Commit: " . htmlspecialchars($build_commit);
236
		}
237
	}
238

    
239
	if (file_exists('/etc/version.gitsync')) {
240
		$gitsync = file_get_contents('/etc/version.gitsync');
241
		if (!empty($gitsync)) {
242
			$firewall_info .= "<br/>A gitsync was performed at " .
243
			    date("D M j G:i:s T Y", filemtime('/etc/version.gitsync')) .
244
			    " to commit " . htmlspecialchars($gitsync);
245
		}
246
	}
247

    
248
	file_put_contents("{$output_path}/Product-Info.txt", str_replace("<br/>", "\n", $firewall_info) . "\n");
249
	return $firewall_info;
250
}
251

    
252
function get_gateway_status() {
253
	return return_gateways_status_text(true, false);
254
}
255

    
256
global $g, $config;
257

    
258
/* Set up all of the commands we want to execute. */
259

    
260
/* OS stats/info */
261
if (function_exists("system_get_thothid") &&
262
    (php_uname("m") == "arm64")) {
263
	$thothid = system_get_thothid();
264
	if (!empty($thothid)) {
265
		defCmdT("Product-Public Key", "/usr/local/sbin/ping-auth -p");
266
	}
267
}
268

    
269
defCmdT("OS-Uptime", "/usr/bin/uptime");
270
defCmdT("Network-Interfaces", "/sbin/ifconfig -vvvvvam");
271
defCmdT("Network-Interface Statistics", "/usr/bin/netstat -nWi");
272
defCmdT("Process-Top Usage", "/usr/bin/top | /usr/bin/head -n5");
273
defCmdT("Process-List", "/bin/ps xauwwd");
274
defCmdT("Disk-Mounted Filesystems", "/sbin/mount");
275
defCmdT("Disk-Free Space", "/bin/df -hi");
276
defCmdT("Network-Routing tables", "/usr/bin/netstat -nWr");
277
defCmdT("Network-Gateway Status", 'get_gateway_status', "php_func");
278
defCmdT("Network-Mbuf Usage", "/usr/bin/netstat -mb");
279
defCmdT("Network-Protocol Statistics", "/usr/bin/netstat -s");
280
defCmdT("Network-Buffer and Timer Statistics", "/usr/bin/netstat -nWx");
281
defCmdT("Network-Listen Queues", "/usr/bin/netstat -LaAn");
282
defCmdT("Network-Sockets", "/usr/bin/sockstat");
283
defCmdT("Network-ARP Table", "/usr/sbin/arp -an");
284
defCmdT("Network-NDP Table", "/usr/sbin/ndp -na");
285
defCmdT("OS-Kernel VMStat", "/usr/bin/vmstat -afimsz");
286

    
287
/* If a device has a switch, put the switch configuration in the status output */
288
if (file_exists("/dev/etherswitch0")) {
289
	defCmdT("Network-Switch Configuration", "/sbin/etherswitchcfg -f /dev/etherswitch0 info");
290
}
291

    
292
/* Firewall rules and info */
293
defCmdT("Firewall-Generated Ruleset", "/bin/cat {$g['tmp_path']}/rules.debug");
294
defCmdT("Firewall-Generated Ruleset Limiters", "/bin/cat {$g['tmp_path']}/rules.limiter");
295
defCmdT("Firewall-Generated Ruleset Limits", "/bin/cat {$g['tmp_path']}/rules.limits");
296
defCmdT("Firewall-pf NAT Rules", "/sbin/pfctl -vvsn");
297
defCmdT("Firewall-pf Firewall Rules", "/sbin/pfctl -vvsr");
298
defCmdT("Firewall-pf Tables", "/sbin/pfctl -vs Tables");
299
defCmdT("Firewall-pf State Table Contents", "/sbin/pfctl -vvss");
300
defCmdT("Firewall-pf Info", "/sbin/pfctl -si");
301
defCmdT("Firewall-pf Show All", "/sbin/pfctl -sa");
302
defCmdT("Firewall-pf Queues", "/sbin/pfctl -s queue -v");
303
defCmdT("Firewall-pf OSFP", "/sbin/pfctl -s osfp");
304
defCmdT("Firewall-pftop Default", "/usr/local/sbin/pftop -a -b");
305
defCmdT("Firewall-pftop Long", "/usr/local/sbin/pftop -w 150 -a -b -v long");
306
defCmdT("Firewall-pftop Queue", "/usr/local/sbin/pftop -w 150 -a -b -v queue");
307
defCmdT("Firewall-pftop Rules", "/usr/local/sbin/pftop -w 150 -a -b -v rules");
308
defCmdT("Firewall-pftop Size", "/usr/local/sbin/pftop -w 150 -a -b -v size");
309
defCmdT("Firewall-pftop Speed", "/usr/local/sbin/pftop -w 150 -a -b -v speed");
310
defCmdT("Firewall-IPFW Rules for Captive Portal", "/sbin/ipfw show");
311
defCmdT("Firewall-IPFW Limiter Info", "/sbin/ipfw pipe show");
312
defCmdT("Firewall-IPFW Queue Info", "/sbin/ipfw queue show");
313

    
314
/* Configuration Files */
315
defCmdT("Disk-Contents of var run", "/bin/ls /var/run");
316
defCmdT("Disk-Contents of conf", "/bin/ls /conf");
317
defCmdT("config.xml", "dumpconfigxml");
318
defCmdT("DNS-Resolution Configuration", "/bin/cat /etc/resolv.conf");
319
defCmdT("DHCP-IPv4 Configuration", "/bin/cat /var/dhcpd/etc/dhcpd.conf");
320
defCmdT("DHCP-IPv6-Configuration", "/bin/cat /var/dhcpd/etc/dhcpdv6.conf");
321
defCmdT("IPsec-strongSwan Configuration", "/bin/cat /var/etc/ipsec/strongswan.conf | /usr/bin/sed 's/[[:blank:]]secret = .*//'");
322
defCmdT("IPsec-Configuration", "/bin/cat /var/etc/ipsec/ipsec.conf");
323
defCmdT("IPsec-Status-Statistics", "/usr/local/sbin/swanctl --stats --pretty");
324
defCmdT("IPsec-Status-Connections", "/usr/local/sbin/swanctl --list-conns");
325
defCmdT("IPsec-Status-Active SAs", "/usr/local/sbin/swanctl --list-sas");
326
defCmdT("IPsec-Status-Policies", "/usr/local/sbin/swanctl --list-pols");
327
defCmdT("IPsec-Status-Certificates", "/usr/local/sbin/swanctl --list-certs --utc");
328
defCmdT("IPsec-Status-Pools", "/usr/local/sbin/swanctl --list-pools --leases");
329
defCmdT("IPsec-SPD", "/sbin/setkey -DP");
330
defCmdT("IPsec-SAD", "/sbin/setkey -D");
331
if (file_exists("/cf/conf/upgrade_log.txt")) {
332
	defCmdT("OS-Upgrade Log", "/bin/cat /cf/conf/upgrade_log.txt");
333
}
334
if (file_exists("/boot/loader.conf")) {
335
	defCmdT("OS-Boot Loader Configuration", "/bin/cat /boot/loader.conf");
336
}
337
if (file_exists("/boot/loader.conf.local")) {
338
	defCmdT("OS-Boot Loader Configuration (Local)", "/bin/cat /boot/loader.conf.local");
339
}
340
if (file_exists("/var/etc/filterdns.conf")) {
341
	defCmdT("DNS-filterdns Daemon Configuration", "/bin/cat /var/etc/filterdns.conf");
342
}
343

    
344
/* Logs */
345
function status_add_log($name, $logfile, $number = 1000) {
346
	if (!file_exists($logfile)) {
347
		return;
348
	}
349
	$descr = "Log-{$name}";
350
	$tail = '';
351
	if ($number != "all") {
352
		$descr .= "-Last {$number} entries";
353
		$tail = ' | tail -n ' . escapeshellarg($number);
354
	}
355
	defCmdT($descr, system_log_get_cat() . ' ' . sort_related_log_files($logfile, true, true) . $tail);
356
}
357

    
358
status_add_log("System", '/var/log/system.log');
359
status_add_log("DHCP", '/var/log/dhcpd.log');
360
status_add_log("Filter", '/var/log/filter.log');
361
status_add_log("Gateways", '/var/log/gateways.log');
362
status_add_log("IPsec", '/var/log/ipsec.log');
363
status_add_log("L2TP", '/var/log/l2tps.log');
364
status_add_log("NTP", '/var/log/ntpd.log');
365
status_add_log("OpenVPN", '/var/log/openvpn.log');
366
status_add_log("Captive Portal Authentication", '/var/log/portalauth.log');
367
status_add_log("PPP", '/var/log/ppp.log');
368
status_add_log("PPPoE Server", '/var/log/poes.log');
369
status_add_log("DNS", '/var/log/resolver.log');
370
status_add_log("Routing", '/var/log/routing.log');
371
status_add_log("Wireless", '/var/log/wireless.log');
372
status_add_log("PHP Errors", '/tmp/PHP_errors.log', 'all');
373

    
374
defCmdT("OS-Message Buffer", "/sbin/dmesg -a");
375
defCmdT("OS-Message Buffer (Boot)", "/bin/cat /var/log/dmesg.boot");
376

    
377
/* OS/Hardware Status */
378
defCmdT("OS-sysctl values", "/sbin/sysctl -aq");
379
defCmdT("OS-Kernel Environment", "/bin/kenv");
380
defCmdT("OS-Kernel Memory Usage", "/usr/local/sbin/kmemusage.sh");
381
defCmdT("OS-Installed Packages", "/usr/sbin/pkg info");
382
defCmdT("OS-Package Manager Configuration", "/usr/sbin/pkg -vv");
383
defCmdT("Hardware-PCI Devices", "/usr/sbin/pciconf -lvb");
384
defCmdT("Hardware-USB Devices", "/usr/sbin/usbconfig dump_device_desc");
385

    
386
if (is_module_loaded("zfs.ko")) {
387
	defCmdT("Disk-ZFS List", "/sbin/zfs list");
388
	defCmdT("Disk-ZFS Properties", "/sbin/zfs get all");
389
	defCmdT("Disk-ZFS Pool List", "/sbin/zpool list");
390
	defCmdT("Disk-ZFS Pool Status", "/sbin/zpool status");
391
}
392
defCmdT("Disk-GEOM Mirror Status", "/sbin/gmirror status");
393

    
394
exec("/bin/date", $dateOutput, $dateStatus);
395
$currentDate = $dateOutput[0];
396

    
397
$pgtitle = array($g['product_name'], "Status");
398

    
399
if (!$console):
400
include("head.inc"); ?>
401

    
402
<form action="status.php" method="post">
403

    
404
<?php print_info_box(
405
	gettext("Make sure all sensitive information is removed! (Passwords, etc.) before posting information from this page in public places such as forum or social media sites.") .
406
	'<br />' .
407
	gettext("Common password and other private fields in config.xml have been automatically redacted.") .
408
	'<br />' .
409
	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) .
410
	' <button name="submit" type="submit" class="btn btn-primary btn-sm" id="download" value="DOWNLOAD">' .
411
	'<i class="fa fa-download icon-embed-btn"></i>' .
412
	gettext("Download") .
413
	'</button>'); ?>
414

    
415
</form>
416

    
417
<?php print_info_box(get_firewall_info(), 'info', false);
418

    
419
if ($show_output) {
420
	listCmds();
421
} else {
422
	print_info_box(gettext("Status output suppressed. Download archive to view."), 'info', false);
423
}
424

    
425
endif;
426

    
427
if ($console) {
428
	print(gettext("Gathering status data...") . "\n");
429
	get_firewall_info();
430
}
431
execCmds();
432

    
433
print(gettext("Saving output to archive..."));
434

    
435
if (is_dir($output_path)) {
436
	mwexec("/usr/bin/tar czpf " . escapeshellarg($output_file) . " -C " . escapeshellarg(dirname($output_path)) . " " . escapeshellarg(basename($output_path)));
437

    
438
	if (!isset($_GET["nocleanup"])) {
439
		unlink_if_exists("{$output_path}/*");
440
		@rmdir($output_path);
441
	}
442
}
443

    
444
print(gettext("Done.") . "\n");
445

    
446
if (!$console) {
447
	include("foot.inc");
448
}
(150-150/227)