Project

General

Profile

Download (14.5 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
156

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

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

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

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

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

    
260
<?php
261

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

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

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

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

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

    
314

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

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

    
329
$counter = 0;
330

    
331
While(!Connection_Aborted()) {
332

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

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

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

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

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

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

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

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

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

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

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

    
396
}
397

    
398
?>
(55-55/133)