miner.php 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059
  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. case 'COIN.Current Block Time':
  723. $ret = date($dfmt, $value);
  724. break;
  725. case 'BUTTON.Rig':
  726. case 'BUTTON.Pool':
  727. case 'BUTTON.GPU':
  728. $ret = $value;
  729. break;
  730. }
  731. if ($section == 'NOTIFY' && substr($name, 0, 1) == '*' && $value != '0')
  732. $class = $errorclass;
  733. if ($class == '' && $section != 'POOL')
  734. $class = classlastshare($when, $alldata, $lstclass, $lstclass);
  735. if ($class == '' && $section == 'total')
  736. $class = $totclass;
  737. if ($class == '' && ($rownum % 2) == 0)
  738. $class = $c2class;
  739. if ($ret === '')
  740. $ret = $b;
  741. return array($ret, $class);
  742. }
  743. #
  744. global $poolcmd;
  745. $poolcmd = array( 'Switch to' => 'switchpool',
  746. 'Enable' => 'enablepool',
  747. 'Disable' => 'disablepool',
  748. 'Remove' => 'removepool' );
  749. #
  750. function showhead($cmd, $values, $justnames = false)
  751. {
  752. global $poolcmd, $readonly;
  753. newrow();
  754. foreach ($values as $name => $value)
  755. {
  756. if ($name == '0' or $name == '')
  757. $name = '&nbsp;';
  758. echo "<td valign=bottom class=h>$name</td>";
  759. }
  760. if ($justnames === false && $cmd == 'pools' && $readonly === false)
  761. foreach ($poolcmd as $name => $pcmd)
  762. echo "<td valign=bottom class=h>$name</td>";
  763. endrow();
  764. }
  765. #
  766. function showdatetime()
  767. {
  768. global $dfmt;
  769. otherrow('<td class=sta>Date: '.date($dfmt).'</td>');
  770. }
  771. #
  772. global $singlerigsum;
  773. $singlerigsum = array(
  774. 'devs' => array('MHS av' => 1, 'MHS 5s' => 1, 'Accepted' => 1, 'Rejected' => 1,
  775. 'Hardware Errors' => 1, 'Utility' => 1, 'Total MH' => 1),
  776. 'pools' => array('Getworks' => 1, 'Accepted' => 1, 'Rejected' => 1, 'Discarded' => 1,
  777. 'Stale' => 1, 'Get Failures' => 1, 'Remote Failures' => 1,
  778. 'Diff1 Shares' => 1),
  779. 'notify' => array('*' => 1));
  780. #
  781. function showtotal($total, $when, $oldvalues)
  782. {
  783. global $rigtotals;
  784. list($showvalue, $class) = fmt('total', '', 'Total:', $when, null);
  785. echo "<td$class align=right>$showvalue</td>";
  786. $skipfirst = true;
  787. foreach ($oldvalues as $name => $value)
  788. {
  789. if ($skipfirst === true)
  790. {
  791. $skipfirst = false;
  792. continue;
  793. }
  794. if (isset($total[$name]))
  795. $newvalue = $total[$name];
  796. else
  797. $newvalue = '';
  798. list($showvalue, $class) = fmt('total', $name, $newvalue, $when, null);
  799. echo "<td$class";
  800. if ($rigtotals === true)
  801. echo ' align=right';
  802. echo ">$showvalue</td>";
  803. }
  804. }
  805. #
  806. function details($cmd, $list, $rig)
  807. {
  808. global $dfmt, $poolcmd, $readonly, $showndate;
  809. global $rownum, $rigtotals, $forcerigtotals, $singlerigsum;
  810. $when = 0;
  811. $stas = array('S' => 'Success', 'W' => 'Warning', 'I' => 'Informational', 'E' => 'Error', 'F' => 'Fatal');
  812. newtable();
  813. if ($showndate === false)
  814. {
  815. showdatetime();
  816. endtable();
  817. newtable();
  818. $showndate = true;
  819. }
  820. if (isset($list['STATUS']))
  821. {
  822. newrow();
  823. echo '<td>Computer: '.$list['STATUS']['Description'].'</td>';
  824. if (isset($list['STATUS']['When']))
  825. {
  826. echo '<td>When: '.date($dfmt, $list['STATUS']['When']).'</td>';
  827. $when = $list['STATUS']['When'];
  828. }
  829. $sta = $list['STATUS']['STATUS'];
  830. echo '<td>Status: '.$stas[$sta].'</td>';
  831. echo '<td>Message: '.$list['STATUS']['Msg'].'</td>';
  832. endrow();
  833. }
  834. if ($rigtotals === true && isset($singlerigsum[$cmd]))
  835. $dototal = $singlerigsum[$cmd];
  836. else
  837. $dototal = array();
  838. $total = array();
  839. $section = '';
  840. $oldvalues = null;
  841. foreach ($list as $item => $values)
  842. {
  843. if ($item == 'STATUS')
  844. continue;
  845. $sectionname = preg_replace('/\d/', '', $item);
  846. // Handle 'devs' possibly containing >1 table
  847. if ($sectionname != $section)
  848. {
  849. if ($oldvalues != null && count($total) > 0
  850. && ($rownum > 2 || $forcerigtotals === true))
  851. showtotal($total, $when, $oldvalues);
  852. endtable();
  853. newtable();
  854. showhead($cmd, $values);
  855. $section = $sectionname;
  856. }
  857. newrow();
  858. foreach ($values as $name => $value)
  859. {
  860. list($showvalue, $class) = fmt($section, $name, $value, $when, $values);
  861. echo "<td$class";
  862. if ($rigtotals === true)
  863. echo ' align=right';
  864. echo ">$showvalue</td>";
  865. if (isset($dototal[$name])
  866. || (isset($dototal['*']) and substr($name, 0, 1) == '*'))
  867. {
  868. if (isset($total[$name]))
  869. $total[$name] += $value;
  870. else
  871. $total[$name] = $value;
  872. }
  873. }
  874. if ($cmd == 'pools' && $readonly === false)
  875. {
  876. reset($values);
  877. $pool = current($values);
  878. foreach ($poolcmd as $name => $pcmd)
  879. {
  880. list($ignore, $class) = fmt('BUTTON', 'Pool', '', $when, $values);
  881. echo "<td$class>";
  882. if ($pool === false)
  883. echo '&nbsp;';
  884. else
  885. {
  886. echo "<input type=button value='Pool $pool'";
  887. echo " onclick='prc(\"$pcmd|$pool&rig=$rig\",\"$name Pool $pool\")'>";
  888. }
  889. echo '</td>';
  890. }
  891. }
  892. endrow();
  893. $oldvalues = $values;
  894. }
  895. if ($oldvalues != null && count($total) > 0
  896. && ($rownum > 2 || $forcerigtotals === true))
  897. showtotal($total, $when, $oldvalues);
  898. endtable();
  899. }
  900. #
  901. global $devs;
  902. $devs = null;
  903. #
  904. function gpubuttons($count, $rig)
  905. {
  906. global $devs;
  907. $basic = array( 'GPU', 'Enable', 'Disable', 'Restart' );
  908. $options = array( 'intensity' => 'Intensity',
  909. 'fan' => 'Fan Percent',
  910. 'engine' => 'GPU Clock',
  911. 'mem' => 'Memory Clock',
  912. 'vddc' => 'GPU Voltage' );
  913. newtable();
  914. newrow();
  915. foreach ($basic as $head)
  916. echo "<td class=h>$head</td>";
  917. foreach ($options as $name => $des)
  918. echo "<td class=h nowrap>$des</td>";
  919. $n = 0;
  920. for ($c = 0; $c < $count; $c++)
  921. {
  922. endrow();
  923. newrow();
  924. foreach ($basic as $name)
  925. {
  926. list($ignore, $class) = fmt('BUTTON', 'GPU', '', 0, null);
  927. echo "<td$class>";
  928. if ($name == 'GPU')
  929. echo $c;
  930. else
  931. {
  932. echo "<input type=button value='$name $c' onclick='prs(\"gpu";
  933. echo strtolower($name);
  934. echo "|$c\",$rig)'>";
  935. }
  936. echo '</td>';
  937. }
  938. foreach ($options as $name => $des)
  939. {
  940. list($ignore, $class) = fmt('BUTTON', 'GPU', '', 0, null);
  941. echo "<td$class>";
  942. if (!isset($devs["GPU$c"][$des]))
  943. echo '&nbsp;';
  944. else
  945. {
  946. $value = $devs["GPU$c"][$des];
  947. echo "<input type=button value='Set $c:' onclick='prs2(\"gpu$name|$c\",$n,$rig)'>";
  948. echo "<input size=7 type=text name=gi$n value='$value' id=gi$n>";
  949. $n++;
  950. }
  951. echo '</td>';
  952. }
  953. }
  954. endrow();
  955. endtable();
  956. }
  957. #
  958. function processgpus($rig)
  959. {
  960. global $error;
  961. global $warnfont, $warnoff;
  962. $gpus = api('gpucount');
  963. if ($error != null)
  964. otherrow("<td>Error getting GPU count: $warnfont$error$warnoff</td>");
  965. else
  966. {
  967. if (!isset($gpus['GPUS']['Count']))
  968. {
  969. $rw = '<td>No GPU count returned: '.$warnfont;
  970. $rw .= $gpus['STATUS']['STATUS'].' '.$gpus['STATUS']['Msg'];
  971. $rw .= $warnoff.'</td>';
  972. otherrow($rw);
  973. }
  974. else
  975. {
  976. $count = $gpus['GPUS']['Count'];
  977. if ($count == 0)
  978. otherrow('<td>No GPUs</td>');
  979. else
  980. gpubuttons($count, $rig);
  981. }
  982. }
  983. }
  984. #
  985. function showpoolinputs($rig, $ans)
  986. {
  987. global $readonly, $poolinputs;
  988. if ($readonly === true || $poolinputs === false)
  989. return;
  990. newtable();
  991. newrow();
  992. $inps = array('Pool URL' => array('purl', 20),
  993. 'Worker Name' => array('pwork', 10),
  994. 'Worker Password' => array('ppass', 10));
  995. $b = '&nbsp;';
  996. echo "<td align=right class=h> Add a pool: </td><td>";
  997. foreach ($inps as $text => $name)
  998. echo "$text: <input name='".$name[0]."' id='".$name[0]."' value='' type=text size=".$name[1]."> ";
  999. echo "</td><td align=middle><input type=button value='Add' onclick='pla($rig)'></td>";
  1000. endrow();
  1001. if (count($ans) > 1)
  1002. {
  1003. newrow();
  1004. echo '<td align=right class=h> Set pool priorities: </td>';
  1005. echo "<td> Comma list of pool numbers: <input type=text name=prio id=prio size=20>";
  1006. echo "</td><td align=middle><input type=button value='Set' onclick='psp($rig)'></td>";
  1007. endrow();
  1008. }
  1009. endtable();
  1010. }
  1011. #
  1012. function process($cmds, $rig)
  1013. {
  1014. global $error, $devs;
  1015. global $warnfont, $warnoff;
  1016. $count = count($cmds);
  1017. foreach ($cmds as $cmd => $des)
  1018. {
  1019. $process = api($cmd);
  1020. if ($error != null)
  1021. {
  1022. otherrow("<td colspan=100>Error getting $des: $warnfont$error$warnoff</td>");
  1023. break;
  1024. }
  1025. else
  1026. {
  1027. details($cmd, $process, $rig);
  1028. if ($cmd == 'devs')
  1029. $devs = $process;
  1030. if ($cmd == 'pools')
  1031. showpoolinputs($rig, $process);
  1032. # Not after the last one
  1033. if (--$count > 0)
  1034. otherrow('<td><br><br></td>');
  1035. }
  1036. }
  1037. }
  1038. #
  1039. function rigbutton($rig, $rigname, $when, $row)
  1040. {
  1041. global $rigs;
  1042. if (isset($rigs[$rig]))
  1043. {
  1044. $parts = explode(':', $rigs[$rig], 3);
  1045. if (count($parts) == 3)
  1046. $rigname = $parts[2];
  1047. }
  1048. list($value, $class) = fmt('BUTTON', 'Rig', '', $when, $row);
  1049. $button = "<td align=middle$class><input type=button value='$rigname'";
  1050. $button .= " onclick='pr(\"&rig=$rig\",null)'></td>";
  1051. return $button;
  1052. }
  1053. #
  1054. function showrigs($anss, $headname, $rigname)
  1055. {
  1056. $dthead = array($headname => 1, 'STATUS' => 1, 'Description' => 1, 'When' => 1, 'API' => 1, 'CGMiner' => 1);
  1057. showhead('', $dthead);
  1058. foreach ($anss as $rig => $ans)
  1059. {
  1060. if ($ans == null)
  1061. continue;
  1062. newrow();
  1063. $when = 0;
  1064. if (isset($ans['STATUS']['When']))
  1065. $when = $ans['STATUS']['When'];
  1066. foreach ($ans as $item => $row)
  1067. {
  1068. if ($item != 'STATUS' && $item != 'VERSION')
  1069. continue;
  1070. foreach ($dthead as $name => $x)
  1071. {
  1072. if ($item == 'STATUS' && $name == $headname)
  1073. echo rigbutton($rig, $rigname.$rig, $when, null);
  1074. else
  1075. {
  1076. if (isset($row[$name]))
  1077. {
  1078. list($showvalue, $class) = fmt('STATUS', $name, $row[$name], $when, null);
  1079. echo "<td$class align=right>$showvalue</td>";
  1080. }
  1081. }
  1082. }
  1083. }
  1084. endrow();
  1085. }
  1086. }
  1087. #
  1088. # $head is a hack but this is just a demo anyway :)
  1089. function doforeach($cmd, $des, $sum, $head, $datetime)
  1090. {
  1091. global $miner, $port;
  1092. global $error, $readonly, $notify, $rigs;
  1093. global $warnfont, $warnoff, $dfmt;
  1094. global $rigerror;
  1095. $when = 0;
  1096. $header = $head;
  1097. $anss = array();
  1098. $count = 0;
  1099. $preverr = count($rigerror);
  1100. foreach ($rigs as $num => $rig)
  1101. {
  1102. $anss[$num] = null;
  1103. if (isset($rigerror[$rig]))
  1104. continue;
  1105. $parts = explode(':', $rig, 3);
  1106. if (count($parts) >= 2)
  1107. {
  1108. $miner = $parts[0];
  1109. $port = $parts[1];
  1110. if (count($parts) > 2)
  1111. $name = $parts[2];
  1112. else
  1113. $name = $num;
  1114. $ans = api($cmd);
  1115. if ($error != null)
  1116. {
  1117. $rw = "<td colspan=100>Error on rig $name getting ";
  1118. $rw .= "$des: $warnfont$error$warnoff</td>";
  1119. otherrow($rw);
  1120. $rigerror[$rig] = $error;
  1121. $error = null;
  1122. }
  1123. else
  1124. {
  1125. $anss[$num] = $ans;
  1126. $count++;
  1127. }
  1128. }
  1129. }
  1130. if ($count == 0)
  1131. {
  1132. $rw = '<td>Failed to access any rigs successfully';
  1133. if ($preverr > 0)
  1134. $rw .= ' (or rigs had previous errors)';
  1135. $rw .= '</td>';
  1136. otherrow($rw);
  1137. return;
  1138. }
  1139. if ($datetime)
  1140. {
  1141. showdatetime();
  1142. endtable();
  1143. newtable();
  1144. showrigs($anss, '', 'Rig ');
  1145. endtable();
  1146. otherrow('<td><br><br></td>');
  1147. newtable();
  1148. return;
  1149. }
  1150. $total = array();
  1151. foreach ($anss as $rig => $ans)
  1152. {
  1153. if ($ans == null)
  1154. continue;
  1155. foreach ($ans as $item => $row)
  1156. {
  1157. if ($item == 'STATUS')
  1158. continue;
  1159. if (count($row) > count($header))
  1160. {
  1161. $header = $head;
  1162. foreach ($row as $name => $value)
  1163. if (!isset($header[$name]))
  1164. $header[$name] = '';
  1165. }
  1166. if ($sum != null)
  1167. foreach ($sum as $name)
  1168. {
  1169. if (isset($row[$name]))
  1170. {
  1171. if (isset($total[$name]))
  1172. $total[$name] += $row[$name];
  1173. else
  1174. $total[$name] = $row[$name];
  1175. }
  1176. }
  1177. }
  1178. }
  1179. if ($sum != null)
  1180. $anss['total']['total'] = $total;
  1181. showhead('', $header);
  1182. foreach ($anss as $rig => $ans)
  1183. {
  1184. if ($ans == null)
  1185. continue;
  1186. $when = 0;
  1187. if (isset($ans['STATUS']['When']))
  1188. $when = $ans['STATUS']['When'];
  1189. foreach ($ans as $item => $row)
  1190. {
  1191. if ($item == 'STATUS')
  1192. continue;
  1193. newrow();
  1194. $section = preg_replace('/\d/', '', $item);
  1195. foreach ($header as $name => $x)
  1196. {
  1197. if ($name == '')
  1198. {
  1199. if ($rig === 'total')
  1200. {
  1201. list($ignore, $class) = fmt($rig, '', '', $when, $row);
  1202. echo "<td align=right$class>Total:</td>";
  1203. }
  1204. else
  1205. echo rigbutton($rig, "Rig $rig", $when, $row);
  1206. }
  1207. else
  1208. {
  1209. if (isset($row[$name]))
  1210. $value = $row[$name];
  1211. else
  1212. $value = null;
  1213. list($showvalue, $class) = fmt($section, $name, $value, $when, $row);
  1214. echo "<td$class align=right>$showvalue</td>";
  1215. }
  1216. }
  1217. endrow();
  1218. }
  1219. }
  1220. }
  1221. #
  1222. function refreshbuttons()
  1223. {
  1224. global $readonly;
  1225. global $ignorerefresh, $changerefresh, $autorefresh;
  1226. if ($ignorerefresh == false && $changerefresh == true)
  1227. {
  1228. echo '&nbsp;&nbsp;&nbsp;&nbsp;';
  1229. echo "<input type=button value='Auto Refresh:' onclick='prr(true)'>";
  1230. echo "<input type=text name='refval' id='refval' size=2 value='$autorefresh'>";
  1231. echo "<input type=button value='Off' onclick='prr(false)'>";
  1232. }
  1233. }
  1234. #
  1235. function pagebuttons($rig, $pg)
  1236. {
  1237. global $readonly, $rigs;
  1238. global $allowcustompages, $customsummarypages;
  1239. if ($rig === null)
  1240. {
  1241. if ($pg === null)
  1242. $refresh = '';
  1243. else
  1244. $refresh = "&pg=$pg";
  1245. }
  1246. else
  1247. $refresh = "&rig=$rig";
  1248. echo '<tr><td><table cellpadding=0 cellspacing=0 border=0><tr><td nowrap>';
  1249. echo "<input type=button value='Refresh' onclick='pr(\"$refresh\",null)'>&nbsp;";
  1250. if (count($rigs) > 1)
  1251. echo "<input type=button value='Summary' onclick='pr(\"\",null)'>&nbsp;";
  1252. if ($allowcustompages === true)
  1253. foreach ($customsummarypages as $pagename => $data)
  1254. echo "<input type=button value='$pagename' onclick='pr(\"&pg=$pagename\",null)'>&nbsp;";
  1255. echo '</td><td width=100%>&nbsp;</td><td nowrap>';
  1256. if ($rig !== null && $readonly === false)
  1257. {
  1258. $rg = '';
  1259. if (count($rigs) > 1)
  1260. $rg = " Rig $rig";
  1261. echo "<input type=button value='Restart' onclick='prc(\"restart&rig=$rig\",\"Restart CGMiner$rg\")'>";
  1262. echo "&nbsp;<input type=button value='Quit' onclick='prc(\"quit&rig=$rig\",\"Quit CGMiner$rg\")'>";
  1263. }
  1264. refreshbuttons();
  1265. echo "</td></tr></table></td></tr>";
  1266. }
  1267. #
  1268. function doOne($rig, $preprocess)
  1269. {
  1270. global $haderror, $readonly, $notify, $rigs;
  1271. global $placebuttons;
  1272. htmlhead(true, $rig);
  1273. if ($placebuttons == 'top' || $placebuttons == 'both')
  1274. pagebuttons($rig, null);
  1275. if ($preprocess != null)
  1276. process(array($preprocess => $preprocess), $rig);
  1277. $cmds = array( 'devs' => 'device list',
  1278. 'summary' => 'summary information',
  1279. 'pools' => 'pool list');
  1280. if ($notify)
  1281. $cmds['notify'] = 'device status';
  1282. $cmds['config'] = 'cgminer config';
  1283. process($cmds, $rig);
  1284. if ($haderror == false && $readonly === false)
  1285. processgpus($rig);
  1286. if ($placebuttons == 'bot' || $placebuttons == 'both')
  1287. pagebuttons($rig, null);
  1288. }
  1289. #
  1290. global $sectionmap;
  1291. # map sections to their api command
  1292. # DEVS is a special case that will match GPU or PGA
  1293. # so you can have a single table with both in it
  1294. # DATE is hard coded so not in here
  1295. $sectionmap = array(
  1296. 'RIGS' => 'version',
  1297. 'SUMMARY' => 'summary',
  1298. 'POOL' => 'pools',
  1299. 'DEVS' => 'devs',
  1300. 'GPU' => 'devs', // You would normally use DEVS
  1301. 'PGA' => 'devs', // You would normally use DEVS
  1302. 'NOTIFY' => 'notify',
  1303. 'DEVDETAILS' => 'devdetails',
  1304. 'STATS' => 'stats',
  1305. 'CONFIG' => 'config',
  1306. 'COIN' => 'coin');
  1307. #
  1308. function joinfields($section1, $section2, $join, $results)
  1309. {
  1310. global $sectionmap;
  1311. $name1 = $sectionmap[$section1];
  1312. $name2 = $sectionmap[$section2];
  1313. $newres = array();
  1314. // foreach rig in section1
  1315. foreach ($results[$name1] as $rig => $result)
  1316. {
  1317. $status = null;
  1318. // foreach answer section in the rig api call
  1319. foreach ($result as $name1b => $fields1b)
  1320. {
  1321. if ($name1b == 'STATUS')
  1322. {
  1323. // remember the STATUS from section1
  1324. $status = $result[$name1b];
  1325. continue;
  1326. }
  1327. // foreach answer section in the rig api call (for the other api command)
  1328. foreach ($results[$name2][$rig] as $name2b => $fields2b)
  1329. {
  1330. if ($name2b == 'STATUS')
  1331. continue;
  1332. // If match the same field values of fields in $join
  1333. $match = true;
  1334. foreach ($join as $field)
  1335. if ($fields1b[$field] != $fields2b[$field])
  1336. {
  1337. $match = false;
  1338. break;
  1339. }
  1340. if ($match === true)
  1341. {
  1342. if ($status != null)
  1343. {
  1344. $newres[$rig]['STATUS'] = $status;
  1345. $status = null;
  1346. }
  1347. $subsection = $section1.'+'.$section2;
  1348. $subsection .= preg_replace('/[^0-9]/', '', $name1b.$name2b);
  1349. foreach ($fields1b as $nam => $val)
  1350. $newres[$rig][$subsection]["$section1.$nam"] = $val;
  1351. foreach ($fields2b as $nam => $val)
  1352. $newres[$rig][$subsection]["$section2.$nam"] = $val;
  1353. }
  1354. }
  1355. }
  1356. }
  1357. return $newres;
  1358. }
  1359. #
  1360. function joinall($section1, $section2, $results)
  1361. {
  1362. global $sectionmap;
  1363. $name1 = $sectionmap[$section1];
  1364. $name2 = $sectionmap[$section2];
  1365. $newres = array();
  1366. // foreach rig in section1
  1367. foreach ($results[$name1] as $rig => $result)
  1368. {
  1369. // foreach answer section in the rig api call
  1370. foreach ($result as $name1b => $fields1b)
  1371. {
  1372. if ($name1b == 'STATUS')
  1373. {
  1374. // copy the STATUS from section1
  1375. $newres[$rig][$name1b] = $result[$name1b];
  1376. continue;
  1377. }
  1378. // foreach answer section in the rig api call (for the other api command)
  1379. foreach ($results[$name2][$rig] as $name2b => $fields2b)
  1380. {
  1381. if ($name2b == 'STATUS')
  1382. continue;
  1383. $subsection = $section1.'+'.$section2;
  1384. $subsection .= preg_replace('/[^0-9]/', '', $name1b.$name2b);
  1385. foreach ($fields1b as $nam => $val)
  1386. $newres[$rig][$subsection]["$section1.$nam"] = $val;
  1387. foreach ($fields2b as $nam => $val)
  1388. $newres[$rig][$subsection]["$section2.$nam"] = $val;
  1389. }
  1390. }
  1391. }
  1392. return $newres;
  1393. }
  1394. #
  1395. function joinsections($sections, $results, $errors)
  1396. {
  1397. global $sectionmap;
  1398. #echo "results['pools']=".print_r($results['pools'],true)."<br>";
  1399. // GPU's don't have Name,ID fields - so create them
  1400. foreach ($results as $section => $res)
  1401. foreach ($res as $rig => $result)
  1402. foreach ($result as $name => $fields)
  1403. {
  1404. $subname = preg_replace('/[0-9]/', '', $name);
  1405. if ($subname == 'GPU' and isset($result[$name]['GPU']))
  1406. {
  1407. $results[$section][$rig][$name]['Name'] = 'GPU';
  1408. $results[$section][$rig][$name]['ID'] = $result[$name]['GPU'];
  1409. }
  1410. }
  1411. foreach ($sections as $section => $fields)
  1412. if ($section != 'DATE' && !isset($sectionmap[$section]))
  1413. {
  1414. $both = explode('+', $section, 2);
  1415. if (count($both) > 1)
  1416. {
  1417. switch($both[0])
  1418. {
  1419. case 'SUMMARY':
  1420. switch($both[1])
  1421. {
  1422. case 'POOL':
  1423. case 'DEVS':
  1424. case 'CONFIG':
  1425. case 'COIN':
  1426. $sectionmap[$section] = $section;
  1427. $results[$section] = joinall($both[0], $both[1], $results);
  1428. break;
  1429. default:
  1430. $errors[] = "Error: Invalid section '$section'";
  1431. break;
  1432. }
  1433. break;
  1434. case 'DEVS':
  1435. $join = array('Name', 'ID');
  1436. switch($both[1])
  1437. {
  1438. case 'NOTIFY':
  1439. case 'DEVDETAILS':
  1440. $sectionmap[$section] = $section;
  1441. $results[$section] = joinfields($both[0], $both[1], $join, $results);
  1442. break;
  1443. default:
  1444. $errors[] = "Error: Invalid section '$section'";
  1445. break;
  1446. }
  1447. break;
  1448. default:
  1449. $errors[] = "Error: Invalid section '$section'";
  1450. break;
  1451. }
  1452. }
  1453. else
  1454. $errors[] = "Error: Invalid section '$section'";
  1455. }
  1456. return array($results, $errors);
  1457. }
  1458. #
  1459. function secmatch($section, $field)
  1460. {
  1461. if ($section == $field)
  1462. return true;
  1463. if ($section == 'DEVS'
  1464. && ($field == 'GPU' || $field == 'PGA'))
  1465. return true;
  1466. return false;
  1467. }
  1468. #
  1469. function customset($showfields, $sum, $section, $rig, $isbutton, $result, $total)
  1470. {
  1471. foreach ($result as $sec => $row)
  1472. {
  1473. $secname = preg_replace('/\d/', '', $sec);
  1474. if ($sec != 'total')
  1475. if (!secmatch($section, $secname))
  1476. continue;
  1477. newrow();
  1478. $when = 0;
  1479. if (isset($result['STATUS']['When']))
  1480. $when = $result['STATUS']['When'];
  1481. if ($isbutton)
  1482. echo rigbutton($rig, $rig, $when, $row);
  1483. else
  1484. {
  1485. list($ignore, $class) = fmt('total', '', '', $when, $row);
  1486. echo "<td align=middle$class>$rig</td>";
  1487. }
  1488. foreach ($showfields as $name => $one)
  1489. {
  1490. if (isset($row[$name]))
  1491. {
  1492. $value = $row[$name];
  1493. if (isset($sum[$section][$name]))
  1494. {
  1495. if (isset($total[$name]))
  1496. $total[$name] += $value;
  1497. else
  1498. $total[$name] = $value;
  1499. }
  1500. }
  1501. else
  1502. {
  1503. if ($sec == 'total' && isset($total[$name]))
  1504. $value = $total[$name];
  1505. else
  1506. $value = null;
  1507. }
  1508. if (strpos($secname, '+') === false)
  1509. list($showvalue, $class) = fmt($secname, $name, $value, $when, $row);
  1510. else
  1511. {
  1512. $parts = explode('.', $name, 2);
  1513. list($showvalue, $class) = fmt($parts[0], $parts[1], $value, $when, $row);
  1514. }
  1515. echo "<td$class align=right>$showvalue</td>";
  1516. }
  1517. endrow();
  1518. }
  1519. return $total;
  1520. }
  1521. #
  1522. function processcustompage($pagename, $sections, $sum, $namemap)
  1523. {
  1524. global $sectionmap;
  1525. global $miner, $port;
  1526. global $rigs, $error;
  1527. global $warnfont, $warnoff;
  1528. global $dfmt;
  1529. global $readonly, $showndate;
  1530. $cmds = array();
  1531. $errors = array();
  1532. foreach ($sections as $section => $fields)
  1533. {
  1534. $all = explode('+', $section);
  1535. foreach ($all as $section)
  1536. {
  1537. if (isset($sectionmap[$section]))
  1538. {
  1539. $cmd = $sectionmap[$section];
  1540. if (!isset($cmds[$cmd]))
  1541. $cmds[$cmd] = 1;
  1542. }
  1543. else
  1544. if ($section != 'DATE')
  1545. $errors[] = "Error: unknown section '$section' in custom summary page '$pagename'";
  1546. }
  1547. }
  1548. $results = array();
  1549. foreach ($rigs as $num => $rig)
  1550. {
  1551. $parts = explode(':', $rig, 3);
  1552. if (count($parts) >= 2)
  1553. {
  1554. $miner = $parts[0];
  1555. $port = $parts[1];
  1556. if (count($parts) > 2)
  1557. $name = $parts[2];
  1558. else
  1559. $name = $rig;
  1560. foreach ($cmds as $cmd => $one)
  1561. {
  1562. $process = api($cmd);
  1563. if ($error != null)
  1564. {
  1565. $errors[] = "Error getting $cmd for $name $warnfont$error$warnoff";
  1566. break;
  1567. }
  1568. else
  1569. $results[$cmd][$num] = $process;
  1570. }
  1571. }
  1572. }
  1573. $shownsomething = false;
  1574. if (count($results) > 0)
  1575. {
  1576. list($results, $errors) = joinsections($sections, $results, $errors);
  1577. $first = true;
  1578. foreach ($sections as $section => $fields)
  1579. {
  1580. if ($section === 'DATE')
  1581. {
  1582. if ($shownsomething)
  1583. otherrow('<td>&nbsp;</td>');
  1584. newtable();
  1585. showdatetime();
  1586. endtable();
  1587. // On top of the next table
  1588. $shownsomething = false;
  1589. continue;
  1590. }
  1591. if ($section === 'RIGS')
  1592. {
  1593. if ($shownsomething)
  1594. otherrow('<td>&nbsp;</td>');
  1595. newtable();
  1596. showrigs($results['version'], 'Rig', '');
  1597. endtable();
  1598. $shownsomething = true;
  1599. continue;
  1600. }
  1601. if (isset($results[$sectionmap[$section]]))
  1602. {
  1603. $rigresults = $results[$sectionmap[$section]];
  1604. $showfields = array();
  1605. $showhead = array();
  1606. foreach ($fields as $field)
  1607. foreach ($rigresults as $result)
  1608. foreach ($result as $sec => $row)
  1609. {
  1610. $secname = preg_replace('/\d/', '', $sec);
  1611. if (secmatch($section, $secname))
  1612. {
  1613. if ($field === '*')
  1614. {
  1615. foreach ($row as $f => $v)
  1616. {
  1617. $showfields[$f] = 1;
  1618. $map = $section.'.'.$f;
  1619. if (isset($namemap[$map]))
  1620. $showhead[$namemap[$map]] = 1;
  1621. else
  1622. $showhead[$f] = 1;
  1623. }
  1624. }
  1625. elseif (isset($row[$field]))
  1626. {
  1627. $showfields[$field] = 1;
  1628. $map = $section.'.'.$field;
  1629. if (isset($namemap[$map]))
  1630. $showhead[$namemap[$map]] = 1;
  1631. else
  1632. $showhead[$field] = 1;
  1633. }
  1634. }
  1635. }
  1636. if (count($showfields) > 0)
  1637. {
  1638. if ($shownsomething)
  1639. otherrow('<td>&nbsp;</td>');
  1640. newtable();
  1641. showhead('', array('Rig'=>1)+$showhead, true);
  1642. $total = array();
  1643. $add = array('total' => array());
  1644. foreach ($rigresults as $num => $result)
  1645. $total = customset($showfields, $sum, $section, $num, true, $result, $total);
  1646. if (count($total) > 0)
  1647. customset($showfields, $sum, $section, '&Sigma;', false, $add, $total);
  1648. $first = false;
  1649. endtable();
  1650. $shownsomething = true;
  1651. }
  1652. }
  1653. }
  1654. }
  1655. if (count($errors) > 0)
  1656. {
  1657. if (count($results) > 0)
  1658. otherrow('<td>&nbsp;</td>');
  1659. foreach ($errors as $err)
  1660. otherrow("<td colspan=100>$err</td>");
  1661. }
  1662. }
  1663. #
  1664. function showcustompage($pagename)
  1665. {
  1666. global $customsummarypages;
  1667. global $placebuttons;
  1668. htmlhead(false, null, $pagename);
  1669. if ($placebuttons == 'top' || $placebuttons == 'both')
  1670. pagebuttons(null, $pagename);
  1671. if (!isset($customsummarypages[$pagename]))
  1672. {
  1673. otherrow("<td colspan=100>Unknown custom summary page '$pagename'</td>");
  1674. return;
  1675. }
  1676. if (count($customsummarypages[$pagename]) != 2)
  1677. {
  1678. $rw = "<td colspan=100>Invalid custom summary page '$pagename' (";
  1679. $rw .= count($customsummarypages[$pagename]).')</td>';
  1680. otherrow($rw);
  1681. return;
  1682. }
  1683. $page = $customsummarypages[$pagename][0];
  1684. $namemap = array();
  1685. foreach ($page as $name => $fields)
  1686. {
  1687. if ($fields === null)
  1688. $page[$name] = array();
  1689. else
  1690. foreach ($fields as $num => $field)
  1691. {
  1692. $pos = strpos($field, '=');
  1693. if ($pos !== false)
  1694. {
  1695. $names = explode('=', $field, 2);
  1696. if (strlen($names[1]) > 0)
  1697. $namemap[$name.'.'.$names[0]] = $names[1];
  1698. $page[$name][$num] = $names[0];
  1699. }
  1700. }
  1701. }
  1702. $sum = $customsummarypages[$pagename][1];
  1703. if ($sum === null)
  1704. $sum = array();
  1705. // convert them to searchable via isset()
  1706. foreach ($sum as $section => $fields)
  1707. {
  1708. $newfields = array();
  1709. foreach ($fields as $field)
  1710. $newfields[$field] = 1;
  1711. $sum[$section] = $newfields;
  1712. }
  1713. if (count($page) <= 1)
  1714. {
  1715. otherrow("<td colspan=100>Invalid custom summary page '$pagename' no content </td>");
  1716. return;
  1717. }
  1718. processcustompage($pagename, $page, $sum, $namemap);
  1719. if ($placebuttons == 'bot' || $placebuttons == 'both')
  1720. pagebuttons(null, $pagename);
  1721. }
  1722. #
  1723. function display()
  1724. {
  1725. global $miner, $port;
  1726. global $readonly, $notify, $rigs;
  1727. global $ignorerefresh, $autorefresh;
  1728. global $allowcustompages;
  1729. global $placebuttons;
  1730. if ($ignorerefresh == false)
  1731. {
  1732. $ref = trim(getparam('ref', true));
  1733. if ($ref != null && $ref != '')
  1734. $autorefresh = intval($ref);
  1735. }
  1736. $rig = trim(getparam('rig', true));
  1737. $arg = trim(getparam('arg', true));
  1738. $preprocess = null;
  1739. if ($arg != null and $arg != '')
  1740. {
  1741. $num = null;
  1742. if ($rig != null and $rig != '')
  1743. {
  1744. if ($rig >= 0 and $rig < count($rigs))
  1745. $num = $rig;
  1746. }
  1747. else
  1748. if (count($rigs) == 0)
  1749. $num = 0;
  1750. if ($num != null)
  1751. {
  1752. $parts = explode(':', $rigs[$num], 3);
  1753. if (count($parts) >= 2)
  1754. {
  1755. $miner = $parts[0];
  1756. $port = $parts[1];
  1757. if ($readonly !== true)
  1758. $preprocess = $arg;
  1759. }
  1760. }
  1761. }
  1762. if ($rigs == null or count($rigs) == 0)
  1763. {
  1764. otherrow("<td>No rigs defined</td>");
  1765. return;
  1766. }
  1767. if ($allowcustompages === true)
  1768. {
  1769. $pg = trim(getparam('pg', true));
  1770. if ($pg != null && $pg != '')
  1771. {
  1772. showcustompage($pg);
  1773. return;
  1774. }
  1775. }
  1776. if (count($rigs) == 1)
  1777. {
  1778. $parts = explode(':', $rigs[0], 3);
  1779. if (count($parts) >= 2)
  1780. {
  1781. $miner = $parts[0];
  1782. $port = $parts[1];
  1783. doOne(0, $preprocess);
  1784. }
  1785. else
  1786. otherrow('<td>Invalid "$rigs" array</td>');
  1787. return;
  1788. }
  1789. if ($rig != null and $rig != '' and $rig >= 0 and $rig < count($rigs))
  1790. {
  1791. $parts = explode(':', $rigs[$rig], 3);
  1792. if (count($parts) >= 2)
  1793. {
  1794. $miner = $parts[0];
  1795. $port = $parts[1];
  1796. doOne($rig, $preprocess);
  1797. }
  1798. else
  1799. otherrow('<td>Invalid "$rigs" array</td>');
  1800. return;
  1801. }
  1802. htmlhead(false, null);
  1803. if ($placebuttons == 'top' || $placebuttons == 'both')
  1804. pagebuttons(null, null);
  1805. if ($preprocess != null)
  1806. process(array($preprocess => $preprocess), $rig);
  1807. newtable();
  1808. doforeach('version', 'rig summary', array(), array(), true);
  1809. $sum = array('MHS av', 'Getworks', 'Found Blocks', 'Accepted', 'Rejected', 'Discarded', 'Stale', 'Utility', 'Local Work', 'Total MH', 'Work Utility', 'Diff1 Shares');
  1810. doforeach('summary', 'summary information', $sum, array(), false);
  1811. endtable();
  1812. otherrow('<td><br><br></td>');
  1813. newtable();
  1814. doforeach('devs', 'device list', $sum, array(''=>'','ID'=>'','Name'=>''), false);
  1815. endtable();
  1816. otherrow('<td><br><br></td>');
  1817. newtable();
  1818. doforeach('pools', 'pool list', $sum, array(''=>''), false);
  1819. endtable();
  1820. if ($placebuttons == 'bot' || $placebuttons == 'both')
  1821. pagebuttons(null, null);
  1822. }
  1823. #
  1824. display();
  1825. #
  1826. ?>
  1827. </table></td></tr></table>
  1828. </body></html>