1 # This example would hide the slightly more sensitive pool information #$hidefields = array('POOL.URL' => 1, 'POOL.User' => 1); $hidefields = array(); # # Auto-refresh of the page (in seconds) # $ignorerefresh = true/false always ignore refresh parameters # $changerefresh = true/false show buttons to change the value # $autorefresh = default value, 0 means dont auto-refresh $ignorerefresh = false; $changerefresh = true; $autorefresh = 0; # # Should we allow custom pages? # (or just completely ignore then and don't display the buttons) $allowcustompages = true; # # OK this is a bit more complex item: Custom Summary Pages # A custom summary page in an array of 'section' => array('FieldA','FieldB'...) # This makes up what is displayed with each 'section' separately as a table # - empty tables are not shown # - empty columns (an unknown field) are not shown # - and missing field data shows as blank # There is a second array, listing fields to be totaled for each section # see the example below (if there is no matching data, no total will show) $mobilepage = array( 'SUMMARY' => array('Elapsed', 'MHS av', 'Found Blocks', 'Accepted', 'Rejected', 'Utility'), 'GPU' => array('GPU', 'Status', 'MHS av', 'Accepted', 'Rejected', 'Utility'), 'PGA' => array('ID', 'Name', 'Status', 'MHS av', 'Accepted', 'Rejected', 'Utility'), 'POOL' => array('POOL', 'Status', 'Accepted', 'Rejected', 'Last Share Time')); $mobilesum = array( 'SUMMARY' => array('MHS av' => 1, 'Found Blocks' => 1, 'Accepted' => 1, 'Rejected' => 1, 'Utility' => 1), 'GPU' => array('MHS av' => 1, 'Accepted' => 1, 'Rejected' => 1, 'Utility' => 1), 'PGA' => array('MHS av' => 1, 'Accepted' => 1, 'Rejected' => 1, 'Utility' => 1), 'POOL' => array('Accepted' => 1, 'Rejected' => 1)); # # customsummarypages is an array of these Custom Summary Pages $customsummarypages = array('Mobile' => array($mobilepage, $mobilesum)); # $here = $_SERVER['PHP_SELF']; # global $tablebegin, $tableend, $warnfont, $warnoff, $dfmt; # $tablebegin = ''; $tableend = '
'; $warnfont = ''; $warnoff = ''; $dfmt = 'H:i:s j-M-Y \U\T\CP'; # global $miner_font_family, $miner_font_size; # $miner_font_family = 'verdana,arial,sans'; $miner_font_size = '13pt'; # # This below allows you to put your own settings into a seperate file # so you don't need to update miner.php with your preferred settings # every time a new version is released # Just create the file 'myminer.php' in the same directory as # 'miner.php' - and put your own settings in there if (file_exists('myminer.php')) include_once('myminer.php'); # # Ensure it is only ever shown once global $showndate; $showndate = false; # # For summary page to stop retrying failed rigs global $rigerror; $rigerror = array(); # function htmlhead($checkapi, $rig, $pg = null) { global $miner_font_family, $miner_font_size; global $error, $readonly, $here; global $ignorerefresh, $autorefresh; $extraparams = ''; if ($rig != null && $rig != '') $extraparams = "&rig=$rig"; else if ($pg != null && $pg != '') $extraparams = "&pg=$pg"; if ($ignorerefresh == true || $autorefresh == 0) $refreshmeta = ''; else { $url = "$here?ref=$autorefresh$extraparams"; $refreshmeta = "\n"; } if ($readonly === false && $checkapi === true) { $error = null; $access = api('privileged'); if ($error != null || !isset($access['STATUS']['STATUS']) || $access['STATUS']['STATUS'] != 'S') $readonly = true; } $miner_font = "font-family:$miner_font_family; font-size:$miner_font_size;"; echo "$refreshmeta Mine
$socktimeoutsec, 'usec' => 0)); $res = socket_connect($socket, $addr, $port); if ($res === false) { $haderror = true; $error = socket_strerror(socket_last_error()); $msg = "socket connect($addr,$port) failed"; $error = "ERR: $msg '$error'\n"; socket_close($socket); return null; } return $socket; } # function readsockline($socket) { $line = ''; while (true) { $byte = socket_read($socket, 1); if ($byte === false || $byte === '') break; if ($byte === "\0") break; $line .= $byte; } return $line; } # function api($cmd) { global $haderror, $error; global $miner, $port, $hidefields; $socket = getsock($miner, $port); if ($socket != null) { socket_write($socket, $cmd, strlen($cmd)); $line = readsockline($socket); socket_close($socket); if (strlen($line) == 0) { $haderror = true; $error = "WARN: '$cmd' returned nothing\n"; return $line; } # print "$cmd returned '$line'\n"; $data = array(); $objs = explode('|', $line); foreach ($objs as $obj) { if (strlen($obj) > 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'; $sectionname = preg_replace('/\d/', '', $name); 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 (isset($hidefields[$sectionname.'.'.$id[0]])) continue; 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 classlastshare($when, $alldata, $warnclass, $errorclass) { global $checklastshare; if ($checklastshare === false) return ''; if ($when == 0) return ''; if (!isset($alldata['MHS av'])) return ''; if (!isset($alldata['Last Share Time'])) return ''; $expected = pow(2, 32) / ($alldata['MHS av'] * pow(10, 6)); $howlong = $when - $alldata['Last Share Time']; if ($howlong < 1) $howlong = 1; if ($howlong > ($expected * 12)) return $errorclass; if ($howlong > ($expected * 8)) return $warnclass; return ''; } # function fmt($section, $name, $value, $when, $alldata) { global $dfmt; if ($alldata == null) $alldata = array(); $errorclass = ' class=err'; $warnclass = ' class=warn'; $lstclass = ' class=lst'; $b = ' '; $ret = $value; $class = ''; if ($value === null) $ret = $b; else switch ($section.'.'.$name) { case 'GPU.Last Share Time': case 'PGA.Last Share Time': if ($value == 0 || (isset($alldata['Last Share Pool']) && $alldata['Last Share Pool'] == -1)) { $ret = 'Never'; $class = $warnclass; } else { $ret = date('H:i:s', $value); $class = classlastshare($when, $alldata, $warnclass, $errorclass); } break; case 'POOL.Last Share Time': if ($value == 0) $ret = 'Never'; else $ret = date('H:i:s d-M', $value); break; case 'GPU.Last Share Pool': case 'PGA.Last Share Pool': if ($value == -1) { $ret = 'None'; $class = $warnclass; } 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 { if ($value == 1) $days = ''; else $days = 's'; $ret = sprintf("%dday$days$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'; if ($value == 0) $class = $warnclass; break; case 'PGA.Temperature': $ret = $value.'°C'; break; case 'GPU.Temperature': $ret = $value.'°C'; case 'GPU.GPU Clock': case 'GPU.Memory Clock': case 'GPU.GPU Voltage': case 'GPU.GPU Activity': if ($value == 0) $class = $warnclass; break; case 'GPU.Fan Percent': if ($value == 0) $class = $warnclass; else { if ($value == 100) $class = $errorclass; else if ($value > 85) $class = $warnclass; } break; case 'GPU.Fan Speed': if ($value == 0) $class = $warnclass; else if (isset($alldata['Fan Percent'])) { $test = $alldata['Fan Percent']; if ($test == 100) $class = $errorclass; else if ($test > 85) $class = $warnclass; } break; case 'GPU.MHS av': case 'PGA.MHS av': case 'SUMMARY.MHS av': case 'GPU.Total MH': case 'PGA.Total MH': case 'SUMMARY.Total MH': case 'SUMMARY.Getworks': case 'GPU.Accepted': case 'PGA.Accepted': case 'SUMMARY.Accepted': case 'GPU.Rejected': case 'PGA.Rejected': case 'SUMMARY.Rejected': case 'SUMMARY.Local Work': case 'POOL.Getworks': case 'POOL.Accepted': case 'POOL.Rejected': case 'POOL.Discarded': $parts = explode('.', $value, 2); if (count($parts) == 1) $dec = ''; else $dec = '.'.$parts[1]; $ret = number_format($parts[0]).$dec; break; case 'GPU.Status': case 'PGA.Status': case 'POOL.Status': if ($value != 'Alive') $class = $errorclass; break; case 'GPU.Enabled': case 'PGA.Enabled': if ($value != 'Y') $class = $warnclass; break; case 'STATUS.When': $ret = date($dfmt, $value); break; } if ($section == 'NOTIFY' && substr($name, 0, 1) == '*' && $value != '0') $class = $errorclass; if ($class == '' && $section != 'POOL') $class = classlastshare($when, $alldata, $lstclass, $lstclass); return array($ret, $class); } # global $poolcmd; $poolcmd = array( 'Switch to' => 'switchpool', 'Enable' => 'enablepool', 'Disable' => 'disablepool' ); # function showhead($cmd, $values, $justnames = false) { global $poolcmd, $readonly; echo ''; foreach ($values as $name => $value) { if ($name == '0' or $name == '') $name = ' '; echo ""; } if ($justnames === false && $cmd == 'pools' && $readonly === false) foreach ($poolcmd as $name => $pcmd) echo ""; echo ''; } # function details($cmd, $list, $rig) { global $tablebegin, $tableend, $dfmt; global $poolcmd, $readonly; global $showndate; $when = 0; $stas = array('S' => 'Success', 'W' => 'Warning', 'I' => 'Informational', 'E' => 'Error', 'F' => 'Fatal'); echo $tablebegin; if ($showndate === false) { echo ''; echo $tableend.$tablebegin; $showndate = true; } if (isset($list['STATUS'])) { echo ''; echo ''; if (isset($list['STATUS']['When'])) { echo ''; $when = $list['STATUS']['When']; } $sta = $list['STATUS']['STATUS']; echo ''; echo ''; echo ''; } $section = ''; foreach ($list as $item => $values) { if ($item == 'STATUS') continue; $sectionname = preg_replace('/\d/', '', $item); if ($sectionname != $section) { echo $tableend.$tablebegin; showhead($cmd, $values); $section = $sectionname; } echo ''; foreach ($values as $name => $value) { list($showvalue, $class) = fmt($section, $name, $value, $when, $values); echo "$showvalue"; } if ($cmd == 'pools' && $readonly === false) { reset($values); $pool = current($values); foreach ($poolcmd as $name => $pcmd) { echo ''; } } echo ''; } echo $tableend; } # global $devs; $devs = null; # function gpubuttons($count, $rig) { global $tablebegin, $tableend; global $devs; $basic = array( 'GPU', 'Enable', 'Disable', 'Restart' ); $options = array( 'intensity' => 'Intensity', 'fan' => 'Fan Percent', 'engine' => 'GPU Clock', 'mem' => 'Memory Clock', 'vddc' => 'GPU Voltage' ); echo $tablebegin.''; foreach ($basic as $head) echo ""; foreach ($options as $name => $des) echo ""; $n = 0; for ($c = 0; $c < $count; $c++) { echo ''; foreach ($basic as $name) { echo ''; } foreach ($options as $name => $des) { echo ''; } } echo ''.$tableend; } # function processgpus($rig) { global $error; global $warnfont, $warnoff; $gpus = api('gpucount'); if ($error != null) echo ''; else { if (!isset($gpus['GPUS']['Count'])) echo ''; else { $count = $gpus['GPUS']['Count']; if ($count == 0) echo ''; else gpubuttons($count, $rig); } } } # function process($cmds, $rig) { global $error, $devs; global $warnfont, $warnoff; foreach ($cmds as $cmd => $des) { $process = api($cmd); if ($error != null) { echo "'; break; } else { details($cmd, $process, $rig); echo ''; if ($cmd == 'devs') $devs = $process; } } } # # $head is a hack but this is just a demo anyway :) function doforeach($cmd, $des, $sum, $head, $datetime) { global $miner, $port; global $error, $readonly, $notify, $rigs; global $tablebegin, $tableend, $warnfont, $warnoff, $dfmt; global $rigerror; $when = 0; $header = $head; $anss = array(); $count = 0; $preverr = count($rigerror); foreach ($rigs as $rig) { if (isset($rigerror[$rig])) continue; $parts = explode(':', $rig, 2); if (count($parts) == 2) { $miner = $parts[0]; $port = $parts[1]; $ans = api($cmd); if ($error != null) { echo "'; $rigerror[$rig] = $error; $error = null; } else $anss[$count] = $ans; } $count++; } if (count($anss) == 0) { echo ''; return; } if ($datetime) { echo ''; echo $tableend.$tablebegin; $dthead = array('' => 1, 'STATUS' => 1, 'Description' => 1, 'When' => 1, 'API' => 1, 'CGMiner' => 1); showhead('', $dthead); foreach ($anss as $rig => $ans) { echo ''; foreach ($ans as $item => $row) { if ($item != 'STATUS' && $item != 'VERSION') continue; foreach ($dthead as $name => $x) { if ($item == 'STATUS' && $name == '') echo ""; else { if (isset($row[$name])) { list($showvalue, $class) = fmt('STATUS', $name, $row[$name], $when, null); echo "$showvalue"; } } } } echo ''; } echo $tableend; echo ''; echo $tablebegin; return; } $total = array(); foreach ($anss as $rig => $ans) { foreach ($ans as $item => $row) { if ($item == 'STATUS') continue; if (count($row) > count($header)) { $header = $head; foreach ($row as $name => $value) if (!isset($header[$name])) $header[$name] = ''; } if ($sum != null) foreach ($sum as $name) { if (isset($row[$name])) { if (isset($total[$name])) $total[$name] += $row[$name]; else $total[$name] = $row[$name]; } } } } if ($sum != null) $anss['total']['total'] = $total; showhead('', $header); $section = ''; foreach ($anss as $rig => $ans) { $when = 0; if (isset($ans['STATUS']['When'])) $when = $ans['STATUS']['When']; foreach ($ans as $item => $row) { if ($item == 'STATUS') continue; echo ''; $newsection = preg_replace('/\d/', '', $item); if ($newsection != 'total') $section = $newsection; foreach ($header as $name => $x) { if ($name == '') { if ($rig === 'total') echo ""; else echo ""; } else { if (isset($row[$name])) $value = $row[$name]; else $value = null; list($showvalue, $class) = fmt($section, $name, $value, $when, $row); if ($rig === 'total' and $class == '') $class = ' class=tot'; echo "$showvalue"; } } echo ''; } } } # function refreshbuttons() { global $readonly; global $ignorerefresh, $changerefresh, $autorefresh; if ($ignorerefresh == false && $changerefresh == true) { echo '    '; echo ""; echo ""; echo ""; } } # function pagetop($rig, $pg) { global $readonly, $rigs; global $allowcustompages, $customsummarypages; if ($rig === null) { if ($pg === null) $refresh = ''; else $refresh = "&pg=$pg"; } else $refresh = "&rig=$rig"; echo '"; } # function doOne($rig, $preprocess) { global $haderror, $readonly, $notify, $rigs; htmlhead(true, $rig); pagetop($rig, null); if ($preprocess != null) process(array($preprocess => $preprocess), $rig); $cmds = array( 'devs' => 'device list', 'summary' => 'summary information', 'pools' => 'pool list'); if ($notify) $cmds['notify'] = 'device status'; $cmds['config'] = 'cgminer config'; process($cmds, $rig); if ($haderror == false && $readonly === false) processgpus($rig); } # global $sectionmap; # map sections to their api command $sectionmap = array( 'SUMMARY' => 'summary', 'POOL' => 'pools', 'GPU' => 'devs', 'PGA' => 'devs', 'NOTIFY' => 'notify', 'CONFIG' => 'config'); # function customset($showfields, $sum, $section, $num, $result, $total) { foreach ($result as $sec => $row) { $secname = preg_replace('/\d/', '', $sec); if ($sec != 'total') { if ($secname != $section) continue; } echo ''; $when = 0; if (isset($result['STATUS']['When'])) $when = $result['STATUS']['When']; if ($sec === 'total') $class = ' class=tot'; else $class = ''; echo ""; foreach ($showfields as $name => $one) { if (isset($row[$name])) { $value = $row[$name]; if (isset($sum[$secname][$name])) { if (isset($total[$name])) $total[$name] += $value; else $total[$name] = $value; } } else { if ($sec == 'total' && isset($total[$name])) $value = $total[$name]; else $value = null; } list($showvalue, $class) = fmt($section, $name, $value, $when, $row); if ($sec === 'total' and $class == '') $class = ' class=tot'; echo "$showvalue"; } echo ''; } return $total; } # function processcustompage($pagename, $sections, $sum) { global $sectionmap; global $miner, $port; global $rigs, $error; global $warnfont, $warnoff; global $tablebegin, $tableend, $dfmt; global $readonly, $showndate; $cmds = array(); $errors = array(); foreach ($sections as $section => $fields) { if (isset($sectionmap[$section])) { $cmd = $sectionmap[$section]; if (!isset($cmds[$cmd])) $cmds[$cmd] = 1; } else $errors[] = "Error: unknown section '$section' in custom summary page '$pagename'"; } $results = array(); foreach ($rigs as $num => $rig) { $parts = explode(':', $rig, 2); if (count($parts) == 2) { $miner = $parts[0]; $port = $parts[1]; foreach ($cmds as $cmd => $one) { $process = api($cmd); if ($error != null) { $errors[] = "Error getting $cmd for $rig $warnfont$error$warnoff"; break; } else $results[$cmd][$num] = $process; } } } if (count($results) > 0) { $first = true; foreach ($sections as $section => $fields) { if (isset($results[$sectionmap[$section]])) { $rigresults = $results[$sectionmap[$section]]; $showfields = array(); foreach ($fields as $field) foreach ($rigresults as $result) foreach ($result as $sec => $row) { $secname = preg_replace('/\d/', '', $sec); if ($secname == $section && isset($row[$field])) $showfields[$field] = 1; } if (count($showfields) > 0) { if ($first === false) echo ''; echo $tablebegin; showhead('', array('Rig'=>1)+$showfields, true); $total = array(); $add = array('total' => array()); foreach ($rigresults as $num => $result) { $rg = ""; $total = customset($showfields, $sum, $section, $rg, $result, $total); } if (count($total) > 0) customset($showfields, $sum, $section, 'Σ', $add, $total); $first = false; echo $tableend; } } } } if (count($errors) > 0) { if (count($results) > 0) echo ''; foreach ($errors as $err) echo ""; } } # function showcustompage($pagename) { global $customsummarypages; htmlhead(false, null, $pagename); pagetop(null, $pagename); if (!isset($customsummarypages[$pagename])) { echo ""; return; } if (count($customsummarypages[$pagename]) != 2) { echo ""; return; } $page = $customsummarypages[$pagename][0]; $sum = $customsummarypages[$pagename][1]; if ($sum === null) $sum = array(); if (count($page) <= 1) { echo ""; return; } processcustompage($pagename, $page, $sum); } # function display() { global $tablebegin, $tableend; global $miner, $port; global $readonly, $notify, $rigs; global $ignorerefresh, $autorefresh; global $allowcustompages; if ($ignorerefresh == false) { $ref = trim(getparam('ref', true)); if ($ref != null && $ref != '') $autorefresh = intval($ref); } $rig = trim(getparam('rig', true)); $arg = trim(getparam('arg', true)); $preprocess = null; if ($arg != null and $arg != '') { $num = null; if ($rig != null and $rig != '') { if ($rig >= 0 and $rig < count($rigs)) $num = $rig; } else if (count($rigs) == 0) $num = 0; if ($num != null) { $parts = explode(':', $rigs[$num], 2); if (count($parts) == 2) { $miner = $parts[0]; $port = $parts[1]; $preprocess = $arg; } } } if ($rigs == null or count($rigs) == 0) { echo ""; return; } if ($allowcustompages === true) { $pg = trim(getparam('pg', true)); if ($pg != null && $pg != '') { showcustompage($pg); return; } } if (count($rigs) == 1) { $parts = explode(':', $rigs[0], 2); if (count($parts) == 2) { $miner = $parts[0]; $port = $parts[1]; doOne(0, $preprocess); } else echo ''; return; } if ($rig != null and $rig != '' and $rig >= 0 and $rig < count($rigs)) { $parts = explode(':', $rigs[$rig], 2); if (count($parts) == 2) { $miner = $parts[0]; $port = $parts[1]; doOne($rig, $preprocess); } else echo ''; return; } htmlhead(false, null); pagetop(null, null); if ($preprocess != null) process(array($preprocess => $preprocess), $rig); echo $tablebegin; doforeach('version', 'rig summary', array(), array(), true); $sum = array('MHS av', 'Getworks', 'Found Blocks', 'Accepted', 'Rejected', 'Discarded', 'Stale', 'Utility', 'Local Work', 'Total MH'); doforeach('summary', 'summary information', $sum, array(), false); echo $tableend; echo ''; echo $tablebegin; doforeach('devs', 'device list', $sum, array(''=>'','ID'=>'','Name'=>''), false); echo $tableend; echo ''; echo $tablebegin; doforeach('pools', 'pool list', $sum, array(''=>''), false); echo $tableend; } # display(); # ?>
$name$name
Date: '.date($dfmt).'
Computer: '.$list['STATUS']['Description'].'When: '.date($dfmt, $list['STATUS']['When']).'Status: '.$stas[$sta].'Message: '.$list['STATUS']['Msg'].'
'; if ($pool === false) echo ' '; else { echo ""; } echo '
$head$des
'; if ($name == 'GPU') echo $c; else { echo ""; } echo ''; if (!isset($devs["GPU$c"][$des])) echo ' '; else { $value = $devs["GPU$c"][$des]; echo ""; echo ""; $n++; } echo '
Error getting GPU count: '.$warnfont.$error.$warnoff.'
No GPU count returned: '.$warnfont.$gpus['STATUS']['STATUS'].' '.$gpus['STATUS']['Msg'].$ro.'
No GPUs
Error getting $des: "; echo $warnfont.$error.$warnoff.'


Error on rig $count getting $des: "; echo $warnfont.$error.$warnoff.'
Failed to access any rigs successfully'; if ($preverr > 0) echo ' (or rigs had previous errors)'; echo '
Date: '.date($dfmt).'


Total:
'; echo " "; if (count($rigs) > 1) echo " "; if ($allowcustompages === true) foreach ($customsummarypages as $pagename => $data) echo " "; echo ' '; if ($rig !== null && $readonly === false) { $rg = ''; if (count($rigs) > 1) $rg = " Rig $rig"; echo ""; echo " "; } refreshbuttons(); echo "
$num
 
 
$err
Unknown custom summary page '$pagename'
Invalid custom summary page '$pagename' (".count($customsummarypages[$pagename]).")
Invalid custom summary page '$pagename' no content
No rigs defined
Invalid "$rigs" array
Invalid "$rigs" array