miner.php 66 KB

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