Project

General

Profile

Download (12.2 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php
2 2cd6010c Scott Ullrich
<?php
3 b46bfcf5 Bill Marquette
/* $Id$ */
4 5b237745 Scott Ullrich
/*
5 b49448ac Scott Ullrich
    index.php
6
    Copyright (C) 2004, 2005 Scott Ullrich
7
    All rights reserved.
8
9
    Originally part of m0n0wall (http://m0n0.ch/wall)
10
    Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
    All rights reserved.
12
13
    Redistribution and use in source and binary forms, with or without
14
    modification, are permitted provided that the following conditions are met:
15
16
    1. Redistributions of source code must retain the above copyright notice,
17
       this list of conditions and the following disclaimer.
18
19
    2. Redistributions in binary form must reproduce the above copyright
20
       notice, this list of conditions and the following disclaimer in the
21
       documentation and/or other materials provided with the distribution.
22
23
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
    POSSIBILITY OF SUCH DAMAGE.
33 5b237745 Scott Ullrich
*/
34
35 f3e2c205 Scott Ullrich
require("guiconfig.inc");
36
37 bf787c0a Scott Ullrich
if(file_exists("/usr/local/www/trigger_initial_wizard")) {
38 02e1170d Scott Ullrich
	conf_mount_rw();
39 dc3c40b1 Bill Marquette
	unlink("/usr/local/www/trigger_initial_wizard");
40 02e1170d Scott Ullrich
	conf_mount_ro();
41 f28b8dd0 Scott Ullrich
?>
42
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
43
<html>
44
<head>
45
<title><?=gentitle("pfSense webGUI");?></title>
46
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
47
<link href="gui.css" rel="stylesheet" type="text/css">
48
</head>
49
<form>
50
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
51
<?php
52 b6d96a2f Scott Ullrich
	echo "<center>";
53
	echo "Welcome to pfSense!<p>";
54
	echo "One moment while we start the initial setup wizard.<p>";
55
	echo "Embedded platform users: Please be patient, the wizard takes a little longer to run than the normal gui.<p>";
56
	echo "To bypass the wizard, click on the pfSense wizard on the initial page.";
57
	echo "<meta http-equiv=\"refresh\" content=\"1;url=wizard.php?xml=setup_wizard.xml\">";
58 02e1170d Scott Ullrich
	exit;
59 bf787c0a Scott Ullrich
}
60
61 5b237745 Scott Ullrich
/* find out whether there's hardware encryption (hifn) */
62
unset($hwcrypto);
63
$fd = @fopen("{$g['varlog_path']}/dmesg.boot", "r");
64
if ($fd) {
65
	while (!feof($fd)) {
66
		$dmesgl = fgets($fd);
67
		if (preg_match("/^hifn.: (.*?),/", $dmesgl, $matches)) {
68
			$hwcrypto = $matches[1];
69
			break;
70
		}
71
	}
72
	fclose($fd);
73
}
74
75 71bceee7 Bill Marquette
function get_uptime() {
76
	exec("/sbin/sysctl -n kern.boottime", $boottime);
77
	preg_match("/sec = (\d+)/", $boottime[0], $matches);
78
	$boottime = $matches[1];
79
	$uptime = time() - $boottime;
80
81
	if ($uptime > 60)
82
		$uptime += 30;
83
	$updays = (int)($uptime / 86400);
84
	$uptime %= 86400;
85
	$uphours = (int)($uptime / 3600);
86
	$uptime %= 3600;
87
	$upmins = (int)($uptime / 60);
88
89
	$uptimestr = "";
90
	if ($updays > 1)
91
		$uptimestr .= "$updays days, ";
92
	else if ($updays > 0)
93
		$uptimestr .= "1 day, ";
94
	$uptimestr .= sprintf("%02d:%02d", $uphours, $upmins);
95
	return $uptimestr;
96
}
97
98
function get_cputicks() {
99
	$cputicks = explode(" ", `/sbin/sysctl -n kern.cp_time`);
100
	return $cputicks;
101
}
102
103
function get_cpuusage($cpuTicks, $cpuTicks2) {
104
105
$diff = array();
106
$diff['user'] = ($cpuTicks2[0] - $cpuTicks[0])+1;
107
$diff['nice'] = ($cpuTicks2[1] - $cpuTicks[1])+1;
108
$diff['sys'] = ($cpuTicks2[2] - $cpuTicks[2])+1;
109
$diff['intr'] = ($cpuTicks2[3] - $cpuTicks[3])+1;
110
$diff['idle'] = ($cpuTicks2[4] - $cpuTicks[4])+1;
111
112
//echo "<!-- user: {$diff['user']}  nice {$diff['nice']}  sys {$diff['sys']}  intr {$diff['intr']}  idle {$diff['idle']} -->";
113
114
$totalDiff = $diff['user'] + $diff['nice'] + $diff['sys'] + $diff['intr'] + $diff['idle'];
115
$cpuUsage = round(100 * (1 - $diff['idle'] / $totalDiff), 0);
116
117
return $cpuUsage;
118
}
119
120 5b237745 Scott Ullrich
?>
121
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
122
<html>
123
<head>
124 c5a17c26 Scott Ullrich
<title><?=gentitle("pfSense webGUI");?></title>
125 5b237745 Scott Ullrich
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
126
<link href="gui.css" rel="stylesheet" type="text/css">
127
</head>
128
129 8dbbc3ed Scott Ullrich
<form>
130
131 5b237745 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
132
<?php include("fbegin.inc"); ?>
133
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
134 2cd6010c Scott Ullrich
              <tr align="center" valign="top">
135 5b237745 Scott Ullrich
                <td height="10" colspan="2">&nbsp;</td>
136
              </tr>
137 2cd6010c Scott Ullrich
              <tr align="center" valign="top">
138 44b9bb7a Scott Ullrich
                <td colspan="2"><img src="logobig.jpg"></td>
139 5b237745 Scott Ullrich
              </tr>
140 44b9bb7a Scott Ullrich
	      <tr><td>&nbsp;</td></tr>
141 2cd6010c Scott Ullrich
              <tr>
142 5b237745 Scott Ullrich
                <td colspan="2" class="listtopic">System information</td>
143
              </tr>
144 2cd6010c Scott Ullrich
              <tr>
145 5b237745 Scott Ullrich
                <td width="25%" class="vncellt">Name</td>
146
                <td width="75%" class="listr">
147
                  <?php echo $config['system']['hostname'] . "." . $config['system']['domain']; ?>
148
                </td>
149
              </tr>
150 2cd6010c Scott Ullrich
              <tr>
151 5b237745 Scott Ullrich
                <td width="25%" valign="top" class="vncellt">Version</td>
152 2cd6010c Scott Ullrich
                <td width="75%" class="listr"> <strong>
153 5b237745 Scott Ullrich
                  <?php readfile("/etc/version"); ?>
154
                  </strong><br>
155 2cd6010c Scott Ullrich
                  built on
156 5b237745 Scott Ullrich
                  <?php readfile("/etc/version.buildtime"); ?>
157
                </td>
158
              </tr>
159 2cd6010c Scott Ullrich
              <tr>
160 5b237745 Scott Ullrich
                <td width="25%" class="vncellt">Platform</td>
161 2cd6010c Scott Ullrich
                <td width="75%" class="listr">
162 5b237745 Scott Ullrich
                  <?=htmlspecialchars($g['platform']);?>
163
                </td>
164
              </tr><?php if ($hwcrypto): ?>
165 2cd6010c Scott Ullrich
              <tr>
166 5b237745 Scott Ullrich
                <td width="25%" class="vncellt">Hardware crypto</td>
167 2cd6010c Scott Ullrich
                <td width="75%" class="listr">
168 5b237745 Scott Ullrich
                  <?=htmlspecialchars($hwcrypto);?>
169
                </td>
170
              </tr><?php endif; ?>
171 2cd6010c Scott Ullrich
              <tr>
172 5b237745 Scott Ullrich
                <td width="25%" class="vncellt">Uptime</td>
173 2cd6010c Scott Ullrich
                <td width="75%" class="listr">
174 5b237745 Scott Ullrich
                  <?php
175 71bceee7 Bill Marquette
                    echo "<input style='border: 0px solid white;' size='30' name='uptime' id='uptime' value='"  .htmlspecialchars(get_uptime()) . "'>";
176 5b237745 Scott Ullrich
				  ?>
177
                </td>
178
              </tr><?php if ($config['lastchange']): ?>
179 2cd6010c Scott Ullrich
              <tr>
180 5b237745 Scott Ullrich
                <td width="25%" class="vncellt">Last config change</td>
181 2cd6010c Scott Ullrich
                <td width="75%" class="listr">
182 5b237745 Scott Ullrich
                  <?=htmlspecialchars(date("D M j G:i:s T Y", $config['lastchange']));?>
183
                </td>
184
              </tr><?php endif; ?>
185 2cd6010c Scott Ullrich
			  <tr>
186 5b237745 Scott Ullrich
                <td width="25%" class="vncellt">CPU usage</td>
187
                <td width="75%" class="listr">
188
<?php
189 71bceee7 Bill Marquette
$cpuUsage = get_cpuusage(get_cputicks(), get_cputicks());
190 2cd6010c Scott Ullrich
191 5b237745 Scott Ullrich
echo "<img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
192 8dbbc3ed Scott Ullrich
echo "<img src='bar_blue.gif' height='15' name='cpuwidtha' id='cpuwidtha' width='" . $cpuUsage . "' border='0' align='absmiddle'>";
193
echo "<img src='bar_gray.gif' height='15' name='cpuwidthb' id='cpuwidthb' width='" . (100 - $cpuUsage) . "' border='0' align='absmiddle'>";
194 5b237745 Scott Ullrich
echo "<img src='bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
195 7b8d63bd Scott Ullrich
echo "<input style='border: 0px solid white;' size='30' name='cpumeter' id='cpumeter' value='{$cpuUsage}% (Updating in 3 seconds)'>";
196 8dbbc3ed Scott Ullrich
//echo $cpuUsage . "%";
197 5b237745 Scott Ullrich
?>
198
                </td>
199
              </tr>
200 2cd6010c Scott Ullrich
			  <tr>
201 5b237745 Scott Ullrich
                <td width="25%" class="vncellt">Memory usage</td>
202
                <td width="75%" class="listr">
203
<?php
204
205
exec("/sbin/sysctl -n vm.stats.vm.v_active_count vm.stats.vm.v_inactive_count " .
206
	"vm.stats.vm.v_wire_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count", $memory);
207
208
$totalMem = $memory[0] + $memory[1] + $memory[2] + $memory[3] + $memory[4];
209
$freeMem = $memory[4];
210
$usedMem = $totalMem - $freeMem;
211
$memUsage = round(($usedMem * 100) / $totalMem, 0);
212 2cd6010c Scott Ullrich
213 5b237745 Scott Ullrich
echo " <img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
214 71bceee7 Bill Marquette
echo "<img src='bar_blue.gif' height='15' name='memwidtha' id='memwidtha' width='" . $memUsage . "' border='0' align='absmiddle'>";
215
echo "<img src='bar_gray.gif' height='15' name='memwidthb' id='memwidthb' width='" . (100 - $memUsage) . "' border='0' align='absmiddle'>";
216 5b237745 Scott Ullrich
echo "<img src='bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
217 7b8d63bd Scott Ullrich
echo "<input style='border: 0px solid white;' size='30' name='memusagemeter' id='memusagemeter' value='{$memUsage}%'>";
218 8dbbc3ed Scott Ullrich
//echo $memUsage . "%";
219 5b237745 Scott Ullrich
?>
220
                </td>
221
              </tr>
222 a3ad4f8a Scott Ullrich
			  <tr>
223
                <td width="25%" class="vncellt">SWAP usage</td>
224
                <td width="75%" class="listr">
225
226
<?php
227
228
$swapUsage = `/usr/sbin/swapinfo | cut -c45-55 | grep "%"`;
229
$swapUsage = ereg_replace('%', "", $swapUsage);
230
$swapUsage = ereg_replace(' ', "", $swapUsage);
231 71bceee7 Bill Marquette
$swapUsage = rtrim($swapUsage);
232 a3ad4f8a Scott Ullrich
233
echo "<img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
234
echo "<img src='bar_blue.gif' height='15' width='" . $swapUsage . "' border='0' align='absmiddle'>";
235
echo "<img src='bar_gray.gif' height='15' width='" . (100 - $swapUsage) . "' border='0' align='absmiddle'>";
236
echo "<img src='bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
237 7b8d63bd Scott Ullrich
echo "<input style='border: 0px solid white;' size='30' name='swapusagemeter' id='swapusagemeter' value='{$swapUsage}%'>";
238 8dbbc3ed Scott Ullrich
//echo $swapUsage . "%";
239 a3ad4f8a Scott Ullrich
240
?>
241
                </td>
242
              </tr>
243 75616b00 Bill Marquette
<?php
244 71bceee7 Bill Marquette
	/* XXX - Stub in the HW monitor for net4801 - needs to use platform var's once we start using them */
245 75616b00 Bill Marquette
	if (file_exists("/etc/48xx")) {
246
echo "			  <tr>";
247 71bceee7 Bill Marquette
echo "                <td width='25%' class='vncellt'>Temperature </td>";
248 75616b00 Bill Marquette
echo "                <td width='75%' class='listr'>";
249
// Initialize hw monitor
250
exec("/usr/local/sbin/env4801 -i");
251 71bceee7 Bill Marquette
$Temp = rtrim(`/usr/local/sbin/env4801 | grep Temp |cut -c24-25`);
252 75616b00 Bill Marquette
echo "<img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
253 71bceee7 Bill Marquette
echo "<img src='bar_blue.gif' height='15' name='Tempwidtha' id='tempwidtha' width='" . $Temp . "' border='0' align='absmiddle'>";
254
echo "<img src='bar_gray.gif' height='15' name='Tempwidthb' id='tempwidthb' width='" . (100 - $Temp) . "' border='0' align='absmiddle'>";
255 75616b00 Bill Marquette
echo "<img src='bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
256
echo "<input style='border: 0px solid white;' size='30' name='Tempmeter' id='Tempmeter' value='{$Temp}C'>";
257
echo "                </td>";
258
echo "              </tr>";
259
	}
260
?>
261 a3ad4f8a Scott Ullrich
262
263 5b237745 Scott Ullrich
            </table>
264
            <?php include("fend.inc"); ?>
265
</body>
266
</html>
267 8dbbc3ed Scott Ullrich
<?php
268
269 df5eae58 Scott Ullrich
$counter = 0;
270
271 c410cf55 Scott Ullrich
While(!Connection_Aborted()) {
272
273 71bceee7 Bill Marquette
    /* Update CPU meter */
274 c410cf55 Scott Ullrich
    sleep(1);
275 71bceee7 Bill Marquette
    $cpuTicks = get_cputicks();
276 c410cf55 Scott Ullrich
    sleep(2);
277 71bceee7 Bill Marquette
    $cpuTicks2 = get_cputicks();
278
    $cpuUsage = get_cpuusage($cpuTicks, $cpuTicks2);
279 c410cf55 Scott Ullrich
280 71bceee7 Bill Marquette
    /* Update memory usage */
281
    exec("/sbin/sysctl -n vm.stats.vm.v_active_count vm.stats.vm.v_inactive_count " .
282
        "vm.stats.vm.v_wire_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count", $memory);
283
284
    $totalMem = $memory[0] + $memory[1] + $memory[2] + $memory[3] + $memory[4];
285
    $freeMem = $memory[4];
286
    $usedMem = $totalMem - $freeMem;
287
    $memUsage = round(($usedMem * 100) / $totalMem, 0);
288
289 aa1f4636 Scott Ullrich
    echo "<script language='javascript'>\n";
290
    echo "document.forms[0].uptime.value = '" . get_uptime() . "';\n";
291 b6d96a2f Scott Ullrich
292 aa1f4636 Scott Ullrich
    echo "document.cpuwidtha.style.width='" . $cpuUsage . "';\n";
293
    echo "document.cpuwidthb.style.width='" . (100 - $cpuUsage) . "';\n";
294
    echo "document.forms[0].cpumeter.value = '" . $cpuUsage . "%';\n";
295
296 71bceee7 Bill Marquette
    echo "document.memwidtha.style.width='" . $memUsage . "';\n";
297
    echo "document.memwidthb.style.width='" . (100 - $memUsage) . "';\n";
298 2e564f1a Bill Marquette
    echo "document.forms[0].memusagemeter.value = '" . $memUsage . "%';\n";
299 71bceee7 Bill Marquette
300 cc890351 Bill Marquette
    if (file_exists("/etc/48xx")) {
301
      /* Update temp. meter */
302
      $Temp = rtrim(`/usr/local/sbin/env4801 | grep Temp |cut -c24-25`);
303
      echo "document.Tempwidtha.style.width='" . $Temp . "';\n";
304
      echo "document.Tempwidthb.style.width='" . (100 - $Temp) . "';\n";
305
      echo "document.forms[0].Tempmeter.value = '" . $Temp . "C';\n";
306
    }
307
308 c410cf55 Scott Ullrich
    echo "</script>\n";
309 a3ad4f8a Scott Ullrich
310 df5eae58 Scott Ullrich
    /*
311
     *   prevent user from running out of ram.
312
     *   firefox and ie can be a bear on ram usage!
313
     */
314
    $counter++;
315
    if($counter > 120) {
316 a58f93ad Scott Ullrich
	    echo "Redirecting to <a href=\"index.php\">Main Status</a>.<p>";
317 df5eae58 Scott Ullrich
	    echo "<meta http-equiv=\"refresh\" content=\"1;url=index.php\">";
318
	    exit;
319
    }
320
321 c410cf55 Scott Ullrich
}
322 8dbbc3ed Scott Ullrich
323
?>