miner.php 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795
  1. <?php
  2. session_start();
  3. date_default_timezone_set(@date_default_timezone_get());
  4. #
  5. global $title, $miner, $port, $readonly, $notify, $rigs;
  6. global $rigipsecurity, $rigtotals, $forcerigtotals;
  7. global $socksndtimeoutsec, $sockrcvtimeoutsec;
  8. global $checklastshare, $poolinputs, $hidefields;
  9. global $ignorerefresh, $changerefresh, $autorefresh;
  10. global $allowcustompages, $customsummarypages;
  11. global $miner_font_family, $miner_font_size;
  12. global $colouroverride, $placebuttons, $userlist;
  13. #
  14. # See README.RPC for more details of these variables and how
  15. # to configure miner.php
  16. #
  17. # Web page title
  18. $title = 'Mine';
  19. #
  20. # Set $readonly to true to force miner.php to be readonly
  21. # Set $readonly to false then it will check BFGMiner 'privileged'
  22. $readonly = false;
  23. #
  24. # Set $userlist to null to allow anyone access or read README.RPC
  25. $userlist = null;
  26. #
  27. # Set $notify to false to NOT attempt to display the notify command
  28. # Set $notify to true to attempt to display the notify command
  29. $notify = true;
  30. #
  31. # Set $checklastshare to true to do the following checks:
  32. # If a device's last share is 12x expected ago then display as an error
  33. # If a device's last share is 8x expected ago then display as a warning
  34. # If either of the above is true, also display the whole line highlighted
  35. # This assumes shares are 1 difficulty shares
  36. $checklastshare = true;
  37. #
  38. # Set $poolinputs to true to show the input fields for adding a pool
  39. # and changing the pool priorities
  40. # N.B. also if $readonly is true, it will not display the fields
  41. $poolinputs = false;
  42. #
  43. # Set $rigs to an array of your BFGMiner rigs that are running
  44. # format: 'IP:Port' or 'Host:Port' or 'Host:Port:Name'
  45. $rigs = array('127.0.0.1:4028');
  46. #
  47. # Set $rigipsecurity to false to show the IP/Port of the rig
  48. # in the socket error messages and also show the full socket message
  49. $rigipsecurity = true;
  50. #
  51. # Set $rigtotals to true to display totals on the single rig page
  52. # 'false' means no totals (and ignores $forcerigtotals)
  53. # You can force it to always show rig totals when there is only
  54. # one line by setting $forcerigtotals = true;
  55. $rigtotals = true;
  56. $forcerigtotals = false;
  57. #
  58. # These should be OK for most cases
  59. $socksndtimeoutsec = 10;
  60. $sockrcvtimeoutsec = 40;
  61. #
  62. # List of fields NOT to be displayed
  63. # This example would hide the slightly more sensitive pool information
  64. #$hidefields = array('POOL.URL' => 1, 'POOL.User' => 1);
  65. $hidefields = array();
  66. #
  67. # Auto-refresh of the page (in seconds) - integers only
  68. # $ignorerefresh = true/false always ignore refresh parameters
  69. # $changerefresh = true/false show buttons to change the value
  70. # $autorefresh = default value, 0 means dont auto-refresh
  71. $ignorerefresh = false;
  72. $changerefresh = true;
  73. $autorefresh = 0;
  74. #
  75. # Should we allow custom pages?
  76. # (or just completely ignore them and don't display the buttons)
  77. $allowcustompages = true;
  78. #
  79. # OK this is a bit more complex item: Custom Summary Pages
  80. # As mentioned above, see README.RPC
  81. # see the example below (if there is no matching data, no total will show)
  82. $mobilepage = array(
  83. 'DATE' => null,
  84. 'RIGS' => null,
  85. 'SUMMARY' => array('Elapsed', 'MHS av', 'Found Blocks=Blks', 'Accepted', 'Rejected=Rej', 'Utility'),
  86. 'DEVS+NOTIFY' => array('DEVS.Name=Name', 'DEVS.ID=ID', 'DEVS.ProcID=Proc',
  87. 'DEVS.Status=Status', 'DEVS.Temperature=Temp',
  88. 'DEVS.MHS av=MHS av', 'DEVS.Accepted=Accept', 'DEVS.Rejected=Rej',
  89. 'DEVS.Utility=Utility', 'NOTIFY.Last Not Well=Not Well'),
  90. 'POOL' => array('POOL', 'Status', 'Accepted', 'Rejected=Rej', 'Last Share Time'));
  91. $mobilesum = array(
  92. 'SUMMARY' => array('MHS av', 'Found Blocks', 'Accepted', 'Rejected', 'Utility'),
  93. 'DEVS+NOTIFY' => array('DEVS.MHS av', 'DEVS.Accepted', 'DEVS.Rejected', 'DEVS.Utility'),
  94. 'POOL' => array('Accepted', 'Rejected'));
  95. #
  96. $statspage = array(
  97. 'DATE' => null,
  98. 'RIGS' => null,
  99. 'SUMMARY' => array('Elapsed', 'MHS av', 'Found Blocks=Blks',
  100. 'Accepted', 'Rejected=Rej', 'Utility',
  101. 'Hardware Errors=HW Errs', 'Network Blocks=Net Blks',
  102. 'Work Utility'),
  103. 'COIN' => array('*'),
  104. 'STATS' => array('*'));
  105. #
  106. $statssum = array(
  107. 'SUMMARY' => array('MHS av', 'Found Blocks', 'Accepted',
  108. 'Rejected', 'Utility', 'Hardware Errors',
  109. 'Work Utility'));
  110. #
  111. $poolspage = array(
  112. 'DATE' => null,
  113. 'RIGS' => null,
  114. 'SUMMARY' => array('Elapsed', 'MHS av', 'Found Blocks=Blks', 'Accepted', 'Rejected=Rej',
  115. 'Utility', 'Hardware Errors=HW Errs', 'Network Blocks=Net Blks'),
  116. 'POOL+STATS' => array('STATS.ID=ID', 'POOL.URL=URL',
  117. 'POOL.Has Stratum=Stratum', 'POOL.Stratum Active=StrAct',
  118. 'STATS.Net Bytes Sent=NSent',
  119. 'STATS.Net Bytes Recv=NRecv'));
  120. #
  121. $poolssum = array(
  122. 'SUMMARY' => array('MHS av', 'Found Blocks', 'Accepted',
  123. 'Rejected', 'Utility', 'Hardware Errors'),
  124. 'POOL+STATS' => array(
  125. 'STATS.Net Bytes Sent',
  126. 'STATS.Net Bytes Recv'));
  127. #
  128. $poolsext = array(
  129. 'POOL+STATS' => array(
  130. 'where' => null,
  131. 'group' => array('POOL.URL', 'POOL.Has Stratum', 'POOL.Stratum Active'),
  132. 'calc' => array(
  133. 'STATS.Net Bytes Sent' => 'sum',
  134. 'STATS.Net Bytes Recv' => 'sum'),
  135. 'having' => array(array('STATS.Bytes Recv', '>', 0)))
  136. );
  137. #
  138. # customsummarypages is an array of these Custom Summary Pages
  139. $customsummarypages = array('Mobile' => array($mobilepage, $mobilesum),
  140. 'Stats' => array($statspage, $statssum),
  141. 'Pools' => array($poolspage, $poolssum, $poolsext));
  142. #
  143. $here = $_SERVER['PHP_SELF'];
  144. #
  145. global $tablebegin, $tableend, $warnfont, $warnoff, $dfmt;
  146. #
  147. $tablebegin = '<tr><td><table border=1 cellpadding=5 cellspacing=0>';
  148. $tableend = '</table></td></tr>';
  149. $warnfont = '<font color=red><b>';
  150. $warnoff = '</b></font>';
  151. $dfmt = 'H:i:s j-M-Y \U\T\CP';
  152. #
  153. $miner_font_family = 'verdana,arial,sans';
  154. $miner_font_size = '13pt';
  155. #
  156. # Edit this or redefine it in myminer.php to change the colour scheme
  157. # See $colourtable below for the list of names
  158. $colouroverride = array();
  159. #
  160. # Where to place the buttons: 'top' 'bot' 'both'
  161. # anything else means don't show them - case sensitive
  162. $placebuttons = 'top';
  163. #
  164. # This below allows you to put your own settings into a seperate file
  165. # so you don't need to update miner.php with your preferred settings
  166. # every time a new version is released
  167. # Just create the file 'myminer.php' in the same directory as
  168. # 'miner.php' - and put your own settings in there
  169. if (file_exists('myminer.php'))
  170. include_once('myminer.php');
  171. #
  172. # This is the system default that must always contain all necessary
  173. # colours so it must be a constant
  174. # You can override these values with $colouroverride
  175. # The only one missing is in $warnfont
  176. # - which you can override directly anyway
  177. global $colourtable;
  178. $colourtable = array(
  179. 'body bgcolor' => '#ecffff',
  180. 'td color' => 'blue',
  181. 'td.two color' => 'blue',
  182. 'td.two background' => '#ecffff',
  183. 'td.h color' => 'blue',
  184. 'td.h background' => '#c4ffff',
  185. 'td.err color' => 'black',
  186. 'td.err background' => '#ff3050',
  187. 'td.warn color' => 'black',
  188. 'td.warn background' => '#ffb050',
  189. 'td.sta color' => 'green',
  190. 'td.tot color' => 'blue',
  191. 'td.tot background' => '#fff8f2',
  192. 'td.lst color' => 'blue',
  193. 'td.lst background' => '#ffffdd',
  194. 'td.hi color' => 'blue',
  195. 'td.hi background' => '#f6ffff',
  196. 'td.lo color' => 'blue',
  197. 'td.lo background' => '#deffff'
  198. );
  199. #
  200. # Don't touch these 2
  201. $miner = null;
  202. $port = null;
  203. #
  204. # Ensure it is only ever shown once
  205. global $showndate;
  206. $showndate = false;
  207. #
  208. # For summary page to stop retrying failed rigs
  209. global $rigerror;
  210. $rigerror = array();
  211. #
  212. global $rownum;
  213. $rownum = 0;
  214. #
  215. // Login
  216. global $ses;
  217. $ses = 'rutroh';
  218. #
  219. function getcss($cssname, $dom = false)
  220. {
  221. global $colourtable, $colouroverride;
  222. $css = '';
  223. foreach ($colourtable as $cssdata => $value)
  224. {
  225. $cssobj = explode(' ', $cssdata, 2);
  226. if ($cssobj[0] == $cssname)
  227. {
  228. if (isset($colouroverride[$cssdata]))
  229. $value = $colouroverride[$cssdata];
  230. if ($dom == true)
  231. $css .= ' '.$cssobj[1].'='.$value;
  232. else
  233. $css .= $cssobj[1].':'.$value.'; ';
  234. }
  235. }
  236. return $css;
  237. }
  238. #
  239. function getdom($domname)
  240. {
  241. return getcss($domname, true);
  242. }
  243. #
  244. function htmlhead($checkapi, $rig, $pg = null, $noscript = false)
  245. {
  246. global $title, $miner_font_family, $miner_font_size;
  247. global $error, $readonly, $poolinputs, $here;
  248. global $ignorerefresh, $autorefresh;
  249. $extraparams = '';
  250. if ($rig != null && $rig != '')
  251. $extraparams = "&rig=$rig";
  252. else
  253. if ($pg != null && $pg != '')
  254. $extraparams = "&pg=$pg";
  255. if ($ignorerefresh == true || $autorefresh == 0)
  256. $refreshmeta = '';
  257. else
  258. {
  259. $url = "$here?ref=$autorefresh$extraparams";
  260. $refreshmeta = "\n<meta http-equiv='refresh' content='$autorefresh;url=$url'>";
  261. }
  262. if ($readonly === false && $checkapi === true)
  263. {
  264. $error = null;
  265. $access = api($rig, 'privileged');
  266. if ($error != null
  267. || !isset($access['STATUS']['STATUS'])
  268. || $access['STATUS']['STATUS'] != 'S')
  269. $readonly = true;
  270. }
  271. $miner_font = "font-family:$miner_font_family; font-size:$miner_font_size;";
  272. echo "<html><head>$refreshmeta
  273. <title>$title</title>
  274. <style type='text/css'>
  275. td { $miner_font ".getcss('td')."}
  276. td.two { $miner_font ".getcss('td.two')."}
  277. td.h { $miner_font ".getcss('td.h')."}
  278. td.err { $miner_font ".getcss('td.err')."}
  279. td.warn { $miner_font ".getcss('td.warn')."}
  280. td.sta { $miner_font ".getcss('td.sta')."}
  281. td.tot { $miner_font ".getcss('td.tot')."}
  282. td.lst { $miner_font ".getcss('td.lst')."}
  283. td.hi { $miner_font ".getcss('td.hi')."}
  284. td.lo { $miner_font ".getcss('td.lo')."}
  285. </style>
  286. </head><body".getdom('body').">\n";
  287. if ($noscript === false)
  288. {
  289. echo "<script type='text/javascript'>
  290. function pr(a,m){if(m!=null){if(!confirm(m+'?'))return}window.location='$here?ref=$autorefresh'+a}\n";
  291. if ($ignorerefresh == false)
  292. echo "function prr(a){if(a){v=document.getElementById('refval').value}else{v=0}window.location='$here?ref='+v+'$extraparams'}\n";
  293. if ($readonly === false && $checkapi === true)
  294. {
  295. echo "function prc(a,m){pr('&arg='+a,m)}
  296. 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)}
  297. 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";
  298. if ($poolinputs === true)
  299. echo "function cbs(s){var t=s.replace(/\\\\/g,'\\\\\\\\'); return t.replace(/,/g, '\\\\,')}\nfunction pla(r){var u=document.getElementById('purl').value;var w=document.getElementById('pwork').value;var p=document.getElementById('ppass').value;pr('&rig='+r+'&arg=addpool|'+cbs(u)+','+cbs(w)+','+cbs(p),'Add Pool '+u)}\nfunction psp(r){var p=document.getElementById('prio').value;pr('&rig='+r+'&arg=poolpriority|'+p,'Set Pool Priorities to '+p)}\n";
  300. }
  301. echo "</script>\n";
  302. }
  303. ?>
  304. <table width=100% height=100% border=0 cellpadding=0 cellspacing=0 summary='Mine'>
  305. <tr><td align=center valign=top>
  306. <table border=0 cellpadding=4 cellspacing=0 summary='Mine'>
  307. <?php
  308. }
  309. #
  310. global $haderror, $error;
  311. $haderror = false;
  312. $error = null;
  313. #
  314. function getsock($rig, $addr, $port)
  315. {
  316. global $rigipsecurity;
  317. global $haderror, $error, $socksndtimeoutsec, $sockrcvtimeoutsec;
  318. $error = null;
  319. $socket = null;
  320. $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  321. if ($socket === false || $socket === null)
  322. {
  323. $haderror = true;
  324. if ($rigipsecurity === false)
  325. {
  326. $error = socket_strerror(socket_last_error());
  327. $msg = "socket create(TCP) failed";
  328. $error = "ERR: $msg '$error'\n";
  329. }
  330. else
  331. $error = "ERR: socket create(TCP) failed\n";
  332. return null;
  333. }
  334. // Ignore if this fails since the socket connect may work anyway
  335. // and nothing is gained by aborting if the option cannot be set
  336. // since we don't know in advance if it can connect
  337. socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, array('sec' => $socksndtimeoutsec, 'usec' => 0));
  338. socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $sockrcvtimeoutsec, 'usec' => 0));
  339. $res = socket_connect($socket, $addr, $port);
  340. if ($res === false)
  341. {
  342. $haderror = true;
  343. if ($rigipsecurity === false)
  344. {
  345. $error = socket_strerror(socket_last_error());
  346. $msg = "socket connect($addr,$port) failed";
  347. $error = "ERR: $msg '$error'\n";
  348. }
  349. else
  350. $error = "ERR: socket connect($rig) failed\n";
  351. socket_close($socket);
  352. return null;
  353. }
  354. return $socket;
  355. }
  356. #
  357. function readsockline($socket)
  358. {
  359. $line = '';
  360. while (true)
  361. {
  362. $byte = socket_read($socket, 1);
  363. if ($byte === false || $byte === '')
  364. break;
  365. if ($byte === "\0")
  366. break;
  367. $line .= $byte;
  368. }
  369. return $line;
  370. }
  371. #
  372. function api_convert_escape($str)
  373. {
  374. $res = '';
  375. $len = strlen($str);
  376. for ($i = 0; $i < $len; $i++)
  377. {
  378. $ch = substr($str, $i, 1);
  379. if ($ch != '\\' || $i == ($len-1))
  380. $res .= $ch;
  381. else
  382. {
  383. $i++;
  384. $ch = substr($str, $i, 1);
  385. switch ($ch)
  386. {
  387. case '|':
  388. $res .= "\1";
  389. break;
  390. case '\\':
  391. $res .= "\2";
  392. break;
  393. case '=':
  394. $res .= "\3";
  395. break;
  396. case ',':
  397. $res .= "\4";
  398. break;
  399. default:
  400. $res .= $ch;
  401. }
  402. }
  403. }
  404. return $res;
  405. }
  406. #
  407. function revert($str)
  408. {
  409. return str_replace(array("\1", "\2", "\3", "\4"), array("|", "\\", "=", ","), $str);
  410. }
  411. #
  412. function api($rig, $cmd)
  413. {
  414. global $haderror, $error;
  415. global $miner, $port, $hidefields;
  416. $socket = getsock($rig, $miner, $port);
  417. if ($socket != null)
  418. {
  419. socket_write($socket, $cmd, strlen($cmd));
  420. $line = readsockline($socket);
  421. socket_close($socket);
  422. if (strlen($line) == 0)
  423. {
  424. $haderror = true;
  425. $error = "WARN: '$cmd' returned nothing\n";
  426. return $line;
  427. }
  428. # print "$cmd returned '$line'\n";
  429. $line = api_convert_escape($line);
  430. $data = array();
  431. $objs = explode('|', $line);
  432. foreach ($objs as $obj)
  433. {
  434. if (strlen($obj) > 0)
  435. {
  436. $items = explode(',', $obj);
  437. $item = $items[0];
  438. $id = explode('=', $items[0], 2);
  439. if (count($id) == 1 or !ctype_digit($id[1]))
  440. $name = $id[0];
  441. else
  442. $name = $id[0].$id[1];
  443. if (strlen($name) == 0)
  444. $name = 'null';
  445. $sectionname = preg_replace('/\d/', '', $name);
  446. if (isset($data[$name]))
  447. {
  448. $num = 1;
  449. while (isset($data[$name.$num]))
  450. $num++;
  451. $name .= $num;
  452. }
  453. $counter = 0;
  454. foreach ($items as $item)
  455. {
  456. $id = explode('=', $item, 2);
  457. if (isset($hidefields[$sectionname.'.'.$id[0]]))
  458. continue;
  459. if (count($id) == 2)
  460. $data[$name][$id[0]] = revert($id[1]);
  461. else
  462. $data[$name][$counter] = $id[0];
  463. $counter++;
  464. }
  465. }
  466. }
  467. return $data;
  468. }
  469. return null;
  470. }
  471. #
  472. function getparam($name, $both = false)
  473. {
  474. $a = null;
  475. if (isset($_POST[$name]))
  476. $a = $_POST[$name];
  477. if (($both === true) and ($a === null))
  478. {
  479. if (isset($_GET[$name]))
  480. $a = $_GET[$name];
  481. }
  482. if ($a == '' || $a == null)
  483. return null;
  484. // limit to 1K just to be safe
  485. return substr($a, 0, 1024);
  486. }
  487. #
  488. function newtable()
  489. {
  490. global $tablebegin, $rownum;
  491. echo $tablebegin;
  492. $rownum = 0;
  493. }
  494. #
  495. function newrow()
  496. {
  497. echo '<tr>';
  498. }
  499. #
  500. function otherrow($row)
  501. {
  502. echo "<tr>$row</tr>";
  503. }
  504. #
  505. function endrow()
  506. {
  507. global $rownum;
  508. echo '</tr>';
  509. $rownum++;
  510. }
  511. #
  512. function endtable()
  513. {
  514. global $tableend;
  515. echo $tableend;
  516. }
  517. #
  518. function classlastshare($when, $alldata, $warnclass, $errorclass)
  519. {
  520. global $checklastshare;
  521. if ($checklastshare === false)
  522. return '';
  523. if ($when == 0)
  524. return '';
  525. if (!isset($alldata['MHS av']))
  526. return '';
  527. if ($alldata['MHS av'] == 0)
  528. return '';
  529. if (!isset($alldata['Last Share Time']))
  530. return '';
  531. if (!isset($alldata['Last Share Difficulty']))
  532. return '';
  533. $expected = pow(2, 32) / ($alldata['MHS av'] * pow(10, 6));
  534. // If the share difficulty changes while waiting on a share,
  535. // this calculation will of course be incorrect
  536. $expected *= $alldata['Last Share Difficulty'];
  537. $howlong = $when - $alldata['Last Share Time'];
  538. if ($howlong < 1)
  539. $howlong = 1;
  540. if ($howlong > ($expected * 12))
  541. return $errorclass;
  542. if ($howlong > ($expected * 8))
  543. return $warnclass;
  544. return '';
  545. }
  546. #
  547. function endzero($num)
  548. {
  549. $rep = preg_replace('/0*$/', '', $num);
  550. if ($rep === '')
  551. $rep = '0';
  552. return $rep;
  553. }
  554. #
  555. function fmt($section, $name, $value, $when, $alldata)
  556. {
  557. global $dfmt, $rownum;
  558. if ($alldata == null)
  559. $alldata = array();
  560. $errorclass = ' class=err';
  561. $warnclass = ' class=warn';
  562. $lstclass = ' class=lst';
  563. $hiclass = ' class=hi';
  564. $loclass = ' class=lo';
  565. $c2class = ' class=two';
  566. $totclass = ' class=tot';
  567. $b = '&nbsp;';
  568. $ret = $value;
  569. $class = '';
  570. $nams = explode('.', $name);
  571. if (count($nams) > 1)
  572. $name = $nams[count($nams)-1];
  573. if ($value === null)
  574. $ret = $b;
  575. else
  576. switch ($section.'.'.$name)
  577. {
  578. case 'GPU.Last Share Time':
  579. case 'PGA.Last Share Time':
  580. case 'DEVS.Last Share Time':
  581. if ($value == 0
  582. || (isset($alldata['Last Share Pool']) && $alldata['Last Share Pool'] == -1))
  583. {
  584. $ret = 'Never';
  585. $class = $warnclass;
  586. }
  587. else
  588. {
  589. $ret = date('H:i:s', $value);
  590. $class = classlastshare($when, $alldata, $warnclass, $errorclass);
  591. }
  592. break;
  593. case 'GPU.Last Valid Work':
  594. case 'PGA.Last Valid Work':
  595. case 'DEVS.Last Valid Work':
  596. if ($value == 0)
  597. $ret = 'Never';
  598. else
  599. $ret = ($value - $when) . 's';
  600. break;
  601. case 'POOL.Last Share Time':
  602. if ($value == 0)
  603. $ret = 'Never';
  604. else
  605. $ret = date('H:i:s d-M', $value);
  606. break;
  607. case 'GPU.Last Share Pool':
  608. case 'PGA.Last Share Pool':
  609. case 'DEVS.Last Share Pool':
  610. if ($value == -1)
  611. {
  612. $ret = 'None';
  613. $class = $warnclass;
  614. }
  615. break;
  616. case 'SUMMARY.Elapsed':
  617. case 'STATS.Elapsed':
  618. $s = $value % 60;
  619. $value -= $s;
  620. $value /= 60;
  621. if ($value == 0)
  622. $ret = $s.'s';
  623. else
  624. {
  625. $m = $value % 60;
  626. $value -= $m;
  627. $value /= 60;
  628. if ($value == 0)
  629. $ret = sprintf("%dm$b%02ds", $m, $s);
  630. else
  631. {
  632. $h = $value % 24;
  633. $value -= $h;
  634. $value /= 24;
  635. if ($value == 0)
  636. $ret = sprintf("%dh$b%02dm$b%02ds", $h, $m, $s);
  637. else
  638. {
  639. if ($value == 1)
  640. $days = '';
  641. else
  642. $days = 's';
  643. $ret = sprintf("%dday$days$b%02dh$b%02dm$b%02ds", $value, $h, $m, $s);
  644. }
  645. }
  646. }
  647. break;
  648. case 'NOTIFY.Last Well':
  649. if ($value == '0')
  650. {
  651. $ret = 'Never';
  652. $class = $warnclass;
  653. }
  654. else
  655. $ret = date('H:i:s', $value);
  656. break;
  657. case 'NOTIFY.Last Not Well':
  658. if ($value == '0')
  659. $ret = 'Never';
  660. else
  661. {
  662. $ret = date('H:i:s', $value);
  663. $class = $errorclass;
  664. }
  665. break;
  666. case 'NOTIFY.Reason Not Well':
  667. if ($value != 'None')
  668. $class = $errorclass;
  669. break;
  670. case 'GPU.Utility':
  671. case 'PGA.Utility':
  672. case 'DEVS.Utility':
  673. case 'SUMMARY.Utility':
  674. case 'total.Utility':
  675. $ret = $value.'/m';
  676. if ($value == 0)
  677. $class = $errorclass;
  678. else
  679. if (isset($alldata['Difficulty Accepted'])
  680. && isset($alldata['Accepted'])
  681. && isset($alldata['MHS av'])
  682. && ($alldata['Difficulty Accepted'] > 0)
  683. && ($alldata['Accepted'] > 0))
  684. {
  685. $expected = 60 * $alldata['MHS av'] * (pow(10, 6) / pow(2, 32));
  686. if ($expected == 0)
  687. $expected = 0.000001; // 1 H/s
  688. $da = $alldata['Difficulty Accepted'];
  689. $a = $alldata['Accepted'];
  690. $expected /= ($da / $a);
  691. $ratio = $value / $expected;
  692. if ($ratio < 0.9)
  693. $class = $loclass;
  694. else
  695. if ($ratio > 1.1)
  696. $class = $hiclass;
  697. }
  698. break;
  699. case 'PGA.Temperature':
  700. case 'GPU.Temperature':
  701. case 'DEVS.Temperature':
  702. $ret = $value.'&deg;C';
  703. if (!isset($alldata['GPU']))
  704. {
  705. if ($value == 0)
  706. $ret = '&nbsp;';
  707. break;
  708. }
  709. case 'GPU.GPU Clock':
  710. case 'DEVS.GPU Clock':
  711. case 'GPU.Memory Clock':
  712. case 'DEVS.Memory Clock':
  713. case 'GPU.GPU Voltage':
  714. case 'DEVS.GPU Voltage':
  715. case 'GPU.GPU Activity':
  716. case 'DEVS.GPU Activity':
  717. if ($value == 0)
  718. $class = $warnclass;
  719. break;
  720. case 'GPU.Fan Percent':
  721. case 'DEVS.Fan Percent':
  722. if ($value == 0)
  723. $class = $warnclass;
  724. else
  725. {
  726. if ($value == 100)
  727. $class = $errorclass;
  728. else
  729. if ($value > 85)
  730. $class = $warnclass;
  731. }
  732. break;
  733. case 'GPU.Fan Speed':
  734. case 'DEVS.Fan Speed':
  735. if ($value == 0)
  736. $class = $warnclass;
  737. else
  738. if (isset($alldata['Fan Percent']))
  739. {
  740. $test = $alldata['Fan Percent'];
  741. if ($test == 100)
  742. $class = $errorclass;
  743. else
  744. if ($test > 85)
  745. $class = $warnclass;
  746. }
  747. break;
  748. case 'GPU.MHS av':
  749. case 'PGA.MHS av':
  750. case 'DEVS.MHS av':
  751. case 'SUMMARY.MHS av':
  752. case 'total.MHS av':
  753. $parts = explode('.', $value, 2);
  754. if (count($parts) == 1)
  755. $dec = '';
  756. else
  757. $dec = '.'.$parts[1];
  758. $ret = number_format((float)$parts[0]).$dec;
  759. if ($value == 0)
  760. $class = $errorclass;
  761. else
  762. if (isset($alldata['Difficulty Accepted'])
  763. && isset($alldata['Accepted'])
  764. && isset($alldata['Utility'])
  765. && ($alldata['Difficulty Accepted'] > 0)
  766. && ($alldata['Accepted'] > 0))
  767. {
  768. $expected = 60 * $value * (pow(10, 6) / pow(2, 32));
  769. if ($expected == 0)
  770. $expected = 0.000001; // 1 H/s
  771. $da = $alldata['Difficulty Accepted'];
  772. $a = $alldata['Accepted'];
  773. $expected /= ($da / $a);
  774. $ratio = $alldata['Utility'] / $expected;
  775. if ($ratio < 0.9)
  776. $class = $hiclass;
  777. else
  778. if ($ratio > 1.1)
  779. $class = $loclass;
  780. }
  781. break;
  782. case 'GPU.Total MH':
  783. case 'PGA.Total MH':
  784. case 'DEVS.Total MH':
  785. case 'SUMMARY.Total MH':
  786. case 'total.Total MH':
  787. case 'SUMMARY.Getworks':
  788. case 'POOL.Getworks':
  789. case 'total.Getworks':
  790. case 'GPU.Accepted':
  791. case 'PGA.Accepted':
  792. case 'DEVS.Accepted':
  793. case 'SUMMARY.Accepted':
  794. case 'POOL.Accepted':
  795. case 'total.Accepted':
  796. case 'GPU.Rejected':
  797. case 'PGA.Rejected':
  798. case 'DEVS.Rejected':
  799. case 'SUMMARY.Rejected':
  800. case 'POOL.Rejected':
  801. case 'total.Rejected':
  802. case 'SUMMARY.Local Work':
  803. case 'total.Local Work':
  804. case 'SUMMARY.Discarded':
  805. case 'POOL.Discarded':
  806. case 'total.Discarded':
  807. case 'POOL.Diff1 Shares':
  808. case 'total.Diff1 Shares':
  809. case 'GPU.Diff1 Work':
  810. case 'PGA.Diff1 Work':
  811. case 'total.Diff1 Work':
  812. case 'STATS.Times Sent':
  813. case 'STATS.Bytes Sent':
  814. case 'STATS.Net Bytes Sent':
  815. case 'STATS.Times Recv':
  816. case 'STATS.Bytes Recv':
  817. case 'STATS.Net Bytes Recv':
  818. case 'total.Times Sent':
  819. case 'total.Bytes Sent':
  820. case 'total.Net Bytes Sent':
  821. case 'total.Times Recv':
  822. case 'total.Bytes Recv':
  823. case 'total.Net Bytes Recv':
  824. $parts = explode('.', $value, 2);
  825. if (count($parts) == 1)
  826. $dec = '';
  827. else
  828. $dec = '.'.$parts[1];
  829. $ret = number_format((float)$parts[0]).$dec;
  830. break;
  831. case 'STATS.Hs':
  832. case 'STATS.W':
  833. case 'STATS.history_time':
  834. case 'STATS.Pool Wait':
  835. case 'STATS.Pool Max':
  836. case 'STATS.Pool Min':
  837. case 'STATS.Pool Av':
  838. case 'STATS.Min Diff':
  839. case 'STATS.Max Diff':
  840. case 'STATS.Work Diff':
  841. $parts = explode('.', $value, 2);
  842. if (count($parts) == 1)
  843. $dec = '';
  844. else
  845. $dec = '.'.endzero($parts[1]);
  846. $ret = number_format((float)$parts[0]).$dec;
  847. break;
  848. case 'GPU.Status':
  849. case 'PGA.Status':
  850. case 'DEVS.Status':
  851. case 'POOL.Status':
  852. if ($value != 'Alive')
  853. $class = $errorclass;
  854. break;
  855. case 'GPU.Enabled':
  856. case 'PGA.Enabled':
  857. case 'DEVS.Enabled':
  858. if ($value != 'Y')
  859. $class = $warnclass;
  860. break;
  861. case 'STATUS.When':
  862. case 'COIN.Current Block Time':
  863. $ret = date($dfmt, $value);
  864. break;
  865. case 'BUTTON.Rig':
  866. case 'BUTTON.Pool':
  867. case 'BUTTON.GPU':
  868. $ret = $value;
  869. break;
  870. case 'SUMMARY.Difficulty Accepted':
  871. case 'GPU.Difficulty Accepted':
  872. case 'PGA.Difficulty Accepted':
  873. case 'DEVS.Difficulty Accepted':
  874. case 'POOL.Difficulty Accepted':
  875. case 'total.Difficulty Accepted':
  876. case 'SUMMARY.Difficulty Rejected':
  877. case 'GPU.Difficulty Rejected':
  878. case 'PGA.Difficulty Rejected':
  879. case 'DEVS.Difficulty Rejected':
  880. case 'POOL.Difficulty Rejected':
  881. case 'total.Difficulty Rejected':
  882. case 'SUMMARY.Difficulty Stale':
  883. case 'POOL.Difficulty Stale':
  884. case 'total.Difficulty Stale':
  885. case 'GPU.Last Share Difficulty':
  886. case 'PGA.Last Share Difficulty':
  887. case 'DEVS.Last Share Difficulty':
  888. case 'POOL.Last Share Difficulty':
  889. if ($value != '')
  890. $ret = number_format((float)$value, 2);
  891. break;
  892. case 'DEVS.Device Hardware%':
  893. case 'DEVS.Device Rejected%':
  894. case 'PGA.Device Hardware%':
  895. case 'PGA.Device Rejected%':
  896. case 'GPU.Device Hardware%':
  897. case 'GPU.Device Rejected%':
  898. case 'POOL.Pool Rejected%':
  899. case 'POOL.Pool Stale%':
  900. case 'SUMMARY.Device Hardware%':
  901. case 'SUMMARY.Device Rejected%':
  902. case 'SUMMARY.Pool Rejected%':
  903. case 'SUMMARY.Pool Stale%':
  904. if ($value != '')
  905. $ret = number_format((float)$value, 2) . '%';
  906. break;
  907. case 'SUMMARY.Best Share':
  908. if ($value != '')
  909. $ret = number_format((float)$value);
  910. break;
  911. }
  912. if ($section == 'NOTIFY' && substr($name, 0, 1) == '*' && $value != '0')
  913. $class = $errorclass;
  914. if ($class == '' && $section != 'POOL')
  915. $class = classlastshare($when, $alldata, $lstclass, $lstclass);
  916. if ($class == '' && $section == 'total')
  917. $class = $totclass;
  918. if ($class == '' && ($rownum % 2) == 0)
  919. $class = $c2class;
  920. if ($ret === '')
  921. $ret = $b;
  922. return array($ret, $class);
  923. }
  924. #
  925. global $poolcmd;
  926. $poolcmd = array( 'Switch to' => 'switchpool',
  927. 'Enable' => 'enablepool',
  928. 'Disable' => 'disablepool',
  929. 'Remove' => 'removepool' );
  930. #
  931. function showhead($cmd, $values, $justnames = false)
  932. {
  933. global $poolcmd, $readonly;
  934. newrow();
  935. foreach ($values as $name => $value)
  936. {
  937. if ($name == '0' or $name == '')
  938. $name = '&nbsp;';
  939. echo "<td valign=bottom class=h>$name</td>";
  940. }
  941. if ($justnames === false && $cmd == 'pools' && $readonly === false)
  942. foreach ($poolcmd as $name => $pcmd)
  943. echo "<td valign=bottom class=h>$name</td>";
  944. endrow();
  945. }
  946. #
  947. function showdatetime()
  948. {
  949. global $dfmt;
  950. otherrow('<td class=sta>Date: '.date($dfmt).'</td>');
  951. }
  952. #
  953. global $singlerigsum;
  954. $singlerigsum = array(
  955. 'devs' => array('MHS av' => 1, 'MHS 5s' => 1, 'Accepted' => 1, 'Rejected' => 1,
  956. 'Temperature' => 2,
  957. 'Hardware Errors' => 1, 'Utility' => 1, 'Total MH' => 1),
  958. 'pools' => array('Getworks' => 1, 'Accepted' => 1, 'Rejected' => 1, 'Discarded' => 1,
  959. 'Stale' => 1, 'Get Failures' => 1, 'Remote Failures' => 1),
  960. 'notify' => array('*' => 1));
  961. #
  962. function showtotal($total, $when, $oldvalues)
  963. {
  964. global $rigtotals;
  965. list($showvalue, $class) = fmt('total', '', 'Total:', $when, null);
  966. echo "<td$class align=right>$showvalue</td>";
  967. $skipfirst = true;
  968. foreach ($oldvalues as $name => $value)
  969. {
  970. if ($skipfirst === true)
  971. {
  972. $skipfirst = false;
  973. continue;
  974. }
  975. if (isset($total[$name]))
  976. $newvalue = $total[$name];
  977. else
  978. $newvalue = '';
  979. list($showvalue, $class) = fmt('total', $name, $newvalue, $when, null);
  980. echo "<td$class";
  981. if ($rigtotals === true)
  982. echo ' align=right';
  983. echo ">$showvalue</td>";
  984. }
  985. }
  986. #
  987. function details($cmd, $list, $rig)
  988. {
  989. global $dfmt, $poolcmd, $readonly, $showndate;
  990. global $rownum, $rigtotals, $forcerigtotals, $singlerigsum;
  991. $when = 0;
  992. $stas = array('S' => 'Success', 'W' => 'Warning', 'I' => 'Informational', 'E' => 'Error', 'F' => 'Fatal');
  993. newtable();
  994. if ($showndate === false)
  995. {
  996. showdatetime();
  997. endtable();
  998. newtable();
  999. $showndate = true;
  1000. }
  1001. if (isset($list['STATUS']))
  1002. {
  1003. newrow();
  1004. echo '<td>Computer: '.$list['STATUS']['Description'].'</td>';
  1005. if (isset($list['STATUS']['When']))
  1006. {
  1007. echo '<td>When: '.date($dfmt, $list['STATUS']['When']).'</td>';
  1008. $when = $list['STATUS']['When'];
  1009. }
  1010. $sta = $list['STATUS']['STATUS'];
  1011. echo '<td>Status: '.$stas[$sta].'</td>';
  1012. echo '<td>Message: '.$list['STATUS']['Msg'].'</td>';
  1013. endrow();
  1014. }
  1015. if ($rigtotals === true && isset($singlerigsum[$cmd]))
  1016. $dototal = $singlerigsum[$cmd];
  1017. else
  1018. $dototal = array();
  1019. $total = array();
  1020. $section = '';
  1021. $oldvalues = null;
  1022. // Build a common row column for all entries
  1023. $columns = array();
  1024. $columnsByIndex = array();
  1025. foreach ($list as $item => $values)
  1026. {
  1027. if ($item == 'STATUS')
  1028. continue;
  1029. if (isset($values['ID']))
  1030. {
  1031. $repr = $values['Name'].$values['ID'];
  1032. if (isset($values['ProcID']))
  1033. $repr .= join_get_field('ProcID', $values);
  1034. $list[$item] = $values = array('Device' => $repr) + array_slice($values, 1);
  1035. unset($values['Name']);
  1036. unset($values['ID']);
  1037. unset($values['ProcID']);
  1038. }
  1039. $namesByIndex = array_keys($values);
  1040. $nameCount = count($namesByIndex);
  1041. for ($i = 0; $i < $nameCount; ++$i)
  1042. {
  1043. $name = $namesByIndex[$i];
  1044. if (isset($columns[$name]))
  1045. continue;
  1046. $value = $values[$name];
  1047. $before = null;
  1048. for ($j = $i + 1; $j < $nameCount; ++$j)
  1049. {
  1050. $maybebefore = $namesByIndex[$j];
  1051. if (isset($columns[$maybebefore]))
  1052. {
  1053. $before = $columns[$maybebefore];
  1054. break;
  1055. }
  1056. }
  1057. if (!$before)
  1058. {
  1059. $columns[$name] = array_push($columnsByIndex, $name) - 1;
  1060. continue;
  1061. }
  1062. array_splice($columnsByIndex, $before, 0, $name);
  1063. $columns[$name] = $before;
  1064. $columnCount = count($columnsByIndex);
  1065. for ($j = $before + 1; $j < $columnCount; ++$j)
  1066. $columns[$columnsByIndex[$j]] = $j;
  1067. }
  1068. }
  1069. asort($columns);
  1070. endtable();
  1071. newtable();
  1072. showhead($cmd, $columns);
  1073. foreach ($list as $item => $values)
  1074. {
  1075. if ($item == 'STATUS')
  1076. continue;
  1077. newrow();
  1078. foreach ($columns as $name => $columnidx)
  1079. {
  1080. if (!isset($values[$name]))
  1081. {
  1082. echo '<td></td>';
  1083. continue;
  1084. }
  1085. $value = $values[$name];
  1086. list($showvalue, $class) = fmt($section, $name, $value, $when, $values);
  1087. echo "<td$class";
  1088. if ($rigtotals === true)
  1089. echo ' align=right';
  1090. echo ">$showvalue</td>";
  1091. if (isset($dototal[$name])
  1092. || (isset($dototal['*']) and substr($name, 0, 1) == '*'))
  1093. {
  1094. if (isset($total[$name]))
  1095. {
  1096. if ($dototal[$name] == 2)
  1097. $total[$name] = max($total[$name], $value);
  1098. else
  1099. $total[$name] += $value;
  1100. }
  1101. else
  1102. $total[$name] = $value;
  1103. }
  1104. }
  1105. if ($cmd == 'pools' && $readonly === false)
  1106. {
  1107. reset($values);
  1108. $pool = current($values);
  1109. foreach ($poolcmd as $name => $pcmd)
  1110. {
  1111. list($ignore, $class) = fmt('BUTTON', 'Pool', '', $when, $values);
  1112. echo "<td$class>";
  1113. if ($pool === false)
  1114. echo '&nbsp;';
  1115. else
  1116. {
  1117. echo "<input type=button value='Pool $pool'";
  1118. echo " onclick='prc(\"$pcmd|$pool&rig=$rig\",\"$name Pool $pool\")'>";
  1119. }
  1120. echo '</td>';
  1121. }
  1122. }
  1123. endrow();
  1124. $oldvalues = $values;
  1125. }
  1126. if ($oldvalues != null && count($total) > 0
  1127. && ($rownum > 2 || $forcerigtotals === true))
  1128. showtotal($total, $when, $columns);
  1129. endtable();
  1130. }
  1131. #
  1132. global $devs;
  1133. $devs = null;
  1134. #
  1135. function gpubuttons($count, $rig)
  1136. {
  1137. global $devs;
  1138. $basic = array( 'GPU', 'Enable', 'Disable', 'Restart' );
  1139. $options = array( 'intensity' => 'Intensity',
  1140. 'fan' => 'Fan Percent',
  1141. 'engine' => 'GPU Clock',
  1142. 'mem' => 'Memory Clock',
  1143. 'vddc' => 'GPU Voltage' );
  1144. newtable();
  1145. newrow();
  1146. foreach ($basic as $head)
  1147. echo "<td class=h>$head</td>";
  1148. foreach ($options as $name => $des)
  1149. echo "<td class=h nowrap>$des</td>";
  1150. $n = 0;
  1151. for ($c = 0; $c < $count; $c++)
  1152. {
  1153. endrow();
  1154. newrow();
  1155. foreach ($basic as $name)
  1156. {
  1157. list($ignore, $class) = fmt('BUTTON', 'GPU', '', 0, null);
  1158. echo "<td$class>";
  1159. if ($name == 'GPU')
  1160. echo $c;
  1161. else
  1162. {
  1163. echo "<input type=button value='$name $c' onclick='prs(\"gpu";
  1164. echo strtolower($name);
  1165. echo "|$c\",$rig)'>";
  1166. }
  1167. echo '</td>';
  1168. }
  1169. foreach ($options as $name => $des)
  1170. {
  1171. list($ignore, $class) = fmt('BUTTON', 'GPU', '', 0, null);
  1172. echo "<td$class>";
  1173. if (!isset($devs["GPU$c"][$des]))
  1174. echo '&nbsp;';
  1175. else
  1176. {
  1177. $value = $devs["GPU$c"][$des];
  1178. echo "<input type=button value='Set $c:' onclick='prs2(\"gpu$name|$c\",$n,$rig)'>";
  1179. echo "<input size=7 type=text name=gi$n value='$value' id=gi$n>";
  1180. $n++;
  1181. }
  1182. echo '</td>';
  1183. }
  1184. }
  1185. endrow();
  1186. endtable();
  1187. }
  1188. #
  1189. function processgpus($rig)
  1190. {
  1191. global $error;
  1192. global $warnfont, $warnoff;
  1193. $gpus = api($rig, 'gpucount');
  1194. if ($error != null)
  1195. otherrow("<td>Error getting GPU count: $warnfont$error$warnoff</td>");
  1196. else
  1197. {
  1198. if (!isset($gpus['GPUS']['Count']))
  1199. {
  1200. $rw = '<td>No GPU count returned: '.$warnfont;
  1201. $rw .= $gpus['STATUS']['STATUS'].' '.$gpus['STATUS']['Msg'];
  1202. $rw .= $warnoff.'</td>';
  1203. otherrow($rw);
  1204. }
  1205. else
  1206. {
  1207. $count = $gpus['GPUS']['Count'];
  1208. if ($count == 0)
  1209. otherrow('<td>No GPUs</td>');
  1210. else
  1211. gpubuttons($count, $rig);
  1212. }
  1213. }
  1214. }
  1215. #
  1216. function showpoolinputs($rig, $ans)
  1217. {
  1218. global $readonly, $poolinputs;
  1219. if ($readonly === true || $poolinputs === false)
  1220. return;
  1221. newtable();
  1222. newrow();
  1223. $inps = array('Pool URL' => array('purl', 20),
  1224. 'Worker Name' => array('pwork', 10),
  1225. 'Worker Password' => array('ppass', 10));
  1226. $b = '&nbsp;';
  1227. echo "<td align=right class=h> Add a pool: </td><td>";
  1228. foreach ($inps as $text => $name)
  1229. echo "$text: <input name='".$name[0]."' id='".$name[0]."' value='' type=text size=".$name[1]."> ";
  1230. echo "</td><td align=middle><input type=button value='Add' onclick='pla($rig)'></td>";
  1231. endrow();
  1232. if (count($ans) > 1)
  1233. {
  1234. newrow();
  1235. echo '<td align=right class=h> Set pool priorities: </td>';
  1236. echo "<td> Comma list of pool numbers: <input type=text name=prio id=prio size=20>";
  1237. echo "</td><td align=middle><input type=button value='Set' onclick='psp($rig)'></td>";
  1238. endrow();
  1239. }
  1240. endtable();
  1241. }
  1242. #
  1243. function process($cmds, $rig)
  1244. {
  1245. global $error, $devs;
  1246. global $warnfont, $warnoff;
  1247. $count = count($cmds);
  1248. foreach ($cmds as $cmd => $des)
  1249. {
  1250. $process = api($rig, $cmd);
  1251. if ($error != null)
  1252. {
  1253. otherrow("<td colspan=100>Error getting $des: $warnfont$error$warnoff</td>");
  1254. break;
  1255. }
  1256. else
  1257. {
  1258. details($cmd, $process, $rig);
  1259. if ($cmd == 'devs')
  1260. $devs = $process;
  1261. if ($cmd == 'pools')
  1262. showpoolinputs($rig, $process);
  1263. # Not after the last one
  1264. if (--$count > 0)
  1265. otherrow('<td><br><br></td>');
  1266. }
  1267. }
  1268. }
  1269. #
  1270. function rigname($rig, $rigname)
  1271. {
  1272. global $rigs;
  1273. if (isset($rigs[$rig]))
  1274. {
  1275. $parts = explode(':', $rigs[$rig], 3);
  1276. if (count($parts) == 3)
  1277. $rigname = $parts[2];
  1278. }
  1279. return $rigname;
  1280. }
  1281. #
  1282. function riginput($rig, $rigname)
  1283. {
  1284. $rigname = rigname($rig, $rigname);
  1285. return "<input type=button value='$rigname' onclick='pr(\"&rig=$rig\",null)'>";
  1286. }
  1287. #
  1288. function rigbutton($rig, $rigname, $when, $row)
  1289. {
  1290. list($value, $class) = fmt('BUTTON', 'Rig', '', $when, $row);
  1291. if ($rig === '')
  1292. $ri = '&nbsp;';
  1293. else
  1294. $ri = riginput($rig, $rigname);
  1295. return "<td align=middle$class>$ri</td>";
  1296. }
  1297. #
  1298. function showrigs($anss, $headname, $rigname)
  1299. {
  1300. $dthead = array($headname => 1, 'STATUS' => 1, 'Description' => 1, 'When' => 1, 'API' => 1, 'CGMiner' => 1);
  1301. showhead('', $dthead);
  1302. foreach ($anss as $rig => $ans)
  1303. {
  1304. if ($ans == null)
  1305. continue;
  1306. newrow();
  1307. $when = 0;
  1308. if (isset($ans['STATUS']['When']))
  1309. $when = $ans['STATUS']['When'];
  1310. foreach ($ans as $item => $row)
  1311. {
  1312. if ($item != 'STATUS' && $item != 'VERSION')
  1313. continue;
  1314. foreach ($dthead as $name => $x)
  1315. {
  1316. if ($item == 'STATUS' && $name == $headname)
  1317. echo rigbutton($rig, $rigname.$rig, $when, null);
  1318. else
  1319. {
  1320. if (isset($row[$name]))
  1321. {
  1322. list($showvalue, $class) = fmt('STATUS', $name, $row[$name], $when, null);
  1323. echo "<td$class align=right>$showvalue</td>";
  1324. }
  1325. }
  1326. }
  1327. }
  1328. endrow();
  1329. }
  1330. }
  1331. #
  1332. # $head is a hack but this is just a demo anyway :)
  1333. function doforeach($cmd, $des, $sum, $head, $datetime)
  1334. {
  1335. global $miner, $port;
  1336. global $error, $readonly, $notify, $rigs;
  1337. global $warnfont, $warnoff, $dfmt;
  1338. global $rigerror;
  1339. $when = 0;
  1340. $header = $head;
  1341. $anss = array();
  1342. $count = 0;
  1343. $preverr = count($rigerror);
  1344. foreach ($rigs as $num => $rig)
  1345. {
  1346. $anss[$num] = null;
  1347. if (isset($rigerror[$rig]))
  1348. continue;
  1349. $parts = explode(':', $rig, 3);
  1350. if (count($parts) >= 2)
  1351. {
  1352. $miner = $parts[0];
  1353. $port = $parts[1];
  1354. if (count($parts) > 2)
  1355. $name = $parts[2];
  1356. else
  1357. $name = $num;
  1358. $ans = api($name, $cmd);
  1359. if ($error != null)
  1360. {
  1361. $rw = "<td colspan=100>Error on rig $name getting ";
  1362. $rw .= "$des: $warnfont$error$warnoff</td>";
  1363. otherrow($rw);
  1364. $rigerror[$rig] = $error;
  1365. $error = null;
  1366. }
  1367. else
  1368. {
  1369. $anss[$num] = $ans;
  1370. $count++;
  1371. }
  1372. }
  1373. }
  1374. if ($count == 0)
  1375. {
  1376. $rw = '<td>Failed to access any rigs successfully';
  1377. if ($preverr > 0)
  1378. $rw .= ' (or rigs had previous errors)';
  1379. $rw .= '</td>';
  1380. otherrow($rw);
  1381. return;
  1382. }
  1383. if ($datetime)
  1384. {
  1385. showdatetime();
  1386. endtable();
  1387. newtable();
  1388. showrigs($anss, '', 'Rig ');
  1389. endtable();
  1390. otherrow('<td><br><br></td>');
  1391. newtable();
  1392. return;
  1393. }
  1394. $total = array();
  1395. foreach ($anss as $rig => $ans)
  1396. {
  1397. if ($ans == null)
  1398. continue;
  1399. foreach ($ans as $item => $row)
  1400. {
  1401. if ($item == 'STATUS')
  1402. continue;
  1403. if (count($row) > count($header))
  1404. {
  1405. $header = $head;
  1406. foreach ($row as $name => $value)
  1407. if (!isset($header[$name]))
  1408. $header[$name] = '';
  1409. }
  1410. if ($sum != null)
  1411. foreach ($sum as $name)
  1412. {
  1413. if (isset($row[$name]))
  1414. {
  1415. if (isset($total[$name]))
  1416. $total[$name] += $row[$name];
  1417. else
  1418. $total[$name] = $row[$name];
  1419. }
  1420. }
  1421. }
  1422. }
  1423. if ($sum != null)
  1424. $anss['total']['total'] = $total;
  1425. showhead('', $header);
  1426. foreach ($anss as $rig => $ans)
  1427. {
  1428. if ($ans == null)
  1429. continue;
  1430. $when = 0;
  1431. if (isset($ans['STATUS']['When']))
  1432. $when = $ans['STATUS']['When'];
  1433. foreach ($ans as $item => $row)
  1434. {
  1435. if ($item == 'STATUS')
  1436. continue;
  1437. newrow();
  1438. $section = preg_replace('/\d/', '', $item);
  1439. foreach ($header as $name => $x)
  1440. {
  1441. if ($name == '')
  1442. {
  1443. if ($rig === 'total')
  1444. {
  1445. list($ignore, $class) = fmt($rig, '', '', $when, $row);
  1446. echo "<td align=right$class>Total:</td>";
  1447. }
  1448. else
  1449. echo rigbutton($rig, "Rig $rig", $when, $row);
  1450. }
  1451. else
  1452. {
  1453. if (isset($row[$name]))
  1454. $value = $row[$name];
  1455. else
  1456. $value = null;
  1457. list($showvalue, $class) = fmt($section, $name, $value, $when, $row);
  1458. echo "<td$class align=right>$showvalue</td>";
  1459. }
  1460. }
  1461. endrow();
  1462. }
  1463. }
  1464. }
  1465. #
  1466. function refreshbuttons()
  1467. {
  1468. global $ignorerefresh, $changerefresh, $autorefresh;
  1469. if ($ignorerefresh == false && $changerefresh == true)
  1470. {
  1471. echo '&nbsp;&nbsp;&nbsp;&nbsp;';
  1472. echo "<input type=button value='Auto Refresh:' onclick='prr(true)'>";
  1473. echo "<input type=text name='refval' id='refval' size=2 value='$autorefresh'>";
  1474. echo "<input type=button value='Off' onclick='prr(false)'>";
  1475. }
  1476. }
  1477. #
  1478. function pagebuttons($rig, $pg)
  1479. {
  1480. global $readonly, $rigs, $userlist, $ses;
  1481. global $allowcustompages, $customsummarypages;
  1482. if ($rig === null)
  1483. {
  1484. $prev = null;
  1485. $next = null;
  1486. if ($pg === null)
  1487. $refresh = '';
  1488. else
  1489. $refresh = "&pg=$pg";
  1490. }
  1491. else
  1492. {
  1493. switch (count($rigs))
  1494. {
  1495. case 0:
  1496. case 1:
  1497. $prev = null;
  1498. $next = null;
  1499. break;
  1500. case 2:
  1501. $prev = null;
  1502. $next = ($rig + 1) % count($rigs);
  1503. break;
  1504. default:
  1505. $prev = ($rig - 1) % count($rigs);
  1506. $next = ($rig + 1) % count($rigs);
  1507. break;
  1508. }
  1509. $refresh = "&rig=$rig";
  1510. }
  1511. echo '<tr><td><table cellpadding=0 cellspacing=0 border=0><tr><td nowrap>';
  1512. if ($userlist === null || isset($_SESSION[$ses]))
  1513. {
  1514. if ($prev !== null)
  1515. echo riginput($prev, 'Prev').'&nbsp;';
  1516. echo "<input type=button value='Refresh' onclick='pr(\"$refresh\",null)'>&nbsp;";
  1517. if ($next !== null)
  1518. echo riginput($next, 'Next').'&nbsp;';
  1519. echo '&nbsp;';
  1520. if (count($rigs) > 1)
  1521. echo "<input type=button value='Summary' onclick='pr(\"\",null)'>&nbsp;";
  1522. }
  1523. if ($allowcustompages === true)
  1524. {
  1525. if ($userlist === null || isset($_SESSION[$ses]))
  1526. $list = $customsummarypages;
  1527. else
  1528. {
  1529. if ($userlist !== null && isset($userlist['def']))
  1530. $list = array_flip($userlist['def']);
  1531. else
  1532. $list = array();
  1533. }
  1534. foreach ($list as $pagename => $data)
  1535. echo "<input type=button value='$pagename' onclick='pr(\"&pg=$pagename\",null)'>&nbsp;";
  1536. }
  1537. echo '</td><td width=100%>&nbsp;</td><td nowrap>';
  1538. if ($rig !== null && $readonly === false)
  1539. {
  1540. $rg = '';
  1541. if (count($rigs) > 1)
  1542. $rg = " Rig $rig";
  1543. echo "<input type=button value='Restart' onclick='prc(\"restart&rig=$rig\",\"Restart BFGMiner$rg\")'>";
  1544. echo "&nbsp;<input type=button value='Quit' onclick='prc(\"quit&rig=$rig\",\"Quit BFGMiner$rg\")'>";
  1545. }
  1546. refreshbuttons();
  1547. if (isset($_SESSION[$ses]))
  1548. echo "&nbsp;<input type=button value='Logout' onclick='pr(\"&logout=1\",null)'>";
  1549. else
  1550. if ($userlist !== null)
  1551. echo "&nbsp;<input type=button value='Login' onclick='pr(\"&login=1\",null)'>";
  1552. echo "</td></tr></table></td></tr>";
  1553. }
  1554. #
  1555. function doOne($rig, $preprocess)
  1556. {
  1557. global $haderror, $readonly, $notify, $rigs;
  1558. global $placebuttons;
  1559. htmlhead(true, $rig);
  1560. if ($placebuttons == 'top' || $placebuttons == 'both')
  1561. pagebuttons($rig, null);
  1562. if ($preprocess != null)
  1563. process(array($preprocess => $preprocess), $rig);
  1564. $cmds = array( 'devs' => 'device list',
  1565. 'summary' => 'summary information',
  1566. 'pools' => 'pool list');
  1567. if ($notify)
  1568. $cmds['notify'] = 'device status';
  1569. $cmds['config'] = 'BFGMiner config';
  1570. process($cmds, $rig);
  1571. if ($haderror == false && $readonly === false)
  1572. processgpus($rig);
  1573. if ($placebuttons == 'bot' || $placebuttons == 'both')
  1574. pagebuttons($rig, null);
  1575. }
  1576. #
  1577. global $sectionmap;
  1578. # map sections to their api command
  1579. # DEVS is a special case that will match GPU or PGA
  1580. # so you can have a single table with both in it
  1581. # DATE is hard coded so not in here
  1582. $sectionmap = array(
  1583. 'RIGS' => 'version',
  1584. 'SUMMARY' => 'summary',
  1585. 'POOL' => 'pools',
  1586. 'DEVS' => 'devs',
  1587. 'GPU' => 'devs', // You would normally use DEVS
  1588. 'PGA' => 'devs', // You would normally use DEVS
  1589. 'NOTIFY' => 'notify',
  1590. 'DEVDETAILS' => 'devdetails',
  1591. 'STATS' => 'stats',
  1592. 'CONFIG' => 'config',
  1593. 'COIN' => 'coin');
  1594. #
  1595. function joinfields($section1, $section2, $join, $results)
  1596. {
  1597. global $sectionmap;
  1598. $name1 = $sectionmap[$section1];
  1599. $name2 = $sectionmap[$section2];
  1600. $newres = array();
  1601. // foreach rig in section1
  1602. foreach ($results[$name1] as $rig => $result)
  1603. {
  1604. $status = null;
  1605. // foreach answer section in the rig api call
  1606. foreach ($result as $name1b => $fields1b)
  1607. {
  1608. if ($name1b == 'STATUS')
  1609. {
  1610. // remember the STATUS from section1
  1611. $status = $result[$name1b];
  1612. continue;
  1613. }
  1614. // foreach answer section in the rig api call (for the other api command)
  1615. foreach ($results[$name2][$rig] as $name2b => $fields2b)
  1616. {
  1617. if ($name2b == 'STATUS')
  1618. continue;
  1619. // If match the same field values of fields in $join
  1620. $match = true;
  1621. foreach ($join as $field)
  1622. if ($fields1b[$field] != $fields2b[$field])
  1623. {
  1624. $match = false;
  1625. break;
  1626. }
  1627. if ($match === true)
  1628. {
  1629. if ($status != null)
  1630. {
  1631. $newres[$rig]['STATUS'] = $status;
  1632. $status = null;
  1633. }
  1634. $subsection = $section1.'+'.$section2;
  1635. $subsection .= preg_replace('/[^0-9]/', '', $name1b.$name2b);
  1636. foreach ($fields1b as $nam => $val)
  1637. $newres[$rig][$subsection]["$section1.$nam"] = $val;
  1638. foreach ($fields2b as $nam => $val)
  1639. $newres[$rig][$subsection]["$section2.$nam"] = $val;
  1640. }
  1641. }
  1642. }
  1643. }
  1644. return $newres;
  1645. }
  1646. #
  1647. function join_get_field($field, $fields)
  1648. {
  1649. // : means a string constant otherwise it's a field name
  1650. // ProcID field name is converted to a lowercase letter
  1651. if (substr($field, 0, 1) == ':')
  1652. return substr($field, 1);
  1653. else
  1654. if ($field == 'ProcID')
  1655. return chr(97 + $fields[$field]);
  1656. else
  1657. return $fields[$field];
  1658. }
  1659. #
  1660. function joinlr($section1, $section2, $join, $results)
  1661. {
  1662. global $sectionmap;
  1663. $name1 = $sectionmap[$section1];
  1664. $name2 = $sectionmap[$section2];
  1665. $newres = array();
  1666. // foreach rig in section1
  1667. foreach ($results[$name1] as $rig => $result)
  1668. {
  1669. $status = null;
  1670. // foreach answer section in the rig api call
  1671. foreach ($result as $name1b => $fields1b)
  1672. {
  1673. if ($name1b == 'STATUS')
  1674. {
  1675. // remember the STATUS from section1
  1676. $status = $result[$name1b];
  1677. continue;
  1678. }
  1679. // Build L string to be matched
  1680. $Lval = '';
  1681. foreach ($join['L'] as $field)
  1682. $Lval .= join_get_field($field, $fields1b);
  1683. // foreach answer section in the rig api call (for the other api command)
  1684. foreach ($results[$name2][$rig] as $name2b => $fields2b)
  1685. {
  1686. if ($name2b == 'STATUS')
  1687. continue;
  1688. // Build R string and compare
  1689. $Rval = '';
  1690. foreach ($join['R'] as $field)
  1691. $Rval .= join_get_field($field, $fields2b);
  1692. if ($Lval === $Rval)
  1693. {
  1694. if ($status != null)
  1695. {
  1696. $newres[$rig]['STATUS'] = $status;
  1697. $status = null;
  1698. }
  1699. $subsection = $section1.'+'.$section2;
  1700. $subsection .= preg_replace('/[^0-9]/', '', $name1b.$name2b);
  1701. foreach ($fields1b as $nam => $val)
  1702. $newres[$rig][$subsection]["$section1.$nam"] = $val;
  1703. foreach ($fields2b as $nam => $val)
  1704. $newres[$rig][$subsection]["$section2.$nam"] = $val;
  1705. }
  1706. }
  1707. }
  1708. }
  1709. return $newres;
  1710. }
  1711. #
  1712. function joinall($section1, $section2, $results)
  1713. {
  1714. global $sectionmap;
  1715. $name1 = $sectionmap[$section1];
  1716. $name2 = $sectionmap[$section2];
  1717. $newres = array();
  1718. // foreach rig in section1
  1719. foreach ($results[$name1] as $rig => $result)
  1720. {
  1721. // foreach answer section in the rig api call
  1722. foreach ($result as $name1b => $fields1b)
  1723. {
  1724. if ($name1b == 'STATUS')
  1725. {
  1726. // copy the STATUS from section1
  1727. $newres[$rig][$name1b] = $result[$name1b];
  1728. continue;
  1729. }
  1730. // foreach answer section in the rig api call (for the other api command)
  1731. foreach ($results[$name2][$rig] as $name2b => $fields2b)
  1732. {
  1733. if ($name2b == 'STATUS')
  1734. continue;
  1735. $subsection = $section1.'+'.$section2;
  1736. $subsection .= preg_replace('/[^0-9]/', '', $name1b.$name2b);
  1737. foreach ($fields1b as $nam => $val)
  1738. $newres[$rig][$subsection]["$section1.$nam"] = $val;
  1739. foreach ($fields2b as $nam => $val)
  1740. $newres[$rig][$subsection]["$section2.$nam"] = $val;
  1741. }
  1742. }
  1743. }
  1744. return $newres;
  1745. }
  1746. #
  1747. function joinsections($sections, $results, $errors)
  1748. {
  1749. global $sectionmap;
  1750. // GPU's don't have Name,ID,ProcID fields - so create them
  1751. foreach ($results as $section => $res)
  1752. foreach ($res as $rig => $result)
  1753. foreach ($result as $name => $fields)
  1754. {
  1755. $subname = preg_replace('/[0-9]/', '', $name);
  1756. if ($subname == 'GPU' and isset($result[$name]['GPU']))
  1757. {
  1758. $results[$section][$rig][$name]['Name'] = 'GPU';
  1759. $results[$section][$rig][$name]['ID'] = $result[$name]['GPU'];
  1760. $results[$section][$rig][$name]['ProcID'] = 0;
  1761. }
  1762. }
  1763. foreach ($sections as $section => $fields)
  1764. if ($section != 'DATE' && !isset($sectionmap[$section]))
  1765. {
  1766. $both = explode('+', $section, 2);
  1767. if (count($both) > 1)
  1768. {
  1769. switch($both[0])
  1770. {
  1771. case 'SUMMARY':
  1772. switch($both[1])
  1773. {
  1774. case 'POOL':
  1775. case 'DEVS':
  1776. case 'CONFIG':
  1777. case 'COIN':
  1778. $sectionmap[$section] = $section;
  1779. $results[$section] = joinall($both[0], $both[1], $results);
  1780. break;
  1781. default:
  1782. $errors[] = "Error: Invalid section '$section'";
  1783. break;
  1784. }
  1785. break;
  1786. case 'DEVS':
  1787. switch($both[1])
  1788. {
  1789. case 'NOTIFY':
  1790. case 'DEVDETAILS':
  1791. case 'USBSTATS':
  1792. $join = array('Name', 'ID', 'ProcID');
  1793. $sectionmap[$section] = $section;
  1794. $results[$section] = joinfields($both[0], $both[1], $join, $results);
  1795. break;
  1796. case 'STATS':
  1797. $join = array('L' => array('Name','ID','ProcID'), 'R' => array('ID'));
  1798. $sectionmap[$section] = $section;
  1799. $results[$section] = joinlr($both[0], $both[1], $join, $results);
  1800. break;
  1801. default:
  1802. $errors[] = "Error: Invalid section '$section'";
  1803. break;
  1804. }
  1805. break;
  1806. case 'POOL':
  1807. switch($both[1])
  1808. {
  1809. case 'STATS':
  1810. $join = array('L' => array(':POOL','POOL'), 'R' => array('ID'));
  1811. $sectionmap[$section] = $section;
  1812. $results[$section] = joinlr($both[0], $both[1], $join, $results);
  1813. break;
  1814. default:
  1815. $errors[] = "Error: Invalid section '$section'";
  1816. break;
  1817. }
  1818. break;
  1819. default:
  1820. $errors[] = "Error: Invalid section '$section'";
  1821. break;
  1822. }
  1823. }
  1824. else
  1825. $errors[] = "Error: Invalid section '$section'";
  1826. }
  1827. return array($results, $errors);
  1828. }
  1829. #
  1830. function secmatch($section, $field)
  1831. {
  1832. if ($section == $field)
  1833. return true;
  1834. if ($section == 'DEVS'
  1835. && ($field == 'GPU' || $field == 'PGA'))
  1836. return true;
  1837. return false;
  1838. }
  1839. #
  1840. function customset($showfields, $sum, $section, $rig, $isbutton, $result, $total)
  1841. {
  1842. foreach ($result as $sec => $row)
  1843. {
  1844. $secname = preg_replace('/\d/', '', $sec);
  1845. if ($sec != 'total')
  1846. if (!secmatch($section, $secname))
  1847. continue;
  1848. newrow();
  1849. $when = 0;
  1850. if (isset($result['STATUS']['When']))
  1851. $when = $result['STATUS']['When'];
  1852. if ($isbutton)
  1853. echo rigbutton($rig, $rig, $when, $row);
  1854. else
  1855. {
  1856. list($ignore, $class) = fmt('total', '', '', $when, $row);
  1857. echo "<td align=middle$class>$rig</td>";
  1858. }
  1859. foreach ($showfields as $name => $one)
  1860. {
  1861. if (isset($row[$name]))
  1862. {
  1863. $value = $row[$name];
  1864. if (isset($sum[$section][$name]))
  1865. {
  1866. if (isset($total[$name]))
  1867. $total[$name] += $value;
  1868. else
  1869. $total[$name] = $value;
  1870. }
  1871. }
  1872. else
  1873. {
  1874. if ($sec == 'total' && isset($total[$name]))
  1875. $value = $total[$name];
  1876. else
  1877. $value = null;
  1878. }
  1879. if (strpos($secname, '+') === false)
  1880. list($showvalue, $class) = fmt($secname, $name, $value, $when, $row);
  1881. else
  1882. {
  1883. $parts = explode('.', $name, 2);
  1884. list($showvalue, $class) = fmt($parts[0], $parts[1], $value, $when, $row);
  1885. }
  1886. echo "<td$class align=right>$showvalue</td>";
  1887. }
  1888. endrow();
  1889. }
  1890. return $total;
  1891. }
  1892. #
  1893. function docalc($func, $data)
  1894. {
  1895. switch ($func)
  1896. {
  1897. case 'sum':
  1898. $tot = 0;
  1899. foreach ($data as $val)
  1900. $tot += $val;
  1901. return $tot;
  1902. case 'avg':
  1903. $tot = 0;
  1904. foreach ($data as $val)
  1905. $tot += $val;
  1906. return ($tot / count($data));
  1907. case 'min':
  1908. $ans = null;
  1909. foreach ($data as $val)
  1910. if ($ans === null)
  1911. $ans = $val;
  1912. else
  1913. if ($val < $ans)
  1914. $ans = $val;
  1915. return $ans;
  1916. case 'max':
  1917. $ans = null;
  1918. foreach ($data as $val)
  1919. if ($ans === null)
  1920. $ans = $val;
  1921. else
  1922. if ($val > $ans)
  1923. $ans = $val;
  1924. return $ans;
  1925. case 'lo':
  1926. $ans = null;
  1927. foreach ($data as $val)
  1928. if ($ans === null)
  1929. $ans = $val;
  1930. else
  1931. if (strcasecmp($val, $ans) < 0)
  1932. $ans = $val;
  1933. return $ans;
  1934. case 'hi':
  1935. $ans = null;
  1936. foreach ($data as $val)
  1937. if ($ans === null)
  1938. $ans = $val;
  1939. else
  1940. if (strcasecmp($val, $ans) > 0)
  1941. $ans = $val;
  1942. return $ans;
  1943. case 'count':
  1944. return count($data);
  1945. case 'any':
  1946. default:
  1947. return $data[0];
  1948. }
  1949. }
  1950. #
  1951. function docompare($row, $test)
  1952. {
  1953. // invalid $test data means true
  1954. if (count($test) < 2)
  1955. return true;
  1956. if (isset($row[$test[0]]))
  1957. $val = $row[$test[0]];
  1958. else
  1959. $val = null;
  1960. if ($test[1] == 'set')
  1961. return ($val !== null);
  1962. if ($val === null || count($test) < 3)
  1963. return true;
  1964. switch($test[1])
  1965. {
  1966. case '=':
  1967. return ($val == $test[2]);
  1968. case '<':
  1969. return ($val < $test[2]);
  1970. case '<=':
  1971. return ($val <= $test[2]);
  1972. case '>':
  1973. return ($val > $test[2]);
  1974. case '>=':
  1975. return ($val >= $test[2]);
  1976. case 'eq':
  1977. return (strcasecmp($val, $test[2]) == 0);
  1978. case 'lt':
  1979. return (strcasecmp($val, $test[2]) < 0);
  1980. case 'le':
  1981. return (strcasecmp($val, $test[2]) <= 0);
  1982. case 'gt':
  1983. return (strcasecmp($val, $test[2]) > 0);
  1984. case 'ge':
  1985. return (strcasecmp($val, $test[2]) >= 0);
  1986. default:
  1987. return true;
  1988. }
  1989. }
  1990. #
  1991. function processcompare($which, $ext, $section, $res)
  1992. {
  1993. if (isset($ext[$section][$which]))
  1994. {
  1995. $proc = $ext[$section][$which];
  1996. if ($proc !== null)
  1997. {
  1998. $res2 = array();
  1999. foreach ($res as $rig => $result)
  2000. foreach ($result as $sec => $row)
  2001. {
  2002. $secname = preg_replace('/\d/', '', $sec);
  2003. if (!secmatch($section, $secname))
  2004. $res2[$rig][$sec] = $row;
  2005. else
  2006. {
  2007. $keep = true;
  2008. foreach ($proc as $test)
  2009. if (!docompare($row, $test))
  2010. {
  2011. $keep = false;
  2012. break;
  2013. }
  2014. if ($keep)
  2015. $res2[$rig][$sec] = $row;
  2016. }
  2017. }
  2018. $res = $res2;
  2019. }
  2020. }
  2021. return $res;
  2022. }
  2023. #
  2024. function processext($ext, $section, $res)
  2025. {
  2026. $res = processcompare('where', $ext, $section, $res);
  2027. if (isset($ext[$section]['group']))
  2028. {
  2029. $grp = $ext[$section]['group'];
  2030. $calc = $ext[$section]['calc'];
  2031. if ($grp !== null)
  2032. {
  2033. $interim = array();
  2034. $res2 = array();
  2035. $cou = 0;
  2036. foreach ($res as $rig => $result)
  2037. foreach ($result as $sec => $row)
  2038. {
  2039. $secname = preg_replace('/\d/', '', $sec);
  2040. if (!secmatch($section, $secname))
  2041. {
  2042. // STATUS may be problematic ...
  2043. if (!isset($res2[$sec]))
  2044. $res2[$sec] = $row;
  2045. }
  2046. else
  2047. {
  2048. $grpkey = '';
  2049. $newrow = array();
  2050. foreach ($grp as $field)
  2051. {
  2052. if (isset($row[$field]))
  2053. {
  2054. $grpkey .= $row[$field].'.';
  2055. $newrow[$field] = $row[$field];
  2056. }
  2057. else
  2058. $grpkey .= '.';
  2059. }
  2060. if (!isset($interim[$grpkey]))
  2061. {
  2062. $interim[$grpkey]['grp'] = $newrow;
  2063. $interim[$grpkey]['sec'] = $secname.$cou;
  2064. $cou++;
  2065. }
  2066. if ($calc !== null)
  2067. foreach ($calc as $field => $func)
  2068. {
  2069. if (!isset($interim[$grpkey]['cal'][$field]))
  2070. $interim[$grpkey]['cal'][$field] = array();
  2071. $interim[$grpkey]['cal'][$field][] = $row[$field];
  2072. }
  2073. }
  2074. }
  2075. // Build the rest of $res2 from $interim
  2076. foreach ($interim as $rowkey => $row)
  2077. {
  2078. $key = $row['sec'];
  2079. foreach ($row['grp'] as $field => $value)
  2080. $res2[$key][$field] = $value;
  2081. foreach ($row['cal'] as $field => $data)
  2082. $res2[$key][$field] = docalc($calc[$field], $data);
  2083. }
  2084. $res = array('' => $res2);
  2085. }
  2086. }
  2087. return processcompare('having', $ext, $section, $res);
  2088. }
  2089. #
  2090. function processcustompage($pagename, $sections, $sum, $ext, $namemap)
  2091. {
  2092. global $sectionmap;
  2093. global $miner, $port;
  2094. global $rigs, $error;
  2095. global $warnfont, $warnoff;
  2096. global $dfmt;
  2097. global $readonly, $showndate;
  2098. $cmds = array();
  2099. $errors = array();
  2100. foreach ($sections as $section => $fields)
  2101. {
  2102. $all = explode('+', $section);
  2103. foreach ($all as $section)
  2104. {
  2105. if (isset($sectionmap[$section]))
  2106. {
  2107. $cmd = $sectionmap[$section];
  2108. if (!isset($cmds[$cmd]))
  2109. $cmds[$cmd] = 1;
  2110. }
  2111. else
  2112. if ($section != 'DATE')
  2113. $errors[] = "Error: unknown section '$section' in custom summary page '$pagename'";
  2114. }
  2115. }
  2116. $results = array();
  2117. foreach ($rigs as $num => $rig)
  2118. {
  2119. $parts = explode(':', $rig, 3);
  2120. if (count($parts) >= 2)
  2121. {
  2122. $miner = $parts[0];
  2123. $port = $parts[1];
  2124. if (count($parts) > 2)
  2125. $name = $parts[2];
  2126. else
  2127. $name = $rig;
  2128. foreach ($cmds as $cmd => $one)
  2129. {
  2130. $process = api($name, $cmd);
  2131. if ($error != null)
  2132. {
  2133. $errors[] = "Error getting $cmd for $name $warnfont$error$warnoff";
  2134. break;
  2135. }
  2136. else
  2137. $results[$cmd][$num] = $process;
  2138. }
  2139. }
  2140. }
  2141. $shownsomething = false;
  2142. if (count($results) > 0)
  2143. {
  2144. list($results, $errors) = joinsections($sections, $results, $errors);
  2145. $first = true;
  2146. foreach ($sections as $section => $fields)
  2147. {
  2148. if ($section === 'DATE')
  2149. {
  2150. if ($shownsomething)
  2151. otherrow('<td>&nbsp;</td>');
  2152. newtable();
  2153. showdatetime();
  2154. endtable();
  2155. // On top of the next table
  2156. $shownsomething = false;
  2157. continue;
  2158. }
  2159. if ($section === 'RIGS')
  2160. {
  2161. if ($shownsomething)
  2162. otherrow('<td>&nbsp;</td>');
  2163. newtable();
  2164. showrigs($results['version'], 'Rig', '');
  2165. endtable();
  2166. $shownsomething = true;
  2167. continue;
  2168. }
  2169. if (isset($results[$sectionmap[$section]]))
  2170. {
  2171. $rigresults = processext($ext, $section, $results[$sectionmap[$section]]);
  2172. $showfields = array();
  2173. $showhead = array();
  2174. foreach ($fields as $field)
  2175. foreach ($rigresults as $result)
  2176. foreach ($result as $sec => $row)
  2177. {
  2178. $secname = preg_replace('/\d/', '', $sec);
  2179. if (secmatch($section, $secname))
  2180. {
  2181. if ($field === '*')
  2182. {
  2183. foreach ($row as $f => $v)
  2184. {
  2185. $showfields[$f] = 1;
  2186. $map = $section.'.'.$f;
  2187. if (isset($namemap[$map]))
  2188. $showhead[$namemap[$map]] = 1;
  2189. else
  2190. $showhead[$f] = 1;
  2191. }
  2192. }
  2193. elseif (isset($row[$field]))
  2194. {
  2195. $showfields[$field] = 1;
  2196. $map = $section.'.'.$field;
  2197. if (isset($namemap[$map]))
  2198. $showhead[$namemap[$map]] = 1;
  2199. else
  2200. $showhead[$field] = 1;
  2201. }
  2202. }
  2203. }
  2204. if (count($showfields) > 0)
  2205. {
  2206. if ($shownsomething)
  2207. otherrow('<td>&nbsp;</td>');
  2208. newtable();
  2209. if (count($rigresults) == 1 && isset($rigresults['']))
  2210. $ri = array('' => 1) + $showhead;
  2211. else
  2212. $ri = array('Rig' => 1) + $showhead;
  2213. showhead('', $ri, true);
  2214. $total = array();
  2215. $add = array('total' => array());
  2216. foreach ($rigresults as $num => $result)
  2217. $total = customset($showfields, $sum, $section, $num, true, $result, $total);
  2218. if (count($total) > 0)
  2219. customset($showfields, $sum, $section, '&Sigma;', false, $add, $total);
  2220. $first = false;
  2221. endtable();
  2222. $shownsomething = true;
  2223. }
  2224. }
  2225. }
  2226. }
  2227. if (count($errors) > 0)
  2228. {
  2229. if (count($results) > 0)
  2230. otherrow('<td>&nbsp;</td>');
  2231. foreach ($errors as $err)
  2232. otherrow("<td colspan=100>$err</td>");
  2233. }
  2234. }
  2235. #
  2236. function showcustompage($pagename)
  2237. {
  2238. global $customsummarypages;
  2239. global $placebuttons;
  2240. htmlhead(false, null, $pagename);
  2241. if ($placebuttons == 'top' || $placebuttons == 'both')
  2242. pagebuttons(null, $pagename);
  2243. if (!isset($customsummarypages[$pagename]))
  2244. {
  2245. otherrow("<td colspan=100>Unknown custom summary page '$pagename'</td>");
  2246. return;
  2247. }
  2248. $c = count($customsummarypages[$pagename]);
  2249. if ($c < 2 || $c > 3)
  2250. {
  2251. $rw = "<td colspan=100>Invalid custom summary page '$pagename' (";
  2252. $rw .= count($customsummarypages[$pagename]).')</td>';
  2253. otherrow($rw);
  2254. return;
  2255. }
  2256. $page = $customsummarypages[$pagename][0];
  2257. $namemap = array();
  2258. foreach ($page as $name => $fields)
  2259. {
  2260. if ($fields === null)
  2261. $page[$name] = array();
  2262. else
  2263. foreach ($fields as $num => $field)
  2264. {
  2265. $pos = strpos($field, '=');
  2266. if ($pos !== false)
  2267. {
  2268. $names = explode('=', $field, 2);
  2269. if (strlen($names[1]) > 0)
  2270. $namemap[$name.'.'.$names[0]] = $names[1];
  2271. $page[$name][$num] = $names[0];
  2272. }
  2273. }
  2274. }
  2275. $ext = null;
  2276. if (isset($customsummarypages[$pagename][2]))
  2277. $ext = $customsummarypages[$pagename][2];
  2278. $sum = $customsummarypages[$pagename][1];
  2279. if ($sum === null)
  2280. $sum = array();
  2281. // convert them to searchable via isset()
  2282. foreach ($sum as $section => $fields)
  2283. {
  2284. $newfields = array();
  2285. foreach ($fields as $field)
  2286. $newfields[$field] = 1;
  2287. $sum[$section] = $newfields;
  2288. }
  2289. if (count($page) <= 1)
  2290. {
  2291. otherrow("<td colspan=100>Invalid custom summary page '$pagename' no content </td>");
  2292. return;
  2293. }
  2294. processcustompage($pagename, $page, $sum, $ext, $namemap);
  2295. if ($placebuttons == 'bot' || $placebuttons == 'both')
  2296. pagebuttons(null, $pagename);
  2297. }
  2298. #
  2299. function onlylogin()
  2300. {
  2301. global $here;
  2302. htmlhead(false, null, null, true);
  2303. ?>
  2304. <tr height=15%><td>&nbsp;</td></tr>
  2305. <tr><td>
  2306. <center>
  2307. <table width=384 height=368 cellpadding=0 cellspacing=0 border=0>
  2308. <tr><td>
  2309. <table width=100% height=100% border=0 align=center cellpadding=5 cellspacing=0>
  2310. <tr><td><form action='<?php echo $here; ?>' method=post>
  2311. <table width=200 border=0 align=center cellpadding=5 cellspacing=0>
  2312. <tr><td height=120 colspan=2>&nbsp;</td></tr>
  2313. <tr><td colspan=2 align=center valign=middle>
  2314. <h2>LOGIN</h2></td></tr>
  2315. <tr><td align=center valign=middle><div align=right>Username:</div></td>
  2316. <td height=33 align=center valign=middle>
  2317. <input type=text name=rut size=18></td></tr>
  2318. <tr><td align=center valign=middle><div align=right>Password:</div></td>
  2319. <td height=33 align=center valign=middle>
  2320. <input type=password name=roh size=18></td></tr>
  2321. <tr valign=top><td></td><td><input type=submit value=Login>
  2322. </td></tr>
  2323. </table></form></td></tr>
  2324. </table></td></tr>
  2325. </table></center>
  2326. </td></tr>
  2327. <?php
  2328. }
  2329. #
  2330. function checklogin()
  2331. {
  2332. global $allowcustompages, $customsummarypages;
  2333. global $readonly, $userlist, $ses;
  2334. $out = trim(getparam('logout', true));
  2335. if ($out !== null && $out !== '' && isset($_SESSION[$ses]))
  2336. unset($_SESSION[$ses]);
  2337. $login = trim(getparam('login', true));
  2338. if ($login !== null && $login !== '')
  2339. {
  2340. if (isset($_SESSION[$ses]))
  2341. unset($_SESSION[$ses]);
  2342. onlylogin();
  2343. return 'login';
  2344. }
  2345. if ($userlist === null)
  2346. return false;
  2347. $rut = trim(getparam('rut', true));
  2348. $roh = trim(getparam('roh', true));
  2349. if (($rut !== null && $rut !== '') || ($roh !== null && $roh !== ''))
  2350. {
  2351. if (isset($_SESSION[$ses]))
  2352. unset($_SESSION[$ses]);
  2353. if ($rut !== null && $rut !== '' && $roh !== null && $roh !== '')
  2354. {
  2355. if (isset($userlist['sys']) && isset($userlist['sys'][$rut])
  2356. && ($userlist['sys'][$rut] === $roh))
  2357. {
  2358. $_SESSION[$ses] = true;
  2359. return false;
  2360. }
  2361. if (isset($userlist['usr']) && isset($userlist['usr'][$rut])
  2362. && ($userlist['usr'][$rut] === $roh))
  2363. {
  2364. $_SESSION[$ses] = false;
  2365. $readonly = true;
  2366. return false;
  2367. }
  2368. }
  2369. }
  2370. if (isset($_SESSION[$ses]))
  2371. {
  2372. if ($_SESSION[$ses] == false)
  2373. $readonly = true;
  2374. return false;
  2375. }
  2376. if (isset($userlist['def']) && $allowcustompages === true)
  2377. {
  2378. // Ensure at least one exists
  2379. foreach ($userlist['def'] as $pg)
  2380. if (isset($customsummarypages[$pg]))
  2381. return true;
  2382. }
  2383. onlylogin();
  2384. return 'login';
  2385. }
  2386. #
  2387. function display()
  2388. {
  2389. global $miner, $port;
  2390. global $readonly, $notify, $rigs;
  2391. global $ignorerefresh, $autorefresh;
  2392. global $allowcustompages, $customsummarypages;
  2393. global $placebuttons;
  2394. global $userlist, $ses;
  2395. $pagesonly = checklogin();
  2396. if ($pagesonly === 'login')
  2397. return;
  2398. if ($rigs == null or count($rigs) == 0)
  2399. {
  2400. otherrow("<td>No rigs defined</td>");
  2401. return;
  2402. }
  2403. if ($ignorerefresh == false)
  2404. {
  2405. $ref = trim(getparam('ref', true));
  2406. if ($ref != null && $ref != '')
  2407. $autorefresh = intval($ref);
  2408. }
  2409. if ($pagesonly !== true)
  2410. {
  2411. $rig = trim(getparam('rig', true));
  2412. $arg = trim(getparam('arg', true));
  2413. $preprocess = null;
  2414. if ($arg != null and $arg != '')
  2415. {
  2416. if ($rig != null and $rig != '' and $rig >= 0 and $rig < count($rigs))
  2417. {
  2418. $parts = explode(':', $rigs[$rig], 3);
  2419. if (count($parts) >= 2)
  2420. {
  2421. $miner = $parts[0];
  2422. $port = $parts[1];
  2423. if ($readonly !== true)
  2424. $preprocess = $arg;
  2425. }
  2426. }
  2427. }
  2428. }
  2429. if ($allowcustompages === true)
  2430. {
  2431. $pg = trim(getparam('pg', true));
  2432. if ($pagesonly === true)
  2433. {
  2434. if ($pg !== null && $pg !== '')
  2435. {
  2436. if ($userlist !== null && isset($userlist['def'])
  2437. && !in_array($pg, $userlist['def']))
  2438. $pg = null;
  2439. }
  2440. else
  2441. {
  2442. if ($userlist !== null && isset($userlist['def']))
  2443. foreach ($userlist['def'] as $pglook)
  2444. if (isset($customsummarypages[$pglook]))
  2445. {
  2446. $pg = $pglook;
  2447. break;
  2448. }
  2449. }
  2450. }
  2451. if ($pg !== null && $pg !== '')
  2452. {
  2453. showcustompage($pg);
  2454. return;
  2455. }
  2456. }
  2457. if ($pagesonly === true)
  2458. {
  2459. onlylogin();
  2460. return;
  2461. }
  2462. if (count($rigs) == 1)
  2463. {
  2464. $parts = explode(':', $rigs[0], 3);
  2465. if (count($parts) >= 2)
  2466. {
  2467. $miner = $parts[0];
  2468. $port = $parts[1];
  2469. doOne(0, $preprocess);
  2470. }
  2471. else
  2472. otherrow('<td>Invalid "$rigs" array</td>');
  2473. return;
  2474. }
  2475. if ($rig != null and $rig != '' and $rig >= 0 and $rig < count($rigs))
  2476. {
  2477. $parts = explode(':', $rigs[$rig], 3);
  2478. if (count($parts) >= 2)
  2479. {
  2480. $miner = $parts[0];
  2481. $port = $parts[1];
  2482. doOne($rig, $preprocess);
  2483. }
  2484. else
  2485. otherrow('<td>Invalid "$rigs" array</td>');
  2486. return;
  2487. }
  2488. htmlhead(false, null);
  2489. if ($placebuttons == 'top' || $placebuttons == 'both')
  2490. pagebuttons(null, null);
  2491. if ($preprocess != null)
  2492. process(array($preprocess => $preprocess), $rig);
  2493. newtable();
  2494. doforeach('version', 'rig summary', array(), array(), true);
  2495. $sum = array('MHS av', 'Getworks', 'Found Blocks', 'Accepted', 'Rejected', 'Discarded', 'Stale', 'Utility', 'Local Work', 'Total MH');
  2496. doforeach('summary', 'summary information', $sum, array(), false);
  2497. endtable();
  2498. otherrow('<td><br><br></td>');
  2499. newtable();
  2500. doforeach('devs', 'device list', $sum, array(''=>'','ProcID'=>'','ID'=>'','Name'=>''), false);
  2501. endtable();
  2502. otherrow('<td><br><br></td>');
  2503. newtable();
  2504. doforeach('pools', 'pool list', $sum, array(''=>''), false);
  2505. endtable();
  2506. if ($placebuttons == 'bot' || $placebuttons == 'both')
  2507. pagebuttons(null, null);
  2508. }
  2509. #
  2510. display();
  2511. #
  2512. ?>
  2513. </table></td></tr></table>
  2514. </body></html>