miner.php 64 KB

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