miner.php 65 KB

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