miner.php 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049
  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 cgminer '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 cgminer 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. $ret = date($dfmt, $value);
  717. break;
  718. case 'BUTTON.Rig':
  719. case 'BUTTON.Pool':
  720. case 'BUTTON.GPU':
  721. $ret = $value;
  722. break;
  723. }
  724. if ($section == 'NOTIFY' && substr($name, 0, 1) == '*' && $value != '0')
  725. $class = $errorclass;
  726. if ($class == '' && $section != 'POOL')
  727. $class = classlastshare($when, $alldata, $lstclass, $lstclass);
  728. if ($class == '' && $section == 'total')
  729. $class = $totclass;
  730. if ($class == '' && ($rownum % 2) == 0)
  731. $class = $c2class;
  732. if ($ret === '')
  733. $ret = $b;
  734. return array($ret, $class);
  735. }
  736. #
  737. global $poolcmd;
  738. $poolcmd = array( 'Switch to' => 'switchpool',
  739. 'Enable' => 'enablepool',
  740. 'Disable' => 'disablepool',
  741. 'Remove' => 'removepool' );
  742. #
  743. function showhead($cmd, $values, $justnames = false)
  744. {
  745. global $poolcmd, $readonly;
  746. newrow();
  747. foreach ($values as $name => $value)
  748. {
  749. if ($name == '0' or $name == '')
  750. $name = '&nbsp;';
  751. echo "<td valign=bottom class=h>$name</td>";
  752. }
  753. if ($justnames === false && $cmd == 'pools' && $readonly === false)
  754. foreach ($poolcmd as $name => $pcmd)
  755. echo "<td valign=bottom class=h>$name</td>";
  756. endrow();
  757. }
  758. #
  759. function showdatetime()
  760. {
  761. global $dfmt;
  762. otherrow('<td class=sta>Date: '.date($dfmt).'</td>');
  763. }
  764. #
  765. global $singlerigsum;
  766. $singlerigsum = array(
  767. 'devs' => array('MHS av' => 1, 'MHS 5s' => 1, 'Accepted' => 1, 'Rejected' => 1,
  768. 'Hardware Errors' => 1, 'Utility' => 1, 'Total MH' => 1),
  769. 'pools' => array('Getworks' => 1, 'Accepted' => 1, 'Rejected' => 1, 'Discarded' => 1,
  770. 'Stale' => 1, 'Get Failures' => 1, 'Remote Failures' => 1),
  771. 'notify' => array('*' => 1));
  772. #
  773. function showtotal($total, $when, $oldvalues)
  774. {
  775. global $rigtotals;
  776. list($showvalue, $class) = fmt('total', '', 'Total:', $when, null);
  777. echo "<td$class align=right>$showvalue</td>";
  778. $skipfirst = true;
  779. foreach ($oldvalues as $name => $value)
  780. {
  781. if ($skipfirst === true)
  782. {
  783. $skipfirst = false;
  784. continue;
  785. }
  786. if (isset($total[$name]))
  787. $newvalue = $total[$name];
  788. else
  789. $newvalue = '';
  790. list($showvalue, $class) = fmt('total', $name, $newvalue, $when, null);
  791. echo "<td$class";
  792. if ($rigtotals === true)
  793. echo ' align=right';
  794. echo ">$showvalue</td>";
  795. }
  796. }
  797. #
  798. function details($cmd, $list, $rig)
  799. {
  800. global $dfmt, $poolcmd, $readonly, $showndate;
  801. global $rownum, $rigtotals, $forcerigtotals, $singlerigsum;
  802. $when = 0;
  803. $stas = array('S' => 'Success', 'W' => 'Warning', 'I' => 'Informational', 'E' => 'Error', 'F' => 'Fatal');
  804. newtable();
  805. if ($showndate === false)
  806. {
  807. showdatetime();
  808. endtable();
  809. newtable();
  810. $showndate = true;
  811. }
  812. if (isset($list['STATUS']))
  813. {
  814. newrow();
  815. echo '<td>Computer: '.$list['STATUS']['Description'].'</td>';
  816. if (isset($list['STATUS']['When']))
  817. {
  818. echo '<td>When: '.date($dfmt, $list['STATUS']['When']).'</td>';
  819. $when = $list['STATUS']['When'];
  820. }
  821. $sta = $list['STATUS']['STATUS'];
  822. echo '<td>Status: '.$stas[$sta].'</td>';
  823. echo '<td>Message: '.$list['STATUS']['Msg'].'</td>';
  824. endrow();
  825. }
  826. if ($rigtotals === true && isset($singlerigsum[$cmd]))
  827. $dototal = $singlerigsum[$cmd];
  828. else
  829. $dototal = array();
  830. $total = array();
  831. $section = '';
  832. $oldvalues = null;
  833. foreach ($list as $item => $values)
  834. {
  835. if ($item == 'STATUS')
  836. continue;
  837. $sectionname = preg_replace('/\d/', '', $item);
  838. // Handle 'devs' possibly containing >1 table
  839. if ($sectionname != $section)
  840. {
  841. if ($oldvalues != null && count($total) > 0
  842. && ($rownum > 2 || $forcerigtotals === true))
  843. showtotal($total, $when, $oldvalues);
  844. endtable();
  845. newtable();
  846. showhead($cmd, $values);
  847. $section = $sectionname;
  848. }
  849. newrow();
  850. foreach ($values as $name => $value)
  851. {
  852. list($showvalue, $class) = fmt($section, $name, $value, $when, $values);
  853. echo "<td$class";
  854. if ($rigtotals === true)
  855. echo ' align=right';
  856. echo ">$showvalue</td>";
  857. if (isset($dototal[$name])
  858. || (isset($dototal['*']) and substr($name, 0, 1) == '*'))
  859. {
  860. if (isset($total[$name]))
  861. $total[$name] += $value;
  862. else
  863. $total[$name] = $value;
  864. }
  865. }
  866. if ($cmd == 'pools' && $readonly === false)
  867. {
  868. reset($values);
  869. $pool = current($values);
  870. foreach ($poolcmd as $name => $pcmd)
  871. {
  872. list($ignore, $class) = fmt('BUTTON', 'Pool', '', $when, $values);
  873. echo "<td$class>";
  874. if ($pool === false)
  875. echo '&nbsp;';
  876. else
  877. {
  878. echo "<input type=button value='Pool $pool'";
  879. echo " onclick='prc(\"$pcmd|$pool&rig=$rig\",\"$name Pool $pool\")'>";
  880. }
  881. echo '</td>';
  882. }
  883. }
  884. endrow();
  885. $oldvalues = $values;
  886. }
  887. if ($oldvalues != null && count($total) > 0
  888. && ($rownum > 2 || $forcerigtotals === true))
  889. showtotal($total, $when, $oldvalues);
  890. endtable();
  891. }
  892. #
  893. global $devs;
  894. $devs = null;
  895. #
  896. function gpubuttons($count, $rig)
  897. {
  898. global $devs;
  899. $basic = array( 'GPU', 'Enable', 'Disable', 'Restart' );
  900. $options = array( 'intensity' => 'Intensity',
  901. 'fan' => 'Fan Percent',
  902. 'engine' => 'GPU Clock',
  903. 'mem' => 'Memory Clock',
  904. 'vddc' => 'GPU Voltage' );
  905. newtable();
  906. newrow();
  907. foreach ($basic as $head)
  908. echo "<td class=h>$head</td>";
  909. foreach ($options as $name => $des)
  910. echo "<td class=h nowrap>$des</td>";
  911. $n = 0;
  912. for ($c = 0; $c < $count; $c++)
  913. {
  914. endrow();
  915. newrow();
  916. foreach ($basic as $name)
  917. {
  918. list($ignore, $class) = fmt('BUTTON', 'GPU', '', 0, null);
  919. echo "<td$class>";
  920. if ($name == 'GPU')
  921. echo $c;
  922. else
  923. {
  924. echo "<input type=button value='$name $c' onclick='prs(\"gpu";
  925. echo strtolower($name);
  926. echo "|$c\",$rig)'>";
  927. }
  928. echo '</td>';
  929. }
  930. foreach ($options as $name => $des)
  931. {
  932. list($ignore, $class) = fmt('BUTTON', 'GPU', '', 0, null);
  933. echo "<td$class>";
  934. if (!isset($devs["GPU$c"][$des]))
  935. echo '&nbsp;';
  936. else
  937. {
  938. $value = $devs["GPU$c"][$des];
  939. echo "<input type=button value='Set $c:' onclick='prs2(\"gpu$name|$c\",$n,$rig)'>";
  940. echo "<input size=7 type=text name=gi$n value='$value' id=gi$n>";
  941. $n++;
  942. }
  943. echo '</td>';
  944. }
  945. }
  946. endrow();
  947. endtable();
  948. }
  949. #
  950. function processgpus($rig)
  951. {
  952. global $error;
  953. global $warnfont, $warnoff;
  954. $gpus = api('gpucount');
  955. if ($error != null)
  956. otherrow("<td>Error getting GPU count: $warnfont$error$warnoff</td>");
  957. else
  958. {
  959. if (!isset($gpus['GPUS']['Count']))
  960. {
  961. $rw = '<td>No GPU count returned: '.$warnfont;
  962. $rw .= $gpus['STATUS']['STATUS'].' '.$gpus['STATUS']['Msg'];
  963. $rw .= $warnoff.'</td>';
  964. otherrow($rw);
  965. }
  966. else
  967. {
  968. $count = $gpus['GPUS']['Count'];
  969. if ($count == 0)
  970. otherrow('<td>No GPUs</td>');
  971. else
  972. gpubuttons($count, $rig);
  973. }
  974. }
  975. }
  976. #
  977. function showpoolinputs($rig, $ans)
  978. {
  979. global $readonly, $poolinputs;
  980. if ($readonly === true || $poolinputs === false)
  981. return;
  982. newtable();
  983. newrow();
  984. $inps = array('Pool URL' => array('purl', 20),
  985. 'Worker Name' => array('pwork', 10),
  986. 'Worker Password' => array('ppass', 10));
  987. $b = '&nbsp;';
  988. echo "<td align=right class=h> Add a pool: </td><td>";
  989. foreach ($inps as $text => $name)
  990. echo "$text: <input name='".$name[0]."' id='".$name[0]."' value='' type=text size=".$name[1]."> ";
  991. echo "</td><td align=middle><input type=button value='Add' onclick='pla($rig)'></td>";
  992. endrow();
  993. if (count($ans) > 1)
  994. {
  995. newrow();
  996. echo '<td align=right class=h> Set pool priorities: </td>';
  997. echo "<td> Comma list of pool numbers: <input type=text name=prio id=prio size=20>";
  998. echo "</td><td align=middle><input type=button value='Set' onclick='psp($rig)'></td>";
  999. endrow();
  1000. }
  1001. endtable();
  1002. }
  1003. #
  1004. function process($cmds, $rig)
  1005. {
  1006. global $error, $devs;
  1007. global $warnfont, $warnoff;
  1008. $count = count($cmds);
  1009. foreach ($cmds as $cmd => $des)
  1010. {
  1011. $process = api($cmd);
  1012. if ($error != null)
  1013. {
  1014. otherrow("<td colspan=100>Error getting $des: $warnfont$error$warnoff</td>");
  1015. break;
  1016. }
  1017. else
  1018. {
  1019. details($cmd, $process, $rig);
  1020. if ($cmd == 'devs')
  1021. $devs = $process;
  1022. if ($cmd == 'pools')
  1023. showpoolinputs($rig, $process);
  1024. # Not after the last one
  1025. if (--$count > 0)
  1026. otherrow('<td><br><br></td>');
  1027. }
  1028. }
  1029. }
  1030. #
  1031. function rigbutton($rig, $rigname, $when, $row)
  1032. {
  1033. global $rigs;
  1034. if (isset($rigs[$rig]))
  1035. {
  1036. $parts = explode(':', $rigs[$rig], 3);
  1037. if (count($parts) == 3)
  1038. $rigname = $parts[2];
  1039. }
  1040. list($value, $class) = fmt('BUTTON', 'Rig', '', $when, $row);
  1041. $button = "<td align=middle$class><input type=button value='$rigname'";
  1042. $button .= " onclick='pr(\"&rig=$rig\",null)'></td>";
  1043. return $button;
  1044. }
  1045. #
  1046. function showrigs($anss, $headname, $rigname)
  1047. {
  1048. $dthead = array($headname => 1, 'STATUS' => 1, 'Description' => 1, 'When' => 1, 'API' => 1, 'CGMiner' => 1);
  1049. showhead('', $dthead);
  1050. foreach ($anss as $rig => $ans)
  1051. {
  1052. if ($ans == null)
  1053. continue;
  1054. newrow();
  1055. $when = 0;
  1056. if (isset($ans['STATUS']['When']))
  1057. $when = $ans['STATUS']['When'];
  1058. foreach ($ans as $item => $row)
  1059. {
  1060. if ($item != 'STATUS' && $item != 'VERSION')
  1061. continue;
  1062. foreach ($dthead as $name => $x)
  1063. {
  1064. if ($item == 'STATUS' && $name == $headname)
  1065. echo rigbutton($rig, $rigname.$rig, $when, null);
  1066. else
  1067. {
  1068. if (isset($row[$name]))
  1069. {
  1070. list($showvalue, $class) = fmt('STATUS', $name, $row[$name], $when, null);
  1071. echo "<td$class align=right>$showvalue</td>";
  1072. }
  1073. }
  1074. }
  1075. }
  1076. endrow();
  1077. }
  1078. }
  1079. #
  1080. # $head is a hack but this is just a demo anyway :)
  1081. function doforeach($cmd, $des, $sum, $head, $datetime)
  1082. {
  1083. global $miner, $port;
  1084. global $error, $readonly, $notify, $rigs;
  1085. global $warnfont, $warnoff, $dfmt;
  1086. global $rigerror;
  1087. $when = 0;
  1088. $header = $head;
  1089. $anss = array();
  1090. $count = 0;
  1091. $preverr = count($rigerror);
  1092. foreach ($rigs as $num => $rig)
  1093. {
  1094. $anss[$num] = null;
  1095. if (isset($rigerror[$rig]))
  1096. continue;
  1097. $parts = explode(':', $rig, 3);
  1098. if (count($parts) >= 2)
  1099. {
  1100. $miner = $parts[0];
  1101. $port = $parts[1];
  1102. if (count($parts) > 2)
  1103. $name = $parts[2];
  1104. else
  1105. $name = $num;
  1106. $ans = api($cmd);
  1107. if ($error != null)
  1108. {
  1109. $rw = "<td colspan=100>Error on rig $name getting ";
  1110. $rw .= "$des: $warnfont$error$warnoff</td>";
  1111. otherrow($rw);
  1112. $rigerror[$rig] = $error;
  1113. $error = null;
  1114. }
  1115. else
  1116. {
  1117. $anss[$num] = $ans;
  1118. $count++;
  1119. }
  1120. }
  1121. }
  1122. if ($count == 0)
  1123. {
  1124. $rw = '<td>Failed to access any rigs successfully';
  1125. if ($preverr > 0)
  1126. $rw .= ' (or rigs had previous errors)';
  1127. $rw .= '</td>';
  1128. otherrow($rw);
  1129. return;
  1130. }
  1131. if ($datetime)
  1132. {
  1133. showdatetime();
  1134. endtable();
  1135. newtable();
  1136. showrigs($anss, '', 'Rig ');
  1137. endtable();
  1138. otherrow('<td><br><br></td>');
  1139. newtable();
  1140. return;
  1141. }
  1142. $total = array();
  1143. foreach ($anss as $rig => $ans)
  1144. {
  1145. if ($ans == null)
  1146. continue;
  1147. foreach ($ans as $item => $row)
  1148. {
  1149. if ($item == 'STATUS')
  1150. continue;
  1151. if (count($row) > count($header))
  1152. {
  1153. $header = $head;
  1154. foreach ($row as $name => $value)
  1155. if (!isset($header[$name]))
  1156. $header[$name] = '';
  1157. }
  1158. if ($sum != null)
  1159. foreach ($sum as $name)
  1160. {
  1161. if (isset($row[$name]))
  1162. {
  1163. if (isset($total[$name]))
  1164. $total[$name] += $row[$name];
  1165. else
  1166. $total[$name] = $row[$name];
  1167. }
  1168. }
  1169. }
  1170. }
  1171. if ($sum != null)
  1172. $anss['total']['total'] = $total;
  1173. showhead('', $header);
  1174. foreach ($anss as $rig => $ans)
  1175. {
  1176. if ($ans == null)
  1177. continue;
  1178. $when = 0;
  1179. if (isset($ans['STATUS']['When']))
  1180. $when = $ans['STATUS']['When'];
  1181. foreach ($ans as $item => $row)
  1182. {
  1183. if ($item == 'STATUS')
  1184. continue;
  1185. newrow();
  1186. $section = preg_replace('/\d/', '', $item);
  1187. foreach ($header as $name => $x)
  1188. {
  1189. if ($name == '')
  1190. {
  1191. if ($rig === 'total')
  1192. {
  1193. list($ignore, $class) = fmt($rig, '', '', $when, $row);
  1194. echo "<td align=right$class>Total:</td>";
  1195. }
  1196. else
  1197. echo rigbutton($rig, "Rig $rig", $when, $row);
  1198. }
  1199. else
  1200. {
  1201. if (isset($row[$name]))
  1202. $value = $row[$name];
  1203. else
  1204. $value = null;
  1205. list($showvalue, $class) = fmt($section, $name, $value, $when, $row);
  1206. echo "<td$class align=right>$showvalue</td>";
  1207. }
  1208. }
  1209. endrow();
  1210. }
  1211. }
  1212. }
  1213. #
  1214. function refreshbuttons()
  1215. {
  1216. global $readonly;
  1217. global $ignorerefresh, $changerefresh, $autorefresh;
  1218. if ($ignorerefresh == false && $changerefresh == true)
  1219. {
  1220. echo '&nbsp;&nbsp;&nbsp;&nbsp;';
  1221. echo "<input type=button value='Auto Refresh:' onclick='prr(true)'>";
  1222. echo "<input type=text name='refval' id='refval' size=2 value='$autorefresh'>";
  1223. echo "<input type=button value='Off' onclick='prr(false)'>";
  1224. }
  1225. }
  1226. #
  1227. function pagebuttons($rig, $pg)
  1228. {
  1229. global $readonly, $rigs;
  1230. global $allowcustompages, $customsummarypages;
  1231. if ($rig === null)
  1232. {
  1233. if ($pg === null)
  1234. $refresh = '';
  1235. else
  1236. $refresh = "&pg=$pg";
  1237. }
  1238. else
  1239. $refresh = "&rig=$rig";
  1240. echo '<tr><td><table cellpadding=0 cellspacing=0 border=0><tr><td nowrap>';
  1241. echo "<input type=button value='Refresh' onclick='pr(\"$refresh\",null)'>&nbsp;";
  1242. if (count($rigs) > 1)
  1243. echo "<input type=button value='Summary' onclick='pr(\"\",null)'>&nbsp;";
  1244. if ($allowcustompages === true)
  1245. foreach ($customsummarypages as $pagename => $data)
  1246. echo "<input type=button value='$pagename' onclick='pr(\"&pg=$pagename\",null)'>&nbsp;";
  1247. echo '</td><td width=100%>&nbsp;</td><td nowrap>';
  1248. if ($rig !== null && $readonly === false)
  1249. {
  1250. $rg = '';
  1251. if (count($rigs) > 1)
  1252. $rg = " Rig $rig";
  1253. echo "<input type=button value='Restart' onclick='prc(\"restart&rig=$rig\",\"Restart CGMiner$rg\")'>";
  1254. echo "&nbsp;<input type=button value='Quit' onclick='prc(\"quit&rig=$rig\",\"Quit CGMiner$rg\")'>";
  1255. }
  1256. refreshbuttons();
  1257. echo "</td></tr></table></td></tr>";
  1258. }
  1259. #
  1260. function doOne($rig, $preprocess)
  1261. {
  1262. global $haderror, $readonly, $notify, $rigs;
  1263. global $placebuttons;
  1264. htmlhead(true, $rig);
  1265. if ($placebuttons == 'top' || $placebuttons == 'both')
  1266. pagebuttons($rig, null);
  1267. if ($preprocess != null)
  1268. process(array($preprocess => $preprocess), $rig);
  1269. $cmds = array( 'devs' => 'device list',
  1270. 'summary' => 'summary information',
  1271. 'pools' => 'pool list');
  1272. if ($notify)
  1273. $cmds['notify'] = 'device status';
  1274. $cmds['config'] = 'cgminer config';
  1275. process($cmds, $rig);
  1276. if ($haderror == false && $readonly === false)
  1277. processgpus($rig);
  1278. if ($placebuttons == 'bot' || $placebuttons == 'both')
  1279. pagebuttons($rig, null);
  1280. }
  1281. #
  1282. global $sectionmap;
  1283. # map sections to their api command
  1284. # DEVS is a special case that will match GPU or PGA
  1285. # so you can have a single table with both in it
  1286. # DATE is hard coded so not in here
  1287. $sectionmap = array(
  1288. 'RIGS' => 'version',
  1289. 'SUMMARY' => 'summary',
  1290. 'POOL' => 'pools',
  1291. 'DEVS' => 'devs',
  1292. 'GPU' => 'devs', // You would normally use DEVS
  1293. 'PGA' => 'devs', // You would normally use DEVS
  1294. 'NOTIFY' => 'notify',
  1295. 'DEVDETAILS' => 'devdetails',
  1296. 'STATS' => 'stats',
  1297. 'CONFIG' => 'config');
  1298. #
  1299. function joinfields($section1, $section2, $join, $results)
  1300. {
  1301. global $sectionmap;
  1302. $name1 = $sectionmap[$section1];
  1303. $name2 = $sectionmap[$section2];
  1304. $newres = array();
  1305. // foreach rig in section1
  1306. foreach ($results[$name1] as $rig => $result)
  1307. {
  1308. $status = null;
  1309. // foreach answer section in the rig api call
  1310. foreach ($result as $name1b => $fields1b)
  1311. {
  1312. if ($name1b == 'STATUS')
  1313. {
  1314. // remember the STATUS from section1
  1315. $status = $result[$name1b];
  1316. continue;
  1317. }
  1318. // foreach answer section in the rig api call (for the other api command)
  1319. foreach ($results[$name2][$rig] as $name2b => $fields2b)
  1320. {
  1321. if ($name2b == 'STATUS')
  1322. continue;
  1323. // If match the same field values of fields in $join
  1324. $match = true;
  1325. foreach ($join as $field)
  1326. if ($fields1b[$field] != $fields2b[$field])
  1327. {
  1328. $match = false;
  1329. break;
  1330. }
  1331. if ($match === true)
  1332. {
  1333. if ($status != null)
  1334. {
  1335. $newres[$rig]['STATUS'] = $status;
  1336. $status = null;
  1337. }
  1338. $subsection = $section1.'+'.$section2;
  1339. $subsection .= preg_replace('/[^0-9]/', '', $name1b.$name2b);
  1340. foreach ($fields1b as $nam => $val)
  1341. $newres[$rig][$subsection]["$section1.$nam"] = $val;
  1342. foreach ($fields2b as $nam => $val)
  1343. $newres[$rig][$subsection]["$section2.$nam"] = $val;
  1344. }
  1345. }
  1346. }
  1347. }
  1348. return $newres;
  1349. }
  1350. #
  1351. function joinall($section1, $section2, $results)
  1352. {
  1353. global $sectionmap;
  1354. $name1 = $sectionmap[$section1];
  1355. $name2 = $sectionmap[$section2];
  1356. $newres = array();
  1357. // foreach rig in section1
  1358. foreach ($results[$name1] as $rig => $result)
  1359. {
  1360. // foreach answer section in the rig api call
  1361. foreach ($result as $name1b => $fields1b)
  1362. {
  1363. if ($name1b == 'STATUS')
  1364. {
  1365. // copy the STATUS from section1
  1366. $newres[$rig][$name1b] = $result[$name1b];
  1367. continue;
  1368. }
  1369. // foreach answer section in the rig api call (for the other api command)
  1370. foreach ($results[$name2][$rig] as $name2b => $fields2b)
  1371. {
  1372. if ($name2b == 'STATUS')
  1373. continue;
  1374. $subsection = $section1.'+'.$section2;
  1375. $subsection .= preg_replace('/[^0-9]/', '', $name1b.$name2b);
  1376. foreach ($fields1b as $nam => $val)
  1377. $newres[$rig][$subsection]["$section1.$nam"] = $val;
  1378. foreach ($fields2b as $nam => $val)
  1379. $newres[$rig][$subsection]["$section2.$nam"] = $val;
  1380. }
  1381. }
  1382. }
  1383. return $newres;
  1384. }
  1385. #
  1386. function joinsections($sections, $results, $errors)
  1387. {
  1388. global $sectionmap;
  1389. #echo "results['pools']=".print_r($results['pools'],true)."<br>";
  1390. // GPU's don't have Name,ID fields - so create them
  1391. foreach ($results as $section => $res)
  1392. foreach ($res as $rig => $result)
  1393. foreach ($result as $name => $fields)
  1394. {
  1395. $subname = preg_replace('/[0-9]/', '', $name);
  1396. if ($subname == 'GPU' and isset($result[$name]['GPU']))
  1397. {
  1398. $results[$section][$rig][$name]['Name'] = 'GPU';
  1399. $results[$section][$rig][$name]['ID'] = $result[$name]['GPU'];
  1400. }
  1401. }
  1402. foreach ($sections as $section => $fields)
  1403. if ($section != 'DATE' && !isset($sectionmap[$section]))
  1404. {
  1405. $both = explode('+', $section, 2);
  1406. if (count($both) > 1)
  1407. {
  1408. switch($both[0])
  1409. {
  1410. case 'SUMMARY':
  1411. switch($both[1])
  1412. {
  1413. case 'POOL':
  1414. case 'DEVS':
  1415. case 'CONFIG':
  1416. $sectionmap[$section] = $section;
  1417. $results[$section] = joinall($both[0], $both[1], $results);
  1418. break;
  1419. default:
  1420. $errors[] = "Error: Invalid section '$section'";
  1421. break;
  1422. }
  1423. break;
  1424. case 'DEVS':
  1425. $join = array('Name', 'ID');
  1426. switch($both[1])
  1427. {
  1428. case 'NOTIFY':
  1429. case 'DEVDETAILS':
  1430. $sectionmap[$section] = $section;
  1431. $results[$section] = joinfields($both[0], $both[1], $join, $results);
  1432. break;
  1433. default:
  1434. $errors[] = "Error: Invalid section '$section'";
  1435. break;
  1436. }
  1437. break;
  1438. default:
  1439. $errors[] = "Error: Invalid section '$section'";
  1440. break;
  1441. }
  1442. }
  1443. else
  1444. $errors[] = "Error: Invalid section '$section'";
  1445. }
  1446. return array($results, $errors);
  1447. }
  1448. #
  1449. function secmatch($section, $field)
  1450. {
  1451. if ($section == $field)
  1452. return true;
  1453. if ($section == 'DEVS'
  1454. && ($field == 'GPU' || $field == 'PGA'))
  1455. return true;
  1456. return false;
  1457. }
  1458. #
  1459. function customset($showfields, $sum, $section, $rig, $isbutton, $result, $total)
  1460. {
  1461. foreach ($result as $sec => $row)
  1462. {
  1463. $secname = preg_replace('/\d/', '', $sec);
  1464. if ($sec != 'total')
  1465. if (!secmatch($section, $secname))
  1466. continue;
  1467. newrow();
  1468. $when = 0;
  1469. if (isset($result['STATUS']['When']))
  1470. $when = $result['STATUS']['When'];
  1471. if ($isbutton)
  1472. echo rigbutton($rig, $rig, $when, $row);
  1473. else
  1474. {
  1475. list($ignore, $class) = fmt('total', '', '', $when, $row);
  1476. echo "<td align=middle$class>$rig</td>";
  1477. }
  1478. foreach ($showfields as $name => $one)
  1479. {
  1480. if (isset($row[$name]))
  1481. {
  1482. $value = $row[$name];
  1483. if (isset($sum[$section][$name]))
  1484. {
  1485. if (isset($total[$name]))
  1486. $total[$name] += $value;
  1487. else
  1488. $total[$name] = $value;
  1489. }
  1490. }
  1491. else
  1492. {
  1493. if ($sec == 'total' && isset($total[$name]))
  1494. $value = $total[$name];
  1495. else
  1496. $value = null;
  1497. }
  1498. if (strpos($secname, '+') === false)
  1499. list($showvalue, $class) = fmt($secname, $name, $value, $when, $row);
  1500. else
  1501. {
  1502. $parts = explode('.', $name, 2);
  1503. list($showvalue, $class) = fmt($parts[0], $parts[1], $value, $when, $row);
  1504. }
  1505. echo "<td$class align=right>$showvalue</td>";
  1506. }
  1507. endrow();
  1508. }
  1509. return $total;
  1510. }
  1511. #
  1512. function processcustompage($pagename, $sections, $sum, $namemap)
  1513. {
  1514. global $sectionmap;
  1515. global $miner, $port;
  1516. global $rigs, $error;
  1517. global $warnfont, $warnoff;
  1518. global $dfmt;
  1519. global $readonly, $showndate;
  1520. $cmds = array();
  1521. $errors = array();
  1522. foreach ($sections as $section => $fields)
  1523. {
  1524. $all = explode('+', $section);
  1525. foreach ($all as $section)
  1526. {
  1527. if (isset($sectionmap[$section]))
  1528. {
  1529. $cmd = $sectionmap[$section];
  1530. if (!isset($cmds[$cmd]))
  1531. $cmds[$cmd] = 1;
  1532. }
  1533. else
  1534. if ($section != 'DATE')
  1535. $errors[] = "Error: unknown section '$section' in custom summary page '$pagename'";
  1536. }
  1537. }
  1538. $results = array();
  1539. foreach ($rigs as $num => $rig)
  1540. {
  1541. $parts = explode(':', $rig, 3);
  1542. if (count($parts) >= 2)
  1543. {
  1544. $miner = $parts[0];
  1545. $port = $parts[1];
  1546. if (count($parts) > 2)
  1547. $name = $parts[2];
  1548. else
  1549. $name = $rig;
  1550. foreach ($cmds as $cmd => $one)
  1551. {
  1552. $process = api($cmd);
  1553. if ($error != null)
  1554. {
  1555. $errors[] = "Error getting $cmd for $name $warnfont$error$warnoff";
  1556. break;
  1557. }
  1558. else
  1559. $results[$cmd][$num] = $process;
  1560. }
  1561. }
  1562. }
  1563. $shownsomething = false;
  1564. if (count($results) > 0)
  1565. {
  1566. list($results, $errors) = joinsections($sections, $results, $errors);
  1567. $first = true;
  1568. foreach ($sections as $section => $fields)
  1569. {
  1570. if ($section === 'DATE')
  1571. {
  1572. if ($shownsomething)
  1573. otherrow('<td>&nbsp;</td>');
  1574. newtable();
  1575. showdatetime();
  1576. endtable();
  1577. // On top of the next table
  1578. $shownsomething = false;
  1579. continue;
  1580. }
  1581. if ($section === 'RIGS')
  1582. {
  1583. if ($shownsomething)
  1584. otherrow('<td>&nbsp;</td>');
  1585. newtable();
  1586. showrigs($results['version'], 'Rig', '');
  1587. endtable();
  1588. $shownsomething = true;
  1589. continue;
  1590. }
  1591. if (isset($results[$sectionmap[$section]]))
  1592. {
  1593. $rigresults = $results[$sectionmap[$section]];
  1594. $showfields = array();
  1595. $showhead = array();
  1596. foreach ($fields as $field)
  1597. foreach ($rigresults as $result)
  1598. foreach ($result as $sec => $row)
  1599. {
  1600. $secname = preg_replace('/\d/', '', $sec);
  1601. if (secmatch($section, $secname))
  1602. {
  1603. if ($field === '*')
  1604. {
  1605. foreach ($row as $f => $v)
  1606. {
  1607. $showfields[$f] = 1;
  1608. $map = $section.'.'.$f;
  1609. if (isset($namemap[$map]))
  1610. $showhead[$namemap[$map]] = 1;
  1611. else
  1612. $showhead[$f] = 1;
  1613. }
  1614. }
  1615. elseif (isset($row[$field]))
  1616. {
  1617. $showfields[$field] = 1;
  1618. $map = $section.'.'.$field;
  1619. if (isset($namemap[$map]))
  1620. $showhead[$namemap[$map]] = 1;
  1621. else
  1622. $showhead[$field] = 1;
  1623. }
  1624. }
  1625. }
  1626. if (count($showfields) > 0)
  1627. {
  1628. if ($shownsomething)
  1629. otherrow('<td>&nbsp;</td>');
  1630. newtable();
  1631. showhead('', array('Rig'=>1)+$showhead, true);
  1632. $total = array();
  1633. $add = array('total' => array());
  1634. foreach ($rigresults as $num => $result)
  1635. $total = customset($showfields, $sum, $section, $num, true, $result, $total);
  1636. if (count($total) > 0)
  1637. customset($showfields, $sum, $section, '&Sigma;', false, $add, $total);
  1638. $first = false;
  1639. endtable();
  1640. $shownsomething = true;
  1641. }
  1642. }
  1643. }
  1644. }
  1645. if (count($errors) > 0)
  1646. {
  1647. if (count($results) > 0)
  1648. otherrow('<td>&nbsp;</td>');
  1649. foreach ($errors as $err)
  1650. otherrow("<td colspan=100>$err</td>");
  1651. }
  1652. }
  1653. #
  1654. function showcustompage($pagename)
  1655. {
  1656. global $customsummarypages;
  1657. global $placebuttons;
  1658. htmlhead(false, null, $pagename);
  1659. if ($placebuttons == 'top' || $placebuttons == 'both')
  1660. pagebuttons(null, $pagename);
  1661. if (!isset($customsummarypages[$pagename]))
  1662. {
  1663. otherrow("<td colspan=100>Unknown custom summary page '$pagename'</td>");
  1664. return;
  1665. }
  1666. if (count($customsummarypages[$pagename]) != 2)
  1667. {
  1668. $rw = "<td colspan=100>Invalid custom summary page '$pagename' (";
  1669. $rw .= count($customsummarypages[$pagename]).')</td>';
  1670. otherrow($rw);
  1671. return;
  1672. }
  1673. $page = $customsummarypages[$pagename][0];
  1674. $namemap = array();
  1675. foreach ($page as $name => $fields)
  1676. {
  1677. if ($fields === null)
  1678. $page[$name] = array();
  1679. else
  1680. foreach ($fields as $num => $field)
  1681. {
  1682. $pos = strpos($field, '=');
  1683. if ($pos !== false)
  1684. {
  1685. $names = explode('=', $field, 2);
  1686. if (strlen($names[1]) > 0)
  1687. $namemap[$name.'.'.$names[0]] = $names[1];
  1688. $page[$name][$num] = $names[0];
  1689. }
  1690. }
  1691. }
  1692. $sum = $customsummarypages[$pagename][1];
  1693. if ($sum === null)
  1694. $sum = array();
  1695. // convert them to searchable via isset()
  1696. foreach ($sum as $section => $fields)
  1697. {
  1698. $newfields = array();
  1699. foreach ($fields as $field)
  1700. $newfields[$field] = 1;
  1701. $sum[$section] = $newfields;
  1702. }
  1703. if (count($page) <= 1)
  1704. {
  1705. otherrow("<td colspan=100>Invalid custom summary page '$pagename' no content </td>");
  1706. return;
  1707. }
  1708. processcustompage($pagename, $page, $sum, $namemap);
  1709. if ($placebuttons == 'bot' || $placebuttons == 'both')
  1710. pagebuttons(null, $pagename);
  1711. }
  1712. #
  1713. function display()
  1714. {
  1715. global $miner, $port;
  1716. global $readonly, $notify, $rigs;
  1717. global $ignorerefresh, $autorefresh;
  1718. global $allowcustompages;
  1719. global $placebuttons;
  1720. if ($ignorerefresh == false)
  1721. {
  1722. $ref = trim(getparam('ref', true));
  1723. if ($ref != null && $ref != '')
  1724. $autorefresh = intval($ref);
  1725. }
  1726. $rig = trim(getparam('rig', true));
  1727. $arg = trim(getparam('arg', true));
  1728. $preprocess = null;
  1729. if ($arg != null and $arg != '')
  1730. {
  1731. $num = null;
  1732. if ($rig != null and $rig != '')
  1733. {
  1734. if ($rig >= 0 and $rig < count($rigs))
  1735. $num = $rig;
  1736. }
  1737. else
  1738. if (count($rigs) == 0)
  1739. $num = 0;
  1740. if ($num != null)
  1741. {
  1742. $parts = explode(':', $rigs[$num], 3);
  1743. if (count($parts) >= 2)
  1744. {
  1745. $miner = $parts[0];
  1746. $port = $parts[1];
  1747. if ($readonly !== true)
  1748. $preprocess = $arg;
  1749. }
  1750. }
  1751. }
  1752. if ($rigs == null or count($rigs) == 0)
  1753. {
  1754. otherrow("<td>No rigs defined</td>");
  1755. return;
  1756. }
  1757. if ($allowcustompages === true)
  1758. {
  1759. $pg = trim(getparam('pg', true));
  1760. if ($pg != null && $pg != '')
  1761. {
  1762. showcustompage($pg);
  1763. return;
  1764. }
  1765. }
  1766. if (count($rigs) == 1)
  1767. {
  1768. $parts = explode(':', $rigs[0], 3);
  1769. if (count($parts) >= 2)
  1770. {
  1771. $miner = $parts[0];
  1772. $port = $parts[1];
  1773. doOne(0, $preprocess);
  1774. }
  1775. else
  1776. otherrow('<td>Invalid "$rigs" array</td>');
  1777. return;
  1778. }
  1779. if ($rig != null and $rig != '' and $rig >= 0 and $rig < count($rigs))
  1780. {
  1781. $parts = explode(':', $rigs[$rig], 3);
  1782. if (count($parts) >= 2)
  1783. {
  1784. $miner = $parts[0];
  1785. $port = $parts[1];
  1786. doOne($rig, $preprocess);
  1787. }
  1788. else
  1789. otherrow('<td>Invalid "$rigs" array</td>');
  1790. return;
  1791. }
  1792. htmlhead(false, null);
  1793. if ($placebuttons == 'top' || $placebuttons == 'both')
  1794. pagebuttons(null, null);
  1795. if ($preprocess != null)
  1796. process(array($preprocess => $preprocess), $rig);
  1797. newtable();
  1798. doforeach('version', 'rig summary', array(), array(), true);
  1799. $sum = array('MHS av', 'Getworks', 'Found Blocks', 'Accepted', 'Rejected', 'Discarded', 'Stale', 'Utility', 'Local Work', 'Total MH');
  1800. doforeach('summary', 'summary information', $sum, array(), false);
  1801. endtable();
  1802. otherrow('<td><br><br></td>');
  1803. newtable();
  1804. doforeach('devs', 'device list', $sum, array(''=>'','ID'=>'','Name'=>''), false);
  1805. endtable();
  1806. otherrow('<td><br><br></td>');
  1807. newtable();
  1808. doforeach('pools', 'pool list', $sum, array(''=>''), false);
  1809. endtable();
  1810. if ($placebuttons == 'bot' || $placebuttons == 'both')
  1811. pagebuttons(null, null);
  1812. }
  1813. #
  1814. display();
  1815. #
  1816. ?>
  1817. </table></td></tr></table>
  1818. </body></html>