Project

General

Profile

Download (14.2 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-2023 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
if (function_exists("system_get_thothid") &&
81
    (php_uname("m") == "arm64")) {
82
	$thothid = system_get_thothid();
83
	if (!empty($thothid)) {
84
		status_cmd_define("Product-Public Key", "/usr/local/sbin/ping-auth -p");
85
	}
86
}
87

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

    
112
/* If a device has a switch, put the switch configuration in the status output */
113
if (file_exists("/dev/etherswitch0")) {
114
	status_cmd_define("Network-Switch Configuration", "/sbin/etherswitchcfg -f /dev/etherswitch0 info");
115
}
116

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

    
154
/* Configuration Files */
155
status_cmd_define("Disk-Contents of var run", "/bin/ls /var/run");
156
status_cmd_define("Disk-Contents of conf", "/bin/ls /conf");
157
status_cmd_define("config.xml", "dumpconfigxml");
158
status_cmd_define("DNS-Resolution Configuration", "/bin/cat /etc/resolv.conf");
159
status_cmd_define("DNS-Resolver Access Lists", "/bin/cat /var/unbound/access_lists.conf");
160
status_cmd_define("DNS-Resolver Configuration", "/bin/cat /var/unbound/unbound.conf");
161
status_cmd_define("DNS-Resolver Domain Overrides", "/bin/cat /var/unbound/domainoverrides.conf");
162
status_cmd_define("DNS-Resolver Host Overrides", "/bin/cat /var/unbound/host_entries.conf");
163
status_cmd_define("DHCP-IPv4 Configuration", '/usr/bin/sed "s/\([[:blank:]]secret \).*/\1<redacted>/" /var/dhcpd/etc/dhcpd.conf');
164
status_cmd_define("DHCP-IPv6-Configuration", '/usr/bin/sed "s/\([[:blank:]]secret \).*/\1<redacted>/" /var/dhcpd/etc/dhcpdv6.conf');
165
status_cmd_define("IPsec-strongSwan Configuration", '/usr/bin/sed "s/\([[:blank:]]secret = \).*/\1<redacted>/" /var/etc/ipsec/strongswan.conf');
166
status_cmd_define("IPsec-Configuration", '/usr/bin/sed -E "s/([[:blank:]]*(secret|pin) = ).*/\1<redacted>/" /var/etc/ipsec/swanctl.conf');
167
status_cmd_define("IPsec-Status-Statistics", "/usr/local/sbin/swanctl --stats --pretty");
168
status_cmd_define("IPsec-Status-Connections", "/usr/local/sbin/swanctl --list-conns");
169
status_cmd_define("IPsec-Status-Active SAs", "/usr/local/sbin/swanctl --list-sas");
170
status_cmd_define("IPsec-Status-Policies", "/usr/local/sbin/swanctl --list-pols");
171
status_cmd_define("IPsec-Status-Certificates", "/usr/local/sbin/swanctl --list-certs --utc");
172
status_cmd_define("IPsec-Status-Pools", "/usr/local/sbin/swanctl --list-pools --leases");
173
status_cmd_define("IPsec-SPD", "/sbin/setkey -DP");
174
status_cmd_define("IPsec-SAD", "/sbin/setkey -D");
175
if (file_exists("/cf/conf/upgrade_log.txt")) {
176
	status_cmd_define("OS-Upgrade Log", "/bin/cat /cf/conf/upgrade_log.txt");
177
}
178
if (file_exists("/cf/conf/upgrade_log.latest.txt")) {
179
	status_cmd_define("OS-Upgrade Log Latest", "/bin/cat /cf/conf/upgrade_log.latest.txt");
180
}
181
if (file_exists("/boot/loader.conf")) {
182
	status_cmd_define("OS-Boot Loader Configuration", "/bin/cat /boot/loader.conf");
183
}
184
if (file_exists("/boot/loader.conf.local")) {
185
	status_cmd_define("OS-Boot Loader Configuration (Local)", "/bin/cat /boot/loader.conf.local");
186
}
187
if (file_exists("/var/etc/filterdns.conf")) {
188
	status_cmd_define("DNS-filterdns Daemon Configuration", "/bin/cat /var/etc/filterdns.conf");
189
}
190

    
191
if (is_dir("/var/etc/openvpn")) {
192
	foreach(glob('/var/etc/openvpn/*/config.ovpn') as $file) {
193
		$ovpnfile = explode('/', $file);
194
		if (!count($ovpnfile) || (count($ovpnfile) < 6)) {
195
			continue;
196
		}
197
		status_cmd_define("OpenVPN-Configuration {$ovpnfile[4]}", "/bin/cat " . escapeshellarg($file));
198
	}
199
}
200

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

    
205
/* Config History */
206
$confvers = get_backups();
207
unset($confvers['versions']);
208
if (count($confvers) != 0) {
209
	for ($c = count($confvers)-1; $c >= 0; $c--) {
210
		$conf_history .= backup_info($confvers[$c], $c+1);
211
		$conf_history .= "\n";
212
	}
213
	status_cmd_define("Config History", "echo " . escapeshellarg($conf_history));
214
}
215

    
216
status_log_add("System", '/var/log/system.log');
217
status_log_add("DHCP", '/var/log/dhcpd.log');
218
status_log_add("Filter", '/var/log/filter.log');
219
status_log_add("Gateways", '/var/log/gateways.log');
220
status_log_add("IPsec", '/var/log/ipsec.log');
221
status_log_add("L2TP", '/var/log/l2tps.log');
222
status_log_add("NTP", '/var/log/ntpd.log');
223
status_log_add("OpenVPN", '/var/log/openvpn.log');
224
status_log_add("Captive Portal Authentication", '/var/log/portalauth.log');
225
status_log_add("PPP", '/var/log/ppp.log');
226
status_log_add("PPPoE Server", '/var/log/poes.log');
227
status_log_add("DNS", '/var/log/resolver.log');
228
status_log_add("Routing", '/var/log/routing.log');
229
status_log_add("Wireless", '/var/log/wireless.log');
230
status_log_add("PHP Errors", '/tmp/PHP_errors.log', 'all');
231

    
232
status_cmd_define("OS-Message Buffer", "/sbin/dmesg -a");
233
status_cmd_define("OS-Message Buffer (Boot)", "/bin/cat /var/log/dmesg.boot");
234

    
235
/* OS/Hardware Status */
236
status_cmd_define("OS-sysctl values", "/sbin/sysctl -aq");
237
status_cmd_define("OS-Kernel Environment", "/bin/kenv");
238
status_cmd_define("OS-Kernel Memory Usage", "/usr/local/sbin/kmemusage.sh");
239
status_cmd_define("OS-Installed Packages", "/usr/local/sbin/pkg-static info");
240
status_cmd_define("OS-Package Manager Configuration", "/usr/local/sbin/pkg-static -vv");
241
status_cmd_define("Hardware-PCI Devices", "/usr/sbin/pciconf -lvb");
242
status_cmd_define("Hardware-USB Devices", "/usr/sbin/usbconfig dump_device_desc");
243

    
244
status_cmd_define("Disk-Filesystem Table", "/bin/cat /etc/fstab");
245
status_cmd_define("Disk-Swap Information", "/usr/sbin/swapinfo");
246

    
247
if (is_module_loaded("zfs.ko")) {
248
	status_cmd_define("Disk-ZFS List", "/sbin/zfs list");
249
	status_cmd_define("Disk-ZFS Properties", "/sbin/zfs get all");
250
	status_cmd_define("Disk-ZFS Pool List", "/sbin/zpool list");
251
	status_cmd_define("Disk-ZFS Pool Status", "/sbin/zpool status");
252
}
253

    
254
status_cmd_define("Disk-GEOM Tree", "/sbin/geom -t");
255
status_cmd_define("Disk-GEOM Disk List", "/sbin/geom disk list -a");
256
status_cmd_define("Disk-GEOM Partition Summary", "/sbin/geom part show -p");
257
status_cmd_define("Disk-GEOM Partition Details", "/sbin/geom part list");
258
status_cmd_define("Disk-GEOM Label Status", "/sbin/geom label status");
259
status_cmd_define("Disk-GEOM Label Details", "/sbin/geom label list");
260
status_cmd_define("Disk-GEOM Mirror Status", "/sbin/gmirror status");
261

    
262
exec("/bin/date", $dateOutput, $dateStatus);
263
$currentDate = $dateOutput[0];
264

    
265
$pgtitle = array(g_get('product_label'), "Status");
266

    
267
if (!$console):
268
include("head.inc"); ?>
269

    
270
<form action="status.php" method="post">
271

    
272
<?php print_info_box(
273
	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.") .
274
	'<br />' .
275
	gettext("Common password and other private fields in config.xml have been automatically redacted.") .
276
	'<br />' .
277
	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) .
278
	' <button name="submit" type="submit" class="btn btn-primary btn-sm" id="download" value="DOWNLOAD">' .
279
	'<i class="fa fa-download icon-embed-btn"></i>' .
280
	gettext("Download") .
281
	'</button>'); ?>
282

    
283
</form>
284

    
285
<?php print_info_box(status_get_firewall_info(), 'info', false);
286

    
287
/* Call any registeredd package plugins which define status output to include
288
 * See https://redmine.pfsense.org/issues/14777 and
289
 *     https://redmine.pfsense.org/issues/1458
290
 */
291
$pluginparams = array();
292
$pluginparams['type'] = 'statusoutput';
293
pkg_call_plugins('plugin_statusoutput', $pluginparams);
294

    
295
if ($show_output) {
296
	status_cmd_list();
297
} else {
298
	print_info_box(gettext("Status output suppressed. Download archive to view."), 'info', false);
299
}
300

    
301
endif;
302

    
303
if ($console) {
304
	status_get_firewall_info();
305
}
306

    
307
status_cmd_run_all();
308

    
309
if (!empty($errors)) {
310
	$errorheader = gettext('Errors') . ": " . count($errors) . "\n";
311
	$errors[] = gettext("NOTE: Some errors are normal if a feature is not enabled or is inaccessible by the current user.\n");
312
	$errortext = $errorheader . implode('', $errors);
313
	file_put_contents("{$output_path}/_errors.txt", $errortext);
314
	if ($console) {
315
		echo $errortext;
316
	} else {
317
		print_info_box($errorheader . "<br/>" . implode('<br/>', $errors), 'warning', false);
318
	}
319
}
320

    
321
print(gettext("Saving output to archive..."));
322

    
323
if (is_dir($output_path)) {
324
	mwexec("/usr/bin/tar czpf " . escapeshellarg($output_file) . " -C " . escapeshellarg(dirname($output_path)) . " " . escapeshellarg(basename($output_path)));
325

    
326
	if (!isset($_GET["nocleanup"])) {
327
		unlink_if_exists("{$output_path}/*");
328
		@rmdir($output_path);
329
	}
330
}
331

    
332
print(gettext("Done.") . "\n");
333

    
334
if (!$console) {
335
	include("foot.inc");
336
}
(150-150/228)