miner.php 64 KB

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