miner.php 34 KB

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