miner.php 64 KB

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