miner.php 17 KB

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