miner.php 64 KB

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