0)
{
$items = explode(',', $obj);
$item = $items[0];
$id = explode('=', $items[0], 2);
if (count($id) == 1 or !ctype_digit($id[1]))
$name = $id[0];
else
$name = $id[0].$id[1];
if (strlen($name) == 0)
$name = 'null';
if (isset($data[$name]))
{
$num = 1;
while (isset($data[$name.$num]))
$num++;
$name .= $num;
}
$counter = 0;
foreach ($items as $item)
{
$id = explode('=', $item, 2);
if (count($id) == 2)
$data[$name][$id[0]] = $id[1];
else
$data[$name][$counter] = $id[0];
$counter++;
}
}
}
return $data;
}
return null;
}
#
function getparam($name, $both = false)
{
$a = null;
if (isset($_POST[$name]))
$a = $_POST[$name];
if (($both === true) and ($a === null))
{
if (isset($_GET[$name]))
$a = $_GET[$name];
}
if ($a == '' || $a == null)
return null;
// limit to 1K just to be safe
return substr($a, 0, 1024);
}
#
function fmt($section, $name, $value)
{
$errorclass = ' class=err';
$warnclass = ' class=warn';
$b = ' ';
$ret = $value;
$class = '';
switch ($section.'.'.$name)
{
case 'GPU.Last Share Time':
case 'PGA.Last Share Time':
$ret = date('H:i:s', $value);
break;
case 'SUMMARY.Elapsed':
$s = $value % 60;
$value -= $s;
$value /= 60;
if ($value == 0)
$ret = $s.'s';
else
{
$m = $value % 60;
$value -= $m;
$value /= 60;
if ($value == 0)
$ret = sprintf("%dm$b%02ds", $m, $s);
else
{
$h = $value % 24;
$value -= $h;
$value /= 24;
if ($value == 0)
$ret = sprintf("%dh$b%02dm$b%02ds", $h, $m, $s);
else
$ret = sprintf("%ddays$b%02dh$b%02dm$b%02ds", $value, $h, $m, $s);
}
}
break;
case 'NOTIFY.Last Well':
if ($value == '0')
{
$ret = 'Never';
$class = $warnclass;
}
else
$ret = date('H:i:s', $value);
break;
case 'NOTIFY.Last Not Well':
if ($value == '0')
$ret = 'Never';
else
{
$ret = date('H:i:s', $value);
$class = $errorclass;
}
break;
case 'NOTIFY.Reason Not Well':
if ($value != 'None')
$class = $errorclass;
break;
case 'GPU.Utility':
case 'PGA.Utility':
case 'SUMMARY.Utility':
$ret = $value.'/m';
break;
case 'GPU.Temperature':
case 'PGA.Temperature':
$ret = $value.'°C';
break;
}
if ($section == 'NOTIFY' && substr($name, 0, 1) == '*' && $value != '0')
$class = $errorclass;
return array($ret, $class);
}
#
global $poolcmd;
$poolcmd = array( 'Switch to' => 'switchpool',
'Enable' => 'enablepool',
'Disable' => 'disablepool' );
#
function showhead($cmd, $item, $values)
{
global $poolcmd, $readonly;
echo '';
foreach ($values as $name => $value)
{
if ($name == '0')
$name = ' ';
echo "$name | ";
}
if ($cmd == 'pools' && $readonly === false)
foreach ($poolcmd as $name => $pcmd)
echo "$name | ";
echo ' ';
}
#
function details($cmd, $list)
{
global $poolcmd, $readonly;
$dfmt = 'H:i:s j-M-Y \U\T\CP';
$stas = array('S' => 'Success', 'W' => 'Warning', 'I' => 'Informational', 'E' => 'Error', 'F' => 'Fatal');
$tb = ' | ';
echo $tb;
echo 'Date: '.date($dfmt).' | ';
echo $te.$tb;
if (isset($list['STATUS']))
{
echo '';
echo 'Computer: '.$list['STATUS']['Description'].' | ';
if (isset($list['STATUS']['When']))
echo 'When: '.date($dfmt, $list['STATUS']['When']).' | ';
$sta = $list['STATUS']['STATUS'];
echo 'Status: '.$stas[$sta].' | ';
echo 'Message: '.$list['STATUS']['Msg'].' | ';
echo ' ';
}
$section = '';
foreach ($list as $item => $values)
{
if ($item == 'STATUS')
continue;
$sectionname = preg_replace('/\d/', '', $item);
if ($sectionname != $section)
{
echo $te.$tb;
showhead($cmd, $item, $values);
$section = $sectionname;
}
echo '';
foreach ($values as $name => $value)
{
list($showvalue, $class) = fmt($section, $name, $value);
echo "$showvalue | ";
}
if ($cmd == 'pools' && $readonly === false)
{
reset($values);
$pool = current($values);
foreach ($poolcmd as $name => $pcmd)
{
echo '';
if ($pool === false)
echo ' ';
else
{
echo "";
}
echo ' | ';
}
}
echo ' ';
}
echo $te;
}
#
global $devs;
$devs = null;
#
function gpubuttons($count)
{
global $devs;
$basic = array( 'GPU', 'Enable', 'Disable', 'Restart' );
$options = array( 'intensity' => 'Intensity',
'fan' => 'Fan Percent',
'engine' => 'GPU Clock',
'mem' => 'Memory Clock',
'vddc' => 'GPU Voltage' );
$tb = ' | ';
echo $tb.'';
foreach ($basic as $head)
echo "$head | ";
foreach ($options as $name => $des)
echo "$des | ";
$n = 0;
for ($c = 0; $c < $count; $c++)
{
echo ' ';
foreach ($basic as $name)
{
echo '';
if ($name == 'GPU')
echo $c;
else
{
echo "";
}
echo ' | ';
}
foreach ($options as $name => $des)
{
echo '';
if (!isset($devs["GPU$c"][$des]))
echo ' ';
else
{
$value = $devs["GPU$c"][$des];
echo "";
echo "";
$n++;
}
echo ' | ';
}
}
echo ' '.$te;
}
#
function processgpus($rd, $ro)
{
global $error;
$gpus = api('gpucount');
if ($error != null)
echo 'Error getting GPU count: '.$rd.$error.$ro.' | ';
else
{
if (!isset($gpus['GPUS']['Count']))
echo 'No GPU count returned: '.$rd.$gpus['STATUS']['STATUS'].' '.$gpus['STATUS']['Msg'].$ro.' | ';
else
{
$count = $gpus['GPUS']['Count'];
if ($count == 0)
echo 'No GPUs | ';
else
gpubuttons($count);
}
}
}
#
function process($cmds, $rd, $ro)
{
global $error, $devs;
foreach ($cmds as $cmd => $des)
{
$process = api($cmd);
if ($error != null)
{
echo "Error getting $des: ";
echo $rd.$error.$ro.' | ';
break;
}
else
{
details($cmd, $process);
echo '
| ';
if ($cmd == 'devs')
$devs = $process;
}
}
}
#
function display()
{
global $error, $readonly, $notify;
$error = null;
$rd = '';
$ro = '';
echo " | ";
$arg = trim(getparam('arg', true));
if ($arg != null and $arg != '')
process(array($arg => $arg), $rd, $ro);
$cmds = array( 'devs' => 'device list',
'summary' => 'summary information',
'pools' => 'pool list');
if ($notify)
$cmds['notify'] = 'device status';
$cmds['config'] = 'cgminer config';
process($cmds, $rd, $ro);
if ($error == null && $readonly === false)
processgpus($rd, $ro);
}
#
htmlhead();
display();
#
?>
|