miner.php 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056
  1. <?php
  2. session_start();
  3. #
  4. global $title, $miner, $port, $readonly, $notify, $rigs;
  5. global $rigtotals, $forcerigtotals;
  6. global $socksndtimeoutsec, $sockrcvtimeoutsec;
  7. global $checklastshare, $poolinputs, $hidefields;
  8. global $ignorerefresh, $changerefresh, $autorefresh;
  9. global $allowcustompages, $customsummarypages;
  10. global $miner_font_family, $miner_font_size;
  11. global $colouroverride, $placebuttons;
  12. #
  13. # See API-README for more details of these variables and how
  14. # to configure miner.php
  15. #
  16. # Web page title
  17. $title = 'Mine';
  18. #
  19. # Set $readonly to true to force miner.php to be readonly
  20. # Set $readonly to false then it will check cgminer 'privileged'
  21. $readonly = false;
  22. #
  23. # Set $notify to false to NOT attempt to display the notify command
  24. # Set $notify to true to attempt to display the notify command
  25. $notify = true;
  26. #
  27. # Set $checklastshare to true to do the following checks:
  28. # If a device's last share is 12x expected ago then display as an error
  29. # If a device's last share is 8x expected ago then display as a warning
  30. # If either of the above is true, also display the whole line highlighted
  31. # This assumes shares are 1 difficulty shares
  32. $checklastshare = true;
  33. #
  34. # Set $poolinputs to true to show the input fields for adding a pool
  35. # and changing the pool priorities
  36. # N.B. also if $readonly is true, it will not display the fields
  37. $poolinputs = false;
  38. #
  39. # Set $rigs to an array of your cgminer rigs that are running
  40. # format: 'IP:Port' or 'Host:Port' or 'Host:Port:Name'
  41. $rigs = array('127.0.0.1:4028');
  42. #
  43. # Set $rigtotals to true to display totals on the single rig page
  44. # 'false' means no totals (and ignores $forcerigtotals)
  45. # You can force it to always show rig totals when there is only
  46. # one line by setting $forcerigtotals = true;
  47. $rigtotals = true;
  48. $forcerigtotals = false;
  49. #
  50. # These should be OK for most cases
  51. $socksndtimeoutsec = 10;
  52. $sockrcvtimeoutsec = 40;
  53. #
  54. # List of fields NOT to be displayed
  55. # This example would hide the slightly more sensitive pool information
  56. #$hidefields = array('POOL.URL' => 1, 'POOL.User' => 1);
  57. $hidefields = array();
  58. #
  59. # Auto-refresh of the page (in seconds) - integers only
  60. # $ignorerefresh = true/false always ignore refresh parameters
  61. # $changerefresh = true/false show buttons to change the value
  62. # $autorefresh = default value, 0 means dont auto-refresh
  63. $ignorerefresh = false;
  64. $changerefresh = true;
  65. $autorefresh = 0;
  66. #
  67. # Should we allow custom pages?
  68. # (or just completely ignore them and don't display the buttons)
  69. $allowcustompages = true;
  70. #
  71. # OK this is a bit more complex item: Custom Summary Pages
  72. # As mentioned above, see API-README
  73. # see the example below (if there is no matching data, no total will show)
  74. $mobilepage = array(
  75. 'DATE' => null,
  76. 'RIGS' => null,
  77. 'SUMMARY' => array('Elapsed', 'MHS av', 'Found Blocks=Blks', 'Accepted', 'Rejected=Rej', 'Utility'),
  78. 'DEVS+NOTIFY' => array('DEVS.Name=Name', 'DEVS.ID=ID', 'DEVS.Status=Status', 'DEVS.Temperature=Temp',
  79. 'DEVS.MHS av=MHS av', 'DEVS.Accepted=Accept', 'DEVS.Rejected=Rej',
  80. 'DEVS.Utility=Utility', 'NOTIFY.Last Not Well=Not Well'),
  81. 'POOL' => array('POOL', 'Status', 'Accepted', 'Rejected=Rej', 'Last Share Time'));
  82. $mobilesum = array(
  83. 'SUMMARY' => array('MHS av', 'Found Blocks', 'Accepted', 'Rejected', 'Utility'),
  84. 'DEVS+NOTIFY' => array('DEVS.MHS av', 'DEVS.Accepted', 'DEVS.Rejected', 'DEVS.Utility'),
  85. 'POOL' => array('Accepted', 'Rejected'));
  86. #
  87. # customsummarypages is an array of these Custom Summary Pages
  88. $customsummarypages = array('Mobile' => array($mobilepage, $mobilesum));
  89. #
  90. $here = $_SERVER['PHP_SELF'];
  91. #
  92. global $tablebegin, $tableend, $warnfont, $warnoff, $dfmt;
  93. #
  94. $tablebegin = '<tr><td><table border=1 cellpadding=5 cellspacing=0>';
  95. $tableend = '</table></td></tr>';
  96. $warnfont = '<font color=red><b>';
  97. $warnoff = '</b></font>';
  98. $dfmt = 'H:i:s j-M-Y \U\T\CP';
  99. #
  100. $miner_font_family = 'verdana,arial,sans';
  101. $miner_font_size = '13pt';
  102. #
  103. # Edit this or redefine it in myminer.php to change the colour scheme
  104. # See $colourtable below for the list of names
  105. $colouroverride = array();
  106. #
  107. # Where to place the buttons: 'top' 'bot' 'both'
  108. # anything else means don't show them - case sensitive
  109. $placebuttons = 'top';
  110. #
  111. # This below allows you to put your own settings into a seperate file
  112. # so you don't need to update miner.php with your preferred settings
  113. # every time a new version is released
  114. # Just create the file 'myminer.php' in the same directory as
  115. # 'miner.php' - and put your own settings in there
  116. if (file_exists('myminer.php'))
  117. include_once('myminer.php');
  118. #
  119. # This is the system default that must always contain all necessary
  120. # colours so it must be a constant
  121. # You can override these values with $colouroverride
  122. # The only one missing is in $warnfont
  123. # - which you can override directly anyway
  124. global $colourtable;
  125. $colourtable = array(
  126. 'body bgcolor' => '#ecffff',
  127. 'td color' => 'blue',
  128. 'td.two color' => 'blue',
  129. 'td.two background' => '#ecffff',
  130. 'td.h color' => 'blue',
  131. 'td.h background' => '#c4ffff',
  132. 'td.err color' => 'black',
  133. 'td.err background' => '#ff3050',
  134. 'td.warn color' => 'black',
  135. 'td.warn background' => '#ffb050',
  136. 'td.sta color' => 'green',
  137. 'td.tot color' => 'blue',
  138. 'td.tot background' => '#fff8f2',
  139. 'td.lst color' => 'blue',
  140. 'td.lst background' => '#ffffdd',
  141. 'td.hi color' => 'blue',
  142. 'td.hi background' => '#f6ffff',
  143. 'td.lo color' => 'blue',
  144. 'td.lo background' => '#deffff'
  145. );
  146. #
  147. # Don't touch these 2
  148. $miner = null;
  149. $port = null;
  150. #
  151. # Ensure it is only ever shown once
  152. global $showndate;
  153. $showndate = false;
  154. #
  155. # For summary page to stop retrying failed rigs
  156. global $rigerror;
  157. $rigerror = array();
  158. #
  159. global $rownum;
  160. $rownum = 0;
  161. #
  162. function getcss($cssname, $dom = false)
  163. {
  164. global $colourtable, $colouroverride;
  165. $css = '';
  166. foreach ($colourtable as $cssdata => $value)
  167. {
  168. $cssobj = explode(' ', $cssdata, 2);
  169. if ($cssobj[0] == $cssname)
  170. {
  171. if (isset($colouroverride[$cssdata]))
  172. $value = $colouroverride[$cssdata];
  173. if ($dom == true)
  174. $css .= ' '.$cssobj[1].'='.$value;
  175. else
  176. $css .= $cssobj[1].':'.$value.'; ';
  177. }
  178. }
  179. return $css;
  180. }
  181. #
  182. function getdom($domname)
  183. {
  184. return getcss($domname, true);
  185. }
  186. #
  187. function htmlhead($checkapi, $rig, $pg = null)
  188. {
  189. global $title, $miner_font_family, $miner_font_size;
  190. global $error, $readonly, $poolinputs, $here;
  191. global $ignorerefresh, $autorefresh;
  192. $extraparams = '';
  193. if ($rig != null && $rig != '')
  194. $extraparams = "&rig=$rig";
  195. else
  196. if ($pg != null && $pg != '')
  197. $extraparams = "&pg=$pg";
  198. if ($ignorerefresh == true || $autorefresh == 0)
  199. $refreshmeta = '';
  200. else
  201. {
  202. $url = "$here?ref=$autorefresh$extraparams";
  203. $refreshmeta = "\n<meta http-equiv='refresh' content='$autorefresh;url=$url'>";
  204. }
  205. if ($readonly === false && $checkapi === true)
  206. {
  207. $error = null;
  208. $access = api('privileged');
  209. if ($error != null
  210. || !isset($access['STATUS']['STATUS'])
  211. || $access['STATUS']['STATUS'] != 'S')
  212. $readonly = true;
  213. }
  214. $miner_font = "font-family:$miner_font_family; font-size:$miner_font_size;";
  215. echo "<html><head>$refreshmeta
  216. <title>$title</title>
  217. <style type='text/css'>
  218. td { $miner_font ".getcss('td')."}
  219. td.two { $miner_font ".getcss('td.two')."}
  220. td.h { $miner_font ".getcss('td.h')."}
  221. td.err { $miner_font ".getcss('td.err')."}
  222. td.warn { $miner_font ".getcss('td.warn')."}
  223. td.sta { $miner_font ".getcss('td.sta')."}
  224. td.tot { $miner_font ".getcss('td.tot')."}
  225. td.lst { $miner_font ".getcss('td.lst')."}
  226. td.hi { $miner_font ".getcss('td.hi')."}
  227. td.lo { $miner_font ".getcss('td.lo')."}
  228. </style>
  229. </head><body".getdom('body').">
  230. <script type='text/javascript'>
  231. function pr(a,m){if(m!=null){if(!confirm(m+'?'))return}window.location='$here?ref=$autorefresh'+a}\n";
  232. if ($ignorerefresh == false)
  233. echo "function prr(a){if(a){v=document.getElementById('refval').value}else{v=0}window.location='$here?ref='+v+'$extraparams'}\n";
  234. if ($readonly === false && $checkapi === true)
  235. {
  236. echo "function prc(a,m){pr('&arg='+a,m)}
  237. 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)}
  238. 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";
  239. if ($poolinputs === true)
  240. echo "function cbs(s){var t=s.replace(/\\\\/g,'\\\\\\\\'); return t.replace(/,/g, '\\\\,')}\nfunction pla(r){var u=document.getElementById('purl').value;var w=document.getElementById('pwork').value;var p=document.getElementById('ppass').value;pr('&rig='+r+'&arg=addpool|'+cbs(u)+','+cbs(w)+','+cbs(p),'Add Pool '+u)}\nfunction psp(r){var p=document.getElementById('prio').value;pr('&rig='+r+'&arg=poolpriority|'+p,'Set Pool Priorities to '+p)}\n";
  241. }
  242. ?>
  243. </script>
  244. <table width=100% height=100% border=0 cellpadding=0 cellspacing=0 summary='Mine'>
  245. <tr><td align=center valign=top>
  246. <table border=0 cellpadding=4 cellspacing=0 summary='Mine'>
  247. <?php
  248. }
  249. #
  250. global $haderror, $error;
  251. $haderror = false;
  252. $error = null;
  253. #
  254. function getsock($addr, $port)
  255. {
  256. global $haderror, $error, $socksndtimeoutsec, $sockrcvtimeoutsec;
  257. $error = null;
  258. $socket = null;
  259. $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  260. if ($socket === false || $socket === null)
  261. {
  262. $haderror = true;
  263. $error = socket_strerror(socket_last_error());
  264. $msg = "socket create(TCP) failed";
  265. $error = "ERR: $msg '$error'\n";
  266. return null;
  267. }
  268. // Ignore if this fails since the socket connect may work anyway
  269. // and nothing is gained by aborting if the option cannot be set
  270. // since we don't know in advance if it can connect
  271. socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, array('sec' => $socksndtimeoutsec, 'usec' => 0));
  272. socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $sockrcvtimeoutsec, 'usec' => 0));
  273. $res = socket_connect($socket, $addr, $port);
  274. if ($res === false)
  275. {
  276. $haderror = true;
  277. $error = socket_strerror(socket_last_error());
  278. $msg = "socket connect($addr,$port) failed";
  279. $error = "ERR: $msg '$error'\n";
  280. socket_close($socket);
  281. return null;
  282. }
  283. return $socket;
  284. }
  285. #
  286. function readsockline($socket)
  287. {
  288. $line = '';
  289. while (true)
  290. {
  291. $byte = socket_read($socket, 1);
  292. if ($byte === false || $byte === '')
  293. break;
  294. if ($byte === "\0")
  295. break;
  296. $line .= $byte;
  297. }
  298. return $line;
  299. }
  300. #
  301. function api_convert_escape($str)
  302. {
  303. $res = '';
  304. $len = strlen($str);
  305. for ($i = 0; $i < $len; $i++)
  306. {
  307. $ch = substr($str, $i, 1);
  308. if ($ch != '\\' || $i == ($len-1))
  309. $res .= $ch;
  310. else
  311. {
  312. $i++;
  313. $ch = substr($str, $i, 1);
  314. switch ($ch)
  315. {
  316. case '|':
  317. $res .= "\1";
  318. break;
  319. case '\\':
  320. $res .= "\2";
  321. break;
  322. case '=':
  323. $res .= "\3";
  324. break;
  325. case ',':
  326. $res .= "\4";
  327. break;
  328. default:
  329. $res .= $ch;
  330. }
  331. }
  332. }
  333. return $res;
  334. }
  335. #
  336. function revert($str)
  337. {
  338. return str_replace(array("\1", "\2", "\3", "\4"), array("|", "\\", "=", ","), $str);
  339. }
  340. #
  341. function api($cmd)
  342. {
  343. global $haderror, $error;
  344. global $miner, $port, $hidefields;
  345. $socket = getsock($miner, $port);
  346. if ($socket != null)
  347. {
  348. socket_write($socket, $cmd, strlen($cmd));
  349. $line = readsockline($socket);
  350. socket_close($socket);
  351. if (strlen($line) == 0)
  352. {
  353. $haderror = true;
  354. $error = "WARN: '$cmd' returned nothing\n";
  355. return $line;
  356. }
  357. # print "$cmd returned '$line'\n";
  358. $line = api_convert_escape($line);
  359. $data = array();
  360. $objs = explode('|', $line);
  361. foreach ($objs as $obj)
  362. {
  363. if (strlen($obj) > 0)
  364. {
  365. $items = explode(',', $obj);
  366. $item = $items[0];
  367. $id = explode('=', $items[0], 2);
  368. if (count($id) == 1 or !ctype_digit($id[1]))
  369. $name = $id[0];
  370. else
  371. $name = $id[0].$id[1];
  372. if (strlen($name) == 0)
  373. $name = 'null';
  374. $sectionname = preg_replace('/\d/', '', $name);
  375. if (isset($data[$name]))
  376. {
  377. $num = 1;
  378. while (isset($data[$name.$num]))
  379. $num++;
  380. $name .= $num;
  381. }
  382. $counter = 0;
  383. foreach ($items as $item)
  384. {
  385. $id = explode('=', $item, 2);
  386. if (isset($hidefields[$sectionname.'.'.$id[0]]))
  387. continue;
  388. if (count($id) == 2)
  389. $data[$name][$id[0]] = revert($id[1]);
  390. else
  391. $data[$name][$counter] = $id[0];
  392. $counter++;
  393. }
  394. }
  395. }
  396. return $data;
  397. }
  398. return null;
  399. }
  400. #
  401. function getparam($name, $both = false)
  402. {
  403. $a = null;
  404. if (isset($_POST[$name]))
  405. $a = $_POST[$name];
  406. if (($both === true) and ($a === null))
  407. {
  408. if (isset($_GET[$name]))
  409. $a = $_GET[$name];
  410. }
  411. if ($a == '' || $a == null)
  412. return null;
  413. // limit to 1K just to be safe
  414. return substr($a, 0, 1024);
  415. }
  416. #
  417. function newtable()
  418. {
  419. global $tablebegin, $rownum;
  420. echo $tablebegin;
  421. $rownum = 0;
  422. }
  423. #
  424. function newrow()
  425. {
  426. echo '<tr>';
  427. }
  428. #
  429. function otherrow($row)
  430. {
  431. echo "<tr>$row</tr>";
  432. }
  433. #
  434. function endrow()
  435. {
  436. global $rownum;
  437. echo '</tr>';
  438. $rownum++;
  439. }
  440. #
  441. function endtable()
  442. {
  443. global $tableend;
  444. echo $tableend;
  445. }
  446. #
  447. function classlastshare($when, $alldata, $warnclass, $errorclass)
  448. {
  449. global $checklastshare;
  450. if ($checklastshare === false)
  451. return '';
  452. if ($when == 0)
  453. return '';
  454. if (!isset($alldata['MHS av']))
  455. return '';
  456. if ($alldata['MHS av'] == 0)
  457. return '';
  458. if (!isset($alldata['Last Share Time']))
  459. return '';
  460. $expected = pow(2, 32) / ($alldata['MHS av'] * pow(10, 6));
  461. $howlong = $when - $alldata['Last Share Time'];
  462. if ($howlong < 1)
  463. $howlong = 1;
  464. if ($howlong > ($expected * 12))
  465. return $errorclass;
  466. if ($howlong > ($expected * 8))
  467. return $warnclass;
  468. return '';
  469. }
  470. #
  471. function fmt($section, $name, $value, $when, $alldata)
  472. {
  473. global $dfmt, $rownum;
  474. if ($alldata == null)
  475. $alldata = array();
  476. $errorclass = ' class=err';
  477. $warnclass = ' class=warn';
  478. $lstclass = ' class=lst';
  479. $hiclass = ' class=hi';
  480. $loclass = ' class=lo';
  481. $c2class = ' class=two';
  482. $totclass = ' class=tot';
  483. $b = '&nbsp;';
  484. $ret = $value;
  485. $class = '';
  486. $nams = explode('.', $name);
  487. if (count($nams) > 1)
  488. $name = $nams[count($nams)-1];
  489. if ($value === null)
  490. $ret = $b;
  491. else
  492. switch ($section.'.'.$name)
  493. {
  494. case 'GPU.Last Share Time':
  495. case 'PGA.Last Share Time':
  496. case 'DEVS.Last Share Time':
  497. if ($value == 0
  498. || (isset($alldata['Last Share Pool']) && $alldata['Last Share Pool'] == -1))
  499. {
  500. $ret = 'Never';
  501. $class = $warnclass;
  502. }
  503. else
  504. {
  505. $ret = date('H:i:s', $value);
  506. $class = classlastshare($when, $alldata, $warnclass, $errorclass);
  507. }
  508. break;
  509. case 'POOL.Last Share Time':
  510. if ($value == 0)
  511. $ret = 'Never';
  512. else
  513. $ret = date('H:i:s d-M', $value);
  514. break;
  515. case 'GPU.Last Share Pool':
  516. case 'PGA.Last Share Pool':
  517. case 'DEVS.Last Share Pool':
  518. if ($value == -1)
  519. {
  520. $ret = 'None';
  521. $class = $warnclass;
  522. }
  523. break;
  524. case 'SUMMARY.Elapsed':
  525. $s = $value % 60;
  526. $value -= $s;
  527. $value /= 60;
  528. if ($value == 0)
  529. $ret = $s.'s';
  530. else
  531. {
  532. $m = $value % 60;
  533. $value -= $m;
  534. $value /= 60;
  535. if ($value == 0)
  536. $ret = sprintf("%dm$b%02ds", $m, $s);
  537. else
  538. {
  539. $h = $value % 24;
  540. $value -= $h;
  541. $value /= 24;
  542. if ($value == 0)
  543. $ret = sprintf("%dh$b%02dm$b%02ds", $h, $m, $s);
  544. else
  545. {
  546. if ($value == 1)
  547. $days = '';
  548. else
  549. $days = 's';
  550. $ret = sprintf("%dday$days$b%02dh$b%02dm$b%02ds", $value, $h, $m, $s);
  551. }
  552. }
  553. }
  554. break;
  555. case 'NOTIFY.Last Well':
  556. if ($value == '0')
  557. {
  558. $ret = 'Never';
  559. $class = $warnclass;
  560. }
  561. else
  562. $ret = date('H:i:s', $value);
  563. break;
  564. case 'NOTIFY.Last Not Well':
  565. if ($value == '0')
  566. $ret = 'Never';
  567. else
  568. {
  569. $ret = date('H:i:s', $value);
  570. $class = $errorclass;
  571. }
  572. break;
  573. case 'NOTIFY.Reason Not Well':
  574. if ($value != 'None')
  575. $class = $errorclass;
  576. break;
  577. case 'GPU.Utility':
  578. case 'PGA.Utility':
  579. case 'DEVS.Utility':
  580. case 'SUMMARY.Utility':
  581. case 'total.Utility':
  582. $ret = $value.'/m';
  583. if ($value == 0)
  584. $class = $errorclass;
  585. else
  586. if (isset($alldata['MHS av']))
  587. {
  588. $expected = 60 * $alldata['MHS av'] * (pow(10, 6) / pow(2, 32));
  589. if ($expected == 0)
  590. $expected = 0.000001; // 1 H/s
  591. $ratio = $value / $expected;
  592. if ($ratio < 0.9)
  593. $class = $loclass;
  594. else
  595. if ($ratio > 1.1)
  596. $class = $hiclass;
  597. }
  598. break;
  599. case 'SUMMARY.Work Utility':
  600. case 'total.Work Utility':
  601. $ret = $value.'/m';
  602. break;
  603. case 'PGA.Temperature':
  604. case 'GPU.Temperature':
  605. case 'DEVS.Temperature':
  606. $ret = $value.'&deg;C';
  607. if (!isset($alldata['GPU']))
  608. break;
  609. case 'GPU.GPU Clock':
  610. case 'DEVS.GPU Clock':
  611. case 'GPU.Memory Clock':
  612. case 'DEVS.Memory Clock':
  613. case 'GPU.GPU Voltage':
  614. case 'DEVS.GPU Voltage':
  615. case 'GPU.GPU Activity':
  616. case 'DEVS.GPU Activity':
  617. if ($value == 0)
  618. $class = $warnclass;
  619. break;
  620. case 'GPU.Fan Percent':
  621. case 'DEVS.Fan Percent':
  622. if ($value == 0)
  623. $class = $warnclass;
  624. else
  625. {
  626. if ($value == 100)
  627. $class = $errorclass;
  628. else
  629. if ($value > 85)
  630. $class = $warnclass;
  631. }
  632. break;
  633. case 'GPU.Fan Speed':
  634. case 'DEVS.Fan Speed':
  635. if ($value == 0)
  636. $class = $warnclass;
  637. else
  638. if (isset($alldata['Fan Percent']))
  639. {
  640. $test = $alldata['Fan Percent'];
  641. if ($test == 100)
  642. $class = $errorclass;
  643. else
  644. if ($test > 85)
  645. $class = $warnclass;
  646. }
  647. break;
  648. case 'GPU.MHS av':
  649. case 'PGA.MHS av':
  650. case 'DEVS.MHS av':
  651. case 'SUMMARY.MHS av':
  652. case 'total.MHS av':
  653. $parts = explode('.', $value, 2);
  654. if (count($parts) == 1)
  655. $dec = '';
  656. else
  657. $dec = '.'.$parts[1];
  658. $ret = number_format($parts[0]).$dec;
  659. if ($value == 0)
  660. $class = $errorclass;
  661. else
  662. if (isset($alldata['Utility']))
  663. {
  664. $expected = 60 * $value * (pow(10, 6) / pow(2, 32));
  665. $utility = $alldata['Utility'];
  666. $ratio = $utility / $expected;
  667. if ($ratio < 0.9)
  668. $class = $hiclass;
  669. else
  670. if ($ratio > 1.1)
  671. $class = $loclass;
  672. }
  673. break;
  674. case 'GPU.Total MH':
  675. case 'PGA.Total MH':
  676. case 'DEVS.Total MH':
  677. case 'SUMMARY.Total MH':
  678. case 'total.Total MH':
  679. case 'SUMMARY.Getworks':
  680. case 'POOL.Getworks':
  681. case 'total.Getworks':
  682. case 'GPU.Accepted':
  683. case 'PGA.Accepted':
  684. case 'DEVS.Accepted':
  685. case 'SUMMARY.Accepted':
  686. case 'POOL.Accepted':
  687. case 'total.Accepted':
  688. case 'GPU.Rejected':
  689. case 'PGA.Rejected':
  690. case 'DEVS.Rejected':
  691. case 'SUMMARY.Rejected':
  692. case 'POOL.Rejected':
  693. case 'total.Rejected':
  694. case 'SUMMARY.Local Work':
  695. case 'total.Local Work':
  696. case 'SUMMARY.Discarded':
  697. case 'POOL.Discarded':
  698. case 'total.Discarded':
  699. case 'POOL.Diff1 Shares':
  700. case 'total.Diff1 Shares':
  701. $parts = explode('.', $value, 2);
  702. if (count($parts) == 1)
  703. $dec = '';
  704. else
  705. $dec = '.'.$parts[1];
  706. $ret = number_format($parts[0]).$dec;
  707. break;
  708. case 'GPU.Status':
  709. case 'PGA.Status':
  710. case 'DEVS.Status':
  711. case 'POOL.Status':
  712. if ($value != 'Alive')
  713. $class = $errorclass;
  714. break;
  715. case 'GPU.Enabled':
  716. case 'PGA.Enabled':
  717. case 'DEVS.Enabled':
  718. if ($value != 'Y')
  719. $class = $warnclass;
  720. break;
  721. case 'STATUS.When':
  722. $ret = date($dfmt, $value);
  723. break;
  724. case 'BUTTON.Rig':
  725. case 'BUTTON.Pool':
  726. case 'BUTTON.GPU':
  727. $ret = $value;
  728. break;
  729. }
  730. if ($section == 'NOTIFY' && substr($name, 0, 1) == '*' && $value != '0')
  731. $class = $errorclass;
  732. if ($class == '' && $section != 'POOL')
  733. $class = classlastshare($when, $alldata, $lstclass, $lstclass);
  734. if ($class == '' && $section == 'total')
  735. $class = $totclass;
  736. if ($class == '' && ($rownum % 2) == 0)
  737. $class = $c2class;
  738. if ($ret === '')
  739. $ret = $b;
  740. return array($ret, $class);
  741. }
  742. #
  743. global $poolcmd;
  744. $poolcmd = array( 'Switch to' => 'switchpool',
  745. 'Enable' => 'enablepool',
  746. 'Disable' => 'disablepool',
  747. 'Remove' => 'removepool' );
  748. #
  749. function showhead($cmd, $values, $justnames = false)
  750. {
  751. global $poolcmd, $readonly;
  752. newrow();
  753. foreach ($values as $name => $value)
  754. {
  755. if ($name == '0' or $name == '')
  756. $name = '&nbsp;';
  757. echo "<td valign=bottom class=h>$name</td>";
  758. }
  759. if ($justnames === false && $cmd == 'pools' && $readonly === false)
  760. foreach ($poolcmd as $name => $pcmd)
  761. echo "<td valign=bottom class=h>$name</td>";
  762. endrow();
  763. }
  764. #
  765. function showdatetime()
  766. {
  767. global $dfmt;
  768. otherrow('<td class=sta>Date: '.date($dfmt).'</td>');
  769. }
  770. #
  771. global $singlerigsum;
  772. $singlerigsum = array(
  773. 'devs' => array('MHS av' => 1, 'MHS 5s' => 1, 'Accepted' => 1, 'Rejected' => 1,
  774. 'Hardware Errors' => 1, 'Utility' => 1, 'Total MH' => 1),
  775. 'pools' => array('Getworks' => 1, 'Accepted' => 1, 'Rejected' => 1, 'Discarded' => 1,
  776. 'Stale' => 1, 'Get Failures' => 1, 'Remote Failures' => 1,
  777. 'Diff1 Shares' => 1),
  778. 'notify' => array('*' => 1));
  779. #
  780. function showtotal($total, $when, $oldvalues)
  781. {
  782. global $rigtotals;
  783. list($showvalue, $class) = fmt('total', '', 'Total:', $when, null);
  784. echo "<td$class align=right>$showvalue</td>";
  785. $skipfirst = true;
  786. foreach ($oldvalues as $name => $value)
  787. {
  788. if ($skipfirst === true)
  789. {
  790. $skipfirst = false;
  791. continue;
  792. }
  793. if (isset($total[$name]))
  794. $newvalue = $total[$name];
  795. else
  796. $newvalue = '';
  797. list($showvalue, $class) = fmt('total', $name, $newvalue, $when, null);
  798. echo "<td$class";
  799. if ($rigtotals === true)
  800. echo ' align=right';
  801. echo ">$showvalue</td>";
  802. }
  803. }
  804. #
  805. function details($cmd, $list, $rig)
  806. {
  807. global $dfmt, $poolcmd, $readonly, $showndate;
  808. global $rownum, $rigtotals, $forcerigtotals, $singlerigsum;
  809. $when = 0;
  810. $stas = array('S' => 'Success', 'W' => 'Warning', 'I' => 'Informational', 'E' => 'Error', 'F' => 'Fatal');
  811. newtable();
  812. if ($showndate === false)
  813. {
  814. showdatetime();
  815. endtable();
  816. newtable();
  817. $showndate = true;
  818. }
  819. if (isset($list['STATUS']))
  820. {
  821. newrow();
  822. echo '<td>Computer: '.$list['STATUS']['Description'].'</td>';
  823. if (isset($list['STATUS']['When']))
  824. {
  825. echo '<td>When: '.date($dfmt, $list['STATUS']['When']).'</td>';
  826. $when = $list['STATUS']['When'];
  827. }
  828. $sta = $list['STATUS']['STATUS'];
  829. echo '<td>Status: '.$stas[$sta].'</td>';
  830. echo '<td>Message: '.$list['STATUS']['Msg'].'</td>';
  831. endrow();
  832. }
  833. if ($rigtotals === true && isset($singlerigsum[$cmd]))
  834. $dototal = $singlerigsum[$cmd];
  835. else
  836. $dototal = array();
  837. $total = array();
  838. $section = '';
  839. $oldvalues = null;
  840. foreach ($list as $item => $values)
  841. {
  842. if ($item == 'STATUS')
  843. continue;
  844. $sectionname = preg_replace('/\d/', '', $item);
  845. // Handle 'devs' possibly containing >1 table
  846. if ($sectionname != $section)
  847. {
  848. if ($oldvalues != null && count($total) > 0
  849. && ($rownum > 2 || $forcerigtotals === true))
  850. showtotal($total, $when, $oldvalues);
  851. endtable();
  852. newtable();
  853. showhead($cmd, $values);
  854. $section = $sectionname;
  855. }
  856. newrow();
  857. foreach ($values as $name => $value)
  858. {
  859. list($showvalue, $class) = fmt($section, $name, $value, $when, $values);
  860. echo "<td$class";
  861. if ($rigtotals === true)
  862. echo ' align=right';
  863. echo ">$showvalue</td>";
  864. if (isset($dototal[$name])
  865. || (isset($dototal['*']) and substr($name, 0, 1) == '*'))
  866. {
  867. if (isset($total[$name]))
  868. $total[$name] += $value;
  869. else
  870. $total[$name] = $value;
  871. }
  872. }
  873. if ($cmd == 'pools' && $readonly === false)
  874. {
  875. reset($values);
  876. $pool = current($values);
  877. foreach ($poolcmd as $name => $pcmd)
  878. {
  879. list($ignore, $class) = fmt('BUTTON', 'Pool', '', $when, $values);
  880. echo "<td$class>";
  881. if ($pool === false)
  882. echo '&nbsp;';
  883. else
  884. {
  885. echo "<input type=button value='Pool $pool'";
  886. echo " onclick='prc(\"$pcmd|$pool&rig=$rig\",\"$name Pool $pool\")'>";
  887. }
  888. echo '</td>';
  889. }
  890. }
  891. endrow();
  892. $oldvalues = $values;
  893. }
  894. if ($oldvalues != null && count($total) > 0
  895. && ($rownum > 2 || $forcerigtotals === true))
  896. showtotal($total, $when, $oldvalues);
  897. endtable();
  898. }
  899. #
  900. global $devs;
  901. $devs = null;
  902. #
  903. function gpubuttons($count, $rig)
  904. {
  905. global $devs;
  906. $basic = array( 'GPU', 'Enable', 'Disable', 'Restart' );
  907. $options = array( 'intensity' => 'Intensity',
  908. 'fan' => 'Fan Percent',
  909. 'engine' => 'GPU Clock',
  910. 'mem' => 'Memory Clock',
  911. 'vddc' => 'GPU Voltage' );
  912. newtable();
  913. newrow();
  914. foreach ($basic as $head)
  915. echo "<td class=h>$head</td>";
  916. foreach ($options as $name => $des)
  917. echo "<td class=h nowrap>$des</td>";
  918. $n = 0;
  919. for ($c = 0; $c < $count; $c++)
  920. {
  921. endrow();
  922. newrow();
  923. foreach ($basic as $name)
  924. {
  925. list($ignore, $class) = fmt('BUTTON', 'GPU', '', 0, null);
  926. echo "<td$class>";
  927. if ($name == 'GPU')
  928. echo $c;
  929. else
  930. {
  931. echo "<input type=button value='$name $c' onclick='prs(\"gpu";
  932. echo strtolower($name);
  933. echo "|$c\",$rig)'>";
  934. }
  935. echo '</td>';
  936. }
  937. foreach ($options as $name => $des)
  938. {
  939. list($ignore, $class) = fmt('BUTTON', 'GPU', '', 0, null);
  940. echo "<td$class>";
  941. if (!isset($devs["GPU$c"][$des]))
  942. echo '&nbsp;';
  943. else
  944. {
  945. $value = $devs["GPU$c"][$des];
  946. echo "<input type=button value='Set $c:' onclick='prs2(\"gpu$name|$c\",$n,$rig)'>";
  947. echo "<input size=7 type=text name=gi$n value='$value' id=gi$n>";
  948. $n++;
  949. }
  950. echo '</td>';
  951. }
  952. }
  953. endrow();
  954. endtable();
  955. }
  956. #
  957. function processgpus($rig)
  958. {
  959. global $error;
  960. global $warnfont, $warnoff;
  961. $gpus = api('gpucount');
  962. if ($error != null)
  963. otherrow("<td>Error getting GPU count: $warnfont$error$warnoff</td>");
  964. else
  965. {
  966. if (!isset($gpus['GPUS']['Count']))
  967. {
  968. $rw = '<td>No GPU count returned: '.$warnfont;
  969. $rw .= $gpus['STATUS']['STATUS'].' '.$gpus['STATUS']['Msg'];
  970. $rw .= $warnoff.'</td>';
  971. otherrow($rw);
  972. }
  973. else
  974. {
  975. $count = $gpus['GPUS']['Count'];
  976. if ($count == 0)
  977. otherrow('<td>No GPUs</td>');
  978. else
  979. gpubuttons($count, $rig);
  980. }
  981. }
  982. }
  983. #
  984. function showpoolinputs($rig, $ans)
  985. {
  986. global $readonly, $poolinputs;
  987. if ($readonly === true || $poolinputs === false)
  988. return;
  989. newtable();
  990. newrow();
  991. $inps = array('Pool URL' => array('purl', 20),
  992. 'Worker Name' => array('pwork', 10),
  993. 'Worker Password' => array('ppass', 10));
  994. $b = '&nbsp;';
  995. echo "<td align=right class=h> Add a pool: </td><td>";
  996. foreach ($inps as $text => $name)
  997. echo "$text: <input name='".$name[0]."' id='".$name[0]."' value='' type=text size=".$name[1]."> ";
  998. echo "</td><td align=middle><input type=button value='Add' onclick='pla($rig)'></td>";
  999. endrow();
  1000. if (count($ans) > 1)
  1001. {
  1002. newrow();
  1003. echo '<td align=right class=h> Set pool priorities: </td>';
  1004. echo "<td> Comma list of pool numbers: <input type=text name=prio id=prio size=20>";
  1005. echo "</td><td align=middle><input type=button value='Set' onclick='psp($rig)'></td>";
  1006. endrow();
  1007. }
  1008. endtable();
  1009. }
  1010. #
  1011. function process($cmds, $rig)
  1012. {
  1013. global $error, $devs;
  1014. global $warnfont, $warnoff;
  1015. $count = count($cmds);
  1016. foreach ($cmds as $cmd => $des)
  1017. {
  1018. $process = api($cmd);
  1019. if ($error != null)
  1020. {
  1021. otherrow("<td colspan=100>Error getting $des: $warnfont$error$warnoff</td>");
  1022. break;
  1023. }
  1024. else
  1025. {
  1026. details($cmd, $process, $rig);
  1027. if ($cmd == 'devs')
  1028. $devs = $process;
  1029. if ($cmd == 'pools')
  1030. showpoolinputs($rig, $process);
  1031. # Not after the last one
  1032. if (--$count > 0)
  1033. otherrow('<td><br><br></td>');
  1034. }
  1035. }
  1036. }
  1037. #
  1038. function rigbutton($rig, $rigname, $when, $row)
  1039. {
  1040. global $rigs;
  1041. if (isset($rigs[$rig]))
  1042. {
  1043. $parts = explode(':', $rigs[$rig], 3);
  1044. if (count($parts) == 3)
  1045. $rigname = $parts[2];
  1046. }
  1047. list($value, $class) = fmt('BUTTON', 'Rig', '', $when, $row);
  1048. $button = "<td align=middle$class><input type=button value='$rigname'";
  1049. $button .= " onclick='pr(\"&rig=$rig\",null)'></td>";
  1050. return $button;
  1051. }
  1052. #
  1053. function showrigs($anss, $headname, $rigname)
  1054. {
  1055. $dthead = array($headname => 1, 'STATUS' => 1, 'Description' => 1, 'When' => 1, 'API' => 1, 'CGMiner' => 1);
  1056. showhead('', $dthead);
  1057. foreach ($anss as $rig => $ans)
  1058. {
  1059. if ($ans == null)
  1060. continue;
  1061. newrow();
  1062. $when = 0;
  1063. if (isset($ans['STATUS']['When']))
  1064. $when = $ans['STATUS']['When'];
  1065. foreach ($ans as $item => $row)
  1066. {
  1067. if ($item != 'STATUS' && $item != 'VERSION')
  1068. continue;
  1069. foreach ($dthead as $name => $x)
  1070. {
  1071. if ($item == 'STATUS' && $name == $headname)
  1072. echo rigbutton($rig, $rigname.$rig, $when, null);
  1073. else
  1074. {
  1075. if (isset($row[$name]))
  1076. {
  1077. list($showvalue, $class) = fmt('STATUS', $name, $row[$name], $when, null);
  1078. echo "<td$class align=right>$showvalue</td>";
  1079. }
  1080. }
  1081. }
  1082. }
  1083. endrow();
  1084. }
  1085. }
  1086. #
  1087. # $head is a hack but this is just a demo anyway :)
  1088. function doforeach($cmd, $des, $sum, $head, $datetime)
  1089. {
  1090. global $miner, $port;
  1091. global $error, $readonly, $notify, $rigs;
  1092. global $warnfont, $warnoff, $dfmt;
  1093. global $rigerror;
  1094. $when = 0;
  1095. $header = $head;
  1096. $anss = array();
  1097. $count = 0;
  1098. $preverr = count($rigerror);
  1099. foreach ($rigs as $num => $rig)
  1100. {
  1101. $anss[$num] = null;
  1102. if (isset($rigerror[$rig]))
  1103. continue;
  1104. $parts = explode(':', $rig, 3);
  1105. if (count($parts) >= 2)
  1106. {
  1107. $miner = $parts[0];
  1108. $port = $parts[1];
  1109. if (count($parts) > 2)
  1110. $name = $parts[2];
  1111. else
  1112. $name = $num;
  1113. $ans = api($cmd);
  1114. if ($error != null)
  1115. {
  1116. $rw = "<td colspan=100>Error on rig $name getting ";
  1117. $rw .= "$des: $warnfont$error$warnoff</td>";
  1118. otherrow($rw);
  1119. $rigerror[$rig] = $error;
  1120. $error = null;
  1121. }
  1122. else
  1123. {
  1124. $anss[$num] = $ans;
  1125. $count++;
  1126. }
  1127. }
  1128. }
  1129. if ($count == 0)
  1130. {
  1131. $rw = '<td>Failed to access any rigs successfully';
  1132. if ($preverr > 0)
  1133. $rw .= ' (or rigs had previous errors)';
  1134. $rw .= '</td>';
  1135. otherrow($rw);
  1136. return;
  1137. }
  1138. if ($datetime)
  1139. {
  1140. showdatetime();
  1141. endtable();
  1142. newtable();
  1143. showrigs($anss, '', 'Rig ');
  1144. endtable();
  1145. otherrow('<td><br><br></td>');
  1146. newtable();
  1147. return;
  1148. }
  1149. $total = array();
  1150. foreach ($anss as $rig => $ans)
  1151. {
  1152. if ($ans == null)
  1153. continue;
  1154. foreach ($ans as $item => $row)
  1155. {
  1156. if ($item == 'STATUS')
  1157. continue;
  1158. if (count($row) > count($header))
  1159. {
  1160. $header = $head;
  1161. foreach ($row as $name => $value)
  1162. if (!isset($header[$name]))
  1163. $header[$name] = '';
  1164. }
  1165. if ($sum != null)
  1166. foreach ($sum as $name)
  1167. {
  1168. if (isset($row[$name]))
  1169. {
  1170. if (isset($total[$name]))
  1171. $total[$name] += $row[$name];
  1172. else
  1173. $total[$name] = $row[$name];
  1174. }
  1175. }
  1176. }
  1177. }
  1178. if ($sum != null)
  1179. $anss['total']['total'] = $total;
  1180. showhead('', $header);
  1181. foreach ($anss as $rig => $ans)
  1182. {
  1183. if ($ans == null)
  1184. continue;
  1185. $when = 0;
  1186. if (isset($ans['STATUS']['When']))
  1187. $when = $ans['STATUS']['When'];
  1188. foreach ($ans as $item => $row)
  1189. {
  1190. if ($item == 'STATUS')
  1191. continue;
  1192. newrow();
  1193. $section = preg_replace('/\d/', '', $item);
  1194. foreach ($header as $name => $x)
  1195. {
  1196. if ($name == '')
  1197. {
  1198. if ($rig === 'total')
  1199. {
  1200. list($ignore, $class) = fmt($rig, '', '', $when, $row);
  1201. echo "<td align=right$class>Total:</td>";
  1202. }
  1203. else
  1204. echo rigbutton($rig, "Rig $rig", $when, $row);
  1205. }
  1206. else
  1207. {
  1208. if (isset($row[$name]))
  1209. $value = $row[$name];
  1210. else
  1211. $value = null;
  1212. list($showvalue, $class) = fmt($section, $name, $value, $when, $row);
  1213. echo "<td$class align=right>$showvalue</td>";
  1214. }
  1215. }
  1216. endrow();
  1217. }
  1218. }
  1219. }
  1220. #
  1221. function refreshbuttons()
  1222. {
  1223. global $readonly;
  1224. global $ignorerefresh, $changerefresh, $autorefresh;
  1225. if ($ignorerefresh == false && $changerefresh == true)
  1226. {
  1227. echo '&nbsp;&nbsp;&nbsp;&nbsp;';
  1228. echo "<input type=button value='Auto Refresh:' onclick='prr(true)'>";
  1229. echo "<input type=text name='refval' id='refval' size=2 value='$autorefresh'>";
  1230. echo "<input type=button value='Off' onclick='prr(false)'>";
  1231. }
  1232. }
  1233. #
  1234. function pagebuttons($rig, $pg)
  1235. {
  1236. global $readonly, $rigs;
  1237. global $allowcustompages, $customsummarypages;
  1238. if ($rig === null)
  1239. {
  1240. if ($pg === null)
  1241. $refresh = '';
  1242. else
  1243. $refresh = "&pg=$pg";
  1244. }
  1245. else
  1246. $refresh = "&rig=$rig";
  1247. echo '<tr><td><table cellpadding=0 cellspacing=0 border=0><tr><td nowrap>';
  1248. echo "<input type=button value='Refresh' onclick='pr(\"$refresh\",null)'>&nbsp;";
  1249. if (count($rigs) > 1)
  1250. echo "<input type=button value='Summary' onclick='pr(\"\",null)'>&nbsp;";
  1251. if ($allowcustompages === true)
  1252. foreach ($customsummarypages as $pagename => $data)
  1253. echo "<input type=button value='$pagename' onclick='pr(\"&pg=$pagename\",null)'>&nbsp;";
  1254. echo '</td><td width=100%>&nbsp;</td><td nowrap>';
  1255. if ($rig !== null && $readonly === false)
  1256. {
  1257. $rg = '';
  1258. if (count($rigs) > 1)
  1259. $rg = " Rig $rig";
  1260. echo "<input type=button value='Restart' onclick='prc(\"restart&rig=$rig\",\"Restart CGMiner$rg\")'>";
  1261. echo "&nbsp;<input type=button value='Quit' onclick='prc(\"quit&rig=$rig\",\"Quit CGMiner$rg\")'>";
  1262. }
  1263. refreshbuttons();
  1264. echo "</td></tr></table></td></tr>";
  1265. }
  1266. #
  1267. function doOne($rig, $preprocess)
  1268. {
  1269. global $haderror, $readonly, $notify, $rigs;
  1270. global $placebuttons;
  1271. htmlhead(true, $rig);
  1272. if ($placebuttons == 'top' || $placebuttons == 'both')
  1273. pagebuttons($rig, null);
  1274. if ($preprocess != null)
  1275. process(array($preprocess => $preprocess), $rig);
  1276. $cmds = array( 'devs' => 'device list',
  1277. 'summary' => 'summary information',
  1278. 'pools' => 'pool list');
  1279. if ($notify)
  1280. $cmds['notify'] = 'device status';
  1281. $cmds['config'] = 'cgminer config';
  1282. process($cmds, $rig);
  1283. if ($haderror == false && $readonly === false)
  1284. processgpus($rig);
  1285. if ($placebuttons == 'bot' || $placebuttons == 'both')
  1286. pagebuttons($rig, null);
  1287. }
  1288. #
  1289. global $sectionmap;
  1290. # map sections to their api command
  1291. # DEVS is a special case that will match GPU or PGA
  1292. # so you can have a single table with both in it
  1293. # DATE is hard coded so not in here
  1294. $sectionmap = array(
  1295. 'RIGS' => 'version',
  1296. 'SUMMARY' => 'summary',
  1297. 'POOL' => 'pools',
  1298. 'DEVS' => 'devs',
  1299. 'GPU' => 'devs', // You would normally use DEVS
  1300. 'PGA' => 'devs', // You would normally use DEVS
  1301. 'NOTIFY' => 'notify',
  1302. 'DEVDETAILS' => 'devdetails',
  1303. 'STATS' => 'stats',
  1304. 'CONFIG' => 'config');
  1305. #
  1306. function joinfields($section1, $section2, $join, $results)
  1307. {
  1308. global $sectionmap;
  1309. $name1 = $sectionmap[$section1];
  1310. $name2 = $sectionmap[$section2];
  1311. $newres = array();
  1312. // foreach rig in section1
  1313. foreach ($results[$name1] as $rig => $result)
  1314. {
  1315. $status = null;
  1316. // foreach answer section in the rig api call
  1317. foreach ($result as $name1b => $fields1b)
  1318. {
  1319. if ($name1b == 'STATUS')
  1320. {
  1321. // remember the STATUS from section1
  1322. $status = $result[$name1b];
  1323. continue;
  1324. }
  1325. // foreach answer section in the rig api call (for the other api command)
  1326. foreach ($results[$name2][$rig] as $name2b => $fields2b)
  1327. {
  1328. if ($name2b == 'STATUS')
  1329. continue;
  1330. // If match the same field values of fields in $join
  1331. $match = true;
  1332. foreach ($join as $field)
  1333. if ($fields1b[$field] != $fields2b[$field])
  1334. {
  1335. $match = false;
  1336. break;
  1337. }
  1338. if ($match === true)
  1339. {
  1340. if ($status != null)
  1341. {
  1342. $newres[$rig]['STATUS'] = $status;
  1343. $status = null;
  1344. }
  1345. $subsection = $section1.'+'.$section2;
  1346. $subsection .= preg_replace('/[^0-9]/', '', $name1b.$name2b);
  1347. foreach ($fields1b as $nam => $val)
  1348. $newres[$rig][$subsection]["$section1.$nam"] = $val;
  1349. foreach ($fields2b as $nam => $val)
  1350. $newres[$rig][$subsection]["$section2.$nam"] = $val;
  1351. }
  1352. }
  1353. }
  1354. }
  1355. return $newres;
  1356. }
  1357. #
  1358. function joinall($section1, $section2, $results)
  1359. {
  1360. global $sectionmap;
  1361. $name1 = $sectionmap[$section1];
  1362. $name2 = $sectionmap[$section2];
  1363. $newres = array();
  1364. // foreach rig in section1
  1365. foreach ($results[$name1] as $rig => $result)
  1366. {
  1367. // foreach answer section in the rig api call
  1368. foreach ($result as $name1b => $fields1b)
  1369. {
  1370. if ($name1b == 'STATUS')
  1371. {
  1372. // copy the STATUS from section1
  1373. $newres[$rig][$name1b] = $result[$name1b];
  1374. continue;
  1375. }
  1376. // foreach answer section in the rig api call (for the other api command)
  1377. foreach ($results[$name2][$rig] as $name2b => $fields2b)
  1378. {
  1379. if ($name2b == 'STATUS')
  1380. continue;
  1381. $subsection = $section1.'+'.$section2;
  1382. $subsection .= preg_replace('/[^0-9]/', '', $name1b.$name2b);
  1383. foreach ($fields1b as $nam => $val)
  1384. $newres[$rig][$subsection]["$section1.$nam"] = $val;
  1385. foreach ($fields2b as $nam => $val)
  1386. $newres[$rig][$subsection]["$section2.$nam"] = $val;
  1387. }
  1388. }
  1389. }
  1390. return $newres;
  1391. }
  1392. #
  1393. function joinsections($sections, $results, $errors)
  1394. {
  1395. global $sectionmap;
  1396. #echo "results['pools']=".print_r($results['pools'],true)."<br>";
  1397. // GPU's don't have Name,ID fields - so create them
  1398. foreach ($results as $section => $res)
  1399. foreach ($res as $rig => $result)
  1400. foreach ($result as $name => $fields)
  1401. {
  1402. $subname = preg_replace('/[0-9]/', '', $name);
  1403. if ($subname == 'GPU' and isset($result[$name]['GPU']))
  1404. {
  1405. $results[$section][$rig][$name]['Name'] = 'GPU';
  1406. $results[$section][$rig][$name]['ID'] = $result[$name]['GPU'];
  1407. }
  1408. }
  1409. foreach ($sections as $section => $fields)
  1410. if ($section != 'DATE' && !isset($sectionmap[$section]))
  1411. {
  1412. $both = explode('+', $section, 2);
  1413. if (count($both) > 1)
  1414. {
  1415. switch($both[0])
  1416. {
  1417. case 'SUMMARY':
  1418. switch($both[1])
  1419. {
  1420. case 'POOL':
  1421. case 'DEVS':
  1422. case 'CONFIG':
  1423. $sectionmap[$section] = $section;
  1424. $results[$section] = joinall($both[0], $both[1], $results);
  1425. break;
  1426. default:
  1427. $errors[] = "Error: Invalid section '$section'";
  1428. break;
  1429. }
  1430. break;
  1431. case 'DEVS':
  1432. $join = array('Name', 'ID');
  1433. switch($both[1])
  1434. {
  1435. case 'NOTIFY':
  1436. case 'DEVDETAILS':
  1437. $sectionmap[$section] = $section;
  1438. $results[$section] = joinfields($both[0], $both[1], $join, $results);
  1439. break;
  1440. default:
  1441. $errors[] = "Error: Invalid section '$section'";
  1442. break;
  1443. }
  1444. break;
  1445. default:
  1446. $errors[] = "Error: Invalid section '$section'";
  1447. break;
  1448. }
  1449. }
  1450. else
  1451. $errors[] = "Error: Invalid section '$section'";
  1452. }
  1453. return array($results, $errors);
  1454. }
  1455. #
  1456. function secmatch($section, $field)
  1457. {
  1458. if ($section == $field)
  1459. return true;
  1460. if ($section == 'DEVS'
  1461. && ($field == 'GPU' || $field == 'PGA'))
  1462. return true;
  1463. return false;
  1464. }
  1465. #
  1466. function customset($showfields, $sum, $section, $rig, $isbutton, $result, $total)
  1467. {
  1468. foreach ($result as $sec => $row)
  1469. {
  1470. $secname = preg_replace('/\d/', '', $sec);
  1471. if ($sec != 'total')
  1472. if (!secmatch($section, $secname))
  1473. continue;
  1474. newrow();
  1475. $when = 0;
  1476. if (isset($result['STATUS']['When']))
  1477. $when = $result['STATUS']['When'];
  1478. if ($isbutton)
  1479. echo rigbutton($rig, $rig, $when, $row);
  1480. else
  1481. {
  1482. list($ignore, $class) = fmt('total', '', '', $when, $row);
  1483. echo "<td align=middle$class>$rig</td>";
  1484. }
  1485. foreach ($showfields as $name => $one)
  1486. {
  1487. if (isset($row[$name]))
  1488. {
  1489. $value = $row[$name];
  1490. if (isset($sum[$section][$name]))
  1491. {
  1492. if (isset($total[$name]))
  1493. $total[$name] += $value;
  1494. else
  1495. $total[$name] = $value;
  1496. }
  1497. }
  1498. else
  1499. {
  1500. if ($sec == 'total' && isset($total[$name]))
  1501. $value = $total[$name];
  1502. else
  1503. $value = null;
  1504. }
  1505. if (strpos($secname, '+') === false)
  1506. list($showvalue, $class) = fmt($secname, $name, $value, $when, $row);
  1507. else
  1508. {
  1509. $parts = explode('.', $name, 2);
  1510. list($showvalue, $class) = fmt($parts[0], $parts[1], $value, $when, $row);
  1511. }
  1512. echo "<td$class align=right>$showvalue</td>";
  1513. }
  1514. endrow();
  1515. }
  1516. return $total;
  1517. }
  1518. #
  1519. function processcustompage($pagename, $sections, $sum, $namemap)
  1520. {
  1521. global $sectionmap;
  1522. global $miner, $port;
  1523. global $rigs, $error;
  1524. global $warnfont, $warnoff;
  1525. global $dfmt;
  1526. global $readonly, $showndate;
  1527. $cmds = array();
  1528. $errors = array();
  1529. foreach ($sections as $section => $fields)
  1530. {
  1531. $all = explode('+', $section);
  1532. foreach ($all as $section)
  1533. {
  1534. if (isset($sectionmap[$section]))
  1535. {
  1536. $cmd = $sectionmap[$section];
  1537. if (!isset($cmds[$cmd]))
  1538. $cmds[$cmd] = 1;
  1539. }
  1540. else
  1541. if ($section != 'DATE')
  1542. $errors[] = "Error: unknown section '$section' in custom summary page '$pagename'";
  1543. }
  1544. }
  1545. $results = array();
  1546. foreach ($rigs as $num => $rig)
  1547. {
  1548. $parts = explode(':', $rig, 3);
  1549. if (count($parts) >= 2)
  1550. {
  1551. $miner = $parts[0];
  1552. $port = $parts[1];
  1553. if (count($parts) > 2)
  1554. $name = $parts[2];
  1555. else
  1556. $name = $rig;
  1557. foreach ($cmds as $cmd => $one)
  1558. {
  1559. $process = api($cmd);
  1560. if ($error != null)
  1561. {
  1562. $errors[] = "Error getting $cmd for $name $warnfont$error$warnoff";
  1563. break;
  1564. }
  1565. else
  1566. $results[$cmd][$num] = $process;
  1567. }
  1568. }
  1569. }
  1570. $shownsomething = false;
  1571. if (count($results) > 0)
  1572. {
  1573. list($results, $errors) = joinsections($sections, $results, $errors);
  1574. $first = true;
  1575. foreach ($sections as $section => $fields)
  1576. {
  1577. if ($section === 'DATE')
  1578. {
  1579. if ($shownsomething)
  1580. otherrow('<td>&nbsp;</td>');
  1581. newtable();
  1582. showdatetime();
  1583. endtable();
  1584. // On top of the next table
  1585. $shownsomething = false;
  1586. continue;
  1587. }
  1588. if ($section === 'RIGS')
  1589. {
  1590. if ($shownsomething)
  1591. otherrow('<td>&nbsp;</td>');
  1592. newtable();
  1593. showrigs($results['version'], 'Rig', '');
  1594. endtable();
  1595. $shownsomething = true;
  1596. continue;
  1597. }
  1598. if (isset($results[$sectionmap[$section]]))
  1599. {
  1600. $rigresults = $results[$sectionmap[$section]];
  1601. $showfields = array();
  1602. $showhead = array();
  1603. foreach ($fields as $field)
  1604. foreach ($rigresults as $result)
  1605. foreach ($result as $sec => $row)
  1606. {
  1607. $secname = preg_replace('/\d/', '', $sec);
  1608. if (secmatch($section, $secname))
  1609. {
  1610. if ($field === '*')
  1611. {
  1612. foreach ($row as $f => $v)
  1613. {
  1614. $showfields[$f] = 1;
  1615. $map = $section.'.'.$f;
  1616. if (isset($namemap[$map]))
  1617. $showhead[$namemap[$map]] = 1;
  1618. else
  1619. $showhead[$f] = 1;
  1620. }
  1621. }
  1622. elseif (isset($row[$field]))
  1623. {
  1624. $showfields[$field] = 1;
  1625. $map = $section.'.'.$field;
  1626. if (isset($namemap[$map]))
  1627. $showhead[$namemap[$map]] = 1;
  1628. else
  1629. $showhead[$field] = 1;
  1630. }
  1631. }
  1632. }
  1633. if (count($showfields) > 0)
  1634. {
  1635. if ($shownsomething)
  1636. otherrow('<td>&nbsp;</td>');
  1637. newtable();
  1638. showhead('', array('Rig'=>1)+$showhead, true);
  1639. $total = array();
  1640. $add = array('total' => array());
  1641. foreach ($rigresults as $num => $result)
  1642. $total = customset($showfields, $sum, $section, $num, true, $result, $total);
  1643. if (count($total) > 0)
  1644. customset($showfields, $sum, $section, '&Sigma;', false, $add, $total);
  1645. $first = false;
  1646. endtable();
  1647. $shownsomething = true;
  1648. }
  1649. }
  1650. }
  1651. }
  1652. if (count($errors) > 0)
  1653. {
  1654. if (count($results) > 0)
  1655. otherrow('<td>&nbsp;</td>');
  1656. foreach ($errors as $err)
  1657. otherrow("<td colspan=100>$err</td>");
  1658. }
  1659. }
  1660. #
  1661. function showcustompage($pagename)
  1662. {
  1663. global $customsummarypages;
  1664. global $placebuttons;
  1665. htmlhead(false, null, $pagename);
  1666. if ($placebuttons == 'top' || $placebuttons == 'both')
  1667. pagebuttons(null, $pagename);
  1668. if (!isset($customsummarypages[$pagename]))
  1669. {
  1670. otherrow("<td colspan=100>Unknown custom summary page '$pagename'</td>");
  1671. return;
  1672. }
  1673. if (count($customsummarypages[$pagename]) != 2)
  1674. {
  1675. $rw = "<td colspan=100>Invalid custom summary page '$pagename' (";
  1676. $rw .= count($customsummarypages[$pagename]).')</td>';
  1677. otherrow($rw);
  1678. return;
  1679. }
  1680. $page = $customsummarypages[$pagename][0];
  1681. $namemap = array();
  1682. foreach ($page as $name => $fields)
  1683. {
  1684. if ($fields === null)
  1685. $page[$name] = array();
  1686. else
  1687. foreach ($fields as $num => $field)
  1688. {
  1689. $pos = strpos($field, '=');
  1690. if ($pos !== false)
  1691. {
  1692. $names = explode('=', $field, 2);
  1693. if (strlen($names[1]) > 0)
  1694. $namemap[$name.'.'.$names[0]] = $names[1];
  1695. $page[$name][$num] = $names[0];
  1696. }
  1697. }
  1698. }
  1699. $sum = $customsummarypages[$pagename][1];
  1700. if ($sum === null)
  1701. $sum = array();
  1702. // convert them to searchable via isset()
  1703. foreach ($sum as $section => $fields)
  1704. {
  1705. $newfields = array();
  1706. foreach ($fields as $field)
  1707. $newfields[$field] = 1;
  1708. $sum[$section] = $newfields;
  1709. }
  1710. if (count($page) <= 1)
  1711. {
  1712. otherrow("<td colspan=100>Invalid custom summary page '$pagename' no content </td>");
  1713. return;
  1714. }
  1715. processcustompage($pagename, $page, $sum, $namemap);
  1716. if ($placebuttons == 'bot' || $placebuttons == 'both')
  1717. pagebuttons(null, $pagename);
  1718. }
  1719. #
  1720. function display()
  1721. {
  1722. global $miner, $port;
  1723. global $readonly, $notify, $rigs;
  1724. global $ignorerefresh, $autorefresh;
  1725. global $allowcustompages;
  1726. global $placebuttons;
  1727. if ($ignorerefresh == false)
  1728. {
  1729. $ref = trim(getparam('ref', true));
  1730. if ($ref != null && $ref != '')
  1731. $autorefresh = intval($ref);
  1732. }
  1733. $rig = trim(getparam('rig', true));
  1734. $arg = trim(getparam('arg', true));
  1735. $preprocess = null;
  1736. if ($arg != null and $arg != '')
  1737. {
  1738. $num = null;
  1739. if ($rig != null and $rig != '')
  1740. {
  1741. if ($rig >= 0 and $rig < count($rigs))
  1742. $num = $rig;
  1743. }
  1744. else
  1745. if (count($rigs) == 0)
  1746. $num = 0;
  1747. if ($num != null)
  1748. {
  1749. $parts = explode(':', $rigs[$num], 3);
  1750. if (count($parts) >= 2)
  1751. {
  1752. $miner = $parts[0];
  1753. $port = $parts[1];
  1754. if ($readonly !== true)
  1755. $preprocess = $arg;
  1756. }
  1757. }
  1758. }
  1759. if ($rigs == null or count($rigs) == 0)
  1760. {
  1761. otherrow("<td>No rigs defined</td>");
  1762. return;
  1763. }
  1764. if ($allowcustompages === true)
  1765. {
  1766. $pg = trim(getparam('pg', true));
  1767. if ($pg != null && $pg != '')
  1768. {
  1769. showcustompage($pg);
  1770. return;
  1771. }
  1772. }
  1773. if (count($rigs) == 1)
  1774. {
  1775. $parts = explode(':', $rigs[0], 3);
  1776. if (count($parts) >= 2)
  1777. {
  1778. $miner = $parts[0];
  1779. $port = $parts[1];
  1780. doOne(0, $preprocess);
  1781. }
  1782. else
  1783. otherrow('<td>Invalid "$rigs" array</td>');
  1784. return;
  1785. }
  1786. if ($rig != null and $rig != '' and $rig >= 0 and $rig < count($rigs))
  1787. {
  1788. $parts = explode(':', $rigs[$rig], 3);
  1789. if (count($parts) >= 2)
  1790. {
  1791. $miner = $parts[0];
  1792. $port = $parts[1];
  1793. doOne($rig, $preprocess);
  1794. }
  1795. else
  1796. otherrow('<td>Invalid "$rigs" array</td>');
  1797. return;
  1798. }
  1799. htmlhead(false, null);
  1800. if ($placebuttons == 'top' || $placebuttons == 'both')
  1801. pagebuttons(null, null);
  1802. if ($preprocess != null)
  1803. process(array($preprocess => $preprocess), $rig);
  1804. newtable();
  1805. doforeach('version', 'rig summary', array(), array(), true);
  1806. $sum = array('MHS av', 'Getworks', 'Found Blocks', 'Accepted', 'Rejected', 'Discarded', 'Stale', 'Utility', 'Local Work', 'Total MH', 'Work Utility', 'Diff1 Shares');
  1807. doforeach('summary', 'summary information', $sum, array(), false);
  1808. endtable();
  1809. otherrow('<td><br><br></td>');
  1810. newtable();
  1811. doforeach('devs', 'device list', $sum, array(''=>'','ID'=>'','Name'=>''), false);
  1812. endtable();
  1813. otherrow('<td><br><br></td>');
  1814. newtable();
  1815. doforeach('pools', 'pool list', $sum, array(''=>''), false);
  1816. endtable();
  1817. if ($placebuttons == 'bot' || $placebuttons == 'both')
  1818. pagebuttons(null, null);
  1819. }
  1820. #
  1821. display();
  1822. #
  1823. ?>
  1824. </table></td></tr></table>
  1825. </body></html>