miner.php 19 KB

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