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
|
|
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
|
status_cmd_define("DHCP-IPv4 Configuration", '/usr/bin/sed "s/\([[:blank:]]secret \).*/\1<redacted>/" /var/dhcpd/etc/dhcpd.conf');
|
157
|
status_cmd_define("DHCP-IPv6-Configuration", '/usr/bin/sed "s/\([[:blank:]]secret \).*/\1<redacted>/" /var/dhcpd/etc/dhcpdv6.conf');
|
158
|
status_cmd_define("IPsec-strongSwan Configuration", '/usr/bin/sed "s/\([[:blank:]]secret = \).*/\1<redacted>/" /var/etc/ipsec/strongswan.conf');
|
159
|
status_cmd_define("IPsec-Configuration", '/usr/bin/sed -E "s/([[:blank:]]*(secret|pin) = ).*/\1<redacted>/" /var/etc/ipsec/swanctl.conf');
|
160
|
status_cmd_define("IPsec-Status-Statistics", "/usr/local/sbin/swanctl --stats --pretty");
|
161
|
status_cmd_define("IPsec-Status-Connections", "/usr/local/sbin/swanctl --list-conns");
|
162
|
status_cmd_define("IPsec-Status-Active SAs", "/usr/local/sbin/swanctl --list-sas");
|
163
|
status_cmd_define("IPsec-Status-Policies", "/usr/local/sbin/swanctl --list-pols");
|
164
|
status_cmd_define("IPsec-Status-Certificates", "/usr/local/sbin/swanctl --list-certs --utc");
|
165
|
status_cmd_define("IPsec-Status-Pools", "/usr/local/sbin/swanctl --list-pools --leases");
|
166
|
status_cmd_define("IPsec-SPD", "/sbin/setkey -DP");
|
167
|
status_cmd_define("IPsec-SAD", "/sbin/setkey -D");
|
168
|
if (file_exists("/cf/conf/upgrade_log.txt")) {
|
169
|
status_cmd_define("OS-Upgrade Log", "/bin/cat /cf/conf/upgrade_log.txt");
|
170
|
}
|
171
|
if (file_exists("/cf/conf/upgrade_log.latest.txt")) {
|
172
|
status_cmd_define("OS-Upgrade Log Latest", "/bin/cat /cf/conf/upgrade_log.latest.txt");
|
173
|
}
|
174
|
if (file_exists("/boot/loader.conf")) {
|
175
|
status_cmd_define("OS-Boot Loader Configuration", "/bin/cat /boot/loader.conf");
|
176
|
}
|
177
|
if (file_exists("/boot/loader.conf.local")) {
|
178
|
status_cmd_define("OS-Boot Loader Configuration (Local)", "/bin/cat /boot/loader.conf.local");
|
179
|
}
|
180
|
if (file_exists("/var/etc/filterdns.conf")) {
|
181
|
status_cmd_define("DNS-filterdns Daemon Configuration", "/bin/cat /var/etc/filterdns.conf");
|
182
|
}
|
183
|
|
184
|
if (is_dir("/var/etc/openvpn")) {
|
185
|
foreach(glob('/var/etc/openvpn/*/config.ovpn') as $file) {
|
186
|
$ovpnfile = explode('/', $file);
|
187
|
if (!count($ovpnfile) || (count($ovpnfile) < 6)) {
|
188
|
continue;
|
189
|
}
|
190
|
status_cmd_define("OpenVPN-Configuration {$ovpnfile[4]}", "/bin/cat " . escapeshellarg($file));
|
191
|
}
|
192
|
}
|
193
|
|
194
|
if (file_exists("/var/etc/l2tp-vpn/mpd.conf")) {
|
195
|
status_cmd_define("L2TP-Configuration", '/usr/bin/sed -E "s/([[:blank:]](secret|radius server .*) ).*/\1<redacted>/" /var/etc/l2tp-vpn/mpd.conf');
|
196
|
}
|
197
|
|
198
|
/* Config History */
|
199
|
$confvers = get_backups();
|
200
|
unset($confvers['versions']);
|
201
|
if (count($confvers) != 0) {
|
202
|
for ($c = count($confvers)-1; $c >= 0; $c--) {
|
203
|
$conf_history .= backup_info($confvers[$c], $c+1);
|
204
|
$conf_history .= "\n";
|
205
|
}
|
206
|
status_cmd_define("Config History", "echo " . escapeshellarg($conf_history));
|
207
|
}
|
208
|
|
209
|
status_log_add("System", '/var/log/system.log');
|
210
|
status_log_add("DHCP", '/var/log/dhcpd.log');
|
211
|
status_log_add("Filter", '/var/log/filter.log');
|
212
|
status_log_add("Gateways", '/var/log/gateways.log');
|
213
|
status_log_add("IPsec", '/var/log/ipsec.log');
|
214
|
status_log_add("L2TP", '/var/log/l2tps.log');
|
215
|
status_log_add("NTP", '/var/log/ntpd.log');
|
216
|
status_log_add("OpenVPN", '/var/log/openvpn.log');
|
217
|
status_log_add("Captive Portal Authentication", '/var/log/portalauth.log');
|
218
|
status_log_add("PPP", '/var/log/ppp.log');
|
219
|
status_log_add("PPPoE Server", '/var/log/poes.log');
|
220
|
status_log_add("DNS", '/var/log/resolver.log');
|
221
|
status_log_add("Routing", '/var/log/routing.log');
|
222
|
status_log_add("Wireless", '/var/log/wireless.log');
|
223
|
status_log_add("PHP Errors", '/tmp/PHP_errors.log', 'all');
|
224
|
|
225
|
status_cmd_define("OS-Message Buffer", "/sbin/dmesg -a");
|
226
|
status_cmd_define("OS-Message Buffer (Boot)", "/bin/cat /var/log/dmesg.boot");
|
227
|
|
228
|
/* OS/Hardware Status */
|
229
|
status_cmd_define("OS-sysctl values", "/sbin/sysctl -aq");
|
230
|
status_cmd_define("OS-Kernel Environment", "/bin/kenv");
|
231
|
status_cmd_define("OS-Kernel Memory Usage", "/usr/local/sbin/kmemusage.sh");
|
232
|
status_cmd_define("OS-Installed Packages", "/usr/local/sbin/pkg-static info");
|
233
|
status_cmd_define("OS-Package Manager Configuration", "/usr/local/sbin/pkg-static -vv");
|
234
|
status_cmd_define("Hardware-PCI Devices", "/usr/sbin/pciconf -lvb");
|
235
|
status_cmd_define("Hardware-USB Devices", "/usr/sbin/usbconfig dump_device_desc");
|
236
|
|
237
|
status_cmd_define("Disk-Filesystem Table", "/bin/cat /etc/fstab");
|
238
|
status_cmd_define("Disk-Swap Information", "/usr/sbin/swapinfo");
|
239
|
|
240
|
if (is_module_loaded("zfs.ko")) {
|
241
|
status_cmd_define("Disk-ZFS List", "/sbin/zfs list");
|
242
|
status_cmd_define("Disk-ZFS Properties", "/sbin/zfs get all");
|
243
|
status_cmd_define("Disk-ZFS Pool List", "/sbin/zpool list");
|
244
|
status_cmd_define("Disk-ZFS Pool Status", "/sbin/zpool status");
|
245
|
}
|
246
|
|
247
|
status_cmd_define("Disk-GEOM Tree", "/sbin/geom -t");
|
248
|
status_cmd_define("Disk-GEOM Disk List", "/sbin/geom disk list -a");
|
249
|
status_cmd_define("Disk-GEOM Partition Summary", "/sbin/geom part show -p");
|
250
|
status_cmd_define("Disk-GEOM Partition Details", "/sbin/geom part list");
|
251
|
status_cmd_define("Disk-GEOM Label Status", "/sbin/geom label status");
|
252
|
status_cmd_define("Disk-GEOM Label Details", "/sbin/geom label list");
|
253
|
status_cmd_define("Disk-GEOM Mirror Status", "/sbin/gmirror status");
|
254
|
|
255
|
exec("/bin/date", $dateOutput, $dateStatus);
|
256
|
$currentDate = $dateOutput[0];
|
257
|
|
258
|
$pgtitle = array(g_get('product_label'), "Status");
|
259
|
|
260
|
if (!$console):
|
261
|
include("head.inc"); ?>
|
262
|
|
263
|
<form action="status.php" method="post">
|
264
|
|
265
|
<?php print_info_box(
|
266
|
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.") .
|
267
|
'<br />' .
|
268
|
gettext("Common password and other private fields in config.xml have been automatically redacted.") .
|
269
|
'<br />' .
|
270
|
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) .
|
271
|
' <button name="submit" type="submit" class="btn btn-primary btn-sm" id="download" value="DOWNLOAD">' .
|
272
|
'<i class="fa-solid fa-download icon-embed-btn"></i>' .
|
273
|
gettext("Download") .
|
274
|
'</button>'); ?>
|
275
|
|
276
|
</form>
|
277
|
|
278
|
<?php print_info_box(status_get_firewall_info(), 'info', false);
|
279
|
|
280
|
/* Call any registeredd package plugins which define status output to include
|
281
|
* See https://redmine.pfsense.org/issues/14777 and
|
282
|
* https://redmine.pfsense.org/issues/1458
|
283
|
*/
|
284
|
$pluginparams = array();
|
285
|
$pluginparams['type'] = 'statusoutput';
|
286
|
pkg_call_plugins('plugin_statusoutput', $pluginparams);
|
287
|
|
288
|
if ($show_output) {
|
289
|
status_cmd_list();
|
290
|
} else {
|
291
|
print_info_box(gettext("Status output suppressed. Download archive to view."), 'info', false);
|
292
|
}
|
293
|
|
294
|
endif;
|
295
|
|
296
|
if ($console) {
|
297
|
status_get_firewall_info();
|
298
|
}
|
299
|
|
300
|
status_cmd_run_all();
|
301
|
|
302
|
if (!empty($errors)) {
|
303
|
$errorheader = gettext('Errors') . ": " . count($errors) . "\n";
|
304
|
$errors[] = gettext("NOTE: Some errors are normal if a feature is not enabled or is inaccessible by the current user.\n");
|
305
|
$errortext = $errorheader . implode('', $errors);
|
306
|
file_put_contents("{$output_path}/_errors.txt", $errortext);
|
307
|
if ($console) {
|
308
|
echo $errortext;
|
309
|
} else {
|
310
|
print_info_box($errorheader . "<br/>" . implode('<br/>', $errors), 'warning', false);
|
311
|
}
|
312
|
}
|
313
|
|
314
|
print(gettext("Saving output to archive..."));
|
315
|
|
316
|
if (is_dir($output_path)) {
|
317
|
mwexec("/usr/bin/tar czpf " . escapeshellarg($output_file) . " -C " . escapeshellarg(dirname($output_path)) . " " . escapeshellarg(basename($output_path)));
|
318
|
|
319
|
if (!isset($_GET["nocleanup"])) {
|
320
|
unlink_if_exists("{$output_path}/*");
|
321
|
@rmdir($output_path);
|
322
|
}
|
323
|
}
|
324
|
|
325
|
print(gettext("Done.") . "\n");
|
326
|
|
327
|
if (!$console) {
|
328
|
include("foot.inc");
|
329
|
}
|