miner.php 44 KB

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