miner.php 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026
  1. <?php
  2. session_start();
  3. date_default_timezone_set(@date_default_timezone_get());
  4. #
  5. global $doctype, $title, $miner, $port, $readonly, $notify, $rigs;
  6. global $mcast, $mcastexpect, $mcastaddr, $mcastport, $mcastcode;
  7. global $mcastlistport, $mcasttimeout, $allowgen;
  8. global $rigipsecurity, $rigtotals, $forcerigtotals;
  9. global $socksndtimeoutsec, $sockrcvtimeoutsec;
  10. global $checklastshare, $poolinputs, $hidefields;
  11. global $ignorerefresh, $changerefresh, $autorefresh;
  12. global $allowcustompages, $customsummarypages;
  13. global $miner_font_family, $miner_font_size;
  14. global $bad_font_family, $bad_font_size;
  15. global $colouroverride, $placebuttons, $userlist;
  16. global $per_proc;
  17. #
  18. $doctype = "<!DOCTYPE html>\n";
  19. #
  20. # See README.RPC for more details of these variables and how
  21. # to configure miner.php
  22. #
  23. # Web page title
  24. $title = 'Mine';
  25. #
  26. # Set $readonly to true to force miner.php to be readonly
  27. # Set $readonly to false then it will check BFGMiner 'privileged'
  28. $readonly = false;
  29. #
  30. # Set $userlist to null to allow anyone access or read README.RPC
  31. $userlist = null;
  32. #
  33. # Set $per_proc to false to display only full device summaries
  34. $per_proc = true;
  35. #
  36. # Set $notify to false to NOT attempt to display the notify command
  37. # Set $notify to true to attempt to display the notify command
  38. $notify = true;
  39. #
  40. # Set $checklastshare to true to do the following checks:
  41. # If a device's last share is 12x expected ago then display as an error
  42. # If a device's last share is 8x expected ago then display as a warning
  43. # If either of the above is true, also display the whole line highlighted
  44. # This assumes shares are 1 difficulty shares
  45. $checklastshare = true;
  46. #
  47. # Set $poolinputs to true to show the input fields for adding a pool
  48. # and changing the pool priorities
  49. # N.B. also if $readonly is true, it will not display the fields
  50. $poolinputs = false;
  51. #
  52. # Set $rigs to an array of your BFGMiner rigs that are running
  53. # format: 'IP:Port' or 'Host:Port' or 'Host:Port:Name'
  54. $rigs = array('127.0.0.1:4028');
  55. #
  56. # Set $mcast to true to look for your rigs and ignore $rigs
  57. $mcast = false;
  58. #
  59. # Set $mcastexpect to at least how many rigs you expect it to find
  60. $mcastexpect = 0;
  61. #
  62. # API Multicast address all cgminers are listening on
  63. $mcastaddr = '224.0.0.75';
  64. #
  65. # API Multicast UDP port all cgminers are listening on
  66. $mcastport = 4028;
  67. #
  68. # The code all cgminers expect in the Multicast message sent
  69. $mcastcode = 'FTW';
  70. #
  71. # UDP port cgminers are to reply on (by request)
  72. $mcastlistport = 4027;
  73. #
  74. # Set $mcasttimeout to the number of seconds (floating point)
  75. # to wait for replies to the Multicast message
  76. $mcasttimeout = 1.5;
  77. #
  78. # Set $allowgen to true to allow customsummarypages to use 'gen'
  79. # false means ignore any 'gen' options
  80. $allowgen = false;
  81. #
  82. # Set $rigipsecurity to false to show the IP/Port of the rig
  83. # in the socket error messages and also show the full socket message
  84. $rigipsecurity = true;
  85. #
  86. # Set $rigtotals to true to display totals on the single rig page
  87. # 'false' means no totals (and ignores $forcerigtotals)
  88. # You can force it to always show rig totals when there is only
  89. # one line by setting $forcerigtotals = true;
  90. $rigtotals = true;
  91. $forcerigtotals = false;
  92. #
  93. # These should be OK for most cases
  94. $socksndtimeoutsec = 10;
  95. $sockrcvtimeoutsec = 40;
  96. #
  97. # List of fields NOT to be displayed
  98. # This example would hide the slightly more sensitive pool information
  99. #$hidefields = array('POOL.URL' => 1, 'POOL.User' => 1);
  100. $hidefields = array();
  101. #
  102. # Auto-refresh of the page (in seconds) - integers only
  103. # $ignorerefresh = true/false always ignore refresh parameters
  104. # $changerefresh = true/false show buttons to change the value
  105. # $autorefresh = default value, 0 means dont auto-refresh
  106. $ignorerefresh = false;
  107. $changerefresh = true;
  108. $autorefresh = 0;
  109. #
  110. # Should we allow custom pages?
  111. # (or just completely ignore them and don't display the buttons)
  112. $allowcustompages = true;
  113. #
  114. # OK this is a bit more complex item: Custom Summary Pages
  115. # As mentioned above, see README.RPC
  116. # see the example below (if there is no matching data, no total will show)
  117. $mobilepage = array(
  118. 'DATE' => null,
  119. 'RIGS' => null,
  120. 'SUMMARY' => array('Elapsed', 'MHS av', 'Found Blocks=Blks', 'Accepted', 'Rejected=Rej', 'Utility'),
  121. 'DEVS+NOTIFY' => array('DEVS.Name=Name', 'DEVS.ID=ID', 'DEVS.ProcID=Proc',
  122. 'DEVS.Status=Status', 'DEVS.Temperature=Temp',
  123. 'DEVS.MHS av=MHS av', 'DEVS.Accepted=Accept', 'DEVS.Rejected=Rej',
  124. 'DEVS.Utility=Utility', 'NOTIFY.Last Not Well=Not Well'),
  125. 'POOL' => array('POOL', 'Status', 'Accepted', 'Rejected=Rej', 'Last Share Time'));
  126. $mobilesum = array(
  127. 'SUMMARY' => array('MHS av', 'Found Blocks', 'Accepted', 'Rejected', 'Utility'),
  128. 'DEVS+NOTIFY' => array('DEVS.MHS av', 'DEVS.Accepted', 'DEVS.Rejected', 'DEVS.Utility'),
  129. 'POOL' => array('Accepted', 'Rejected'));
  130. #
  131. $statspage = array(
  132. 'DATE' => null,
  133. 'RIGS' => null,
  134. 'SUMMARY' => array('Elapsed', 'MHS av', 'Found Blocks=Blks',
  135. 'Accepted', 'Rejected=Rej', 'Utility',
  136. 'Hardware Errors=HW Errs', 'Network Blocks=Net Blks',
  137. 'Work Utility'),
  138. 'COIN' => array('*'),
  139. 'STATS' => array('*'));
  140. #
  141. $statssum = array(
  142. 'SUMMARY' => array('MHS av', 'Found Blocks', 'Accepted',
  143. 'Rejected', 'Utility', 'Hardware Errors',
  144. 'Work Utility'));
  145. #
  146. $poolspage = array(
  147. 'DATE' => null,
  148. 'RIGS' => null,
  149. 'SUMMARY' => array('Elapsed', 'MHS av', 'Found Blocks=Blks', 'Accepted', 'Rejected=Rej',
  150. 'Utility', 'Hardware Errors=HW Errs', 'Network Blocks=Net Blks'),
  151. 'POOL+STATS' => array('STATS.ID=ID', 'POOL.URL=URL',
  152. 'POOL.Has Stratum=Stratum', 'POOL.Stratum Active=StrAct',
  153. 'STATS.Net Bytes Sent=NSent',
  154. 'STATS.Net Bytes Recv=NRecv', 'GEN.AvShr=AvShr'));
  155. #
  156. $poolssum = array(
  157. 'SUMMARY' => array('MHS av', 'Found Blocks', 'Accepted',
  158. 'Rejected', 'Utility', 'Hardware Errors'),
  159. 'POOL+STATS' => array(
  160. 'STATS.Net Bytes Sent',
  161. 'STATS.Net Bytes Recv'));
  162. #
  163. $poolsext = array(
  164. 'POOL+STATS' => array(
  165. 'where' => null,
  166. 'group' => array('POOL.URL', 'POOL.Has Stratum', 'POOL.Stratum Active'),
  167. 'calc' => array(
  168. 'STATS.Net Bytes Sent' => 'sum',
  169. 'STATS.Net Bytes Recv' => 'sum',
  170. 'POOL.Accepted' => 'sum'),
  171. 'gen' => array('AvShr' => 'round(POOL.Difficulty Accepted/max(POOL.Accepted,1)*100)/100'),
  172. 'having' => array(array('STATS.Bytes Recv', '>', 0)))
  173. );
  174. #
  175. # customsummarypages is an array of these Custom Summary Pages
  176. $customsummarypages = array('Mobile' => array($mobilepage, $mobilesum),
  177. 'Stats' => array($statspage, $statssum),
  178. 'Pools' => array($poolspage, $poolssum, $poolsext));
  179. #
  180. $here = $_SERVER['PHP_SELF'];
  181. #
  182. global $tablebegin, $tableend, $warnfont, $warnoff, $dfmt;
  183. #
  184. $tablebegin = '<tr><td><table border=1 cellpadding=5 cellspacing=0>';
  185. $tableend = '</table></td></tr>';
  186. $warnfont = '<font color=red><b>';
  187. $warnoff = '</b></font>';
  188. $dfmt = 'H:i:s j-M-Y \U\T\CP';
  189. #
  190. $miner_font_family = 'Verdana, Arial, sans-serif, sans';
  191. $miner_font_size = '13pt';
  192. #
  193. $bad_font_family = '"Times New Roman", Times, serif';
  194. $bad_font_size = '18pt';
  195. #
  196. # Edit this or redefine it in myminer.php to change the colour scheme
  197. # See $colourtable below for the list of names
  198. $colouroverride = array();
  199. #
  200. # Where to place the buttons: 'top' 'bot' 'both'
  201. # anything else means don't show them - case sensitive
  202. $placebuttons = 'top';
  203. #
  204. # This below allows you to put your own settings into a seperate file
  205. # so you don't need to update miner.php with your preferred settings
  206. # every time a new version is released
  207. # Just create the file 'myminer.php' in the same directory as
  208. # 'miner.php' - and put your own settings in there
  209. if (file_exists('myminer.php'))
  210. include_once('myminer.php');
  211. #
  212. # This is the system default that must always contain all necessary
  213. # colours so it must be a constant
  214. # You can override these values with $colouroverride
  215. # The only one missing is $warnfont
  216. # - which you can override directly anyway
  217. global $colourtable;
  218. $colourtable = array(
  219. 'body bgcolor' => '#ecffff',
  220. 'td color' => 'blue',
  221. 'td.two color' => 'blue',
  222. 'td.two background' => '#ecffff',
  223. 'td.h color' => 'blue',
  224. 'td.h background' => '#c4ffff',
  225. 'td.err color' => 'black',
  226. 'td.err background' => '#ff3050',
  227. 'td.bad color' => 'black',
  228. 'td.bad background' => '#ff3050',
  229. 'td.warn color' => 'black',
  230. 'td.warn background' => '#ffb050',
  231. 'td.sta color' => 'green',
  232. 'td.tot color' => 'blue',
  233. 'td.tot background' => '#fff8f2',
  234. 'td.lst color' => 'blue',
  235. 'td.lst background' => '#ffffdd',
  236. 'td.hi color' => 'blue',
  237. 'td.hi background' => '#f6ffff',
  238. 'td.lo color' => 'blue',
  239. 'td.lo background' => '#deffff'
  240. );
  241. #
  242. # Don't touch these 2
  243. $miner = null;
  244. $port = null;
  245. #
  246. # Ensure it is only ever shown once
  247. global $showndate;
  248. $showndate = false;
  249. #
  250. # For summary page to stop retrying failed rigs
  251. global $rigerror;
  252. $rigerror = array();
  253. #
  254. global $rownum;
  255. $rownum = 0;
  256. #
  257. // Login
  258. global $ses;
  259. $ses = 'rutroh';
  260. #
  261. function getcss($cssname, $dom = false)
  262. {
  263. global $colourtable, $colouroverride;
  264. $css = '';
  265. foreach ($colourtable as $cssdata => $value)
  266. {
  267. $cssobj = explode(' ', $cssdata, 2);
  268. if ($cssobj[0] == $cssname)
  269. {
  270. if (isset($colouroverride[$cssdata]))
  271. $value = $colouroverride[$cssdata];
  272. if ($dom == true)
  273. $css .= ' '.$cssobj[1].'='.$value;
  274. else
  275. $css .= $cssobj[1].':'.$value.'; ';
  276. }
  277. }
  278. return $css;
  279. }
  280. #
  281. function getdom($domname)
  282. {
  283. return getcss($domname, true);
  284. }
  285. #
  286. function htmlhead($mcerr, $checkapi, $rig, $pg = null, $noscript = false)
  287. {
  288. global $doctype, $title, $miner_font_family, $miner_font_size;
  289. global $bad_font_family, $bad_font_size;
  290. global $error, $readonly, $poolinputs, $here;
  291. global $ignorerefresh, $autorefresh;
  292. $extraparams = '';
  293. if ($rig != null && $rig != '')
  294. $extraparams = "&rig=$rig";
  295. else
  296. if ($pg != null && $pg != '')
  297. $extraparams = "&pg=$pg";
  298. if ($ignorerefresh == true || $autorefresh == 0)
  299. $refreshmeta = '';
  300. else
  301. {
  302. $url = "$here?ref=$autorefresh$extraparams";
  303. $refreshmeta = "\n<meta http-equiv='refresh' content='$autorefresh;url=$url'>";
  304. }
  305. if ($readonly === false && $checkapi === true)
  306. {
  307. $error = null;
  308. $access = api($rig, 'privileged');
  309. if ($error != null
  310. || !isset($access['STATUS']['STATUS'])
  311. || $access['STATUS']['STATUS'] != 'S')
  312. $readonly = true;
  313. }
  314. $miner_font = "font-family:$miner_font_family; font-size:$miner_font_size;";
  315. $bad_font = "font-family:$bad_font_family; font-size:$bad_font_size;";
  316. echo "$doctype<html><head>$refreshmeta
  317. <title>$title</title>
  318. <style type='text/css'>
  319. td { $miner_font ".getcss('td')."}
  320. td.two { $miner_font ".getcss('td.two')."}
  321. td.h { $miner_font ".getcss('td.h')."}
  322. td.err { $miner_font ".getcss('td.err')."}
  323. td.bad { $bad_font ".getcss('td.bad')."}
  324. td.warn { $miner_font ".getcss('td.warn')."}
  325. td.sta { $miner_font ".getcss('td.sta')."}
  326. td.tot { $miner_font ".getcss('td.tot')."}
  327. td.lst { $miner_font ".getcss('td.lst')."}
  328. td.hi { $miner_font ".getcss('td.hi')."}
  329. td.lo { $miner_font ".getcss('td.lo')."}
  330. </style>
  331. </head><body".getdom('body').">\n";
  332. if ($noscript === false)
  333. {
  334. echo "<script type='text/javascript'>
  335. function pr(a,m){if(m!=null){if(!confirm(m+'?'))return}window.location='$here?ref=$autorefresh'+a}\n";
  336. if ($ignorerefresh == false)
  337. echo "function prr(a){if(a){v=document.getElementById('refval').value}else{v=0}window.location='$here?ref='+v+'$extraparams'}\n";
  338. if ($readonly === false && $checkapi === true)
  339. {
  340. echo "function prc(a,m){pr('&arg='+a,m)}
  341. 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)}
  342. 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";
  343. if ($poolinputs === true)
  344. 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";
  345. }
  346. echo "</script>\n";
  347. }
  348. ?>
  349. <table width=100% height=100% border=0 cellpadding=0 cellspacing=0 summary='Mine'>
  350. <tr><td align=center valign=top>
  351. <table border=0 cellpadding=4 cellspacing=0 summary='Mine'>
  352. <?php
  353. echo $mcerr;
  354. }
  355. #
  356. function minhead($mcerr = '')
  357. {
  358. global $readonly;
  359. $readonly = true;
  360. htmlhead($mcerr, false, null, null, true);
  361. }
  362. #
  363. global $haderror, $error;
  364. $haderror = false;
  365. $error = null;
  366. #
  367. function getrigs()
  368. {
  369. global $rigs, $mcastaddr, $mcastport, $mcastcode;
  370. global $mcastlistport, $mcasttimeout, $error;
  371. $listname = "0.0.0.0";
  372. $rigs = array();
  373. $rep_soc = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
  374. if ($rep_soc === false || $rep_soc == null)
  375. {
  376. $msg = "ERR: mcast listen socket create(UDP) failed";
  377. if ($rigipsecurity === false)
  378. {
  379. $error = socket_strerror(socket_last_error());
  380. $error = "$msg '$error'\n";
  381. }
  382. else
  383. $error = "$msg\n";
  384. return;
  385. }
  386. $res = socket_bind($rep_soc, $listname, $mcastlistport);
  387. if ($res === false)
  388. {
  389. $msg1 = "ERR: mcast listen socket bind(";
  390. $msg2 = ") failed";
  391. if ($rigipsecurity === false)
  392. {
  393. $error = socket_strerror(socket_last_error());
  394. $error = "$msg1$listname,$mcastlistport$msg2 '$error'\n";
  395. }
  396. else
  397. $error = "$msg1$msg2\n";
  398. socket_close($rep_soc);
  399. return;
  400. }
  401. $mcast_soc = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
  402. if ($mcast_soc === false || $mcast_soc == null)
  403. {
  404. $msg = "ERR: mcast send socket create(UDP) failed";
  405. if ($rigipsecurity === false)
  406. {
  407. $error = socket_strerror(socket_last_error());
  408. $error = "$msg '$error'\n";
  409. }
  410. else
  411. $error = "$msg\n";
  412. socket_close($rep_soc);
  413. return;
  414. }
  415. $buf = "cgminer-$mcastcode-$mcastlistport";
  416. socket_sendto($mcast_soc, $buf, strlen($buf), 0, $mcastaddr, $mcastport);
  417. socket_close($mcast_soc);
  418. $stt = microtime(true);
  419. while (true)
  420. {
  421. $got = @socket_recvfrom($rep_soc, $buf, 32, MSG_DONTWAIT, $ip, $p);
  422. if ($got !== false && $got > 0)
  423. {
  424. $ans = explode('-', $buf, 4);
  425. if (count($ans) >= 3 && $ans[0] == 'cgm' && $ans[1] == 'FTW')
  426. {
  427. $rp = intval($ans[2]);
  428. if (count($ans) > 3)
  429. $mdes = str_replace("\0", '', $ans[3]);
  430. else
  431. $mdes = '';
  432. if (strlen($mdes) > 0)
  433. $rigs[] = "$ip:$rp:$mdes";
  434. else
  435. $rigs[] = "$ip:$rp";
  436. }
  437. }
  438. if ((microtime(true) - $stt) >= $mcasttimeout)
  439. break;
  440. usleep(100000);
  441. }
  442. socket_close($rep_soc);
  443. }
  444. #
  445. function getsock($rig, $addr, $port)
  446. {
  447. global $rigipsecurity;
  448. global $haderror, $error, $socksndtimeoutsec, $sockrcvtimeoutsec;
  449. $error = null;
  450. $socket = null;
  451. $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  452. if ($socket === false || $socket === null)
  453. {
  454. $haderror = true;
  455. if ($rigipsecurity === false)
  456. {
  457. $error = socket_strerror(socket_last_error());
  458. $msg = "socket create(TCP) failed";
  459. $error = "ERR: $msg '$error'\n";
  460. }
  461. else
  462. $error = "ERR: socket create(TCP) failed\n";
  463. return null;
  464. }
  465. // Ignore if this fails since the socket connect may work anyway
  466. // and nothing is gained by aborting if the option cannot be set
  467. // since we don't know in advance if it can connect
  468. socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, array('sec' => $socksndtimeoutsec, 'usec' => 0));
  469. socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $sockrcvtimeoutsec, 'usec' => 0));
  470. $res = socket_connect($socket, $addr, $port);
  471. if ($res === false)
  472. {
  473. $haderror = true;
  474. if ($rigipsecurity === false)
  475. {
  476. $error = socket_strerror(socket_last_error());
  477. $msg = "socket connect($addr,$port) failed";
  478. $error = "ERR: $msg '$error'\n";
  479. }
  480. else
  481. $error = "ERR: socket connect($rig) failed\n";
  482. socket_close($socket);
  483. return null;
  484. }
  485. return $socket;
  486. }
  487. #
  488. function readsockline($socket)
  489. {
  490. $line = '';
  491. while (true)
  492. {
  493. $byte = socket_read($socket, 1);
  494. if ($byte === false || $byte === '')
  495. break;
  496. if ($byte === "\0")
  497. break;
  498. $line .= $byte;
  499. }
  500. return $line;
  501. }
  502. #
  503. function api_convert_escape($str)
  504. {
  505. $res = '';
  506. $len = strlen($str);
  507. for ($i = 0; $i < $len; $i++)
  508. {
  509. $ch = substr($str, $i, 1);
  510. if ($ch != '\\' || $i == ($len-1))
  511. $res .= $ch;
  512. else
  513. {
  514. $i++;
  515. $ch = substr($str, $i, 1);
  516. switch ($ch)
  517. {
  518. case '|':
  519. $res .= "\1";
  520. break;
  521. case '\\':
  522. $res .= "\2";
  523. break;
  524. case '=':
  525. $res .= "\3";
  526. break;
  527. case ',':
  528. $res .= "\4";
  529. break;
  530. default:
  531. $res .= $ch;
  532. }
  533. }
  534. }
  535. return $res;
  536. }
  537. #
  538. function revert($str)
  539. {
  540. return str_replace(array("\1", "\2", "\3", "\4"), array("|", "\\", "=", ","), $str);
  541. }
  542. #
  543. function api($rig, $cmd)
  544. {
  545. global $haderror, $error;
  546. global $miner, $port, $hidefields;
  547. global $per_proc;
  548. if ($per_proc)
  549. {
  550. $cmd = preg_replace('/^devs\b/', 'procs', $cmd);
  551. $cmd = preg_replace('/^pga/', 'proc', $cmd);
  552. }
  553. $socket = getsock($rig, $miner, $port);
  554. if ($socket != null)
  555. {
  556. socket_write($socket, $cmd, strlen($cmd));
  557. $line = readsockline($socket);
  558. socket_close($socket);
  559. if (strlen($line) == 0)
  560. {
  561. $haderror = true;
  562. $error = "WARN: '$cmd' returned nothing\n";
  563. return $line;
  564. }
  565. # print "$cmd returned '$line'\n";
  566. $line = api_convert_escape($line);
  567. $data = array();
  568. $objs = explode('|', $line);
  569. foreach ($objs as $obj)
  570. {
  571. if (strlen($obj) > 0)
  572. {
  573. $items = explode(',', $obj);
  574. $item = $items[0];
  575. $id = explode('=', $items[0], 2);
  576. if (count($id) == 1 or !ctype_digit($id[1]))
  577. $name = $id[0];
  578. else
  579. $name = $id[0].$id[1];
  580. if (strlen($name) == 0)
  581. $name = 'null';
  582. $sectionname = preg_replace('/\d/', '', $name);
  583. if (isset($data[$name]))
  584. {
  585. $num = 1;
  586. while (isset($data[$name.$num]))
  587. $num++;
  588. $name .= $num;
  589. }
  590. $counter = 0;
  591. foreach ($items as $item)
  592. {
  593. $id = explode('=', $item, 2);
  594. if (isset($hidefields[$sectionname.'.'.$id[0]]))
  595. continue;
  596. if (count($id) == 2)
  597. $data[$name][$id[0]] = revert($id[1]);
  598. else
  599. $data[$name][$counter] = $id[0];
  600. $counter++;
  601. }
  602. }
  603. }
  604. return $data;
  605. }
  606. return null;
  607. }
  608. #
  609. function getparam($name, $both = false)
  610. {
  611. $a = null;
  612. if (isset($_POST[$name]))
  613. $a = $_POST[$name];
  614. if (($both === true) and ($a === null))
  615. {
  616. if (isset($_GET[$name]))
  617. $a = $_GET[$name];
  618. }
  619. if ($a == '' || $a == null)
  620. return null;
  621. // limit to 1K just to be safe
  622. return substr($a, 0, 1024);
  623. }
  624. #
  625. function newtable()
  626. {
  627. global $tablebegin, $rownum;
  628. echo $tablebegin;
  629. $rownum = 0;
  630. }
  631. #
  632. function newrow()
  633. {
  634. echo '<tr>';
  635. }
  636. #
  637. function othrow($row)
  638. {
  639. return "<tr>$row</tr>";
  640. }
  641. #
  642. function otherrow($row)
  643. {
  644. echo othrow($row);
  645. }
  646. #
  647. function endrow()
  648. {
  649. global $rownum;
  650. echo '</tr>';
  651. $rownum++;
  652. }
  653. #
  654. function endtable()
  655. {
  656. global $tableend;
  657. echo $tableend;
  658. }
  659. #
  660. function classlastshare($when, $alldata, $warnclass, $errorclass)
  661. {
  662. global $checklastshare;
  663. if ($checklastshare === false)
  664. return '';
  665. if ($when == 0)
  666. return '';
  667. if (!isset($alldata['MHS av']))
  668. return '';
  669. if ($alldata['MHS av'] == 0)
  670. return '';
  671. if (!isset($alldata['Last Share Time']))
  672. return '';
  673. if (!isset($alldata['Last Share Difficulty']))
  674. return '';
  675. $expected = pow(2, 32) / ($alldata['MHS av'] * pow(10, 6));
  676. // If the share difficulty changes while waiting on a share,
  677. // this calculation will of course be incorrect
  678. $expected *= $alldata['Last Share Difficulty'];
  679. $howlong = $when - $alldata['Last Share Time'];
  680. if ($howlong < 1)
  681. $howlong = 1;
  682. if ($howlong > ($expected * 12))
  683. return $errorclass;
  684. if ($howlong > ($expected * 8))
  685. return $warnclass;
  686. return '';
  687. }
  688. #
  689. function endzero($num)
  690. {
  691. $rep = preg_replace('/0*$/', '', $num);
  692. if ($rep === '')
  693. $rep = '0';
  694. return $rep;
  695. }
  696. #
  697. function fmt($section, $name, $value, $when, $alldata)
  698. {
  699. global $dfmt, $rownum;
  700. if ($alldata == null)
  701. $alldata = array();
  702. $errorclass = ' class=err';
  703. $warnclass = ' class=warn';
  704. $lstclass = ' class=lst';
  705. $hiclass = ' class=hi';
  706. $loclass = ' class=lo';
  707. $c2class = ' class=two';
  708. $totclass = ' class=tot';
  709. $b = '&nbsp;';
  710. $ret = $value;
  711. $class = '';
  712. $nams = explode('.', $name);
  713. if (count($nams) > 1)
  714. $name = $nams[count($nams)-1];
  715. if ($value === null)
  716. $ret = $b;
  717. else
  718. switch ($section.'.'.$name)
  719. {
  720. case 'GPU.Last Share Time':
  721. case 'PGA.Last Share Time':
  722. case 'DEVS.Last Share Time':
  723. if ($value == 0
  724. || (isset($alldata['Last Share Pool']) && $alldata['Last Share Pool'] == -1))
  725. {
  726. $ret = 'Never';
  727. $class = $warnclass;
  728. }
  729. else
  730. {
  731. $ret = date('H:i:s', $value);
  732. $class = classlastshare($when, $alldata, $warnclass, $errorclass);
  733. }
  734. break;
  735. case 'GPU.Last Valid Work':
  736. case 'PGA.Last Valid Work':
  737. case 'DEVS.Last Valid Work':
  738. if ($value == 0)
  739. $ret = 'Never';
  740. else
  741. $ret = ($value - $when) . 's';
  742. break;
  743. case 'POOL.Last Share Time':
  744. if ($value == 0)
  745. $ret = 'Never';
  746. else
  747. $ret = date('H:i:s d-M', $value);
  748. break;
  749. case 'GPU.Last Share Pool':
  750. case 'PGA.Last Share Pool':
  751. case 'DEVS.Last Share Pool':
  752. if ($value == -1)
  753. {
  754. $ret = 'None';
  755. $class = $warnclass;
  756. }
  757. break;
  758. case 'SUMMARY.Elapsed':
  759. case 'STATS.Elapsed':
  760. $s = $value % 60;
  761. $value -= $s;
  762. $value /= 60;
  763. if ($value == 0)
  764. $ret = $s.'s';
  765. else
  766. {
  767. $m = $value % 60;
  768. $value -= $m;
  769. $value /= 60;
  770. if ($value == 0)
  771. $ret = sprintf("%dm$b%02ds", $m, $s);
  772. else
  773. {
  774. $h = $value % 24;
  775. $value -= $h;
  776. $value /= 24;
  777. if ($value == 0)
  778. $ret = sprintf("%dh$b%02dm$b%02ds", $h, $m, $s);
  779. else
  780. {
  781. if ($value == 1)
  782. $days = '';
  783. else
  784. $days = 's';
  785. $ret = sprintf("%dday$days$b%02dh$b%02dm$b%02ds", $value, $h, $m, $s);
  786. }
  787. }
  788. }
  789. break;
  790. case 'NOTIFY.Last Well':
  791. if ($value == '0')
  792. {
  793. $ret = 'Never';
  794. $class = $warnclass;
  795. }
  796. else
  797. $ret = date('H:i:s', $value);
  798. break;
  799. case 'NOTIFY.Last Not Well':
  800. if ($value == '0')
  801. $ret = 'Never';
  802. else
  803. {
  804. $ret = date('H:i:s', $value);
  805. $class = $errorclass;
  806. }
  807. break;
  808. case 'NOTIFY.Reason Not Well':
  809. if ($value != 'None')
  810. $class = $errorclass;
  811. break;
  812. case 'GPU.Utility':
  813. case 'PGA.Utility':
  814. case 'DEVS.Utility':
  815. case 'SUMMARY.Utility':
  816. case 'total.Utility':
  817. $ret = $value.'/m';
  818. if ($value == 0)
  819. $class = $errorclass;
  820. else
  821. if (isset($alldata['Difficulty Accepted'])
  822. && isset($alldata['Accepted'])
  823. && isset($alldata['MHS av'])
  824. && ($alldata['Difficulty Accepted'] > 0)
  825. && ($alldata['Accepted'] > 0))
  826. {
  827. $expected = 60 * $alldata['MHS av'] * (pow(10, 6) / pow(2, 32));
  828. if ($expected == 0)
  829. $expected = 0.000001; // 1 H/s
  830. $da = $alldata['Difficulty Accepted'];
  831. $a = $alldata['Accepted'];
  832. $expected /= ($da / $a);
  833. $ratio = $value / $expected;
  834. if ($ratio < 0.9)
  835. $class = $loclass;
  836. else
  837. if ($ratio > 1.1)
  838. $class = $hiclass;
  839. }
  840. break;
  841. case 'PGA.Temperature':
  842. case 'GPU.Temperature':
  843. case 'DEVS.Temperature':
  844. $ret = $value.'&deg;C';
  845. if (!isset($alldata['GPU']))
  846. {
  847. if ($value == 0)
  848. $ret = '&nbsp;';
  849. break;
  850. }
  851. case 'GPU.GPU Clock':
  852. case 'DEVS.GPU Clock':
  853. case 'GPU.Memory Clock':
  854. case 'DEVS.Memory Clock':
  855. case 'GPU.GPU Voltage':
  856. case 'DEVS.GPU Voltage':
  857. case 'GPU.GPU Activity':
  858. case 'DEVS.GPU Activity':
  859. if ($value == 0)
  860. $class = $warnclass;
  861. break;
  862. case 'GPU.Fan Percent':
  863. case 'DEVS.Fan Percent':
  864. if ($value == 0)
  865. $class = $warnclass;
  866. else
  867. {
  868. if ($value == 100)
  869. $class = $errorclass;
  870. else
  871. if ($value > 85)
  872. $class = $warnclass;
  873. }
  874. break;
  875. case 'GPU.Fan Speed':
  876. case 'DEVS.Fan Speed':
  877. if ($value == 0)
  878. $class = $warnclass;
  879. else
  880. if (isset($alldata['Fan Percent']))
  881. {
  882. $test = $alldata['Fan Percent'];
  883. if ($test == 100)
  884. $class = $errorclass;
  885. else
  886. if ($test > 85)
  887. $class = $warnclass;
  888. }
  889. break;
  890. case 'GPU.MHS av':
  891. case 'PGA.MHS av':
  892. case 'DEVS.MHS av':
  893. case 'SUMMARY.MHS av':
  894. case 'total.MHS av':
  895. $parts = explode('.', $value, 2);
  896. if (count($parts) == 1)
  897. $dec = '';
  898. else
  899. $dec = '.'.$parts[1];
  900. $ret = number_format((float)$parts[0]).$dec;
  901. if ($value == 0)
  902. $class = $errorclass;
  903. else
  904. if (isset($alldata['Difficulty Accepted'])
  905. && isset($alldata['Accepted'])
  906. && isset($alldata['Utility'])
  907. && ($alldata['Difficulty Accepted'] > 0)
  908. && ($alldata['Accepted'] > 0))
  909. {
  910. $expected = 60 * $value * (pow(10, 6) / pow(2, 32));
  911. if ($expected == 0)
  912. $expected = 0.000001; // 1 H/s
  913. $da = $alldata['Difficulty Accepted'];
  914. $a = $alldata['Accepted'];
  915. $expected /= ($da / $a);
  916. $ratio = $alldata['Utility'] / $expected;
  917. if ($ratio < 0.9)
  918. $class = $hiclass;
  919. else
  920. if ($ratio > 1.1)
  921. $class = $loclass;
  922. }
  923. break;
  924. case 'GPU.Total MH':
  925. case 'PGA.Total MH':
  926. case 'DEVS.Total MH':
  927. case 'SUMMARY.Total MH':
  928. case 'total.Total MH':
  929. case 'SUMMARY.Getworks':
  930. case 'POOL.Getworks':
  931. case 'total.Getworks':
  932. case 'GPU.Accepted':
  933. case 'PGA.Accepted':
  934. case 'DEVS.Accepted':
  935. case 'SUMMARY.Accepted':
  936. case 'POOL.Accepted':
  937. case 'total.Accepted':
  938. case 'GPU.Rejected':
  939. case 'PGA.Rejected':
  940. case 'DEVS.Rejected':
  941. case 'SUMMARY.Rejected':
  942. case 'POOL.Rejected':
  943. case 'total.Rejected':
  944. case 'SUMMARY.Local Work':
  945. case 'total.Local Work':
  946. case 'SUMMARY.Discarded':
  947. case 'POOL.Discarded':
  948. case 'total.Discarded':
  949. case 'POOL.Diff1 Shares':
  950. case 'total.Diff1 Shares':
  951. case 'GPU.Diff1 Work':
  952. case 'PGA.Diff1 Work':
  953. case 'total.Diff1 Work':
  954. case 'STATS.Times Sent':
  955. case 'STATS.Bytes Sent':
  956. case 'STATS.Net Bytes Sent':
  957. case 'STATS.Times Recv':
  958. case 'STATS.Bytes Recv':
  959. case 'STATS.Net Bytes Recv':
  960. case 'total.Times Sent':
  961. case 'total.Bytes Sent':
  962. case 'total.Net Bytes Sent':
  963. case 'total.Times Recv':
  964. case 'total.Bytes Recv':
  965. case 'total.Net Bytes Recv':
  966. $parts = explode('.', $value, 2);
  967. if (count($parts) == 1)
  968. $dec = '';
  969. else
  970. $dec = '.'.$parts[1];
  971. $ret = number_format((float)$parts[0]).$dec;
  972. break;
  973. case 'STATS.Hs':
  974. case 'STATS.W':
  975. case 'STATS.history_time':
  976. case 'STATS.Pool Wait':
  977. case 'STATS.Pool Max':
  978. case 'STATS.Pool Min':
  979. case 'STATS.Pool Av':
  980. case 'STATS.Min Diff':
  981. case 'STATS.Max Diff':
  982. case 'STATS.Work Diff':
  983. $parts = explode('.', $value, 2);
  984. if (count($parts) == 1)
  985. $dec = '';
  986. else
  987. $dec = '.'.endzero($parts[1]);
  988. $ret = number_format((float)$parts[0]).$dec;
  989. break;
  990. case 'GPU.Status':
  991. case 'PGA.Status':
  992. case 'DEVS.Status':
  993. case 'POOL.Status':
  994. if ($value != 'Alive')
  995. $class = $errorclass;
  996. break;
  997. case 'GPU.Enabled':
  998. case 'PGA.Enabled':
  999. case 'DEVS.Enabled':
  1000. if ($value != 'Y')
  1001. $class = $warnclass;
  1002. break;
  1003. case 'STATUS.When':
  1004. case 'COIN.Current Block Time':
  1005. $ret = date($dfmt, $value);
  1006. break;
  1007. case 'BUTTON.Rig':
  1008. case 'BUTTON.Pool':
  1009. case 'BUTTON.GPU':
  1010. $ret = $value;
  1011. break;
  1012. case 'SUMMARY.Difficulty Accepted':
  1013. case 'GPU.Difficulty Accepted':
  1014. case 'PGA.Difficulty Accepted':
  1015. case 'DEVS.Difficulty Accepted':
  1016. case 'POOL.Difficulty Accepted':
  1017. case 'total.Difficulty Accepted':
  1018. case 'SUMMARY.Difficulty Rejected':
  1019. case 'GPU.Difficulty Rejected':
  1020. case 'PGA.Difficulty Rejected':
  1021. case 'DEVS.Difficulty Rejected':
  1022. case 'POOL.Difficulty Rejected':
  1023. case 'total.Difficulty Rejected':
  1024. case 'SUMMARY.Difficulty Stale':
  1025. case 'POOL.Difficulty Stale':
  1026. case 'total.Difficulty Stale':
  1027. case 'GPU.Last Share Difficulty':
  1028. case 'PGA.Last Share Difficulty':
  1029. case 'DEVS.Last Share Difficulty':
  1030. case 'POOL.Last Share Difficulty':
  1031. if ($value != '')
  1032. $ret = number_format((float)$value, 2);
  1033. break;
  1034. case 'DEVS.Device Hardware%':
  1035. case 'DEVS.Device Rejected%':
  1036. case 'PGA.Device Hardware%':
  1037. case 'PGA.Device Rejected%':
  1038. case 'GPU.Device Hardware%':
  1039. case 'GPU.Device Rejected%':
  1040. case 'POOL.Pool Rejected%':
  1041. case 'POOL.Pool Stale%':
  1042. case 'SUMMARY.Device Hardware%':
  1043. case 'SUMMARY.Device Rejected%':
  1044. case 'SUMMARY.Pool Rejected%':
  1045. case 'SUMMARY.Pool Stale%':
  1046. if ($value != '')
  1047. $ret = number_format((float)$value, 2) . '%';
  1048. break;
  1049. case 'SUMMARY.Best Share':
  1050. if ($value != '')
  1051. $ret = number_format((float)$value);
  1052. break;
  1053. }
  1054. if ($section == 'NOTIFY' && substr($name, 0, 1) == '*' && $value != '0')
  1055. $class = $errorclass;
  1056. if ($class == '' && $section != 'POOL')
  1057. $class = classlastshare($when, $alldata, $lstclass, $lstclass);
  1058. if ($class == '' && $section == 'total')
  1059. $class = $totclass;
  1060. if ($class == '' && ($rownum % 2) == 0)
  1061. $class = $c2class;
  1062. if ($ret === '')
  1063. $ret = $b;
  1064. return array($ret, $class);
  1065. }
  1066. #
  1067. global $poolcmd;
  1068. $poolcmd = array( 'Switch to' => 'switchpool',
  1069. 'Enable' => 'enablepool',
  1070. 'Disable' => 'disablepool',
  1071. 'Remove' => 'removepool' );
  1072. #
  1073. function showhead($cmd, $values, $justnames = false)
  1074. {
  1075. global $poolcmd, $readonly;
  1076. newrow();
  1077. foreach ($values as $name => $value)
  1078. {
  1079. if ($name == '0' or $name == '')
  1080. $name = '&nbsp;';
  1081. echo "<td valign=bottom class=h>$name</td>";
  1082. }
  1083. if ($justnames === false && $cmd == 'pools' && $readonly === false)
  1084. foreach ($poolcmd as $name => $pcmd)
  1085. echo "<td valign=bottom class=h>$name</td>";
  1086. endrow();
  1087. }
  1088. #
  1089. function showdatetime()
  1090. {
  1091. global $dfmt;
  1092. otherrow('<td class=sta>Date: '.date($dfmt).'</td>');
  1093. }
  1094. #
  1095. global $singlerigsum;
  1096. $singlerigsum = array(
  1097. 'devs' => array('MHS av' => 1, 'MHS 5s' => 1, 'Accepted' => 1, 'Rejected' => 1,
  1098. 'Temperature' => 2,
  1099. 'Hardware Errors' => 1, 'Utility' => 1, 'Total MH' => 1),
  1100. 'pools' => array('Getworks' => 1, 'Accepted' => 1, 'Rejected' => 1, 'Discarded' => 1,
  1101. 'Stale' => 1, 'Get Failures' => 1, 'Remote Failures' => 1),
  1102. 'notify' => array('*' => 1));
  1103. #
  1104. function showtotal($total, $when, $oldvalues)
  1105. {
  1106. global $rigtotals;
  1107. list($showvalue, $class) = fmt('total', '', 'Total:', $when, null);
  1108. echo "<td$class align=right>$showvalue</td>";
  1109. $skipfirst = true;
  1110. foreach ($oldvalues as $name => $value)
  1111. {
  1112. if ($skipfirst === true)
  1113. {
  1114. $skipfirst = false;
  1115. continue;
  1116. }
  1117. if (isset($total[$name]))
  1118. $newvalue = $total[$name];
  1119. else
  1120. $newvalue = '';
  1121. list($showvalue, $class) = fmt('total', $name, $newvalue, $when, null);
  1122. echo "<td$class";
  1123. if ($rigtotals === true)
  1124. echo ' align=right';
  1125. echo ">$showvalue</td>";
  1126. }
  1127. }
  1128. #
  1129. function details($cmd, $list, $rig)
  1130. {
  1131. global $dfmt, $poolcmd, $readonly, $showndate;
  1132. global $rownum, $rigtotals, $forcerigtotals, $singlerigsum;
  1133. $when = 0;
  1134. $stas = array('S' => 'Success', 'W' => 'Warning', 'I' => 'Informational', 'E' => 'Error', 'F' => 'Fatal');
  1135. newtable();
  1136. if ($showndate === false)
  1137. {
  1138. showdatetime();
  1139. endtable();
  1140. newtable();
  1141. $showndate = true;
  1142. }
  1143. if (isset($list['STATUS']))
  1144. {
  1145. newrow();
  1146. echo '<td>Computer: '.$list['STATUS']['Description'].'</td>';
  1147. if (isset($list['STATUS']['When']))
  1148. {
  1149. echo '<td>When: '.date($dfmt, $list['STATUS']['When']).'</td>';
  1150. $when = $list['STATUS']['When'];
  1151. }
  1152. $sta = $list['STATUS']['STATUS'];
  1153. echo '<td>Status: '.$stas[$sta].'</td>';
  1154. echo '<td>Message: '.$list['STATUS']['Msg'].'</td>';
  1155. endrow();
  1156. }
  1157. if ($rigtotals === true && isset($singlerigsum[$cmd]))
  1158. $dototal = $singlerigsum[$cmd];
  1159. else
  1160. $dototal = array();
  1161. $total = array();
  1162. $section = '';
  1163. $oldvalues = null;
  1164. // Build a common row column for all entries
  1165. $columns = array();
  1166. $columnsByIndex = array();
  1167. foreach ($list as $item => $values)
  1168. {
  1169. if ($item == 'STATUS')
  1170. continue;
  1171. if (isset($values['ID']))
  1172. {
  1173. $repr = $values['Name'].$values['ID'];
  1174. if (isset($values['ProcID']))
  1175. $repr .= join_get_field('ProcID', $values);
  1176. $list[$item] = $values = array('Device' => $repr) + array_slice($values, 1);
  1177. unset($values['Name']);
  1178. unset($values['ID']);
  1179. unset($values['ProcID']);
  1180. }
  1181. $namesByIndex = array_keys($values);
  1182. $nameCount = count($namesByIndex);
  1183. for ($i = 0; $i < $nameCount; ++$i)
  1184. {
  1185. $name = $namesByIndex[$i];
  1186. if (isset($columns[$name]))
  1187. continue;
  1188. $value = $values[$name];
  1189. $before = null;
  1190. for ($j = $i + 1; $j < $nameCount; ++$j)
  1191. {
  1192. $maybebefore = $namesByIndex[$j];
  1193. if (isset($columns[$maybebefore]))
  1194. {
  1195. $before = $columns[$maybebefore];
  1196. break;
  1197. }
  1198. }
  1199. if (!$before)
  1200. {
  1201. $columns[$name] = array_push($columnsByIndex, $name) - 1;
  1202. continue;
  1203. }
  1204. array_splice($columnsByIndex, $before, 0, $name);
  1205. $columns[$name] = $before;
  1206. $columnCount = count($columnsByIndex);
  1207. for ($j = $before + 1; $j < $columnCount; ++$j)
  1208. $columns[$columnsByIndex[$j]] = $j;
  1209. }
  1210. }
  1211. asort($columns);
  1212. endtable();
  1213. newtable();
  1214. showhead($cmd, $columns);
  1215. foreach ($list as $item => $values)
  1216. {
  1217. if ($item == 'STATUS')
  1218. continue;
  1219. newrow();
  1220. foreach ($columns as $name => $columnidx)
  1221. {
  1222. if (!isset($values[$name]))
  1223. {
  1224. echo '<td></td>';
  1225. continue;
  1226. }
  1227. $value = $values[$name];
  1228. list($showvalue, $class) = fmt($section, $name, $value, $when, $values);
  1229. echo "<td$class";
  1230. if ($rigtotals === true)
  1231. echo ' align=right';
  1232. echo ">$showvalue</td>";
  1233. if (isset($dototal[$name])
  1234. || (isset($dototal['*']) and substr($name, 0, 1) == '*'))
  1235. {
  1236. if (isset($total[$name]))
  1237. {
  1238. if (isset($dototal[$name]) && $dototal[$name] == 2)
  1239. $total[$name] = max($total[$name], $value);
  1240. else
  1241. $total[$name] += $value;
  1242. }
  1243. else
  1244. $total[$name] = $value;
  1245. }
  1246. }
  1247. if ($cmd == 'pools' && $readonly === false)
  1248. {
  1249. reset($values);
  1250. $pool = current($values);
  1251. foreach ($poolcmd as $name => $pcmd)
  1252. {
  1253. list($ignore, $class) = fmt('BUTTON', 'Pool', '', $when, $values);
  1254. echo "<td$class>";
  1255. if ($pool === false)
  1256. echo '&nbsp;';
  1257. else
  1258. {
  1259. echo "<input type=button value='Pool $pool'";
  1260. echo " onclick='prc(\"$pcmd|$pool&rig=$rig\",\"$name Pool $pool\")'>";
  1261. }
  1262. echo '</td>';
  1263. }
  1264. }
  1265. endrow();
  1266. $oldvalues = $values;
  1267. }
  1268. if ($oldvalues != null && count($total) > 0
  1269. && ($rownum > 2 || $forcerigtotals === true))
  1270. showtotal($total, $when, $columns);
  1271. endtable();
  1272. }
  1273. #
  1274. global $devs;
  1275. $devs = null;
  1276. #
  1277. function gpubuttons($count, $rig)
  1278. {
  1279. global $devs;
  1280. $basic = array( 'GPU', 'Enable', 'Disable', 'Restart' );
  1281. $options = array( 'intensity' => 'Intensity',
  1282. 'fan' => 'Fan Percent',
  1283. 'engine' => 'GPU Clock',
  1284. 'mem' => 'Memory Clock',
  1285. 'vddc' => 'GPU Voltage' );
  1286. newtable();
  1287. newrow();
  1288. foreach ($basic as $head)
  1289. echo "<td class=h>$head</td>";
  1290. foreach ($options as $name => $des)
  1291. echo "<td class=h nowrap>$des</td>";
  1292. $n = 0;
  1293. for ($c = 0; $c < $count; $c++)
  1294. {
  1295. endrow();
  1296. newrow();
  1297. foreach ($basic as $name)
  1298. {
  1299. list($ignore, $class) = fmt('BUTTON', 'GPU', '', 0, null);
  1300. echo "<td$class>";
  1301. if ($name == 'GPU')
  1302. echo $c;
  1303. else
  1304. {
  1305. echo "<input type=button value='$name $c' onclick='prs(\"gpu";
  1306. echo strtolower($name);
  1307. echo "|$c\",$rig)'>";
  1308. }
  1309. echo '</td>';
  1310. }
  1311. foreach ($options as $name => $des)
  1312. {
  1313. list($ignore, $class) = fmt('BUTTON', 'GPU', '', 0, null);
  1314. echo "<td$class>";
  1315. if (!isset($devs["GPU$c"][$des]))
  1316. echo '&nbsp;';
  1317. else
  1318. {
  1319. $value = $devs["GPU$c"][$des];
  1320. echo "<input type=button value='Set $c:' onclick='prs2(\"gpu$name|$c\",$n,$rig)'>";
  1321. echo "<input size=7 type=text name=gi$n value='$value' id=gi$n>";
  1322. $n++;
  1323. }
  1324. echo '</td>';
  1325. }
  1326. }
  1327. endrow();
  1328. endtable();
  1329. }
  1330. #
  1331. function processgpus($rig)
  1332. {
  1333. global $error;
  1334. global $warnfont, $warnoff;
  1335. $gpus = api($rig, 'gpucount');
  1336. if ($error != null)
  1337. otherrow("<td>Error getting GPU count: $warnfont$error$warnoff</td>");
  1338. else
  1339. {
  1340. if (!isset($gpus['GPUS']['Count']))
  1341. {
  1342. $rw = '<td>No GPU count returned: '.$warnfont;
  1343. $rw .= $gpus['STATUS']['STATUS'].' '.$gpus['STATUS']['Msg'];
  1344. $rw .= $warnoff.'</td>';
  1345. otherrow($rw);
  1346. }
  1347. else
  1348. {
  1349. $count = $gpus['GPUS']['Count'];
  1350. if ($count == 0)
  1351. otherrow('<td>No GPUs</td>');
  1352. else
  1353. gpubuttons($count, $rig);
  1354. }
  1355. }
  1356. }
  1357. #
  1358. function showpoolinputs($rig, $ans)
  1359. {
  1360. global $readonly, $poolinputs;
  1361. if ($readonly === true || $poolinputs === false)
  1362. return;
  1363. newtable();
  1364. newrow();
  1365. $inps = array('Pool URL' => array('purl', 20),
  1366. 'Worker Name' => array('pwork', 10),
  1367. 'Worker Password' => array('ppass', 10));
  1368. $b = '&nbsp;';
  1369. echo "<td align=right class=h> Add a pool: </td><td>";
  1370. foreach ($inps as $text => $name)
  1371. echo "$text: <input name='".$name[0]."' id='".$name[0]."' value='' type=text size=".$name[1]."> ";
  1372. echo "</td><td align=middle><input type=button value='Add' onclick='pla($rig)'></td>";
  1373. endrow();
  1374. if (count($ans) > 1)
  1375. {
  1376. newrow();
  1377. echo '<td align=right class=h> Set pool priorities: </td>';
  1378. echo "<td> Comma list of pool numbers: <input type=text name=prio id=prio size=20>";
  1379. echo "</td><td align=middle><input type=button value='Set' onclick='psp($rig)'></td>";
  1380. endrow();
  1381. }
  1382. endtable();
  1383. }
  1384. #
  1385. function process($cmds, $rig)
  1386. {
  1387. global $error, $devs;
  1388. global $warnfont, $warnoff;
  1389. $count = count($cmds);
  1390. foreach ($cmds as $cmd => $des)
  1391. {
  1392. $process = api($rig, $cmd);
  1393. if ($error != null)
  1394. {
  1395. otherrow("<td colspan=100>Error getting $des: $warnfont$error$warnoff</td>");
  1396. break;
  1397. }
  1398. else
  1399. {
  1400. details($cmd, $process, $rig);
  1401. if ($cmd == 'devs')
  1402. $devs = $process;
  1403. if ($cmd == 'pools')
  1404. showpoolinputs($rig, $process);
  1405. # Not after the last one
  1406. if (--$count > 0)
  1407. otherrow('<td><br><br></td>');
  1408. }
  1409. }
  1410. }
  1411. #
  1412. function rigname($rig, $rigname)
  1413. {
  1414. global $rigs;
  1415. if (isset($rigs[$rig]))
  1416. {
  1417. $parts = explode(':', $rigs[$rig], 3);
  1418. if (count($parts) == 3)
  1419. $rigname = $parts[2];
  1420. }
  1421. return $rigname;
  1422. }
  1423. #
  1424. function riginput($rig, $rigname)
  1425. {
  1426. $rigname = rigname($rig, $rigname);
  1427. return "<input type=button value='$rigname' onclick='pr(\"&rig=$rig\",null)'>";
  1428. }
  1429. #
  1430. function rigbutton($rig, $rigname, $when, $row)
  1431. {
  1432. list($value, $class) = fmt('BUTTON', 'Rig', '', $when, $row);
  1433. if ($rig === '')
  1434. $ri = '&nbsp;';
  1435. else
  1436. $ri = riginput($rig, $rigname);
  1437. return "<td align=middle$class>$ri</td>";
  1438. }
  1439. #
  1440. function showrigs($anss, $headname, $rigname)
  1441. {
  1442. $dthead = array($headname => 1, 'STATUS' => 1, 'Description' => 1, 'When' => 1, 'API' => 1, 'CGMiner' => 1);
  1443. showhead('', $dthead);
  1444. foreach ($anss as $rig => $ans)
  1445. {
  1446. if ($ans == null)
  1447. continue;
  1448. newrow();
  1449. $when = 0;
  1450. if (isset($ans['STATUS']['When']))
  1451. $when = $ans['STATUS']['When'];
  1452. foreach ($ans as $item => $row)
  1453. {
  1454. if ($item != 'STATUS' && $item != 'VERSION')
  1455. continue;
  1456. foreach ($dthead as $name => $x)
  1457. {
  1458. if ($item == 'STATUS' && $name == $headname)
  1459. echo rigbutton($rig, $rigname.$rig, $when, null);
  1460. else
  1461. {
  1462. if (isset($row[$name]))
  1463. {
  1464. list($showvalue, $class) = fmt('STATUS', $name, $row[$name], $when, null);
  1465. echo "<td$class align=right>$showvalue</td>";
  1466. }
  1467. }
  1468. }
  1469. }
  1470. endrow();
  1471. }
  1472. }
  1473. #
  1474. # $head is a hack but this is just a demo anyway :)
  1475. function doforeach($cmd, $des, $sum, $head, $datetime)
  1476. {
  1477. global $miner, $port;
  1478. global $error, $readonly, $notify, $rigs;
  1479. global $warnfont, $warnoff, $dfmt;
  1480. global $rigerror;
  1481. $when = 0;
  1482. $header = $head;
  1483. $anss = array();
  1484. $count = 0;
  1485. $preverr = count($rigerror);
  1486. foreach ($rigs as $num => $rig)
  1487. {
  1488. $anss[$num] = null;
  1489. if (isset($rigerror[$rig]))
  1490. continue;
  1491. $parts = explode(':', $rig, 3);
  1492. if (count($parts) >= 2)
  1493. {
  1494. $miner = $parts[0];
  1495. $port = $parts[1];
  1496. if (count($parts) > 2)
  1497. $name = $parts[2];
  1498. else
  1499. $name = $num;
  1500. $ans = api($name, $cmd);
  1501. if ($error != null)
  1502. {
  1503. $rw = "<td colspan=100>Error on rig $name getting ";
  1504. $rw .= "$des: $warnfont$error$warnoff</td>";
  1505. otherrow($rw);
  1506. $rigerror[$rig] = $error;
  1507. $error = null;
  1508. }
  1509. else
  1510. {
  1511. $anss[$num] = $ans;
  1512. $count++;
  1513. }
  1514. }
  1515. }
  1516. if ($count == 0)
  1517. {
  1518. $rw = '<td>Failed to access any rigs successfully';
  1519. if ($preverr > 0)
  1520. $rw .= ' (or rigs had previous errors)';
  1521. $rw .= '</td>';
  1522. otherrow($rw);
  1523. return;
  1524. }
  1525. if ($datetime)
  1526. {
  1527. showdatetime();
  1528. endtable();
  1529. newtable();
  1530. showrigs($anss, '', 'Rig ');
  1531. endtable();
  1532. otherrow('<td><br><br></td>');
  1533. newtable();
  1534. return;
  1535. }
  1536. $total = array();
  1537. foreach ($anss as $rig => $ans)
  1538. {
  1539. if ($ans == null)
  1540. continue;
  1541. foreach ($ans as $item => $row)
  1542. {
  1543. if ($item == 'STATUS')
  1544. continue;
  1545. if (count($row) > count($header))
  1546. {
  1547. $header = $head;
  1548. foreach ($row as $name => $value)
  1549. if (!isset($header[$name]))
  1550. $header[$name] = '';
  1551. }
  1552. if ($sum != null)
  1553. foreach ($sum as $name)
  1554. {
  1555. if (isset($row[$name]))
  1556. {
  1557. if (isset($total[$name]))
  1558. $total[$name] += $row[$name];
  1559. else
  1560. $total[$name] = $row[$name];
  1561. }
  1562. }
  1563. }
  1564. }
  1565. if ($sum != null)
  1566. $anss['total']['total'] = $total;
  1567. showhead('', $header);
  1568. foreach ($anss as $rig => $ans)
  1569. {
  1570. if ($ans == null)
  1571. continue;
  1572. $when = 0;
  1573. if (isset($ans['STATUS']['When']))
  1574. $when = $ans['STATUS']['When'];
  1575. foreach ($ans as $item => $row)
  1576. {
  1577. if ($item == 'STATUS')
  1578. continue;
  1579. newrow();
  1580. $section = preg_replace('/\d/', '', $item);
  1581. foreach ($header as $name => $x)
  1582. {
  1583. if ($name == '')
  1584. {
  1585. if ($rig === 'total')
  1586. {
  1587. list($ignore, $class) = fmt($rig, '', '', $when, $row);
  1588. echo "<td align=right$class>Total:</td>";
  1589. }
  1590. else
  1591. echo rigbutton($rig, "Rig $rig", $when, $row);
  1592. }
  1593. else
  1594. {
  1595. if (isset($row[$name]))
  1596. $value = $row[$name];
  1597. else
  1598. $value = null;
  1599. list($showvalue, $class) = fmt($section, $name, $value, $when, $row);
  1600. echo "<td$class align=right>$showvalue</td>";
  1601. }
  1602. }
  1603. endrow();
  1604. }
  1605. }
  1606. }
  1607. #
  1608. function refreshbuttons()
  1609. {
  1610. global $ignorerefresh, $changerefresh, $autorefresh;
  1611. if ($ignorerefresh == false && $changerefresh == true)
  1612. {
  1613. echo '&nbsp;&nbsp;&nbsp;&nbsp;';
  1614. echo "<input type=button value='Auto Refresh:' onclick='prr(true)'>";
  1615. echo "<input type=text name='refval' id='refval' size=2 value='$autorefresh'>";
  1616. echo "<input type=button value='Off' onclick='prr(false)'>";
  1617. }
  1618. }
  1619. #
  1620. function pagebuttons($rig, $pg)
  1621. {
  1622. global $readonly, $rigs, $userlist, $ses;
  1623. global $allowcustompages, $customsummarypages;
  1624. if ($rig === null)
  1625. {
  1626. $prev = null;
  1627. $next = null;
  1628. if ($pg === null)
  1629. $refresh = '';
  1630. else
  1631. $refresh = "&pg=$pg";
  1632. }
  1633. else
  1634. {
  1635. switch (count($rigs))
  1636. {
  1637. case 0:
  1638. case 1:
  1639. $prev = null;
  1640. $next = null;
  1641. break;
  1642. case 2:
  1643. $prev = null;
  1644. $next = ($rig + 1) % count($rigs);
  1645. break;
  1646. default:
  1647. $prev = ($rig - 1) % count($rigs);
  1648. $next = ($rig + 1) % count($rigs);
  1649. break;
  1650. }
  1651. $refresh = "&rig=$rig";
  1652. }
  1653. echo '<tr><td><table cellpadding=0 cellspacing=0 border=0><tr><td nowrap>';
  1654. if ($userlist === null || isset($_SESSION[$ses]))
  1655. {
  1656. if ($prev !== null)
  1657. echo riginput($prev, 'Prev').'&nbsp;';
  1658. echo "<input type=button value='Refresh' onclick='pr(\"$refresh\",null)'>&nbsp;";
  1659. if ($next !== null)
  1660. echo riginput($next, 'Next').'&nbsp;';
  1661. echo '&nbsp;';
  1662. if (count($rigs) > 1)
  1663. echo "<input type=button value='Summary' onclick='pr(\"\",null)'>&nbsp;";
  1664. }
  1665. if ($allowcustompages === true)
  1666. {
  1667. if ($userlist === null || isset($_SESSION[$ses]))
  1668. $list = $customsummarypages;
  1669. else
  1670. {
  1671. if ($userlist !== null && isset($userlist['def']))
  1672. $list = array_flip($userlist['def']);
  1673. else
  1674. $list = array();
  1675. }
  1676. foreach ($list as $pagename => $data)
  1677. echo "<input type=button value='$pagename' onclick='pr(\"&pg=$pagename\",null)'>&nbsp;";
  1678. }
  1679. echo '</td><td width=100%>&nbsp;</td><td nowrap>';
  1680. if ($rig !== null && $readonly === false)
  1681. {
  1682. $rg = '';
  1683. if (count($rigs) > 1)
  1684. $rg = " Rig $rig";
  1685. echo "<input type=button value='Restart' onclick='prc(\"restart&rig=$rig\",\"Restart BFGMiner$rg\")'>";
  1686. echo "&nbsp;<input type=button value='Quit' onclick='prc(\"quit&rig=$rig\",\"Quit BFGMiner$rg\")'>";
  1687. }
  1688. refreshbuttons();
  1689. if (isset($_SESSION[$ses]))
  1690. echo "&nbsp;<input type=button value='Logout' onclick='pr(\"&logout=1\",null)'>";
  1691. else
  1692. if ($userlist !== null)
  1693. echo "&nbsp;<input type=button value='Login' onclick='pr(\"&login=1\",null)'>";
  1694. echo "</td></tr></table></td></tr>";
  1695. }
  1696. #
  1697. function doOne($rig, $preprocess)
  1698. {
  1699. global $haderror, $readonly, $notify, $rigs;
  1700. global $placebuttons;
  1701. if ($placebuttons == 'top' || $placebuttons == 'both')
  1702. pagebuttons($rig, null);
  1703. if ($preprocess != null)
  1704. process(array($preprocess => $preprocess), $rig);
  1705. $cmds = array( 'devs' => 'device list',
  1706. 'summary' => 'summary information',
  1707. 'pools' => 'pool list');
  1708. if ($notify)
  1709. $cmds['notify'] = 'device status';
  1710. $cmds['config'] = 'BFGMiner config';
  1711. process($cmds, $rig);
  1712. if ($haderror == false && $readonly === false)
  1713. processgpus($rig);
  1714. if ($placebuttons == 'bot' || $placebuttons == 'both')
  1715. pagebuttons($rig, null);
  1716. }
  1717. #
  1718. global $sectionmap;
  1719. # map sections to their api command
  1720. # DEVS is a special case that will match GPU or PGA
  1721. # so you can have a single table with both in it
  1722. # DATE is hard coded so not in here
  1723. $sectionmap = array(
  1724. 'RIGS' => 'version',
  1725. 'SUMMARY' => 'summary',
  1726. 'POOL' => 'pools',
  1727. 'DEVS' => 'devs',
  1728. 'GPU' => 'devs', // You would normally use DEVS
  1729. 'PGA' => 'devs', // You would normally use DEVS
  1730. 'NOTIFY' => 'notify',
  1731. 'DEVDETAILS' => 'devdetails',
  1732. 'STATS' => 'stats',
  1733. 'CONFIG' => 'config',
  1734. 'COIN' => 'coin');
  1735. #
  1736. function joinfields($section1, $section2, $join, $results)
  1737. {
  1738. global $sectionmap;
  1739. $name1 = $sectionmap[$section1];
  1740. $name2 = $sectionmap[$section2];
  1741. $newres = array();
  1742. // foreach rig in section1
  1743. foreach ($results[$name1] as $rig => $result)
  1744. {
  1745. $status = null;
  1746. // foreach answer section in the rig api call
  1747. foreach ($result as $name1b => $fields1b)
  1748. {
  1749. if ($name1b == 'STATUS')
  1750. {
  1751. // remember the STATUS from section1
  1752. $status = $result[$name1b];
  1753. continue;
  1754. }
  1755. // foreach answer section in the rig api call (for the other api command)
  1756. foreach ($results[$name2][$rig] as $name2b => $fields2b)
  1757. {
  1758. if ($name2b == 'STATUS')
  1759. continue;
  1760. // If match the same field values of fields in $join
  1761. $match = true;
  1762. foreach ($join as $field)
  1763. if ($fields1b[$field] != $fields2b[$field])
  1764. {
  1765. $match = false;
  1766. break;
  1767. }
  1768. if ($match === true)
  1769. {
  1770. if ($status != null)
  1771. {
  1772. $newres[$rig]['STATUS'] = $status;
  1773. $status = null;
  1774. }
  1775. $subsection = $section1.'+'.$section2;
  1776. $subsection .= preg_replace('/[^0-9]/', '', $name1b.$name2b);
  1777. foreach ($fields1b as $nam => $val)
  1778. $newres[$rig][$subsection]["$section1.$nam"] = $val;
  1779. foreach ($fields2b as $nam => $val)
  1780. $newres[$rig][$subsection]["$section2.$nam"] = $val;
  1781. }
  1782. }
  1783. }
  1784. }
  1785. return $newres;
  1786. }
  1787. #
  1788. function join_get_field($field, $fields)
  1789. {
  1790. // : means a string constant otherwise it's a field name
  1791. // ProcID field name is converted to a lowercase letter
  1792. if (substr($field, 0, 1) == ':')
  1793. return substr($field, 1);
  1794. else
  1795. if ($field == 'ProcID')
  1796. return chr(97 + $fields[$field]);
  1797. else
  1798. return $fields[$field];
  1799. }
  1800. #
  1801. function joinlr($section1, $section2, $join, $results)
  1802. {
  1803. global $sectionmap;
  1804. $name1 = $sectionmap[$section1];
  1805. $name2 = $sectionmap[$section2];
  1806. $newres = array();
  1807. // foreach rig in section1
  1808. foreach ($results[$name1] as $rig => $result)
  1809. {
  1810. $status = null;
  1811. // foreach answer section in the rig api call
  1812. foreach ($result as $name1b => $fields1b)
  1813. {
  1814. if ($name1b == 'STATUS')
  1815. {
  1816. // remember the STATUS from section1
  1817. $status = $result[$name1b];
  1818. continue;
  1819. }
  1820. // Build L string to be matched
  1821. $Lval = '';
  1822. foreach ($join['L'] as $field)
  1823. $Lval .= join_get_field($field, $fields1b);
  1824. // foreach answer section in the rig api call (for the other api command)
  1825. foreach ($results[$name2][$rig] as $name2b => $fields2b)
  1826. {
  1827. if ($name2b == 'STATUS')
  1828. continue;
  1829. // Build R string and compare
  1830. $Rval = '';
  1831. foreach ($join['R'] as $field)
  1832. $Rval .= join_get_field($field, $fields2b);
  1833. if ($Lval === $Rval)
  1834. {
  1835. if ($status != null)
  1836. {
  1837. $newres[$rig]['STATUS'] = $status;
  1838. $status = null;
  1839. }
  1840. $subsection = $section1.'+'.$section2;
  1841. $subsection .= preg_replace('/[^0-9]/', '', $name1b.$name2b);
  1842. foreach ($fields1b as $nam => $val)
  1843. $newres[$rig][$subsection]["$section1.$nam"] = $val;
  1844. foreach ($fields2b as $nam => $val)
  1845. $newres[$rig][$subsection]["$section2.$nam"] = $val;
  1846. }
  1847. }
  1848. }
  1849. }
  1850. return $newres;
  1851. }
  1852. #
  1853. function joinall($section1, $section2, $results)
  1854. {
  1855. global $sectionmap;
  1856. $name1 = $sectionmap[$section1];
  1857. $name2 = $sectionmap[$section2];
  1858. $newres = array();
  1859. // foreach rig in section1
  1860. foreach ($results[$name1] as $rig => $result)
  1861. {
  1862. // foreach answer section in the rig api call
  1863. foreach ($result as $name1b => $fields1b)
  1864. {
  1865. if ($name1b == 'STATUS')
  1866. {
  1867. // copy the STATUS from section1
  1868. $newres[$rig][$name1b] = $result[$name1b];
  1869. continue;
  1870. }
  1871. // foreach answer section in the rig api call (for the other api command)
  1872. foreach ($results[$name2][$rig] as $name2b => $fields2b)
  1873. {
  1874. if ($name2b == 'STATUS')
  1875. continue;
  1876. $subsection = $section1.'+'.$section2;
  1877. $subsection .= preg_replace('/[^0-9]/', '', $name1b.$name2b);
  1878. foreach ($fields1b as $nam => $val)
  1879. $newres[$rig][$subsection]["$section1.$nam"] = $val;
  1880. foreach ($fields2b as $nam => $val)
  1881. $newres[$rig][$subsection]["$section2.$nam"] = $val;
  1882. }
  1883. }
  1884. }
  1885. return $newres;
  1886. }
  1887. #
  1888. function joinsections($sections, $results, $errors)
  1889. {
  1890. global $sectionmap;
  1891. // GPU's don't have Name,ID,ProcID fields - so create them
  1892. foreach ($results as $section => $res)
  1893. foreach ($res as $rig => $result)
  1894. foreach ($result as $name => $fields)
  1895. {
  1896. $subname = preg_replace('/[0-9]/', '', $name);
  1897. if ($subname == 'GPU' and isset($result[$name]['GPU']))
  1898. {
  1899. $results[$section][$rig][$name]['Name'] = 'GPU';
  1900. $results[$section][$rig][$name]['ID'] = $result[$name]['GPU'];
  1901. $results[$section][$rig][$name]['ProcID'] = 0;
  1902. }
  1903. }
  1904. foreach ($sections as $section => $fields)
  1905. if ($section != 'DATE' && !isset($sectionmap[$section]))
  1906. {
  1907. $both = explode('+', $section, 2);
  1908. if (count($both) > 1)
  1909. {
  1910. switch($both[0])
  1911. {
  1912. case 'SUMMARY':
  1913. switch($both[1])
  1914. {
  1915. case 'POOL':
  1916. case 'DEVS':
  1917. case 'CONFIG':
  1918. case 'COIN':
  1919. $sectionmap[$section] = $section;
  1920. $results[$section] = joinall($both[0], $both[1], $results);
  1921. break;
  1922. default:
  1923. $errors[] = "Error: Invalid section '$section'";
  1924. break;
  1925. }
  1926. break;
  1927. case 'DEVS':
  1928. switch($both[1])
  1929. {
  1930. case 'NOTIFY':
  1931. case 'DEVDETAILS':
  1932. case 'USBSTATS':
  1933. $join = array('Name', 'ID', 'ProcID');
  1934. $sectionmap[$section] = $section;
  1935. $results[$section] = joinfields($both[0], $both[1], $join, $results);
  1936. break;
  1937. case 'STATS':
  1938. $join = array('L' => array('Name','ID','ProcID'), 'R' => array('ID'));
  1939. $sectionmap[$section] = $section;
  1940. $results[$section] = joinlr($both[0], $both[1], $join, $results);
  1941. break;
  1942. default:
  1943. $errors[] = "Error: Invalid section '$section'";
  1944. break;
  1945. }
  1946. break;
  1947. case 'POOL':
  1948. switch($both[1])
  1949. {
  1950. case 'STATS':
  1951. $join = array('L' => array(':POOL','POOL'), 'R' => array('ID'));
  1952. $sectionmap[$section] = $section;
  1953. $results[$section] = joinlr($both[0], $both[1], $join, $results);
  1954. break;
  1955. default:
  1956. $errors[] = "Error: Invalid section '$section'";
  1957. break;
  1958. }
  1959. break;
  1960. default:
  1961. $errors[] = "Error: Invalid section '$section'";
  1962. break;
  1963. }
  1964. }
  1965. else
  1966. $errors[] = "Error: Invalid section '$section'";
  1967. }
  1968. return array($results, $errors);
  1969. }
  1970. #
  1971. function secmatch($section, $field)
  1972. {
  1973. if ($section == $field)
  1974. return true;
  1975. if ($section == 'DEVS'
  1976. && ($field == 'GPU' || $field == 'PGA'))
  1977. return true;
  1978. return false;
  1979. }
  1980. #
  1981. function customset($showfields, $sum, $section, $rig, $isbutton, $result, $total)
  1982. {
  1983. foreach ($result as $sec => $row)
  1984. {
  1985. $secname = preg_replace('/\d/', '', $sec);
  1986. if ($sec != 'total')
  1987. if (!secmatch($section, $secname))
  1988. continue;
  1989. newrow();
  1990. $when = 0;
  1991. if (isset($result['STATUS']['When']))
  1992. $when = $result['STATUS']['When'];
  1993. if ($isbutton)
  1994. echo rigbutton($rig, $rig, $when, $row);
  1995. else
  1996. {
  1997. list($ignore, $class) = fmt('total', '', '', $when, $row);
  1998. echo "<td align=middle$class>$rig</td>";
  1999. }
  2000. foreach ($showfields as $name => $one)
  2001. {
  2002. if (isset($row[$name]))
  2003. {
  2004. $value = $row[$name];
  2005. if (isset($sum[$section][$name]))
  2006. {
  2007. if (isset($total[$name]))
  2008. $total[$name] += $value;
  2009. else
  2010. $total[$name] = $value;
  2011. }
  2012. }
  2013. else
  2014. {
  2015. if ($sec == 'total' && isset($total[$name]))
  2016. $value = $total[$name];
  2017. else
  2018. $value = null;
  2019. }
  2020. if (strpos($secname, '+') === false)
  2021. list($showvalue, $class) = fmt($secname, $name, $value, $when, $row);
  2022. else
  2023. {
  2024. $parts = explode('.', $name, 2);
  2025. list($showvalue, $class) = fmt($parts[0], $parts[1], $value, $when, $row);
  2026. }
  2027. echo "<td$class align=right>$showvalue</td>";
  2028. }
  2029. endrow();
  2030. }
  2031. return $total;
  2032. }
  2033. #
  2034. function docalc($func, $data)
  2035. {
  2036. switch ($func)
  2037. {
  2038. case 'sum':
  2039. $tot = 0;
  2040. foreach ($data as $val)
  2041. $tot += $val;
  2042. return $tot;
  2043. case 'avg':
  2044. $tot = 0;
  2045. foreach ($data as $val)
  2046. $tot += $val;
  2047. return ($tot / count($data));
  2048. case 'min':
  2049. $ans = null;
  2050. foreach ($data as $val)
  2051. if ($ans === null)
  2052. $ans = $val;
  2053. else
  2054. if ($val < $ans)
  2055. $ans = $val;
  2056. return $ans;
  2057. case 'max':
  2058. $ans = null;
  2059. foreach ($data as $val)
  2060. if ($ans === null)
  2061. $ans = $val;
  2062. else
  2063. if ($val > $ans)
  2064. $ans = $val;
  2065. return $ans;
  2066. case 'lo':
  2067. $ans = null;
  2068. foreach ($data as $val)
  2069. if ($ans === null)
  2070. $ans = $val;
  2071. else
  2072. if (strcasecmp($val, $ans) < 0)
  2073. $ans = $val;
  2074. return $ans;
  2075. case 'hi':
  2076. $ans = null;
  2077. foreach ($data as $val)
  2078. if ($ans === null)
  2079. $ans = $val;
  2080. else
  2081. if (strcasecmp($val, $ans) > 0)
  2082. $ans = $val;
  2083. return $ans;
  2084. case 'count':
  2085. return count($data);
  2086. case 'any':
  2087. default:
  2088. return $data[0];
  2089. }
  2090. }
  2091. #
  2092. function docompare($row, $test)
  2093. {
  2094. // invalid $test data means true
  2095. if (count($test) < 2)
  2096. return true;
  2097. if (isset($row[$test[0]]))
  2098. $val = $row[$test[0]];
  2099. else
  2100. $val = null;
  2101. if ($test[1] == 'set')
  2102. return ($val !== null);
  2103. if ($val === null || count($test) < 3)
  2104. return true;
  2105. switch($test[1])
  2106. {
  2107. case '=':
  2108. return ($val == $test[2]);
  2109. case '<':
  2110. return ($val < $test[2]);
  2111. case '<=':
  2112. return ($val <= $test[2]);
  2113. case '>':
  2114. return ($val > $test[2]);
  2115. case '>=':
  2116. return ($val >= $test[2]);
  2117. case 'eq':
  2118. return (strcasecmp($val, $test[2]) == 0);
  2119. case 'lt':
  2120. return (strcasecmp($val, $test[2]) < 0);
  2121. case 'le':
  2122. return (strcasecmp($val, $test[2]) <= 0);
  2123. case 'gt':
  2124. return (strcasecmp($val, $test[2]) > 0);
  2125. case 'ge':
  2126. return (strcasecmp($val, $test[2]) >= 0);
  2127. default:
  2128. return true;
  2129. }
  2130. }
  2131. #
  2132. function processcompare($which, $ext, $section, $res)
  2133. {
  2134. if (isset($ext[$section][$which]))
  2135. {
  2136. $proc = $ext[$section][$which];
  2137. if ($proc !== null)
  2138. {
  2139. $res2 = array();
  2140. foreach ($res as $rig => $result)
  2141. foreach ($result as $sec => $row)
  2142. {
  2143. $secname = preg_replace('/\d/', '', $sec);
  2144. if (!secmatch($section, $secname))
  2145. $res2[$rig][$sec] = $row;
  2146. else
  2147. {
  2148. $keep = true;
  2149. foreach ($proc as $test)
  2150. if (!docompare($row, $test))
  2151. {
  2152. $keep = false;
  2153. break;
  2154. }
  2155. if ($keep)
  2156. $res2[$rig][$sec] = $row;
  2157. }
  2158. }
  2159. $res = $res2;
  2160. }
  2161. }
  2162. return $res;
  2163. }
  2164. #
  2165. function ss($a, $b)
  2166. {
  2167. $la = strlen(a);
  2168. $lb = strlen(b);
  2169. if ($la != $lb)
  2170. return $la - $lb;
  2171. return strcmp($a, $b);
  2172. }
  2173. #
  2174. function genfld($row, $calc)
  2175. {
  2176. uksort($row, "ss");
  2177. foreach ($row as $name => $value)
  2178. if (strstr($calc, $name) !== FALSE)
  2179. $calc = str_replace($name, $value, $calc);
  2180. eval("\$val = $calc;");
  2181. return $val;
  2182. }
  2183. #
  2184. function dogen($ext, $section, &$res, &$fields)
  2185. {
  2186. $gen = $ext[$section]['gen'];
  2187. foreach ($gen as $fld => $calc)
  2188. $fields[] = "GEN.$fld";
  2189. foreach ($res as $rig => $result)
  2190. foreach ($result as $sec => $row)
  2191. {
  2192. $secname = preg_replace('/\d/', '', $sec);
  2193. if (secmatch($section, $secname))
  2194. foreach ($gen as $fld => $calc)
  2195. {
  2196. $name = "GEN.$fld";
  2197. $val = genfld($row, $calc);
  2198. $res[$rig][$sec][$name] = $val;
  2199. }
  2200. }
  2201. }
  2202. #
  2203. function processext($ext, $section, $res, &$fields)
  2204. {
  2205. global $allowgen;
  2206. $res = processcompare('where', $ext, $section, $res);
  2207. if (isset($ext[$section]['group']))
  2208. {
  2209. $grp = $ext[$section]['group'];
  2210. $calc = $ext[$section]['calc'];
  2211. if ($grp !== null)
  2212. {
  2213. $interim = array();
  2214. $res2 = array();
  2215. $cou = 0;
  2216. foreach ($res as $rig => $result)
  2217. foreach ($result as $sec => $row)
  2218. {
  2219. $secname = preg_replace('/\d/', '', $sec);
  2220. if (!secmatch($section, $secname))
  2221. {
  2222. // STATUS may be problematic ...
  2223. if (!isset($res2[$sec]))
  2224. $res2[$sec] = $row;
  2225. }
  2226. else
  2227. {
  2228. $grpkey = '';
  2229. $newrow = array();
  2230. foreach ($grp as $field)
  2231. {
  2232. if (isset($row[$field]))
  2233. {
  2234. $grpkey .= $row[$field].'.';
  2235. $newrow[$field] = $row[$field];
  2236. }
  2237. else
  2238. $grpkey .= '.';
  2239. }
  2240. if (!isset($interim[$grpkey]))
  2241. {
  2242. $interim[$grpkey]['grp'] = $newrow;
  2243. $interim[$grpkey]['sec'] = $secname.$cou;
  2244. $cou++;
  2245. }
  2246. if ($calc !== null)
  2247. foreach ($calc as $field => $func)
  2248. {
  2249. if (!isset($interim[$grpkey]['cal'][$field]))
  2250. $interim[$grpkey]['cal'][$field] = array();
  2251. $interim[$grpkey]['cal'][$field][] = $row[$field];
  2252. }
  2253. }
  2254. }
  2255. // Build the rest of $res2 from $interim
  2256. foreach ($interim as $rowkey => $row)
  2257. {
  2258. $key = $row['sec'];
  2259. foreach ($row['grp'] as $field => $value)
  2260. $res2[$key][$field] = $value;
  2261. foreach ($row['cal'] as $field => $data)
  2262. $res2[$key][$field] = docalc($calc[$field], $data);
  2263. }
  2264. $res = array('' => $res2);
  2265. }
  2266. }
  2267. // Generated fields (functions of other fields)
  2268. if ($allowgen === true && isset($ext[$section]['gen']))
  2269. dogen($ext, $section, $res, $fields);
  2270. return processcompare('having', $ext, $section, $res);
  2271. }
  2272. #
  2273. function processcustompage($pagename, $sections, $sum, $ext, $namemap)
  2274. {
  2275. global $sectionmap;
  2276. global $miner, $port;
  2277. global $rigs, $error;
  2278. global $warnfont, $warnoff;
  2279. global $dfmt;
  2280. global $readonly, $showndate;
  2281. $cmds = array();
  2282. $errors = array();
  2283. foreach ($sections as $section => $fields)
  2284. {
  2285. $all = explode('+', $section);
  2286. foreach ($all as $section)
  2287. {
  2288. if (isset($sectionmap[$section]))
  2289. {
  2290. $cmd = $sectionmap[$section];
  2291. if (!isset($cmds[$cmd]))
  2292. $cmds[$cmd] = 1;
  2293. }
  2294. else
  2295. if ($section != 'DATE')
  2296. $errors[] = "Error: unknown section '$section' in custom summary page '$pagename'";
  2297. }
  2298. }
  2299. $results = array();
  2300. foreach ($rigs as $num => $rig)
  2301. {
  2302. $parts = explode(':', $rig, 3);
  2303. if (count($parts) >= 2)
  2304. {
  2305. $miner = $parts[0];
  2306. $port = $parts[1];
  2307. if (count($parts) > 2)
  2308. $name = $parts[2];
  2309. else
  2310. $name = $rig;
  2311. foreach ($cmds as $cmd => $one)
  2312. {
  2313. $process = api($name, $cmd);
  2314. if ($error != null)
  2315. {
  2316. $errors[] = "Error getting $cmd for $name $warnfont$error$warnoff";
  2317. break;
  2318. }
  2319. else
  2320. $results[$cmd][$num] = $process;
  2321. }
  2322. }
  2323. else
  2324. otherrow('<td class=bad>Bad "$rigs" array</td>');
  2325. }
  2326. $shownsomething = false;
  2327. if (count($results) > 0)
  2328. {
  2329. list($results, $errors) = joinsections($sections, $results, $errors);
  2330. $first = true;
  2331. foreach ($sections as $section => $fields)
  2332. {
  2333. if ($section === 'DATE')
  2334. {
  2335. if ($shownsomething)
  2336. otherrow('<td>&nbsp;</td>');
  2337. newtable();
  2338. showdatetime();
  2339. endtable();
  2340. // On top of the next table
  2341. $shownsomething = false;
  2342. continue;
  2343. }
  2344. if ($section === 'RIGS')
  2345. {
  2346. if ($shownsomething)
  2347. otherrow('<td>&nbsp;</td>');
  2348. newtable();
  2349. showrigs($results['version'], 'Rig', '');
  2350. endtable();
  2351. $shownsomething = true;
  2352. continue;
  2353. }
  2354. if (isset($results[$sectionmap[$section]]))
  2355. {
  2356. $rigresults = processext($ext, $section, $results[$sectionmap[$section]], $fields);
  2357. $showfields = array();
  2358. $showhead = array();
  2359. foreach ($fields as $field)
  2360. foreach ($rigresults as $result)
  2361. foreach ($result as $sec => $row)
  2362. {
  2363. $secname = preg_replace('/\d/', '', $sec);
  2364. if (secmatch($section, $secname))
  2365. {
  2366. if ($field === '*')
  2367. {
  2368. foreach ($row as $f => $v)
  2369. {
  2370. $showfields[$f] = 1;
  2371. $map = $section.'.'.$f;
  2372. if (isset($namemap[$map]))
  2373. $showhead[$namemap[$map]] = 1;
  2374. else
  2375. $showhead[$f] = 1;
  2376. }
  2377. }
  2378. elseif (isset($row[$field]))
  2379. {
  2380. $showfields[$field] = 1;
  2381. $map = $section.'.'.$field;
  2382. if (isset($namemap[$map]))
  2383. $showhead[$namemap[$map]] = 1;
  2384. else
  2385. $showhead[$field] = 1;
  2386. }
  2387. }
  2388. }
  2389. if (count($showfields) > 0)
  2390. {
  2391. if ($shownsomething)
  2392. otherrow('<td>&nbsp;</td>');
  2393. newtable();
  2394. if (count($rigresults) == 1 && isset($rigresults['']))
  2395. $ri = array('' => 1) + $showhead;
  2396. else
  2397. $ri = array('Rig' => 1) + $showhead;
  2398. showhead('', $ri, true);
  2399. $total = array();
  2400. $add = array('total' => array());
  2401. foreach ($rigresults as $num => $result)
  2402. $total = customset($showfields, $sum, $section, $num, true, $result, $total);
  2403. if (count($total) > 0)
  2404. customset($showfields, $sum, $section, '&Sigma;', false, $add, $total);
  2405. $first = false;
  2406. endtable();
  2407. $shownsomething = true;
  2408. }
  2409. }
  2410. }
  2411. }
  2412. if (count($errors) > 0)
  2413. {
  2414. if (count($results) > 0)
  2415. otherrow('<td>&nbsp;</td>');
  2416. foreach ($errors as $err)
  2417. otherrow("<td colspan=100>$err</td>");
  2418. }
  2419. }
  2420. #
  2421. function showcustompage($pagename)
  2422. {
  2423. global $customsummarypages;
  2424. global $placebuttons;
  2425. if ($placebuttons == 'top' || $placebuttons == 'both')
  2426. pagebuttons(null, $pagename);
  2427. if (!isset($customsummarypages[$pagename]))
  2428. {
  2429. otherrow("<td colspan=100 class=bad>Unknown custom summary page '$pagename'</td>");
  2430. return;
  2431. }
  2432. $c = count($customsummarypages[$pagename]);
  2433. if ($c < 2 || $c > 3)
  2434. {
  2435. $rw = "<td colspan=100 class=bad>Invalid custom summary page '$pagename' (";
  2436. $rw .= count($customsummarypages[$pagename]).')</td>';
  2437. otherrow($rw);
  2438. return;
  2439. }
  2440. $page = $customsummarypages[$pagename][0];
  2441. $namemap = array();
  2442. foreach ($page as $name => $fields)
  2443. {
  2444. if ($fields === null)
  2445. $page[$name] = array();
  2446. else
  2447. foreach ($fields as $num => $field)
  2448. {
  2449. $pos = strpos($field, '=');
  2450. if ($pos !== false)
  2451. {
  2452. $names = explode('=', $field, 2);
  2453. if (strlen($names[1]) > 0)
  2454. $namemap[$name.'.'.$names[0]] = $names[1];
  2455. $page[$name][$num] = $names[0];
  2456. }
  2457. }
  2458. }
  2459. $ext = null;
  2460. if (isset($customsummarypages[$pagename][2]))
  2461. $ext = $customsummarypages[$pagename][2];
  2462. $sum = $customsummarypages[$pagename][1];
  2463. if ($sum === null)
  2464. $sum = array();
  2465. // convert them to searchable via isset()
  2466. foreach ($sum as $section => $fields)
  2467. {
  2468. $newfields = array();
  2469. foreach ($fields as $field)
  2470. $newfields[$field] = 1;
  2471. $sum[$section] = $newfields;
  2472. }
  2473. if (count($page) <= 1)
  2474. {
  2475. otherrow("<td colspan=100 class=bad>Invalid custom summary page '$pagename' no content </td>");
  2476. return;
  2477. }
  2478. processcustompage($pagename, $page, $sum, $ext, $namemap);
  2479. if ($placebuttons == 'bot' || $placebuttons == 'both')
  2480. pagebuttons(null, $pagename);
  2481. }
  2482. #
  2483. function onlylogin()
  2484. {
  2485. global $here;
  2486. htmlhead('', false, null, null, true);
  2487. ?>
  2488. <tr height=15%><td>&nbsp;</td></tr>
  2489. <tr><td>
  2490. <center>
  2491. <table width=384 height=368 cellpadding=0 cellspacing=0 border=0>
  2492. <tr><td>
  2493. <table width=100% height=100% border=0 align=center cellpadding=5 cellspacing=0>
  2494. <tr><td><form action='<?php echo $here; ?>' method=post>
  2495. <table width=200 border=0 align=center cellpadding=5 cellspacing=0>
  2496. <tr><td height=120 colspan=2>&nbsp;</td></tr>
  2497. <tr><td colspan=2 align=center valign=middle>
  2498. <h2>LOGIN</h2></td></tr>
  2499. <tr><td align=center valign=middle><div align=right>Username:</div></td>
  2500. <td height=33 align=center valign=middle>
  2501. <input type=text name=rut size=18></td></tr>
  2502. <tr><td align=center valign=middle><div align=right>Password:</div></td>
  2503. <td height=33 align=center valign=middle>
  2504. <input type=password name=roh size=18></td></tr>
  2505. <tr valign=top><td></td><td><input type=submit value=Login>
  2506. </td></tr>
  2507. </table></form></td></tr>
  2508. </table></td></tr>
  2509. </table></center>
  2510. </td></tr>
  2511. <?php
  2512. }
  2513. #
  2514. function checklogin()
  2515. {
  2516. global $allowcustompages, $customsummarypages;
  2517. global $readonly, $userlist, $ses;
  2518. $out = trim(getparam('logout', true));
  2519. if ($out !== null && $out !== '' && isset($_SESSION[$ses]))
  2520. unset($_SESSION[$ses]);
  2521. $login = trim(getparam('login', true));
  2522. if ($login !== null && $login !== '')
  2523. {
  2524. if (isset($_SESSION[$ses]))
  2525. unset($_SESSION[$ses]);
  2526. onlylogin();
  2527. return 'login';
  2528. }
  2529. if ($userlist === null)
  2530. return false;
  2531. $rut = trim(getparam('rut', true));
  2532. $roh = trim(getparam('roh', true));
  2533. if (($rut !== null && $rut !== '') || ($roh !== null && $roh !== ''))
  2534. {
  2535. if (isset($_SESSION[$ses]))
  2536. unset($_SESSION[$ses]);
  2537. if ($rut !== null && $rut !== '' && $roh !== null && $roh !== '')
  2538. {
  2539. if (isset($userlist['sys']) && isset($userlist['sys'][$rut])
  2540. && ($userlist['sys'][$rut] === $roh))
  2541. {
  2542. $_SESSION[$ses] = true;
  2543. return false;
  2544. }
  2545. if (isset($userlist['usr']) && isset($userlist['usr'][$rut])
  2546. && ($userlist['usr'][$rut] === $roh))
  2547. {
  2548. $_SESSION[$ses] = false;
  2549. $readonly = true;
  2550. return false;
  2551. }
  2552. }
  2553. }
  2554. if (isset($_SESSION[$ses]))
  2555. {
  2556. if ($_SESSION[$ses] == false)
  2557. $readonly = true;
  2558. return false;
  2559. }
  2560. if (isset($userlist['def']) && $allowcustompages === true)
  2561. {
  2562. // Ensure at least one exists
  2563. foreach ($userlist['def'] as $pg)
  2564. if (isset($customsummarypages[$pg]))
  2565. return true;
  2566. }
  2567. onlylogin();
  2568. return 'login';
  2569. }
  2570. #
  2571. function display()
  2572. {
  2573. global $miner, $port;
  2574. global $mcast, $mcastexpect;
  2575. global $readonly, $notify, $rigs;
  2576. global $ignorerefresh, $autorefresh;
  2577. global $allowcustompages, $customsummarypages;
  2578. global $placebuttons;
  2579. global $userlist, $ses;
  2580. $pagesonly = checklogin();
  2581. if ($pagesonly === 'login')
  2582. return;
  2583. $mcerr = '';
  2584. if ($rigs == null or count($rigs) == 0)
  2585. {
  2586. if ($mcast === true)
  2587. $action = 'found';
  2588. else
  2589. $action = 'defined';
  2590. minhead();
  2591. otherrow("<td class=bad>No rigs $action</td>");
  2592. return;
  2593. }
  2594. else
  2595. {
  2596. if ($mcast === true && count($rigs) < $mcastexpect)
  2597. $mcerr = othrow('<td class=bad>Found '.count($rigs)." rigs but expected at least $mcastexpect</td>");
  2598. }
  2599. if ($ignorerefresh == false)
  2600. {
  2601. $ref = trim(getparam('ref', true));
  2602. if ($ref != null && $ref != '')
  2603. $autorefresh = intval($ref);
  2604. }
  2605. if ($pagesonly !== true)
  2606. {
  2607. $rig = trim(getparam('rig', true));
  2608. $arg = trim(getparam('arg', true));
  2609. $preprocess = null;
  2610. if ($arg != null and $arg != '')
  2611. {
  2612. if ($rig != null and $rig != '' and $rig >= 0 and $rig < count($rigs))
  2613. {
  2614. $parts = explode(':', $rigs[$rig], 3);
  2615. if (count($parts) >= 2)
  2616. {
  2617. $miner = $parts[0];
  2618. $port = $parts[1];
  2619. if ($readonly !== true)
  2620. $preprocess = $arg;
  2621. }
  2622. }
  2623. }
  2624. }
  2625. if ($allowcustompages === true)
  2626. {
  2627. $pg = trim(getparam('pg', true));
  2628. if ($pagesonly === true)
  2629. {
  2630. if ($pg !== null && $pg !== '')
  2631. {
  2632. if ($userlist !== null && isset($userlist['def'])
  2633. && !in_array($pg, $userlist['def']))
  2634. $pg = null;
  2635. }
  2636. else
  2637. {
  2638. if ($userlist !== null && isset($userlist['def']))
  2639. foreach ($userlist['def'] as $pglook)
  2640. if (isset($customsummarypages[$pglook]))
  2641. {
  2642. $pg = $pglook;
  2643. break;
  2644. }
  2645. }
  2646. }
  2647. if ($pg !== null && $pg !== '')
  2648. {
  2649. htmlhead($mcerr, false, null, $pg);
  2650. showcustompage($pg, $mcerr);
  2651. return;
  2652. }
  2653. }
  2654. if ($pagesonly === true)
  2655. {
  2656. onlylogin();
  2657. return;
  2658. }
  2659. if (count($rigs) == 1)
  2660. {
  2661. $parts = explode(':', $rigs[0], 3);
  2662. if (count($parts) >= 2)
  2663. {
  2664. $miner = $parts[0];
  2665. $port = $parts[1];
  2666. htmlhead($mcerr, true, 0);
  2667. doOne(0, $preprocess);
  2668. }
  2669. else
  2670. {
  2671. minhead($mcerr);
  2672. otherrow('<td class=bad>Invalid "$rigs" array</td>');
  2673. }
  2674. return;
  2675. }
  2676. if ($rig != null and $rig != '' and $rig >= 0 and $rig < count($rigs))
  2677. {
  2678. $parts = explode(':', $rigs[$rig], 3);
  2679. if (count($parts) >= 2)
  2680. {
  2681. $miner = $parts[0];
  2682. $port = $parts[1];
  2683. htmlhead($mcerr, true, 0);
  2684. doOne($rig, $preprocess);
  2685. }
  2686. else
  2687. {
  2688. minhead($mcerr);
  2689. otherrow('<td class=bad>Invalid "$rigs" array</td>');
  2690. }
  2691. return;
  2692. }
  2693. htmlhead($mcerr, false, null);
  2694. if ($placebuttons == 'top' || $placebuttons == 'both')
  2695. pagebuttons(null, null);
  2696. if ($preprocess != null)
  2697. process(array($preprocess => $preprocess), $rig);
  2698. newtable();
  2699. doforeach('version', 'rig summary', array(), array(), true);
  2700. $sum = array('MHS av', 'Getworks', 'Found Blocks', 'Accepted', 'Rejected', 'Discarded', 'Stale', 'Utility', 'Local Work', 'Total MH');
  2701. doforeach('summary', 'summary information', $sum, array(), false);
  2702. endtable();
  2703. otherrow('<td><br><br></td>');
  2704. newtable();
  2705. doforeach('devs', 'device list', $sum, array(''=>'','ProcID'=>'','ID'=>'','Name'=>''), false);
  2706. endtable();
  2707. otherrow('<td><br><br></td>');
  2708. newtable();
  2709. doforeach('pools', 'pool list', $sum, array(''=>''), false);
  2710. endtable();
  2711. if ($placebuttons == 'bot' || $placebuttons == 'both')
  2712. pagebuttons(null, null);
  2713. }
  2714. #
  2715. if ($mcast === true)
  2716. getrigs();
  2717. display();
  2718. #
  2719. ?>
  2720. </table></td></tr></table>
  2721. </body></html>