Project

General

Profile

Download (13.1 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/* $Id$ */
4
/*
5
    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
*/
34

    
35
require("guiconfig.inc");
36

    
37
if(file_exists("/usr/local/www/trigger_initial_wizard")) {
38
	conf_mount_rw();
39
	unlink("/usr/local/www/trigger_initial_wizard");
40
	conf_mount_ro();
41
?>
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
	echo "<center>";
53
	echo "<a href=\"/\"><img src=\"/logo.gif\" border=\"0\"></a><p>";
54
	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
	exit;
60
}
61

    
62
/* 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
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
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
?>
134
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
135
<html>
136
<head>
137
<title><?=gentitle("pfSense webGUI");?></title>
138
<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
<form>
143

    
144
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
145
<?php include("fbegin.inc"); ?>
146
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
147
              <tr align="center" valign="top">
148
                <td height="10" colspan="2">&nbsp;</td>
149
              </tr>
150
              <tr align="center" valign="top">
151
                <td colspan="2"><img src="logobig.jpg"></td>
152
              </tr>
153
	      <tr><td>&nbsp;</td></tr>
154
              <tr>
155
                <td colspan="2" class="listtopic">System information</td>
156
              </tr>
157
              <tr>
158
                <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
              <tr>
164
                <td width="25%" valign="top" class="vncellt">Version</td>
165
                <td width="75%" class="listr"> <strong>
166
                  <?php readfile("/etc/version"); ?>
167
                  </strong><br>
168
                  built on
169
                  <?php readfile("/etc/version.buildtime"); ?>
170
                </td>
171
              </tr>
172
              <tr>
173
                <td width="25%" class="vncellt">Platform</td>
174
                <td width="75%" class="listr">
175
                  <?=htmlspecialchars($g['platform']);?>
176
                </td>
177
              </tr><?php if ($hwcrypto): ?>
178
              <tr>
179
                <td width="25%" class="vncellt">Hardware crypto</td>
180
                <td width="75%" class="listr">
181
                  <?=htmlspecialchars($hwcrypto);?>
182
                </td>
183
              </tr><?php endif; ?>
184
              <tr>
185
                <td width="25%" class="vncellt">Uptime</td>
186
                <td width="75%" class="listr">
187
                  <?php
188
                    echo "<input style='border: 0px solid white;' size='30' name='uptime' id='uptime' value='"  .htmlspecialchars(get_uptime()) . "'>";
189
				  ?>
190
                </td>
191
              </tr><?php if ($config['lastchange']): ?>
192
              <tr>
193
                <td width="25%" class="vncellt">Last config change</td>
194
                <td width="75%" class="listr">
195
                  <?=htmlspecialchars(date("D M j G:i:s T Y", $config['lastchange']));?>
196
                </td>
197
              </tr><?php endif; ?>
198
              <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
                <td width="25%" class="vncellt">CPU usage</td>
208
                <td width="75%" class="listr">
209
<?php
210
$cpuUsage = get_cpuusage(get_cputicks(), get_cputicks());
211

    
212
echo "<img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
213
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
echo "<img src='bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
216
echo "<input style='border: 0px solid white;' size='30' name='cpumeter' id='cpumeter' value='{$cpuUsage}% (Updating in 3 seconds)'>";
217
//echo $cpuUsage . "%";
218
?>
219
                </td>
220
              </tr>
221
			  <tr>
222
                <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

    
234
echo " <img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
235
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
echo "<img src='bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
238
echo "<input style='border: 0px solid white;' size='30' name='memusagemeter' id='memusagemeter' value='{$memUsage}%'>";
239
//echo $memUsage . "%";
240
?>
241
                </td>
242
              </tr>
243
			  <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
$swapUsage = rtrim($swapUsage);
253

    
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
echo "<input style='border: 0px solid white;' size='30' name='swapusagemeter' id='swapusagemeter' value='{$swapUsage}%'>";
259
//echo $swapUsage . "%";
260

    
261
?>
262
                </td>
263
              </tr>
264
<?php
265
	/* XXX - Stub in the HW monitor for net4801 - needs to use platform var's once we start using them */
266
	if (file_exists("/etc/48xx")) {
267
echo "			  <tr>";
268
echo "                <td width='25%' class='vncellt'>Temperature </td>";
269
echo "                <td width='75%' class='listr'>";
270
// Initialize hw monitor
271
exec("/usr/local/sbin/env4801 -i");
272
$Temp = rtrim(`/usr/local/sbin/env4801 | grep Temp |cut -c24-25`);
273
echo "<img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
274
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
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

    
283

    
284
            </table>
285
            <?php include("fend.inc"); ?>
286
</body>
287
</html>
288
<?php
289

    
290
$counter = 0;
291

    
292
While(!Connection_Aborted()) {
293

    
294
    /* Update CPU meter */
295
    sleep(1);
296
    $cpuTicks = get_cputicks();
297
    sleep(2);
298
    $cpuTicks2 = get_cputicks();
299
    $cpuUsage = get_cpuusage($cpuTicks, $cpuTicks2);
300

    
301
    /* 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
    echo "<script language='javascript'>\n";
311
    echo "document.forms[0].uptime.value = '" . get_uptime() . "';\n";
312
    echo "document.forms[0].pfstate.value = '" . get_pfstate() . "';\n";
313

    
314
    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
    echo "document.memwidtha.style.width='" . $memUsage . "';\n";
319
    echo "document.memwidthb.style.width='" . (100 - $memUsage) . "';\n";
320
    echo "document.forms[0].memusagemeter.value = '" . $memUsage . "%';\n";
321

    
322
    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
    echo "</script>\n";
331

    
332
    /*
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
	    echo "Redirecting to <a href=\"index.php\">Main Status</a>.<p>";
339
	    echo "<meta http-equiv=\"refresh\" content=\"1;url=index.php\">";
340
	    exit;
341
    }
342

    
343
}
344

    
345
?>
346

    
(46-46/113)