miner.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  1. <?php
  2. session_start();
  3. #
  4. global $miner, $port, $readonly, $notify, $rigs, $socktimeoutsec;
  5. global $checklastshare;
  6. #
  7. # Don't touch these 2 - see $rigs below
  8. $miner = null;
  9. $port = null;
  10. #
  11. # Set $readonly to true to force miner.php to be readonly
  12. # Set $readonly to false then it will check BFGMiner 'privileged'
  13. $readonly = false;
  14. #
  15. # Set $notify to false to NOT attempt to display the notify command
  16. # Set $notify to true to attempt to display the notify command
  17. # If your older version of BFGMiner returns an 'Invalid command'
  18. # coz it doesn't have notify - it just shows the error status table
  19. $notify = true;
  20. #
  21. # set $checklastshare to true to do the following checks:
  22. # If a device's last share is 12x expected ago then display as an error
  23. # If a device's last share is 8x expected ago then display as a warning
  24. # If either of the above is true, also display the whole line highlighted
  25. # This assumes shares are 1 difficulty shares
  26. $checklastshare = true;
  27. #
  28. # Set $rigs to an array of your BFGMiner rigs that are running
  29. # format: 'IP:Port' or 'Host:Port'
  30. # If you only have one rig, it will just show the detail of that rig
  31. # If you have more than one rig it will show a summary of all the rigs
  32. # with buttons to show the details of each rig
  33. # e.g. $rigs = array('127.0.0.1:4028','myrig.com:4028');
  34. $rigs = array('127.0.0.1:4028');
  35. #
  36. # This should be OK for most cases
  37. # However, the longer it is the longer you have to wait while php
  38. # hangs if the target cgminer isn't runnning or listening
  39. # Feel free to increase it if your network is very slow
  40. # Also, on some windows PHP, apparently the $usec is ignored
  41. $socktimeoutsec = 10;
  42. #
  43. $here = $_SERVER['PHP_SELF'];
  44. #
  45. global $tablebegin, $tableend, $warnfont, $warnoff, $dfmt;
  46. #
  47. $tablebegin = '<tr><td><table border=1 cellpadding=5 cellspacing=0>';
  48. $tableend = '</table></td></tr>';
  49. $warnfont = '<font color=red><b>';
  50. $warnoff = '</b></font>';
  51. $dfmt = 'H:i:s j-M-Y \U\T\CP';
  52. #
  53. # Ensure it is only ever shown once
  54. global $showndate;
  55. $showndate = false;
  56. #
  57. # For summary page to stop retrying failed rigs
  58. global $rigerror;
  59. $rigerror = array();
  60. #
  61. function htmlhead($checkapi)
  62. {
  63. global $error, $readonly, $here;
  64. if ($readonly === false && $checkapi === true)
  65. {
  66. $access = api('privileged');
  67. if ($error != null
  68. || !isset($access['STATUS']['STATUS'])
  69. || $access['STATUS']['STATUS'] != 'S')
  70. $readonly = true;
  71. }
  72. ?>
  73. <html><head><title>Mine</title>
  74. <style type='text/css'>
  75. td { color:blue; font-family:verdana,arial,sans; font-size:13pt; }
  76. td.h { color:blue; font-family:verdana,arial,sans; font-size:13pt; background:#d0ffff }
  77. td.err { color:black; font-family:verdana,arial,sans; font-size:13pt; background:#ff3050 }
  78. td.warn { color:black; font-family:verdana,arial,sans; font-size:13pt; background:#ffb050 }
  79. td.sta { color:green; font-family:verdana,arial,sans; font-size:13pt; }
  80. td.tot { color:blue; font-family:verdana,arial,sans; font-size:13pt; background:#fff8f2 }
  81. td.lst { color:blue; font-family:verdana,arial,sans; font-size:13pt; background:#ffffdd }
  82. </style>
  83. </head><body bgcolor=#ecffff>
  84. <script type='text/javascript'>
  85. function pr(a,m){if(m!=null){if(!confirm(m+'?'))return}window.location="<?php echo $here ?>"+a}
  86. <?php
  87. if ($readonly === false && $checkapi === true)
  88. {
  89. ?>
  90. function prc(a,m){pr('?arg='+a,m)}
  91. 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)}
  92. 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)}
  93. <?php
  94. }
  95. ?>
  96. </script>
  97. <table width=100% height=100% border=0 cellpadding=0 cellspacing=0 summary='Mine'>
  98. <tr><td align=center valign=top>
  99. <table border=0 cellpadding=4 cellspacing=0 summary='Mine'>
  100. <?php
  101. }
  102. #
  103. global $error;
  104. $error = null;
  105. #
  106. function getsock($addr, $port)
  107. {
  108. global $error, $socktimeoutsec;
  109. $socket = null;
  110. $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  111. if ($socket === false || $socket === null)
  112. {
  113. $error = socket_strerror(socket_last_error());
  114. $msg = "socket create(TCP) failed";
  115. $error = "ERR: $msg '$error'\n";
  116. return null;
  117. }
  118. // Ignore if this fails since the socket connect may work anyway
  119. // and nothing is gained by aborting if the option cannot be set
  120. // since we don't know in advance if it can connect
  121. socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, array('sec' => $socktimeoutsec, 'usec' => 0));
  122. $res = socket_connect($socket, $addr, $port);
  123. if ($res === false)
  124. {
  125. $error = socket_strerror(socket_last_error());
  126. $msg = "socket connect($addr,$port) failed";
  127. $error = "ERR: $msg '$error'\n";
  128. socket_close($socket);
  129. return null;
  130. }
  131. return $socket;
  132. }
  133. #
  134. function readsockline($socket)
  135. {
  136. $line = '';
  137. while (true)
  138. {
  139. $byte = socket_read($socket, 1);
  140. if ($byte === false || $byte === '')
  141. break;
  142. if ($byte === "\0")
  143. break;
  144. $line .= $byte;
  145. }
  146. return $line;
  147. }
  148. #
  149. function api($cmd)
  150. {
  151. global $miner, $port;
  152. $socket = getsock($miner, $port);
  153. if ($socket != null)
  154. {
  155. socket_write($socket, $cmd, strlen($cmd));
  156. $line = readsockline($socket);
  157. socket_close($socket);
  158. if (strlen($line) == 0)
  159. {
  160. $error = "WARN: '$cmd' returned nothing\n";
  161. return $line;
  162. }
  163. # print "$cmd returned '$line'\n";
  164. $data = array();
  165. $objs = explode('|', $line);
  166. foreach ($objs as $obj)
  167. {
  168. if (strlen($obj) > 0)
  169. {
  170. $items = explode(',', $obj);
  171. $item = $items[0];
  172. $id = explode('=', $items[0], 2);
  173. if (count($id) == 1 or !ctype_digit($id[1]))
  174. $name = $id[0];
  175. else
  176. $name = $id[0].$id[1];
  177. if (strlen($name) == 0)
  178. $name = 'null';
  179. if (isset($data[$name]))
  180. {
  181. $num = 1;
  182. while (isset($data[$name.$num]))
  183. $num++;
  184. $name .= $num;
  185. }
  186. $counter = 0;
  187. foreach ($items as $item)
  188. {
  189. $id = explode('=', $item, 2);
  190. if (count($id) == 2)
  191. $data[$name][$id[0]] = $id[1];
  192. else
  193. $data[$name][$counter] = $id[0];
  194. $counter++;
  195. }
  196. }
  197. }
  198. return $data;
  199. }
  200. return null;
  201. }
  202. #
  203. function getparam($name, $both = false)
  204. {
  205. $a = null;
  206. if (isset($_POST[$name]))
  207. $a = $_POST[$name];
  208. if (($both === true) and ($a === null))
  209. {
  210. if (isset($_GET[$name]))
  211. $a = $_GET[$name];
  212. }
  213. if ($a == '' || $a == null)
  214. return null;
  215. // limit to 1K just to be safe
  216. return substr($a, 0, 1024);
  217. }
  218. #
  219. function classlastshare($when, $alldata, $warnclass, $errorclass)
  220. {
  221. global $checklastshare;
  222. if ($checklastshare === false)
  223. return '';
  224. if ($when == 0)
  225. return '';
  226. if (!isset($alldata['MHS av']))
  227. return '';
  228. if (!isset($alldata['Last Share Time']))
  229. return '';
  230. $expected = pow(2, 32) / ($alldata['MHS av'] * pow(10, 6));
  231. $howlong = $when - $alldata['Last Share Time'];
  232. if ($howlong < 1)
  233. $howlong = 1;
  234. if ($howlong > ($expected * 12))
  235. return $errorclass;
  236. if ($howlong > ($expected * 8))
  237. return $warnclass;
  238. return '';
  239. }
  240. #
  241. function fmt($section, $name, $value, $when, $alldata)
  242. {
  243. global $dfmt;
  244. if ($alldata == null)
  245. $alldata = array();
  246. $errorclass = ' class=err';
  247. $warnclass = ' class=warn';
  248. $lstclass = ' class=lst';
  249. $b = '&nbsp;';
  250. $ret = $value;
  251. $class = '';
  252. if ($value === null)
  253. $ret = $b;
  254. else
  255. switch ($section.'.'.$name)
  256. {
  257. case 'GPU.Last Share Time':
  258. case 'PGA.Last Share Time':
  259. if ($value == 0
  260. || (isset($alldata['Last Share Pool']) && $alldata['Last Share Pool'] == -1))
  261. {
  262. $ret = 'Never';
  263. $class = $warnclass;
  264. }
  265. else
  266. {
  267. $ret = date('H:i:s', $value);
  268. $class = classlastshare($when, $alldata, $warnclass, $errorclass);
  269. }
  270. break;
  271. case 'POOL.Last Share Time':
  272. if ($value == 0)
  273. $ret = 'Never';
  274. else
  275. $ret = date('H:i:s d-M', $value);
  276. break;
  277. case 'GPU.Last Share Pool':
  278. case 'PGA.Last Share Pool':
  279. if ($value == -1)
  280. {
  281. $ret = 'None';
  282. $class = $warnclass;
  283. }
  284. break;
  285. case 'SUMMARY.Elapsed':
  286. $s = $value % 60;
  287. $value -= $s;
  288. $value /= 60;
  289. if ($value == 0)
  290. $ret = $s.'s';
  291. else
  292. {
  293. $m = $value % 60;
  294. $value -= $m;
  295. $value /= 60;
  296. if ($value == 0)
  297. $ret = sprintf("%dm$b%02ds", $m, $s);
  298. else
  299. {
  300. $h = $value % 24;
  301. $value -= $h;
  302. $value /= 24;
  303. if ($value == 0)
  304. $ret = sprintf("%dh$b%02dm$b%02ds", $h, $m, $s);
  305. else
  306. {
  307. if ($value == 1)
  308. $days = '';
  309. else
  310. $days = 's';
  311. $ret = sprintf("%dday$days$b%02dh$b%02dm$b%02ds", $value, $h, $m, $s);
  312. }
  313. }
  314. }
  315. break;
  316. case 'NOTIFY.Last Well':
  317. if ($value == '0')
  318. {
  319. $ret = 'Never';
  320. $class = $warnclass;
  321. }
  322. else
  323. $ret = date('H:i:s', $value);
  324. break;
  325. case 'NOTIFY.Last Not Well':
  326. if ($value == '0')
  327. $ret = 'Never';
  328. else
  329. {
  330. $ret = date('H:i:s', $value);
  331. $class = $errorclass;
  332. }
  333. break;
  334. case 'NOTIFY.Reason Not Well':
  335. if ($value != 'None')
  336. $class = $errorclass;
  337. break;
  338. case 'GPU.Utility':
  339. case 'PGA.Utility':
  340. case 'SUMMARY.Utility':
  341. $ret = $value.'/m';
  342. if ($value == 0)
  343. $class = $warnclass;
  344. break;
  345. case 'PGA.Temperature':
  346. $ret = $value.'&deg;C';
  347. break;
  348. case 'GPU.Temperature':
  349. $ret = $value.'&deg;C';
  350. case 'GPU.GPU Clock':
  351. case 'GPU.Memory Clock':
  352. case 'GPU.GPU Voltage':
  353. case 'GPU.GPU Activity':
  354. if ($value == 0)
  355. $class = $warnclass;
  356. break;
  357. case 'GPU.Fan Percent':
  358. if ($value == 0)
  359. $class = $warnclass;
  360. else
  361. {
  362. if ($value == 100)
  363. $class = $errorclass;
  364. else
  365. if ($value > 85)
  366. $class = $warnclass;
  367. }
  368. break;
  369. case 'GPU.Fan Speed':
  370. if ($value == 0)
  371. $class = $warnclass;
  372. else
  373. if (isset($alldata['Fan Percent']))
  374. {
  375. $test = $alldata['Fan Percent'];
  376. if ($test == 100)
  377. $class = $errorclass;
  378. else
  379. if ($test > 85)
  380. $class = $warnclass;
  381. }
  382. break;
  383. case 'GPU.MHS av':
  384. case 'PGA.MHS av':
  385. case 'SUMMARY.MHS av':
  386. case 'GPU.Total MH':
  387. case 'PGA.Total MH':
  388. case 'SUMMARY.Total MH':
  389. case 'SUMMARY.Getworks':
  390. case 'GPU.Accepted':
  391. case 'PGA.Accepted':
  392. case 'SUMMARY.Accepted':
  393. case 'GPU.Rejected':
  394. case 'PGA.Rejected':
  395. case 'SUMMARY.Rejected':
  396. case 'SUMMARY.Local Work':
  397. case 'POOL.Getworks':
  398. case 'POOL.Accepted':
  399. case 'POOL.Rejected':
  400. case 'POOL.Discarded':
  401. $parts = explode('.', $value, 2);
  402. if (count($parts) == 1)
  403. $dec = '';
  404. else
  405. $dec = '.'.$parts[1];
  406. $ret = number_format($parts[0]).$dec;
  407. break;
  408. case 'GPU.Status':
  409. case 'PGA.Status':
  410. case 'POOL.Status':
  411. if ($value != 'Alive')
  412. $class = $errorclass;
  413. break;
  414. case 'GPU.Enabled':
  415. case 'PGA.Enabled':
  416. if ($value != 'Y')
  417. $class = $warnclass;
  418. break;
  419. case 'STATUS.When':
  420. $ret = date($dfmt, $value);
  421. break;
  422. }
  423. if ($section == 'NOTIFY' && substr($name, 0, 1) == '*' && $value != '0')
  424. $class = $errorclass;
  425. if ($class == '' && $section != 'POOL')
  426. $class = classlastshare($when, $alldata, $lstclass, $lstclass);
  427. return array($ret, $class);
  428. }
  429. #
  430. global $poolcmd;
  431. $poolcmd = array( 'Switch to' => 'switchpool',
  432. 'Enable' => 'enablepool',
  433. 'Disable' => 'disablepool' );
  434. #
  435. function showhead($cmd, $item, $values)
  436. {
  437. global $poolcmd, $readonly;
  438. echo '<tr>';
  439. foreach ($values as $name => $value)
  440. {
  441. if ($name == '0' or $name == '')
  442. $name = '&nbsp;';
  443. echo "<td valign=bottom class=h>$name</td>";
  444. }
  445. if ($cmd == 'pools' && $readonly === false)
  446. foreach ($poolcmd as $name => $pcmd)
  447. echo "<td valign=bottom class=h>$name</td>";
  448. echo '</tr>';
  449. }
  450. #
  451. function details($cmd, $list, $rig)
  452. {
  453. global $tablebegin, $tableend, $dfmt;
  454. global $poolcmd, $readonly;
  455. global $showndate;
  456. $when = 0;
  457. $stas = array('S' => 'Success', 'W' => 'Warning', 'I' => 'Informational', 'E' => 'Error', 'F' => 'Fatal');
  458. echo $tablebegin;
  459. if ($showndate === false)
  460. {
  461. echo '<tr><td class=sta>Date: '.date($dfmt).'</td></tr>';
  462. echo $tableend.$tablebegin;
  463. $showndate = true;
  464. }
  465. if (isset($list['STATUS']))
  466. {
  467. echo '<tr>';
  468. echo '<td>Computer: '.$list['STATUS']['Description'].'</td>';
  469. if (isset($list['STATUS']['When']))
  470. {
  471. echo '<td>When: '.date($dfmt, $list['STATUS']['When']).'</td>';
  472. $when = $list['STATUS']['When'];
  473. }
  474. $sta = $list['STATUS']['STATUS'];
  475. echo '<td>Status: '.$stas[$sta].'</td>';
  476. echo '<td>Message: '.$list['STATUS']['Msg'].'</td>';
  477. echo '</tr>';
  478. }
  479. $section = '';
  480. foreach ($list as $item => $values)
  481. {
  482. if ($item == 'STATUS')
  483. continue;
  484. $sectionname = preg_replace('/\d/', '', $item);
  485. if ($sectionname != $section)
  486. {
  487. echo $tableend.$tablebegin;
  488. showhead($cmd, $item, $values);
  489. $section = $sectionname;
  490. }
  491. echo '<tr>';
  492. foreach ($values as $name => $value)
  493. {
  494. list($showvalue, $class) = fmt($section, $name, $value, $when, $values);
  495. echo "<td$class>$showvalue</td>";
  496. }
  497. if ($cmd == 'pools' && $readonly === false)
  498. {
  499. reset($values);
  500. $pool = current($values);
  501. foreach ($poolcmd as $name => $pcmd)
  502. {
  503. echo '<td>';
  504. if ($pool === false)
  505. echo '&nbsp;';
  506. else
  507. {
  508. echo "<input type=button value='Pool $pool'";
  509. echo " onclick='prc(\"$pcmd|$pool&rig=$rig\",\"$name Pool $pool\")'>";
  510. }
  511. echo '</td>';
  512. }
  513. }
  514. echo '</tr>';
  515. }
  516. echo $tableend;
  517. }
  518. #
  519. global $devs;
  520. $devs = null;
  521. #
  522. function gpubuttons($count, $rig)
  523. {
  524. global $tablebegin, $tableend;
  525. global $devs;
  526. $basic = array( 'GPU', 'Enable', 'Disable', 'Restart' );
  527. $options = array( 'intensity' => 'Intensity',
  528. 'fan' => 'Fan Percent',
  529. 'engine' => 'GPU Clock',
  530. 'mem' => 'Memory Clock',
  531. 'vddc' => 'GPU Voltage' );
  532. echo $tablebegin.'<tr>';
  533. foreach ($basic as $head)
  534. echo "<td>$head</td>";
  535. foreach ($options as $name => $des)
  536. echo "<td nowrap>$des</td>";
  537. $n = 0;
  538. for ($c = 0; $c < $count; $c++)
  539. {
  540. echo '</tr><tr>';
  541. foreach ($basic as $name)
  542. {
  543. echo '<td>';
  544. if ($name == 'GPU')
  545. echo $c;
  546. else
  547. {
  548. echo "<input type=button value='$name $c' onclick='prs(\"gpu";
  549. echo strtolower($name);
  550. echo "|$c\",$rig)'>";
  551. }
  552. echo '</td>';
  553. }
  554. foreach ($options as $name => $des)
  555. {
  556. echo '<td>';
  557. if (!isset($devs["GPU$c"][$des]))
  558. echo '&nbsp;';
  559. else
  560. {
  561. $value = $devs["GPU$c"][$des];
  562. echo "<input type=button value='Set $c:' onclick='prs2(\"gpu$name|$c\",$n,$rig)'>";
  563. echo "<input size=7 type=text name=gi$n value='$value' id=gi$n>";
  564. $n++;
  565. }
  566. echo '</td>';
  567. }
  568. }
  569. echo '</tr>'.$tableend;
  570. }
  571. #
  572. function processgpus($rig)
  573. {
  574. global $error;
  575. global $warnfont, $warnoff;
  576. $gpus = api('gpucount');
  577. if ($error != null)
  578. echo '<tr><td>Error getting GPU count: '.$warnfont.$error.$warnoff.'</td></tr>';
  579. else
  580. {
  581. if (!isset($gpus['GPUS']['Count']))
  582. echo '<tr><td>No GPU count returned: '.$warnfont.$gpus['STATUS']['STATUS'].' '.$gpus['STATUS']['Msg'].$ro.'</td></tr>';
  583. else
  584. {
  585. $count = $gpus['GPUS']['Count'];
  586. if ($count == 0)
  587. echo '<tr><td>No GPUs</td></tr>';
  588. else
  589. gpubuttons($count, $rig);
  590. }
  591. }
  592. }
  593. #
  594. function process($cmds, $rig)
  595. {
  596. global $error, $devs;
  597. global $warnfont, $warnoff;
  598. foreach ($cmds as $cmd => $des)
  599. {
  600. $process = api($cmd);
  601. if ($error != null)
  602. {
  603. echo "<tr><td colspan=100>Error getting $des: ";
  604. echo $warnfont.$error.$warnoff.'</td></tr>';
  605. break;
  606. }
  607. else
  608. {
  609. details($cmd, $process, $rig);
  610. echo '<tr><td><br><br></td></tr>';
  611. if ($cmd == 'devs')
  612. $devs = $process;
  613. }
  614. }
  615. }
  616. #
  617. # $head is a hack but this is just a demo anyway :)
  618. function doforeach($cmd, $des, $sum, $head, $datetime)
  619. {
  620. global $miner, $port;
  621. global $error, $readonly, $notify, $rigs;
  622. global $tablebegin, $tableend, $warnfont, $warnoff, $dfmt;
  623. global $rigerror;
  624. $when = 0;
  625. $header = $head;
  626. $anss = array();
  627. $count = 0;
  628. $preverr = count($rigerror);
  629. foreach ($rigs as $rig)
  630. {
  631. if (isset($rigerror[$rig]))
  632. continue;
  633. $parts = explode(':', $rig, 2);
  634. if (count($parts) == 2)
  635. {
  636. $miner = $parts[0];
  637. $port = $parts[1];
  638. $ans = api($cmd);
  639. if ($error != null)
  640. {
  641. echo "<tr><td colspan=100>Error on rig $count getting $des: ";
  642. echo $warnfont.$error.$warnoff.'</td></tr>';
  643. $rigerror[$rig] = $error;
  644. $error = null;
  645. }
  646. else
  647. $anss[$count] = $ans;
  648. }
  649. $count++;
  650. }
  651. if (count($anss) == 0)
  652. {
  653. echo '<tr><td>Failed to access any rigs successfully';
  654. if ($preverr > 0)
  655. echo ' (or rigs had previous errors)';
  656. echo '</td></tr>';
  657. return;
  658. }
  659. if ($datetime)
  660. {
  661. echo '<tr><td class=sta>Date: '.date($dfmt).'</td></tr>';
  662. echo $tableend.$tablebegin;
  663. $dthead = array('' => 1, 'STATUS' => 1, 'Description' => 1, 'When' => 1);
  664. showhead('', null, $dthead);
  665. foreach ($anss as $rig => $ans)
  666. {
  667. echo '<tr>';
  668. foreach ($ans as $item => $row)
  669. {
  670. if ($item != 'STATUS')
  671. continue;
  672. foreach ($dthead as $name => $x)
  673. {
  674. if ($name == '')
  675. echo "<td align=right><input type=button value='Rig $rig' onclick='pr(\"?rig=$rig\",null)'></td>";
  676. else
  677. {
  678. if (isset($row[$name]))
  679. list($showvalue, $class) = fmt('STATUS', $name, $row[$name], $when, null);
  680. else
  681. {
  682. $class = '';
  683. $showvalue = '&nbsp;';
  684. }
  685. echo "<td$class align=right>$showvalue</td>";
  686. }
  687. }
  688. }
  689. echo '</tr>';
  690. }
  691. echo $tableend;
  692. echo '<tr><td><br><br></td></tr>';
  693. echo $tablebegin;
  694. }
  695. $total = array();
  696. foreach ($anss as $rig => $ans)
  697. {
  698. foreach ($ans as $item => $row)
  699. {
  700. if ($item == 'STATUS')
  701. continue;
  702. if (count($row) > count($header))
  703. {
  704. $header = $head;
  705. foreach ($row as $name => $value)
  706. if (!isset($header[$name]))
  707. $header[$name] = '';
  708. }
  709. if ($sum != null)
  710. foreach ($sum as $name)
  711. {
  712. if (isset($row[$name]))
  713. {
  714. if (isset($total[$name]))
  715. $total[$name] += $row[$name];
  716. else
  717. $total[$name] = $row[$name];
  718. }
  719. }
  720. }
  721. }
  722. if ($sum != null)
  723. $anss['total']['total'] = $total;
  724. showhead('', null, $header);
  725. $section = '';
  726. foreach ($anss as $rig => $ans)
  727. {
  728. $when = 0;
  729. if (isset($ans['STATUS']['When']))
  730. $when = $ans['STATUS']['When'];
  731. foreach ($ans as $item => $row)
  732. {
  733. if ($item == 'STATUS')
  734. continue;
  735. echo '<tr>';
  736. $newsection = preg_replace('/\d/', '', $item);
  737. if ($newsection != 'total')
  738. $section = $newsection;
  739. foreach ($header as $name => $x)
  740. {
  741. if ($name == '')
  742. {
  743. if ($rig === 'total')
  744. echo "<td align=right class=tot>Total:</td>";
  745. else
  746. echo "<td align=right><input type=button value='Rig $rig' onclick='pr(\"?rig=$rig\",null)'></td>";
  747. }
  748. else
  749. {
  750. if (isset($row[$name]))
  751. $value = $row[$name];
  752. else
  753. $value = null;
  754. list($showvalue, $class) = fmt($section, $name, $value, $when, $row);
  755. if ($rig === 'total' and $class == '')
  756. $class = ' class=tot';
  757. echo "<td$class align=right>$showvalue</td>";
  758. }
  759. }
  760. echo '</tr>';
  761. }
  762. }
  763. }
  764. #
  765. function doOne($rig, $preprocess)
  766. {
  767. global $error, $readonly, $notify;
  768. global $rigs;
  769. htmlhead(true);
  770. $error = null;
  771. echo "<tr><td><table cellpadding=0 cellspacing=0 border=0><tr><td>";
  772. echo "<input type=button value='Refresh' onclick='pr(\"?rig=$rig\",null)'></td>";
  773. if (count($rigs) > 1)
  774. echo "<td><input type=button value='Summary' onclick='pr(\"\",null)'></td>";
  775. echo "<td width=100%>&nbsp;</td><td>";
  776. if ($readonly === false)
  777. {
  778. $msg = 'Quit BFGMiner';
  779. if (count($rigs) > 1)
  780. $msg .= " Rig $rig";
  781. echo "<input type=button value='Quit' onclick='prc(\"quit&rig=$rig\",\"$msg\")'>";
  782. }
  783. echo "</td></tr></table></td></tr>";
  784. if ($preprocess != null)
  785. process(array($preprocess => $preprocess), $rig);
  786. $cmds = array( 'devs' => 'device list',
  787. 'summary' => 'summary information',
  788. 'pools' => 'pool list');
  789. if ($notify)
  790. $cmds['notify'] = 'device status';
  791. $cmds['config'] = 'BFGMiner config';
  792. process($cmds, $rig);
  793. if ($error == null && $readonly === false)
  794. processgpus($rig);
  795. }
  796. #
  797. function display()
  798. {
  799. global $tablebegin, $tableend;
  800. global $miner, $port;
  801. global $error, $readonly, $notify, $rigs;
  802. $rig = trim(getparam('rig', true));
  803. $arg = trim(getparam('arg', true));
  804. $preprocess = null;
  805. if ($arg != null and $arg != '')
  806. {
  807. $num = null;
  808. if ($rig != null and $rig != '')
  809. {
  810. if ($rig >= 0 and $rig < count($rigs))
  811. $num = $rig;
  812. }
  813. else
  814. if (count($rigs) == 0)
  815. $num = 0;
  816. if ($num != null)
  817. {
  818. $parts = explode(':', $rigs[$num], 2);
  819. if (count($parts) == 2)
  820. {
  821. $miner = $parts[0];
  822. $port = $parts[1];
  823. $preprocess = $arg;
  824. }
  825. }
  826. }
  827. if ($rigs == null or count($rigs) == 0)
  828. {
  829. echo "<tr><td>No rigs defined</td></tr>";
  830. return;
  831. }
  832. if (count($rigs) == 1)
  833. {
  834. $parts = explode(':', $rigs[0], 2);
  835. if (count($parts) == 2)
  836. {
  837. $miner = $parts[0];
  838. $port = $parts[1];
  839. doOne(0, $preprocess);
  840. }
  841. else
  842. echo '<tr><td>Invalid "$rigs" array</td></tr>';
  843. return;
  844. }
  845. if ($rig != null and $rig != '' and $rig >= 0 and $rig < count($rigs))
  846. {
  847. $parts = explode(':', $rigs[$rig], 2);
  848. if (count($parts) == 2)
  849. {
  850. $miner = $parts[0];
  851. $port = $parts[1];
  852. doOne($rig, $preprocess);
  853. }
  854. else
  855. echo '<tr><td>Invalid "$rigs" array</td></tr>';
  856. return;
  857. }
  858. htmlhead(false);
  859. echo "<tr><td><table cellpadding=0 cellspacing=0 border=0><tr><td>";
  860. echo "<input type=button value='Refresh' onclick='pr(\"\",null)'>";
  861. echo "</td></tr></table></td></tr>";
  862. if ($preprocess != null)
  863. process(array($preprocess => $preprocess), $rig);
  864. echo $tablebegin;
  865. $sum = array('MHS av', 'Getworks', 'Found Blocks', 'Accepted', 'Rejected', 'Discarded', 'Stale', 'Utility', 'Local Work', 'Total MH');
  866. doforeach('summary', 'summary information', $sum, array(), true);
  867. echo $tableend;
  868. echo '<tr><td><br><br></td></tr>';
  869. echo $tablebegin;
  870. doforeach('devs', 'device list', $sum, array(''=>'','ID'=>'','Name'=>''), false);
  871. echo $tableend;
  872. echo '<tr><td><br><br></td></tr>';
  873. echo $tablebegin;
  874. doforeach('pools', 'pool list', $sum, array(''=>''), false);
  875. echo $tableend;
  876. }
  877. #
  878. display();
  879. #
  880. ?>
  881. </table></td></tr></table>
  882. </body></html>