miner.php 66 KB

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