Projet

Général

Profil

Télécharger (11,7 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / widgets / widgets / system_information.widget.php @ 0d4b6b89

1 1eaee2f9 Scott Dale
<?php
2
/*
3
        $Id$
4
        Copyright 2007 Scott Dale
5 184016fc Chris Buechler
        Part of pfSense widgets (https://www.pfsense.org)
6 1eaee2f9 Scott Dale
        originally based on m0n0wall (http://m0n0.ch/wall)
7
8
        Copyright (C) 2004-2005 T. Lechat <dev@lechat.org>, Manuel Kasper <mk@neon1.net>
9
        and Jonathan Watt <jwatt@jwatt.org>.
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 9d488ea4 Scott Dale
34
require_once("functions.inc");
35 f5bdff7f sullrich
require_once("guiconfig.inc");
36 9d488ea4 Scott Dale
require_once('notices.inc');
37 d0fc4479 Warren Baker
include_once("includes/functions.inc.php");
38 9d488ea4 Scott Dale
39 371f8c19 Scott Ullrich
if($_REQUEST['getupdatestatus']) {
40 7a058f06 jim-p
	if(isset($config['system']['firmware']['disablecheck'])) {
41
		exit;
42
	}
43 c3606a3b Ermal
	if(isset($config['system']['firmware']['alturl']['enable']))
44 371f8c19 Scott Ullrich
		$updater_url = "{$config['system']['firmware']['alturl']['firmwareurl']}";
45
	else 
46
		$updater_url = $g['update_url'];
47 2e591a5d jim-p
48
	$nanosize = "";
49
	if ($g['platform'] == "nanobsd") {
50 ba581f07 jim-p
		if (file_exists("/etc/nano_use_vga.txt"))
51
			$nanosize = "-nanobsd-vga-";
52
		else
53
			$nanosize = "-nanobsd-";
54
		$nanosize .= strtolower(trim(file_get_contents("/etc/nanosize.txt")));
55 2e591a5d jim-p
	}
56
57 5ee6a457 Ermal
	@unlink("/tmp/{$g['product_name']}_version");
58 4ed69f33 jim-p
	if (download_file_with_progress_bar("{$updater_url}/version{$nanosize}", "/tmp/{$g['product_name']}_version", 'read_body', 5, 5) === true)
59 d164643a jim-p
		$remote_version = trim(@file_get_contents("/tmp/{$g['product_name']}_version"));
60 2e591a5d jim-p
61 2cfbe062 jim-p
	if(empty($remote_version))
62 371f8c19 Scott Ullrich
		echo "<br /><br />Unable to check for updates.";
63 773c99bc Ermal
	else {
64 2cfbe062 jim-p
		$current_installed_buildtime = trim(file_get_contents("/etc/version.buildtime"));
65
		$current_installed_version = trim(file_get_contents("/etc/version"));
66 773c99bc Ermal
67 2cfbe062 jim-p
		if(!$remote_version) {
68
			echo "<br /><br />Unable to check for updates.";
69 371f8c19 Scott Ullrich
		}
70
		else {
71 773c99bc Ermal
			$needs_system_upgrade = false;
72 2cfbe062 jim-p
			if (pfs_version_compare($current_installed_buildtime, $current_installed_version, $remote_version) == -1) {
73 8cd558b6 ayvis
				echo "<br /><span class=\"red\" id=\"updatealert\"><b>Update available. </b></span><a href=\"/system_firmware_check.php\">Click Here</a> to view update.";
74 bd42727d Colin Fleming
				echo "\n<script type=\"text/javascript\">\n";
75
				echo "//<![CDATA[\n";
76
				echo "jQuery('#updatealert').effect('pulsate',{times: 30},10000);\n";
77
				echo "//]]>\n";
78
				echo "</script>\n";
79 773c99bc Ermal
			} else
80 2cfbe062 jim-p
				echo "<br />You are on the latest version.";
81 773c99bc Ermal
		}
82
	}
83 371f8c19 Scott Ullrich
	exit;
84
}
85
86 e862ba62 Scott Dale
$curcfg = $config['system']['firmware'];
87
88 0d4b6b89 jim-p
$filesystems = get_mounted_filesystems();
89
90 1eaee2f9 Scott Dale
?>
91 07130afe ayvis
<script type="text/javascript">
92 bd42727d Colin Fleming
//<![CDATA[
93 bc0a344b Charlie Marshall
	jQuery(function() { 
94
		jQuery("#statePB").progressbar( { value: <?php echo get_pfstate(true); ?> } );
95
		jQuery("#mbufPB").progressbar( { value: <?php echo get_mbuf(true); ?> } );
96
		jQuery("#cpuPB").progressbar( { value:false } );
97
		jQuery("#memUsagePB").progressbar( { value: <?php echo mem_usage(); ?> } );
98 0d4b6b89 jim-p
99
<?PHP $d = 0; ?>
100
<?PHP foreach ($filesystems as $fs): ?>
101
		jQuery("#diskUsagePB<?php echo $d++; ?>").progressbar( { value: <?php echo $fs['percent_used']; ?> } );
102
<?PHP endforeach; ?>
103 5ef8ec88 Charlie Marshall
104
		<?php if($showswap == true): ?>
105
			jQuery("#swapUsagePB").progressbar( { value: <?php echo swap_usage(); ?> } );
106
		<?php endif; ?>
107
		<?php if (get_temp() != ""): ?>
108
                	jQuery("#tempPB").progressbar( { value: <?php echo get_temp(); ?> } );
109
		<?php endif; ?>
110 bc0a344b Charlie Marshall
	});
111 bd42727d Colin Fleming
//]]>
112 bc0a344b Charlie Marshall
</script>
113 9c07440e Colin Fleming
114
<table width="100%" border="0" cellspacing="0" cellpadding="0" summary="system information">
115 f69aa687 Scott Dale
	<tbody>
116
		<tr>
117 5765d691 Selim
			<td width="25%" class="vncellt"><?=gettext("Name");?></td>
118 f69aa687 Scott Dale
			<td width="75%" class="listr"><?php echo $config['system']['hostname'] . "." . $config['system']['domain']; ?></td>
119
		</tr>
120
		<tr>
121 5765d691 Selim
			<td width="25%" valign="top" class="vncellt"><?=gettext("Version");?></td>
122 f69aa687 Scott Dale
			<td width="75%" class="listr">
123
				<strong><?php readfile("/etc/version"); ?></strong>
124 7b228323 Ermal
				(<?php echo php_uname("m"); ?>)
125 f69aa687 Scott Dale
				<br />
126
				built on <?php readfile("/etc/version.buildtime"); ?>
127 3312d8af jim-p
		<?php if(!$g['hideuname']): ?>
128 7a058f06 jim-p
		<br />
129 9c07440e Colin Fleming
		<div id="uname"><a href="#" onclick='swapuname(); return false;'><?php echo php_uname("s") . " " . php_uname("r"); ?></a></div>
130 3312d8af jim-p
		<?php endif; ?>
131 7a058f06 jim-p
		<?php if(!isset($config['system']['firmware']['disablecheck'])): ?>
132 8cd558b6 ayvis
		<div id='updatestatus'><br /><?php echo gettext("Obtaining update status"); ?> ...</div>
133 7a058f06 jim-p
		<?php endif; ?>
134 f69aa687 Scott Dale
			</td>
135
		</tr>
136 82ef398a Scott Ullrich
		<?php if(!$g['hideplatform']): ?>
137 f69aa687 Scott Dale
		<tr>
138 5765d691 Selim
			<td width="25%" class="vncellt"><?=gettext("Platform");?></td>
139 59d73709 jim-p
			<td width="75%" class="listr">
140
				<?=htmlspecialchars($g['platform']);?>
141
				<?php if (($g['platform'] == "nanobsd") && (file_exists("/etc/nanosize.txt"))) {
142
					echo " (" . htmlspecialchars(trim(file_get_contents("/etc/nanosize.txt"))) . ")";
143
				} ?>
144
			</td>
145 f69aa687 Scott Dale
		</tr>
146 82ef398a Scott Ullrich
		<?php endif; ?>
147 a91333d3 jim-p
		<?php if ($g['platform'] == "nanobsd"): ?>
148
			<?
149 08fd5444 jim-p
			global $SLICE, $OLDSLICE, $TOFLASH, $COMPLETE_PATH, $COMPLETE_BOOT_PATH;
150
			global $GLABEL_SLICE, $UFS_ID, $OLD_UFS_ID, $BOOTFLASH;
151
			global $BOOT_DEVICE, $REAL_BOOT_DEVICE, $BOOT_DRIVE, $ACTIVE_SLICE;
152
			nanobsd_detect_slice_info();
153 7b229013 jim-p
			$rw = is_writable("/") ? "(rw)" : "(ro)";
154 a91333d3 jim-p
			?>
155
		<tr>
156 5765d691 Selim
			<td width="25%" class="vncellt"><?=gettext("NanoBSD Boot Slice");?></td>
157 08fd5444 jim-p
			<td width="75%" class="listr">
158 7b229013 jim-p
				<?=htmlspecialchars(nanobsd_friendly_slice_name($BOOT_DEVICE));?> / <?=htmlspecialchars($BOOTFLASH);?> <?php echo $rw; ?>
159 08fd5444 jim-p
				<?php if ($BOOTFLASH != $ACTIVE_SLICE): ?>
160 8cd558b6 ayvis
				<br /><br />Next Boot:<br />
161 ce338162 jim-p
				<?=htmlspecialchars(nanobsd_friendly_slice_name($GLABEL_SLICE));?> / <?=htmlspecialchars($ACTIVE_SLICE);?>
162 08fd5444 jim-p
				<?php endif; ?>
163
			</td>
164 a91333d3 jim-p
		</tr>
165
		<?php endif; ?>
166 f69aa687 Scott Dale
		<tr>
167 5765d691 Selim
			<td width="25%" class="vncellt"><?=gettext("CPU Type");?></td>
168 f69aa687 Scott Dale
			<td width="75%" class="listr">
169
			<?php 
170
				$cpumodel = "";
171
				exec("/sbin/sysctl -n hw.model", $cpumodel);
172
				$cpumodel = implode(" ", $cpumodel);
173 81ab3a73 jim-p
				echo (htmlspecialchars($cpumodel));
174
			?>
175 4dedd18a Cristian Feldman
			<div id="cpufreq"><?= get_cpufreq(); ?></div>
176 b097a7cf jim-p
		<?php	$cpucount = get_cpu_count();
177
			if ($cpucount > 1): ?>
178
			<div id="cpucount">
179
				<?= htmlspecialchars($cpucount) ?> CPUs: <?= htmlspecialchars(get_cpu_count(true)); ?></div>
180
		<?php	endif; ?>
181 f69aa687 Scott Dale
			</td>
182
		</tr>
183
		<?php if ($hwcrypto): ?>
184
		<tr>
185 5765d691 Selim
			<td width="25%" class="vncellt"><?=gettext("Hardware crypto");?></td>
186 f69aa687 Scott Dale
			<td width="75%" class="listr"><?=htmlspecialchars($hwcrypto);?></td>
187
		</tr>
188
		<?php endif; ?>
189 9d551001 Scott Dale
		<tr>
190 5765d691 Selim
			<td width="25%" class="vncellt"><?=gettext("Uptime");?></td>
191 3a94345c jim-p
			<td width="75%" class="listr" id="uptime"><?= htmlspecialchars(get_uptime()); ?></td>
192 9d488ea4 Scott Dale
		</tr>
193
        <tr>
194
            <td width="25%" class="vncellt"><?=gettext("Current date/time");?></td>
195
            <td width="75%" class="listr">
196
                <div id="datetime"><?= date("D M j G:i:s T Y"); ?></div>
197
            </td>
198 9b50c0ed Charlie Marshall
        </tr>
199 f69aa687 Scott Dale
		 <tr>
200 5765d691 Selim
             <td width="30%" class="vncellt"><?=gettext("DNS server(s)");?></td>
201 f69aa687 Scott Dale
             <td width="70%" class="listr">
202
					<?php
203
						$dns_servers = get_dns_servers();
204
						foreach($dns_servers as $dns) {
205 8cd558b6 ayvis
							echo "{$dns}<br />";
206 f69aa687 Scott Dale
						}
207
					?>
208
			</td>
209
		</tr>	
210
		<?php if ($config['revision']): ?>
211
		<tr>
212 5765d691 Selim
			<td width="25%" class="vncellt"><?=gettext("Last config change");?></td>
213 995047da Seth Mos
			<td width="75%" class="listr"><?= htmlspecialchars(date("D M j G:i:s T Y", intval($config['revision']['time'])));?></td>
214 f69aa687 Scott Dale
		</tr>
215
		<?php endif; ?>
216
		<tr>
217 5765d691 Selim
			<td width="25%" class="vncellt"><?=gettext("State table size");?></td>
218 9d551001 Scott Dale
			<td width="75%" class="listr">
219 4a83831c jim-p
				<?php	$pfstatetext = get_pfstate();
220
					$pfstateusage = get_pfstate(true);
221
				?>
222 bc0a344b Charlie Marshall
				<div id="statePB"></div>
223
				<span id="pfstateusagemeter"><?= $pfstateusage.'%'; ?></span> (<span id="pfstate"><?= htmlspecialchars($pfstatetext); ?></span>)
224 9d551001 Scott Dale
		    	<br />
225 5765d691 Selim
		    	<a href="diag_dump_states.php"><?=gettext("Show states");?></a>
226 9d551001 Scott Dale
			</td>
227
		</tr>
228 88207a6b Scott Ullrich
		<tr>
229 5765d691 Selim
			<td width="25%" class="vncellt"><?=gettext("MBUF Usage");?></td>
230 88207a6b Scott Ullrich
			<td width="75%" class="listr">
231
				<?php
232 2cb760da jim-p
					$mbufstext = get_mbuf();
233
					$mbufusage = get_mbuf(true);
234 88207a6b Scott Ullrich
				?>
235 bc0a344b Charlie Marshall
				<div id="mbufPB"></div>
236
				<span id="mbufusagemeter"><?= $mbufusage.'%'; ?></span> (<span id="mbuf"><?= $mbufstext ?></span>)
237 88207a6b Scott Ullrich
			</td>
238
		</tr>
239 135a0956 Joecowboy
                <?php if (get_temp() != ""): ?>
240 24d51534 Joecowboy
                <tr>
241 5765d691 Selim
                        <td width="25%" class="vncellt"><?=gettext("Temperature");?></td>
242 24d51534 Joecowboy
			<td width="75%" class="listr">
243 135a0956 Joecowboy
				<?php $TempMeter = $temp = get_temp(); ?>
244 bc0a344b Charlie Marshall
				<div id="tempPB"></div>
245 3a94345c jim-p
				<span id="tempmeter"><?= $temp."&#176;C"; ?></span>
246 24d51534 Joecowboy
			</td>
247
                </tr>
248 135a0956 Joecowboy
                <?php endif; ?>
249 25a46a3c Cristian Feldman
		<tr>
250 5765d691 Selim
			<td width="25%" class="vncellt"><?=gettext("Load average");?></td>
251 25a46a3c Cristian Feldman
			<td width="75%" class="listr">
252
			<div id="load_average" title="Last 1, 5 and 15 minutes"><?= get_load_average(); ?></div>
253
			</td>
254
		</tr>
255 9d551001 Scott Dale
		<tr>
256 5765d691 Selim
			<td width="25%" class="vncellt"><?=gettext("CPU usage");?></td>
257 9d551001 Scott Dale
			<td width="75%" class="listr">
258 bc0a344b Charlie Marshall
				<div id="cpuPB"></div>
259
				<span id="cpumeter">(Updating in 10 seconds)</span>
260 9d551001 Scott Dale
			</td>
261
		</tr>
262
		<tr>
263 5765d691 Selim
			<td width="25%" class="vncellt"><?=gettext("Memory usage");?></td>
264 9d551001 Scott Dale
			<td width="75%" class="listr">
265
				<?php $memUsage = mem_usage(); ?>
266 bc0a344b Charlie Marshall
				<div id="memUsagePB"></div>
267
				<span id="memusagemeter"><?= $memUsage.'%'; ?></span> of <?= sprintf("%.0f", `/sbin/sysctl -n hw.physmem` / (1024*1024)) ?> MB
268 9d551001 Scott Dale
			</td>
269
		</tr>
270 f69aa687 Scott Dale
		<?php if($showswap == true): ?>
271
		<tr>
272 5765d691 Selim
			<td width="25%" class="vncellt"><?=gettext("SWAP usage");?></td>
273 f69aa687 Scott Dale
			<td width="75%" class="listr">
274
				<?php $swapusage = swap_usage(); ?>
275 bc0a344b Charlie Marshall
				<div id="swapUsagePB"></div>
276
				<span id="swapusagemeter"><?= $swapusage.'%'; ?></span> of <?= sprintf("%.0f", `/usr/sbin/swapinfo -m | /usr/bin/grep -v Device | /usr/bin/awk '{ print $2;}'`) ?> MB
277 f69aa687 Scott Dale
			</td>
278
		</tr>
279
		<?php endif; ?>
280
		<tr>
281 5765d691 Selim
			<td width="25%" class="vncellt"><?=gettext("Disk usage");?></td>
282 9d551001 Scott Dale
			<td width="75%" class="listr">
283 0d4b6b89 jim-p
<?PHP $d = 0; ?>
284
<?PHP foreach ($filesystems as $fs): ?>
285
				<div id="diskUsagePB<?php echo $d; ?>"></div>
286
				<?PHP if (substr(basename($fs['device']), 0, 2) == "md") $fs['type'] .= " in RAM"; ?>
287
				<?PHP echo "{$fs['mountpoint']} ({$fs['type']})";?>: <span id="diskusagemeter<?php echo $d++ ?>"><?= $fs['percent_used'].'%'; ?></span> of <?PHP echo $fs['total_size'];?>
288
				<br />
289
<?PHP endforeach; ?>
290 9d551001 Scott Dale
			</td>
291
		</tr>
292 f69aa687 Scott Dale
	</tbody>
293 3defdb8a Scott Ullrich
</table>
294 371f8c19 Scott Ullrich
<script type="text/javascript">
295 9c07440e Colin Fleming
//<![CDATA[
296 7a058f06 jim-p
	function swapuname() {
297
		jQuery('#uname').html("<?php echo php_uname("a"); ?>");
298
	}
299
	<?php if(!isset($config['system']['firmware']['disablecheck'])): ?>
300 0eea8800 Scott Ullrich
	function getstatus() {
301
		scroll(0,0);
302
		var url = "/widgets/widgets/system_information.widget.php";
303
		var pars = 'getupdatestatus=yes';
304 f910c29e Vinicius Coque
		jQuery.ajax(
305 0eea8800 Scott Ullrich
			url,
306
			{
307 f910c29e Vinicius Coque
				type: 'get',
308
				data: pars,
309
				complete: activitycallback
310 0eea8800 Scott Ullrich
			});
311
	}
312 371f8c19 Scott Ullrich
	function activitycallback(transport) {
313 5d0d5eb0 Vinicius Coque
		// .html() method process all script tags contained in responseText,
314
		// to avoid this we set the innerHTML property
315
		jQuery('#updatestatus').prop('innerHTML',transport.responseText);
316 371f8c19 Scott Ullrich
	}
317 a2026525 Scott Ullrich
	setTimeout('getstatus()', 4000);
318 7a058f06 jim-p
	<?php endif; ?>
319 9c07440e Colin Fleming
//]]>
320 371f8c19 Scott Ullrich
</script>