Project

General

Profile

Download (14.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_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>";
66
	echo "<a href=\"/\"><img src=\"/logo.gif\" border=\"0\"></a><p>";
67
	echo "Welcome to pfSense!<p>";
68
	echo "One moment while we start the initial setup wizard.<p>";
69
	echo "Embedded platform users: Please be patient, the wizard takes a little longer to run than the normal gui.<p>";
70
	echo "To bypass the wizard, click on the pfSense wizard on the initial page.";
71
	echo "<meta http-equiv=\"refresh\" content=\"1;url=wizard.php?xml=setup_wizard.xml\">";
72
	exit;
73
}
74

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

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

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

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

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

    
117
function get_cpuusage($cpuTicks, $cpuTicks2) {
118

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

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

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

    
131
return $cpuUsage;
132
}
133

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

    
147
$pgtitle = "pfSense webGUI";
148
/* include header and other code */
149
include("head.inc");
150

    
151
?>
152

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

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

    
234
exec("/sbin/sysctl -n vm.stats.vm.v_active_count vm.stats.vm.v_inactive_count " .
235
	"vm.stats.vm.v_wire_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count", $memory);
236

    
237
$totalMem = $memory[0] + $memory[1] + $memory[2] + $memory[3] + $memory[4];
238
$freeMem = $memory[4];
239
$usedMem = $totalMem - $freeMem;
240
$memUsage = round(($usedMem * 100) / $totalMem, 0);
241

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

    
257
<?php
258

    
259
$swapUsage = `/usr/sbin/swapinfo | cut -c45-55 | grep "%"`;
260
$swapUsage = ereg_replace('%', "", $swapUsage);
261
$swapUsage = ereg_replace(' ', "", $swapUsage);
262
$swapUsage = rtrim($swapUsage);
263

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

    
271
?>
272
                </td>
273
              </tr>
274
<?php endif; ?>
275

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

    
302
echo "<img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
303
echo "<img src='bar_blue.gif' height='15' width='" . $diskusage . "' border='0' align='absmiddle'>";
304
echo "<img src='bar_gray.gif' height='15' width='" . (100 - $diskusage) . "' border='0' align='absmiddle'>";
305
echo "<img src='bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
306
echo $diskusage . "%";
307
?>
308
			</td>
309
	</tr>
310

    
311

    
312
            </table>
313
	    </div>
314
            <?php include("fend.inc"); ?>
315
	    
316
<script type="text/javascript">
317
NiftyCheck();
318
Rounded("div#nifty","top","#FFF","#EEEEEE","smooth");
319
</script>
320
</form>
321

    
322
</body>
323
</html>
324
<?php
325

    
326
$counter = 0;
327

    
328
While(!Connection_Aborted()) {
329

    
330
    /* Update CPU meter */
331
    sleep(1);
332
    $cpuTicks = get_cputicks();
333
    sleep(2);
334
    $cpuTicks2 = get_cputicks();
335
    $cpuUsage = get_cpuusage($cpuTicks, $cpuTicks2);
336

    
337
    /* Update memory usage */
338
    exec("/sbin/sysctl -n vm.stats.vm.v_active_count vm.stats.vm.v_inactive_count " .
339
        "vm.stats.vm.v_wire_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count", $memory);
340

    
341
    $totalMem = $memory[0] + $memory[1] + $memory[2] + $memory[3] + $memory[4];
342
    $freeMem = $memory[4];
343
    $usedMem = $totalMem - $freeMem;
344
    $memUsage = round(($usedMem * 100) / $totalMem, 0);
345

    
346
    echo "<script language='javascript'>\n";
347
    echo "document.forms[0].uptime.value = '" . get_uptime() . "';\n";
348
    echo "document.forms[0].pfstate.value = '" . get_pfstate() . "';\n";
349

    
350
    echo "document.cpuwidtha.style.width='" . $cpuUsage . "';\n";
351
    echo "document.cpuwidthb.style.width='" . (100 - $cpuUsage) . "';\n";
352
    echo "document.forms[0].cpumeter.value = '" . $cpuUsage . "%';\n";
353

    
354
    echo "document.memwidtha.style.width='" . $memUsage . "';\n";
355
    echo "document.memwidthb.style.width='" . (100 - $memUsage) . "';\n";
356
    echo "document.forms[0].memusagemeter.value = '" . $memUsage . "%';\n";
357

    
358
    if (file_exists("/etc/48xx")) {
359
      /* Update temp. meter */
360
      $Temp = rtrim(`/usr/local/sbin/env4801 | grep Temp |cut -c24-25`);
361
      echo "document.Tempwidtha.style.width='" . $Temp . "';\n";
362
      echo "document.Tempwidthb.style.width='" . (100 - $Temp) . "';\n";
363
      echo "document.forms[0].Tempmeter.value = '" . $Temp . "C';\n";
364
    }
365

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

    
370
    echo "document.Diskwidtha.style.width='" . $diskusage . "';\n";
371
    echo "document.Diskwidthb.style.width='" . (100 - $diskusage) . "';\n";
372
    echo "document.forms[0].Diskmeter.value = '" . $diskusage . "%';\n";
373
*/
374

    
375
    echo "</script>\n";
376

    
377
     if(are_notices_pending() == true and $found_notices == false) {
378
	/* found a notice, lets redirect so they can see the notice */
379
	$counter = 500;
380
     }
381
     
382
    /*
383
     *   prevent user from running out of ram.
384
     *   firefox and ie can be a bear on ram usage!
385
     */
386
    $counter++;
387
    if($counter > 120) {
388
	    echo "Redirecting to <a href=\"index.php\">Main Status</a>.<p>";
389
	    echo "<meta http-equiv=\"refresh\" content=\"1;url=index.php\">";
390
	    exit;
391
    }
392

    
393
}
394

    
395
?>
(55-55/133)