miner.php 34 KB

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