miner.php 66 KB

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