miner.php 47 KB

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