miner.php 61 KB

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