miner.php 64 KB

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