<?PHP
/* Copyright 2012, Bergware International & Andrew Hamer-Adams.
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 */
?>
<?
ini_set('display_errors',0);
error_reporting(E_ALL|E_STRICT);
$var = parse_ini_file("/var/local/emhttp/var.ini");
?>

<link type="text/css" rel="stylesheet" href="/plugins/webGui/style/template.css">

<script>
// server uptime & update period
var uptime = <?=strtok(exec("cat /proc/uptime"),' ')?>;
var period = 1; //seconds

function add(value, label, last) {
  return parseInt(value)+' '+label+(parseInt(value)!=1?'s':'')+(!last?', ':'');
}
function updateTime() {
  document.getElementById('uptime').innerHTML = add(uptime/86400,'day')+add(uptime/3600%24,'hr')+add(uptime/60%60,'min')+add(uptime%60,'sec',true);;
  uptime += period;
  setTimeout('updateTime()', period*1000);
}
</script>

<body onLoad="updateTime();" style="margin-bottom: 0; margin-top: 20px;">
<center>
<img src="/plugins/webGui/images/logo.png" alt="unRAID" width="169" height="28" border="0" /><br>
<span style="font-size:16px;color:#6FA239;font-weight:bold">unRAID Server <?=$var['regTy']?></span><br>
</center>
<div style="margin-top:14px;font-size:12px;line-height:30px;color:#333; margin-left: 40px;">

<div style="margin-top:20px;"><span style="width:80px;display:inline-block"><strong>System:</strong></span>
<?
$motherboard = exec("dmidecode -q -t 2 | grep 'Manufacturer' | cut -f2 -d: | cut -f2 -d' '");
$product = exec("dmidecode -q -t 2 | grep 'Product Name' | cut -f2 -d: | cut -f2 -d' '");
echo "$motherboard - $product";
?>
</div>
<div class="clear:both;"></div>
<div><span style="width: 80px; display: inline-block"><strong>CPU:</strong></span>
<?
function write($number) {
  $words = array('zero','one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen','twenty');
  return $number<=count($words) ? $words[$number] : $number;
}

$cpumodel = exec("dmidecode -q -t 4 | grep 'Version' | cut -f2- -d' '");
$cpumodel = str_replace("(R)", "<sup>&reg;</sup>", str_ireplace("(tm)", "<sup>TM</sup>", str_replace("Processor", "", $cpumodel)));
$cpuspeed = exec("dmidecode -q -t 4 | grep 'Current' | cut -f3- -d' '");
$cpuspeed = explode(' ',$cpuspeed);
if ($cpuspeed[0]>=1000 && $cpuspeed[1]=='MHz'):
  $cpuspeed[0] /= 1000;
  $cpuspeed[1] = 'GHz';
endif;
echo "$cpumodel - $cpuspeed[0] $cpuspeed[1]";
?>
</div>
<div class="clear:both;"></div>
<div><span style="width: 80px; display: inline-block"><strong>Cache:</strong></span>
<?
$cachememory = exec("dmidecode -q -t 7 | grep 'Installed Size' -m 1 | cut -f2 -d:");
echo $cachememory;
?>
</div>
<div class="clear:both;"></div>
<div><span style="width: 80px; display: inline-block"><strong>Memory:</strong></span>
<?
$memorytotal = exec("dmidecode -q -t 19 | grep 'Range Size' | cut -f2 -d:");
$memoryspeed = exec("dmidecode -q -t 17 | grep 'Speed' -m 1 | cut -f2 -d:");
echo "$memorytotal - $memoryspeed";
?>
</div>
<div class="clear:both;"></div>
<div><span style="width: 80px; display: inline-block"><strong>Network:</strong></span>
<?
$port = exec("ifconfig -s | grep eth | cut -f1 -d ' '");
if ($port!=""):
  $networkspeed = exec("ethtool $port | grep 'Speed' | cut -f2 -d:");
  $networkduplex = exec("ethtool $port | grep 'Duplex' | cut -f2 -d:");
  echo "$networkspeed - $networkduplex Duplex";
else:
  echo "Not available";
endif;
?>
</div>
<div class="clear:both;"></div>
<div><span style="width: 80px; display: inline-block"><strong>Connections:</strong></span>
<?
$AFPUsers = 0;
$SMBUsers = 0;
if ($var['shareAFPEnabled']=="yes") {
  $AFPUsers = exec("ps anucx | grep -c 'afpd'");
  if ($AFPUsers > 0) $AFPUsers--;
}
if ($var['shareSMBEnabled']=="yes") {
  $SMBUsers = exec("smbstatus -p | awk 'NR>4' | wc -l");
}
echo ucfirst(write($AFPUsers+$SMBUsers));
?>
</div>
<div class="clear:both;"></div>
<div><span style="width:80px;display:inline-block"><strong>Uptime:</strong></span><span id="uptime"></span></div>
<br>
<div class="clear:both;"></div>
</div>
<center>
<?if (is_file("/etc/simpleFeatures-system-info")):?>
<a href="/Utils/SystemProfiler" class="button" target="_parent">More Info</a>
<?else:?>
<button type="button" onclick="window.parent.Shadowbox.close()">Close
<?endif;?>
</center>
</body>