miner.php 67 KB

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