miner.php 44 KB

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