Project

General

Profile

Download (13.4 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
$swapinfo = `/usr/sbin/swapinfo`;
38
if(stristr($swapinfo,"%") == true) $showswap=true;
39

    
40
if(file_exists("/usr/local/www/trigger_initial_wizard")) {
41
	conf_mount_rw();
42
	unlink("/usr/local/www/trigger_initial_wizard");
43
	conf_mount_ro();
44
?>
45
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
46
<html>
47
<head>
48
<title><?=gentitle("pfSense webGUI");?></title>
49
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
50
<link href="gui.css" rel="stylesheet" type="text/css">
51
</head>
52
<form>
53
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
54
<?php
55
	echo "<center>";
56
	echo "<a href=\"/\"><img src=\"/logo.gif\" border=\"0\"></a><p>";
57
	echo "Welcome to pfSense!<p>";
58
	echo "One moment while we start the initial setup wizard.<p>";
59
	echo "Embedded platform users: Please be patient, the wizard takes a little longer to run than the normal gui.<p>";
60
	echo "To bypass the wizard, click on the pfSense wizard on the initial page.";
61
	echo "<meta http-equiv=\"refresh\" content=\"1;url=wizard.php?xml=setup_wizard.xml\">";
62
	exit;
63
}
64

    
65
/* find out whether there's hardware encryption (hifn) */
66
unset($hwcrypto);
67
$fd = @fopen("{$g['varlog_path']}/dmesg.boot", "r");
68
if ($fd) {
69
	while (!feof($fd)) {
70
		$dmesgl = fgets($fd);
71
		if (preg_match("/^hifn.: (.*?),/", $dmesgl, $matches)) {
72
			$hwcrypto = $matches[1];
73
			break;
74
		}
75
	}
76
	fclose($fd);
77
}
78

    
79
function get_uptime() {
80
	exec("/sbin/sysctl -n kern.boottime", $boottime);
81
	preg_match("/sec = (\d+)/", $boottime[0], $matches);
82
	$boottime = $matches[1];
83
	$uptime = time() - $boottime;
84

    
85
	if ($uptime > 60)
86
		$uptime += 30;
87
	$updays = (int)($uptime / 86400);
88
	$uptime %= 86400;
89
	$uphours = (int)($uptime / 3600);
90
	$uptime %= 3600;
91
	$upmins = (int)($uptime / 60);
92

    
93
	$uptimestr = "";
94
	if ($updays > 1)
95
		$uptimestr .= "$updays days, ";
96
	else if ($updays > 0)
97
		$uptimestr .= "1 day, ";
98
	$uptimestr .= sprintf("%02d:%02d", $uphours, $upmins);
99
	return $uptimestr;
100
}
101

    
102
function get_cputicks() {
103
	$cputicks = explode(" ", `/sbin/sysctl -n kern.cp_time`);
104
	return $cputicks;
105
}
106

    
107
function get_cpuusage($cpuTicks, $cpuTicks2) {
108

    
109
$diff = array();
110
$diff['user'] = ($cpuTicks2[0] - $cpuTicks[0])+1;
111
$diff['nice'] = ($cpuTicks2[1] - $cpuTicks[1])+1;
112
$diff['sys'] = ($cpuTicks2[2] - $cpuTicks[2])+1;
113
$diff['intr'] = ($cpuTicks2[3] - $cpuTicks[3])+1;
114
$diff['idle'] = ($cpuTicks2[4] - $cpuTicks[4])+1;
115

    
116
//echo "<!-- user: {$diff['user']}  nice {$diff['nice']}  sys {$diff['sys']}  intr {$diff['intr']}  idle {$diff['idle']} -->";
117

    
118
$totalDiff = $diff['user'] + $diff['nice'] + $diff['sys'] + $diff['intr'] + $diff['idle'];
119
$cpuUsage = round(100 * (1 - $diff['idle'] / $totalDiff), 0);
120

    
121
return $cpuUsage;
122
}
123

    
124
function get_pfstate() {
125
	global $config, $g;
126
        if (isset($config['system']['maximumstates']) and $config['system']['maximumstates'] > 0)
127
                $maxstates="/{$config['system']['maximumstates']}";
128
        else
129
                $maxstates="/10000";
130
        $curentries = `/sbin/pfctl -si |grep current`;
131
        if (preg_match("/([0-9]+)/", $curentries, $matches)) {
132
             $curentries = $matches[1];
133
        }
134
        return $curentries . $maxstates;
135
}
136

    
137
?>
138
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
139
<html>
140
<head>
141
<title><?=gentitle("pfSense webGUI");?></title>
142
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
143
<link href="gui.css" rel="stylesheet" type="text/css">
144
</head>
145

    
146
<form>
147

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

    
216
echo "<img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
217
echo "<img src='bar_blue.gif' height='15' name='cpuwidtha' id='cpuwidtha' width='" . $cpuUsage . "' border='0' align='absmiddle'>";
218
echo "<img src='bar_gray.gif' height='15' name='cpuwidthb' id='cpuwidthb' width='" . (100 - $cpuUsage) . "' border='0' align='absmiddle'>";
219
echo "<img src='bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
220
echo "<input style='border: 0px solid white;' size='30' name='cpumeter' id='cpumeter' value='{$cpuUsage}% (Updating in 3 seconds)'>";
221
//echo $cpuUsage . "%";
222
?>
223
                </td>
224
              </tr>
225
			  <tr>
226
                <td width="25%" class="vncellt">Memory usage</td>
227
                <td width="75%" class="listr">
228
<?php
229

    
230
exec("/sbin/sysctl -n vm.stats.vm.v_active_count vm.stats.vm.v_inactive_count " .
231
	"vm.stats.vm.v_wire_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count", $memory);
232

    
233
$totalMem = $memory[0] + $memory[1] + $memory[2] + $memory[3] + $memory[4];
234
$freeMem = $memory[4];
235
$usedMem = $totalMem - $freeMem;
236
$memUsage = round(($usedMem * 100) / $totalMem, 0);
237

    
238
echo " <img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
239
echo "<img src='bar_blue.gif' height='15' name='memwidtha' id='memwidtha' width='" . $memUsage . "' border='0' align='absmiddle'>";
240
echo "<img src='bar_gray.gif' height='15' name='memwidthb' id='memwidthb' width='" . (100 - $memUsage) . "' border='0' align='absmiddle'>";
241
echo "<img src='bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
242
echo "<input style='border: 0px solid white;' size='30' name='memusagemeter' id='memusagemeter' value='{$memUsage}%'>";
243
//echo $memUsage . "%";
244
?>
245
                </td>
246
              </tr>
247
	      
248
<?php if($showswap == true): ?>
249
			  <tr>
250
                <td width="25%" class="vncellt">SWAP usage</td>
251
                <td width="75%" class="listr">
252

    
253
<?php
254

    
255
$swapUsage = `/usr/sbin/swapinfo | cut -c45-55 | grep "%"`;
256
$swapUsage = ereg_replace('%', "", $swapUsage);
257
$swapUsage = ereg_replace(' ', "", $swapUsage);
258
$swapUsage = rtrim($swapUsage);
259

    
260
echo "<img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
261
echo "<img src='bar_blue.gif' height='15' width='" . $swapUsage . "' border='0' align='absmiddle'>";
262
echo "<img src='bar_gray.gif' height='15' width='" . (100 - $swapUsage) . "' border='0' align='absmiddle'>";
263
echo "<img src='bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
264
echo "<input style='border: 0px solid white;' size='30' name='swapusagemeter' id='swapusagemeter' value='{$swapUsage}%'>";
265
//echo $swapUsage . "%";
266

    
267
?>
268
                </td>
269
              </tr>
270
<?php endif; ?>
271

    
272
<?php
273
	/* XXX - Stub in the HW monitor for net4801 - needs to use platform var's once we start using them */
274
	$is4801 = `/sbin/dmesg -a | grep NET4801`;
275
	if($is4801 <> "") {
276
echo "			  <tr>";
277
echo "                <td width='25%' class='vncellt'>Temperature </td>";
278
echo "                <td width='75%' class='listr'>";
279
// Initialize hw monitor
280
exec("/usr/local/sbin/env4801 -i");
281
$Temp = rtrim(`/usr/local/sbin/env4801 | grep Temp |cut -c24-25`);
282
echo "<img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
283
echo "<img src='bar_blue.gif' height='15' name='Tempwidtha' id='tempwidtha' width='" . $Temp . "' border='0' align='absmiddle'>";
284
echo "<img src='bar_gray.gif' height='15' name='Tempwidthb' id='tempwidthb' width='" . (100 - $Temp) . "' border='0' align='absmiddle'>";
285
echo "<img src='bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
286
echo "<input style='border: 0px solid white;' size='30' name='Tempmeter' id='Tempmeter' value='{$Temp}C'>";
287
echo "                </td>";
288
echo "              </tr>";
289
	}
290
?>
291

    
292

    
293
            </table>
294
            <?php include("fend.inc"); ?>
295
</body>
296
</html>
297
<?php
298

    
299
$counter = 0;
300

    
301
While(!Connection_Aborted()) {
302

    
303
    /* Update CPU meter */
304
    sleep(1);
305
    $cpuTicks = get_cputicks();
306
    sleep(2);
307
    $cpuTicks2 = get_cputicks();
308
    $cpuUsage = get_cpuusage($cpuTicks, $cpuTicks2);
309

    
310
    /* Update memory usage */
311
    exec("/sbin/sysctl -n vm.stats.vm.v_active_count vm.stats.vm.v_inactive_count " .
312
        "vm.stats.vm.v_wire_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count", $memory);
313

    
314
    $totalMem = $memory[0] + $memory[1] + $memory[2] + $memory[3] + $memory[4];
315
    $freeMem = $memory[4];
316
    $usedMem = $totalMem - $freeMem;
317
    $memUsage = round(($usedMem * 100) / $totalMem, 0);
318

    
319
    echo "<script language='javascript'>\n";
320
    echo "document.forms[0].uptime.value = '" . get_uptime() . "';\n";
321
    echo "document.forms[0].pfstate.value = '" . get_pfstate() . "';\n";
322

    
323
    echo "document.cpuwidtha.style.width='" . $cpuUsage . "';\n";
324
    echo "document.cpuwidthb.style.width='" . (100 - $cpuUsage) . "';\n";
325
    echo "document.forms[0].cpumeter.value = '" . $cpuUsage . "%';\n";
326

    
327
    echo "document.memwidtha.style.width='" . $memUsage . "';\n";
328
    echo "document.memwidthb.style.width='" . (100 - $memUsage) . "';\n";
329
    echo "document.forms[0].memusagemeter.value = '" . $memUsage . "%';\n";
330

    
331
    if (file_exists("/etc/48xx")) {
332
      /* Update temp. meter */
333
      $Temp = rtrim(`/usr/local/sbin/env4801 | grep Temp |cut -c24-25`);
334
      echo "document.Tempwidtha.style.width='" . $Temp . "';\n";
335
      echo "document.Tempwidthb.style.width='" . (100 - $Temp) . "';\n";
336
      echo "document.forms[0].Tempmeter.value = '" . $Temp . "C';\n";
337
    }
338

    
339
    echo "</script>\n";
340

    
341
    /*
342
     *   prevent user from running out of ram.
343
     *   firefox and ie can be a bear on ram usage!
344
     */
345
    $counter++;
346
    if($counter > 120) {
347
	    echo "Redirecting to <a href=\"index.php\">Main Status</a>.<p>";
348
	    echo "<meta http-equiv=\"refresh\" content=\"1;url=index.php\">";
349
	    exit;
350
    }
351

    
352
}
353

    
354
?>
355

    
(46-46/113)