Project

General

Profile

Download (15.1 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-2024 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
global $errors;
43

    
44
$console = false;
45
$show_output = !isset($_GET['archiveonly']);
46
$errors = [];
47
$output_path = "/tmp/status_output/";
48
$output_file = "/tmp/status_output.tgz";
49

    
50
if ((php_sapi_name() == 'cli') ||
51
    (defined('STDIN'))) {
52
	/* Running from console/shell, not web */
53
	$console = true;
54
	$show_output = false;
55
	parse_str($argv[1], $_GET);
56
}
57

    
58
require_once('status_output.inc');
59

    
60
if ($_POST['submit'] == "DOWNLOAD" &&
61
    file_exists($output_file)) {
62
	session_cache_limiter('public');
63
	send_user_download('file', $output_file);
64
}
65

    
66
if (is_dir($output_path)) {
67
	unlink_if_exists("{$output_path}/*");
68
	@rmdir($output_path);
69
}
70
unlink_if_exists($output_file);
71
mkdir($output_path);
72

    
73
if ($console) {
74
	print(gettext("Gathering status data...") . "\n");
75
}
76

    
77
/* Set up all of the commands we want to execute. */
78

    
79
/* OS stats/info */
80

    
81
status_cmd_define("OS-Uptime", "/usr/bin/uptime");
82
status_cmd_define("Network-Interfaces", "/sbin/ifconfig -vvvvvam");
83
status_cmd_define("Network-Interface Statistics", "/usr/bin/netstat -nWi");
84
status_cmd_define("Network-Multicast Groups", "/usr/sbin/ifmcstat");
85
status_cmd_define("Process-Top Usage", "/usr/bin/top | /usr/bin/head -n5");
86
status_cmd_define("Process-List", "/bin/ps xauwwd");
87
status_cmd_define("Disk-Mounted Filesystems", "/sbin/mount");
88
status_cmd_define("Disk-Free Space", "/bin/df -hi");
89
status_cmd_define("Network-Routing tables", "/usr/bin/netstat -nWr");
90
status_cmd_define("Network-IPv4 Nexthop Data", "/usr/bin/netstat -4onW");
91
status_cmd_define("Network-IPv6 Nexthop Data", "/usr/bin/netstat -6onW");
92
status_cmd_define("Network-IPv4 Nexthop Group Data", "/usr/bin/netstat -4OnW");
93
status_cmd_define("Network-IPv6 Nexthop Group Data", "/usr/bin/netstat -6OnW");
94
status_cmd_define("Network-Gateway Status", 'status_get_gateway_status', "php_func");
95
status_cmd_define("Network-Mbuf Usage", "/usr/bin/netstat -mb");
96
status_cmd_define("Network-Protocol Statistics", "/usr/bin/netstat -s");
97
status_cmd_define("Network-Buffer and Timer Statistics", "/usr/bin/netstat -nWx");
98
status_cmd_define("Network-Listen Queues", "/usr/bin/netstat -LaAn");
99
status_cmd_define("Network-Sockets", "/usr/bin/sockstat");
100
status_cmd_define("Network-ARP Table", "/usr/sbin/arp -an");
101
status_cmd_define("Network-NDP Table", "/usr/sbin/ndp -na");
102
status_cmd_define("OS-Kernel Modules", "/sbin/kldstat -v");
103
status_cmd_define("OS-Kernel VMStat", "/usr/bin/vmstat -afimsz");
104

    
105
/* If a device has a switch, put the switch configuration in the status output */
106
if (file_exists("/dev/etherswitch0")) {
107
	status_cmd_define("Network-Switch Configuration", "/sbin/etherswitchcfg -f /dev/etherswitch0 info");
108
}
109

    
110
/* Firewall rules and info */
111
status_cmd_define("Firewall-Generated Ruleset", "/bin/cat " . g_get('tmp_path') . "/rules.debug");
112
status_cmd_define("Firewall-Generated Ruleset Limiters", "/bin/cat " . g_get('tmp_path') . "/rules.limiter");
113
status_cmd_define("Firewall-Generated Ruleset Limits", "/bin/cat " . g_get('tmp_path') . "/rules.limits");
114
foreach (glob(g_get('tmp_path') . "/rules.packages.*") as $pkgrules) {
115
	$pkgname = substr($pkgrules, strrpos($pkgrules, '.') + 1);
116
	status_cmd_define("Firewall-Generated Package Invalid Ruleset {$pkgname}", "/bin/cat " . escapeshellarg($pkgrules));
117
}
118
$ovpnradrules = array();
119
foreach (glob(g_get('tmp_path') . "/ovpn_ovpns*.rules") as $ovpnrules) {
120
	if (preg_match('/ovpn_ovpns(\d+)\_(\w+)\_(\d+)\.rules/', basename($ovpnrules), $matches)) {
121
		$ovpnradrules[$matches[1]] .= "# user '{$matches[2]}' remote port {$matches[3]}\n";
122
		$ovpnradrules[$matches[1]] .= file_get_contents($ovpnrules);
123
		$ovpnradrules[$matches[1]] .= "\n";
124
	}
125
}
126
foreach ($ovpnradrules as $ovpns => $genrules) {
127
	status_cmd_define("OpenVPN-Generated RADIUS ACL Ruleset for server{$ovpns}",
128
	  "echo " .  escapeshellarg($genrules));
129
}
130
status_cmd_define("Firewall-pf NAT Rules", "/sbin/pfctl -vvsn");
131
status_cmd_define("Firewall-pf Firewall Rules", "/sbin/pfctl -vvsr");
132
status_cmd_define("Firewall-pf Tables", "/sbin/pfctl -vs Tables");
133
status_cmd_define("Firewall-pf State Table Contents", "/sbin/pfctl -vvss");
134
status_cmd_define("Firewall-pf Info", "/sbin/pfctl -si");
135
status_cmd_define("Firewall-pf Show All", "/sbin/pfctl -sa");
136
status_cmd_define("Firewall-pf Queues", "/sbin/pfctl -s queue -v");
137
status_cmd_define("Firewall-pf OSFP", "/sbin/pfctl -s osfp");
138
status_cmd_define("Firewall-pftop Default", "/usr/local/sbin/pftop -a -b");
139
status_cmd_define("Firewall-pftop Long", "/usr/local/sbin/pftop -w 150 -a -b -v long");
140
status_cmd_define("Firewall-pftop Queue", "/usr/local/sbin/pftop -w 150 -a -b -v queue");
141
status_cmd_define("Firewall-pftop Rules", "/usr/local/sbin/pftop -w 150 -a -b -v rules");
142
status_cmd_define("Firewall-pftop Size", "/usr/local/sbin/pftop -w 150 -a -b -v size");
143
status_cmd_define("Firewall-pftop Speed", "/usr/local/sbin/pftop -w 150 -a -b -v speed");
144
status_cmd_define("Firewall-Limiter Info", "/sbin/dnctl pipe show");
145
status_cmd_define("Firewall-Queue Info", "/sbin/dnctl queue show");
146

    
147
/* Configuration Files */
148
status_cmd_define("Disk-Contents of var run", "/bin/ls /var/run");
149
status_cmd_define("Disk-Contents of conf", "/bin/ls /conf");
150
status_cmd_define("config.xml", "dumpconfigxml");
151
status_cmd_define("DNS-Resolution Configuration", "/bin/cat /etc/resolv.conf");
152
status_cmd_define("DNS-Resolver Access Lists", "/bin/cat /var/unbound/access_lists.conf");
153
status_cmd_define("DNS-Resolver Configuration", "/bin/cat /var/unbound/unbound.conf");
154
status_cmd_define("DNS-Resolver Domain Overrides", "/bin/cat /var/unbound/domainoverrides.conf");
155
status_cmd_define("DNS-Resolver Host Overrides", "/bin/cat /var/unbound/host_entries.conf");
156

    
157
if (file_exists("/var/dhcpd/etc/dhcpd.conf")) {
158
	status_cmd_define("DHCP-ISC-IPv4 Configuration", '/usr/bin/sed "s/\([[:blank:]]secret \).*/\1<redacted>/" /var/dhcpd/etc/dhcpd.conf');
159
}
160
if (file_exists("/var/dhcpd/etc/dhcpdv6.conf")) {
161
	status_cmd_define("DHCP-ISC-IPv6-Configuration", '/usr/bin/sed "s/\([[:blank:]]secret \).*/\1<redacted>/" /var/dhcpd/etc/dhcpdv6.conf');
162
}
163
if (file_exists("/usr/local/etc/kea/kea-dhcp4.conf")) {
164
	status_cmd_define("DHCP-Kea-IPv4 Configuration", '/bin/cat /usr/local/etc/kea/kea-dhcp4.conf');
165
}
166
if (file_exists("/usr/local/etc/kea/kea-dhcp6.conf")) {
167
	status_cmd_define("DHCP-Kea-IPv6 Configuration", '/bin/cat /usr/local/etc/kea/kea-dhcp6.conf');
168
}
169

    
170
if (file_exists("/var/etc/ipsec/strongswan.conf")) {
171
	status_cmd_define("IPsec-strongSwan Configuration", '/usr/bin/sed "s/\([[:blank:]]secret = \).*/\1<redacted>/" /var/etc/ipsec/strongswan.conf');
172
}
173
if (file_exists("/var/etc/ipsec/swanctl.conf")) {
174
	status_cmd_define("IPsec-Configuration", '/usr/bin/sed -E "s/([[:blank:]]*(secret|pin) = ).*/\1<redacted>/" /var/etc/ipsec/swanctl.conf');
175
}
176
if (file_exists("/var/run/charon.vici")) {
177
	status_cmd_define("IPsec-Status-Statistics", "/usr/local/sbin/swanctl --stats --pretty");
178
	status_cmd_define("IPsec-Status-Connections", "/usr/local/sbin/swanctl --list-conns");
179
	status_cmd_define("IPsec-Status-Active SAs", "/usr/local/sbin/swanctl --list-sas");
180
	status_cmd_define("IPsec-Status-Policies", "/usr/local/sbin/swanctl --list-pols");
181
	status_cmd_define("IPsec-Status-Certificates", "/usr/local/sbin/swanctl --list-certs --utc");
182
	status_cmd_define("IPsec-Status-Pools", "/usr/local/sbin/swanctl --list-pools --leases");
183
}
184

    
185
status_cmd_define("IPsec-SPD", "/sbin/setkey -DP");
186
status_cmd_define("IPsec-SAD", "/sbin/setkey -D");
187
if (file_exists("/cf/conf/upgrade_log.txt")) {
188
	status_cmd_define("OS-Upgrade Log", "/bin/cat /cf/conf/upgrade_log.txt");
189
}
190
if (file_exists("/cf/conf/upgrade_log.latest.txt")) {
191
	status_cmd_define("OS-Upgrade Log Latest", "/bin/cat /cf/conf/upgrade_log.latest.txt");
192
}
193
if (file_exists("/boot/loader.conf")) {
194
	status_cmd_define("OS-Boot Loader Configuration", "/bin/cat /boot/loader.conf");
195
}
196
if (file_exists("/boot/loader.conf.local")) {
197
	status_cmd_define("OS-Boot Loader Configuration (Local)", "/bin/cat /boot/loader.conf.local");
198
}
199
if (file_exists("/boot/loader.conf.lua")) {
200
	status_cmd_define("OS-Boot Loader Configuration (Lua)", "/bin/cat /boot/loader.conf.lua");
201
}
202
if (file_exists("/var/etc/filterdns.conf")) {
203
	status_cmd_define("DNS-filterdns Daemon Configuration", "/bin/cat /var/etc/filterdns.conf");
204
}
205

    
206
if (is_dir("/var/etc/openvpn")) {
207
	foreach(glob('/var/etc/openvpn/*/config.ovpn') as $file) {
208
		$ovpnfile = explode('/', $file);
209
		if (!count($ovpnfile) || (count($ovpnfile) < 6)) {
210
			continue;
211
		}
212
		status_cmd_define("OpenVPN-Configuration {$ovpnfile[4]}", "/bin/cat " . escapeshellarg($file));
213
	}
214
}
215

    
216
if (file_exists("/var/etc/l2tp-vpn/mpd.conf")) {
217
	status_cmd_define("L2TP-Configuration", '/usr/bin/sed -E "s/([[:blank:]](secret|radius server .*) ).*/\1<redacted>/" /var/etc/l2tp-vpn/mpd.conf');
218
}
219

    
220
/* Config History */
221
$confvers = get_backups();
222
unset($confvers['versions']);
223
if (count($confvers) != 0) {
224
	for ($c = count($confvers)-1; $c >= 0; $c--) {
225
		$conf_history .= backup_info($confvers[$c], $c+1);
226
		$conf_history .= "\n";
227
	}
228
	status_cmd_define("Config History", "echo " . escapeshellarg($conf_history));
229
}
230

    
231
status_log_add("System", '/var/log/system.log');
232
status_log_add("DHCP", '/var/log/dhcpd.log');
233
status_log_add("Filter", '/var/log/filter.log');
234
status_log_add("Gateways", '/var/log/gateways.log');
235
status_log_add("IPsec", '/var/log/ipsec.log');
236
status_log_add("L2TP", '/var/log/l2tps.log');
237
status_log_add("NTP", '/var/log/ntpd.log');
238
status_log_add("OpenVPN", '/var/log/openvpn.log');
239
status_log_add("Captive Portal Authentication", '/var/log/portalauth.log');
240
status_log_add("PPP", '/var/log/ppp.log');
241
status_log_add("PPPoE Server", '/var/log/poes.log');
242
status_log_add("DNS", '/var/log/resolver.log');
243
status_log_add("Routing", '/var/log/routing.log');
244
status_log_add("Wireless", '/var/log/wireless.log');
245
status_log_add("PHP Errors", '/tmp/PHP_errors.log', 'all');
246

    
247
status_cmd_define("OS-Message Buffer", "/sbin/dmesg -a");
248
status_cmd_define("OS-Message Buffer (Boot)", "/bin/cat /var/log/dmesg.boot");
249

    
250
/* OS/Hardware Status */
251
status_cmd_define("OS-sysctl values", "/sbin/sysctl -aq");
252
status_cmd_define("OS-Kernel Environment", "/bin/kenv");
253
status_cmd_define("OS-Kernel Memory Usage", "/usr/local/sbin/kmemusage.sh");
254
status_cmd_define("OS-Installed Packages", "/usr/local/sbin/pkg-static info");
255
status_cmd_define("OS-Package Manager Configuration", "/usr/local/sbin/pkg-static -vv");
256
status_cmd_define("Hardware-PCI Devices", "/usr/sbin/pciconf -lvb");
257
status_cmd_define("Hardware-USB Devices", "/usr/sbin/usbconfig dump_device_desc");
258

    
259
status_cmd_define("Disk-Filesystem Table", "/bin/cat /etc/fstab");
260
status_cmd_define("Disk-Swap Information", "/usr/sbin/swapinfo");
261

    
262
if (is_module_loaded("zfs.ko")) {
263
	status_cmd_define("Disk-ZFS List", "/sbin/zfs list");
264
	status_cmd_define("Disk-ZFS Properties", "/sbin/zfs get all");
265
	status_cmd_define("Disk-ZFS Pool List", "/sbin/zpool list");
266
	status_cmd_define("Disk-ZFS Pool Status", "/sbin/zpool status");
267
}
268

    
269
status_cmd_define("Disk-GEOM Tree", "/sbin/geom -t");
270
status_cmd_define("Disk-GEOM Disk List", "/sbin/geom disk list -a");
271
status_cmd_define("Disk-GEOM Partition Summary", "/sbin/geom part show -p");
272
status_cmd_define("Disk-GEOM Partition Details", "/sbin/geom part list");
273
status_cmd_define("Disk-GEOM Label Status", "/sbin/geom label status");
274
status_cmd_define("Disk-GEOM Label Details", "/sbin/geom label list");
275
status_cmd_define("Disk-GEOM Mirror Status", "/sbin/gmirror status");
276

    
277
/* Items specific to EFI */
278
if (get_single_sysctl("machdep.bootmethod") == "UEFI") {
279
	/* Basic EFI boot list is easier to read but only includes active entries */
280
	status_cmd_define("EFI-Boot Manager List", "/usr/sbin/efibootmgr");
281
	/* Verbose EFI boot list has a lot more detail but is more difficult to read */
282
	status_cmd_define("EFI-Boot Manager List (Verbose)", "/usr/sbin/efibootmgr -v");
283
}
284

    
285
exec("/bin/date", $dateOutput, $dateStatus);
286
$currentDate = $dateOutput[0];
287

    
288
$pgtitle = array(g_get('product_label'), "Status");
289

    
290
if (!$console):
291
include("head.inc"); ?>
292

    
293
<form action="status.php" method="post">
294

    
295
<?php print_info_box(
296
	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.") .
297
	'<br />' .
298
	gettext("Common password and other private fields in config.xml have been automatically redacted.") .
299
	'<br />' .
300
	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) .
301
	' <button name="submit" type="submit" class="btn btn-primary btn-sm" id="download" value="DOWNLOAD">' .
302
	'<i class="fa-solid fa-download icon-embed-btn"></i>' .
303
	gettext("Download") .
304
	'</button>'); ?>
305

    
306
</form>
307

    
308
<?php print_info_box(status_get_firewall_info(), 'info', false);
309

    
310
/* Call any registeredd package plugins which define status output to include
311
 * See https://redmine.pfsense.org/issues/14777 and
312
 *     https://redmine.pfsense.org/issues/1458
313
 */
314
$pluginparams = array();
315
$pluginparams['type'] = 'statusoutput';
316
pkg_call_plugins('plugin_statusoutput', $pluginparams);
317

    
318
if ($show_output) {
319
	status_cmd_list();
320
} else {
321
	print_info_box(gettext("Status output suppressed. Download archive to view."), 'info', false);
322
}
323

    
324
endif;
325

    
326
if ($console) {
327
	status_get_firewall_info();
328
}
329

    
330
status_cmd_run_all();
331

    
332
if (!empty($errors)) {
333
	$errorheader = gettext('Errors') . ": " . count($errors) . "\n";
334
	$errors[] = gettext("NOTE: Some errors are normal if a feature is not enabled or is inaccessible by the current user.\n");
335
	$errortext = $errorheader . implode('', $errors);
336
	file_put_contents("{$output_path}/_errors.txt", $errortext);
337
	if ($console) {
338
		echo $errortext;
339
	} else {
340
		print_info_box($errorheader . "<br/>" . implode('<br/>', $errors), 'warning', false);
341
	}
342
}
343

    
344
print(gettext("Saving output to archive..."));
345

    
346
if (is_dir($output_path)) {
347
	mwexec("/usr/bin/tar czpf " . escapeshellarg($output_file) . " -C " . escapeshellarg(dirname($output_path)) . " " . escapeshellarg(basename($output_path)));
348

    
349
	if (!isset($_GET["nocleanup"])) {
350
		unlink_if_exists("{$output_path}/*");
351
		@rmdir($output_path);
352
	}
353
}
354

    
355
print(gettext("Done.") . "\n");
356

    
357
if (!$console) {
358
	include("foot.inc");
359
}
(150-150/228)