miner.php 44 KB

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