Project

General

Profile

Download (13.6 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
/* User recently restored his config.
41
   If packages are installed lets resync
42
*/
43
if(file_exists("/needs_package_sync")) {
44
	if($config['installedpackages'] <> "") {
45
		conf_mount_rw();
46
		unlink("/needs_package_sync");
47
		header("Location: pkg_mgr_install.php?mode=reinstallall");
48
		exit;
49
	}
50
}
51

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

    
77
/* find out whether there's hardware encryption (hifn) */
78
unset($hwcrypto);
79
$fd = @fopen("{$g['varlog_path']}/dmesg.boot", "r");
80
if ($fd) {
81
	while (!feof($fd)) {
82
		$dmesgl = fgets($fd);
83
		if (preg_match("/^hifn.: (.*?),/", $dmesgl, $matches)) {
84
			$hwcrypto = $matches[1];
85
			break;
86
		}
87
	}
88
	fclose($fd);
89
}
90

    
91
function get_uptime() {
92
	exec("/sbin/sysctl -n kern.boottime", $boottime);
93
	preg_match("/sec = (\d+)/", $boottime[0], $matches);
94
	$boottime = $matches[1];
95
	$uptime = time() - $boottime;
96

    
97
	if ($uptime > 60)
98
		$uptime += 30;
99
	$updays = (int)($uptime / 86400);
100
	$uptime %= 86400;
101
	$uphours = (int)($uptime / 3600);
102
	$uptime %= 3600;
103
	$upmins = (int)($uptime / 60);
104

    
105
	$uptimestr = "";
106
	if ($updays > 1)
107
		$uptimestr .= "$updays days, ";
108
	else if ($updays > 0)
109
		$uptimestr .= "1 day, ";
110
	$uptimestr .= sprintf("%02d:%02d", $uphours, $upmins);
111
	return $uptimestr;
112
}
113

    
114
function get_cputicks() {
115
	$cputicks = explode(" ", `/sbin/sysctl -n kern.cp_time`);
116
	return $cputicks;
117
}
118

    
119
function get_cpuusage($cpuTicks, $cpuTicks2) {
120

    
121
$diff = array();
122
$diff['user'] = ($cpuTicks2[0] - $cpuTicks[0])+1;
123
$diff['nice'] = ($cpuTicks2[1] - $cpuTicks[1])+1;
124
$diff['sys'] = ($cpuTicks2[2] - $cpuTicks[2])+1;
125
$diff['intr'] = ($cpuTicks2[3] - $cpuTicks[3])+1;
126
$diff['idle'] = ($cpuTicks2[4] - $cpuTicks[4])+1;
127

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

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

    
133
return $cpuUsage;
134
}
135

    
136
function get_pfstate() {
137
	global $config, $g;
138
        if (isset($config['system']['maximumstates']) and $config['system']['maximumstates'] > 0)
139
                $maxstates="/{$config['system']['maximumstates']}";
140
        else
141
                $maxstates="/10000";
142
        $curentries = `/sbin/pfctl -si |grep current`;
143
        if (preg_match("/([0-9]+)/", $curentries, $matches)) {
144
             $curentries = $matches[1];
145
        }
146
        return $curentries . $maxstates;
147
}
148

    
149
?>
150
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
151
<html>
152
<head>
153
<title><?=gentitle("pfSense webGUI");?></title>
154
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
155
<link href="gui.css" rel="stylesheet" type="text/css">
156
</head>
157

    
158
<form>
159

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

    
228
echo "<img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
229
echo "<img src='bar_blue.gif' height='15' name='cpuwidtha' id='cpuwidtha' width='" . $cpuUsage . "' border='0' align='absmiddle'>";
230
echo "<img src='bar_gray.gif' height='15' name='cpuwidthb' id='cpuwidthb' width='" . (100 - $cpuUsage) . "' border='0' align='absmiddle'>";
231
echo "<img src='bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
232
echo "<input style='border: 0px solid white;' size='30' name='cpumeter' id='cpumeter' value='{$cpuUsage}% (Updating in 3 seconds)'>";
233
//echo $cpuUsage . "%";
234
?>
235
                </td>
236
              </tr>
237
			  <tr>
238
                <td width="25%" class="vncellt">Memory usage</td>
239
                <td width="75%" class="listr">
240
<?php
241

    
242
exec("/sbin/sysctl -n vm.stats.vm.v_active_count vm.stats.vm.v_inactive_count " .
243
	"vm.stats.vm.v_wire_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count", $memory);
244

    
245
$totalMem = $memory[0] + $memory[1] + $memory[2] + $memory[3] + $memory[4];
246
$freeMem = $memory[4];
247
$usedMem = $totalMem - $freeMem;
248
$memUsage = round(($usedMem * 100) / $totalMem, 0);
249

    
250
echo " <img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
251
echo "<img src='bar_blue.gif' height='15' name='memwidtha' id='memwidtha' width='" . $memUsage . "' border='0' align='absmiddle'>";
252
echo "<img src='bar_gray.gif' height='15' name='memwidthb' id='memwidthb' width='" . (100 - $memUsage) . "' border='0' align='absmiddle'>";
253
echo "<img src='bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
254
echo "<input style='border: 0px solid white;' size='30' name='memusagemeter' id='memusagemeter' value='{$memUsage}%'>";
255
//echo $memUsage . "%";
256
?>
257
                </td>
258
              </tr>
259
	      
260
<?php if($showswap == true): ?>
261
			  <tr>
262
                <td width="25%" class="vncellt">SWAP usage</td>
263
                <td width="75%" class="listr">
264

    
265
<?php
266

    
267
$swapUsage = `/usr/sbin/swapinfo | cut -c45-55 | grep "%"`;
268
$swapUsage = ereg_replace('%', "", $swapUsage);
269
$swapUsage = ereg_replace(' ', "", $swapUsage);
270
$swapUsage = rtrim($swapUsage);
271

    
272
echo "<img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
273
echo "<img src='bar_blue.gif' height='15' width='" . $swapUsage . "' border='0' align='absmiddle'>";
274
echo "<img src='bar_gray.gif' height='15' width='" . (100 - $swapUsage) . "' border='0' align='absmiddle'>";
275
echo "<img src='bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
276
echo "<input style='border: 0px solid white;' size='30' name='swapusagemeter' id='swapusagemeter' value='{$swapUsage}%'>";
277
//echo $swapUsage . "%";
278

    
279
?>
280
                </td>
281
              </tr>
282
<?php endif; ?>
283

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

    
304

    
305
            </table>
306
            <?php include("fend.inc"); ?>
307
</body>
308
</html>
309
<?php
310

    
311
$counter = 0;
312

    
313
While(!Connection_Aborted()) {
314

    
315
    /* Update CPU meter */
316
    sleep(1);
317
    $cpuTicks = get_cputicks();
318
    sleep(2);
319
    $cpuTicks2 = get_cputicks();
320
    $cpuUsage = get_cpuusage($cpuTicks, $cpuTicks2);
321

    
322
    /* Update memory usage */
323
    exec("/sbin/sysctl -n vm.stats.vm.v_active_count vm.stats.vm.v_inactive_count " .
324
        "vm.stats.vm.v_wire_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count", $memory);
325

    
326
    $totalMem = $memory[0] + $memory[1] + $memory[2] + $memory[3] + $memory[4];
327
    $freeMem = $memory[4];
328
    $usedMem = $totalMem - $freeMem;
329
    $memUsage = round(($usedMem * 100) / $totalMem, 0);
330

    
331
    echo "<script language='javascript'>\n";
332
    echo "document.forms[0].uptime.value = '" . get_uptime() . "';\n";
333
    echo "document.forms[0].pfstate.value = '" . get_pfstate() . "';\n";
334

    
335
    echo "document.cpuwidtha.style.width='" . $cpuUsage . "';\n";
336
    echo "document.cpuwidthb.style.width='" . (100 - $cpuUsage) . "';\n";
337
    echo "document.forms[0].cpumeter.value = '" . $cpuUsage . "%';\n";
338

    
339
    echo "document.memwidtha.style.width='" . $memUsage . "';\n";
340
    echo "document.memwidthb.style.width='" . (100 - $memUsage) . "';\n";
341
    echo "document.forms[0].memusagemeter.value = '" . $memUsage . "%';\n";
342

    
343
    if (file_exists("/etc/48xx")) {
344
      /* Update temp. meter */
345
      $Temp = rtrim(`/usr/local/sbin/env4801 | grep Temp |cut -c24-25`);
346
      echo "document.Tempwidtha.style.width='" . $Temp . "';\n";
347
      echo "document.Tempwidthb.style.width='" . (100 - $Temp) . "';\n";
348
      echo "document.forms[0].Tempmeter.value = '" . $Temp . "C';\n";
349
    }
350

    
351
    echo "</script>\n";
352

    
353
    /*
354
     *   prevent user from running out of ram.
355
     *   firefox and ie can be a bear on ram usage!
356
     */
357
    $counter++;
358
    if($counter > 120) {
359
	    echo "Redirecting to <a href=\"index.php\">Main Status</a>.<p>";
360
	    echo "<meta http-equiv=\"refresh\" content=\"1;url=index.php\">";
361
	    exit;
362
    }
363

    
364
}
365

    
366
?>
367

    
(48-48/117)