Project

General

Profile

Download (5.37 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/* $Id$ */
4
/* 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
 * (modified for pfSense by Scott Ullrich geekgod@pfsense.com)
9
 */
10

    
11
/* Execute a command, with a title, and generate an HTML table
12
 * showing the results.
13
 */
14

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

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

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

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

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

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

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

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

    
90
global $g;
91

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

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

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

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

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

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

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

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

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

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

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

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

    
137
$pageTitle = "pfSense: status";
138

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

    
142
?>
143
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
144
<html>
145
<head>
146
<title><?=$pageTitle;?></title>
147
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
148
<link href="gui.css" rel="stylesheet" type="text/css">
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
</head>
160

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

    
169
<?php listCmds(); ?>
170

    
171
<?php execCmds(); ?>
172

    
173
</body>
174
</html>
(84-84/109)