miner.php 49 KB

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