miner.php 64 KB

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