Project

General

Profile

Download (4.46 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 password tag 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 = str_replace("\t", "    ", $line);
29
				echo htmlspecialchars($line,ENT_NOQUOTES);
30
			}
31
		}
32
		fclose($fd);
33
	} else {
34
		exec ($command . " 2>&1", $execOutput, $execStatus);
35
		for ($i = 0; isset($execOutput[$i]); $i++) {
36
			if ($i > 0) {
37
				echo "\n";
38
			}
39
			echo htmlspecialchars($execOutput[$i],ENT_NOQUOTES);
40
		}
41
	}
42
    echo "</pre></tr>\n";
43
    echo "</table>\n";
44
}
45

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

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

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

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

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

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

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

    
90
defCmdT("ipfw show", "/sbin/ipfw show");
91
defCmdT("pfctl -s nat ", "/sbin/pfctl -s nat");
92
defCmdT("pfctl -s rules", "/sbin/pfctl -s rules");
93
defCmdT("pfctl -s all"," /sbin/pfctl -s all");
94
defCmdT("pfctl -s rules -v"," /sbin/pfctl -s rules -v");
95

    
96
defCmdT("resolv.conf","cat /etc/resolv.conf");
97

    
98
defCmdT("Processes","ps xauww");
99
defCmdT("dhcpd.conf","cat /var/etc/dhcpd.conf");
100
defCmdT("ez-ipupdate.cache","cat /conf/ez-ipupdate.cache");
101

    
102
defCmdT("df","/bin/df");
103

    
104
defCmdT("racoon.conf","cat /var/etc/racoon.conf");
105
defCmdT("SPD","/usr/sbin/setkey -DP");
106
defCmdT("SAD","/usr/sbin/setkey -D");
107

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

    
111
defCmd("ls /conf");
112
defCmd("ls /var/run");
113
defCmdT("config.xml","dumpconfigxml");
114

    
115
$pageTitle = "pfSense: status";
116

    
117
exec("/bin/date", $dateOutput, $dateStatus);
118
$currentDate = $dateOutput[0];
119

    
120
?>
121
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
122
<html>
123
<head>
124
<title><?=$pageTitle;?></title>
125
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
126
<link href="gui.css" rel="stylesheet" type="text/css">
127
<style type="text/css">
128
<!--
129
pre {
130
   margin: 0px;
131
   font-family: courier new, courier;
132
   font-weight: normal;
133
   font-size: 9pt;
134
}
135
-->
136
</style>
137
</head>
138

    
139
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
140
<p><span class="pgtitle"><?=$pageTitle;?></span><br>
141
<strong><?=$currentDate;?></strong>
142
<p><span class="red"><strong>Note: make sure to remove any sensitive information
143
(passwords, maybe also IP addresses) before posting
144
information from this page in public places (like mailing lists)!</strong></span><br>
145
Passwords in config.xml have been automatically removed.
146

    
147
<?php listCmds(); ?>
148

    
149
<?php execCmds(); ?>
150

    
151
</body>
152
</html>
(66-66/86)