miner.php 19 KB

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