Project

General

Profile

Download (11.9 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

    
37
if(file_exists("/usr/local/www/trigger_initial_wizard")) {
38
	conf_mount_rw();
39
	unlink("/usr/local/www/trigger_initial_wizard");
40
	conf_mount_ro();
41
	echo "<center>";
42
	echo "Welcome to pfSense!<p>";
43
	echo "One moment while we start the initial setup wizard.<p>";
44
	echo "Embedded platform users: Please be patient, the wizard takes a little longer to run than the normal gui.<p>";
45
	echo "To bypass the wizard, click on the pfSense wizard on the initial page.";
46
	echo "<meta http-equiv=\"refresh\" content=\"1;url=wizard.php?xml=setup_wizard.xml\">";
47
	exit;
48
}
49

    
50
/* find out whether there's hardware encryption (hifn) */
51
unset($hwcrypto);
52
$fd = @fopen("{$g['varlog_path']}/dmesg.boot", "r");
53
if ($fd) {
54
	while (!feof($fd)) {
55
		$dmesgl = fgets($fd);
56
		if (preg_match("/^hifn.: (.*?),/", $dmesgl, $matches)) {
57
			$hwcrypto = $matches[1];
58
			break;
59
		}
60
	}
61
	fclose($fd);
62
}
63

    
64
function get_uptime() {
65
	exec("/sbin/sysctl -n kern.boottime", $boottime);
66
	preg_match("/sec = (\d+)/", $boottime[0], $matches);
67
	$boottime = $matches[1];
68
	$uptime = time() - $boottime;
69

    
70
	if ($uptime > 60)
71
		$uptime += 30;
72
	$updays = (int)($uptime / 86400);
73
	$uptime %= 86400;
74
	$uphours = (int)($uptime / 3600);
75
	$uptime %= 3600;
76
	$upmins = (int)($uptime / 60);
77

    
78
	$uptimestr = "";
79
	if ($updays > 1)
80
		$uptimestr .= "$updays days, ";
81
	else if ($updays > 0)
82
		$uptimestr .= "1 day, ";
83
	$uptimestr .= sprintf("%02d:%02d", $uphours, $upmins);
84
	return $uptimestr;
85
}
86

    
87
function get_cputicks() {
88
	$cputicks = explode(" ", `/sbin/sysctl -n kern.cp_time`);
89
	return $cputicks;
90
}
91

    
92
function get_cpuusage($cpuTicks, $cpuTicks2) {
93

    
94
$diff = array();
95
$diff['user'] = ($cpuTicks2[0] - $cpuTicks[0])+1;
96
$diff['nice'] = ($cpuTicks2[1] - $cpuTicks[1])+1;
97
$diff['sys'] = ($cpuTicks2[2] - $cpuTicks[2])+1;
98
$diff['intr'] = ($cpuTicks2[3] - $cpuTicks[3])+1;
99
$diff['idle'] = ($cpuTicks2[4] - $cpuTicks[4])+1;
100

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

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

    
106
return $cpuUsage;
107
}
108

    
109
?>
110
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
111
<html>
112
<head>
113
<title><?=gentitle("pfSense webGUI");?></title>
114
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
115
<link href="gui.css" rel="stylesheet" type="text/css">
116
</head>
117

    
118
<form>
119

    
120
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
121
<?php include("fbegin.inc"); ?>
122
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
123
              <tr align="center" valign="top">
124
                <td height="10" colspan="2">&nbsp;</td>
125
              </tr>
126
              <tr align="center" valign="top">
127
                <td colspan="2"><img src="logobig.jpg"></td>
128
              </tr>
129
	      <tr><td>&nbsp;</td></tr>
130
              <tr>
131
                <td colspan="2" class="listtopic">System information</td>
132
              </tr>
133
              <tr>
134
                <td width="25%" class="vncellt">Name</td>
135
                <td width="75%" class="listr">
136
                  <?php echo $config['system']['hostname'] . "." . $config['system']['domain']; ?>
137
                </td>
138
              </tr>
139
              <tr>
140
                <td width="25%" valign="top" class="vncellt">Version</td>
141
                <td width="75%" class="listr"> <strong>
142
                  <?php readfile("/etc/version"); ?>
143
                  </strong><br>
144
                  built on
145
                  <?php readfile("/etc/version.buildtime"); ?>
146
                </td>
147
              </tr>
148
              <tr>
149
                <td width="25%" class="vncellt">Platform</td>
150
                <td width="75%" class="listr">
151
                  <?=htmlspecialchars($g['platform']);?>
152
                </td>
153
              </tr><?php if ($hwcrypto): ?>
154
              <tr>
155
                <td width="25%" class="vncellt">Hardware crypto</td>
156
                <td width="75%" class="listr">
157
                  <?=htmlspecialchars($hwcrypto);?>
158
                </td>
159
              </tr><?php endif; ?>
160
              <tr>
161
                <td width="25%" class="vncellt">Uptime</td>
162
                <td width="75%" class="listr">
163
                  <?php
164
                    echo "<input style='border: 0px solid white;' size='30' name='uptime' id='uptime' value='"  .htmlspecialchars(get_uptime()) . "'>";
165
				  ?>
166
                </td>
167
              </tr><?php if ($config['lastchange']): ?>
168
              <tr>
169
                <td width="25%" class="vncellt">Last config change</td>
170
                <td width="75%" class="listr">
171
                  <?=htmlspecialchars(date("D M j G:i:s T Y", $config['lastchange']));?>
172
                </td>
173
              </tr><?php endif; ?>
174
			  <tr>
175
                <td width="25%" class="vncellt">CPU usage</td>
176
                <td width="75%" class="listr">
177
<?php
178
$cpuUsage = get_cpuusage(get_cputicks(), get_cputicks());
179

    
180
echo "<img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
181
echo "<img src='bar_blue.gif' height='15' name='cpuwidtha' id='cpuwidtha' width='" . $cpuUsage . "' border='0' align='absmiddle'>";
182
echo "<img src='bar_gray.gif' height='15' name='cpuwidthb' id='cpuwidthb' width='" . (100 - $cpuUsage) . "' border='0' align='absmiddle'>";
183
echo "<img src='bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
184
echo "<input style='border: 0px solid white;' size='30' name='cpumeter' id='cpumeter' value='{$cpuUsage}% (Updating in 3 seconds)'>";
185
//echo $cpuUsage . "%";
186
?>
187
                </td>
188
              </tr>
189
			  <tr>
190
                <td width="25%" class="vncellt">Memory usage</td>
191
                <td width="75%" class="listr">
192
<?php
193

    
194
exec("/sbin/sysctl -n vm.stats.vm.v_active_count vm.stats.vm.v_inactive_count " .
195
	"vm.stats.vm.v_wire_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count", $memory);
196

    
197
$totalMem = $memory[0] + $memory[1] + $memory[2] + $memory[3] + $memory[4];
198
$freeMem = $memory[4];
199
$usedMem = $totalMem - $freeMem;
200
$memUsage = round(($usedMem * 100) / $totalMem, 0);
201

    
202
echo " <img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
203
echo "<img src='bar_blue.gif' height='15' name='memwidtha' id='memwidtha' width='" . $memUsage . "' border='0' align='absmiddle'>";
204
echo "<img src='bar_gray.gif' height='15' name='memwidthb' id='memwidthb' width='" . (100 - $memUsage) . "' border='0' align='absmiddle'>";
205
echo "<img src='bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
206
echo "<input style='border: 0px solid white;' size='30' name='memusagemeter' id='memusagemeter' value='{$memUsage}%'>";
207
//echo $memUsage . "%";
208
?>
209
                </td>
210
              </tr>
211
			  <tr>
212
                <td width="25%" class="vncellt">SWAP usage</td>
213
                <td width="75%" class="listr">
214

    
215
<?php
216

    
217
$swapUsage = `/usr/sbin/swapinfo | cut -c45-55 | grep "%"`;
218
$swapUsage = ereg_replace('%', "", $swapUsage);
219
$swapUsage = ereg_replace(' ', "", $swapUsage);
220
$swapUsage = rtrim($swapUsage);
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' width='" . $swapUsage . "' border='0' align='absmiddle'>";
224
echo "<img src='bar_gray.gif' height='15' width='" . (100 - $swapUsage) . "' 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='swapusagemeter' id='swapusagemeter' value='{$swapUsage}%'>";
227
//echo $swapUsage . "%";
228

    
229
?>
230
                </td>
231
              </tr>
232
<?php
233
	/* XXX - Stub in the HW monitor for net4801 - needs to use platform var's once we start using them */
234
	if (file_exists("/etc/48xx")) {
235
echo "			  <tr>";
236
echo "                <td width='25%' class='vncellt'>Temperature </td>";
237
echo "                <td width='75%' class='listr'>";
238
// Initialize hw monitor
239
exec("/usr/local/sbin/env4801 -i");
240
$Temp = rtrim(`/usr/local/sbin/env4801 | grep Temp |cut -c24-25`);
241
echo "<img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
242
echo "<img src='bar_blue.gif' height='15' name='Tempwidtha' id='tempwidtha' width='" . $Temp . "' border='0' align='absmiddle'>";
243
echo "<img src='bar_gray.gif' height='15' name='Tempwidthb' id='tempwidthb' width='" . (100 - $Temp) . "' border='0' align='absmiddle'>";
244
echo "<img src='bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
245
echo "<input style='border: 0px solid white;' size='30' name='Tempmeter' id='Tempmeter' value='{$Temp}C'>";
246
echo "                </td>";
247
echo "              </tr>";
248
	}
249
?>
250

    
251

    
252
            </table>
253
            <?php include("fend.inc"); ?>
254
</body>
255
</html>
256
<?php
257

    
258
$counter = 0;
259

    
260
While(!Connection_Aborted()) {
261

    
262
    /* Update CPU meter */
263
    sleep(1);
264
    $cpuTicks = get_cputicks();
265
    sleep(2);
266
    $cpuTicks2 = get_cputicks();
267
    $cpuUsage = get_cpuusage($cpuTicks, $cpuTicks2);
268

    
269
    /* Update memory usage */
270
    exec("/sbin/sysctl -n vm.stats.vm.v_active_count vm.stats.vm.v_inactive_count " .
271
        "vm.stats.vm.v_wire_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count", $memory);
272

    
273
    $totalMem = $memory[0] + $memory[1] + $memory[2] + $memory[3] + $memory[4];
274
    $freeMem = $memory[4];
275
    $usedMem = $totalMem - $freeMem;
276
    $memUsage = round(($usedMem * 100) / $totalMem, 0);
277

    
278
    echo "<script language='javascript'>\n";
279
    echo "document.forms[0].uptime.value = '" . get_uptime() . "';\n";
280

    
281
    echo "document.cpuwidtha.style.width='" . $cpuUsage . "';\n";
282
    echo "document.cpuwidthb.style.width='" . (100 - $cpuUsage) . "';\n";
283
    echo "document.forms[0].cpumeter.value = '" . $cpuUsage . "%';\n";
284

    
285
    echo "document.memwidtha.style.width='" . $memUsage . "';\n";
286
    echo "document.memwidthb.style.width='" . (100 - $memUsage) . "';\n";
287
    echo "document.forms[0].memusagemeter.value = '" . $memUsage . "%';\n";
288

    
289
    if (file_exists("/etc/48xx")) {
290
      /* Update temp. meter */
291
      $Temp = rtrim(`/usr/local/sbin/env4801 | grep Temp |cut -c24-25`);
292
      echo "document.Tempwidtha.style.width='" . $Temp . "';\n";
293
      echo "document.Tempwidthb.style.width='" . (100 - $Temp) . "';\n";
294
      echo "document.forms[0].Tempmeter.value = '" . $Temp . "C';\n";
295
    }
296

    
297
    echo "</script>\n";
298

    
299
    /*
300
     *   prevent user from running out of ram.
301
     *   firefox and ie can be a bear on ram usage!
302
     */
303
    $counter++;
304
    if($counter > 120) {
305
	    echo "Redirecting to <a href=\"index.php\">Main Status</a>.<p>";
306
	    echo "<meta http-equiv=\"refresh\" content=\"1;url=index.php\">";
307
	    exit;
308
    }
309

    
310
}
311

    
312
?>
313

    
(44-44/109)