Project

General

Profile

Download (13.1 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 dbe7b505 Scott Ullrich
	echo "<a href=\"/\"><img src=\"/logo.gif\" border=\"0\"></a><p>";
54 b6d96a2f Scott Ullrich
	echo "Welcome to pfSense!<p>";
55
	echo "One moment while we start the initial setup wizard.<p>";
56
	echo "Embedded platform users: Please be patient, the wizard takes a little longer to run than the normal gui.<p>";
57
	echo "To bypass the wizard, click on the pfSense wizard on the initial page.";
58
	echo "<meta http-equiv=\"refresh\" content=\"1;url=wizard.php?xml=setup_wizard.xml\">";
59 02e1170d Scott Ullrich
	exit;
60 bf787c0a Scott Ullrich
}
61
62 5b237745 Scott Ullrich
/* find out whether there's hardware encryption (hifn) */
63
unset($hwcrypto);
64
$fd = @fopen("{$g['varlog_path']}/dmesg.boot", "r");
65
if ($fd) {
66
	while (!feof($fd)) {
67
		$dmesgl = fgets($fd);
68
		if (preg_match("/^hifn.: (.*?),/", $dmesgl, $matches)) {
69
			$hwcrypto = $matches[1];
70
			break;
71
		}
72
	}
73
	fclose($fd);
74
}
75
76 71bceee7 Bill Marquette
function get_uptime() {
77
	exec("/sbin/sysctl -n kern.boottime", $boottime);
78
	preg_match("/sec = (\d+)/", $boottime[0], $matches);
79
	$boottime = $matches[1];
80
	$uptime = time() - $boottime;
81
82
	if ($uptime > 60)
83
		$uptime += 30;
84
	$updays = (int)($uptime / 86400);
85
	$uptime %= 86400;
86
	$uphours = (int)($uptime / 3600);
87
	$uptime %= 3600;
88
	$upmins = (int)($uptime / 60);
89
90
	$uptimestr = "";
91
	if ($updays > 1)
92
		$uptimestr .= "$updays days, ";
93
	else if ($updays > 0)
94
		$uptimestr .= "1 day, ";
95
	$uptimestr .= sprintf("%02d:%02d", $uphours, $upmins);
96
	return $uptimestr;
97
}
98
99
function get_cputicks() {
100
	$cputicks = explode(" ", `/sbin/sysctl -n kern.cp_time`);
101
	return $cputicks;
102
}
103
104
function get_cpuusage($cpuTicks, $cpuTicks2) {
105
106
$diff = array();
107
$diff['user'] = ($cpuTicks2[0] - $cpuTicks[0])+1;
108
$diff['nice'] = ($cpuTicks2[1] - $cpuTicks[1])+1;
109
$diff['sys'] = ($cpuTicks2[2] - $cpuTicks[2])+1;
110
$diff['intr'] = ($cpuTicks2[3] - $cpuTicks[3])+1;
111
$diff['idle'] = ($cpuTicks2[4] - $cpuTicks[4])+1;
112
113
//echo "<!-- user: {$diff['user']}  nice {$diff['nice']}  sys {$diff['sys']}  intr {$diff['intr']}  idle {$diff['idle']} -->";
114
115
$totalDiff = $diff['user'] + $diff['nice'] + $diff['sys'] + $diff['intr'] + $diff['idle'];
116
$cpuUsage = round(100 * (1 - $diff['idle'] / $totalDiff), 0);
117
118
return $cpuUsage;
119
}
120
121 4f2c1590 Bill Marquette
function get_pfstate() {
122
        if (isset($config['system']['maximumstates']))
123
                $maxstates="/{$config['system']['maximumstates']}";
124
        else
125
                $maxstates="/10000";
126
        $curentries = `/sbin/pfctl -si |grep current`;
127
        if (preg_match("/([0-9]+)/", $curentries, $matches)) {
128
             $curentries = $matches[1];
129
        }
130
        return $curentries . $maxstates;
131
}
132
133 5b237745 Scott Ullrich
?>
134
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
135
<html>
136
<head>
137 c5a17c26 Scott Ullrich
<title><?=gentitle("pfSense webGUI");?></title>
138 5b237745 Scott Ullrich
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
139
<link href="gui.css" rel="stylesheet" type="text/css">
140
</head>
141
142 8dbbc3ed Scott Ullrich
<form>
143
144 5b237745 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
145
<?php include("fbegin.inc"); ?>
146
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
147 2cd6010c Scott Ullrich
              <tr align="center" valign="top">
148 5b237745 Scott Ullrich
                <td height="10" colspan="2">&nbsp;</td>
149
              </tr>
150 2cd6010c Scott Ullrich
              <tr align="center" valign="top">
151 44b9bb7a Scott Ullrich
                <td colspan="2"><img src="logobig.jpg"></td>
152 5b237745 Scott Ullrich
              </tr>
153 44b9bb7a Scott Ullrich
	      <tr><td>&nbsp;</td></tr>
154 2cd6010c Scott Ullrich
              <tr>
155 5b237745 Scott Ullrich
                <td colspan="2" class="listtopic">System information</td>
156
              </tr>
157 2cd6010c Scott Ullrich
              <tr>
158 5b237745 Scott Ullrich
                <td width="25%" class="vncellt">Name</td>
159
                <td width="75%" class="listr">
160
                  <?php echo $config['system']['hostname'] . "." . $config['system']['domain']; ?>
161
                </td>
162
              </tr>
163 2cd6010c Scott Ullrich
              <tr>
164 5b237745 Scott Ullrich
                <td width="25%" valign="top" class="vncellt">Version</td>
165 2cd6010c Scott Ullrich
                <td width="75%" class="listr"> <strong>
166 5b237745 Scott Ullrich
                  <?php readfile("/etc/version"); ?>
167
                  </strong><br>
168 2cd6010c Scott Ullrich
                  built on
169 5b237745 Scott Ullrich
                  <?php readfile("/etc/version.buildtime"); ?>
170
                </td>
171
              </tr>
172 2cd6010c Scott Ullrich
              <tr>
173 5b237745 Scott Ullrich
                <td width="25%" class="vncellt">Platform</td>
174 2cd6010c Scott Ullrich
                <td width="75%" class="listr">
175 5b237745 Scott Ullrich
                  <?=htmlspecialchars($g['platform']);?>
176
                </td>
177
              </tr><?php if ($hwcrypto): ?>
178 2cd6010c Scott Ullrich
              <tr>
179 5b237745 Scott Ullrich
                <td width="25%" class="vncellt">Hardware crypto</td>
180 2cd6010c Scott Ullrich
                <td width="75%" class="listr">
181 5b237745 Scott Ullrich
                  <?=htmlspecialchars($hwcrypto);?>
182
                </td>
183
              </tr><?php endif; ?>
184 2cd6010c Scott Ullrich
              <tr>
185 5b237745 Scott Ullrich
                <td width="25%" class="vncellt">Uptime</td>
186 2cd6010c Scott Ullrich
                <td width="75%" class="listr">
187 5b237745 Scott Ullrich
                  <?php
188 71bceee7 Bill Marquette
                    echo "<input style='border: 0px solid white;' size='30' name='uptime' id='uptime' value='"  .htmlspecialchars(get_uptime()) . "'>";
189 5b237745 Scott Ullrich
				  ?>
190
                </td>
191
              </tr><?php if ($config['lastchange']): ?>
192 2cd6010c Scott Ullrich
              <tr>
193 5b237745 Scott Ullrich
                <td width="25%" class="vncellt">Last config change</td>
194 2cd6010c Scott Ullrich
                <td width="75%" class="listr">
195 5b237745 Scott Ullrich
                  <?=htmlspecialchars(date("D M j G:i:s T Y", $config['lastchange']));?>
196
                </td>
197
              </tr><?php endif; ?>
198 4f2c1590 Bill Marquette
              <tr>
199
                <td width="25%" class="vncellt">State table size</td>
200
                <td width="75%" class="listr">
201
                  <?php
202
                    echo "<input style='border: 0px solid white;' size='30' name='pfstate' id='pfstate' value='"  .htmlspecialchars(get_pfstate()) . "'>";
203
                                  ?>
204
                </td>
205
              </tr>
206
	      <tr>
207 5b237745 Scott Ullrich
                <td width="25%" class="vncellt">CPU usage</td>
208
                <td width="75%" class="listr">
209
<?php
210 71bceee7 Bill Marquette
$cpuUsage = get_cpuusage(get_cputicks(), get_cputicks());
211 2cd6010c Scott Ullrich
212 5b237745 Scott Ullrich
echo "<img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
213 8dbbc3ed Scott Ullrich
echo "<img src='bar_blue.gif' height='15' name='cpuwidtha' id='cpuwidtha' width='" . $cpuUsage . "' border='0' align='absmiddle'>";
214
echo "<img src='bar_gray.gif' height='15' name='cpuwidthb' id='cpuwidthb' width='" . (100 - $cpuUsage) . "' border='0' align='absmiddle'>";
215 5b237745 Scott Ullrich
echo "<img src='bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
216 7b8d63bd Scott Ullrich
echo "<input style='border: 0px solid white;' size='30' name='cpumeter' id='cpumeter' value='{$cpuUsage}% (Updating in 3 seconds)'>";
217 8dbbc3ed Scott Ullrich
//echo $cpuUsage . "%";
218 5b237745 Scott Ullrich
?>
219
                </td>
220
              </tr>
221 2cd6010c Scott Ullrich
			  <tr>
222 5b237745 Scott Ullrich
                <td width="25%" class="vncellt">Memory usage</td>
223
                <td width="75%" class="listr">
224
<?php
225
226
exec("/sbin/sysctl -n vm.stats.vm.v_active_count vm.stats.vm.v_inactive_count " .
227
	"vm.stats.vm.v_wire_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count", $memory);
228
229
$totalMem = $memory[0] + $memory[1] + $memory[2] + $memory[3] + $memory[4];
230
$freeMem = $memory[4];
231
$usedMem = $totalMem - $freeMem;
232
$memUsage = round(($usedMem * 100) / $totalMem, 0);
233 2cd6010c Scott Ullrich
234 5b237745 Scott Ullrich
echo " <img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
235 71bceee7 Bill Marquette
echo "<img src='bar_blue.gif' height='15' name='memwidtha' id='memwidtha' width='" . $memUsage . "' border='0' align='absmiddle'>";
236
echo "<img src='bar_gray.gif' height='15' name='memwidthb' id='memwidthb' width='" . (100 - $memUsage) . "' border='0' align='absmiddle'>";
237 5b237745 Scott Ullrich
echo "<img src='bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
238 7b8d63bd Scott Ullrich
echo "<input style='border: 0px solid white;' size='30' name='memusagemeter' id='memusagemeter' value='{$memUsage}%'>";
239 8dbbc3ed Scott Ullrich
//echo $memUsage . "%";
240 5b237745 Scott Ullrich
?>
241
                </td>
242
              </tr>
243 a3ad4f8a Scott Ullrich
			  <tr>
244
                <td width="25%" class="vncellt">SWAP usage</td>
245
                <td width="75%" class="listr">
246
247
<?php
248
249
$swapUsage = `/usr/sbin/swapinfo | cut -c45-55 | grep "%"`;
250
$swapUsage = ereg_replace('%', "", $swapUsage);
251
$swapUsage = ereg_replace(' ', "", $swapUsage);
252 71bceee7 Bill Marquette
$swapUsage = rtrim($swapUsage);
253 a3ad4f8a Scott Ullrich
254
echo "<img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
255
echo "<img src='bar_blue.gif' height='15' width='" . $swapUsage . "' border='0' align='absmiddle'>";
256
echo "<img src='bar_gray.gif' height='15' width='" . (100 - $swapUsage) . "' border='0' align='absmiddle'>";
257
echo "<img src='bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
258 7b8d63bd Scott Ullrich
echo "<input style='border: 0px solid white;' size='30' name='swapusagemeter' id='swapusagemeter' value='{$swapUsage}%'>";
259 8dbbc3ed Scott Ullrich
//echo $swapUsage . "%";
260 a3ad4f8a Scott Ullrich
261
?>
262
                </td>
263
              </tr>
264 75616b00 Bill Marquette
<?php
265 71bceee7 Bill Marquette
	/* XXX - Stub in the HW monitor for net4801 - needs to use platform var's once we start using them */
266 75616b00 Bill Marquette
	if (file_exists("/etc/48xx")) {
267
echo "			  <tr>";
268 71bceee7 Bill Marquette
echo "                <td width='25%' class='vncellt'>Temperature </td>";
269 75616b00 Bill Marquette
echo "                <td width='75%' class='listr'>";
270
// Initialize hw monitor
271
exec("/usr/local/sbin/env4801 -i");
272 71bceee7 Bill Marquette
$Temp = rtrim(`/usr/local/sbin/env4801 | grep Temp |cut -c24-25`);
273 75616b00 Bill Marquette
echo "<img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
274 71bceee7 Bill Marquette
echo "<img src='bar_blue.gif' height='15' name='Tempwidtha' id='tempwidtha' width='" . $Temp . "' border='0' align='absmiddle'>";
275
echo "<img src='bar_gray.gif' height='15' name='Tempwidthb' id='tempwidthb' width='" . (100 - $Temp) . "' border='0' align='absmiddle'>";
276 75616b00 Bill Marquette
echo "<img src='bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
277
echo "<input style='border: 0px solid white;' size='30' name='Tempmeter' id='Tempmeter' value='{$Temp}C'>";
278
echo "                </td>";
279
echo "              </tr>";
280
	}
281
?>
282 a3ad4f8a Scott Ullrich
283
284 5b237745 Scott Ullrich
            </table>
285
            <?php include("fend.inc"); ?>
286
</body>
287
</html>
288 8dbbc3ed Scott Ullrich
<?php
289
290 df5eae58 Scott Ullrich
$counter = 0;
291
292 c410cf55 Scott Ullrich
While(!Connection_Aborted()) {
293
294 71bceee7 Bill Marquette
    /* Update CPU meter */
295 c410cf55 Scott Ullrich
    sleep(1);
296 71bceee7 Bill Marquette
    $cpuTicks = get_cputicks();
297 c410cf55 Scott Ullrich
    sleep(2);
298 71bceee7 Bill Marquette
    $cpuTicks2 = get_cputicks();
299
    $cpuUsage = get_cpuusage($cpuTicks, $cpuTicks2);
300 c410cf55 Scott Ullrich
301 71bceee7 Bill Marquette
    /* Update memory usage */
302
    exec("/sbin/sysctl -n vm.stats.vm.v_active_count vm.stats.vm.v_inactive_count " .
303
        "vm.stats.vm.v_wire_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count", $memory);
304
305
    $totalMem = $memory[0] + $memory[1] + $memory[2] + $memory[3] + $memory[4];
306
    $freeMem = $memory[4];
307
    $usedMem = $totalMem - $freeMem;
308
    $memUsage = round(($usedMem * 100) / $totalMem, 0);
309
310 aa1f4636 Scott Ullrich
    echo "<script language='javascript'>\n";
311
    echo "document.forms[0].uptime.value = '" . get_uptime() . "';\n";
312 4f2c1590 Bill Marquette
    echo "document.forms[0].pfstate.value = '" . get_pfstate() . "';\n";
313 b6d96a2f Scott Ullrich
314 aa1f4636 Scott Ullrich
    echo "document.cpuwidtha.style.width='" . $cpuUsage . "';\n";
315
    echo "document.cpuwidthb.style.width='" . (100 - $cpuUsage) . "';\n";
316
    echo "document.forms[0].cpumeter.value = '" . $cpuUsage . "%';\n";
317
318 71bceee7 Bill Marquette
    echo "document.memwidtha.style.width='" . $memUsage . "';\n";
319
    echo "document.memwidthb.style.width='" . (100 - $memUsage) . "';\n";
320 2e564f1a Bill Marquette
    echo "document.forms[0].memusagemeter.value = '" . $memUsage . "%';\n";
321 71bceee7 Bill Marquette
322 cc890351 Bill Marquette
    if (file_exists("/etc/48xx")) {
323
      /* Update temp. meter */
324
      $Temp = rtrim(`/usr/local/sbin/env4801 | grep Temp |cut -c24-25`);
325
      echo "document.Tempwidtha.style.width='" . $Temp . "';\n";
326
      echo "document.Tempwidthb.style.width='" . (100 - $Temp) . "';\n";
327
      echo "document.forms[0].Tempmeter.value = '" . $Temp . "C';\n";
328
    }
329
330 c410cf55 Scott Ullrich
    echo "</script>\n";
331 a3ad4f8a Scott Ullrich
332 df5eae58 Scott Ullrich
    /*
333
     *   prevent user from running out of ram.
334
     *   firefox and ie can be a bear on ram usage!
335
     */
336
    $counter++;
337
    if($counter > 120) {
338 a58f93ad Scott Ullrich
	    echo "Redirecting to <a href=\"index.php\">Main Status</a>.<p>";
339 df5eae58 Scott Ullrich
	    echo "<meta http-equiv=\"refresh\" content=\"1;url=index.php\">";
340
	    exit;
341
    }
342
343 c410cf55 Scott Ullrich
}
344 8dbbc3ed Scott Ullrich
345
?>