miner.php 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052
  1. <?php
  2. session_start();
  3. #
  4. global $title, $miner, $port, $readonly, $notify, $rigs;
  5. global $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;
  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 BFGMiner 'privileged'
  21. $readonly = false;
  22. #
  23. # Set $notify to false to NOT attempt to display the notify command
  24. # Set $notify to true to attempt to display the notify command
  25. $notify = true;
  26. #
  27. # Set $checklastshare to true to do the following checks:
  28. # If a device's last share is 12x expected ago then display as an error
  29. # If a device's last share is 8x expected ago then display as a warning
  30. # If either of the above is true, also display the whole line highlighted
  31. # This assumes shares are 1 difficulty shares
  32. $checklastshare = true;
  33. #
  34. # Set $poolinputs to true to show the input fields for adding a pool
  35. # and changing the pool priorities
  36. # N.B. also if $readonly is true, it will not display the fields
  37. $poolinputs = false;
  38. #
  39. # Set $rigs to an array of your BFGMiner rigs that are running
  40. # format: 'IP:Port' or 'Host:Port' or 'Host:Port:Name'
  41. $rigs = array('127.0.0.1:4028');
  42. #
  43. # Set $rigtotals to true to display totals on the single rig page
  44. # 'false' means no totals (and ignores $forcerigtotals)
  45. # You can force it to always show rig totals when there is only
  46. # one line by setting $forcerigtotals = true;
  47. $rigtotals = true;
  48. $forcerigtotals = false;
  49. #
  50. # These should be OK for most cases
  51. $socksndtimeoutsec = 10;
  52. $sockrcvtimeoutsec = 40;
  53. #
  54. # List of fields NOT to be displayed
  55. # This example would hide the slightly more sensitive pool information
  56. #$hidefields = array('POOL.URL' => 1, 'POOL.User' => 1);
  57. $hidefields = array();
  58. #
  59. # Auto-refresh of the page (in seconds) - integers only
  60. # $ignorerefresh = true/false always ignore refresh parameters
  61. # $changerefresh = true/false show buttons to change the value
  62. # $autorefresh = default value, 0 means dont auto-refresh
  63. $ignorerefresh = false;
  64. $changerefresh = true;
  65. $autorefresh = 0;
  66. #
  67. # Should we allow custom pages?
  68. # (or just completely ignore them and don't display the buttons)
  69. $allowcustompages = true;
  70. #
  71. # OK this is a bit more complex item: Custom Summary Pages
  72. # As mentioned above, see API-README
  73. # see the example below (if there is no matching data, no total will show)
  74. $mobilepage = array(
  75. 'DATE' => null,
  76. 'RIGS' => null,
  77. 'SUMMARY' => array('Elapsed', 'MHS av', 'Found Blocks=Blks', 'Accepted', 'Rejected=Rej', 'Utility'),
  78. 'DEVS+NOTIFY' => array('DEVS.Name=Name', 'DEVS.ID=ID', 'DEVS.Status=Status', 'DEVS.Temperature=Temp',
  79. 'DEVS.MHS av=MHS av', 'DEVS.Accepted=Accept', 'DEVS.Rejected=Rej',
  80. 'DEVS.Utility=Utility', 'NOTIFY.Last Not Well=Not Well'),
  81. 'POOL' => array('POOL', 'Status', 'Accepted', 'Rejected=Rej', 'Last Share Time'));
  82. $mobilesum = array(
  83. 'SUMMARY' => array('MHS av', 'Found Blocks', 'Accepted', 'Rejected', 'Utility'),
  84. 'DEVS+NOTIFY' => array('DEVS.MHS av', 'DEVS.Accepted', 'DEVS.Rejected', 'DEVS.Utility'),
  85. 'POOL' => array('Accepted', 'Rejected'));
  86. #
  87. # customsummarypages is an array of these Custom Summary Pages
  88. $customsummarypages = array('Mobile' => array($mobilepage, $mobilesum));
  89. #
  90. $here = $_SERVER['PHP_SELF'];
  91. #
  92. global $tablebegin, $tableend, $warnfont, $warnoff, $dfmt;
  93. #
  94. $tablebegin = '<tr><td><table border=1 cellpadding=5 cellspacing=0>';
  95. $tableend = '</table></td></tr>';
  96. $warnfont = '<font color=red><b>';
  97. $warnoff = '</b></font>';
  98. $dfmt = 'H:i:s j-M-Y \U\T\CP';
  99. #
  100. $miner_font_family = 'verdana,arial,sans';
  101. $miner_font_size = '13pt';
  102. #
  103. # Edit this or redefine it in myminer.php to change the colour scheme
  104. # See $colourtable below for the list of names
  105. $colouroverride = array();
  106. #
  107. # Where to place the buttons: 'top' 'bot' 'both'
  108. # anything else means don't show them - case sensitive
  109. $placebuttons = 'top';
  110. #
  111. # This below allows you to put your own settings into a seperate file
  112. # so you don't need to update miner.php with your preferred settings
  113. # every time a new version is released
  114. # Just create the file 'myminer.php' in the same directory as
  115. # 'miner.php' - and put your own settings in there
  116. if (file_exists('myminer.php'))
  117. include_once('myminer.php');
  118. #
  119. # This is the system default that must always contain all necessary
  120. # colours so it must be a constant
  121. # You can override these values with $colouroverride
  122. # The only one missing is in $warnfont
  123. # - which you can override directly anyway
  124. global $colourtable;
  125. $colourtable = array(
  126. 'body bgcolor' => '#ecffff',
  127. 'td color' => 'blue',
  128. 'td.two color' => 'blue',
  129. 'td.two background' => '#ecffff',
  130. 'td.h color' => 'blue',
  131. 'td.h background' => '#c4ffff',
  132. 'td.err color' => 'black',
  133. 'td.err background' => '#ff3050',
  134. 'td.warn color' => 'black',
  135. 'td.warn background' => '#ffb050',
  136. 'td.sta color' => 'green',
  137. 'td.tot color' => 'blue',
  138. 'td.tot background' => '#fff8f2',
  139. 'td.lst color' => 'blue',
  140. 'td.lst background' => '#ffffdd',
  141. 'td.hi color' => 'blue',
  142. 'td.hi background' => '#f6ffff',
  143. 'td.lo color' => 'blue',
  144. 'td.lo background' => '#deffff'
  145. );
  146. #
  147. # Don't touch these 2
  148. $miner = null;
  149. $port = null;
  150. #
  151. # Ensure it is only ever shown once
  152. global $showndate;
  153. $showndate = false;
  154. #
  155. # For summary page to stop retrying failed rigs
  156. global $rigerror;
  157. $rigerror = array();
  158. #
  159. global $rownum;
  160. $rownum = 0;
  161. #
  162. function getcss($cssname, $dom = false)
  163. {
  164. global $colourtable, $colouroverride;
  165. $css = '';
  166. foreach ($colourtable as $cssdata => $value)
  167. {
  168. $cssobj = explode(' ', $cssdata, 2);
  169. if ($cssobj[0] == $cssname)
  170. {
  171. if (isset($colouroverride[$cssdata]))
  172. $value = $colouroverride[$cssdata];
  173. if ($dom == true)
  174. $css .= ' '.$cssobj[1].'='.$value;
  175. else
  176. $css .= $cssobj[1].':'.$value.'; ';
  177. }
  178. }
  179. return $css;
  180. }
  181. #
  182. function getdom($domname)
  183. {
  184. return getcss($domname, true);
  185. }
  186. #
  187. function htmlhead($checkapi, $rig, $pg = null)
  188. {
  189. global $title, $miner_font_family, $miner_font_size;
  190. global $error, $readonly, $poolinputs, $here;
  191. global $ignorerefresh, $autorefresh;
  192. $extraparams = '';
  193. if ($rig != null && $rig != '')
  194. $extraparams = "&rig=$rig";
  195. else
  196. if ($pg != null && $pg != '')
  197. $extraparams = "&pg=$pg";
  198. if ($ignorerefresh == true || $autorefresh == 0)
  199. $refreshmeta = '';
  200. else
  201. {
  202. $url = "$here?ref=$autorefresh$extraparams";
  203. $refreshmeta = "\n<meta http-equiv='refresh' content='$autorefresh;url=$url'>";
  204. }
  205. if ($readonly === false && $checkapi === true)
  206. {
  207. $error = null;
  208. $access = api('privileged');
  209. if ($error != null
  210. || !isset($access['STATUS']['STATUS'])
  211. || $access['STATUS']['STATUS'] != 'S')
  212. $readonly = true;
  213. }
  214. $miner_font = "font-family:$miner_font_family; font-size:$miner_font_size;";
  215. echo "<html><head>$refreshmeta
  216. <title>$title</title>
  217. <style type='text/css'>
  218. td { $miner_font ".getcss('td')."}
  219. td.two { $miner_font ".getcss('td.two')."}
  220. td.h { $miner_font ".getcss('td.h')."}
  221. td.err { $miner_font ".getcss('td.err')."}
  222. td.warn { $miner_font ".getcss('td.warn')."}
  223. td.sta { $miner_font ".getcss('td.sta')."}
  224. td.tot { $miner_font ".getcss('td.tot')."}
  225. td.lst { $miner_font ".getcss('td.lst')."}
  226. td.hi { $miner_font ".getcss('td.hi')."}
  227. td.lo { $miner_font ".getcss('td.lo')."}
  228. </style>
  229. </head><body".getdom('body').">
  230. <script type='text/javascript'>
  231. function pr(a,m){if(m!=null){if(!confirm(m+'?'))return}window.location='$here?ref=$autorefresh'+a}\n";
  232. if ($ignorerefresh == false)
  233. echo "function prr(a){if(a){v=document.getElementById('refval').value}else{v=0}window.location='$here?ref='+v+'$extraparams'}\n";
  234. if ($readonly === false && $checkapi === true)
  235. {
  236. echo "function prc(a,m){pr('&arg='+a,m)}
  237. 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)}
  238. 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";
  239. if ($poolinputs === true)
  240. 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";
  241. }
  242. ?>
  243. </script>
  244. <table width=100% height=100% border=0 cellpadding=0 cellspacing=0 summary='Mine'>
  245. <tr><td align=center valign=top>
  246. <table border=0 cellpadding=4 cellspacing=0 summary='Mine'>
  247. <?php
  248. }
  249. #
  250. global $haderror, $error;
  251. $haderror = false;
  252. $error = null;
  253. #
  254. function getsock($addr, $port)
  255. {
  256. global $haderror, $error, $socksndtimeoutsec, $sockrcvtimeoutsec;
  257. $error = null;
  258. $socket = null;
  259. $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  260. if ($socket === false || $socket === null)
  261. {
  262. $haderror = true;
  263. $error = socket_strerror(socket_last_error());
  264. $msg = "socket create(TCP) failed";
  265. $error = "ERR: $msg '$error'\n";
  266. return null;
  267. }
  268. // Ignore if this fails since the socket connect may work anyway
  269. // and nothing is gained by aborting if the option cannot be set
  270. // since we don't know in advance if it can connect
  271. socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, array('sec' => $socksndtimeoutsec, 'usec' => 0));
  272. socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $sockrcvtimeoutsec, 'usec' => 0));
  273. $res = socket_connect($socket, $addr, $port);
  274. if ($res === false)
  275. {
  276. $haderror = true;
  277. $error = socket_strerror(socket_last_error());
  278. $msg = "socket connect($addr,$port) failed";
  279. $error = "ERR: $msg '$error'\n";
  280. socket_close($socket);
  281. return null;
  282. }
  283. return $socket;
  284. }
  285. #
  286. function readsockline($socket)
  287. {
  288. $line = '';
  289. while (true)
  290. {
  291. $byte = socket_read($socket, 1);
  292. if ($byte === false || $byte === '')
  293. break;
  294. if ($byte === "\0")
  295. break;
  296. $line .= $byte;
  297. }
  298. return $line;
  299. }
  300. #
  301. function api_convert_escape($str)
  302. {
  303. $res = '';
  304. $len = strlen($str);
  305. for ($i = 0; $i < $len; $i++)
  306. {
  307. $ch = substr($str, $i, 1);
  308. if ($ch != '\\' || $i == ($len-1))
  309. $res .= $ch;
  310. else
  311. {
  312. $i++;
  313. $ch = substr($str, $i, 1);
  314. switch ($ch)
  315. {
  316. case '|':
  317. $res .= "\1";
  318. break;
  319. case '\\':
  320. $res .= "\2";
  321. break;
  322. case '=':
  323. $res .= "\3";
  324. break;
  325. case ',':
  326. $res .= "\4";
  327. break;
  328. default:
  329. $res .= $ch;
  330. }
  331. }
  332. }
  333. return $res;
  334. }
  335. #
  336. function revert($str)
  337. {
  338. return str_replace(array("\1", "\2", "\3", "\4"), array("|", "\\", "=", ","), $str);
  339. }
  340. #
  341. function api($cmd)
  342. {
  343. global $haderror, $error;
  344. global $miner, $port, $hidefields;
  345. $socket = getsock($miner, $port);
  346. if ($socket != null)
  347. {
  348. socket_write($socket, $cmd, strlen($cmd));
  349. $line = readsockline($socket);
  350. socket_close($socket);
  351. if (strlen($line) == 0)
  352. {
  353. $haderror = true;
  354. $error = "WARN: '$cmd' returned nothing\n";
  355. return $line;
  356. }
  357. # print "$cmd returned '$line'\n";
  358. $line = api_convert_escape($line);
  359. $data = array();
  360. $objs = explode('|', $line);
  361. foreach ($objs as $obj)
  362. {
  363. if (strlen($obj) > 0)
  364. {
  365. $items = explode(',', $obj);
  366. $item = $items[0];
  367. $id = explode('=', $items[0], 2);
  368. if (count($id) == 1 or !ctype_digit($id[1]))
  369. $name = $id[0];
  370. else
  371. $name = $id[0].$id[1];
  372. if (strlen($name) == 0)
  373. $name = 'null';
  374. $sectionname = preg_replace('/\d/', '', $name);
  375. if (isset($data[$name]))
  376. {
  377. $num = 1;
  378. while (isset($data[$name.$num]))
  379. $num++;
  380. $name .= $num;
  381. }
  382. $counter = 0;
  383. foreach ($items as $item)
  384. {
  385. $id = explode('=', $item, 2);
  386. if (isset($hidefields[$sectionname.'.'.$id[0]]))
  387. continue;
  388. if (count($id) == 2)
  389. $data[$name][$id[0]] = revert($id[1]);
  390. else
  391. $data[$name][$counter] = $id[0];
  392. $counter++;
  393. }
  394. }
  395. }
  396. return $data;
  397. }
  398. return null;
  399. }
  400. #
  401. function getparam($name, $both = false)
  402. {
  403. $a = null;
  404. if (isset($_POST[$name]))
  405. $a = $_POST[$name];
  406. if (($both === true) and ($a === null))
  407. {
  408. if (isset($_GET[$name]))
  409. $a = $_GET[$name];
  410. }
  411. if ($a == '' || $a == null)
  412. return null;
  413. // limit to 1K just to be safe
  414. return substr($a, 0, 1024);
  415. }
  416. #
  417. function newtable()
  418. {
  419. global $tablebegin, $rownum;
  420. echo $tablebegin;
  421. $rownum = 0;
  422. }
  423. #
  424. function newrow()
  425. {
  426. echo '<tr>';
  427. }
  428. #
  429. function otherrow($row)
  430. {
  431. echo "<tr>$row</tr>";
  432. }
  433. #
  434. function endrow()
  435. {
  436. global $rownum;
  437. echo '</tr>';
  438. $rownum++;
  439. }
  440. #
  441. function endtable()
  442. {
  443. global $tableend;
  444. echo $tableend;
  445. }
  446. #
  447. function classlastshare($when, $alldata, $warnclass, $errorclass)
  448. {
  449. global $checklastshare;
  450. if ($checklastshare === false)
  451. return '';
  452. if ($when == 0)
  453. return '';
  454. if (!isset($alldata['MHS av']))
  455. return '';
  456. if ($alldata['MHS av'] == 0)
  457. return '';
  458. if (!isset($alldata['Last Share Time']))
  459. return '';
  460. $expected = pow(2, 32) / ($alldata['MHS av'] * pow(10, 6));
  461. $howlong = $when - $alldata['Last Share Time'];
  462. if ($howlong < 1)
  463. $howlong = 1;
  464. if ($howlong > ($expected * 12))
  465. return $errorclass;
  466. if ($howlong > ($expected * 8))
  467. return $warnclass;
  468. return '';
  469. }
  470. #
  471. function fmt($section, $name, $value, $when, $alldata)
  472. {
  473. global $dfmt, $rownum;
  474. if ($alldata == null)
  475. $alldata = array();
  476. $errorclass = ' class=err';
  477. $warnclass = ' class=warn';
  478. $lstclass = ' class=lst';
  479. $hiclass = ' class=hi';
  480. $loclass = ' class=lo';
  481. $c2class = ' class=two';
  482. $totclass = ' class=tot';
  483. $b = '&nbsp;';
  484. $ret = $value;
  485. $class = '';
  486. $nams = explode('.', $name);
  487. if (count($nams) > 1)
  488. $name = $nams[count($nams)-1];
  489. if ($value === null)
  490. $ret = $b;
  491. else
  492. switch ($section.'.'.$name)
  493. {
  494. case 'GPU.Last Share Time':
  495. case 'PGA.Last Share Time':
  496. case 'DEVS.Last Share Time':
  497. if ($value == 0
  498. || (isset($alldata['Last Share Pool']) && $alldata['Last Share Pool'] == -1))
  499. {
  500. $ret = 'Never';
  501. $class = $warnclass;
  502. }
  503. else
  504. {
  505. $ret = date('H:i:s', $value);
  506. $class = classlastshare($when, $alldata, $warnclass, $errorclass);
  507. }
  508. break;
  509. case 'POOL.Last Share Time':
  510. if ($value == 0)
  511. $ret = 'Never';
  512. else
  513. $ret = date('H:i:s d-M', $value);
  514. break;
  515. case 'GPU.Last Share Pool':
  516. case 'PGA.Last Share Pool':
  517. case 'DEVS.Last Share Pool':
  518. if ($value == -1)
  519. {
  520. $ret = 'None';
  521. $class = $warnclass;
  522. }
  523. break;
  524. case 'SUMMARY.Elapsed':
  525. $s = $value % 60;
  526. $value -= $s;
  527. $value /= 60;
  528. if ($value == 0)
  529. $ret = $s.'s';
  530. else
  531. {
  532. $m = $value % 60;
  533. $value -= $m;
  534. $value /= 60;
  535. if ($value == 0)
  536. $ret = sprintf("%dm$b%02ds", $m, $s);
  537. else
  538. {
  539. $h = $value % 24;
  540. $value -= $h;
  541. $value /= 24;
  542. if ($value == 0)
  543. $ret = sprintf("%dh$b%02dm$b%02ds", $h, $m, $s);
  544. else
  545. {
  546. if ($value == 1)
  547. $days = '';
  548. else
  549. $days = 's';
  550. $ret = sprintf("%dday$days$b%02dh$b%02dm$b%02ds", $value, $h, $m, $s);
  551. }
  552. }
  553. }
  554. break;
  555. case 'NOTIFY.Last Well':
  556. if ($value == '0')
  557. {
  558. $ret = 'Never';
  559. $class = $warnclass;
  560. }
  561. else
  562. $ret = date('H:i:s', $value);
  563. break;
  564. case 'NOTIFY.Last Not Well':
  565. if ($value == '0')
  566. $ret = 'Never';
  567. else
  568. {
  569. $ret = date('H:i:s', $value);
  570. $class = $errorclass;
  571. }
  572. break;
  573. case 'NOTIFY.Reason Not Well':
  574. if ($value != 'None')
  575. $class = $errorclass;
  576. break;
  577. case 'GPU.Utility':
  578. case 'PGA.Utility':
  579. case 'DEVS.Utility':
  580. case 'SUMMARY.Utility':
  581. case 'total.Utility':
  582. $ret = $value.'/m';
  583. if ($value == 0)
  584. $class = $errorclass;
  585. else
  586. if (isset($alldata['MHS av']))
  587. {
  588. $expected = 60 * $alldata['MHS av'] * (pow(10, 6) / pow(2, 32));
  589. if ($expected == 0)
  590. $expected = 0.000001; // 1 H/s
  591. $ratio = $value / $expected;
  592. if ($ratio < 0.9)
  593. $class = $loclass;
  594. else
  595. if ($ratio > 1.1)
  596. $class = $hiclass;
  597. }
  598. break;
  599. case 'PGA.Temperature':
  600. case 'GPU.Temperature':
  601. case 'DEVS.Temperature':
  602. $ret = $value.'&deg;C';
  603. if (!isset($alldata['GPU']))
  604. break;
  605. case 'GPU.GPU Clock':
  606. case 'DEVS.GPU Clock':
  607. case 'GPU.Memory Clock':
  608. case 'DEVS.Memory Clock':
  609. case 'GPU.GPU Voltage':
  610. case 'DEVS.GPU Voltage':
  611. case 'GPU.GPU Activity':
  612. case 'DEVS.GPU Activity':
  613. if ($value == 0)
  614. $class = $warnclass;
  615. break;
  616. case 'GPU.Fan Percent':
  617. case 'DEVS.Fan Percent':
  618. if ($value == 0)
  619. $class = $warnclass;
  620. else
  621. {
  622. if ($value == 100)
  623. $class = $errorclass;
  624. else
  625. if ($value > 85)
  626. $class = $warnclass;
  627. }
  628. break;
  629. case 'GPU.Fan Speed':
  630. case 'DEVS.Fan Speed':
  631. if ($value == 0)
  632. $class = $warnclass;
  633. else
  634. if (isset($alldata['Fan Percent']))
  635. {
  636. $test = $alldata['Fan Percent'];
  637. if ($test == 100)
  638. $class = $errorclass;
  639. else
  640. if ($test > 85)
  641. $class = $warnclass;
  642. }
  643. break;
  644. case 'GPU.MHS av':
  645. case 'PGA.MHS av':
  646. case 'DEVS.MHS av':
  647. case 'SUMMARY.MHS av':
  648. case 'total.MHS av':
  649. $parts = explode('.', $value, 2);
  650. if (count($parts) == 1)
  651. $dec = '';
  652. else
  653. $dec = '.'.$parts[1];
  654. $ret = number_format($parts[0]).$dec;
  655. if ($value == 0)
  656. $class = $errorclass;
  657. else
  658. if (isset($alldata['Utility']))
  659. {
  660. $expected = 60 * $value * (pow(10, 6) / pow(2, 32));
  661. $utility = $alldata['Utility'];
  662. $ratio = $utility / $expected;
  663. if ($ratio < 0.9)
  664. $class = $hiclass;
  665. else
  666. if ($ratio > 1.1)
  667. $class = $loclass;
  668. }
  669. break;
  670. case 'GPU.Total MH':
  671. case 'PGA.Total MH':
  672. case 'DEVS.Total MH':
  673. case 'SUMMARY.Total MH':
  674. case 'total.Total MH':
  675. case 'SUMMARY.Getworks':
  676. case 'POOL.Getworks':
  677. case 'total.Getworks':
  678. case 'GPU.Accepted':
  679. case 'PGA.Accepted':
  680. case 'DEVS.Accepted':
  681. case 'SUMMARY.Accepted':
  682. case 'POOL.Accepted':
  683. case 'total.Accepted':
  684. case 'GPU.Rejected':
  685. case 'PGA.Rejected':
  686. case 'DEVS.Rejected':
  687. case 'SUMMARY.Rejected':
  688. case 'POOL.Rejected':
  689. case 'total.Rejected':
  690. case 'SUMMARY.Local Work':
  691. case 'total.Local Work':
  692. case 'SUMMARY.Discarded':
  693. case 'POOL.Discarded':
  694. case 'total.Discarded':
  695. $parts = explode('.', $value, 2);
  696. if (count($parts) == 1)
  697. $dec = '';
  698. else
  699. $dec = '.'.$parts[1];
  700. $ret = number_format($parts[0]).$dec;
  701. break;
  702. case 'GPU.Status':
  703. case 'PGA.Status':
  704. case 'DEVS.Status':
  705. case 'POOL.Status':
  706. if ($value != 'Alive')
  707. $class = $errorclass;
  708. break;
  709. case 'GPU.Enabled':
  710. case 'PGA.Enabled':
  711. case 'DEVS.Enabled':
  712. if ($value != 'Y')
  713. $class = $warnclass;
  714. break;
  715. case 'STATUS.When':
  716. case 'COIN.Current Block Time':
  717. $ret = date($dfmt, $value);
  718. break;
  719. case 'BUTTON.Rig':
  720. case 'BUTTON.Pool':
  721. case 'BUTTON.GPU':
  722. $ret = $value;
  723. break;
  724. }
  725. if ($section == 'NOTIFY' && substr($name, 0, 1) == '*' && $value != '0')
  726. $class = $errorclass;
  727. if ($class == '' && $section != 'POOL')
  728. $class = classlastshare($when, $alldata, $lstclass, $lstclass);
  729. if ($class == '' && $section == 'total')
  730. $class = $totclass;
  731. if ($class == '' && ($rownum % 2) == 0)
  732. $class = $c2class;
  733. if ($ret === '')
  734. $ret = $b;
  735. return array($ret, $class);
  736. }
  737. #
  738. global $poolcmd;
  739. $poolcmd = array( 'Switch to' => 'switchpool',
  740. 'Enable' => 'enablepool',
  741. 'Disable' => 'disablepool',
  742. 'Remove' => 'removepool' );
  743. #
  744. function showhead($cmd, $values, $justnames = false)
  745. {
  746. global $poolcmd, $readonly;
  747. newrow();
  748. foreach ($values as $name => $value)
  749. {
  750. if ($name == '0' or $name == '')
  751. $name = '&nbsp;';
  752. echo "<td valign=bottom class=h>$name</td>";
  753. }
  754. if ($justnames === false && $cmd == 'pools' && $readonly === false)
  755. foreach ($poolcmd as $name => $pcmd)
  756. echo "<td valign=bottom class=h>$name</td>";
  757. endrow();
  758. }
  759. #
  760. function showdatetime()
  761. {
  762. global $dfmt;
  763. otherrow('<td class=sta>Date: '.date($dfmt).'</td>');
  764. }
  765. #
  766. global $singlerigsum;
  767. $singlerigsum = array(
  768. 'devs' => array('MHS av' => 1, 'MHS 5s' => 1, 'Accepted' => 1, 'Rejected' => 1,
  769. 'Hardware Errors' => 1, 'Utility' => 1, 'Total MH' => 1),
  770. 'pools' => array('Getworks' => 1, 'Accepted' => 1, 'Rejected' => 1, 'Discarded' => 1,
  771. 'Stale' => 1, 'Get Failures' => 1, 'Remote Failures' => 1),
  772. 'notify' => array('*' => 1));
  773. #
  774. function showtotal($total, $when, $oldvalues)
  775. {
  776. global $rigtotals;
  777. list($showvalue, $class) = fmt('total', '', 'Total:', $when, null);
  778. echo "<td$class align=right>$showvalue</td>";
  779. $skipfirst = true;
  780. foreach ($oldvalues as $name => $value)
  781. {
  782. if ($skipfirst === true)
  783. {
  784. $skipfirst = false;
  785. continue;
  786. }
  787. if (isset($total[$name]))
  788. $newvalue = $total[$name];
  789. else
  790. $newvalue = '';
  791. list($showvalue, $class) = fmt('total', $name, $newvalue, $when, null);
  792. echo "<td$class";
  793. if ($rigtotals === true)
  794. echo ' align=right';
  795. echo ">$showvalue</td>";
  796. }
  797. }
  798. #
  799. function details($cmd, $list, $rig)
  800. {
  801. global $dfmt, $poolcmd, $readonly, $showndate;
  802. global $rownum, $rigtotals, $forcerigtotals, $singlerigsum;
  803. $when = 0;
  804. $stas = array('S' => 'Success', 'W' => 'Warning', 'I' => 'Informational', 'E' => 'Error', 'F' => 'Fatal');
  805. newtable();
  806. if ($showndate === false)
  807. {
  808. showdatetime();
  809. endtable();
  810. newtable();
  811. $showndate = true;
  812. }
  813. if (isset($list['STATUS']))
  814. {
  815. newrow();
  816. echo '<td>Computer: '.$list['STATUS']['Description'].'</td>';
  817. if (isset($list['STATUS']['When']))
  818. {
  819. echo '<td>When: '.date($dfmt, $list['STATUS']['When']).'</td>';
  820. $when = $list['STATUS']['When'];
  821. }
  822. $sta = $list['STATUS']['STATUS'];
  823. echo '<td>Status: '.$stas[$sta].'</td>';
  824. echo '<td>Message: '.$list['STATUS']['Msg'].'</td>';
  825. endrow();
  826. }
  827. if ($rigtotals === true && isset($singlerigsum[$cmd]))
  828. $dototal = $singlerigsum[$cmd];
  829. else
  830. $dototal = array();
  831. $total = array();
  832. $section = '';
  833. $oldvalues = null;
  834. foreach ($list as $item => $values)
  835. {
  836. if ($item == 'STATUS')
  837. continue;
  838. $sectionname = preg_replace('/\d/', '', $item);
  839. // Handle 'devs' possibly containing >1 table
  840. if ($sectionname != $section)
  841. {
  842. if ($oldvalues != null && count($total) > 0
  843. && ($rownum > 2 || $forcerigtotals === true))
  844. showtotal($total, $when, $oldvalues);
  845. endtable();
  846. newtable();
  847. showhead($cmd, $values);
  848. $section = $sectionname;
  849. }
  850. newrow();
  851. foreach ($values as $name => $value)
  852. {
  853. list($showvalue, $class) = fmt($section, $name, $value, $when, $values);
  854. echo "<td$class";
  855. if ($rigtotals === true)
  856. echo ' align=right';
  857. echo ">$showvalue</td>";
  858. if (isset($dototal[$name])
  859. || (isset($dototal['*']) and substr($name, 0, 1) == '*'))
  860. {
  861. if (isset($total[$name]))
  862. $total[$name] += $value;
  863. else
  864. $total[$name] = $value;
  865. }
  866. }
  867. if ($cmd == 'pools' && $readonly === false)
  868. {
  869. reset($values);
  870. $pool = current($values);
  871. foreach ($poolcmd as $name => $pcmd)
  872. {
  873. list($ignore, $class) = fmt('BUTTON', 'Pool', '', $when, $values);
  874. echo "<td$class>";
  875. if ($pool === false)
  876. echo '&nbsp;';
  877. else
  878. {
  879. echo "<input type=button value='Pool $pool'";
  880. echo " onclick='prc(\"$pcmd|$pool&rig=$rig\",\"$name Pool $pool\")'>";
  881. }
  882. echo '</td>';
  883. }
  884. }
  885. endrow();
  886. $oldvalues = $values;
  887. }
  888. if ($oldvalues != null && count($total) > 0
  889. && ($rownum > 2 || $forcerigtotals === true))
  890. showtotal($total, $when, $oldvalues);
  891. endtable();
  892. }
  893. #
  894. global $devs;
  895. $devs = null;
  896. #
  897. function gpubuttons($count, $rig)
  898. {
  899. global $devs;
  900. $basic = array( 'GPU', 'Enable', 'Disable', 'Restart' );
  901. $options = array( 'intensity' => 'Intensity',
  902. 'fan' => 'Fan Percent',
  903. 'engine' => 'GPU Clock',
  904. 'mem' => 'Memory Clock',
  905. 'vddc' => 'GPU Voltage' );
  906. newtable();
  907. newrow();
  908. foreach ($basic as $head)
  909. echo "<td class=h>$head</td>";
  910. foreach ($options as $name => $des)
  911. echo "<td class=h nowrap>$des</td>";
  912. $n = 0;
  913. for ($c = 0; $c < $count; $c++)
  914. {
  915. endrow();
  916. newrow();
  917. foreach ($basic as $name)
  918. {
  919. list($ignore, $class) = fmt('BUTTON', 'GPU', '', 0, null);
  920. echo "<td$class>";
  921. if ($name == 'GPU')
  922. echo $c;
  923. else
  924. {
  925. echo "<input type=button value='$name $c' onclick='prs(\"gpu";
  926. echo strtolower($name);
  927. echo "|$c\",$rig)'>";
  928. }
  929. echo '</td>';
  930. }
  931. foreach ($options as $name => $des)
  932. {
  933. list($ignore, $class) = fmt('BUTTON', 'GPU', '', 0, null);
  934. echo "<td$class>";
  935. if (!isset($devs["GPU$c"][$des]))
  936. echo '&nbsp;';
  937. else
  938. {
  939. $value = $devs["GPU$c"][$des];
  940. echo "<input type=button value='Set $c:' onclick='prs2(\"gpu$name|$c\",$n,$rig)'>";
  941. echo "<input size=7 type=text name=gi$n value='$value' id=gi$n>";
  942. $n++;
  943. }
  944. echo '</td>';
  945. }
  946. }
  947. endrow();
  948. endtable();
  949. }
  950. #
  951. function processgpus($rig)
  952. {
  953. global $error;
  954. global $warnfont, $warnoff;
  955. $gpus = api('gpucount');
  956. if ($error != null)
  957. otherrow("<td>Error getting GPU count: $warnfont$error$warnoff</td>");
  958. else
  959. {
  960. if (!isset($gpus['GPUS']['Count']))
  961. {
  962. $rw = '<td>No GPU count returned: '.$warnfont;
  963. $rw .= $gpus['STATUS']['STATUS'].' '.$gpus['STATUS']['Msg'];
  964. $rw .= $warnoff.'</td>';
  965. otherrow($rw);
  966. }
  967. else
  968. {
  969. $count = $gpus['GPUS']['Count'];
  970. if ($count == 0)
  971. otherrow('<td>No GPUs</td>');
  972. else
  973. gpubuttons($count, $rig);
  974. }
  975. }
  976. }
  977. #
  978. function showpoolinputs($rig, $ans)
  979. {
  980. global $readonly, $poolinputs;
  981. if ($readonly === true || $poolinputs === false)
  982. return;
  983. newtable();
  984. newrow();
  985. $inps = array('Pool URL' => array('purl', 20),
  986. 'Worker Name' => array('pwork', 10),
  987. 'Worker Password' => array('ppass', 10));
  988. $b = '&nbsp;';
  989. echo "<td align=right class=h> Add a pool: </td><td>";
  990. foreach ($inps as $text => $name)
  991. echo "$text: <input name='".$name[0]."' id='".$name[0]."' value='' type=text size=".$name[1]."> ";
  992. echo "</td><td align=middle><input type=button value='Add' onclick='pla($rig)'></td>";
  993. endrow();
  994. if (count($ans) > 1)
  995. {
  996. newrow();
  997. echo '<td align=right class=h> Set pool priorities: </td>';
  998. echo "<td> Comma list of pool numbers: <input type=text name=prio id=prio size=20>";
  999. echo "</td><td align=middle><input type=button value='Set' onclick='psp($rig)'></td>";
  1000. endrow();
  1001. }
  1002. endtable();
  1003. }
  1004. #
  1005. function process($cmds, $rig)
  1006. {
  1007. global $error, $devs;
  1008. global $warnfont, $warnoff;
  1009. $count = count($cmds);
  1010. foreach ($cmds as $cmd => $des)
  1011. {
  1012. $process = api($cmd);
  1013. if ($error != null)
  1014. {
  1015. otherrow("<td colspan=100>Error getting $des: $warnfont$error$warnoff</td>");
  1016. break;
  1017. }
  1018. else
  1019. {
  1020. details($cmd, $process, $rig);
  1021. if ($cmd == 'devs')
  1022. $devs = $process;
  1023. if ($cmd == 'pools')
  1024. showpoolinputs($rig, $process);
  1025. # Not after the last one
  1026. if (--$count > 0)
  1027. otherrow('<td><br><br></td>');
  1028. }
  1029. }
  1030. }
  1031. #
  1032. function rigbutton($rig, $rigname, $when, $row)
  1033. {
  1034. global $rigs;
  1035. if (isset($rigs[$rig]))
  1036. {
  1037. $parts = explode(':', $rigs[$rig], 3);
  1038. if (count($parts) == 3)
  1039. $rigname = $parts[2];
  1040. }
  1041. list($value, $class) = fmt('BUTTON', 'Rig', '', $when, $row);
  1042. $button = "<td align=middle$class><input type=button value='$rigname'";
  1043. $button .= " onclick='pr(\"&rig=$rig\",null)'></td>";
  1044. return $button;
  1045. }
  1046. #
  1047. function showrigs($anss, $headname, $rigname)
  1048. {
  1049. $dthead = array($headname => 1, 'STATUS' => 1, 'Description' => 1, 'When' => 1, 'API' => 1, 'CGMiner' => 1);
  1050. showhead('', $dthead);
  1051. foreach ($anss as $rig => $ans)
  1052. {
  1053. if ($ans == null)
  1054. continue;
  1055. newrow();
  1056. $when = 0;
  1057. if (isset($ans['STATUS']['When']))
  1058. $when = $ans['STATUS']['When'];
  1059. foreach ($ans as $item => $row)
  1060. {
  1061. if ($item != 'STATUS' && $item != 'VERSION')
  1062. continue;
  1063. foreach ($dthead as $name => $x)
  1064. {
  1065. if ($item == 'STATUS' && $name == $headname)
  1066. echo rigbutton($rig, $rigname.$rig, $when, null);
  1067. else
  1068. {
  1069. if (isset($row[$name]))
  1070. {
  1071. list($showvalue, $class) = fmt('STATUS', $name, $row[$name], $when, null);
  1072. echo "<td$class align=right>$showvalue</td>";
  1073. }
  1074. }
  1075. }
  1076. }
  1077. endrow();
  1078. }
  1079. }
  1080. #
  1081. # $head is a hack but this is just a demo anyway :)
  1082. function doforeach($cmd, $des, $sum, $head, $datetime)
  1083. {
  1084. global $miner, $port;
  1085. global $error, $readonly, $notify, $rigs;
  1086. global $warnfont, $warnoff, $dfmt;
  1087. global $rigerror;
  1088. $when = 0;
  1089. $header = $head;
  1090. $anss = array();
  1091. $count = 0;
  1092. $preverr = count($rigerror);
  1093. foreach ($rigs as $num => $rig)
  1094. {
  1095. $anss[$num] = null;
  1096. if (isset($rigerror[$rig]))
  1097. continue;
  1098. $parts = explode(':', $rig, 3);
  1099. if (count($parts) >= 2)
  1100. {
  1101. $miner = $parts[0];
  1102. $port = $parts[1];
  1103. if (count($parts) > 2)
  1104. $name = $parts[2];
  1105. else
  1106. $name = $num;
  1107. $ans = api($cmd);
  1108. if ($error != null)
  1109. {
  1110. $rw = "<td colspan=100>Error on rig $name getting ";
  1111. $rw .= "$des: $warnfont$error$warnoff</td>";
  1112. otherrow($rw);
  1113. $rigerror[$rig] = $error;
  1114. $error = null;
  1115. }
  1116. else
  1117. {
  1118. $anss[$num] = $ans;
  1119. $count++;
  1120. }
  1121. }
  1122. }
  1123. if ($count == 0)
  1124. {
  1125. $rw = '<td>Failed to access any rigs successfully';
  1126. if ($preverr > 0)
  1127. $rw .= ' (or rigs had previous errors)';
  1128. $rw .= '</td>';
  1129. otherrow($rw);
  1130. return;
  1131. }
  1132. if ($datetime)
  1133. {
  1134. showdatetime();
  1135. endtable();
  1136. newtable();
  1137. showrigs($anss, '', 'Rig ');
  1138. endtable();
  1139. otherrow('<td><br><br></td>');
  1140. newtable();
  1141. return;
  1142. }
  1143. $total = array();
  1144. foreach ($anss as $rig => $ans)
  1145. {
  1146. if ($ans == null)
  1147. continue;
  1148. foreach ($ans as $item => $row)
  1149. {
  1150. if ($item == 'STATUS')
  1151. continue;
  1152. if (count($row) > count($header))
  1153. {
  1154. $header = $head;
  1155. foreach ($row as $name => $value)
  1156. if (!isset($header[$name]))
  1157. $header[$name] = '';
  1158. }
  1159. if ($sum != null)
  1160. foreach ($sum as $name)
  1161. {
  1162. if (isset($row[$name]))
  1163. {
  1164. if (isset($total[$name]))
  1165. $total[$name] += $row[$name];
  1166. else
  1167. $total[$name] = $row[$name];
  1168. }
  1169. }
  1170. }
  1171. }
  1172. if ($sum != null)
  1173. $anss['total']['total'] = $total;
  1174. showhead('', $header);
  1175. foreach ($anss as $rig => $ans)
  1176. {
  1177. if ($ans == null)
  1178. continue;
  1179. $when = 0;
  1180. if (isset($ans['STATUS']['When']))
  1181. $when = $ans['STATUS']['When'];
  1182. foreach ($ans as $item => $row)
  1183. {
  1184. if ($item == 'STATUS')
  1185. continue;
  1186. newrow();
  1187. $section = preg_replace('/\d/', '', $item);
  1188. foreach ($header as $name => $x)
  1189. {
  1190. if ($name == '')
  1191. {
  1192. if ($rig === 'total')
  1193. {
  1194. list($ignore, $class) = fmt($rig, '', '', $when, $row);
  1195. echo "<td align=right$class>Total:</td>";
  1196. }
  1197. else
  1198. echo rigbutton($rig, "Rig $rig", $when, $row);
  1199. }
  1200. else
  1201. {
  1202. if (isset($row[$name]))
  1203. $value = $row[$name];
  1204. else
  1205. $value = null;
  1206. list($showvalue, $class) = fmt($section, $name, $value, $when, $row);
  1207. echo "<td$class align=right>$showvalue</td>";
  1208. }
  1209. }
  1210. endrow();
  1211. }
  1212. }
  1213. }
  1214. #
  1215. function refreshbuttons()
  1216. {
  1217. global $readonly;
  1218. global $ignorerefresh, $changerefresh, $autorefresh;
  1219. if ($ignorerefresh == false && $changerefresh == true)
  1220. {
  1221. echo '&nbsp;&nbsp;&nbsp;&nbsp;';
  1222. echo "<input type=button value='Auto Refresh:' onclick='prr(true)'>";
  1223. echo "<input type=text name='refval' id='refval' size=2 value='$autorefresh'>";
  1224. echo "<input type=button value='Off' onclick='prr(false)'>";
  1225. }
  1226. }
  1227. #
  1228. function pagebuttons($rig, $pg)
  1229. {
  1230. global $readonly, $rigs;
  1231. global $allowcustompages, $customsummarypages;
  1232. if ($rig === null)
  1233. {
  1234. if ($pg === null)
  1235. $refresh = '';
  1236. else
  1237. $refresh = "&pg=$pg";
  1238. }
  1239. else
  1240. $refresh = "&rig=$rig";
  1241. echo '<tr><td><table cellpadding=0 cellspacing=0 border=0><tr><td nowrap>';
  1242. echo "<input type=button value='Refresh' onclick='pr(\"$refresh\",null)'>&nbsp;";
  1243. if (count($rigs) > 1)
  1244. echo "<input type=button value='Summary' onclick='pr(\"\",null)'>&nbsp;";
  1245. if ($allowcustompages === true)
  1246. foreach ($customsummarypages as $pagename => $data)
  1247. echo "<input type=button value='$pagename' onclick='pr(\"&pg=$pagename\",null)'>&nbsp;";
  1248. echo '</td><td width=100%>&nbsp;</td><td nowrap>';
  1249. if ($rig !== null && $readonly === false)
  1250. {
  1251. $rg = '';
  1252. if (count($rigs) > 1)
  1253. $rg = " Rig $rig";
  1254. echo "<input type=button value='Restart' onclick='prc(\"restart&rig=$rig\",\"Restart BFGMiner$rg\")'>";
  1255. echo "&nbsp;<input type=button value='Quit' onclick='prc(\"quit&rig=$rig\",\"Quit BFGMiner$rg\")'>";
  1256. }
  1257. refreshbuttons();
  1258. echo "</td></tr></table></td></tr>";
  1259. }
  1260. #
  1261. function doOne($rig, $preprocess)
  1262. {
  1263. global $haderror, $readonly, $notify, $rigs;
  1264. global $placebuttons;
  1265. htmlhead(true, $rig);
  1266. if ($placebuttons == 'top' || $placebuttons == 'both')
  1267. pagebuttons($rig, null);
  1268. if ($preprocess != null)
  1269. process(array($preprocess => $preprocess), $rig);
  1270. $cmds = array( 'devs' => 'device list',
  1271. 'summary' => 'summary information',
  1272. 'pools' => 'pool list');
  1273. if ($notify)
  1274. $cmds['notify'] = 'device status';
  1275. $cmds['config'] = 'BFGMiner config';
  1276. process($cmds, $rig);
  1277. if ($haderror == false && $readonly === false)
  1278. processgpus($rig);
  1279. if ($placebuttons == 'bot' || $placebuttons == 'both')
  1280. pagebuttons($rig, null);
  1281. }
  1282. #
  1283. global $sectionmap;
  1284. # map sections to their api command
  1285. # DEVS is a special case that will match GPU or PGA
  1286. # so you can have a single table with both in it
  1287. # DATE is hard coded so not in here
  1288. $sectionmap = array(
  1289. 'RIGS' => 'version',
  1290. 'SUMMARY' => 'summary',
  1291. 'POOL' => 'pools',
  1292. 'DEVS' => 'devs',
  1293. 'GPU' => 'devs', // You would normally use DEVS
  1294. 'PGA' => 'devs', // You would normally use DEVS
  1295. 'NOTIFY' => 'notify',
  1296. 'DEVDETAILS' => 'devdetails',
  1297. 'STATS' => 'stats',
  1298. 'CONFIG' => 'config',
  1299. 'COIN' => 'coin');
  1300. #
  1301. function joinfields($section1, $section2, $join, $results)
  1302. {
  1303. global $sectionmap;
  1304. $name1 = $sectionmap[$section1];
  1305. $name2 = $sectionmap[$section2];
  1306. $newres = array();
  1307. // foreach rig in section1
  1308. foreach ($results[$name1] as $rig => $result)
  1309. {
  1310. $status = null;
  1311. // foreach answer section in the rig api call
  1312. foreach ($result as $name1b => $fields1b)
  1313. {
  1314. if ($name1b == 'STATUS')
  1315. {
  1316. // remember the STATUS from section1
  1317. $status = $result[$name1b];
  1318. continue;
  1319. }
  1320. // foreach answer section in the rig api call (for the other api command)
  1321. foreach ($results[$name2][$rig] as $name2b => $fields2b)
  1322. {
  1323. if ($name2b == 'STATUS')
  1324. continue;
  1325. // If match the same field values of fields in $join
  1326. $match = true;
  1327. foreach ($join as $field)
  1328. if ($fields1b[$field] != $fields2b[$field])
  1329. {
  1330. $match = false;
  1331. break;
  1332. }
  1333. if ($match === true)
  1334. {
  1335. if ($status != null)
  1336. {
  1337. $newres[$rig]['STATUS'] = $status;
  1338. $status = null;
  1339. }
  1340. $subsection = $section1.'+'.$section2;
  1341. $subsection .= preg_replace('/[^0-9]/', '', $name1b.$name2b);
  1342. foreach ($fields1b as $nam => $val)
  1343. $newres[$rig][$subsection]["$section1.$nam"] = $val;
  1344. foreach ($fields2b as $nam => $val)
  1345. $newres[$rig][$subsection]["$section2.$nam"] = $val;
  1346. }
  1347. }
  1348. }
  1349. }
  1350. return $newres;
  1351. }
  1352. #
  1353. function joinall($section1, $section2, $results)
  1354. {
  1355. global $sectionmap;
  1356. $name1 = $sectionmap[$section1];
  1357. $name2 = $sectionmap[$section2];
  1358. $newres = array();
  1359. // foreach rig in section1
  1360. foreach ($results[$name1] as $rig => $result)
  1361. {
  1362. // foreach answer section in the rig api call
  1363. foreach ($result as $name1b => $fields1b)
  1364. {
  1365. if ($name1b == 'STATUS')
  1366. {
  1367. // copy the STATUS from section1
  1368. $newres[$rig][$name1b] = $result[$name1b];
  1369. continue;
  1370. }
  1371. // foreach answer section in the rig api call (for the other api command)
  1372. foreach ($results[$name2][$rig] as $name2b => $fields2b)
  1373. {
  1374. if ($name2b == 'STATUS')
  1375. continue;
  1376. $subsection = $section1.'+'.$section2;
  1377. $subsection .= preg_replace('/[^0-9]/', '', $name1b.$name2b);
  1378. foreach ($fields1b as $nam => $val)
  1379. $newres[$rig][$subsection]["$section1.$nam"] = $val;
  1380. foreach ($fields2b as $nam => $val)
  1381. $newres[$rig][$subsection]["$section2.$nam"] = $val;
  1382. }
  1383. }
  1384. }
  1385. return $newres;
  1386. }
  1387. #
  1388. function joinsections($sections, $results, $errors)
  1389. {
  1390. global $sectionmap;
  1391. #echo "results['pools']=".print_r($results['pools'],true)."<br>";
  1392. // GPU's don't have Name,ID fields - so create them
  1393. foreach ($results as $section => $res)
  1394. foreach ($res as $rig => $result)
  1395. foreach ($result as $name => $fields)
  1396. {
  1397. $subname = preg_replace('/[0-9]/', '', $name);
  1398. if ($subname == 'GPU' and isset($result[$name]['GPU']))
  1399. {
  1400. $results[$section][$rig][$name]['Name'] = 'GPU';
  1401. $results[$section][$rig][$name]['ID'] = $result[$name]['GPU'];
  1402. }
  1403. }
  1404. foreach ($sections as $section => $fields)
  1405. if ($section != 'DATE' && !isset($sectionmap[$section]))
  1406. {
  1407. $both = explode('+', $section, 2);
  1408. if (count($both) > 1)
  1409. {
  1410. switch($both[0])
  1411. {
  1412. case 'SUMMARY':
  1413. switch($both[1])
  1414. {
  1415. case 'POOL':
  1416. case 'DEVS':
  1417. case 'CONFIG':
  1418. case 'COIN':
  1419. $sectionmap[$section] = $section;
  1420. $results[$section] = joinall($both[0], $both[1], $results);
  1421. break;
  1422. default:
  1423. $errors[] = "Error: Invalid section '$section'";
  1424. break;
  1425. }
  1426. break;
  1427. case 'DEVS':
  1428. $join = array('Name', 'ID');
  1429. switch($both[1])
  1430. {
  1431. case 'NOTIFY':
  1432. case 'DEVDETAILS':
  1433. $sectionmap[$section] = $section;
  1434. $results[$section] = joinfields($both[0], $both[1], $join, $results);
  1435. break;
  1436. default:
  1437. $errors[] = "Error: Invalid section '$section'";
  1438. break;
  1439. }
  1440. break;
  1441. default:
  1442. $errors[] = "Error: Invalid section '$section'";
  1443. break;
  1444. }
  1445. }
  1446. else
  1447. $errors[] = "Error: Invalid section '$section'";
  1448. }
  1449. return array($results, $errors);
  1450. }
  1451. #
  1452. function secmatch($section, $field)
  1453. {
  1454. if ($section == $field)
  1455. return true;
  1456. if ($section == 'DEVS'
  1457. && ($field == 'GPU' || $field == 'PGA'))
  1458. return true;
  1459. return false;
  1460. }
  1461. #
  1462. function customset($showfields, $sum, $section, $rig, $isbutton, $result, $total)
  1463. {
  1464. foreach ($result as $sec => $row)
  1465. {
  1466. $secname = preg_replace('/\d/', '', $sec);
  1467. if ($sec != 'total')
  1468. if (!secmatch($section, $secname))
  1469. continue;
  1470. newrow();
  1471. $when = 0;
  1472. if (isset($result['STATUS']['When']))
  1473. $when = $result['STATUS']['When'];
  1474. if ($isbutton)
  1475. echo rigbutton($rig, $rig, $when, $row);
  1476. else
  1477. {
  1478. list($ignore, $class) = fmt('total', '', '', $when, $row);
  1479. echo "<td align=middle$class>$rig</td>";
  1480. }
  1481. foreach ($showfields as $name => $one)
  1482. {
  1483. if (isset($row[$name]))
  1484. {
  1485. $value = $row[$name];
  1486. if (isset($sum[$section][$name]))
  1487. {
  1488. if (isset($total[$name]))
  1489. $total[$name] += $value;
  1490. else
  1491. $total[$name] = $value;
  1492. }
  1493. }
  1494. else
  1495. {
  1496. if ($sec == 'total' && isset($total[$name]))
  1497. $value = $total[$name];
  1498. else
  1499. $value = null;
  1500. }
  1501. if (strpos($secname, '+') === false)
  1502. list($showvalue, $class) = fmt($secname, $name, $value, $when, $row);
  1503. else
  1504. {
  1505. $parts = explode('.', $name, 2);
  1506. list($showvalue, $class) = fmt($parts[0], $parts[1], $value, $when, $row);
  1507. }
  1508. echo "<td$class align=right>$showvalue</td>";
  1509. }
  1510. endrow();
  1511. }
  1512. return $total;
  1513. }
  1514. #
  1515. function processcustompage($pagename, $sections, $sum, $namemap)
  1516. {
  1517. global $sectionmap;
  1518. global $miner, $port;
  1519. global $rigs, $error;
  1520. global $warnfont, $warnoff;
  1521. global $dfmt;
  1522. global $readonly, $showndate;
  1523. $cmds = array();
  1524. $errors = array();
  1525. foreach ($sections as $section => $fields)
  1526. {
  1527. $all = explode('+', $section);
  1528. foreach ($all as $section)
  1529. {
  1530. if (isset($sectionmap[$section]))
  1531. {
  1532. $cmd = $sectionmap[$section];
  1533. if (!isset($cmds[$cmd]))
  1534. $cmds[$cmd] = 1;
  1535. }
  1536. else
  1537. if ($section != 'DATE')
  1538. $errors[] = "Error: unknown section '$section' in custom summary page '$pagename'";
  1539. }
  1540. }
  1541. $results = array();
  1542. foreach ($rigs as $num => $rig)
  1543. {
  1544. $parts = explode(':', $rig, 3);
  1545. if (count($parts) >= 2)
  1546. {
  1547. $miner = $parts[0];
  1548. $port = $parts[1];
  1549. if (count($parts) > 2)
  1550. $name = $parts[2];
  1551. else
  1552. $name = $rig;
  1553. foreach ($cmds as $cmd => $one)
  1554. {
  1555. $process = api($cmd);
  1556. if ($error != null)
  1557. {
  1558. $errors[] = "Error getting $cmd for $name $warnfont$error$warnoff";
  1559. break;
  1560. }
  1561. else
  1562. $results[$cmd][$num] = $process;
  1563. }
  1564. }
  1565. }
  1566. $shownsomething = false;
  1567. if (count($results) > 0)
  1568. {
  1569. list($results, $errors) = joinsections($sections, $results, $errors);
  1570. $first = true;
  1571. foreach ($sections as $section => $fields)
  1572. {
  1573. if ($section === 'DATE')
  1574. {
  1575. if ($shownsomething)
  1576. otherrow('<td>&nbsp;</td>');
  1577. newtable();
  1578. showdatetime();
  1579. endtable();
  1580. // On top of the next table
  1581. $shownsomething = false;
  1582. continue;
  1583. }
  1584. if ($section === 'RIGS')
  1585. {
  1586. if ($shownsomething)
  1587. otherrow('<td>&nbsp;</td>');
  1588. newtable();
  1589. showrigs($results['version'], 'Rig', '');
  1590. endtable();
  1591. $shownsomething = true;
  1592. continue;
  1593. }
  1594. if (isset($results[$sectionmap[$section]]))
  1595. {
  1596. $rigresults = $results[$sectionmap[$section]];
  1597. $showfields = array();
  1598. $showhead = array();
  1599. foreach ($fields as $field)
  1600. foreach ($rigresults as $result)
  1601. foreach ($result as $sec => $row)
  1602. {
  1603. $secname = preg_replace('/\d/', '', $sec);
  1604. if (secmatch($section, $secname))
  1605. {
  1606. if ($field === '*')
  1607. {
  1608. foreach ($row as $f => $v)
  1609. {
  1610. $showfields[$f] = 1;
  1611. $map = $section.'.'.$f;
  1612. if (isset($namemap[$map]))
  1613. $showhead[$namemap[$map]] = 1;
  1614. else
  1615. $showhead[$f] = 1;
  1616. }
  1617. }
  1618. elseif (isset($row[$field]))
  1619. {
  1620. $showfields[$field] = 1;
  1621. $map = $section.'.'.$field;
  1622. if (isset($namemap[$map]))
  1623. $showhead[$namemap[$map]] = 1;
  1624. else
  1625. $showhead[$field] = 1;
  1626. }
  1627. }
  1628. }
  1629. if (count($showfields) > 0)
  1630. {
  1631. if ($shownsomething)
  1632. otherrow('<td>&nbsp;</td>');
  1633. newtable();
  1634. showhead('', array('Rig'=>1)+$showhead, true);
  1635. $total = array();
  1636. $add = array('total' => array());
  1637. foreach ($rigresults as $num => $result)
  1638. $total = customset($showfields, $sum, $section, $num, true, $result, $total);
  1639. if (count($total) > 0)
  1640. customset($showfields, $sum, $section, '&Sigma;', false, $add, $total);
  1641. $first = false;
  1642. endtable();
  1643. $shownsomething = true;
  1644. }
  1645. }
  1646. }
  1647. }
  1648. if (count($errors) > 0)
  1649. {
  1650. if (count($results) > 0)
  1651. otherrow('<td>&nbsp;</td>');
  1652. foreach ($errors as $err)
  1653. otherrow("<td colspan=100>$err</td>");
  1654. }
  1655. }
  1656. #
  1657. function showcustompage($pagename)
  1658. {
  1659. global $customsummarypages;
  1660. global $placebuttons;
  1661. htmlhead(false, null, $pagename);
  1662. if ($placebuttons == 'top' || $placebuttons == 'both')
  1663. pagebuttons(null, $pagename);
  1664. if (!isset($customsummarypages[$pagename]))
  1665. {
  1666. otherrow("<td colspan=100>Unknown custom summary page '$pagename'</td>");
  1667. return;
  1668. }
  1669. if (count($customsummarypages[$pagename]) != 2)
  1670. {
  1671. $rw = "<td colspan=100>Invalid custom summary page '$pagename' (";
  1672. $rw .= count($customsummarypages[$pagename]).')</td>';
  1673. otherrow($rw);
  1674. return;
  1675. }
  1676. $page = $customsummarypages[$pagename][0];
  1677. $namemap = array();
  1678. foreach ($page as $name => $fields)
  1679. {
  1680. if ($fields === null)
  1681. $page[$name] = array();
  1682. else
  1683. foreach ($fields as $num => $field)
  1684. {
  1685. $pos = strpos($field, '=');
  1686. if ($pos !== false)
  1687. {
  1688. $names = explode('=', $field, 2);
  1689. if (strlen($names[1]) > 0)
  1690. $namemap[$name.'.'.$names[0]] = $names[1];
  1691. $page[$name][$num] = $names[0];
  1692. }
  1693. }
  1694. }
  1695. $sum = $customsummarypages[$pagename][1];
  1696. if ($sum === null)
  1697. $sum = array();
  1698. // convert them to searchable via isset()
  1699. foreach ($sum as $section => $fields)
  1700. {
  1701. $newfields = array();
  1702. foreach ($fields as $field)
  1703. $newfields[$field] = 1;
  1704. $sum[$section] = $newfields;
  1705. }
  1706. if (count($page) <= 1)
  1707. {
  1708. otherrow("<td colspan=100>Invalid custom summary page '$pagename' no content </td>");
  1709. return;
  1710. }
  1711. processcustompage($pagename, $page, $sum, $namemap);
  1712. if ($placebuttons == 'bot' || $placebuttons == 'both')
  1713. pagebuttons(null, $pagename);
  1714. }
  1715. #
  1716. function display()
  1717. {
  1718. global $miner, $port;
  1719. global $readonly, $notify, $rigs;
  1720. global $ignorerefresh, $autorefresh;
  1721. global $allowcustompages;
  1722. global $placebuttons;
  1723. if ($ignorerefresh == false)
  1724. {
  1725. $ref = trim(getparam('ref', true));
  1726. if ($ref != null && $ref != '')
  1727. $autorefresh = intval($ref);
  1728. }
  1729. $rig = trim(getparam('rig', true));
  1730. $arg = trim(getparam('arg', true));
  1731. $preprocess = null;
  1732. if ($arg != null and $arg != '')
  1733. {
  1734. $num = null;
  1735. if ($rig != null and $rig != '')
  1736. {
  1737. if ($rig >= 0 and $rig < count($rigs))
  1738. $num = $rig;
  1739. }
  1740. else
  1741. if (count($rigs) == 0)
  1742. $num = 0;
  1743. if ($num != null)
  1744. {
  1745. $parts = explode(':', $rigs[$num], 3);
  1746. if (count($parts) >= 2)
  1747. {
  1748. $miner = $parts[0];
  1749. $port = $parts[1];
  1750. if ($readonly !== true)
  1751. $preprocess = $arg;
  1752. }
  1753. }
  1754. }
  1755. if ($rigs == null or count($rigs) == 0)
  1756. {
  1757. otherrow("<td>No rigs defined</td>");
  1758. return;
  1759. }
  1760. if ($allowcustompages === true)
  1761. {
  1762. $pg = trim(getparam('pg', true));
  1763. if ($pg != null && $pg != '')
  1764. {
  1765. showcustompage($pg);
  1766. return;
  1767. }
  1768. }
  1769. if (count($rigs) == 1)
  1770. {
  1771. $parts = explode(':', $rigs[0], 3);
  1772. if (count($parts) >= 2)
  1773. {
  1774. $miner = $parts[0];
  1775. $port = $parts[1];
  1776. doOne(0, $preprocess);
  1777. }
  1778. else
  1779. otherrow('<td>Invalid "$rigs" array</td>');
  1780. return;
  1781. }
  1782. if ($rig != null and $rig != '' and $rig >= 0 and $rig < count($rigs))
  1783. {
  1784. $parts = explode(':', $rigs[$rig], 3);
  1785. if (count($parts) >= 2)
  1786. {
  1787. $miner = $parts[0];
  1788. $port = $parts[1];
  1789. doOne($rig, $preprocess);
  1790. }
  1791. else
  1792. otherrow('<td>Invalid "$rigs" array</td>');
  1793. return;
  1794. }
  1795. htmlhead(false, null);
  1796. if ($placebuttons == 'top' || $placebuttons == 'both')
  1797. pagebuttons(null, null);
  1798. if ($preprocess != null)
  1799. process(array($preprocess => $preprocess), $rig);
  1800. newtable();
  1801. doforeach('version', 'rig summary', array(), array(), true);
  1802. $sum = array('MHS av', 'Getworks', 'Found Blocks', 'Accepted', 'Rejected', 'Discarded', 'Stale', 'Utility', 'Local Work', 'Total MH');
  1803. doforeach('summary', 'summary information', $sum, array(), false);
  1804. endtable();
  1805. otherrow('<td><br><br></td>');
  1806. newtable();
  1807. doforeach('devs', 'device list', $sum, array(''=>'','ID'=>'','Name'=>''), false);
  1808. endtable();
  1809. otherrow('<td><br><br></td>');
  1810. newtable();
  1811. doforeach('pools', 'pool list', $sum, array(''=>''), false);
  1812. endtable();
  1813. if ($placebuttons == 'bot' || $placebuttons == 'both')
  1814. pagebuttons(null, null);
  1815. }
  1816. #
  1817. display();
  1818. #
  1819. ?>
  1820. </table></td></tr></table>
  1821. </body></html>