miner.php 66 KB

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