Project

General

Profile

Download (11.5 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/*
4
    index.php
5
    Copyright (C) 2004, 2005 Scott Ullrich
6
    All rights reserved.
7

    
8
    Originally part of m0n0wall (http://m0n0.ch/wall)
9
    Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
    All rights reserved.
11

    
12
    Redistribution and use in source and binary forms, with or without
13
    modification, are permitted provided that the following conditions are met:
14

    
15
    1. Redistributions of source code must retain the above copyright notice,
16
       this list of conditions and the following disclaimer.
17

    
18
    2. Redistributions in binary form must reproduce the above copyright
19
       notice, this list of conditions and the following disclaimer in the
20
       documentation and/or other materials provided with the distribution.
21

    
22
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
    POSSIBILITY OF SUCH DAMAGE.
32
*/
33

    
34
if(file_exists("/usr/local/www/trigger_initial_wizard")) {
35
	unlink("/usr/local/www/trigger_initial_wizard");
36
	header("Location:  wizard.php?xml=setup_wizard.xml");
37
}
38

    
39
require("guiconfig.inc");
40

    
41
/* find out whether there's hardware encryption (hifn) */
42
unset($hwcrypto);
43
$fd = @fopen("{$g['varlog_path']}/dmesg.boot", "r");
44
if ($fd) {
45
	while (!feof($fd)) {
46
		$dmesgl = fgets($fd);
47
		if (preg_match("/^hifn.: (.*?),/", $dmesgl, $matches)) {
48
			$hwcrypto = $matches[1];
49
			break;
50
		}
51
	}
52
	fclose($fd);
53
}
54

    
55
function get_uptime() {
56
	exec("/sbin/sysctl -n kern.boottime", $boottime);
57
	preg_match("/sec = (\d+)/", $boottime[0], $matches);
58
	$boottime = $matches[1];
59
	$uptime = time() - $boottime;
60

    
61
	if ($uptime > 60)
62
		$uptime += 30;
63
	$updays = (int)($uptime / 86400);
64
	$uptime %= 86400;
65
	$uphours = (int)($uptime / 3600);
66
	$uptime %= 3600;
67
	$upmins = (int)($uptime / 60);
68

    
69
	$uptimestr = "";
70
	if ($updays > 1)
71
		$uptimestr .= "$updays days, ";
72
	else if ($updays > 0)
73
		$uptimestr .= "1 day, ";
74
	$uptimestr .= sprintf("%02d:%02d", $uphours, $upmins);
75
	return $uptimestr;
76
}
77

    
78
function get_cputicks() {
79
	$cputicks = explode(" ", `/sbin/sysctl -n kern.cp_time`);
80
	return $cputicks;
81
}
82

    
83
function get_cpuusage($cpuTicks, $cpuTicks2) {
84

    
85
$diff = array();
86
$diff['user'] = ($cpuTicks2[0] - $cpuTicks[0])+1;
87
$diff['nice'] = ($cpuTicks2[1] - $cpuTicks[1])+1;
88
$diff['sys'] = ($cpuTicks2[2] - $cpuTicks[2])+1;
89
$diff['intr'] = ($cpuTicks2[3] - $cpuTicks[3])+1;
90
$diff['idle'] = ($cpuTicks2[4] - $cpuTicks[4])+1;
91

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

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

    
97
return $cpuUsage;
98
}
99

    
100

    
101
?>
102
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
103
<html>
104
<head>
105
<title><?=gentitle("pfSense webGUI");?></title>
106
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
107
<link href="gui.css" rel="stylesheet" type="text/css">
108
</head>
109

    
110
<form>
111

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

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

    
186
exec("/sbin/sysctl -n vm.stats.vm.v_active_count vm.stats.vm.v_inactive_count " .
187
	"vm.stats.vm.v_wire_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count", $memory);
188

    
189
$totalMem = $memory[0] + $memory[1] + $memory[2] + $memory[3] + $memory[4];
190
$freeMem = $memory[4];
191
$usedMem = $totalMem - $freeMem;
192
$memUsage = round(($usedMem * 100) / $totalMem, 0);
193

    
194
echo " <img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
195
echo "<img src='bar_blue.gif' height='15' name='memwidtha' id='memwidtha' width='" . $memUsage . "' border='0' align='absmiddle'>";
196
echo "<img src='bar_gray.gif' height='15' name='memwidthb' id='memwidthb' width='" . (100 - $memUsage) . "' border='0' align='absmiddle'>";
197
echo "<img src='bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
198
echo "<input style='border: 0px solid white;' size='30' name='memusagemeter' id='memusagemeter' value='{$memUsage}%'>";
199
//echo $memUsage . "%";
200
?>
201
                </td>
202
              </tr>
203
			  <tr>
204
                <td width="25%" class="vncellt">SWAP usage</td>
205
                <td width="75%" class="listr">
206

    
207
<?php
208

    
209
$swapUsage = `/usr/sbin/swapinfo | cut -c45-55 | grep "%"`;
210
$swapUsage = ereg_replace('%', "", $swapUsage);
211
$swapUsage = ereg_replace(' ', "", $swapUsage);
212
$swapUsage = rtrim($swapUsage);
213

    
214
echo "<img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
215
echo "<img src='bar_blue.gif' height='15' width='" . $swapUsage . "' border='0' align='absmiddle'>";
216
echo "<img src='bar_gray.gif' height='15' width='" . (100 - $swapUsage) . "' border='0' align='absmiddle'>";
217
echo "<img src='bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
218
echo "<input style='border: 0px solid white;' size='30' name='swapusagemeter' id='swapusagemeter' value='{$swapUsage}%'>";
219
//echo $swapUsage . "%";
220

    
221
?>
222
                </td>
223
              </tr>
224
<?php
225
	/* XXX - Stub in the HW monitor for net4801 - needs to use platform var's once we start using them */
226
	if (file_exists("/etc/48xx")) {
227
echo "			  <tr>";
228
echo "                <td width='25%' class='vncellt'>Temperature </td>";
229
echo "                <td width='75%' class='listr'>";
230
// Initialize hw monitor
231
exec("/usr/local/sbin/env4801 -i");
232
$Temp = rtrim(`/usr/local/sbin/env4801 | grep Temp |cut -c24-25`);
233
echo "<img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
234
echo "<img src='bar_blue.gif' height='15' name='Tempwidtha' id='tempwidtha' width='" . $Temp . "' border='0' align='absmiddle'>";
235
echo "<img src='bar_gray.gif' height='15' name='Tempwidthb' id='tempwidthb' width='" . (100 - $Temp) . "' 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='Tempmeter' id='Tempmeter' value='{$Temp}C'>";
238
echo "                </td>";
239
echo "              </tr>";
240
	}
241
?>
242

    
243

    
244
            </table>
245
            <?php include("fend.inc"); ?>
246
</body>
247
</html>
248
<?php
249

    
250
$counter = 0;
251

    
252
While(!Connection_Aborted()) {
253

    
254
    /* Update CPU meter */
255
    sleep(1);
256
    $cpuTicks = get_cputicks();
257
    sleep(2);
258
    $cpuTicks2 = get_cputicks();
259
    $cpuUsage = get_cpuusage($cpuTicks, $cpuTicks2);
260

    
261
    /* Update memory usage */
262
    exec("/sbin/sysctl -n vm.stats.vm.v_active_count vm.stats.vm.v_inactive_count " .
263
        "vm.stats.vm.v_wire_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count", $memory);
264

    
265
    $totalMem = $memory[0] + $memory[1] + $memory[2] + $memory[3] + $memory[4];
266
    $freeMem = $memory[4];
267
    $usedMem = $totalMem - $freeMem;
268
    $memUsage = round(($usedMem * 100) / $totalMem, 0);
269

    
270
    echo "<script language='javascript'>\n";
271
    echo "document.forms[0].uptime.value = '" . get_uptime() . "';\n";
272
    
273
    echo "document.cpuwidtha.style.width='" . $cpuUsage . "';\n";
274
    echo "document.cpuwidthb.style.width='" . (100 - $cpuUsage) . "';\n";
275
    echo "document.forms[0].cpumeter.value = '" . $cpuUsage . "%';\n";
276

    
277
    echo "document.memwidtha.style.width='" . $memUsage . "';\n";
278
    echo "document.memwidthb.style.width='" . (100 - $memUsage) . "';\n";
279
    echo "document.forms[0].memusagemeter.value = '" . $memUsage . "%';\n";
280

    
281
    if (file_exists("/etc/48xx")) {
282
      /* Update temp. meter */
283
      $Temp = rtrim(`/usr/local/sbin/env4801 | grep Temp |cut -c24-25`);
284
      echo "document.Tempwidtha.style.width='" . $Temp . "';\n";
285
      echo "document.Tempwidthb.style.width='" . (100 - $Temp) . "';\n";
286
      echo "document.forms[0].Tempmeter.value = '" . $Temp . "C';\n";
287
    }
288

    
289
    echo "</script>\n";
290

    
291
    /*
292
     *   prevent user from running out of ram.
293
     *   firefox and ie can be a bear on ram usage!
294
     */
295
    $counter++;
296
    if($counter > 120) {
297
	    echo "Redirecting to <a href=\"index.php\">Main Status</a>.<p>";
298
	    echo "<meta http-equiv=\"refresh\" content=\"1;url=index.php\">";
299
	    exit;
300
    }
301

    
302
}
303

    
304
?>
305

    
(44-44/106)