miner.php 67 KB

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