miner.php 18 KB

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