miner.php 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238
  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 BFGMiner '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 BFGMiner 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 'PGA.Temperature':
  643. case 'GPU.Temperature':
  644. case 'DEVS.Temperature':
  645. $ret = $value.'&deg;C';
  646. if (!isset($alldata['GPU']))
  647. break;
  648. case 'GPU.GPU Clock':
  649. case 'DEVS.GPU Clock':
  650. case 'GPU.Memory Clock':
  651. case 'DEVS.Memory Clock':
  652. case 'GPU.GPU Voltage':
  653. case 'DEVS.GPU Voltage':
  654. case 'GPU.GPU Activity':
  655. case 'DEVS.GPU Activity':
  656. if ($value == 0)
  657. $class = $warnclass;
  658. break;
  659. case 'GPU.Fan Percent':
  660. case 'DEVS.Fan Percent':
  661. if ($value == 0)
  662. $class = $warnclass;
  663. else
  664. {
  665. if ($value == 100)
  666. $class = $errorclass;
  667. else
  668. if ($value > 85)
  669. $class = $warnclass;
  670. }
  671. break;
  672. case 'GPU.Fan Speed':
  673. case 'DEVS.Fan Speed':
  674. if ($value == 0)
  675. $class = $warnclass;
  676. else
  677. if (isset($alldata['Fan Percent']))
  678. {
  679. $test = $alldata['Fan Percent'];
  680. if ($test == 100)
  681. $class = $errorclass;
  682. else
  683. if ($test > 85)
  684. $class = $warnclass;
  685. }
  686. break;
  687. case 'GPU.MHS av':
  688. case 'PGA.MHS av':
  689. case 'DEVS.MHS av':
  690. case 'SUMMARY.MHS av':
  691. case 'total.MHS av':
  692. $parts = explode('.', $value, 2);
  693. if (count($parts) == 1)
  694. $dec = '';
  695. else
  696. $dec = '.'.$parts[1];
  697. $ret = number_format((float)$parts[0]).$dec;
  698. if ($value == 0)
  699. $class = $errorclass;
  700. else
  701. if (isset($alldata['Difficulty Accepted'])
  702. && isset($alldata['Accepted'])
  703. && isset($alldata['Utility'])
  704. && ($alldata['Difficulty Accepted'] > 0)
  705. && ($alldata['Accepted'] > 0))
  706. {
  707. $expected = 60 * $value * (pow(10, 6) / pow(2, 32));
  708. if ($expected == 0)
  709. $expected = 0.000001; // 1 H/s
  710. $da = $alldata['Difficulty Accepted'];
  711. $a = $alldata['Accepted'];
  712. $expected /= ($da / $a);
  713. $ratio = $alldata['Utility'] / $expected;
  714. if ($ratio < 0.9)
  715. $class = $hiclass;
  716. else
  717. if ($ratio > 1.1)
  718. $class = $loclass;
  719. }
  720. break;
  721. case 'GPU.Total MH':
  722. case 'PGA.Total MH':
  723. case 'DEVS.Total MH':
  724. case 'SUMMARY.Total MH':
  725. case 'total.Total MH':
  726. case 'SUMMARY.Getworks':
  727. case 'POOL.Getworks':
  728. case 'total.Getworks':
  729. case 'GPU.Accepted':
  730. case 'PGA.Accepted':
  731. case 'DEVS.Accepted':
  732. case 'SUMMARY.Accepted':
  733. case 'POOL.Accepted':
  734. case 'total.Accepted':
  735. case 'GPU.Rejected':
  736. case 'PGA.Rejected':
  737. case 'DEVS.Rejected':
  738. case 'SUMMARY.Rejected':
  739. case 'POOL.Rejected':
  740. case 'total.Rejected':
  741. case 'SUMMARY.Local Work':
  742. case 'total.Local Work':
  743. case 'SUMMARY.Discarded':
  744. case 'POOL.Discarded':
  745. case 'total.Discarded':
  746. $parts = explode('.', $value, 2);
  747. if (count($parts) == 1)
  748. $dec = '';
  749. else
  750. $dec = '.'.$parts[1];
  751. $ret = number_format((float)$parts[0]).$dec;
  752. break;
  753. case 'GPU.Status':
  754. case 'PGA.Status':
  755. case 'DEVS.Status':
  756. case 'POOL.Status':
  757. if ($value != 'Alive')
  758. $class = $errorclass;
  759. break;
  760. case 'GPU.Enabled':
  761. case 'PGA.Enabled':
  762. case 'DEVS.Enabled':
  763. if ($value != 'Y')
  764. $class = $warnclass;
  765. break;
  766. case 'STATUS.When':
  767. case 'COIN.Current Block Time':
  768. $ret = date($dfmt, $value);
  769. break;
  770. case 'BUTTON.Rig':
  771. case 'BUTTON.Pool':
  772. case 'BUTTON.GPU':
  773. $ret = $value;
  774. break;
  775. }
  776. if ($section == 'NOTIFY' && substr($name, 0, 1) == '*' && $value != '0')
  777. $class = $errorclass;
  778. if ($class == '' && $section != 'POOL')
  779. $class = classlastshare($when, $alldata, $lstclass, $lstclass);
  780. if ($class == '' && $section == 'total')
  781. $class = $totclass;
  782. if ($class == '' && ($rownum % 2) == 0)
  783. $class = $c2class;
  784. if ($ret === '')
  785. $ret = $b;
  786. return array($ret, $class);
  787. }
  788. #
  789. global $poolcmd;
  790. $poolcmd = array( 'Switch to' => 'switchpool',
  791. 'Enable' => 'enablepool',
  792. 'Disable' => 'disablepool',
  793. 'Remove' => 'removepool' );
  794. #
  795. function showhead($cmd, $values, $justnames = false)
  796. {
  797. global $poolcmd, $readonly;
  798. newrow();
  799. foreach ($values as $name => $value)
  800. {
  801. if ($name == '0' or $name == '')
  802. $name = '&nbsp;';
  803. echo "<td valign=bottom class=h>$name</td>";
  804. }
  805. if ($justnames === false && $cmd == 'pools' && $readonly === false)
  806. foreach ($poolcmd as $name => $pcmd)
  807. echo "<td valign=bottom class=h>$name</td>";
  808. endrow();
  809. }
  810. #
  811. function showdatetime()
  812. {
  813. global $dfmt;
  814. otherrow('<td class=sta>Date: '.date($dfmt).'</td>');
  815. }
  816. #
  817. global $singlerigsum;
  818. $singlerigsum = array(
  819. 'devs' => array('MHS av' => 1, 'MHS 5s' => 1, 'Accepted' => 1, 'Rejected' => 1,
  820. 'Hardware Errors' => 1, 'Utility' => 1, 'Total MH' => 1),
  821. 'pools' => array('Getworks' => 1, 'Accepted' => 1, 'Rejected' => 1, 'Discarded' => 1,
  822. 'Stale' => 1, 'Get Failures' => 1, 'Remote Failures' => 1),
  823. 'notify' => array('*' => 1));
  824. #
  825. function showtotal($total, $when, $oldvalues)
  826. {
  827. global $rigtotals;
  828. list($showvalue, $class) = fmt('total', '', 'Total:', $when, null);
  829. echo "<td$class align=right>$showvalue</td>";
  830. $skipfirst = true;
  831. foreach ($oldvalues as $name => $value)
  832. {
  833. if ($skipfirst === true)
  834. {
  835. $skipfirst = false;
  836. continue;
  837. }
  838. if (isset($total[$name]))
  839. $newvalue = $total[$name];
  840. else
  841. $newvalue = '';
  842. list($showvalue, $class) = fmt('total', $name, $newvalue, $when, null);
  843. echo "<td$class";
  844. if ($rigtotals === true)
  845. echo ' align=right';
  846. echo ">$showvalue</td>";
  847. }
  848. }
  849. #
  850. function details($cmd, $list, $rig)
  851. {
  852. global $dfmt, $poolcmd, $readonly, $showndate;
  853. global $rownum, $rigtotals, $forcerigtotals, $singlerigsum;
  854. $when = 0;
  855. $stas = array('S' => 'Success', 'W' => 'Warning', 'I' => 'Informational', 'E' => 'Error', 'F' => 'Fatal');
  856. newtable();
  857. if ($showndate === false)
  858. {
  859. showdatetime();
  860. endtable();
  861. newtable();
  862. $showndate = true;
  863. }
  864. if (isset($list['STATUS']))
  865. {
  866. newrow();
  867. echo '<td>Computer: '.$list['STATUS']['Description'].'</td>';
  868. if (isset($list['STATUS']['When']))
  869. {
  870. echo '<td>When: '.date($dfmt, $list['STATUS']['When']).'</td>';
  871. $when = $list['STATUS']['When'];
  872. }
  873. $sta = $list['STATUS']['STATUS'];
  874. echo '<td>Status: '.$stas[$sta].'</td>';
  875. echo '<td>Message: '.$list['STATUS']['Msg'].'</td>';
  876. endrow();
  877. }
  878. if ($rigtotals === true && isset($singlerigsum[$cmd]))
  879. $dototal = $singlerigsum[$cmd];
  880. else
  881. $dototal = array();
  882. $total = array();
  883. $section = '';
  884. $oldvalues = null;
  885. foreach ($list as $item => $values)
  886. {
  887. if ($item == 'STATUS')
  888. continue;
  889. $sectionname = preg_replace('/\d/', '', $item);
  890. // Handle 'devs' possibly containing >1 table
  891. if ($sectionname != $section)
  892. {
  893. if ($oldvalues != null && count($total) > 0
  894. && ($rownum > 2 || $forcerigtotals === true))
  895. showtotal($total, $when, $oldvalues);
  896. endtable();
  897. newtable();
  898. showhead($cmd, $values);
  899. $section = $sectionname;
  900. }
  901. newrow();
  902. foreach ($values as $name => $value)
  903. {
  904. list($showvalue, $class) = fmt($section, $name, $value, $when, $values);
  905. echo "<td$class";
  906. if ($rigtotals === true)
  907. echo ' align=right';
  908. echo ">$showvalue</td>";
  909. if (isset($dototal[$name])
  910. || (isset($dototal['*']) and substr($name, 0, 1) == '*'))
  911. {
  912. if (isset($total[$name]))
  913. $total[$name] += $value;
  914. else
  915. $total[$name] = $value;
  916. }
  917. }
  918. if ($cmd == 'pools' && $readonly === false)
  919. {
  920. reset($values);
  921. $pool = current($values);
  922. foreach ($poolcmd as $name => $pcmd)
  923. {
  924. list($ignore, $class) = fmt('BUTTON', 'Pool', '', $when, $values);
  925. echo "<td$class>";
  926. if ($pool === false)
  927. echo '&nbsp;';
  928. else
  929. {
  930. echo "<input type=button value='Pool $pool'";
  931. echo " onclick='prc(\"$pcmd|$pool&rig=$rig\",\"$name Pool $pool\")'>";
  932. }
  933. echo '</td>';
  934. }
  935. }
  936. endrow();
  937. $oldvalues = $values;
  938. }
  939. if ($oldvalues != null && count($total) > 0
  940. && ($rownum > 2 || $forcerigtotals === true))
  941. showtotal($total, $when, $oldvalues);
  942. endtable();
  943. }
  944. #
  945. global $devs;
  946. $devs = null;
  947. #
  948. function gpubuttons($count, $rig)
  949. {
  950. global $devs;
  951. $basic = array( 'GPU', 'Enable', 'Disable', 'Restart' );
  952. $options = array( 'intensity' => 'Intensity',
  953. 'fan' => 'Fan Percent',
  954. 'engine' => 'GPU Clock',
  955. 'mem' => 'Memory Clock',
  956. 'vddc' => 'GPU Voltage' );
  957. newtable();
  958. newrow();
  959. foreach ($basic as $head)
  960. echo "<td class=h>$head</td>";
  961. foreach ($options as $name => $des)
  962. echo "<td class=h nowrap>$des</td>";
  963. $n = 0;
  964. for ($c = 0; $c < $count; $c++)
  965. {
  966. endrow();
  967. newrow();
  968. foreach ($basic as $name)
  969. {
  970. list($ignore, $class) = fmt('BUTTON', 'GPU', '', 0, null);
  971. echo "<td$class>";
  972. if ($name == 'GPU')
  973. echo $c;
  974. else
  975. {
  976. echo "<input type=button value='$name $c' onclick='prs(\"gpu";
  977. echo strtolower($name);
  978. echo "|$c\",$rig)'>";
  979. }
  980. echo '</td>';
  981. }
  982. foreach ($options as $name => $des)
  983. {
  984. list($ignore, $class) = fmt('BUTTON', 'GPU', '', 0, null);
  985. echo "<td$class>";
  986. if (!isset($devs["GPU$c"][$des]))
  987. echo '&nbsp;';
  988. else
  989. {
  990. $value = $devs["GPU$c"][$des];
  991. echo "<input type=button value='Set $c:' onclick='prs2(\"gpu$name|$c\",$n,$rig)'>";
  992. echo "<input size=7 type=text name=gi$n value='$value' id=gi$n>";
  993. $n++;
  994. }
  995. echo '</td>';
  996. }
  997. }
  998. endrow();
  999. endtable();
  1000. }
  1001. #
  1002. function processgpus($rig)
  1003. {
  1004. global $error;
  1005. global $warnfont, $warnoff;
  1006. $gpus = api($rig, 'gpucount');
  1007. if ($error != null)
  1008. otherrow("<td>Error getting GPU count: $warnfont$error$warnoff</td>");
  1009. else
  1010. {
  1011. if (!isset($gpus['GPUS']['Count']))
  1012. {
  1013. $rw = '<td>No GPU count returned: '.$warnfont;
  1014. $rw .= $gpus['STATUS']['STATUS'].' '.$gpus['STATUS']['Msg'];
  1015. $rw .= $warnoff.'</td>';
  1016. otherrow($rw);
  1017. }
  1018. else
  1019. {
  1020. $count = $gpus['GPUS']['Count'];
  1021. if ($count == 0)
  1022. otherrow('<td>No GPUs</td>');
  1023. else
  1024. gpubuttons($count, $rig);
  1025. }
  1026. }
  1027. }
  1028. #
  1029. function showpoolinputs($rig, $ans)
  1030. {
  1031. global $readonly, $poolinputs;
  1032. if ($readonly === true || $poolinputs === false)
  1033. return;
  1034. newtable();
  1035. newrow();
  1036. $inps = array('Pool URL' => array('purl', 20),
  1037. 'Worker Name' => array('pwork', 10),
  1038. 'Worker Password' => array('ppass', 10));
  1039. $b = '&nbsp;';
  1040. echo "<td align=right class=h> Add a pool: </td><td>";
  1041. foreach ($inps as $text => $name)
  1042. echo "$text: <input name='".$name[0]."' id='".$name[0]."' value='' type=text size=".$name[1]."> ";
  1043. echo "</td><td align=middle><input type=button value='Add' onclick='pla($rig)'></td>";
  1044. endrow();
  1045. if (count($ans) > 1)
  1046. {
  1047. newrow();
  1048. echo '<td align=right class=h> Set pool priorities: </td>';
  1049. echo "<td> Comma list of pool numbers: <input type=text name=prio id=prio size=20>";
  1050. echo "</td><td align=middle><input type=button value='Set' onclick='psp($rig)'></td>";
  1051. endrow();
  1052. }
  1053. endtable();
  1054. }
  1055. #
  1056. function process($cmds, $rig)
  1057. {
  1058. global $error, $devs;
  1059. global $warnfont, $warnoff;
  1060. $count = count($cmds);
  1061. foreach ($cmds as $cmd => $des)
  1062. {
  1063. $process = api($rig, $cmd);
  1064. if ($error != null)
  1065. {
  1066. otherrow("<td colspan=100>Error getting $des: $warnfont$error$warnoff</td>");
  1067. break;
  1068. }
  1069. else
  1070. {
  1071. details($cmd, $process, $rig);
  1072. if ($cmd == 'devs')
  1073. $devs = $process;
  1074. if ($cmd == 'pools')
  1075. showpoolinputs($rig, $process);
  1076. # Not after the last one
  1077. if (--$count > 0)
  1078. otherrow('<td><br><br></td>');
  1079. }
  1080. }
  1081. }
  1082. #
  1083. function rigname($rig, $rigname)
  1084. {
  1085. global $rigs;
  1086. if (isset($rigs[$rig]))
  1087. {
  1088. $parts = explode(':', $rigs[$rig], 3);
  1089. if (count($parts) == 3)
  1090. $rigname = $parts[2];
  1091. }
  1092. return $rigname;
  1093. }
  1094. #
  1095. function riginput($rig, $rigname)
  1096. {
  1097. $rigname = rigname($rig, $rigname);
  1098. return "<input type=button value='$rigname' onclick='pr(\"&rig=$rig\",null)'>";
  1099. }
  1100. #
  1101. function rigbutton($rig, $rigname, $when, $row)
  1102. {
  1103. list($value, $class) = fmt('BUTTON', 'Rig', '', $when, $row);
  1104. return "<td align=middle$class>".riginput($rig, $rigname).'</td>';
  1105. }
  1106. #
  1107. function showrigs($anss, $headname, $rigname)
  1108. {
  1109. $dthead = array($headname => 1, 'STATUS' => 1, 'Description' => 1, 'When' => 1, 'API' => 1, 'CGMiner' => 1);
  1110. showhead('', $dthead);
  1111. foreach ($anss as $rig => $ans)
  1112. {
  1113. if ($ans == null)
  1114. continue;
  1115. newrow();
  1116. $when = 0;
  1117. if (isset($ans['STATUS']['When']))
  1118. $when = $ans['STATUS']['When'];
  1119. foreach ($ans as $item => $row)
  1120. {
  1121. if ($item != 'STATUS' && $item != 'VERSION')
  1122. continue;
  1123. foreach ($dthead as $name => $x)
  1124. {
  1125. if ($item == 'STATUS' && $name == $headname)
  1126. echo rigbutton($rig, $rigname.$rig, $when, null);
  1127. else
  1128. {
  1129. if (isset($row[$name]))
  1130. {
  1131. list($showvalue, $class) = fmt('STATUS', $name, $row[$name], $when, null);
  1132. echo "<td$class align=right>$showvalue</td>";
  1133. }
  1134. }
  1135. }
  1136. }
  1137. endrow();
  1138. }
  1139. }
  1140. #
  1141. # $head is a hack but this is just a demo anyway :)
  1142. function doforeach($cmd, $des, $sum, $head, $datetime)
  1143. {
  1144. global $miner, $port;
  1145. global $error, $readonly, $notify, $rigs;
  1146. global $warnfont, $warnoff, $dfmt;
  1147. global $rigerror;
  1148. $when = 0;
  1149. $header = $head;
  1150. $anss = array();
  1151. $count = 0;
  1152. $preverr = count($rigerror);
  1153. foreach ($rigs as $num => $rig)
  1154. {
  1155. $anss[$num] = null;
  1156. if (isset($rigerror[$rig]))
  1157. continue;
  1158. $parts = explode(':', $rig, 3);
  1159. if (count($parts) >= 2)
  1160. {
  1161. $miner = $parts[0];
  1162. $port = $parts[1];
  1163. if (count($parts) > 2)
  1164. $name = $parts[2];
  1165. else
  1166. $name = $num;
  1167. $ans = api($name, $cmd);
  1168. if ($error != null)
  1169. {
  1170. $rw = "<td colspan=100>Error on rig $name getting ";
  1171. $rw .= "$des: $warnfont$error$warnoff</td>";
  1172. otherrow($rw);
  1173. $rigerror[$rig] = $error;
  1174. $error = null;
  1175. }
  1176. else
  1177. {
  1178. $anss[$num] = $ans;
  1179. $count++;
  1180. }
  1181. }
  1182. }
  1183. if ($count == 0)
  1184. {
  1185. $rw = '<td>Failed to access any rigs successfully';
  1186. if ($preverr > 0)
  1187. $rw .= ' (or rigs had previous errors)';
  1188. $rw .= '</td>';
  1189. otherrow($rw);
  1190. return;
  1191. }
  1192. if ($datetime)
  1193. {
  1194. showdatetime();
  1195. endtable();
  1196. newtable();
  1197. showrigs($anss, '', 'Rig ');
  1198. endtable();
  1199. otherrow('<td><br><br></td>');
  1200. newtable();
  1201. return;
  1202. }
  1203. $total = array();
  1204. foreach ($anss as $rig => $ans)
  1205. {
  1206. if ($ans == null)
  1207. continue;
  1208. foreach ($ans as $item => $row)
  1209. {
  1210. if ($item == 'STATUS')
  1211. continue;
  1212. if (count($row) > count($header))
  1213. {
  1214. $header = $head;
  1215. foreach ($row as $name => $value)
  1216. if (!isset($header[$name]))
  1217. $header[$name] = '';
  1218. }
  1219. if ($sum != null)
  1220. foreach ($sum as $name)
  1221. {
  1222. if (isset($row[$name]))
  1223. {
  1224. if (isset($total[$name]))
  1225. $total[$name] += $row[$name];
  1226. else
  1227. $total[$name] = $row[$name];
  1228. }
  1229. }
  1230. }
  1231. }
  1232. if ($sum != null)
  1233. $anss['total']['total'] = $total;
  1234. showhead('', $header);
  1235. foreach ($anss as $rig => $ans)
  1236. {
  1237. if ($ans == null)
  1238. continue;
  1239. $when = 0;
  1240. if (isset($ans['STATUS']['When']))
  1241. $when = $ans['STATUS']['When'];
  1242. foreach ($ans as $item => $row)
  1243. {
  1244. if ($item == 'STATUS')
  1245. continue;
  1246. newrow();
  1247. $section = preg_replace('/\d/', '', $item);
  1248. foreach ($header as $name => $x)
  1249. {
  1250. if ($name == '')
  1251. {
  1252. if ($rig === 'total')
  1253. {
  1254. list($ignore, $class) = fmt($rig, '', '', $when, $row);
  1255. echo "<td align=right$class>Total:</td>";
  1256. }
  1257. else
  1258. echo rigbutton($rig, "Rig $rig", $when, $row);
  1259. }
  1260. else
  1261. {
  1262. if (isset($row[$name]))
  1263. $value = $row[$name];
  1264. else
  1265. $value = null;
  1266. list($showvalue, $class) = fmt($section, $name, $value, $when, $row);
  1267. echo "<td$class align=right>$showvalue</td>";
  1268. }
  1269. }
  1270. endrow();
  1271. }
  1272. }
  1273. }
  1274. #
  1275. function refreshbuttons()
  1276. {
  1277. global $readonly;
  1278. global $ignorerefresh, $changerefresh, $autorefresh;
  1279. if ($ignorerefresh == false && $changerefresh == true)
  1280. {
  1281. echo '&nbsp;&nbsp;&nbsp;&nbsp;';
  1282. echo "<input type=button value='Auto Refresh:' onclick='prr(true)'>";
  1283. echo "<input type=text name='refval' id='refval' size=2 value='$autorefresh'>";
  1284. echo "<input type=button value='Off' onclick='prr(false)'>";
  1285. }
  1286. }
  1287. #
  1288. function pagebuttons($rig, $pg)
  1289. {
  1290. global $readonly, $rigs;
  1291. global $allowcustompages, $customsummarypages;
  1292. if ($rig === null)
  1293. {
  1294. $prev = null;
  1295. $next = null;
  1296. if ($pg === null)
  1297. $refresh = '';
  1298. else
  1299. $refresh = "&pg=$pg";
  1300. }
  1301. else
  1302. {
  1303. switch (count($rigs))
  1304. {
  1305. case 0:
  1306. case 1:
  1307. $prev = null;
  1308. $next = null;
  1309. break;
  1310. case 2:
  1311. $prev = null;
  1312. $next = ($rig + 1) % count($rigs);
  1313. break;
  1314. default:
  1315. $prev = ($rig - 1) % count($rigs);
  1316. $next = ($rig + 1) % count($rigs);
  1317. break;
  1318. }
  1319. $refresh = "&rig=$rig";
  1320. }
  1321. echo '<tr><td><table cellpadding=0 cellspacing=0 border=0><tr><td nowrap>';
  1322. if ($prev !== null)
  1323. echo riginput($prev, 'Prev').'&nbsp;';
  1324. echo "<input type=button value='Refresh' onclick='pr(\"$refresh\",null)'>&nbsp;";
  1325. if ($next !== null)
  1326. echo riginput($next, 'Next').'&nbsp;';
  1327. echo '&nbsp;';
  1328. if (count($rigs) > 1)
  1329. echo "<input type=button value='Summary' onclick='pr(\"\",null)'>&nbsp;";
  1330. if ($allowcustompages === true)
  1331. foreach ($customsummarypages as $pagename => $data)
  1332. echo "<input type=button value='$pagename' onclick='pr(\"&pg=$pagename\",null)'>&nbsp;";
  1333. echo '</td><td width=100%>&nbsp;</td><td nowrap>';
  1334. if ($rig !== null && $readonly === false)
  1335. {
  1336. $rg = '';
  1337. if (count($rigs) > 1)
  1338. $rg = " Rig $rig";
  1339. echo "<input type=button value='Restart' onclick='prc(\"restart&rig=$rig\",\"Restart BFGMiner$rg\")'>";
  1340. echo "&nbsp;<input type=button value='Quit' onclick='prc(\"quit&rig=$rig\",\"Quit BFGMiner$rg\")'>";
  1341. }
  1342. refreshbuttons();
  1343. echo "</td></tr></table></td></tr>";
  1344. }
  1345. #
  1346. function doOne($rig, $preprocess)
  1347. {
  1348. global $haderror, $readonly, $notify, $rigs;
  1349. global $placebuttons;
  1350. htmlhead(true, $rig);
  1351. if ($placebuttons == 'top' || $placebuttons == 'both')
  1352. pagebuttons($rig, null);
  1353. if ($preprocess != null)
  1354. process(array($preprocess => $preprocess), $rig);
  1355. $cmds = array( 'devs' => 'device list',
  1356. 'summary' => 'summary information',
  1357. 'pools' => 'pool list');
  1358. if ($notify)
  1359. $cmds['notify'] = 'device status';
  1360. $cmds['config'] = 'BFGMiner config';
  1361. process($cmds, $rig);
  1362. if ($haderror == false && $readonly === false)
  1363. processgpus($rig);
  1364. if ($placebuttons == 'bot' || $placebuttons == 'both')
  1365. pagebuttons($rig, null);
  1366. }
  1367. #
  1368. global $sectionmap;
  1369. # map sections to their api command
  1370. # DEVS is a special case that will match GPU or PGA
  1371. # so you can have a single table with both in it
  1372. # DATE is hard coded so not in here
  1373. $sectionmap = array(
  1374. 'RIGS' => 'version',
  1375. 'SUMMARY' => 'summary',
  1376. 'POOL' => 'pools',
  1377. 'DEVS' => 'devs',
  1378. 'GPU' => 'devs', // You would normally use DEVS
  1379. 'PGA' => 'devs', // You would normally use DEVS
  1380. 'NOTIFY' => 'notify',
  1381. 'DEVDETAILS' => 'devdetails',
  1382. 'STATS' => 'stats',
  1383. 'CONFIG' => 'config',
  1384. 'COIN' => 'coin');
  1385. #
  1386. function joinfields($section1, $section2, $join, $results)
  1387. {
  1388. global $sectionmap;
  1389. $name1 = $sectionmap[$section1];
  1390. $name2 = $sectionmap[$section2];
  1391. $newres = array();
  1392. // foreach rig in section1
  1393. foreach ($results[$name1] as $rig => $result)
  1394. {
  1395. $status = null;
  1396. // foreach answer section in the rig api call
  1397. foreach ($result as $name1b => $fields1b)
  1398. {
  1399. if ($name1b == 'STATUS')
  1400. {
  1401. // remember the STATUS from section1
  1402. $status = $result[$name1b];
  1403. continue;
  1404. }
  1405. // foreach answer section in the rig api call (for the other api command)
  1406. foreach ($results[$name2][$rig] as $name2b => $fields2b)
  1407. {
  1408. if ($name2b == 'STATUS')
  1409. continue;
  1410. // If match the same field values of fields in $join
  1411. $match = true;
  1412. foreach ($join as $field)
  1413. if ($fields1b[$field] != $fields2b[$field])
  1414. {
  1415. $match = false;
  1416. break;
  1417. }
  1418. if ($match === true)
  1419. {
  1420. if ($status != null)
  1421. {
  1422. $newres[$rig]['STATUS'] = $status;
  1423. $status = null;
  1424. }
  1425. $subsection = $section1.'+'.$section2;
  1426. $subsection .= preg_replace('/[^0-9]/', '', $name1b.$name2b);
  1427. foreach ($fields1b as $nam => $val)
  1428. $newres[$rig][$subsection]["$section1.$nam"] = $val;
  1429. foreach ($fields2b as $nam => $val)
  1430. $newres[$rig][$subsection]["$section2.$nam"] = $val;
  1431. }
  1432. }
  1433. }
  1434. }
  1435. return $newres;
  1436. }
  1437. #
  1438. function joinlr($section1, $section2, $join, $results)
  1439. {
  1440. global $sectionmap;
  1441. $name1 = $sectionmap[$section1];
  1442. $name2 = $sectionmap[$section2];
  1443. $newres = array();
  1444. // foreach rig in section1
  1445. foreach ($results[$name1] as $rig => $result)
  1446. {
  1447. $status = null;
  1448. // foreach answer section in the rig api call
  1449. foreach ($result as $name1b => $fields1b)
  1450. {
  1451. if ($name1b == 'STATUS')
  1452. {
  1453. // remember the STATUS from section1
  1454. $status = $result[$name1b];
  1455. continue;
  1456. }
  1457. // Build L string to be matched
  1458. // : means a string constant otherwise it's a field name
  1459. $Lval = '';
  1460. foreach ($join['L'] as $field)
  1461. {
  1462. if (substr($field, 0, 1) == ':')
  1463. $Lval .= substr($field, 1);
  1464. else
  1465. $Lval .= $fields1b[$field];
  1466. }
  1467. // foreach answer section in the rig api call (for the other api command)
  1468. foreach ($results[$name2][$rig] as $name2b => $fields2b)
  1469. {
  1470. if ($name2b == 'STATUS')
  1471. continue;
  1472. // Build R string and compare
  1473. // : means a string constant otherwise it's a field name
  1474. $Rval = '';
  1475. foreach ($join['R'] as $field)
  1476. {
  1477. if (substr($field, 0, 1) == ':')
  1478. $Rval .= substr($field, 1);
  1479. else
  1480. $Rval .= $fields2b[$field];
  1481. }
  1482. if ($Lval === $Rval)
  1483. {
  1484. if ($status != null)
  1485. {
  1486. $newres[$rig]['STATUS'] = $status;
  1487. $status = null;
  1488. }
  1489. $subsection = $section1.'+'.$section2;
  1490. $subsection .= preg_replace('/[^0-9]/', '', $name1b.$name2b);
  1491. foreach ($fields1b as $nam => $val)
  1492. $newres[$rig][$subsection]["$section1.$nam"] = $val;
  1493. foreach ($fields2b as $nam => $val)
  1494. $newres[$rig][$subsection]["$section2.$nam"] = $val;
  1495. }
  1496. }
  1497. }
  1498. }
  1499. return $newres;
  1500. }
  1501. #
  1502. function joinall($section1, $section2, $results)
  1503. {
  1504. global $sectionmap;
  1505. $name1 = $sectionmap[$section1];
  1506. $name2 = $sectionmap[$section2];
  1507. $newres = array();
  1508. // foreach rig in section1
  1509. foreach ($results[$name1] as $rig => $result)
  1510. {
  1511. // foreach answer section in the rig api call
  1512. foreach ($result as $name1b => $fields1b)
  1513. {
  1514. if ($name1b == 'STATUS')
  1515. {
  1516. // copy the STATUS from section1
  1517. $newres[$rig][$name1b] = $result[$name1b];
  1518. continue;
  1519. }
  1520. // foreach answer section in the rig api call (for the other api command)
  1521. foreach ($results[$name2][$rig] as $name2b => $fields2b)
  1522. {
  1523. if ($name2b == 'STATUS')
  1524. continue;
  1525. $subsection = $section1.'+'.$section2;
  1526. $subsection .= preg_replace('/[^0-9]/', '', $name1b.$name2b);
  1527. foreach ($fields1b as $nam => $val)
  1528. $newres[$rig][$subsection]["$section1.$nam"] = $val;
  1529. foreach ($fields2b as $nam => $val)
  1530. $newres[$rig][$subsection]["$section2.$nam"] = $val;
  1531. }
  1532. }
  1533. }
  1534. return $newres;
  1535. }
  1536. #
  1537. function joinsections($sections, $results, $errors)
  1538. {
  1539. global $sectionmap;
  1540. // GPU's don't have Name,ID fields - so create them
  1541. foreach ($results as $section => $res)
  1542. foreach ($res as $rig => $result)
  1543. foreach ($result as $name => $fields)
  1544. {
  1545. $subname = preg_replace('/[0-9]/', '', $name);
  1546. if ($subname == 'GPU' and isset($result[$name]['GPU']))
  1547. {
  1548. $results[$section][$rig][$name]['Name'] = 'GPU';
  1549. $results[$section][$rig][$name]['ID'] = $result[$name]['GPU'];
  1550. }
  1551. }
  1552. foreach ($sections as $section => $fields)
  1553. if ($section != 'DATE' && !isset($sectionmap[$section]))
  1554. {
  1555. $both = explode('+', $section, 2);
  1556. if (count($both) > 1)
  1557. {
  1558. switch($both[0])
  1559. {
  1560. case 'SUMMARY':
  1561. switch($both[1])
  1562. {
  1563. case 'POOL':
  1564. case 'DEVS':
  1565. case 'CONFIG':
  1566. case 'COIN':
  1567. $sectionmap[$section] = $section;
  1568. $results[$section] = joinall($both[0], $both[1], $results);
  1569. break;
  1570. default:
  1571. $errors[] = "Error: Invalid section '$section'";
  1572. break;
  1573. }
  1574. break;
  1575. case 'DEVS':
  1576. switch($both[1])
  1577. {
  1578. case 'NOTIFY':
  1579. case 'DEVDETAILS':
  1580. case 'USBSTATS':
  1581. $join = array('Name', 'ID');
  1582. $sectionmap[$section] = $section;
  1583. $results[$section] = joinfields($both[0], $both[1], $join, $results);
  1584. break;
  1585. case 'STATS':
  1586. $join = array('L' => array('Name','ID'), 'R' => array('ID'));
  1587. $sectionmap[$section] = $section;
  1588. $results[$section] = joinlr($both[0], $both[1], $join, $results);
  1589. break;
  1590. default:
  1591. $errors[] = "Error: Invalid section '$section'";
  1592. break;
  1593. }
  1594. break;
  1595. case 'POOL':
  1596. switch($both[1])
  1597. {
  1598. case 'STATS':
  1599. $join = array('L' => array(':POOL','POOL'), 'R' => array('ID'));
  1600. $sectionmap[$section] = $section;
  1601. $results[$section] = joinlr($both[0], $both[1], $join, $results);
  1602. break;
  1603. default:
  1604. $errors[] = "Error: Invalid section '$section'";
  1605. break;
  1606. }
  1607. break;
  1608. default:
  1609. $errors[] = "Error: Invalid section '$section'";
  1610. break;
  1611. }
  1612. }
  1613. else
  1614. $errors[] = "Error: Invalid section '$section'";
  1615. }
  1616. return array($results, $errors);
  1617. }
  1618. #
  1619. function secmatch($section, $field)
  1620. {
  1621. if ($section == $field)
  1622. return true;
  1623. if ($section == 'DEVS'
  1624. && ($field == 'GPU' || $field == 'PGA'))
  1625. return true;
  1626. return false;
  1627. }
  1628. #
  1629. function customset($showfields, $sum, $section, $rig, $isbutton, $result, $total)
  1630. {
  1631. foreach ($result as $sec => $row)
  1632. {
  1633. $secname = preg_replace('/\d/', '', $sec);
  1634. if ($sec != 'total')
  1635. if (!secmatch($section, $secname))
  1636. continue;
  1637. newrow();
  1638. $when = 0;
  1639. if (isset($result['STATUS']['When']))
  1640. $when = $result['STATUS']['When'];
  1641. if ($isbutton)
  1642. echo rigbutton($rig, $rig, $when, $row);
  1643. else
  1644. {
  1645. list($ignore, $class) = fmt('total', '', '', $when, $row);
  1646. echo "<td align=middle$class>$rig</td>";
  1647. }
  1648. foreach ($showfields as $name => $one)
  1649. {
  1650. if (isset($row[$name]))
  1651. {
  1652. $value = $row[$name];
  1653. if (isset($sum[$section][$name]))
  1654. {
  1655. if (isset($total[$name]))
  1656. $total[$name] += $value;
  1657. else
  1658. $total[$name] = $value;
  1659. }
  1660. }
  1661. else
  1662. {
  1663. if ($sec == 'total' && isset($total[$name]))
  1664. $value = $total[$name];
  1665. else
  1666. $value = null;
  1667. }
  1668. if (strpos($secname, '+') === false)
  1669. list($showvalue, $class) = fmt($secname, $name, $value, $when, $row);
  1670. else
  1671. {
  1672. $parts = explode('.', $name, 2);
  1673. list($showvalue, $class) = fmt($parts[0], $parts[1], $value, $when, $row);
  1674. }
  1675. echo "<td$class align=right>$showvalue</td>";
  1676. }
  1677. endrow();
  1678. }
  1679. return $total;
  1680. }
  1681. #
  1682. function processcustompage($pagename, $sections, $sum, $namemap)
  1683. {
  1684. global $sectionmap;
  1685. global $miner, $port;
  1686. global $rigs, $error;
  1687. global $warnfont, $warnoff;
  1688. global $dfmt;
  1689. global $readonly, $showndate;
  1690. $cmds = array();
  1691. $errors = array();
  1692. foreach ($sections as $section => $fields)
  1693. {
  1694. $all = explode('+', $section);
  1695. foreach ($all as $section)
  1696. {
  1697. if (isset($sectionmap[$section]))
  1698. {
  1699. $cmd = $sectionmap[$section];
  1700. if (!isset($cmds[$cmd]))
  1701. $cmds[$cmd] = 1;
  1702. }
  1703. else
  1704. if ($section != 'DATE')
  1705. $errors[] = "Error: unknown section '$section' in custom summary page '$pagename'";
  1706. }
  1707. }
  1708. $results = array();
  1709. foreach ($rigs as $num => $rig)
  1710. {
  1711. $parts = explode(':', $rig, 3);
  1712. if (count($parts) >= 2)
  1713. {
  1714. $miner = $parts[0];
  1715. $port = $parts[1];
  1716. if (count($parts) > 2)
  1717. $name = $parts[2];
  1718. else
  1719. $name = $rig;
  1720. foreach ($cmds as $cmd => $one)
  1721. {
  1722. $process = api($name, $cmd);
  1723. if ($error != null)
  1724. {
  1725. $errors[] = "Error getting $cmd for $name $warnfont$error$warnoff";
  1726. break;
  1727. }
  1728. else
  1729. $results[$cmd][$num] = $process;
  1730. }
  1731. }
  1732. }
  1733. $shownsomething = false;
  1734. if (count($results) > 0)
  1735. {
  1736. list($results, $errors) = joinsections($sections, $results, $errors);
  1737. $first = true;
  1738. foreach ($sections as $section => $fields)
  1739. {
  1740. if ($section === 'DATE')
  1741. {
  1742. if ($shownsomething)
  1743. otherrow('<td>&nbsp;</td>');
  1744. newtable();
  1745. showdatetime();
  1746. endtable();
  1747. // On top of the next table
  1748. $shownsomething = false;
  1749. continue;
  1750. }
  1751. if ($section === 'RIGS')
  1752. {
  1753. if ($shownsomething)
  1754. otherrow('<td>&nbsp;</td>');
  1755. newtable();
  1756. showrigs($results['version'], 'Rig', '');
  1757. endtable();
  1758. $shownsomething = true;
  1759. continue;
  1760. }
  1761. if (isset($results[$sectionmap[$section]]))
  1762. {
  1763. $rigresults = $results[$sectionmap[$section]];
  1764. $showfields = array();
  1765. $showhead = array();
  1766. foreach ($fields as $field)
  1767. foreach ($rigresults as $result)
  1768. foreach ($result as $sec => $row)
  1769. {
  1770. $secname = preg_replace('/\d/', '', $sec);
  1771. if (secmatch($section, $secname))
  1772. {
  1773. if ($field === '*')
  1774. {
  1775. foreach ($row as $f => $v)
  1776. {
  1777. $showfields[$f] = 1;
  1778. $map = $section.'.'.$f;
  1779. if (isset($namemap[$map]))
  1780. $showhead[$namemap[$map]] = 1;
  1781. else
  1782. $showhead[$f] = 1;
  1783. }
  1784. }
  1785. elseif (isset($row[$field]))
  1786. {
  1787. $showfields[$field] = 1;
  1788. $map = $section.'.'.$field;
  1789. if (isset($namemap[$map]))
  1790. $showhead[$namemap[$map]] = 1;
  1791. else
  1792. $showhead[$field] = 1;
  1793. }
  1794. }
  1795. }
  1796. if (count($showfields) > 0)
  1797. {
  1798. if ($shownsomething)
  1799. otherrow('<td>&nbsp;</td>');
  1800. newtable();
  1801. showhead('', array('Rig'=>1)+$showhead, true);
  1802. $total = array();
  1803. $add = array('total' => array());
  1804. foreach ($rigresults as $num => $result)
  1805. $total = customset($showfields, $sum, $section, $num, true, $result, $total);
  1806. if (count($total) > 0)
  1807. customset($showfields, $sum, $section, '&Sigma;', false, $add, $total);
  1808. $first = false;
  1809. endtable();
  1810. $shownsomething = true;
  1811. }
  1812. }
  1813. }
  1814. }
  1815. if (count($errors) > 0)
  1816. {
  1817. if (count($results) > 0)
  1818. otherrow('<td>&nbsp;</td>');
  1819. foreach ($errors as $err)
  1820. otherrow("<td colspan=100>$err</td>");
  1821. }
  1822. }
  1823. #
  1824. function showcustompage($pagename)
  1825. {
  1826. global $customsummarypages;
  1827. global $placebuttons;
  1828. htmlhead(false, null, $pagename);
  1829. if ($placebuttons == 'top' || $placebuttons == 'both')
  1830. pagebuttons(null, $pagename);
  1831. if (!isset($customsummarypages[$pagename]))
  1832. {
  1833. otherrow("<td colspan=100>Unknown custom summary page '$pagename'</td>");
  1834. return;
  1835. }
  1836. if (count($customsummarypages[$pagename]) != 2)
  1837. {
  1838. $rw = "<td colspan=100>Invalid custom summary page '$pagename' (";
  1839. $rw .= count($customsummarypages[$pagename]).')</td>';
  1840. otherrow($rw);
  1841. return;
  1842. }
  1843. $page = $customsummarypages[$pagename][0];
  1844. $namemap = array();
  1845. foreach ($page as $name => $fields)
  1846. {
  1847. if ($fields === null)
  1848. $page[$name] = array();
  1849. else
  1850. foreach ($fields as $num => $field)
  1851. {
  1852. $pos = strpos($field, '=');
  1853. if ($pos !== false)
  1854. {
  1855. $names = explode('=', $field, 2);
  1856. if (strlen($names[1]) > 0)
  1857. $namemap[$name.'.'.$names[0]] = $names[1];
  1858. $page[$name][$num] = $names[0];
  1859. }
  1860. }
  1861. }
  1862. $sum = $customsummarypages[$pagename][1];
  1863. if ($sum === null)
  1864. $sum = array();
  1865. // convert them to searchable via isset()
  1866. foreach ($sum as $section => $fields)
  1867. {
  1868. $newfields = array();
  1869. foreach ($fields as $field)
  1870. $newfields[$field] = 1;
  1871. $sum[$section] = $newfields;
  1872. }
  1873. if (count($page) <= 1)
  1874. {
  1875. otherrow("<td colspan=100>Invalid custom summary page '$pagename' no content </td>");
  1876. return;
  1877. }
  1878. processcustompage($pagename, $page, $sum, $namemap);
  1879. if ($placebuttons == 'bot' || $placebuttons == 'both')
  1880. pagebuttons(null, $pagename);
  1881. }
  1882. #
  1883. function display()
  1884. {
  1885. global $miner, $port;
  1886. global $readonly, $notify, $rigs;
  1887. global $ignorerefresh, $autorefresh;
  1888. global $allowcustompages;
  1889. global $placebuttons;
  1890. if ($ignorerefresh == false)
  1891. {
  1892. $ref = trim(getparam('ref', true));
  1893. if ($ref != null && $ref != '')
  1894. $autorefresh = intval($ref);
  1895. }
  1896. $rig = trim(getparam('rig', true));
  1897. $arg = trim(getparam('arg', true));
  1898. $preprocess = null;
  1899. if ($arg != null and $arg != '')
  1900. {
  1901. $num = null;
  1902. if ($rig != null and $rig != '')
  1903. {
  1904. if ($rig >= 0 and $rig < count($rigs))
  1905. $num = $rig;
  1906. }
  1907. else
  1908. if (count($rigs) == 0)
  1909. $num = 0;
  1910. if ($num != null)
  1911. {
  1912. $parts = explode(':', $rigs[$num], 3);
  1913. if (count($parts) >= 2)
  1914. {
  1915. $miner = $parts[0];
  1916. $port = $parts[1];
  1917. if ($readonly !== true)
  1918. $preprocess = $arg;
  1919. }
  1920. }
  1921. }
  1922. if ($rigs == null or count($rigs) == 0)
  1923. {
  1924. otherrow("<td>No rigs defined</td>");
  1925. return;
  1926. }
  1927. if ($allowcustompages === true)
  1928. {
  1929. $pg = trim(getparam('pg', true));
  1930. if ($pg != null && $pg != '')
  1931. {
  1932. showcustompage($pg);
  1933. return;
  1934. }
  1935. }
  1936. if (count($rigs) == 1)
  1937. {
  1938. $parts = explode(':', $rigs[0], 3);
  1939. if (count($parts) >= 2)
  1940. {
  1941. $miner = $parts[0];
  1942. $port = $parts[1];
  1943. doOne(0, $preprocess);
  1944. }
  1945. else
  1946. otherrow('<td>Invalid "$rigs" array</td>');
  1947. return;
  1948. }
  1949. if ($rig != null and $rig != '' and $rig >= 0 and $rig < count($rigs))
  1950. {
  1951. $parts = explode(':', $rigs[$rig], 3);
  1952. if (count($parts) >= 2)
  1953. {
  1954. $miner = $parts[0];
  1955. $port = $parts[1];
  1956. doOne($rig, $preprocess);
  1957. }
  1958. else
  1959. otherrow('<td>Invalid "$rigs" array</td>');
  1960. return;
  1961. }
  1962. htmlhead(false, null);
  1963. if ($placebuttons == 'top' || $placebuttons == 'both')
  1964. pagebuttons(null, null);
  1965. if ($preprocess != null)
  1966. process(array($preprocess => $preprocess), $rig);
  1967. newtable();
  1968. doforeach('version', 'rig summary', array(), array(), true);
  1969. $sum = array('MHS av', 'Getworks', 'Found Blocks', 'Accepted', 'Rejected', 'Discarded', 'Stale', 'Utility', 'Local Work', 'Total MH');
  1970. doforeach('summary', 'summary information', $sum, array(), false);
  1971. endtable();
  1972. otherrow('<td><br><br></td>');
  1973. newtable();
  1974. doforeach('devs', 'device list', $sum, array(''=>'','ID'=>'','Name'=>''), false);
  1975. endtable();
  1976. otherrow('<td><br><br></td>');
  1977. newtable();
  1978. doforeach('pools', 'pool list', $sum, array(''=>''), false);
  1979. endtable();
  1980. if ($placebuttons == 'bot' || $placebuttons == 'both')
  1981. pagebuttons(null, null);
  1982. }
  1983. #
  1984. display();
  1985. #
  1986. ?>
  1987. </table></td></tr></table>
  1988. </body></html>