miner.php 17 KB

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