miner.php 68 KB

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