Project

General

Profile

Download (15.8 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_once("guiconfig.inc");
36
require_once("notices.inc");
37

    
38
$swapinfo = `/usr/sbin/swapinfo`;
39
if(stristr($swapinfo,"%") == true) $showswap=true;
40

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

    
53
if(file_exists("/trigger_initial_wizard")) {
54
	conf_mount_rw();
55
	unlink("/trigger_initial_wizard");
56
	conf_mount_ro();
57

    
58
$pgtitle = "pfSense first time setup";
59
include("head.inc");
60

    
61
?>
62
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
63
<form>
64
<?php
65
	echo "<center>\n";
66
	echo "<img src=\"/themes/{$g['theme']}/images/logo.gif\" border=\"0\"><p>\n";
67
	echo "<div \" style=\"width:700px;background-color:#ffffff\" id=\"nifty\">\n";
68
	echo "Welcome to pfSense!<p>\n";
69
	echo "One moment while we start the initial setup wizard.<p>\n";
70
	echo "Embedded platform users: Please be patient, the wizard takes a little longer to run than the normal gui.<p>\n";
71
	echo "To bypass the wizard, click on the pfSense wizard on the initial page.\n";
72
	echo "</div>\n";
73
	echo "<meta http-equiv=\"refresh\" content=\"1;url=wizard.php?xml=setup_wizard.xml\">\n";
74
	echo "<script type=\"text/javascript\">\n";
75
	echo "NiftyCheck();\n";
76
	echo "Rounded(\"div#nifty\",\"all\",\"#000\",\"#FFFFFF\",\"smooth\");\n";
77
	echo "</script>\n";
78
	exit;
79
}
80

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

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

    
101
	if ($uptime > 60)
102
		$uptime += 30;
103
	$updays = (int)($uptime / 86400);
104
	$uptime %= 86400;
105
	$uphours = (int)($uptime / 3600);
106
	$uptime %= 3600;
107
	$upmins = (int)($uptime / 60);
108

    
109
	$uptimestr = "";
110
	if ($updays > 1)
111
		$uptimestr .= "$updays days, ";
112
	else if ($updays > 0)
113
		$uptimestr .= "1 day, ";
114
	$uptimestr .= sprintf("%02d:%02d", $uphours, $upmins);
115
	return $uptimestr;
116
}
117

    
118
function get_cputicks() {
119
	$cputicks = explode(" ", `/sbin/sysctl -n kern.cp_time`);
120
	return $cputicks;
121
}
122

    
123
function get_cpuusage($cpuTicks, $cpuTicks2) {
124

    
125
$diff = array();
126
$diff['user'] = ($cpuTicks2[0] - $cpuTicks[0])+1;
127
$diff['nice'] = ($cpuTicks2[1] - $cpuTicks[1])+1;
128
$diff['sys'] = ($cpuTicks2[2] - $cpuTicks[2])+1;
129
$diff['intr'] = ($cpuTicks2[3] - $cpuTicks[3])+1;
130
$diff['idle'] = ($cpuTicks2[4] - $cpuTicks[4])+1;
131

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

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

    
137
return $cpuUsage;
138
}
139

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

    
153
$pgtitle = "pfSense webGUI";
154
/* include header and other code */
155
include("head.inc");
156

    
157
?>
158

    
159
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
160
<form>
161
<?php
162

    
163
include("fbegin.inc");
164
	if(!file_exists("/usr/local/www/themes/{$g['theme']}/no_big_logo"))
165
		echo "<center><img src=\"./themes/".$g['theme']."/images/logobig.jpg\"></center><br>";
166
?>
167
<p class="pgtitle">System Overview</p>
168

    
169
	    <div id="niftyOutter" width="650">
170
            <table bgcolor="#990000" width="100%" border="0" cellspacing="0" cellpadding="0">
171
              <tr>
172
                <td colspan="2" class="listtopic">System information</td>
173
              </tr>
174
              <tr>
175
                <td width="25%" class="vncellt">Name</td>
176
                <td width="75%" class="listr">
177
                  <?php echo $config['system']['hostname'] . "." . $config['system']['domain']; ?>
178
                </td>
179
              </tr>
180
              <tr>
181
                <td width="25%" valign="top" class="vncellt">Version</td>
182
                <td width="75%" class="listr"> <strong>
183
                  <?php readfile("/etc/version"); ?>
184
                  </strong><br>
185
                  built on
186
                  <?php readfile("/etc/version.buildtime"); ?>
187
                </td>
188
              </tr>
189
              <tr>
190
                <td width="25%" class="vncellt">Platform</td>
191
                <td width="75%" class="listr">
192
                  <?=htmlspecialchars($g['platform']);?>
193
                </td>
194
              </tr><?php if ($hwcrypto): ?>
195
              <tr>
196
                <td width="25%" class="vncellt">Hardware crypto</td>
197
                <td width="75%" class="listr">
198
                  <?=htmlspecialchars($hwcrypto);?>
199
                </td>
200
              </tr><?php endif; ?>
201
              <tr>
202
                <td width="25%" class="vncellt">Uptime</td>
203
                <td width="75%" class="listr">
204
                  <?php
205
                    echo "<input style='border: 0px solid white;' size='30' name='uptime' id='uptime' value='"  .htmlspecialchars(get_uptime()) . "'>";
206
				  ?>
207
                </td>
208
              </tr><?php if ($config['lastchange']): ?>
209
              <tr>
210
                <td width="25%" class="vncellt">Last config change</td>
211
                <td width="75%" class="listr">
212
                  <?=htmlspecialchars(date("D M j G:i:s T Y", $config['revision']['time']));?>
213
                </td>
214
              </tr><?php endif; ?>
215
              <tr>
216
                <td width="25%" class="vncellt">State table size</td>
217
                <td width="75%" class="listr">
218
                  <?php
219
                    echo "<input style='border: 0px solid white;' size='30' name='pfstate' id='pfstate' value='"  .htmlspecialchars(get_pfstate()) . "'>";
220
                  ?>
221
		    <br>
222
		    <a href="diag_dump_states.php">Show states</a>
223
                </td>
224
              </tr>
225
	      <tr>
226
                <td width="25%" class="vncellt">CPU usage</td>
227
                <td width="75%" class="listr">
228
<?php
229
if (preg_match("/MSIE/i", $_SERVER['HTTP_USER_AGENT'])) {
230
	$seconds = "30";
231
} else {
232
	$seconds = "3";
233
}
234

    
235
$cpuUsage = get_cpuusage(get_cputicks(), get_cputicks());
236

    
237
echo "<img src='./themes/".$g['theme']."/images/misc/bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
238
echo "<img src='./themes/".$g['theme']."/images/misc/bar_blue.gif' height='15' name='cpuwidtha' id='cpuwidtha' width='" . $cpuUsage . "' border='0' align='absmiddle'>";
239
echo "<img src='./themes/".$g['theme']."/images/misc/bar_gray.gif' height='15' name='cpuwidthb' id='cpuwidthb' width='" . (100 - $cpuUsage) . "' border='0' align='absmiddle'>";
240
echo "<img src='./themes/".$g['theme']."/images/misc/bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
241
echo "<input style='border: 0px solid white;' size='30' name='cpumeter' id='cpumeter' value='{$cpuUsage}% (Updating in $seconds seconds)'>";
242
//echo $cpuUsage . "%";
243
?>
244
                </td>
245
              </tr>
246
			  <tr>
247
                <td width="25%" class="vncellt">Memory usage</td>
248
                <td width="75%" class="listr">
249
<?php
250

    
251
exec("/sbin/sysctl -n vm.stats.vm.v_active_count vm.stats.vm.v_inactive_count " .
252
	"vm.stats.vm.v_wire_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count", $memory);
253

    
254
$totalMem = $memory[0] + $memory[1] + $memory[2] + $memory[3] + $memory[4];
255
$freeMem = $memory[4];
256
$usedMem = $totalMem - $freeMem;
257
$memUsage = round(($usedMem * 100) / $totalMem, 0);
258

    
259
echo " <img src='./themes/".$g['theme']."/images/misc/bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
260
echo "<img src='./themes/".$g['theme']."/images/misc/bar_blue.gif' height='15' name='memwidtha' id='memwidtha' width='" . $memUsage . "' border='0' align='absmiddle'>";
261
echo "<img src='./themes/".$g['theme']."/images/misc/bar_gray.gif' height='15' name='memwidthb' id='memwidthb' width='" . (100 - $memUsage) . "' border='0' align='absmiddle'>";
262
echo "<img src='./themes/".$g['theme']."/images/misc/bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
263
echo "<input style='border: 0px solid white;' size='30' name='memusagemeter' id='memusagemeter' value='{$memUsage}%'>";
264
//echo $memUsage . "%";
265
?>
266
                </td>
267
              </tr>
268
	      
269
<?php if($showswap == true): ?>
270
			  <tr>
271
                <td width="25%" class="vncellt">SWAP usage</td>
272
                <td width="75%" class="listr">
273

    
274
<?php
275

    
276
$swapUsage = `/usr/sbin/swapinfo | cut -c45-55 | grep "%"`;
277
$swapUsage = ereg_replace('%', "", $swapUsage);
278
$swapUsage = ereg_replace(' ', "", $swapUsage);
279
$swapUsage = rtrim($swapUsage);
280

    
281
echo "<img src='./themes/".$g['theme']."/images/misc/bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
282
echo "<img src='./themes/".$g['theme']."/images/misc/bar_blue.gif' height='15' width='" . $swapUsage . "' border='0' align='absmiddle'>";
283
echo "<img src='./themes/".$g['theme']."/images/misc/bar_gray.gif' height='15' width='" . (100 - $swapUsage) . "' border='0' align='absmiddle'>";
284
echo "<img src='./themes/".$g['theme']."/images/misc/bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
285
echo "<input style='border: 0px solid white;' size='30' name='swapusagemeter' id='swapusagemeter' value='{$swapUsage}%'>";
286
//echo $swapUsage . "%";
287

    
288
?>
289
                </td>
290
              </tr>
291
<?php endif; ?>
292

    
293
<?php
294
	/* XXX - Stub in the HW monitor for net4801 - needs to use platform var's once we start using them */
295
	$is4801 = `/sbin/dmesg -a | grep NET4801`;
296
	if($is4801 <> "") {
297
echo "			  <tr>";
298
echo "                <td width='25%' class='vncellt'>Temperature </td>";
299
echo "                <td width='75%' class='listr'>";
300
// Initialize hw monitor
301
exec("/usr/local/sbin/env4801 -i");
302
$Temp = rtrim(`/usr/local/sbin/env4801 | grep Temp |cut -c24-25`);
303
echo "<img src='./themes/".$g['theme']."/images/misc/bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
304
echo "<img src='./themes/".$g['theme']."/images/misc/bar_blue.gif' height='15' name='Tempwidtha' id='tempwidtha' width='" . $Temp . "' border='0' align='absmiddle'>";
305
echo "<img src='./themes/".$g['theme']."/images/misc/bar_gray.gif' height='15' name='Tempwidthb' id='tempwidthb' width='" . (100 - $Temp) . "' border='0' align='absmiddle'>";
306
echo "<img src='./themes/".$g['theme']."/images/misc/bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
307
echo "<input style='border: 0px solid white;' size='30' name='Tempmeter' id='Tempmeter' value='{$Temp}C'>";
308
echo "                </td>";
309
echo "              </tr>";
310
	}
311
?>
312
	<tr>
313
		<td width="25%" class="vncellt">Disk usage</td>
314
			<td width="75%" class="listr">
315
<?php
316
exec("df -h | grep -w '/' | awk '{ print $5 }' | cut -d '%' -f 1", $dfout);
317
$diskusage = trim($dfout[0]);
318

    
319
echo "<img src='./themes/".$g['theme']."/images/misc/bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
320
echo "<img src='./themes/".$g['theme']."/images/misc/bar_blue.gif' height='15' width='" . $diskusage . "' border='0' align='absmiddle'>";
321
echo "<img src='./themes/".$g['theme']."/images/misc/bar_gray.gif' height='15' width='" . (100 - $diskusage) . "' border='0' align='absmiddle'>";
322
echo "<img src='./themes/".$g['theme']."/images/misc/bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
323
echo $diskusage . "%";
324
?>
325
			</td>
326
	</tr>
327

    
328

    
329
            </table>
330
	    </div>
331
            <?php include("fend.inc"); ?>
332
	    
333
<script type="text/javascript">
334
NiftyCheck();
335
Rounded("div#nifty","top","#FFF","#EEEEEE","smooth");
336
</script>
337
</form>
338

    
339
</body>
340
</html>
341
<?php
342
if (preg_match("/MSIE/i", $_SERVER['HTTP_USER_AGENT'])) {
343
	echo "<meta http-equiv=\"refresh\" content=\"30;url=index.php\">";
344
	exit;
345
}
346

    
347
$counter = 0;
348

    
349
While(!Connection_Aborted()) {
350

    
351
    /* Update CPU meter */
352
    sleep(1);
353
    $cpuTicks = get_cputicks();
354
    sleep(2);
355
    $cpuTicks2 = get_cputicks();
356
    $cpuUsage = get_cpuusage($cpuTicks, $cpuTicks2);
357

    
358
    /* Update memory usage */
359
    exec("/sbin/sysctl -n vm.stats.vm.v_active_count vm.stats.vm.v_inactive_count " .
360
        "vm.stats.vm.v_wire_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count", $memory);
361

    
362
    $totalMem = $memory[0] + $memory[1] + $memory[2] + $memory[3] + $memory[4];
363
    $freeMem = $memory[4];
364
    $usedMem = $totalMem - $freeMem;
365
    $memUsage = round(($usedMem * 100) / $totalMem, 0);
366

    
367
    echo "<script language='javascript'>\n";
368
    echo "document.forms[0].uptime.value = '" . get_uptime() . "';\n";
369
    echo "document.forms[0].pfstate.value = '" . get_pfstate() . "';\n";
370

    
371
    echo "document.cpuwidtha.style.width='" . $cpuUsage . "px';\n";
372
    echo "document.cpuwidthb.style.width='" . (100 - $cpuUsage) . "px';\n";
373
    echo "document.forms[0].cpumeter.value = '" . $cpuUsage . "%';\n";
374

    
375
    echo "document.memwidtha.style.width='" . $memUsage . "px';\n";
376
    echo "document.memwidthb.style.width='" . (100 - $memUsage) . "px';\n";
377
    echo "document.forms[0].memusagemeter.value = '" . $memUsage . "%';\n";
378

    
379
    if (file_exists("/etc/48xx")) {
380
      /* Update temp. meter */
381
      $Temp = rtrim(`/usr/local/sbin/env4801 | grep Temp |cut -c24-25`);
382
      echo "document.Tempwidtha.style.width='" . $Temp . "px';\n";
383
      echo "document.Tempwidthb.style.width='" . (100 - $Temp) . "px';\n";
384
      echo "document.forms[0].Tempmeter.value = '" . $Temp . "C';\n";
385
    }
386

    
387
/*
388
    exec("df -h | grep -w '/' | awk '{ print $5 }' | cut -d '%' -f 1", $dfout);
389
    $diskusage = trim($dfout[0]);
390

    
391
    echo "document.Diskwidtha.style.width='" . $diskusage . "px';\n";
392
    echo "document.Diskwidthb.style.width='" . (100 - $diskusage) . "px';\n";
393
    echo "document.forms[0].Diskmeter.value = '" . $diskusage . "%';\n";
394
*/
395

    
396
    echo "</script>\n";
397

    
398
     if(are_notices_pending() == true and $found_notices == false) {
399
	/* found a notice, lets redirect so they can see the notice */
400
	$counter = 500;
401
     }
402
     
403
    /*
404
     *   prevent user from running out of ram.
405
     *   firefox and ie can be a bear on ram usage!
406
     */
407
    $counter++;
408
    if($counter > 120) {
409
	    echo "Redirecting to <a href=\"index.php\">Main Status</a>.<p>";
410
	    echo "<meta http-equiv=\"refresh\" content=\"1;url=index.php\">";
411
	    exit;
412
    }
413

    
414
}
415

    
416
?>
(56-56/144)