| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475 |
- <?php
- session_start();
- #
- global $miner, $port, $readonly, $notify, $rigs, $socktimeoutsec;
- global $checklastshare, $hidefields;
- global $ignorerefresh, $changerefresh, $autorefresh;
- global $allowcustompages, $customsummarypages;
- global $miner_font_family, $miner_font_size;
- global $colouroverride, $placebuttons;
- #
- # Don't touch these 2 - see $rigs below
- $miner = null;
- $port = null;
- #
- # Set $readonly to true to force miner.php to be readonly
- # Set $readonly to false then it will check cgminer 'privileged'
- $readonly = false;
- #
- # Set $notify to false to NOT attempt to display the notify command
- # Set $notify to true to attempt to display the notify command
- # If your older version of cgminer returns an 'Invalid command'
- # coz it doesn't have notify - it just shows the error status table
- $notify = true;
- #
- # set $checklastshare to true to do the following checks:
- # If a device's last share is 12x expected ago then display as an error
- # If a device's last share is 8x expected ago then display as a warning
- # If either of the above is true, also display the whole line highlighted
- # This assumes shares are 1 difficulty shares
- $checklastshare = true;
- #
- # Set $rigs to an array of your cgminer rigs that are running
- # format: 'IP:Port' or 'Host:Port'
- # If you only have one rig, it will just show the detail of that rig
- # If you have more than one rig it will show a summary of all the rigs
- # with buttons to show the details of each rig
- # e.g. $rigs = array('127.0.0.1:4028','myrig.com:4028');
- $rigs = array('127.0.0.1:4028');
- #
- # This should be OK for most cases
- # However, the longer it is the longer you have to wait while php
- # hangs if the target cgminer isn't runnning or listening
- # Feel free to increase it if your network is very slow
- # Also, on some windows PHP, apparently the $usec is ignored
- $socktimeoutsec = 10;
- #
- # List of fields NOT to be displayed
- # You can use this to hide data you don't want to see or don't want
- # shown on a public web page
- # The list of sections are: SUMMARY, POOL, PGA, GPU, NOTIFY, CONFIG
- # See the web page for the list of field names (the table headers)
- # It is an array of 'SECTION.Field Name' => 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 = '<tr><td><table border=1 cellpadding=5 cellspacing=0>';
- $tableend = '</table></td></tr>';
- $warnfont = '<font color=red><b>';
- $warnoff = '</b></font>';
- $dfmt = 'H:i:s j-M-Y \U\T\CP';
- #
- $miner_font_family = 'verdana,arial,sans';
- $miner_font_size = '13pt';
- #
- # Edit this or redefine it in myminer.php to change the colour scheme
- # See $colourtable below for the list of names
- $colouroverride = array();
- #
- # Where to place the buttons: 'top' 'bot' 'both'
- # anything else means don't show them - case sensitive
- $placebuttons = 'top';
- #
- # 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');
- #
- # This is the system default that must always contain all necessary
- # colours so it must be a constant
- # You can override these values with $colouroverride
- # The only one missing is in $warnfont
- # - which you can override directly anyway
- global $colourtable;
- $colourtable = array(
- 'body bgcolor' => '#ecffff',
- 'td color' => 'blue',
- 'td.h color' => 'blue',
- 'td.h background' => '#c4ffff',
- 'td.err color' => 'black',
- 'td.err background' => '#ff3050',
- 'td.warn color' => 'black',
- 'td.warn background' => '#ffb050',
- 'td.sta color' => 'green',
- 'td.tot color' => 'blue',
- 'td.tot background' => '#fff8f2',
- 'td.lst color' => 'blue',
- 'td.lst background' => '#ffffdd',
- 'td.hi color' => 'blue',
- 'td.hi background' => '#f6ffff',
- 'td.lo color' => 'blue',
- 'td.lo background' => '#deffff'
- );
- #
- # Ensure it is only ever shown once
- global $showndate;
- $showndate = false;
- #
- # For summary page to stop retrying failed rigs
- global $rigerror;
- $rigerror = array();
- #
- function getcss($cssname, $dom = false)
- {
- global $colourtable, $colouroverride;
- $css = '';
- foreach ($colourtable as $cssdata => $colour)
- {
- $cssobj = split(' ', $cssdata, 2);
- if ($cssobj[0] == $cssname)
- {
- if (isset($colouroverride[$cssdata]))
- $color = $colouroverride[$cssdata];
- if ($dom == true)
- $css .= ' '.$cssobj[1].'='.$colour;
- else
- $css .= $cssobj[1].':'.$colour.'; ';
- }
- }
- return $css;
- }
- #
- 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<meta http-equiv='refresh' content='$autorefresh;url=$url'>";
- }
- 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 "<html><head>$refreshmeta
- <title>Mine</title>
- <style type='text/css'>
- td { $miner_font ".getcss('td')."}
- td.h { $miner_font ".getcss('td.h')."}
- td.err { $miner_font ".getcss('td.err')."}
- td.warn { $miner_font ".getcss('td.warn')."}
- td.sta { $miner_font ".getcss('td.sta')."}
- td.tot { $miner_font ".getcss('td.tot')."}
- td.lst { $miner_font ".getcss('td.lst')."}
- td.hi { $miner_font ".getcss('td.hi')."}
- td.lo { $miner_font ".getcss('td.lo')."}
- </style>
- </head><body".getcss('body',true).">
- <script type='text/javascript'>
- function pr(a,m){if(m!=null){if(!confirm(m+'?'))return}window.location='$here?ref=$autorefresh'+a}\n";
- if ($ignorerefresh == false)
- echo "function prr(a){if(a){v=document.getElementById('refval').value}else{v=0}window.location='$here?ref='+v+'$extraparams'}\n";
- if ($readonly === false && $checkapi === true)
- {
- echo "function prc(a,m){pr('&arg='+a,m)}
- function prs(a,r){var c=a.substr(3);var z=c.split('|',2);var m=z[0].substr(0,1).toUpperCase()+z[0].substr(1)+' GPU '+z[1];prc(a+'&rig='+r,m)}
- function prs2(a,n,r){var v=document.getElementById('gi'+n).value;var c=a.substr(3);var z=c.split('|',2);var m='Set GPU '+z[1]+' '+z[0].substr(0,1).toUpperCase()+z[0].substr(1)+' to '+v;prc(a+','+v+'&rig='+r,m)}\n";
- }
- ?>
- </script>
- <table width=100% height=100% border=0 cellpadding=0 cellspacing=0 summary='Mine'>
- <tr><td align=center valign=top>
- <table border=0 cellpadding=4 cellspacing=0 summary='Mine'>
- <?php
- }
- #
- global $haderror, $error;
- $haderror = false;
- $error = null;
- #
- function getsock($addr, $port)
- {
- global $haderror, $error, $socktimeoutsec;
- $error = null;
- $socket = null;
- $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
- if ($socket === false || $socket === null)
- {
- $haderror = true;
- $error = socket_strerror(socket_last_error());
- $msg = "socket create(TCP) failed";
- $error = "ERR: $msg '$error'\n";
- return null;
- }
- // Ignore if this fails since the socket connect may work anyway
- // and nothing is gained by aborting if the option cannot be set
- // since we don't know in advance if it can connect
- socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, array('sec' => $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';
- $hiclass = ' class=hi';
- $loclass = ' class=lo';
- $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 = $errorclass;
- else
- if (isset($alldata['MHS av']))
- {
- $expected = 60 * $alldata['MHS av'] * (pow(10, 6) / pow(2, 32));
- if ($expected == 0)
- $expected = 0.000001; // 1 H/s
- $ratio = $value / $expected;
- if ($ratio < 0.9)
- $class = $loclass;
- else
- if ($ratio > 1.1)
- $class = $hiclass;
- }
- 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':
- $parts = explode('.', $value, 2);
- if (count($parts) == 1)
- $dec = '';
- else
- $dec = '.'.$parts[1];
- $ret = number_format($parts[0]).$dec;
- if ($value == 0)
- $class = $errorclass;
- else
- if (isset($alldata['Utility']))
- {
- $expected = 60 * $value * (pow(10, 6) / pow(2, 32));
- $utility = $alldata['Utility'];
- $ratio = $utility / $expected;
- if ($ratio < 0.9)
- $class = $hiclass;
- else
- if ($ratio > 1.1)
- $class = $loclass;
- }
- break;
- 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 '<tr>';
- foreach ($values as $name => $value)
- {
- if ($name == '0' or $name == '')
- $name = ' ';
- echo "<td valign=bottom class=h>$name</td>";
- }
- if ($justnames === false && $cmd == 'pools' && $readonly === false)
- foreach ($poolcmd as $name => $pcmd)
- echo "<td valign=bottom class=h>$name</td>";
- echo '</tr>';
- }
- #
- 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 '<tr><td class=sta>Date: '.date($dfmt).'</td></tr>';
- echo $tableend.$tablebegin;
- $showndate = true;
- }
- if (isset($list['STATUS']))
- {
- echo '<tr>';
- echo '<td>Computer: '.$list['STATUS']['Description'].'</td>';
- if (isset($list['STATUS']['When']))
- {
- echo '<td>When: '.date($dfmt, $list['STATUS']['When']).'</td>';
- $when = $list['STATUS']['When'];
- }
- $sta = $list['STATUS']['STATUS'];
- echo '<td>Status: '.$stas[$sta].'</td>';
- echo '<td>Message: '.$list['STATUS']['Msg'].'</td>';
- echo '</tr>';
- }
- $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 '<tr>';
- foreach ($values as $name => $value)
- {
- list($showvalue, $class) = fmt($section, $name, $value, $when, $values);
- echo "<td$class>$showvalue</td>";
- }
- if ($cmd == 'pools' && $readonly === false)
- {
- reset($values);
- $pool = current($values);
- foreach ($poolcmd as $name => $pcmd)
- {
- echo '<td>';
- if ($pool === false)
- echo ' ';
- else
- {
- echo "<input type=button value='Pool $pool'";
- echo " onclick='prc(\"$pcmd|$pool&rig=$rig\",\"$name Pool $pool\")'>";
- }
- echo '</td>';
- }
- }
- echo '</tr>';
- }
- 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.'<tr>';
- foreach ($basic as $head)
- echo "<td>$head</td>";
- foreach ($options as $name => $des)
- echo "<td nowrap>$des</td>";
- $n = 0;
- for ($c = 0; $c < $count; $c++)
- {
- echo '</tr><tr>';
- foreach ($basic as $name)
- {
- echo '<td>';
- if ($name == 'GPU')
- echo $c;
- else
- {
- echo "<input type=button value='$name $c' onclick='prs(\"gpu";
- echo strtolower($name);
- echo "|$c\",$rig)'>";
- }
- echo '</td>';
- }
- foreach ($options as $name => $des)
- {
- echo '<td>';
- if (!isset($devs["GPU$c"][$des]))
- echo ' ';
- else
- {
- $value = $devs["GPU$c"][$des];
- echo "<input type=button value='Set $c:' onclick='prs2(\"gpu$name|$c\",$n,$rig)'>";
- echo "<input size=7 type=text name=gi$n value='$value' id=gi$n>";
- $n++;
- }
- echo '</td>';
- }
- }
- echo '</tr>'.$tableend;
- }
- #
- function processgpus($rig)
- {
- global $error;
- global $warnfont, $warnoff;
- $gpus = api('gpucount');
- if ($error != null)
- echo '<tr><td>Error getting GPU count: '.$warnfont.$error.$warnoff.'</td></tr>';
- else
- {
- if (!isset($gpus['GPUS']['Count']))
- echo '<tr><td>No GPU count returned: '.$warnfont.$gpus['STATUS']['STATUS'].' '.$gpus['STATUS']['Msg'].$ro.'</td></tr>';
- else
- {
- $count = $gpus['GPUS']['Count'];
- if ($count == 0)
- echo '<tr><td>No GPUs</td></tr>';
- else
- gpubuttons($count, $rig);
- }
- }
- }
- #
- function process($cmds, $rig)
- {
- global $error, $devs;
- global $warnfont, $warnoff;
- $count = count($cmds);
- foreach ($cmds as $cmd => $des)
- {
- $process = api($cmd);
- if ($error != null)
- {
- echo "<tr><td colspan=100>Error getting $des: ";
- echo $warnfont.$error.$warnoff.'</td></tr>';
- break;
- }
- else
- {
- details($cmd, $process, $rig);
- # Not after the last one
- if (--$count > 0)
- echo '<tr><td><br><br></td></tr>';
- 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 "<tr><td colspan=100>Error on rig $count getting $des: ";
- echo $warnfont.$error.$warnoff.'</td></tr>';
- $rigerror[$rig] = $error;
- $error = null;
- }
- else
- $anss[$count] = $ans;
- }
- $count++;
- }
- if (count($anss) == 0)
- {
- echo '<tr><td>Failed to access any rigs successfully';
- if ($preverr > 0)
- echo ' (or rigs had previous errors)';
- echo '</td></tr>';
- return;
- }
- if ($datetime)
- {
- echo '<tr><td class=sta>Date: '.date($dfmt).'</td></tr>';
- echo $tableend.$tablebegin;
- $dthead = array('' => 1, 'STATUS' => 1, 'Description' => 1, 'When' => 1, 'API' => 1, 'CGMiner' => 1);
- showhead('', $dthead);
- foreach ($anss as $rig => $ans)
- {
- echo '<tr>';
- foreach ($ans as $item => $row)
- {
- if ($item != 'STATUS' && $item != 'VERSION')
- continue;
- foreach ($dthead as $name => $x)
- {
- if ($item == 'STATUS' && $name == '')
- echo "<td align=right><input type=button value='Rig $rig' onclick='pr(\"&rig=$rig\",null)'></td>";
- else
- {
- if (isset($row[$name]))
- {
- list($showvalue, $class) = fmt('STATUS', $name, $row[$name], $when, null);
- echo "<td$class align=right>$showvalue</td>";
- }
- }
- }
- }
- echo '</tr>';
- }
- echo $tableend;
- echo '<tr><td><br><br></td></tr>';
- 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 '<tr>';
- $newsection = preg_replace('/\d/', '', $item);
- if ($newsection != 'total')
- $section = $newsection;
- foreach ($header as $name => $x)
- {
- if ($name == '')
- {
- if ($rig === 'total')
- echo "<td align=right class=tot>Total:</td>";
- else
- echo "<td align=right><input type=button value='Rig $rig' onclick='pr(\"&rig=$rig\",null)'></td>";
- }
- 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 "<td$class align=right>$showvalue</td>";
- }
- }
- echo '</tr>';
- }
- }
- }
- #
- function refreshbuttons()
- {
- global $readonly;
- global $ignorerefresh, $changerefresh, $autorefresh;
- if ($ignorerefresh == false && $changerefresh == true)
- {
- echo ' ';
- echo "<input type=button value='Auto Refresh:' onclick='prr(true)'>";
- echo "<input type=text name='refval' id='refval' size=2 value='$autorefresh'>";
- echo "<input type=button value='Off' onclick='prr(false)'>";
- }
- }
- #
- function pagebuttons($rig, $pg)
- {
- global $readonly, $rigs;
- global $allowcustompages, $customsummarypages;
- if ($rig === null)
- {
- if ($pg === null)
- $refresh = '';
- else
- $refresh = "&pg=$pg";
- }
- else
- $refresh = "&rig=$rig";
- echo '<tr><td><table cellpadding=0 cellspacing=0 border=0><tr><td nowrap>';
- echo "<input type=button value='Refresh' onclick='pr(\"$refresh\",null)'> ";
- if (count($rigs) > 1)
- echo "<input type=button value='Summary' onclick='pr(\"\",null)'> ";
- if ($allowcustompages === true)
- foreach ($customsummarypages as $pagename => $data)
- echo "<input type=button value='$pagename' onclick='pr(\"&pg=$pagename\",null)'> ";
- echo '</td><td width=100%> </td><td nowrap>';
- if ($rig !== null && $readonly === false)
- {
- $rg = '';
- if (count($rigs) > 1)
- $rg = " Rig $rig";
- echo "<input type=button value='Restart' onclick='prc(\"restart&rig=$rig\",\"Restart CGMiner$rg\")'>";
- echo " <input type=button value='Quit' onclick='prc(\"quit&rig=$rig\",\"Quit CGMiner$rg\")'>";
- }
- refreshbuttons();
- echo "</td></tr></table></td></tr>";
- }
- #
- function doOne($rig, $preprocess)
- {
- global $haderror, $readonly, $notify, $rigs;
- global $placebuttons;
- htmlhead(true, $rig);
- if ($placebuttons == 'top' || $placebuttons == 'both')
- pagebuttons($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);
- if ($placebuttons == 'bot' || $placebuttons == 'both')
- pagebuttons($rig, null);
- }
- #
- 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 '<tr>';
- $when = 0;
- if (isset($result['STATUS']['When']))
- $when = $result['STATUS']['When'];
- if ($sec === 'total')
- $class = ' class=tot';
- else
- $class = '';
- echo "<td align=middle$class>$num</td>";
- 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 "<td$class align=right>$showvalue</td>";
- }
- echo '</tr>';
- }
- 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 '<tr><td> </td></tr>';
- echo $tablebegin;
- showhead('', array('Rig'=>1)+$showfields, true);
- $total = array();
- $add = array('total' => array());
- foreach ($rigresults as $num => $result)
- {
- $rg = "<input type=button value='$num' onclick='pr(\"&rig=$num\",null)'>";
- $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 '<tr><td> </td></tr>';
- foreach ($errors as $err)
- echo "<tr><td colspan=100>$err</td></tr>";
- }
- }
- #
- function showcustompage($pagename)
- {
- global $customsummarypages;
- global $placebuttons;
- htmlhead(false, null, $pagename);
- if ($placebuttons == 'top' || $placebuttons == 'both')
- pagebuttons(null, $pagename);
- if (!isset($customsummarypages[$pagename]))
- {
- echo "<tr><td colspan=100>Unknown custom summary page '$pagename'</td></tr>";
- return;
- }
- if (count($customsummarypages[$pagename]) != 2)
- {
- echo "<tr><td colspan=100>Invalid custom summary page '$pagename' (".count($customsummarypages[$pagename]).")</td></tr>";
- return;
- }
- $page = $customsummarypages[$pagename][0];
- $sum = $customsummarypages[$pagename][1];
- if ($sum === null)
- $sum = array();
- if (count($page) <= 1)
- {
- echo "<tr><td colspan=100>Invalid custom summary page '$pagename' no content </td></tr>";
- return;
- }
- processcustompage($pagename, $page, $sum);
- if ($placebuttons == 'bot' || $placebuttons == 'both')
- pagebuttons(null, $pagename);
- }
- #
- function display()
- {
- global $tablebegin, $tableend;
- global $miner, $port;
- global $readonly, $notify, $rigs;
- global $ignorerefresh, $autorefresh;
- global $allowcustompages;
- global $placebuttons;
- 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 "<tr><td>No rigs defined</td></tr>";
- 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 '<tr><td>Invalid "$rigs" array</td></tr>';
- 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 '<tr><td>Invalid "$rigs" array</td></tr>';
- return;
- }
- htmlhead(false, null);
- if ($placebuttons == 'top' || $placebuttons == 'both')
- pagebuttons(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 '<tr><td><br><br></td></tr>';
- echo $tablebegin;
- doforeach('devs', 'device list', $sum, array(''=>'','ID'=>'','Name'=>''), false);
- echo $tableend;
- echo '<tr><td><br><br></td></tr>';
- echo $tablebegin;
- doforeach('pools', 'pool list', $sum, array(''=>''), false);
- echo $tableend;
- if ($placebuttons == 'bot' || $placebuttons == 'both')
- pagebuttons(null, null);
- }
- #
- display();
- #
- ?>
- </table></td></tr></table>
- </body></html>
|