miner.php 64 KB

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