Project

General

Profile

Download (5.36 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

    
14
/* include all configuration functions */
15
require_once("functions.inc");
16

    
17
function doCmdT($title, $command) {
18
    echo "<p>\n";
19
    echo "<a name=\"" . $title . "\">\n";
20
    echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
21
    echo "<tr><td class=\"listtopic\">" . $title . "</td></tr>\n";
22
    echo "<tr><td class=\"listlr\"><pre>";		/* no newline after pre */
23

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

    
51
/* Execute a command, giving it a title which is the same as the command. */
52
function doCmd($command) {
53
    doCmdT($command,$command);
54
}
55

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

    
63
/* Define a command, with a title which is the same as the command,
64
 * to be executed later.
65
 */
66
function defCmd($command) {
67
    defCmdT($command,$command);
68
}
69

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

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

    
89
global $g;
90

    
91
/* Set up all of the commands we want to execute. */
92
defCmdT("System uptime","uptime");
93
defCmdT("Interfaces","/sbin/ifconfig -a");
94

    
95
defCmdT("Routing tables","netstat -nr");
96

    
97
defCmdT("ipfw show", "/sbin/ipfw show");
98
defCmdT("pfctl -sn", "/sbin/pfctl -sn");
99
defCmdT("pfctl -sr", "/sbin/pfctl -sr");
100
defCmdT("pfctl -ss", "/sbin/pfctl -ss");
101
defCmdT("pfctl -si", "/sbin/pfctl -si");
102
defCmdT("pfctl -sa"," /sbin/pfctl -sa");
103
defCmdT("pfctl -s rules -v","/sbin/pfctl -s rules -v");
104
defCmdT("pfctl -s queue -v","/sbin/pfctl -s queue -v");
105
defCmdT("pfctl -vsq","/sbin/pfctl -vsq");
106

    
107
defCmdT("pftop -w 150 -a -b","/usr/local/sbin/pftop -a -b");
108
defCmdT("pftop -w 150 -a -b -v long","/usr/local/sbin/pftop -w 150 -a -b -v long");
109
defCmdT("pftop -w 150 -a -b -v queue","/usr/local/sbin/pftop -w 150 -a -b -v queue");
110
defCmdT("pftop -w 150 -a -b -v rules","/usr/local/sbin/pftop -w 150 -a -b -v rules");
111
defCmdT("pftop -w 150 -a -b -v size","/usr/local/sbin/pftop -w 150 -a -b -v size");
112
defCmdT("pftop -w 150 -a -b -v speed","/usr/local/sbin/pftop -w 150 -a -b -v speed");
113

    
114
defCmdT("resolv.conf","cat /etc/resolv.conf");
115

    
116
defCmdT("Processes","ps xauww");
117
defCmdT("dhcpd.conf","cat /var/etc/dhcpd.conf");
118
defCmdT("ez-ipupdate.cache","cat /conf/ez-ipupdate.cache");
119

    
120
defCmdT("df","/bin/df");
121

    
122
defCmdT("racoon.conf","cat /var/etc/racoon.conf");
123
defCmdT("SPD","/usr/sbin/setkey -DP");
124
defCmdT("SAD","/usr/sbin/setkey -D");
125

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

    
129
defCmd("ls /conf");
130
defCmd("ls /var/run");
131

    
132
defCmdT("cat {$g['tmp_path']}/rules.debug","cat {$g['tmp_path']}/rules.debug");
133

    
134
defCmdT("config.xml","dumpconfigxml");
135

    
136
$pageTitle = "pfSense: status";
137

    
138
exec("/bin/date", $dateOutput, $dateStatus);
139
$currentDate = $dateOutput[0];
140

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

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

    
168
<?php listCmds(); ?>
169

    
170
<?php execCmds(); ?>
171

    
172
</body>
173
</html>
(77-77/100)