miner.php 65 KB

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