Browse Source

miner.php allow links for rig buttons in tables and allow using the 4th IP octet if no rig name - default disabled for both

port-ckolivas
Kano 11 years ago committed by Noel Maersk
parent
commit
e3e5d68b92
  1. 21
      doc/API
  2. 78
      miner.php

21
doc/API

@ -1284,6 +1284,27 @@ e.g. $rigs = array('127.0.0.1:4028','myrig.com:4028:Sugoi');
--------- ---------
Default:
$rignames = false;
Set $rignames to false to not affect the display.
Set $rignames to one of 'ip' or 'ipx' to alter the name displayed
if the rig doesn't have a 'name' in $rigs
Currently:
'ip' means use the 4th byte of the rig IP address as an integer
'ipx' means use the 4th byte of the rig IP address as 2 hex bytes
---------
Default:
$rigbuttons = true;
Set $rigbuttons to false to display a link rather than a button on
the left of any summary table with rig buttons, in order to reduce
the height of the table cells
---------
Default: Default:
$mcast = false; $mcast = false;

78
miner.php

@ -2,6 +2,7 @@
session_start(); session_start();
# #
global $doctype, $title, $miner, $port, $readonly, $notify, $rigs; global $doctype, $title, $miner, $port, $readonly, $notify, $rigs;
global $rignames, $rigbuttons;
global $mcast, $mcastexpect, $mcastaddr, $mcastport, $mcastcode; global $mcast, $mcastexpect, $mcastaddr, $mcastport, $mcastcode;
global $mcastlistport, $mcasttimeout, $mcastretries, $allowgen; global $mcastlistport, $mcasttimeout, $mcastretries, $allowgen;
global $rigipsecurity, $rigtotals, $forcerigtotals; global $rigipsecurity, $rigtotals, $forcerigtotals;
@ -48,6 +49,13 @@ $poolinputs = false;
# format: 'IP:Port' or 'Host:Port' or 'Host:Port:Name' # format: 'IP:Port' or 'Host:Port' or 'Host:Port:Name'
$rigs = array('127.0.0.1:4028'); $rigs = array('127.0.0.1:4028');
# #
# Set $rignames to false, or one of 'ip' or 'ipx'
# this says what to use if $rigs doesn't have a 'name'
$rignames = false;
#
# Set $rigbuttons to false to display a link rather than a button
$rigbuttons = true;
#
# Set $mcast to true to look for your rigs and ignore $rigs # Set $mcast to true to look for your rigs and ignore $rigs
$mcast = false; $mcast = false;
# #
@ -247,6 +255,9 @@ $colourtable = array(
$miner = null; $miner = null;
$port = null; $port = null;
# #
global $rigips;
$rigips = array();
#
# Ensure it is only ever shown once # Ensure it is only ever shown once
global $showndate; global $showndate;
$showndate = false; $showndate = false;
@ -289,6 +300,14 @@ function getdom($domname)
return getcss($domname, true); return getcss($domname, true);
} }
# #
# N.B. don't call this before calling htmlhead()
function php_pr($cmd)
{
global $here, $autorefresh;
return "$here?ref=$autorefresh$cmd";
}
#
function htmlhead($mcerr, $checkapi, $rig, $pg = null, $noscript = false) function htmlhead($mcerr, $checkapi, $rig, $pg = null, $noscript = false)
{ {
global $doctype, $title, $miner_font_family, $miner_font_size; global $doctype, $title, $miner_font_family, $miner_font_size;
@ -491,7 +510,7 @@ function getrigs()
# #
function getsock($rig, $addr, $port) function getsock($rig, $addr, $port)
{ {
global $rigipsecurity; global $rigips, $rignames, $rigipsecurity;
global $haderror, $error, $socksndtimeoutsec, $sockrcvtimeoutsec; global $haderror, $error, $socksndtimeoutsec, $sockrcvtimeoutsec;
$error = null; $error = null;
@ -534,6 +553,9 @@ function getsock($rig, $addr, $port)
socket_close($socket); socket_close($socket);
return null; return null;
} }
if ($rignames !== false && !isset($rigips[$addr]))
if (socket_getpeername($socket, $ip) == true)
$rigips[$addr] = $ip;
return $socket; return $socket;
} }
# #
@ -1536,39 +1558,67 @@ function process($cmds, $rig)
# #
function rigname($rig, $rigname) function rigname($rig, $rigname)
{ {
global $rigs; global $rigs, $rignames, $rigips;
if (isset($rigs[$rig])) if (isset($rigs[$rig]))
{ {
$parts = explode(':', $rigs[$rig], 3); $parts = explode(':', $rigs[$rig], 3);
if (count($parts) == 3) if (count($parts) == 3)
$rigname = $parts[2]; $rigname = $parts[2];
else
if ($rignames !== false)
{
switch ($rignames)
{
case 'ip':
if (isset($parts[0]) && isset($rigips[$parts[0]]))
{
$ip = explode('.', $rigips[$parts[0]]);
if (count($ip) == 4)
$rigname = intval($ip[3]);
}
break;
case 'ipx':
if (isset($parts[0]) && isset($rigips[$parts[0]]))
{
$ip = explode('.', $rigips[$parts[0]]);
if (count($ip) == 4)
$rigname = intval($ip[3], 16);
}
break;
}
}
} }
return $rigname; return $rigname;
} }
# #
function riginput($rig, $rigname) function riginput($rig, $rigname, $usebuttons)
{ {
$rigname = rigname($rig, $rigname); $rigname = rigname($rig, $rigname);
if ($usebuttons === true)
return "<input type=button value='$rigname' onclick='pr(\"&rig=$rig\",null)'>"; return "<input type=button value='$rigname' onclick='pr(\"&rig=$rig\",null)'>";
else
return "<a href='".php_pr("&rig=$rig")."'>$rigname</a>";
} }
# #
function rigbutton($rig, $rigname, $when, $row) function rigbutton($rig, $rigname, $when, $row, $usebuttons)
{ {
list($value, $class) = fmt('BUTTON', 'Rig', '', $when, $row); list($value, $class) = fmt('BUTTON', 'Rig', '', $when, $row);
if ($rig === '') if ($rig === '')
$ri = '&nbsp;'; $ri = '&nbsp;';
else else
$ri = riginput($rig, $rigname); $ri = riginput($rig, $rigname, $usebuttons);
return "<td align=middle$class>$ri</td>"; return "<td align=middle$class>$ri</td>";
} }
# #
function showrigs($anss, $headname, $rigname) function showrigs($anss, $headname, $rigname)
{ {
global $rigbuttons;
$dthead = array($headname => 1, 'STATUS' => 1, 'Description' => 1, 'When' => 1, 'API' => 1, 'sgminer' => 1); $dthead = array($headname => 1, 'STATUS' => 1, 'Description' => 1, 'When' => 1, 'API' => 1, 'sgminer' => 1);
showhead('', $dthead); showhead('', $dthead);
@ -1591,7 +1641,7 @@ function showrigs($anss, $headname, $rigname)
foreach ($dthead as $name => $x) foreach ($dthead as $name => $x)
{ {
if ($item == 'STATUS' && $name == $headname) if ($item == 'STATUS' && $name == $headname)
echo rigbutton($rig, $rigname.$rig, $when, null); echo rigbutton($rig, $rigname.$rig, $when, null, $rigbuttons);
else else
{ {
if (isset($row[$name])) if (isset($row[$name]))
@ -1610,7 +1660,7 @@ function showrigs($anss, $headname, $rigname)
function doforeach($cmd, $des, $sum, $head, $datetime) function doforeach($cmd, $des, $sum, $head, $datetime)
{ {
global $miner, $port; global $miner, $port;
global $error, $readonly, $notify, $rigs; global $error, $readonly, $notify, $rigs, $rigbuttons;
global $warnfont, $warnoff, $dfmt; global $warnfont, $warnoff, $dfmt;
global $rigerror; global $rigerror;
@ -1747,7 +1797,7 @@ function doforeach($cmd, $des, $sum, $head, $datetime)
echo "<td align=right$class>Total:</td>"; echo "<td align=right$class>Total:</td>";
} }
else else
echo rigbutton($rig, "Rig $rig", $when, $row); echo rigbutton($rig, "Rig $rig", $when, $row, $rigbuttons);
} }
else else
{ {
@ -1780,7 +1830,7 @@ function refreshbuttons()
# #
function pagebuttons($rig, $pg) function pagebuttons($rig, $pg)
{ {
global $readonly, $rigs, $userlist, $ses; global $readonly, $rigs, $rigbuttons, $userlist, $ses;
global $allowcustompages, $customsummarypages; global $allowcustompages, $customsummarypages;
if ($rig === null) if ($rig === null)
@ -1819,10 +1869,12 @@ function pagebuttons($rig, $pg)
if ($userlist === null || isset($_SESSION[$ses])) if ($userlist === null || isset($_SESSION[$ses]))
{ {
if ($prev !== null) if ($prev !== null)
echo riginput($prev, 'Prev').'&nbsp;'; echo riginput($prev, 'Prev', true).'&nbsp;';
echo "<input type=button value='Refresh' onclick='pr(\"$refresh\",null)'>&nbsp;"; echo "<input type=button value='Refresh' onclick='pr(\"$refresh\",null)'>&nbsp;";
if ($next !== null) if ($next !== null)
echo riginput($next, 'Next').'&nbsp;'; echo riginput($next, 'Next', true).'&nbsp;';
echo '&nbsp;'; echo '&nbsp;';
if (count($rigs) > 1) if (count($rigs) > 1)
echo "<input type=button value='Summary' onclick='pr(\"\",null)'>&nbsp;"; echo "<input type=button value='Summary' onclick='pr(\"\",null)'>&nbsp;";
@ -2184,6 +2236,8 @@ function secmatch($section, $field)
# #
function customset($showfields, $sum, $section, $rig, $isbutton, $result, $total) function customset($showfields, $sum, $section, $rig, $isbutton, $result, $total)
{ {
global $rigbuttons;
foreach ($result as $sec => $row) foreach ($result as $sec => $row)
{ {
$secname = preg_replace('/\d/', '', $sec); $secname = preg_replace('/\d/', '', $sec);
@ -2200,7 +2254,7 @@ function customset($showfields, $sum, $section, $rig, $isbutton, $result, $total
if ($isbutton) if ($isbutton)
echo rigbutton($rig, $rig, $when, $row); echo rigbutton($rig, $rig, $when, $row, $rigbuttons);
else else
{ {
list($ignore, $class) = fmt('total', '', '', $when, $row); list($ignore, $class) = fmt('total', '', '', $when, $row);

Loading…
Cancel
Save