miner.php 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678
  1. <?php
  2. session_start();
  3. #
  4. global $miner, $port, $readonly, $notify, $rigs;
  5. global $socksndtimeoutsec, $sockrcvtimeoutsec;
  6. global $checklastshare, $hidefields;
  7. global $ignorerefresh, $changerefresh, $autorefresh;
  8. global $allowcustompages, $customsummarypages;
  9. global $miner_font_family, $miner_font_size;
  10. global $colouroverride, $placebuttons;
  11. #
  12. # Don't touch these 2 - see $rigs below
  13. $miner = null;
  14. $port = null;
  15. #
  16. # Set $readonly to true to force miner.php to be readonly
  17. # Set $readonly to false then it will check BFGMiner 'privileged'
  18. $readonly = false;
  19. #
  20. # Set $notify to false to NOT attempt to display the notify command
  21. # Set $notify to true to attempt to display the notify command
  22. # If your older version of BFGMiner returns an 'Invalid command'
  23. # coz it doesn't have notify - it just shows the error status table
  24. $notify = true;
  25. #
  26. # set $checklastshare to true to do the following checks:
  27. # If a device's last share is 12x expected ago then display as an error
  28. # If a device's last share is 8x expected ago then display as a warning
  29. # If either of the above is true, also display the whole line highlighted
  30. # This assumes shares are 1 difficulty shares
  31. $checklastshare = true;
  32. #
  33. # Set $rigs to an array of your BFGMiner rigs that are running
  34. # format: 'IP:Port' or 'Host:Port' or 'Host:Port:Name'
  35. # If you only have one rig, it will just show the detail of that rig
  36. # If you have more than one rig it will show a summary of all the rigs
  37. # with buttons to show the details of each rig -
  38. # the button contents will be 'Name' if that was specified
  39. # e.g. $rigs = array('127.0.0.1:4028','myrig.com:4028:Sugoi');
  40. $rigs = array('127.0.0.1:4028');
  41. #
  42. # These should be OK for most cases
  43. # However, the longer SND is, the longer you have to wait while
  44. # php hangs if the target cgminer isn't runnning or listening
  45. # RCV should only ever be relevant if cgminer has hung but the
  46. # API thread is still running, RCV would normally be >= SND
  47. # Feel free to increase SND if your network is very slow
  48. # or decrease RCV if that happens often to you
  49. # Also, on some windows PHP, apparently the $usec is ignored
  50. $socksndtimeoutsec = 10;
  51. $sockrcvtimeoutsec = 40;
  52. #
  53. # List of fields NOT to be displayed
  54. # You can use this to hide data you don't want to see or don't want
  55. # shown on a public web page
  56. # The list of sections are: SUMMARY, POOL, PGA, GPU, NOTIFY, CONFIG
  57. # See the web page for the list of field names (the table headers)
  58. # It is an array of 'SECTION.Field Name' => 1
  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 then and don't display the buttons)
  73. $allowcustompages = true;
  74. #
  75. # OK this is a bit more complex item: Custom Summary Pages
  76. # A custom summary page in an array of 'section' => array('FieldA','FieldB'...)
  77. # Field can be 'name=new name' to display 'name' with a different heading 'new name'
  78. # This makes up what is displayed with each 'section' separately as a table
  79. # - empty tables are not shown
  80. # - empty columns (an unknown field) are not shown
  81. # - and missing field data shows as blank
  82. # - section = 'DATE' displays a date table like 'Summary'
  83. # - section = 'RIGS' displays a rig table like 'Summary'
  84. # There is a second array, listing fields to be totaled for each section
  85. # see the example below (if there is no matching data, no total will show)
  86. $mobilepage = array(
  87. 'DATE' => null,
  88. 'RIGS' => null,
  89. 'SUMMARY' => array('Elapsed', 'MHS av', 'Found Blocks=Blks', 'Accepted', 'Rejected=Rej', 'Utility'),
  90. 'DEVS' => array('ID', 'Name', 'GPU', 'Status', 'MHS av', 'Accepted', 'Rejected=Rej', 'Utility'),
  91. 'POOL' => array('POOL', 'Status', 'Accepted', 'Rejected=Rej', 'Last Share Time'));
  92. $mobilesum = array(
  93. 'SUMMARY' => array('MHS av', 'Found Blocks', 'Accepted', 'Rejected', 'Utility'),
  94. 'DEVS' => array('MHS av', 'Accepted', 'Rejected', 'Utility'),
  95. 'POOL' => array('Accepted', 'Rejected'));
  96. #
  97. # customsummarypages is an array of these Custom Summary Pages
  98. $customsummarypages = array('Mobile' => array($mobilepage, $mobilesum));
  99. #
  100. $here = $_SERVER['PHP_SELF'];
  101. #
  102. global $tablebegin, $tableend, $warnfont, $warnoff, $dfmt;
  103. #
  104. $tablebegin = '<tr><td><table border=1 cellpadding=5 cellspacing=0>';
  105. $tableend = '</table></td></tr>';
  106. $warnfont = '<font color=red><b>';
  107. $warnoff = '</b></font>';
  108. $dfmt = 'H:i:s j-M-Y \U\T\CP';
  109. #
  110. $miner_font_family = 'verdana,arial,sans';
  111. $miner_font_size = '13pt';
  112. #
  113. # Edit this or redefine it in myminer.php to change the colour scheme
  114. # See $colourtable below for the list of names
  115. $colouroverride = array();
  116. #
  117. # Where to place the buttons: 'top' 'bot' 'both'
  118. # anything else means don't show them - case sensitive
  119. $placebuttons = 'top';
  120. #
  121. # This below allows you to put your own settings into a seperate file
  122. # so you don't need to update miner.php with your preferred settings
  123. # every time a new version is released
  124. # Just create the file 'myminer.php' in the same directory as
  125. # 'miner.php' - and put your own settings in there
  126. if (file_exists('myminer.php'))
  127. include_once('myminer.php');
  128. #
  129. # This is the system default that must always contain all necessary
  130. # colours so it must be a constant
  131. # You can override these values with $colouroverride
  132. # The only one missing is in $warnfont
  133. # - which you can override directly anyway
  134. global $colourtable;
  135. $colourtable = array(
  136. 'body bgcolor' => '#ecffff',
  137. 'td color' => 'blue',
  138. 'td.two color' => 'blue',
  139. 'td.two background' => '#ecffff',
  140. 'td.h color' => 'blue',
  141. 'td.h background' => '#c4ffff',
  142. 'td.err color' => 'black',
  143. 'td.err background' => '#ff3050',
  144. 'td.warn color' => 'black',
  145. 'td.warn background' => '#ffb050',
  146. 'td.sta color' => 'green',
  147. 'td.tot color' => 'blue',
  148. 'td.tot background' => '#fff8f2',
  149. 'td.lst color' => 'blue',
  150. 'td.lst background' => '#ffffdd',
  151. 'td.hi color' => 'blue',
  152. 'td.hi background' => '#f6ffff',
  153. 'td.lo color' => 'blue',
  154. 'td.lo background' => '#deffff'
  155. );
  156. #
  157. # Ensure it is only ever shown once
  158. global $showndate;
  159. $showndate = false;
  160. #
  161. # For summary page to stop retrying failed rigs
  162. global $rigerror;
  163. $rigerror = array();
  164. #
  165. global $rownum;
  166. $rownum = 0;
  167. #
  168. function getcss($cssname, $dom = false)
  169. {
  170. global $colourtable, $colouroverride;
  171. $css = '';
  172. foreach ($colourtable as $cssdata => $value)
  173. {
  174. $cssobj = explode(' ', $cssdata, 2);
  175. if ($cssobj[0] == $cssname)
  176. {
  177. if (isset($colouroverride[$cssdata]))
  178. $value = $colouroverride[$cssdata];
  179. if ($dom == true)
  180. $css .= ' '.$cssobj[1].'='.$value;
  181. else
  182. $css .= $cssobj[1].':'.$value.'; ';
  183. }
  184. }
  185. return $css;
  186. }
  187. #
  188. function getdom($domname)
  189. {
  190. return getcss($domname, true);
  191. }
  192. #
  193. function htmlhead($checkapi, $rig, $pg = null)
  194. {
  195. global $miner_font_family, $miner_font_size;
  196. global $error, $readonly, $here;
  197. global $ignorerefresh, $autorefresh;
  198. $extraparams = '';
  199. if ($rig != null && $rig != '')
  200. $extraparams = "&rig=$rig";
  201. else
  202. if ($pg != null && $pg != '')
  203. $extraparams = "&pg=$pg";
  204. if ($ignorerefresh == true || $autorefresh == 0)
  205. $refreshmeta = '';
  206. else
  207. {
  208. $url = "$here?ref=$autorefresh$extraparams";
  209. $refreshmeta = "\n<meta http-equiv='refresh' content='$autorefresh;url=$url'>";
  210. }
  211. if ($readonly === false && $checkapi === true)
  212. {
  213. $error = null;
  214. $access = api('privileged');
  215. if ($error != null
  216. || !isset($access['STATUS']['STATUS'])
  217. || $access['STATUS']['STATUS'] != 'S')
  218. $readonly = true;
  219. }
  220. $miner_font = "font-family:$miner_font_family; font-size:$miner_font_size;";
  221. echo "<html><head>$refreshmeta
  222. <title>Mine</title>
  223. <style type='text/css'>
  224. td { $miner_font ".getcss('td')."}
  225. td.two { $miner_font ".getcss('td.two')."}
  226. td.h { $miner_font ".getcss('td.h')."}
  227. td.err { $miner_font ".getcss('td.err')."}
  228. td.warn { $miner_font ".getcss('td.warn')."}
  229. td.sta { $miner_font ".getcss('td.sta')."}
  230. td.tot { $miner_font ".getcss('td.tot')."}
  231. td.lst { $miner_font ".getcss('td.lst')."}
  232. td.hi { $miner_font ".getcss('td.hi')."}
  233. td.lo { $miner_font ".getcss('td.lo')."}
  234. </style>
  235. </head><body".getdom('body').">
  236. <script type='text/javascript'>
  237. function pr(a,m){if(m!=null){if(!confirm(m+'?'))return}window.location='$here?ref=$autorefresh'+a}\n";
  238. if ($ignorerefresh == false)
  239. echo "function prr(a){if(a){v=document.getElementById('refval').value}else{v=0}window.location='$here?ref='+v+'$extraparams'}\n";
  240. if ($readonly === false && $checkapi === true)
  241. {
  242. echo "function prc(a,m){pr('&arg='+a,m)}
  243. 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)}
  244. 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";
  245. }
  246. ?>
  247. </script>
  248. <table width=100% height=100% border=0 cellpadding=0 cellspacing=0 summary='Mine'>
  249. <tr><td align=center valign=top>
  250. <table border=0 cellpadding=4 cellspacing=0 summary='Mine'>
  251. <?php
  252. }
  253. #
  254. global $haderror, $error;
  255. $haderror = false;
  256. $error = null;
  257. #
  258. function getsock($addr, $port)
  259. {
  260. global $haderror, $error, $socksndtimeoutsec, $sockrcvtimeoutsec;
  261. $error = null;
  262. $socket = null;
  263. $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  264. if ($socket === false || $socket === null)
  265. {
  266. $haderror = true;
  267. $error = socket_strerror(socket_last_error());
  268. $msg = "socket create(TCP) failed";
  269. $error = "ERR: $msg '$error'\n";
  270. return null;
  271. }
  272. // Ignore if this fails since the socket connect may work anyway
  273. // and nothing is gained by aborting if the option cannot be set
  274. // since we don't know in advance if it can connect
  275. socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, array('sec' => $socksndtimeoutsec, 'usec' => 0));
  276. socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $sockrcvtimeoutsec, 'usec' => 0));
  277. $res = socket_connect($socket, $addr, $port);
  278. if ($res === false)
  279. {
  280. $haderror = true;
  281. $error = socket_strerror(socket_last_error());
  282. $msg = "socket connect($addr,$port) failed";
  283. $error = "ERR: $msg '$error'\n";
  284. socket_close($socket);
  285. return null;
  286. }
  287. return $socket;
  288. }
  289. #
  290. function readsockline($socket)
  291. {
  292. $line = '';
  293. while (true)
  294. {
  295. $byte = socket_read($socket, 1);
  296. if ($byte === false || $byte === '')
  297. break;
  298. if ($byte === "\0")
  299. break;
  300. $line .= $byte;
  301. }
  302. return $line;
  303. }
  304. #
  305. function api($cmd)
  306. {
  307. global $haderror, $error;
  308. global $miner, $port, $hidefields;
  309. $socket = getsock($miner, $port);
  310. if ($socket != null)
  311. {
  312. socket_write($socket, $cmd, strlen($cmd));
  313. $line = readsockline($socket);
  314. socket_close($socket);
  315. if (strlen($line) == 0)
  316. {
  317. $haderror = true;
  318. $error = "WARN: '$cmd' returned nothing\n";
  319. return $line;
  320. }
  321. # print "$cmd returned '$line'\n";
  322. $data = array();
  323. $objs = explode('|', $line);
  324. foreach ($objs as $obj)
  325. {
  326. if (strlen($obj) > 0)
  327. {
  328. $items = explode(',', $obj);
  329. $item = $items[0];
  330. $id = explode('=', $items[0], 2);
  331. if (count($id) == 1 or !ctype_digit($id[1]))
  332. $name = $id[0];
  333. else
  334. $name = $id[0].$id[1];
  335. if (strlen($name) == 0)
  336. $name = 'null';
  337. $sectionname = preg_replace('/\d/', '', $name);
  338. if (isset($data[$name]))
  339. {
  340. $num = 1;
  341. while (isset($data[$name.$num]))
  342. $num++;
  343. $name .= $num;
  344. }
  345. $counter = 0;
  346. foreach ($items as $item)
  347. {
  348. $id = explode('=', $item, 2);
  349. if (isset($hidefields[$sectionname.'.'.$id[0]]))
  350. continue;
  351. if (count($id) == 2)
  352. $data[$name][$id[0]] = $id[1];
  353. else
  354. $data[$name][$counter] = $id[0];
  355. $counter++;
  356. }
  357. }
  358. }
  359. return $data;
  360. }
  361. return null;
  362. }
  363. #
  364. function getparam($name, $both = false)
  365. {
  366. $a = null;
  367. if (isset($_POST[$name]))
  368. $a = $_POST[$name];
  369. if (($both === true) and ($a === null))
  370. {
  371. if (isset($_GET[$name]))
  372. $a = $_GET[$name];
  373. }
  374. if ($a == '' || $a == null)
  375. return null;
  376. // limit to 1K just to be safe
  377. return substr($a, 0, 1024);
  378. }
  379. #
  380. function newtable()
  381. {
  382. global $tablebegin, $rownum;
  383. echo $tablebegin;
  384. $rownum = 0;
  385. }
  386. #
  387. function newrow()
  388. {
  389. echo '<tr>';
  390. }
  391. #
  392. function otherrow($row)
  393. {
  394. echo "<tr>$row</tr>";
  395. }
  396. #
  397. function endrow()
  398. {
  399. global $rownum;
  400. echo '</tr>';
  401. $rownum++;
  402. }
  403. #
  404. function endtable()
  405. {
  406. global $tableend;
  407. echo $tableend;
  408. }
  409. #
  410. function classlastshare($when, $alldata, $warnclass, $errorclass)
  411. {
  412. global $checklastshare;
  413. if ($checklastshare === false)
  414. return '';
  415. if ($when == 0)
  416. return '';
  417. if (!isset($alldata['MHS av']))
  418. return '';
  419. if (!isset($alldata['Last Share Time']))
  420. return '';
  421. $expected = pow(2, 32) / ($alldata['MHS av'] * pow(10, 6));
  422. $howlong = $when - $alldata['Last Share Time'];
  423. if ($howlong < 1)
  424. $howlong = 1;
  425. if ($howlong > ($expected * 12))
  426. return $errorclass;
  427. if ($howlong > ($expected * 8))
  428. return $warnclass;
  429. return '';
  430. }
  431. #
  432. function fmt($section, $name, $value, $when, $alldata)
  433. {
  434. global $dfmt, $rownum;
  435. if ($alldata == null)
  436. $alldata = array();
  437. $errorclass = ' class=err';
  438. $warnclass = ' class=warn';
  439. $lstclass = ' class=lst';
  440. $hiclass = ' class=hi';
  441. $loclass = ' class=lo';
  442. $c2class = ' class=two';
  443. $totclass = ' class=tot';
  444. $b = '&nbsp;';
  445. $ret = $value;
  446. $class = '';
  447. if ($value === null)
  448. $ret = $b;
  449. else
  450. switch ($section.'.'.$name)
  451. {
  452. case 'GPU.Last Share Time':
  453. case 'PGA.Last Share Time':
  454. if ($value == 0
  455. || (isset($alldata['Last Share Pool']) && $alldata['Last Share Pool'] == -1))
  456. {
  457. $ret = 'Never';
  458. $class = $warnclass;
  459. }
  460. else
  461. {
  462. $ret = date('H:i:s', $value);
  463. $class = classlastshare($when, $alldata, $warnclass, $errorclass);
  464. }
  465. break;
  466. case 'POOL.Last Share Time':
  467. if ($value == 0)
  468. $ret = 'Never';
  469. else
  470. $ret = date('H:i:s d-M', $value);
  471. break;
  472. case 'GPU.Last Share Pool':
  473. case 'PGA.Last Share Pool':
  474. if ($value == -1)
  475. {
  476. $ret = 'None';
  477. $class = $warnclass;
  478. }
  479. break;
  480. case 'SUMMARY.Elapsed':
  481. $s = $value % 60;
  482. $value -= $s;
  483. $value /= 60;
  484. if ($value == 0)
  485. $ret = $s.'s';
  486. else
  487. {
  488. $m = $value % 60;
  489. $value -= $m;
  490. $value /= 60;
  491. if ($value == 0)
  492. $ret = sprintf("%dm$b%02ds", $m, $s);
  493. else
  494. {
  495. $h = $value % 24;
  496. $value -= $h;
  497. $value /= 24;
  498. if ($value == 0)
  499. $ret = sprintf("%dh$b%02dm$b%02ds", $h, $m, $s);
  500. else
  501. {
  502. if ($value == 1)
  503. $days = '';
  504. else
  505. $days = 's';
  506. $ret = sprintf("%dday$days$b%02dh$b%02dm$b%02ds", $value, $h, $m, $s);
  507. }
  508. }
  509. }
  510. break;
  511. case 'NOTIFY.Last Well':
  512. if ($value == '0')
  513. {
  514. $ret = 'Never';
  515. $class = $warnclass;
  516. }
  517. else
  518. $ret = date('H:i:s', $value);
  519. break;
  520. case 'NOTIFY.Last Not Well':
  521. if ($value == '0')
  522. $ret = 'Never';
  523. else
  524. {
  525. $ret = date('H:i:s', $value);
  526. $class = $errorclass;
  527. }
  528. break;
  529. case 'NOTIFY.Reason Not Well':
  530. if ($value != 'None')
  531. $class = $errorclass;
  532. break;
  533. case 'GPU.Utility':
  534. case 'PGA.Utility':
  535. case 'SUMMARY.Utility':
  536. case 'total.Utility':
  537. $ret = $value.'/m';
  538. if ($value == 0)
  539. $class = $errorclass;
  540. else
  541. if (isset($alldata['MHS av']))
  542. {
  543. $expected = 60 * $alldata['MHS av'] * (pow(10, 6) / pow(2, 32));
  544. if ($expected == 0)
  545. $expected = 0.000001; // 1 H/s
  546. $ratio = $value / $expected;
  547. if ($ratio < 0.9)
  548. $class = $loclass;
  549. else
  550. if ($ratio > 1.1)
  551. $class = $hiclass;
  552. }
  553. break;
  554. case 'PGA.Temperature':
  555. $ret = $value.'&deg;C';
  556. break;
  557. case 'GPU.Temperature':
  558. $ret = $value.'&deg;C';
  559. case 'GPU.GPU Clock':
  560. case 'GPU.Memory Clock':
  561. case 'GPU.GPU Voltage':
  562. case 'GPU.GPU Activity':
  563. if ($value == 0)
  564. $class = $warnclass;
  565. break;
  566. case 'GPU.Fan Percent':
  567. if ($value == 0)
  568. $class = $warnclass;
  569. else
  570. {
  571. if ($value == 100)
  572. $class = $errorclass;
  573. else
  574. if ($value > 85)
  575. $class = $warnclass;
  576. }
  577. break;
  578. case 'GPU.Fan Speed':
  579. if ($value == 0)
  580. $class = $warnclass;
  581. else
  582. if (isset($alldata['Fan Percent']))
  583. {
  584. $test = $alldata['Fan Percent'];
  585. if ($test == 100)
  586. $class = $errorclass;
  587. else
  588. if ($test > 85)
  589. $class = $warnclass;
  590. }
  591. break;
  592. case 'GPU.MHS av':
  593. case 'PGA.MHS av':
  594. case 'SUMMARY.MHS av':
  595. case 'total.MHS av':
  596. $parts = explode('.', $value, 2);
  597. if (count($parts) == 1)
  598. $dec = '';
  599. else
  600. $dec = '.'.$parts[1];
  601. $ret = number_format($parts[0]).$dec;
  602. if ($value == 0)
  603. $class = $errorclass;
  604. else
  605. if (isset($alldata['Utility']))
  606. {
  607. $expected = 60 * $value * (pow(10, 6) / pow(2, 32));
  608. $utility = $alldata['Utility'];
  609. $ratio = $utility / $expected;
  610. if ($ratio < 0.9)
  611. $class = $hiclass;
  612. else
  613. if ($ratio > 1.1)
  614. $class = $loclass;
  615. }
  616. break;
  617. case 'GPU.Total MH':
  618. case 'PGA.Total MH':
  619. case 'SUMMARY.Total MH':
  620. case 'total.Total MH':
  621. case 'SUMMARY.Getworks':
  622. case 'POOL.Getworks':
  623. case 'total.Getworks':
  624. case 'GPU.Accepted':
  625. case 'PGA.Accepted':
  626. case 'SUMMARY.Accepted':
  627. case 'POOL.Accepted':
  628. case 'total.Accepted':
  629. case 'GPU.Rejected':
  630. case 'PGA.Rejected':
  631. case 'SUMMARY.Rejected':
  632. case 'POOL.Rejected':
  633. case 'total.Rejected':
  634. case 'SUMMARY.Local Work':
  635. case 'total.Local Work':
  636. case 'SUMMARY.Discarded':
  637. case 'POOL.Discarded':
  638. case 'total.Discarded':
  639. $parts = explode('.', $value, 2);
  640. if (count($parts) == 1)
  641. $dec = '';
  642. else
  643. $dec = '.'.$parts[1];
  644. $ret = number_format($parts[0]).$dec;
  645. break;
  646. case 'GPU.Status':
  647. case 'PGA.Status':
  648. case 'POOL.Status':
  649. if ($value != 'Alive')
  650. $class = $errorclass;
  651. break;
  652. case 'GPU.Enabled':
  653. case 'PGA.Enabled':
  654. if ($value != 'Y')
  655. $class = $warnclass;
  656. break;
  657. case 'STATUS.When':
  658. $ret = date($dfmt, $value);
  659. break;
  660. case 'BUTTON.Rig':
  661. case 'BUTTON.Pool':
  662. case 'BUTTON.GPU':
  663. $ret = $value;
  664. break;
  665. }
  666. if ($section == 'NOTIFY' && substr($name, 0, 1) == '*' && $value != '0')
  667. $class = $errorclass;
  668. if ($class == '' && $section != 'POOL')
  669. $class = classlastshare($when, $alldata, $lstclass, $lstclass);
  670. if ($class == '' && $section == 'total')
  671. $class = $totclass;
  672. if ($class == '' && ($rownum % 2) == 0)
  673. $class = $c2class;
  674. return array($ret, $class);
  675. }
  676. #
  677. global $poolcmd;
  678. $poolcmd = array( 'Switch to' => 'switchpool',
  679. 'Enable' => 'enablepool',
  680. 'Disable' => 'disablepool' );
  681. #
  682. function showhead($cmd, $values, $justnames = false)
  683. {
  684. global $poolcmd, $readonly;
  685. newrow();
  686. foreach ($values as $name => $value)
  687. {
  688. if ($name == '0' or $name == '')
  689. $name = '&nbsp;';
  690. echo "<td valign=bottom class=h>$name</td>";
  691. }
  692. if ($justnames === false && $cmd == 'pools' && $readonly === false)
  693. foreach ($poolcmd as $name => $pcmd)
  694. echo "<td valign=bottom class=h>$name</td>";
  695. endrow();
  696. }
  697. #
  698. function showdatetime()
  699. {
  700. global $dfmt;
  701. otherrow('<td class=sta>Date: '.date($dfmt).'</td>');
  702. }
  703. #
  704. function details($cmd, $list, $rig)
  705. {
  706. global $dfmt, $poolcmd, $readonly, $showndate;
  707. $when = 0;
  708. $stas = array('S' => 'Success', 'W' => 'Warning', 'I' => 'Informational', 'E' => 'Error', 'F' => 'Fatal');
  709. newtable();
  710. if ($showndate === false)
  711. {
  712. showdatetime();
  713. endtable();
  714. newtable();
  715. $showndate = true;
  716. }
  717. if (isset($list['STATUS']))
  718. {
  719. newrow();
  720. echo '<td>Computer: '.$list['STATUS']['Description'].'</td>';
  721. if (isset($list['STATUS']['When']))
  722. {
  723. echo '<td>When: '.date($dfmt, $list['STATUS']['When']).'</td>';
  724. $when = $list['STATUS']['When'];
  725. }
  726. $sta = $list['STATUS']['STATUS'];
  727. echo '<td>Status: '.$stas[$sta].'</td>';
  728. echo '<td>Message: '.$list['STATUS']['Msg'].'</td>';
  729. endrow();
  730. }
  731. $section = '';
  732. foreach ($list as $item => $values)
  733. {
  734. if ($item == 'STATUS')
  735. continue;
  736. $sectionname = preg_replace('/\d/', '', $item);
  737. if ($sectionname != $section)
  738. {
  739. endtable();
  740. newtable();
  741. showhead($cmd, $values);
  742. $section = $sectionname;
  743. }
  744. newrow();
  745. foreach ($values as $name => $value)
  746. {
  747. list($showvalue, $class) = fmt($section, $name, $value, $when, $values);
  748. echo "<td$class>$showvalue</td>";
  749. }
  750. if ($cmd == 'pools' && $readonly === false)
  751. {
  752. reset($values);
  753. $pool = current($values);
  754. foreach ($poolcmd as $name => $pcmd)
  755. {
  756. list($ignore, $class) = fmt('BUTTON', 'Pool', '', $when, $values);
  757. echo "<td$class>";
  758. if ($pool === false)
  759. echo '&nbsp;';
  760. else
  761. {
  762. echo "<input type=button value='Pool $pool'";
  763. echo " onclick='prc(\"$pcmd|$pool&rig=$rig\",\"$name Pool $pool\")'>";
  764. }
  765. echo '</td>';
  766. }
  767. }
  768. endrow();
  769. }
  770. endtable();
  771. }
  772. #
  773. global $devs;
  774. $devs = null;
  775. #
  776. function gpubuttons($count, $rig)
  777. {
  778. global $devs;
  779. $basic = array( 'GPU', 'Enable', 'Disable', 'Restart' );
  780. $options = array( 'intensity' => 'Intensity',
  781. 'fan' => 'Fan Percent',
  782. 'engine' => 'GPU Clock',
  783. 'mem' => 'Memory Clock',
  784. 'vddc' => 'GPU Voltage' );
  785. newtable();
  786. newrow();
  787. foreach ($basic as $head)
  788. echo "<td class=h>$head</td>";
  789. foreach ($options as $name => $des)
  790. echo "<td class=h nowrap>$des</td>";
  791. $n = 0;
  792. for ($c = 0; $c < $count; $c++)
  793. {
  794. endrow();
  795. newrow();
  796. foreach ($basic as $name)
  797. {
  798. list($ignore, $class) = fmt('BUTTON', 'GPU', '', 0, null);
  799. echo "<td$class>";
  800. if ($name == 'GPU')
  801. echo $c;
  802. else
  803. {
  804. echo "<input type=button value='$name $c' onclick='prs(\"gpu";
  805. echo strtolower($name);
  806. echo "|$c\",$rig)'>";
  807. }
  808. echo '</td>';
  809. }
  810. foreach ($options as $name => $des)
  811. {
  812. list($ignore, $class) = fmt('BUTTON', 'GPU', '', 0, null);
  813. echo "<td$class>";
  814. if (!isset($devs["GPU$c"][$des]))
  815. echo '&nbsp;';
  816. else
  817. {
  818. $value = $devs["GPU$c"][$des];
  819. echo "<input type=button value='Set $c:' onclick='prs2(\"gpu$name|$c\",$n,$rig)'>";
  820. echo "<input size=7 type=text name=gi$n value='$value' id=gi$n>";
  821. $n++;
  822. }
  823. echo '</td>';
  824. }
  825. }
  826. endrow();
  827. endtable();
  828. }
  829. #
  830. function processgpus($rig)
  831. {
  832. global $error;
  833. global $warnfont, $warnoff;
  834. $gpus = api('gpucount');
  835. if ($error != null)
  836. otherrow("<td>Error getting GPU count: $warnfont$error$warnoff</td>");
  837. else
  838. {
  839. if (!isset($gpus['GPUS']['Count']))
  840. {
  841. $rw = '<td>No GPU count returned: '.$warnfont;
  842. $rw .= $gpus['STATUS']['STATUS'].' '.$gpus['STATUS']['Msg'];
  843. $rw .= $warnoff.'</td>';
  844. otherrow($rw);
  845. }
  846. else
  847. {
  848. $count = $gpus['GPUS']['Count'];
  849. if ($count == 0)
  850. otherrow('<td>No GPUs</td>');
  851. else
  852. gpubuttons($count, $rig);
  853. }
  854. }
  855. }
  856. #
  857. function process($cmds, $rig)
  858. {
  859. global $error, $devs;
  860. global $warnfont, $warnoff;
  861. $count = count($cmds);
  862. foreach ($cmds as $cmd => $des)
  863. {
  864. $process = api($cmd);
  865. if ($error != null)
  866. {
  867. otherrow("<td colspan=100>Error getting $des: $warnfont$error$warnoff</td>");
  868. break;
  869. }
  870. else
  871. {
  872. details($cmd, $process, $rig);
  873. # Not after the last one
  874. if (--$count > 0)
  875. otherrow('<td><br><br></td>');
  876. if ($cmd == 'devs')
  877. $devs = $process;
  878. }
  879. }
  880. }
  881. #
  882. function rigbutton($rig, $rigname, $when, $row)
  883. {
  884. global $rigs;
  885. if (isset($rigs[$rig]))
  886. {
  887. $parts = explode(':', $rigs[$rig], 3);
  888. if (count($parts) == 3)
  889. $rigname = $parts[2];
  890. }
  891. list($value, $class) = fmt('BUTTON', 'Rig', '', $when, $row);
  892. $button = "<td align=middle$class><input type=button value='$rigname'";
  893. $button .= " onclick='pr(\"&rig=$rig\",null)'></td>";
  894. return $button;
  895. }
  896. #
  897. function showrigs($anss, $headname, $rigname)
  898. {
  899. $dthead = array($headname => 1, 'STATUS' => 1, 'Description' => 1, 'When' => 1, 'API' => 1, 'CGMiner' => 1);
  900. showhead('', $dthead);
  901. foreach ($anss as $rig => $ans)
  902. {
  903. if ($ans == null)
  904. continue;
  905. newrow();
  906. $when = 0;
  907. if (isset($ans['STATUS']['When']))
  908. $when = $ans['STATUS']['When'];
  909. foreach ($ans as $item => $row)
  910. {
  911. if ($item != 'STATUS' && $item != 'VERSION')
  912. continue;
  913. foreach ($dthead as $name => $x)
  914. {
  915. if ($item == 'STATUS' && $name == $headname)
  916. echo rigbutton($rig, $rigname.$rig, $when, null);
  917. else
  918. {
  919. if (isset($row[$name]))
  920. {
  921. list($showvalue, $class) = fmt('STATUS', $name, $row[$name], $when, null);
  922. echo "<td$class align=right>$showvalue</td>";
  923. }
  924. }
  925. }
  926. }
  927. endrow();
  928. }
  929. }
  930. #
  931. # $head is a hack but this is just a demo anyway :)
  932. function doforeach($cmd, $des, $sum, $head, $datetime)
  933. {
  934. global $miner, $port;
  935. global $error, $readonly, $notify, $rigs;
  936. global $warnfont, $warnoff, $dfmt;
  937. global $rigerror;
  938. $when = 0;
  939. $header = $head;
  940. $anss = array();
  941. $count = 0;
  942. $preverr = count($rigerror);
  943. foreach ($rigs as $num => $rig)
  944. {
  945. $anss[$num] = null;
  946. if (isset($rigerror[$rig]))
  947. continue;
  948. $parts = explode(':', $rig, 3);
  949. if (count($parts) >= 2)
  950. {
  951. $miner = $parts[0];
  952. $port = $parts[1];
  953. if (count($parts) > 2)
  954. $name = $parts[2];
  955. else
  956. $name = $num;
  957. $ans = api($cmd);
  958. if ($error != null)
  959. {
  960. $rw = "<td colspan=100>Error on rig $name getting ";
  961. $rw .= "$des: $warnfont$error$warnoff</td>";
  962. otherrow($rw);
  963. $rigerror[$rig] = $error;
  964. $error = null;
  965. }
  966. else
  967. {
  968. $anss[$num] = $ans;
  969. $count++;
  970. }
  971. }
  972. }
  973. if ($count == 0)
  974. {
  975. $rw = '<td>Failed to access any rigs successfully';
  976. if ($preverr > 0)
  977. $rw .= ' (or rigs had previous errors)';
  978. $rw .= '</td>';
  979. otherrow($rw);
  980. return;
  981. }
  982. if ($datetime)
  983. {
  984. showdatetime();
  985. endtable();
  986. newtable();
  987. showrigs($anss, '', 'Rig ');
  988. endtable();
  989. otherrow('<td><br><br></td>');
  990. newtable();
  991. return;
  992. }
  993. $total = array();
  994. foreach ($anss as $rig => $ans)
  995. {
  996. if ($ans == null)
  997. continue;
  998. foreach ($ans as $item => $row)
  999. {
  1000. if ($item == 'STATUS')
  1001. continue;
  1002. if (count($row) > count($header))
  1003. {
  1004. $header = $head;
  1005. foreach ($row as $name => $value)
  1006. if (!isset($header[$name]))
  1007. $header[$name] = '';
  1008. }
  1009. if ($sum != null)
  1010. foreach ($sum as $name)
  1011. {
  1012. if (isset($row[$name]))
  1013. {
  1014. if (isset($total[$name]))
  1015. $total[$name] += $row[$name];
  1016. else
  1017. $total[$name] = $row[$name];
  1018. }
  1019. }
  1020. }
  1021. }
  1022. if ($sum != null)
  1023. $anss['total']['total'] = $total;
  1024. showhead('', $header);
  1025. foreach ($anss as $rig => $ans)
  1026. {
  1027. if ($ans == null)
  1028. continue;
  1029. $when = 0;
  1030. if (isset($ans['STATUS']['When']))
  1031. $when = $ans['STATUS']['When'];
  1032. foreach ($ans as $item => $row)
  1033. {
  1034. if ($item == 'STATUS')
  1035. continue;
  1036. newrow();
  1037. $section = preg_replace('/\d/', '', $item);
  1038. foreach ($header as $name => $x)
  1039. {
  1040. if ($name == '')
  1041. {
  1042. if ($rig === 'total')
  1043. {
  1044. list($ignore, $class) = fmt($rig, '', '', $when, $row);
  1045. echo "<td align=right$class>Total:</td>";
  1046. }
  1047. else
  1048. echo rigbutton($rig, "Rig $rig", $when, $row);
  1049. }
  1050. else
  1051. {
  1052. if (isset($row[$name]))
  1053. $value = $row[$name];
  1054. else
  1055. $value = null;
  1056. list($showvalue, $class) = fmt($section, $name, $value, $when, $row);
  1057. echo "<td$class align=right>$showvalue</td>";
  1058. }
  1059. }
  1060. endrow();
  1061. }
  1062. }
  1063. }
  1064. #
  1065. function refreshbuttons()
  1066. {
  1067. global $readonly;
  1068. global $ignorerefresh, $changerefresh, $autorefresh;
  1069. if ($ignorerefresh == false && $changerefresh == true)
  1070. {
  1071. echo '&nbsp;&nbsp;&nbsp;&nbsp;';
  1072. echo "<input type=button value='Auto Refresh:' onclick='prr(true)'>";
  1073. echo "<input type=text name='refval' id='refval' size=2 value='$autorefresh'>";
  1074. echo "<input type=button value='Off' onclick='prr(false)'>";
  1075. }
  1076. }
  1077. #
  1078. function pagebuttons($rig, $pg)
  1079. {
  1080. global $readonly, $rigs;
  1081. global $allowcustompages, $customsummarypages;
  1082. if ($rig === null)
  1083. {
  1084. if ($pg === null)
  1085. $refresh = '';
  1086. else
  1087. $refresh = "&pg=$pg";
  1088. }
  1089. else
  1090. $refresh = "&rig=$rig";
  1091. echo '<tr><td><table cellpadding=0 cellspacing=0 border=0><tr><td nowrap>';
  1092. echo "<input type=button value='Refresh' onclick='pr(\"$refresh\",null)'>&nbsp;";
  1093. if (count($rigs) > 1)
  1094. echo "<input type=button value='Summary' onclick='pr(\"\",null)'>&nbsp;";
  1095. if ($allowcustompages === true)
  1096. foreach ($customsummarypages as $pagename => $data)
  1097. echo "<input type=button value='$pagename' onclick='pr(\"&pg=$pagename\",null)'>&nbsp;";
  1098. echo '</td><td width=100%>&nbsp;</td><td nowrap>';
  1099. if ($rig !== null && $readonly === false)
  1100. {
  1101. $rg = '';
  1102. if (count($rigs) > 1)
  1103. $rg = " Rig $rig";
  1104. echo "<input type=button value='Restart' onclick='prc(\"restart&rig=$rig\",\"Restart BFGMiner$rg\")'>";
  1105. echo "&nbsp;<input type=button value='Quit' onclick='prc(\"quit&rig=$rig\",\"Quit BFGMiner$rg\")'>";
  1106. }
  1107. refreshbuttons();
  1108. echo "</td></tr></table></td></tr>";
  1109. }
  1110. #
  1111. function doOne($rig, $preprocess)
  1112. {
  1113. global $haderror, $readonly, $notify, $rigs;
  1114. global $placebuttons;
  1115. htmlhead(true, $rig);
  1116. if ($placebuttons == 'top' || $placebuttons == 'both')
  1117. pagebuttons($rig, null);
  1118. if ($preprocess != null)
  1119. process(array($preprocess => $preprocess), $rig);
  1120. $cmds = array( 'devs' => 'device list',
  1121. 'summary' => 'summary information',
  1122. 'pools' => 'pool list');
  1123. if ($notify)
  1124. $cmds['notify'] = 'device status';
  1125. $cmds['config'] = 'BFGMiner config';
  1126. process($cmds, $rig);
  1127. if ($haderror == false && $readonly === false)
  1128. processgpus($rig);
  1129. if ($placebuttons == 'bot' || $placebuttons == 'both')
  1130. pagebuttons($rig, null);
  1131. }
  1132. #
  1133. global $sectionmap;
  1134. # map sections to their api command
  1135. # DEVS is a special case that will match GPU or PGA
  1136. # so you can have a single table with both in it
  1137. # DATE is hard coded so not in here
  1138. $sectionmap = array(
  1139. 'RIGS' => 'version',
  1140. 'SUMMARY' => 'summary',
  1141. 'POOL' => 'pools',
  1142. 'DEVS' => 'devs',
  1143. 'GPU' => 'devs', // You would normally use DEVS
  1144. 'PGA' => 'devs', // You would normally use DEVS
  1145. 'NOTIFY' => 'notify',
  1146. 'CONFIG' => 'config');
  1147. #
  1148. function secmatch($section, $field)
  1149. {
  1150. if ($section == $field)
  1151. return true;
  1152. if ($section == 'DEVS'
  1153. && ($field == 'GPU' || $field == 'PGA'))
  1154. return true;
  1155. return false;
  1156. }
  1157. #
  1158. function customset($showfields, $sum, $section, $rig, $isbutton, $result, $total)
  1159. {
  1160. foreach ($result as $sec => $row)
  1161. {
  1162. $secname = preg_replace('/\d/', '', $sec);
  1163. if ($sec != 'total')
  1164. if (!secmatch($section, $secname))
  1165. continue;
  1166. newrow();
  1167. $when = 0;
  1168. if (isset($result['STATUS']['When']))
  1169. $when = $result['STATUS']['When'];
  1170. if ($isbutton)
  1171. echo rigbutton($rig, $rig, $when, $row);
  1172. else
  1173. {
  1174. list($ignore, $class) = fmt('total', '', '', $when, $row);
  1175. echo "<td align=middle$class>$rig</td>";
  1176. }
  1177. foreach ($showfields as $name => $one)
  1178. {
  1179. if (isset($row[$name]))
  1180. {
  1181. $value = $row[$name];
  1182. if (isset($sum[$section][$name]))
  1183. {
  1184. if (isset($total[$name]))
  1185. $total[$name] += $value;
  1186. else
  1187. $total[$name] = $value;
  1188. }
  1189. }
  1190. else
  1191. {
  1192. if ($sec == 'total' && isset($total[$name]))
  1193. $value = $total[$name];
  1194. else
  1195. $value = null;
  1196. }
  1197. list($showvalue, $class) = fmt($secname, $name, $value, $when, $row);
  1198. echo "<td$class align=right>$showvalue</td>";
  1199. }
  1200. endrow();
  1201. }
  1202. return $total;
  1203. }
  1204. #
  1205. function processcustompage($pagename, $sections, $sum, $namemap)
  1206. {
  1207. global $sectionmap;
  1208. global $miner, $port;
  1209. global $rigs, $error;
  1210. global $warnfont, $warnoff;
  1211. global $dfmt;
  1212. global $readonly, $showndate;
  1213. $cmds = array();
  1214. $errors = array();
  1215. foreach ($sections as $section => $fields)
  1216. {
  1217. if (isset($sectionmap[$section]))
  1218. {
  1219. $cmd = $sectionmap[$section];
  1220. if (!isset($cmds[$cmd]))
  1221. $cmds[$cmd] = 1;
  1222. }
  1223. else
  1224. if ($section != 'DATE')
  1225. $errors[] = "Error: unknown section '$section' in custom summary page '$pagename'";
  1226. }
  1227. $results = array();
  1228. foreach ($rigs as $num => $rig)
  1229. {
  1230. $parts = explode(':', $rig, 3);
  1231. if (count($parts) >= 2)
  1232. {
  1233. $miner = $parts[0];
  1234. $port = $parts[1];
  1235. if (count($parts) > 2)
  1236. $name = $parts[2];
  1237. else
  1238. $name = $rig;
  1239. foreach ($cmds as $cmd => $one)
  1240. {
  1241. $process = api($cmd);
  1242. if ($error != null)
  1243. {
  1244. $errors[] = "Error getting $cmd for $name $warnfont$error$warnoff";
  1245. break;
  1246. }
  1247. else
  1248. $results[$cmd][$num] = $process;
  1249. }
  1250. }
  1251. }
  1252. $shownsomething = false;
  1253. if (count($results) > 0)
  1254. {
  1255. $first = true;
  1256. foreach ($sections as $section => $fields)
  1257. {
  1258. if ($section === 'DATE')
  1259. {
  1260. if ($shownsomething)
  1261. otherrow('<td>&nbsp;</td>');
  1262. newtable();
  1263. showdatetime();
  1264. endtable();
  1265. // On top of the next table
  1266. $shownsomething = false;
  1267. continue;
  1268. }
  1269. if ($section === 'RIGS')
  1270. {
  1271. if ($shownsomething)
  1272. otherrow('<td>&nbsp;</td>');
  1273. newtable();
  1274. showrigs($results['version'], 'Rig', '');
  1275. endtable();
  1276. $shownsomething = true;
  1277. continue;
  1278. }
  1279. if (isset($results[$sectionmap[$section]]))
  1280. {
  1281. $rigresults = $results[$sectionmap[$section]];
  1282. $showfields = array();
  1283. $showhead = array();
  1284. foreach ($fields as $field)
  1285. foreach ($rigresults as $result)
  1286. foreach ($result as $sec => $row)
  1287. {
  1288. $secname = preg_replace('/\d/', '', $sec);
  1289. if (secmatch($section, $secname) && isset($row[$field]))
  1290. {
  1291. $showfields[$field] = 1;
  1292. $map = $section.'.'.$field;
  1293. if (isset($namemap[$map]))
  1294. $showhead[$namemap[$map]] = 1;
  1295. else
  1296. $showhead[$field] = 1;
  1297. }
  1298. }
  1299. if (count($showfields) > 0)
  1300. {
  1301. if ($shownsomething)
  1302. otherrow('<td>&nbsp;</td>');
  1303. newtable();
  1304. showhead('', array('Rig'=>1)+$showhead, true);
  1305. $total = array();
  1306. $add = array('total' => array());
  1307. foreach ($rigresults as $num => $result)
  1308. $total = customset($showfields, $sum, $section, $num, true, $result, $total);
  1309. if (count($total) > 0)
  1310. customset($showfields, $sum, $section, '&Sigma;', false, $add, $total);
  1311. $first = false;
  1312. endtable();
  1313. $shownsomething = true;
  1314. }
  1315. }
  1316. }
  1317. }
  1318. if (count($errors) > 0)
  1319. {
  1320. if (count($results) > 0)
  1321. otherrow('<td>&nbsp;</td>');
  1322. foreach ($errors as $err)
  1323. otherrow("<td colspan=100>$err</td>");
  1324. }
  1325. }
  1326. #
  1327. function showcustompage($pagename)
  1328. {
  1329. global $customsummarypages;
  1330. global $placebuttons;
  1331. htmlhead(false, null, $pagename);
  1332. if ($placebuttons == 'top' || $placebuttons == 'both')
  1333. pagebuttons(null, $pagename);
  1334. if (!isset($customsummarypages[$pagename]))
  1335. {
  1336. otherrow("<td colspan=100>Unknown custom summary page '$pagename'</td>");
  1337. return;
  1338. }
  1339. if (count($customsummarypages[$pagename]) != 2)
  1340. {
  1341. $rw = "<td colspan=100>Invalid custom summary page '$pagename' (";
  1342. $rw .= count($customsummarypages[$pagename]).')</td>';
  1343. otherrow($rw);
  1344. return;
  1345. }
  1346. $page = $customsummarypages[$pagename][0];
  1347. $namemap = array();
  1348. foreach ($page as $name => $fields)
  1349. {
  1350. if ($fields === null)
  1351. $page[$name] = array();
  1352. else
  1353. foreach ($fields as $num => $field)
  1354. {
  1355. $pos = strpos($field, '=');
  1356. if ($pos !== false)
  1357. {
  1358. $names = explode('=', $field, 2);
  1359. if (strlen($names[1]) > 0)
  1360. $namemap[$name.'.'.$names[0]] = $names[1];
  1361. $page[$name][$num] = $names[0];
  1362. }
  1363. }
  1364. }
  1365. $sum = $customsummarypages[$pagename][1];
  1366. if ($sum === null)
  1367. $sum = array();
  1368. // convert them to searchable via isset()
  1369. foreach ($sum as $section => $fields)
  1370. {
  1371. $newfields = array();
  1372. foreach ($fields as $field)
  1373. $newfields[$field] = 1;
  1374. $sum[$section] = $newfields;
  1375. }
  1376. if (count($page) <= 1)
  1377. {
  1378. otherrow("<td colspan=100>Invalid custom summary page '$pagename' no content </td>");
  1379. return;
  1380. }
  1381. processcustompage($pagename, $page, $sum, $namemap);
  1382. if ($placebuttons == 'bot' || $placebuttons == 'both')
  1383. pagebuttons(null, $pagename);
  1384. }
  1385. #
  1386. function display()
  1387. {
  1388. global $miner, $port;
  1389. global $readonly, $notify, $rigs;
  1390. global $ignorerefresh, $autorefresh;
  1391. global $allowcustompages;
  1392. global $placebuttons;
  1393. if ($ignorerefresh == false)
  1394. {
  1395. $ref = trim(getparam('ref', true));
  1396. if ($ref != null && $ref != '')
  1397. $autorefresh = intval($ref);
  1398. }
  1399. $rig = trim(getparam('rig', true));
  1400. $arg = trim(getparam('arg', true));
  1401. $preprocess = null;
  1402. if ($arg != null and $arg != '')
  1403. {
  1404. $num = null;
  1405. if ($rig != null and $rig != '')
  1406. {
  1407. if ($rig >= 0 and $rig < count($rigs))
  1408. $num = $rig;
  1409. }
  1410. else
  1411. if (count($rigs) == 0)
  1412. $num = 0;
  1413. if ($num != null)
  1414. {
  1415. $parts = explode(':', $rigs[$num], 3);
  1416. if (count($parts) >= 2)
  1417. {
  1418. $miner = $parts[0];
  1419. $port = $parts[1];
  1420. $preprocess = $arg;
  1421. }
  1422. }
  1423. }
  1424. if ($rigs == null or count($rigs) == 0)
  1425. {
  1426. otherrow("<td>No rigs defined</td>");
  1427. return;
  1428. }
  1429. if ($allowcustompages === true)
  1430. {
  1431. $pg = trim(getparam('pg', true));
  1432. if ($pg != null && $pg != '')
  1433. {
  1434. showcustompage($pg);
  1435. return;
  1436. }
  1437. }
  1438. if (count($rigs) == 1)
  1439. {
  1440. $parts = explode(':', $rigs[0], 3);
  1441. if (count($parts) >= 2)
  1442. {
  1443. $miner = $parts[0];
  1444. $port = $parts[1];
  1445. doOne(0, $preprocess);
  1446. }
  1447. else
  1448. otherrow('<td>Invalid "$rigs" array</td>');
  1449. return;
  1450. }
  1451. if ($rig != null and $rig != '' and $rig >= 0 and $rig < count($rigs))
  1452. {
  1453. $parts = explode(':', $rigs[$rig], 3);
  1454. if (count($parts) >= 2)
  1455. {
  1456. $miner = $parts[0];
  1457. $port = $parts[1];
  1458. doOne($rig, $preprocess);
  1459. }
  1460. else
  1461. otherrow('<td>Invalid "$rigs" array</td>');
  1462. return;
  1463. }
  1464. htmlhead(false, null);
  1465. if ($placebuttons == 'top' || $placebuttons == 'both')
  1466. pagebuttons(null, null);
  1467. if ($preprocess != null)
  1468. process(array($preprocess => $preprocess), $rig);
  1469. newtable();
  1470. doforeach('version', 'rig summary', array(), array(), true);
  1471. $sum = array('MHS av', 'Getworks', 'Found Blocks', 'Accepted', 'Rejected', 'Discarded', 'Stale', 'Utility', 'Local Work', 'Total MH');
  1472. doforeach('summary', 'summary information', $sum, array(), false);
  1473. endtable();
  1474. otherrow('<td><br><br></td>');
  1475. newtable();
  1476. doforeach('devs', 'device list', $sum, array(''=>'','ID'=>'','Name'=>''), false);
  1477. endtable();
  1478. otherrow('<td><br><br></td>');
  1479. newtable();
  1480. doforeach('pools', 'pool list', $sum, array(''=>''), false);
  1481. endtable();
  1482. if ($placebuttons == 'bot' || $placebuttons == 'both')
  1483. pagebuttons(null, null);
  1484. }
  1485. #
  1486. display();
  1487. #
  1488. ?>
  1489. </table></td></tr></table>
  1490. </body></html>