Project

General

Profile

Download (5.25 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/* Run various commands and collect their output into HTML tables.
4
 * Jim McBeath <jimmc@macrovision.com> Nov 2003
5
 *
6
 * (modified for m0n0wall by Manuel Kasper <mk@neon1.net>)
7
 * (modified for pfSense by Scott Ullrich geekgod@pfsense.com)
8
 */
9

    
10
/* Execute a command, with a title, and generate an HTML table
11
 * showing the results.
12
 */
13
function doCmdT($title, $command) {
14
    echo "<p>\n";
15
    echo "<a name=\"" . $title . "\">\n";
16
    echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
17
    echo "<tr><td class=\"listtopic\">" . $title . "</td></tr>\n";
18
    echo "<tr><td class=\"listlr\"><pre>";		/* no newline after pre */
19

    
20
	if ($command == "dumpconfigxml") {
21
		$fd = @fopen("/conf/config.xml", "r");
22
		if ($fd) {
23
			while (!feof($fd)) {
24
				$line = fgets($fd);
25
				/* remove sensitive contents */
26
				$line = preg_replace("/<password>.*?<\\/password>/", "<password>xxxxx</password>", $line);
27
				$line = preg_replace("/<pre-shared-key>.*?<\\/pre-shared-key>/", "<pre-shared-key>xxxxx</pre-shared-key>", $line);
28
				$line = preg_replace("/<rocommunity>.*?<\\/rocommunity>/", "<rocommunity>xxxxx</rocommunity>", $line);
29
				$line = str_replace("\t", "    ", $line);
30
				echo htmlspecialchars($line,ENT_NOQUOTES);
31
			}
32
		}
33
		fclose($fd);
34
	} else {
35
		exec ($command . " 2>&1", $execOutput, $execStatus);
36
		for ($i = 0; isset($execOutput[$i]); $i++) {
37
			if ($i > 0) {
38
				echo "\n";
39
			}
40
			echo htmlspecialchars($execOutput[$i],ENT_NOQUOTES);
41
		}
42
	}
43
    echo "</pre></tr>\n";
44
    echo "</table>\n";
45
}
46

    
47
/* Execute a command, giving it a title which is the same as the command. */
48
function doCmd($command) {
49
    doCmdT($command,$command);
50
}
51

    
52
/* Define a command, with a title, to be executed later. */
53
function defCmdT($title, $command) {
54
    global $commands;
55
    $title = htmlspecialchars($title,ENT_NOQUOTES);
56
    $commands[] = array($title, $command);
57
}
58

    
59
/* Define a command, with a title which is the same as the command,
60
 * to be executed later.
61
 */
62
function defCmd($command) {
63
    defCmdT($command,$command);
64
}
65

    
66
/* List all of the commands as an index. */
67
function listCmds() {
68
    global $commands;
69
    echo "<p>This status page includes the following information:\n";
70
    echo "<ul>\n";
71
    for ($i = 0; isset($commands[$i]); $i++ ) {
72
        echo "<li><strong><a href=\"#" . $commands[$i][0] . "\">" . $commands[$i][0] . "</a></strong>\n";
73
    }
74
    echo "</ul>\n";
75
}
76

    
77
/* Execute all of the commands which were defined by a call to defCmd. */
78
function execCmds() {
79
    global $commands;
80
    for ($i = 0; isset($commands[$i]); $i++ ) {
81
        doCmdT($commands[$i][0], $commands[$i][1]);
82
    }
83
}
84

    
85
/* Set up all of the commands we want to execute. */
86
defCmdT("System uptime","uptime");
87
defCmdT("Interfaces","/sbin/ifconfig -a");
88

    
89
defCmdT("Routing tables","netstat -nr");
90

    
91
defCmdT("ipfw show", "/sbin/ipfw show");
92
defCmdT("pfctl -sn", "/sbin/pfctl -sn");
93
defCmdT("pfctl -sr", "/sbin/pfctl -sr");
94
defCmdT("pfctl -ss", "/sbin/pfctl -ss");
95
defCmdT("pfctl -si", "/sbin/pfctl -si");
96
defCmdT("pfctl -sa"," /sbin/pfctl -sa");
97
defCmdT("pfctl -s rules -v","/sbin/pfctl -s rules -v");
98
defCmdT("pfctl -s queue -v","/sbin/pfctl -s queue -v");
99
defCmdT("pfctl -vsq","/sbin/pfctl -vsq");
100

    
101
defCmdT("pftop -w 150 -a -b","/usr/local/sbin/pftop -a -b");
102
defCmdT("pftop -w 150 -a -b -v long","/usr/local/sbin/pftop -w 150 -a -b -v long");
103
defCmdT("pftop -w 150 -a -b -v queue","/usr/local/sbin/pftop -w 150 -a -b -v queue");
104
defCmdT("pftop -w 150 -a -b -v rules","/usr/local/sbin/pftop -w 150 -a -b -v rules");
105
defCmdT("pftop -w 150 -a -b -v size","/usr/local/sbin/pftop -w 150 -a -b -v size");
106
defCmdT("pftop -w 150 -a -b -v speed","/usr/local/sbin/pftop -w 150 -a -b -v speed");
107

    
108
defCmdT("resolv.conf","cat /etc/resolv.conf");
109

    
110
defCmdT("Processes","ps xauww");
111
defCmdT("dhcpd.conf","cat /var/etc/dhcpd.conf");
112
defCmdT("ez-ipupdate.cache","cat /conf/ez-ipupdate.cache");
113

    
114
defCmdT("df","/bin/df");
115

    
116
defCmdT("racoon.conf","cat /var/etc/racoon.conf");
117
defCmdT("SPD","/usr/sbin/setkey -DP");
118
defCmdT("SAD","/usr/sbin/setkey -D");
119

    
120
defCmdT("last 200 system log entries","/usr/sbin/clog /var/log/system.log 2>&1 | tail -n 200");
121
defCmdT("last 50 filter log entries","/usr/sbin/clog /var/log/filter.log 2>&1 | tail -n 50");
122

    
123
defCmd("ls /conf");
124
defCmd("ls /var/run");
125

    
126
defCmdT("cat /tmp/rules.debug","cat /tmp/rules.debug");
127

    
128
defCmdT("config.xml","dumpconfigxml");
129

    
130
$pageTitle = "pfSense: status";
131

    
132
exec("/bin/date", $dateOutput, $dateStatus);
133
$currentDate = $dateOutput[0];
134

    
135
?>
136
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
137
<html>
138
<head>
139
<title><?=$pageTitle;?></title>
140
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
141
<link href="gui.css" rel="stylesheet" type="text/css">
142
<style type="text/css">
143
<!--
144
pre {
145
   margin: 0px;
146
   font-family: courier new, courier;
147
   font-weight: normal;
148
   font-size: 9pt;
149
}
150
-->
151
</style>
152
</head>
153

    
154
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
155
<p><span class="pgtitle"><?=$pageTitle;?></span><br>
156
<strong><?=$currentDate;?></strong>
157
<p><span class="red"><strong>Note: make sure to remove any sensitive information
158
(passwords, maybe also IP addresses) before posting
159
information from this page in public places (like mailing lists)!</strong></span><br>
160
Passwords in config.xml have been automatically removed.
161

    
162
<?php listCmds(); ?>
163

    
164
<?php execCmds(); ?>
165

    
166
</body>
167
</html>
(77-77/100)