miner.php 41 KB

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