miner.php 61 KB

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