miner.php 35 KB

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