miner.php 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357
  1. <?php
  2. session_start();
  3. #
  4. global $miner, $port, $readonly, $notify, $rigs, $socktimeoutsec;
  5. global $checklastshare, $hidefields;
  6. global $ignorerefresh, $changerefresh, $autorefresh;
  7. global $allowcustompages, $customsummarypages;
  8. #
  9. # Don't touch these 2 - see $rigs below
  10. $miner = null;
  11. $port = null;
  12. #
  13. # Set $readonly to true to force miner.php to be readonly
  14. # Set $readonly to false then it will check cgminer 'privileged'
  15. $readonly = false;
  16. #
  17. # Set $notify to false to NOT attempt to display the notify command
  18. # Set $notify to true to attempt to display the notify command
  19. # If your older version of cgminer returns an 'Invalid command'
  20. # coz it doesn't have notify - it just shows the error status table
  21. $notify = true;
  22. #
  23. # set $checklastshare to true to do the following checks:
  24. # If a device's last share is 12x expected ago then display as an error
  25. # If a device's last share is 8x expected ago then display as a warning
  26. # If either of the above is true, also display the whole line highlighted
  27. # This assumes shares are 1 difficulty shares
  28. $checklastshare = true;
  29. #
  30. # Set $rigs to an array of your cgminer rigs that are running
  31. # format: 'IP:Port' or 'Host:Port'
  32. # If you only have one rig, it will just show the detail of that rig
  33. # If you have more than one rig it will show a summary of all the rigs
  34. # with buttons to show the details of each rig
  35. # e.g. $rigs = array('127.0.0.1:4028','myrig.com:4028');
  36. $rigs = array('127.0.0.1:4028');
  37. #
  38. # This should be OK for most cases
  39. # However, the longer it is the longer you have to wait while php
  40. # hangs if the target cgminer isn't runnning or listening
  41. # Feel free to increase it if your network is very slow
  42. # Also, on some windows PHP, apparently the $usec is ignored
  43. $socktimeoutsec = 10;
  44. #
  45. # List of fields NOT to be displayed
  46. # You can use this to hide data you don't want to see or don't want
  47. # shown on a public web page
  48. # The list of sections are: SUMMARY, POOL, PGA, GPU, NOTIFY, CONFIG
  49. # See the web page for the list of field names (the table headers)
  50. # It is an array of 'SECTION.Field Name' => 1
  51. # This example would hide the slightly more sensitive pool information
  52. #$hidefields = array('POOL.URL' => 1, 'POOL.User' => 1);
  53. $hidefields = array();
  54. #
  55. # Auto-refresh of the page (in seconds)
  56. # $ignorerefresh = true/false always ignore refresh parameters
  57. # $changerefresh = true/false show buttons to change the value
  58. # $autorefresh = default value, 0 means dont auto-refresh
  59. $ignorerefresh = false;
  60. $changerefresh = true;
  61. $autorefresh = 0;
  62. #
  63. # Should we allow custom pages?
  64. # (or just completely ignore then and don't display the buttons)
  65. $allowcustompages = true;
  66. #
  67. # OK this is a bit more complex item: Custom Summary Pages
  68. # A custom summary page in an array of 'section' => array('FieldA','FieldB'...)
  69. # This makes up what is displayed with each 'section' separately as a table
  70. # - empty tables are not shown
  71. # - empty columns (an unknown field) are not shown
  72. # - and missing field data shows as blank
  73. # There is a second array, listing fields to be totaled for each section
  74. # see the example below (if there is no matching data, no total will show)
  75. $mobilepage = array(
  76. 'SUMMARY' => array('Elapsed', 'MHS av', 'Found Blocks', 'Accepted', 'Rejected', 'Utility'),
  77. 'GPU' => array('GPU', 'Status', 'MHS av', 'Accepted', 'Rejected', 'Utility'),
  78. 'PGA' => array('ID', 'Name', 'Status', 'MHS av', 'Accepted', 'Rejected', 'Utility'),
  79. 'POOL' => array('POOL', 'Status', 'Accepted', 'Rejected', 'Last Share Time'));
  80. $mobilesum = array(
  81. 'SUMMARY' => array('MHS av' => 1, 'Found Blocks' => 1, 'Accepted' => 1, 'Rejected' => 1, 'Utility' => 1),
  82. 'GPU' => array('MHS av' => 1, 'Accepted' => 1, 'Rejected' => 1, 'Utility' => 1),
  83. 'PGA' => array('MHS av' => 1, 'Accepted' => 1, 'Rejected' => 1, 'Utility' => 1),
  84. 'POOL' => array('Accepted' => 1, 'Rejected' => 1));
  85. #
  86. # customsummarypages is an array of these Custom Summary Pages
  87. $customsummarypages = array('Mobile' => array($mobilepage, $mobilesum));
  88. #
  89. $here = $_SERVER['PHP_SELF'];
  90. #
  91. global $tablebegin, $tableend, $warnfont, $warnoff, $dfmt;
  92. #
  93. $tablebegin = '<tr><td><table border=1 cellpadding=5 cellspacing=0>';
  94. $tableend = '</table></td></tr>';
  95. $warnfont = '<font color=red><b>';
  96. $warnoff = '</b></font>';
  97. $dfmt = 'H:i:s j-M-Y \U\T\CP';
  98. #
  99. global $miner_font_family, $miner_font_size;
  100. #
  101. $miner_font_family = 'verdana,arial,sans';
  102. $miner_font_size = '13pt';
  103. #
  104. # This below allows you to put your own settings into a seperate file
  105. # so you don't need to update miner.php with your preferred settings
  106. # every time a new version is released
  107. # Just create the file 'myminer.php' in the same directory as
  108. # 'miner.php' - and put your own settings in there
  109. if (file_exists('myminer.php'))
  110. include_once('myminer.php');
  111. #
  112. # Ensure it is only ever shown once
  113. global $showndate;
  114. $showndate = false;
  115. #
  116. # For summary page to stop retrying failed rigs
  117. global $rigerror;
  118. $rigerror = array();
  119. #
  120. function htmlhead($checkapi, $rig)
  121. {
  122. global $miner_font_family, $miner_font_size;
  123. global $error, $readonly, $here;
  124. global $ignorerefresh, $autorefresh;
  125. $paramrig = '';
  126. if ($rig != null && $rig != '')
  127. $paramrig = "&rig=$rig";
  128. if ($ignorerefresh == true || $autorefresh == 0)
  129. $refreshmeta = '';
  130. else
  131. {
  132. $url = "$here?ref=$autorefresh$paramrig";
  133. $refreshmeta = "\n<meta http-equiv='refresh' content='$autorefresh;url=$url'>";
  134. }
  135. if ($readonly === false && $checkapi === true)
  136. {
  137. $error = null;
  138. $access = api('privileged');
  139. if ($error != null
  140. || !isset($access['STATUS']['STATUS'])
  141. || $access['STATUS']['STATUS'] != 'S')
  142. $readonly = true;
  143. }
  144. $miner_font = "font-family:$miner_font_family; font-size:$miner_font_size;";
  145. echo "<html><head>$refreshmeta
  146. <title>Mine</title>
  147. <style type='text/css'>
  148. td { color:blue; $miner_font }
  149. td.h { color:blue; $miner_font background:#d0ffff }
  150. td.err { color:black; $miner_font background:#ff3050 }
  151. td.warn { color:black; $miner_font background:#ffb050 }
  152. td.sta { color:green; $miner_font }
  153. td.tot { color:blue; $miner_font background:#fff8f2 }
  154. td.lst { color:blue; $miner_font background:#ffffdd }
  155. </style>
  156. </head><body bgcolor=#ecffff>
  157. <script type='text/javascript'>
  158. function pr(a,m){if(m!=null){if(!confirm(m+'?'))return}window.location='$here?ref=$autorefresh'+a}\n";
  159. if ($ignorerefresh == false)
  160. echo "function prr(a){if(a){v=document.getElementById('refval').value}else{v=0}window.location='$here?ref='+v+'$paramrig'}\n";
  161. if ($readonly === false && $checkapi === true)
  162. {
  163. echo "function prc(a,m){pr('&arg='+a,m)}
  164. 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)}
  165. 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)}\n";
  166. }
  167. ?>
  168. </script>
  169. <table width=100% height=100% border=0 cellpadding=0 cellspacing=0 summary='Mine'>
  170. <tr><td align=center valign=top>
  171. <table border=0 cellpadding=4 cellspacing=0 summary='Mine'>
  172. <?php
  173. }
  174. #
  175. global $haderror, $error;
  176. $haderror = false;
  177. $error = null;
  178. #
  179. function getsock($addr, $port)
  180. {
  181. global $haderror, $error, $socktimeoutsec;
  182. $error = null;
  183. $socket = null;
  184. $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  185. if ($socket === false || $socket === null)
  186. {
  187. $haderror = true;
  188. $error = socket_strerror(socket_last_error());
  189. $msg = "socket create(TCP) failed";
  190. $error = "ERR: $msg '$error'\n";
  191. return null;
  192. }
  193. // Ignore if this fails since the socket connect may work anyway
  194. // and nothing is gained by aborting if the option cannot be set
  195. // since we don't know in advance if it can connect
  196. socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, array('sec' => $socktimeoutsec, 'usec' => 0));
  197. $res = socket_connect($socket, $addr, $port);
  198. if ($res === false)
  199. {
  200. $haderror = true;
  201. $error = socket_strerror(socket_last_error());
  202. $msg = "socket connect($addr,$port) failed";
  203. $error = "ERR: $msg '$error'\n";
  204. socket_close($socket);
  205. return null;
  206. }
  207. return $socket;
  208. }
  209. #
  210. function readsockline($socket)
  211. {
  212. $line = '';
  213. while (true)
  214. {
  215. $byte = socket_read($socket, 1);
  216. if ($byte === false || $byte === '')
  217. break;
  218. if ($byte === "\0")
  219. break;
  220. $line .= $byte;
  221. }
  222. return $line;
  223. }
  224. #
  225. function api($cmd)
  226. {
  227. global $haderror, $error;
  228. global $miner, $port, $hidefields;
  229. $socket = getsock($miner, $port);
  230. if ($socket != null)
  231. {
  232. socket_write($socket, $cmd, strlen($cmd));
  233. $line = readsockline($socket);
  234. socket_close($socket);
  235. if (strlen($line) == 0)
  236. {
  237. $haderror = true;
  238. $error = "WARN: '$cmd' returned nothing\n";
  239. return $line;
  240. }
  241. # print "$cmd returned '$line'\n";
  242. $data = array();
  243. $objs = explode('|', $line);
  244. foreach ($objs as $obj)
  245. {
  246. if (strlen($obj) > 0)
  247. {
  248. $items = explode(',', $obj);
  249. $item = $items[0];
  250. $id = explode('=', $items[0], 2);
  251. if (count($id) == 1 or !ctype_digit($id[1]))
  252. $name = $id[0];
  253. else
  254. $name = $id[0].$id[1];
  255. if (strlen($name) == 0)
  256. $name = 'null';
  257. $sectionname = preg_replace('/\d/', '', $name);
  258. if (isset($data[$name]))
  259. {
  260. $num = 1;
  261. while (isset($data[$name.$num]))
  262. $num++;
  263. $name .= $num;
  264. }
  265. $counter = 0;
  266. foreach ($items as $item)
  267. {
  268. $id = explode('=', $item, 2);
  269. if (isset($hidefields[$sectionname.'.'.$id[0]]))
  270. continue;
  271. if (count($id) == 2)
  272. $data[$name][$id[0]] = $id[1];
  273. else
  274. $data[$name][$counter] = $id[0];
  275. $counter++;
  276. }
  277. }
  278. }
  279. return $data;
  280. }
  281. return null;
  282. }
  283. #
  284. function getparam($name, $both = false)
  285. {
  286. $a = null;
  287. if (isset($_POST[$name]))
  288. $a = $_POST[$name];
  289. if (($both === true) and ($a === null))
  290. {
  291. if (isset($_GET[$name]))
  292. $a = $_GET[$name];
  293. }
  294. if ($a == '' || $a == null)
  295. return null;
  296. // limit to 1K just to be safe
  297. return substr($a, 0, 1024);
  298. }
  299. #
  300. function classlastshare($when, $alldata, $warnclass, $errorclass)
  301. {
  302. global $checklastshare;
  303. if ($checklastshare === false)
  304. return '';
  305. if ($when == 0)
  306. return '';
  307. if (!isset($alldata['MHS av']))
  308. return '';
  309. if (!isset($alldata['Last Share Time']))
  310. return '';
  311. $expected = pow(2, 32) / ($alldata['MHS av'] * pow(10, 6));
  312. $howlong = $when - $alldata['Last Share Time'];
  313. if ($howlong < 1)
  314. $howlong = 1;
  315. if ($howlong > ($expected * 12))
  316. return $errorclass;
  317. if ($howlong > ($expected * 8))
  318. return $warnclass;
  319. return '';
  320. }
  321. #
  322. function fmt($section, $name, $value, $when, $alldata)
  323. {
  324. global $dfmt;
  325. if ($alldata == null)
  326. $alldata = array();
  327. $errorclass = ' class=err';
  328. $warnclass = ' class=warn';
  329. $lstclass = ' class=lst';
  330. $b = '&nbsp;';
  331. $ret = $value;
  332. $class = '';
  333. if ($value === null)
  334. $ret = $b;
  335. else
  336. switch ($section.'.'.$name)
  337. {
  338. case 'GPU.Last Share Time':
  339. case 'PGA.Last Share Time':
  340. if ($value == 0
  341. || (isset($alldata['Last Share Pool']) && $alldata['Last Share Pool'] == -1))
  342. {
  343. $ret = 'Never';
  344. $class = $warnclass;
  345. }
  346. else
  347. {
  348. $ret = date('H:i:s', $value);
  349. $class = classlastshare($when, $alldata, $warnclass, $errorclass);
  350. }
  351. break;
  352. case 'POOL.Last Share Time':
  353. if ($value == 0)
  354. $ret = 'Never';
  355. else
  356. $ret = date('H:i:s d-M', $value);
  357. break;
  358. case 'GPU.Last Share Pool':
  359. case 'PGA.Last Share Pool':
  360. if ($value == -1)
  361. {
  362. $ret = 'None';
  363. $class = $warnclass;
  364. }
  365. break;
  366. case 'SUMMARY.Elapsed':
  367. $s = $value % 60;
  368. $value -= $s;
  369. $value /= 60;
  370. if ($value == 0)
  371. $ret = $s.'s';
  372. else
  373. {
  374. $m = $value % 60;
  375. $value -= $m;
  376. $value /= 60;
  377. if ($value == 0)
  378. $ret = sprintf("%dm$b%02ds", $m, $s);
  379. else
  380. {
  381. $h = $value % 24;
  382. $value -= $h;
  383. $value /= 24;
  384. if ($value == 0)
  385. $ret = sprintf("%dh$b%02dm$b%02ds", $h, $m, $s);
  386. else
  387. {
  388. if ($value == 1)
  389. $days = '';
  390. else
  391. $days = 's';
  392. $ret = sprintf("%dday$days$b%02dh$b%02dm$b%02ds", $value, $h, $m, $s);
  393. }
  394. }
  395. }
  396. break;
  397. case 'NOTIFY.Last Well':
  398. if ($value == '0')
  399. {
  400. $ret = 'Never';
  401. $class = $warnclass;
  402. }
  403. else
  404. $ret = date('H:i:s', $value);
  405. break;
  406. case 'NOTIFY.Last Not Well':
  407. if ($value == '0')
  408. $ret = 'Never';
  409. else
  410. {
  411. $ret = date('H:i:s', $value);
  412. $class = $errorclass;
  413. }
  414. break;
  415. case 'NOTIFY.Reason Not Well':
  416. if ($value != 'None')
  417. $class = $errorclass;
  418. break;
  419. case 'GPU.Utility':
  420. case 'PGA.Utility':
  421. case 'SUMMARY.Utility':
  422. $ret = $value.'/m';
  423. if ($value == 0)
  424. $class = $warnclass;
  425. break;
  426. case 'PGA.Temperature':
  427. $ret = $value.'&deg;C';
  428. break;
  429. case 'GPU.Temperature':
  430. $ret = $value.'&deg;C';
  431. case 'GPU.GPU Clock':
  432. case 'GPU.Memory Clock':
  433. case 'GPU.GPU Voltage':
  434. case 'GPU.GPU Activity':
  435. if ($value == 0)
  436. $class = $warnclass;
  437. break;
  438. case 'GPU.Fan Percent':
  439. if ($value == 0)
  440. $class = $warnclass;
  441. else
  442. {
  443. if ($value == 100)
  444. $class = $errorclass;
  445. else
  446. if ($value > 85)
  447. $class = $warnclass;
  448. }
  449. break;
  450. case 'GPU.Fan Speed':
  451. if ($value == 0)
  452. $class = $warnclass;
  453. else
  454. if (isset($alldata['Fan Percent']))
  455. {
  456. $test = $alldata['Fan Percent'];
  457. if ($test == 100)
  458. $class = $errorclass;
  459. else
  460. if ($test > 85)
  461. $class = $warnclass;
  462. }
  463. break;
  464. case 'GPU.MHS av':
  465. case 'PGA.MHS av':
  466. case 'SUMMARY.MHS av':
  467. case 'GPU.Total MH':
  468. case 'PGA.Total MH':
  469. case 'SUMMARY.Total MH':
  470. case 'SUMMARY.Getworks':
  471. case 'GPU.Accepted':
  472. case 'PGA.Accepted':
  473. case 'SUMMARY.Accepted':
  474. case 'GPU.Rejected':
  475. case 'PGA.Rejected':
  476. case 'SUMMARY.Rejected':
  477. case 'SUMMARY.Local Work':
  478. case 'POOL.Getworks':
  479. case 'POOL.Accepted':
  480. case 'POOL.Rejected':
  481. case 'POOL.Discarded':
  482. $parts = explode('.', $value, 2);
  483. if (count($parts) == 1)
  484. $dec = '';
  485. else
  486. $dec = '.'.$parts[1];
  487. $ret = number_format($parts[0]).$dec;
  488. break;
  489. case 'GPU.Status':
  490. case 'PGA.Status':
  491. case 'POOL.Status':
  492. if ($value != 'Alive')
  493. $class = $errorclass;
  494. break;
  495. case 'GPU.Enabled':
  496. case 'PGA.Enabled':
  497. if ($value != 'Y')
  498. $class = $warnclass;
  499. break;
  500. case 'STATUS.When':
  501. $ret = date($dfmt, $value);
  502. break;
  503. }
  504. if ($section == 'NOTIFY' && substr($name, 0, 1) == '*' && $value != '0')
  505. $class = $errorclass;
  506. if ($class == '' && $section != 'POOL')
  507. $class = classlastshare($when, $alldata, $lstclass, $lstclass);
  508. return array($ret, $class);
  509. }
  510. #
  511. global $poolcmd;
  512. $poolcmd = array( 'Switch to' => 'switchpool',
  513. 'Enable' => 'enablepool',
  514. 'Disable' => 'disablepool' );
  515. #
  516. function showhead($cmd, $values, $justnames = false)
  517. {
  518. global $poolcmd, $readonly;
  519. echo '<tr>';
  520. foreach ($values as $name => $value)
  521. {
  522. if ($name == '0' or $name == '')
  523. $name = '&nbsp;';
  524. echo "<td valign=bottom class=h>$name</td>";
  525. }
  526. if ($justnames === false && $cmd == 'pools' && $readonly === false)
  527. foreach ($poolcmd as $name => $pcmd)
  528. echo "<td valign=bottom class=h>$name</td>";
  529. echo '</tr>';
  530. }
  531. #
  532. function details($cmd, $list, $rig)
  533. {
  534. global $tablebegin, $tableend, $dfmt;
  535. global $poolcmd, $readonly;
  536. global $showndate;
  537. $when = 0;
  538. $stas = array('S' => 'Success', 'W' => 'Warning', 'I' => 'Informational', 'E' => 'Error', 'F' => 'Fatal');
  539. echo $tablebegin;
  540. if ($showndate === false)
  541. {
  542. echo '<tr><td class=sta>Date: '.date($dfmt).'</td></tr>';
  543. echo $tableend.$tablebegin;
  544. $showndate = true;
  545. }
  546. if (isset($list['STATUS']))
  547. {
  548. echo '<tr>';
  549. echo '<td>Computer: '.$list['STATUS']['Description'].'</td>';
  550. if (isset($list['STATUS']['When']))
  551. {
  552. echo '<td>When: '.date($dfmt, $list['STATUS']['When']).'</td>';
  553. $when = $list['STATUS']['When'];
  554. }
  555. $sta = $list['STATUS']['STATUS'];
  556. echo '<td>Status: '.$stas[$sta].'</td>';
  557. echo '<td>Message: '.$list['STATUS']['Msg'].'</td>';
  558. echo '</tr>';
  559. }
  560. $section = '';
  561. foreach ($list as $item => $values)
  562. {
  563. if ($item == 'STATUS')
  564. continue;
  565. $sectionname = preg_replace('/\d/', '', $item);
  566. if ($sectionname != $section)
  567. {
  568. echo $tableend.$tablebegin;
  569. showhead($cmd, $values);
  570. $section = $sectionname;
  571. }
  572. echo '<tr>';
  573. foreach ($values as $name => $value)
  574. {
  575. list($showvalue, $class) = fmt($section, $name, $value, $when, $values);
  576. echo "<td$class>$showvalue</td>";
  577. }
  578. if ($cmd == 'pools' && $readonly === false)
  579. {
  580. reset($values);
  581. $pool = current($values);
  582. foreach ($poolcmd as $name => $pcmd)
  583. {
  584. echo '<td>';
  585. if ($pool === false)
  586. echo '&nbsp;';
  587. else
  588. {
  589. echo "<input type=button value='Pool $pool'";
  590. echo " onclick='prc(\"$pcmd|$pool&rig=$rig\",\"$name Pool $pool\")'>";
  591. }
  592. echo '</td>';
  593. }
  594. }
  595. echo '</tr>';
  596. }
  597. echo $tableend;
  598. }
  599. #
  600. global $devs;
  601. $devs = null;
  602. #
  603. function gpubuttons($count, $rig)
  604. {
  605. global $tablebegin, $tableend;
  606. global $devs;
  607. $basic = array( 'GPU', 'Enable', 'Disable', 'Restart' );
  608. $options = array( 'intensity' => 'Intensity',
  609. 'fan' => 'Fan Percent',
  610. 'engine' => 'GPU Clock',
  611. 'mem' => 'Memory Clock',
  612. 'vddc' => 'GPU Voltage' );
  613. echo $tablebegin.'<tr>';
  614. foreach ($basic as $head)
  615. echo "<td>$head</td>";
  616. foreach ($options as $name => $des)
  617. echo "<td nowrap>$des</td>";
  618. $n = 0;
  619. for ($c = 0; $c < $count; $c++)
  620. {
  621. echo '</tr><tr>';
  622. foreach ($basic as $name)
  623. {
  624. echo '<td>';
  625. if ($name == 'GPU')
  626. echo $c;
  627. else
  628. {
  629. echo "<input type=button value='$name $c' onclick='prs(\"gpu";
  630. echo strtolower($name);
  631. echo "|$c\",$rig)'>";
  632. }
  633. echo '</td>';
  634. }
  635. foreach ($options as $name => $des)
  636. {
  637. echo '<td>';
  638. if (!isset($devs["GPU$c"][$des]))
  639. echo '&nbsp;';
  640. else
  641. {
  642. $value = $devs["GPU$c"][$des];
  643. echo "<input type=button value='Set $c:' onclick='prs2(\"gpu$name|$c\",$n,$rig)'>";
  644. echo "<input size=7 type=text name=gi$n value='$value' id=gi$n>";
  645. $n++;
  646. }
  647. echo '</td>';
  648. }
  649. }
  650. echo '</tr>'.$tableend;
  651. }
  652. #
  653. function processgpus($rig)
  654. {
  655. global $error;
  656. global $warnfont, $warnoff;
  657. $gpus = api('gpucount');
  658. if ($error != null)
  659. echo '<tr><td>Error getting GPU count: '.$warnfont.$error.$warnoff.'</td></tr>';
  660. else
  661. {
  662. if (!isset($gpus['GPUS']['Count']))
  663. echo '<tr><td>No GPU count returned: '.$warnfont.$gpus['STATUS']['STATUS'].' '.$gpus['STATUS']['Msg'].$ro.'</td></tr>';
  664. else
  665. {
  666. $count = $gpus['GPUS']['Count'];
  667. if ($count == 0)
  668. echo '<tr><td>No GPUs</td></tr>';
  669. else
  670. gpubuttons($count, $rig);
  671. }
  672. }
  673. }
  674. #
  675. function process($cmds, $rig)
  676. {
  677. global $error, $devs;
  678. global $warnfont, $warnoff;
  679. foreach ($cmds as $cmd => $des)
  680. {
  681. $process = api($cmd);
  682. if ($error != null)
  683. {
  684. echo "<tr><td colspan=100>Error getting $des: ";
  685. echo $warnfont.$error.$warnoff.'</td></tr>';
  686. break;
  687. }
  688. else
  689. {
  690. details($cmd, $process, $rig);
  691. echo '<tr><td><br><br></td></tr>';
  692. if ($cmd == 'devs')
  693. $devs = $process;
  694. }
  695. }
  696. }
  697. #
  698. # $head is a hack but this is just a demo anyway :)
  699. function doforeach($cmd, $des, $sum, $head, $datetime)
  700. {
  701. global $miner, $port;
  702. global $error, $readonly, $notify, $rigs;
  703. global $tablebegin, $tableend, $warnfont, $warnoff, $dfmt;
  704. global $rigerror;
  705. $when = 0;
  706. $header = $head;
  707. $anss = array();
  708. $count = 0;
  709. $preverr = count($rigerror);
  710. foreach ($rigs as $rig)
  711. {
  712. if (isset($rigerror[$rig]))
  713. continue;
  714. $parts = explode(':', $rig, 2);
  715. if (count($parts) == 2)
  716. {
  717. $miner = $parts[0];
  718. $port = $parts[1];
  719. $ans = api($cmd);
  720. if ($error != null)
  721. {
  722. echo "<tr><td colspan=100>Error on rig $count getting $des: ";
  723. echo $warnfont.$error.$warnoff.'</td></tr>';
  724. $rigerror[$rig] = $error;
  725. $error = null;
  726. }
  727. else
  728. $anss[$count] = $ans;
  729. }
  730. $count++;
  731. }
  732. if (count($anss) == 0)
  733. {
  734. echo '<tr><td>Failed to access any rigs successfully';
  735. if ($preverr > 0)
  736. echo ' (or rigs had previous errors)';
  737. echo '</td></tr>';
  738. return;
  739. }
  740. if ($datetime)
  741. {
  742. echo '<tr><td class=sta>Date: '.date($dfmt).'</td></tr>';
  743. echo $tableend.$tablebegin;
  744. $dthead = array('' => 1, 'STATUS' => 1, 'Description' => 1, 'When' => 1, 'API' => 1, 'CGMiner' => 1);
  745. showhead('', $dthead);
  746. foreach ($anss as $rig => $ans)
  747. {
  748. echo '<tr>';
  749. foreach ($ans as $item => $row)
  750. {
  751. if ($item != 'STATUS' && $item != 'VERSION')
  752. continue;
  753. foreach ($dthead as $name => $x)
  754. {
  755. if ($item == 'STATUS' && $name == '')
  756. echo "<td align=right><input type=button value='Rig $rig' onclick='pr(\"&rig=$rig\",null)'></td>";
  757. else
  758. {
  759. if (isset($row[$name]))
  760. {
  761. list($showvalue, $class) = fmt('STATUS', $name, $row[$name], $when, null);
  762. echo "<td$class align=right>$showvalue</td>";
  763. }
  764. }
  765. }
  766. }
  767. echo '</tr>';
  768. }
  769. echo $tableend;
  770. echo '<tr><td><br><br></td></tr>';
  771. echo $tablebegin;
  772. return;
  773. }
  774. $total = array();
  775. foreach ($anss as $rig => $ans)
  776. {
  777. foreach ($ans as $item => $row)
  778. {
  779. if ($item == 'STATUS')
  780. continue;
  781. if (count($row) > count($header))
  782. {
  783. $header = $head;
  784. foreach ($row as $name => $value)
  785. if (!isset($header[$name]))
  786. $header[$name] = '';
  787. }
  788. if ($sum != null)
  789. foreach ($sum as $name)
  790. {
  791. if (isset($row[$name]))
  792. {
  793. if (isset($total[$name]))
  794. $total[$name] += $row[$name];
  795. else
  796. $total[$name] = $row[$name];
  797. }
  798. }
  799. }
  800. }
  801. if ($sum != null)
  802. $anss['total']['total'] = $total;
  803. showhead('', $header);
  804. $section = '';
  805. foreach ($anss as $rig => $ans)
  806. {
  807. $when = 0;
  808. if (isset($ans['STATUS']['When']))
  809. $when = $ans['STATUS']['When'];
  810. foreach ($ans as $item => $row)
  811. {
  812. if ($item == 'STATUS')
  813. continue;
  814. echo '<tr>';
  815. $newsection = preg_replace('/\d/', '', $item);
  816. if ($newsection != 'total')
  817. $section = $newsection;
  818. foreach ($header as $name => $x)
  819. {
  820. if ($name == '')
  821. {
  822. if ($rig === 'total')
  823. echo "<td align=right class=tot>Total:</td>";
  824. else
  825. echo "<td align=right><input type=button value='Rig $rig' onclick='pr(\"&rig=$rig\",null)'></td>";
  826. }
  827. else
  828. {
  829. if (isset($row[$name]))
  830. $value = $row[$name];
  831. else
  832. $value = null;
  833. list($showvalue, $class) = fmt($section, $name, $value, $when, $row);
  834. if ($rig === 'total' and $class == '')
  835. $class = ' class=tot';
  836. echo "<td$class align=right>$showvalue</td>";
  837. }
  838. }
  839. echo '</tr>';
  840. }
  841. }
  842. }
  843. #
  844. function refreshbuttons()
  845. {
  846. global $readonly;
  847. global $ignorerefresh, $changerefresh, $autorefresh;
  848. if ($ignorerefresh == false && $changerefresh == true)
  849. {
  850. echo '&nbsp;&nbsp;&nbsp;&nbsp;';
  851. echo "<input type=button value='Auto Refresh:' onclick='prr(true)'>";
  852. echo "<input type=text name='refval' id='refval' size=2 value='$autorefresh'>";
  853. echo "<input type=button value='Off' onclick='prr(false)'>";
  854. }
  855. }
  856. #
  857. function pagetop($rig, $pg)
  858. {
  859. global $readonly, $rigs;
  860. global $allowcustompages, $customsummarypages;
  861. if ($rig === null)
  862. {
  863. if ($pg === null)
  864. $refresh = '';
  865. else
  866. $refresh = "&pg=$pg";
  867. }
  868. else
  869. $refresh = "&rig=$rig";
  870. echo '<tr><td><table cellpadding=0 cellspacing=0 border=0><tr><td nowrap>';
  871. echo "<input type=button value='Refresh' onclick='pr(\"$refresh\",null)'>&nbsp;";
  872. if (count($rigs) > 1)
  873. echo "<input type=button value='Summary' onclick='pr(\"\",null)'>&nbsp;";
  874. if ($allowcustompages === true)
  875. foreach ($customsummarypages as $pagename => $data)
  876. echo "<input type=button value='$pagename' onclick='pr(\"&pg=$pagename\",null)'>&nbsp;";
  877. echo '</td><td width=100%>&nbsp;</td><td nowrap>';
  878. if ($rig !== null && $readonly === false)
  879. {
  880. $rg = '';
  881. if (count($rigs) > 1)
  882. $rg = " Rig $rig";
  883. echo "<input type=button value='Restart' onclick='prc(\"restart&rig=$rig\",\"Restart CGMiner$rg\")'>";
  884. echo "&nbsp;<input type=button value='Quit' onclick='prc(\"quit&rig=$rig\",\"Quit CGMiner$rg\")'>";
  885. }
  886. refreshbuttons();
  887. echo "</td></tr></table></td></tr>";
  888. }
  889. #
  890. function doOne($rig, $preprocess)
  891. {
  892. global $haderror, $readonly, $notify, $rigs;
  893. htmlhead(true, $rig);
  894. pagetop($rig, null);
  895. if ($preprocess != null)
  896. process(array($preprocess => $preprocess), $rig);
  897. $cmds = array( 'devs' => 'device list',
  898. 'summary' => 'summary information',
  899. 'pools' => 'pool list');
  900. if ($notify)
  901. $cmds['notify'] = 'device status';
  902. $cmds['config'] = 'cgminer config';
  903. process($cmds, $rig);
  904. if ($haderror == false && $readonly === false)
  905. processgpus($rig);
  906. }
  907. #
  908. global $sectionmap;
  909. # map sections to their api command
  910. $sectionmap = array(
  911. 'SUMMARY' => 'summary',
  912. 'POOL' => 'pools',
  913. 'GPU' => 'devs',
  914. 'PGA' => 'devs',
  915. 'NOTIFY' => 'notify',
  916. 'CONFIG' => 'config');
  917. #
  918. function customset($showfields, $sum, $section, $num, $result, $total)
  919. {
  920. foreach ($result as $sec => $row)
  921. {
  922. $secname = preg_replace('/\d/', '', $sec);
  923. if ($sec != 'total')
  924. {
  925. if ($secname != $section)
  926. continue;
  927. }
  928. echo '<tr>';
  929. $when = 0;
  930. if (isset($result['STATUS']['When']))
  931. $when = $result['STATUS']['When'];
  932. if ($sec === 'total')
  933. $class = ' class=tot';
  934. else
  935. $class = '';
  936. echo "<td align=middle$class>$num</td>";
  937. foreach ($showfields as $name => $one)
  938. {
  939. if (isset($row[$name]))
  940. {
  941. $value = $row[$name];
  942. if (isset($sum[$secname][$name]))
  943. {
  944. if (isset($total[$name]))
  945. $total[$name] += $value;
  946. else
  947. $total[$name] = $value;
  948. }
  949. }
  950. else
  951. {
  952. if ($sec == 'total' && isset($total[$name]))
  953. $value = $total[$name];
  954. else
  955. $value = null;
  956. }
  957. list($showvalue, $class) = fmt($section, $name, $value, $when, $row);
  958. if ($sec === 'total' and $class == '')
  959. $class = ' class=tot';
  960. echo "<td$class align=right>$showvalue</td>";
  961. }
  962. echo '</tr>';
  963. }
  964. return $total;
  965. }
  966. #
  967. function processcustompage($pagename, $sections, $sum)
  968. {
  969. global $sectionmap;
  970. global $miner, $port;
  971. global $rigs, $error;
  972. global $warnfont, $warnoff;
  973. global $tablebegin, $tableend, $dfmt;
  974. global $readonly, $showndate;
  975. $cmds = array();
  976. $errors = array();
  977. foreach ($sections as $section => $fields)
  978. {
  979. if (isset($sectionmap[$section]))
  980. {
  981. $cmd = $sectionmap[$section];
  982. if (!isset($cmds[$cmd]))
  983. $cmds[$cmd] = 1;
  984. }
  985. else
  986. $errors[] = "Error: unknown section '$section' in custom summary page '$pagename'";
  987. }
  988. $results = array();
  989. foreach ($rigs as $num => $rig)
  990. {
  991. $parts = explode(':', $rig, 2);
  992. if (count($parts) == 2)
  993. {
  994. $miner = $parts[0];
  995. $port = $parts[1];
  996. foreach ($cmds as $cmd => $one)
  997. {
  998. $process = api($cmd);
  999. if ($error != null)
  1000. {
  1001. $errors[] = "Error getting $cmd for $rig $warnfont$error$warnoff";
  1002. break;
  1003. }
  1004. else
  1005. $results[$cmd][$num] = $process;
  1006. }
  1007. }
  1008. }
  1009. if (count($results) > 0)
  1010. {
  1011. $first = true;
  1012. foreach ($sections as $section => $fields)
  1013. {
  1014. if (isset($results[$sectionmap[$section]]))
  1015. {
  1016. $rigresults = $results[$sectionmap[$section]];
  1017. $showfields = array();
  1018. foreach ($fields as $field)
  1019. foreach ($rigresults as $result)
  1020. foreach ($result as $sec => $row)
  1021. {
  1022. $secname = preg_replace('/\d/', '', $sec);
  1023. if ($secname == $section && isset($row[$field]))
  1024. $showfields[$field] = 1;
  1025. }
  1026. if (count($showfields) > 0)
  1027. {
  1028. if ($first === false)
  1029. echo '<tr><td>&nbsp;</td></tr>';
  1030. echo $tablebegin;
  1031. showhead('', array('Rig'=>1)+$showfields, true);
  1032. $total = array();
  1033. $add = array('total' => array());
  1034. foreach ($rigresults as $num => $result)
  1035. {
  1036. $rg = "<input type=button value='$num' onclick='pr(\"&rig=$num\",null)'>";
  1037. $total = customset($showfields, $sum, $section, $rg, $result, $total);
  1038. }
  1039. if (count($total) > 0)
  1040. customset($showfields, $sum, $section, '&Sigma;', $add, $total);
  1041. $first = false;
  1042. echo $tableend;
  1043. }
  1044. }
  1045. }
  1046. }
  1047. if (count($errors) > 0)
  1048. {
  1049. if (count($results) > 0)
  1050. echo '<tr><td>&nbsp;</td></tr>';
  1051. foreach ($errors as $err)
  1052. echo "<tr><td colspan=100>$err</td></tr>";
  1053. }
  1054. }
  1055. #
  1056. function showcustompage($pagename)
  1057. {
  1058. global $customsummarypages;
  1059. htmlhead(false, null);
  1060. pagetop(null, $pagename);
  1061. if (!isset($customsummarypages[$pagename]))
  1062. {
  1063. echo "<tr><td colspan=100>Unknown custom summary page '$pagename'</td></tr>";
  1064. return;
  1065. }
  1066. if (count($customsummarypages[$pagename]) != 2)
  1067. {
  1068. echo "<tr><td colspan=100>Invalid custom summary page '$pagename' (".count($customsummarypages[$pagename]).")</td></tr>";
  1069. return;
  1070. }
  1071. $page = $customsummarypages[$pagename][0];
  1072. $sum = $customsummarypages[$pagename][1];
  1073. if ($sum === null)
  1074. $sum = array();
  1075. if (count($page) <= 1)
  1076. {
  1077. echo "<tr><td colspan=100>Invalid custom summary page '$pagename' no content </td></tr>";
  1078. return;
  1079. }
  1080. processcustompage($pagename, $page, $sum);
  1081. }
  1082. #
  1083. function display()
  1084. {
  1085. global $tablebegin, $tableend;
  1086. global $miner, $port;
  1087. global $readonly, $notify, $rigs;
  1088. global $ignorerefresh, $autorefresh;
  1089. global $allowcustompages;
  1090. if ($ignorerefresh == false)
  1091. {
  1092. $ref = trim(getparam('ref', true));
  1093. if ($ref != null && $ref != '')
  1094. $autorefresh = intval($ref);
  1095. }
  1096. $rig = trim(getparam('rig', true));
  1097. $arg = trim(getparam('arg', true));
  1098. $preprocess = null;
  1099. if ($arg != null and $arg != '')
  1100. {
  1101. $num = null;
  1102. if ($rig != null and $rig != '')
  1103. {
  1104. if ($rig >= 0 and $rig < count($rigs))
  1105. $num = $rig;
  1106. }
  1107. else
  1108. if (count($rigs) == 0)
  1109. $num = 0;
  1110. if ($num != null)
  1111. {
  1112. $parts = explode(':', $rigs[$num], 2);
  1113. if (count($parts) == 2)
  1114. {
  1115. $miner = $parts[0];
  1116. $port = $parts[1];
  1117. $preprocess = $arg;
  1118. }
  1119. }
  1120. }
  1121. if ($rigs == null or count($rigs) == 0)
  1122. {
  1123. echo "<tr><td>No rigs defined</td></tr>";
  1124. return;
  1125. }
  1126. if ($allowcustompages === true)
  1127. {
  1128. $pg = trim(getparam('pg', true));
  1129. if ($pg != null && $pg != '')
  1130. {
  1131. showcustompage($pg);
  1132. return;
  1133. }
  1134. }
  1135. if (count($rigs) == 1)
  1136. {
  1137. $parts = explode(':', $rigs[0], 2);
  1138. if (count($parts) == 2)
  1139. {
  1140. $miner = $parts[0];
  1141. $port = $parts[1];
  1142. doOne(0, $preprocess);
  1143. }
  1144. else
  1145. echo '<tr><td>Invalid "$rigs" array</td></tr>';
  1146. return;
  1147. }
  1148. if ($rig != null and $rig != '' and $rig >= 0 and $rig < count($rigs))
  1149. {
  1150. $parts = explode(':', $rigs[$rig], 2);
  1151. if (count($parts) == 2)
  1152. {
  1153. $miner = $parts[0];
  1154. $port = $parts[1];
  1155. doOne($rig, $preprocess);
  1156. }
  1157. else
  1158. echo '<tr><td>Invalid "$rigs" array</td></tr>';
  1159. return;
  1160. }
  1161. htmlhead(false, null);
  1162. pagetop(null, null);
  1163. if ($preprocess != null)
  1164. process(array($preprocess => $preprocess), $rig);
  1165. echo $tablebegin;
  1166. doforeach('version', 'rig summary', array(), array(), true);
  1167. $sum = array('MHS av', 'Getworks', 'Found Blocks', 'Accepted', 'Rejected', 'Discarded', 'Stale', 'Utility', 'Local Work', 'Total MH');
  1168. doforeach('summary', 'summary information', $sum, array(), false);
  1169. echo $tableend;
  1170. echo '<tr><td><br><br></td></tr>';
  1171. echo $tablebegin;
  1172. doforeach('devs', 'device list', $sum, array(''=>'','ID'=>'','Name'=>''), false);
  1173. echo $tableend;
  1174. echo '<tr><td><br><br></td></tr>';
  1175. echo $tablebegin;
  1176. doforeach('pools', 'pool list', $sum, array(''=>''), false);
  1177. echo $tableend;
  1178. }
  1179. #
  1180. display();
  1181. #
  1182. ?>
  1183. </table></td></tr></table>
  1184. </body></html>