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("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
if(file_exists("{$g["tmp_path"]}/filter_reloading")) 
62
	file_notice("Filter load in progress", "The filter rules are currently reloading.  An alert will be sent if there is an error.", "", "");
63

    
64
?>
65
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
66
<form>
67
<?php
68
	echo "<center>";
69
	echo "<a href=\"/\"><img src=\"/logo.gif\" border=\"0\"></a><p>";
70
	echo "Welcome to pfSense!<p>";
71
	echo "One moment while we start the initial setup wizard.<p>";
72
	echo "Embedded platform users: Please be patient, the wizard takes a little longer to run than the normal gui.<p>";
73
	echo "To bypass the wizard, click on the pfSense wizard on the initial page.";
74
	echo "<meta http-equiv=\"refresh\" content=\"1;url=wizard.php?xml=setup_wizard.xml\">";
75
	exit;
76
}
77

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

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

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

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

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

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

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

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

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

    
134
return $cpuUsage;
135
}
136

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

    
150
$pgtitle = "pfSense webGUI";
151
/* include header and other code */
152
include("head.inc");
153

    
154
?>
155

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

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

    
239
exec("/sbin/sysctl -n vm.stats.vm.v_active_count vm.stats.vm.v_inactive_count " .
240
	"vm.stats.vm.v_wire_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count", $memory);
241

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

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

    
262
<?php
263

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

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

    
276
?>
277
                </td>
278
              </tr>
279
<?php endif; ?>
280

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

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

    
316

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

    
327
</body>
328
</html>
329
<?php
330

    
331
$counter = 0;
332

    
333
While(!Connection_Aborted()) {
334

    
335
    /* Update CPU meter */
336
    sleep(1);
337
    $cpuTicks = get_cputicks();
338
    sleep(2);
339
    $cpuTicks2 = get_cputicks();
340
    $cpuUsage = get_cpuusage($cpuTicks, $cpuTicks2);
341

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

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

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

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

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

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

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

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

    
380
    echo "</script>\n";
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
?>
(50-50/128)