miner.php 67 KB

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