miner.php 69 KB

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