Project

General

Profile

Download (5.39 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php
2
<?php
3 b46bfcf5 Bill Marquette
/* $Id$ */
4 5b237745 Scott Ullrich
/* Run various commands and collect their output into HTML tables.
5
 * Jim McBeath <jimmc@macrovision.com> Nov 2003
6
 *
7
 * (modified for m0n0wall by Manuel Kasper <mk@neon1.net>)
8 878f7270 Scott Ullrich
 * (modified for pfSense by Scott Ullrich geekgod@pfsense.com)
9 5b237745 Scott Ullrich
 */
10
11
/* Execute a command, with a title, and generate an HTML table
12
 * showing the results.
13
 */
14 1d169baa Bill Marquette
15
/* include all configuration functions */
16 f977ac60 Bill Marquette
require_once("guiconfig.inc");
17 1d169baa Bill Marquette
require_once("functions.inc");
18
19 5b237745 Scott Ullrich
function doCmdT($title, $command) {
20
    echo "<p>\n";
21
    echo "<a name=\"" . $title . "\">\n";
22
    echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
23
    echo "<tr><td class=\"listtopic\">" . $title . "</td></tr>\n";
24
    echo "<tr><td class=\"listlr\"><pre>";		/* no newline after pre */
25 f997992b Scott Ullrich
26 5b237745 Scott Ullrich
	if ($command == "dumpconfigxml") {
27
		$fd = @fopen("/conf/config.xml", "r");
28
		if ($fd) {
29
			while (!feof($fd)) {
30
				$line = fgets($fd);
31 70069758 Bill Marquette
				/* remove sensitive contents */
32 5b237745 Scott Ullrich
				$line = preg_replace("/<password>.*?<\\/password>/", "<password>xxxxx</password>", $line);
33
				$line = preg_replace("/<pre-shared-key>.*?<\\/pre-shared-key>/", "<pre-shared-key>xxxxx</pre-shared-key>", $line);
34 70069758 Bill Marquette
				$line = preg_replace("/<rocommunity>.*?<\\/rocommunity>/", "<rocommunity>xxxxx</rocommunity>", $line);
35 5b237745 Scott Ullrich
				$line = str_replace("\t", "    ", $line);
36
				echo htmlspecialchars($line,ENT_NOQUOTES);
37
			}
38
		}
39
		fclose($fd);
40
	} else {
41
		exec ($command . " 2>&1", $execOutput, $execStatus);
42
		for ($i = 0; isset($execOutput[$i]); $i++) {
43
			if ($i > 0) {
44
				echo "\n";
45
			}
46
			echo htmlspecialchars($execOutput[$i],ENT_NOQUOTES);
47
		}
48
	}
49
    echo "</pre></tr>\n";
50
    echo "</table>\n";
51
}
52
53
/* Execute a command, giving it a title which is the same as the command. */
54
function doCmd($command) {
55
    doCmdT($command,$command);
56
}
57
58
/* Define a command, with a title, to be executed later. */
59
function defCmdT($title, $command) {
60
    global $commands;
61
    $title = htmlspecialchars($title,ENT_NOQUOTES);
62
    $commands[] = array($title, $command);
63
}
64
65
/* Define a command, with a title which is the same as the command,
66
 * to be executed later.
67
 */
68
function defCmd($command) {
69
    defCmdT($command,$command);
70
}
71
72
/* List all of the commands as an index. */
73
function listCmds() {
74
    global $commands;
75
    echo "<p>This status page includes the following information:\n";
76 0774ed52 Scott Ullrich
    echo "<ul width=\"700\">\n";
77 5b237745 Scott Ullrich
    for ($i = 0; isset($commands[$i]); $i++ ) {
78
        echo "<li><strong><a href=\"#" . $commands[$i][0] . "\">" . $commands[$i][0] . "</a></strong>\n";
79
    }
80
    echo "</ul>\n";
81
}
82
83
/* Execute all of the commands which were defined by a call to defCmd. */
84
function execCmds() {
85
    global $commands;
86
    for ($i = 0; isset($commands[$i]); $i++ ) {
87
        doCmdT($commands[$i][0], $commands[$i][1]);
88
    }
89
}
90
91 1d169baa Bill Marquette
global $g;
92
93 5b237745 Scott Ullrich
/* Set up all of the commands we want to execute. */
94
defCmdT("System uptime","uptime");
95
defCmdT("Interfaces","/sbin/ifconfig -a");
96
97
defCmdT("Routing tables","netstat -nr");
98
99
defCmdT("ipfw show", "/sbin/ipfw show");
100 fd69ff6e Scott Ullrich
defCmdT("pfctl -sn", "/sbin/pfctl -sn");
101
defCmdT("pfctl -sr", "/sbin/pfctl -sr");
102
defCmdT("pfctl -ss", "/sbin/pfctl -ss");
103
defCmdT("pfctl -si", "/sbin/pfctl -si");
104
defCmdT("pfctl -sa"," /sbin/pfctl -sa");
105 135c91d5 Scott Ullrich
defCmdT("pfctl -s rules -vv","/sbin/pfctl -s rules -vv");
106
defCmdT("pfctl -s queue -vv","/sbin/pfctl -s queue -vv");
107 a88fe761 Scott Ullrich
defCmdT("pfctl -vsq","/sbin/pfctl -vsq");
108
109 a4fb527f Scott Ullrich
defCmdT("Load Balancer","/sbin/pfctl -a slb -s nat");
110 557228e4 Scott Ullrich
111 b6f87f46 Scott Ullrich
defCmdT("pftop -w 150 -a -b","/usr/local/sbin/pftop -a -b");
112
defCmdT("pftop -w 150 -a -b -v long","/usr/local/sbin/pftop -w 150 -a -b -v long");
113
defCmdT("pftop -w 150 -a -b -v queue","/usr/local/sbin/pftop -w 150 -a -b -v queue");
114
defCmdT("pftop -w 150 -a -b -v rules","/usr/local/sbin/pftop -w 150 -a -b -v rules");
115
defCmdT("pftop -w 150 -a -b -v size","/usr/local/sbin/pftop -w 150 -a -b -v size");
116
defCmdT("pftop -w 150 -a -b -v speed","/usr/local/sbin/pftop -w 150 -a -b -v speed");
117 5b237745 Scott Ullrich
118
defCmdT("resolv.conf","cat /etc/resolv.conf");
119
120
defCmdT("Processes","ps xauww");
121
defCmdT("dhcpd.conf","cat /var/etc/dhcpd.conf");
122
defCmdT("ez-ipupdate.cache","cat /conf/ez-ipupdate.cache");
123
124
defCmdT("df","/bin/df");
125
126
defCmdT("racoon.conf","cat /var/etc/racoon.conf");
127
defCmdT("SPD","/usr/sbin/setkey -DP");
128
defCmdT("SAD","/usr/sbin/setkey -D");
129
130
defCmdT("last 200 system log entries","/usr/sbin/clog /var/log/system.log 2>&1 | tail -n 200");
131
defCmdT("last 50 filter log entries","/usr/sbin/clog /var/log/filter.log 2>&1 | tail -n 50");
132
133
defCmd("ls /conf");
134
defCmd("ls /var/run");
135 8002c538 Scott Ullrich
136 1d169baa Bill Marquette
defCmdT("cat {$g['tmp_path']}/rules.debug","cat {$g['tmp_path']}/rules.debug");
137 8002c538 Scott Ullrich
138 5b237745 Scott Ullrich
defCmdT("config.xml","dumpconfigxml");
139
140 89a9d56b Scott Ullrich
defCmdT("Interrupts", "vmstat -i");
141
142 5b237745 Scott Ullrich
exec("/bin/date", $dateOutput, $dateStatus);
143
$currentDate = $dateOutput[0];
144
145 74f446e8 Bill Marquette
$pgtitle = "pfSense: status";
146 4df96eff Scott Ullrich
include("head.inc");
147
148 5b237745 Scott Ullrich
?>
149
<style type="text/css">
150
<!--
151
pre {
152
   margin: 0px;
153
   font-family: courier new, courier;
154
   font-weight: normal;
155
   font-size: 9pt;
156
}
157
-->
158
</style>
159
160
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
161 7173af6e Scott Ullrich
<?php include("fbegin.inc"); ?>
162 74f446e8 Bill Marquette
<p><span class="pgtitle"><?=$pgtitle;?></span><br>
163 5b237745 Scott Ullrich
<strong><?=$currentDate;?></strong>
164 f997992b Scott Ullrich
<p><span class="red"><strong>Note: make sure to remove any sensitive information
165
(passwords, maybe also IP addresses) before posting
166 5b237745 Scott Ullrich
information from this page in public places (like mailing lists)!</strong></span><br>
167
Passwords in config.xml have been automatically removed.
168
169 0774ed52 Scott Ullrich
<div id="cmdspace" style="width:700px">
170 5b237745 Scott Ullrich
<?php listCmds(); ?>
171
172
<?php execCmds(); ?>
173 0774ed52 Scott Ullrich
</div>
174 5b237745 Scott Ullrich
175 7173af6e Scott Ullrich
<?php include("fend.inc"); ?>
176 5b237745 Scott Ullrich
</body>
177
</html>