Project

General

Profile

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

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

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

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

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

    
259
<?php
260

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

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

    
273
?>
274
                </td>
275
              </tr>
276
<?php endif; ?>
277

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

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

    
313

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

    
324
</body>
325
</html>
326
<?php
327

    
328
$counter = 0;
329

    
330
While(!Connection_Aborted()) {
331

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

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

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

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

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

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

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

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

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

    
377
    echo "</script>\n";
378

    
379
    /*
380
     *   prevent user from running out of ram.
381
     *   firefox and ie can be a bear on ram usage!
382
     */
383
    $counter++;
384
    if($counter > 120) {
385
	    echo "Redirecting to <a href=\"index.php\">Main Status</a>.<p>";
386
	    echo "<meta http-equiv=\"refresh\" content=\"1;url=index.php\">";
387
	    exit;
388
    }
389

    
390
}
391

    
392
?>
(50-50/128)