Project

General

Profile

Download (12.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

    
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
?>
42
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
43
<html>
44
<head>
45
<title><?=gentitle("pfSense webGUI");?></title>
46
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
47
<link href="gui.css" rel="stylesheet" type="text/css">
48
</head>
49
<form>
50
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
51
<?php
52
	echo "<center>";
53
	echo "Welcome to pfSense!<p>";
54
	echo "One moment while we start the initial setup wizard.<p>";
55
	echo "Embedded platform users: Please be patient, the wizard takes a little longer to run than the normal gui.<p>";
56
	echo "To bypass the wizard, click on the pfSense wizard on the initial page.";
57
	echo "<meta http-equiv=\"refresh\" content=\"1;url=wizard.php?xml=setup_wizard.xml\">";
58
	exit;
59
}
60

    
61
/* find out whether there's hardware encryption (hifn) */
62
unset($hwcrypto);
63
$fd = @fopen("{$g['varlog_path']}/dmesg.boot", "r");
64
if ($fd) {
65
	while (!feof($fd)) {
66
		$dmesgl = fgets($fd);
67
		if (preg_match("/^hifn.: (.*?),/", $dmesgl, $matches)) {
68
			$hwcrypto = $matches[1];
69
			break;
70
		}
71
	}
72
	fclose($fd);
73
}
74

    
75
function get_uptime() {
76
	exec("/sbin/sysctl -n kern.boottime", $boottime);
77
	preg_match("/sec = (\d+)/", $boottime[0], $matches);
78
	$boottime = $matches[1];
79
	$uptime = time() - $boottime;
80

    
81
	if ($uptime > 60)
82
		$uptime += 30;
83
	$updays = (int)($uptime / 86400);
84
	$uptime %= 86400;
85
	$uphours = (int)($uptime / 3600);
86
	$uptime %= 3600;
87
	$upmins = (int)($uptime / 60);
88

    
89
	$uptimestr = "";
90
	if ($updays > 1)
91
		$uptimestr .= "$updays days, ";
92
	else if ($updays > 0)
93
		$uptimestr .= "1 day, ";
94
	$uptimestr .= sprintf("%02d:%02d", $uphours, $upmins);
95
	return $uptimestr;
96
}
97

    
98
function get_cputicks() {
99
	$cputicks = explode(" ", `/sbin/sysctl -n kern.cp_time`);
100
	return $cputicks;
101
}
102

    
103
function get_cpuusage($cpuTicks, $cpuTicks2) {
104

    
105
$diff = array();
106
$diff['user'] = ($cpuTicks2[0] - $cpuTicks[0])+1;
107
$diff['nice'] = ($cpuTicks2[1] - $cpuTicks[1])+1;
108
$diff['sys'] = ($cpuTicks2[2] - $cpuTicks[2])+1;
109
$diff['intr'] = ($cpuTicks2[3] - $cpuTicks[3])+1;
110
$diff['idle'] = ($cpuTicks2[4] - $cpuTicks[4])+1;
111

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

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

    
117
return $cpuUsage;
118
}
119

    
120
?>
121
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
122
<html>
123
<head>
124
<title><?=gentitle("pfSense webGUI");?></title>
125
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
126
<link href="gui.css" rel="stylesheet" type="text/css">
127
</head>
128

    
129
<form>
130

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

    
191
echo "<img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
192
echo "<img src='bar_blue.gif' height='15' name='cpuwidtha' id='cpuwidtha' width='" . $cpuUsage . "' border='0' align='absmiddle'>";
193
echo "<img src='bar_gray.gif' height='15' name='cpuwidthb' id='cpuwidthb' width='" . (100 - $cpuUsage) . "' border='0' align='absmiddle'>";
194
echo "<img src='bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
195
echo "<input style='border: 0px solid white;' size='30' name='cpumeter' id='cpumeter' value='{$cpuUsage}% (Updating in 3 seconds)'>";
196
//echo $cpuUsage . "%";
197
?>
198
                </td>
199
              </tr>
200
			  <tr>
201
                <td width="25%" class="vncellt">Memory usage</td>
202
                <td width="75%" class="listr">
203
<?php
204

    
205
exec("/sbin/sysctl -n vm.stats.vm.v_active_count vm.stats.vm.v_inactive_count " .
206
	"vm.stats.vm.v_wire_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count", $memory);
207

    
208
$totalMem = $memory[0] + $memory[1] + $memory[2] + $memory[3] + $memory[4];
209
$freeMem = $memory[4];
210
$usedMem = $totalMem - $freeMem;
211
$memUsage = round(($usedMem * 100) / $totalMem, 0);
212

    
213
echo " <img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
214
echo "<img src='bar_blue.gif' height='15' name='memwidtha' id='memwidtha' width='" . $memUsage . "' border='0' align='absmiddle'>";
215
echo "<img src='bar_gray.gif' height='15' name='memwidthb' id='memwidthb' width='" . (100 - $memUsage) . "' border='0' align='absmiddle'>";
216
echo "<img src='bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
217
echo "<input style='border: 0px solid white;' size='30' name='memusagemeter' id='memusagemeter' value='{$memUsage}%'>";
218
//echo $memUsage . "%";
219
?>
220
                </td>
221
              </tr>
222
			  <tr>
223
                <td width="25%" class="vncellt">SWAP usage</td>
224
                <td width="75%" class="listr">
225

    
226
<?php
227

    
228
$swapUsage = `/usr/sbin/swapinfo | cut -c45-55 | grep "%"`;
229
$swapUsage = ereg_replace('%', "", $swapUsage);
230
$swapUsage = ereg_replace(' ', "", $swapUsage);
231
$swapUsage = rtrim($swapUsage);
232

    
233
echo "<img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
234
echo "<img src='bar_blue.gif' height='15' width='" . $swapUsage . "' border='0' align='absmiddle'>";
235
echo "<img src='bar_gray.gif' height='15' width='" . (100 - $swapUsage) . "' border='0' align='absmiddle'>";
236
echo "<img src='bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
237
echo "<input style='border: 0px solid white;' size='30' name='swapusagemeter' id='swapusagemeter' value='{$swapUsage}%'>";
238
//echo $swapUsage . "%";
239

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

    
262

    
263
            </table>
264
            <?php include("fend.inc"); ?>
265
</body>
266
</html>
267
<?php
268

    
269
$counter = 0;
270

    
271
While(!Connection_Aborted()) {
272

    
273
    /* Update CPU meter */
274
    sleep(1);
275
    $cpuTicks = get_cputicks();
276
    sleep(2);
277
    $cpuTicks2 = get_cputicks();
278
    $cpuUsage = get_cpuusage($cpuTicks, $cpuTicks2);
279

    
280
    /* Update memory usage */
281
    exec("/sbin/sysctl -n vm.stats.vm.v_active_count vm.stats.vm.v_inactive_count " .
282
        "vm.stats.vm.v_wire_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count", $memory);
283

    
284
    $totalMem = $memory[0] + $memory[1] + $memory[2] + $memory[3] + $memory[4];
285
    $freeMem = $memory[4];
286
    $usedMem = $totalMem - $freeMem;
287
    $memUsage = round(($usedMem * 100) / $totalMem, 0);
288

    
289
    echo "<script language='javascript'>\n";
290
    echo "document.forms[0].uptime.value = '" . get_uptime() . "';\n";
291

    
292
    echo "document.cpuwidtha.style.width='" . $cpuUsage . "';\n";
293
    echo "document.cpuwidthb.style.width='" . (100 - $cpuUsage) . "';\n";
294
    echo "document.forms[0].cpumeter.value = '" . $cpuUsage . "%';\n";
295

    
296
    echo "document.memwidtha.style.width='" . $memUsage . "';\n";
297
    echo "document.memwidthb.style.width='" . (100 - $memUsage) . "';\n";
298
    echo "document.forms[0].memusagemeter.value = '" . $memUsage . "%';\n";
299

    
300
    if (file_exists("/etc/48xx")) {
301
      /* Update temp. meter */
302
      $Temp = rtrim(`/usr/local/sbin/env4801 | grep Temp |cut -c24-25`);
303
      echo "document.Tempwidtha.style.width='" . $Temp . "';\n";
304
      echo "document.Tempwidthb.style.width='" . (100 - $Temp) . "';\n";
305
      echo "document.forms[0].Tempmeter.value = '" . $Temp . "C';\n";
306
    }
307

    
308
    echo "</script>\n";
309

    
310
    /*
311
     *   prevent user from running out of ram.
312
     *   firefox and ie can be a bear on ram usage!
313
     */
314
    $counter++;
315
    if($counter > 120) {
316
	    echo "Redirecting to <a href=\"index.php\">Main Status</a>.<p>";
317
	    echo "<meta http-equiv=\"refresh\" content=\"1;url=index.php\">";
318
	    exit;
319
    }
320

    
321
}
322

    
323
?>
324

    
(45-45/111)