Project

General

Profile

Download (4.5 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
defCmdT("pfctl -si","/sbin/pfctl -si");
96

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

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

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

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

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

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

    
116
$pageTitle = "pfSense: status";
117

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

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

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

    
148
<?php listCmds(); ?>
149

    
150
<?php execCmds(); ?>
151

    
152
</body>
153
</html>
(68-68/90)