miner.php 36 KB

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