miner.php 65 KB

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