Merge pull request #548 from kanoi/master miner.php auto naming and size reduction for a large number of rigs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
diff --git a/API-README b/API-README
index 88b29a2..3416aba 100644
--- a/API-README
+++ b/API-README
@@ -1220,20 +1220,49 @@ However, if $readonly is true, it will not display them
---------
Default:
+ $rigport = 4028;
+
+Default port to use if any $rigs entries don't specify the port number
+
+---------
+
+Default:
$rigs = array('127.0.0.1:4028');
Set $rigs to an array of your cgminer rigs that are running
- format: 'IP:Port' or 'Host:Port' or 'Host:Port:Name'
+ format: 'IP' or 'Host' or 'IP:Port' or 'Host:Port' or 'Host:Port:Name'
If you only have one rig, it will just show the detail of that rig
If you have more than one rig it will show a summary of all the rigs
with buttons to show the details of each rig -
the button contents will be 'Name' rather than rig number, if you
specify 'Name'
+If Port is missing or blank, it will try $rigport
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:
$mcast = false;
Set $mcast to true to look for your rigs and ignore $rigs
diff --git a/miner.php b/miner.php
index ff2e457..6fd0658 100644
--- a/miner.php
+++ b/miner.php
@@ -1,7 +1,8 @@
<?php
session_start();
#
-global $doctype, $title, $miner, $port, $readonly, $notify, $rigs;
+global $doctype, $title, $miner, $port, $readonly, $notify;
+global $rigport, $rigs, $rignames, $rigbuttons;
global $mcast, $mcastexpect, $mcastaddr, $mcastport, $mcastcode;
global $mcastlistport, $mcasttimeout, $mcastretries, $allowgen;
global $rigipsecurity, $rigtotals, $forcerigtotals;
@@ -44,10 +45,20 @@ $checklastshare = true;
# N.B. also if $readonly is true, it will not display the fields
$poolinputs = false;
#
+# Default port to use if any $rigs entries don't specify the port number
+$rigport = 4028;
+#
# Set $rigs to an array of your cgminer rigs that are running
-# format: 'IP:Port' or 'Host:Port' or 'Host:Port:Name'
+# format: 'IP' or 'Host' or 'IP:Port' or 'Host:Port' or 'Host:Port:Name'
$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
$mcast = false;
#
@@ -247,6 +258,9 @@ $colourtable = array(
$miner = null;
$port = null;
#
+global $rigips;
+$rigips = array();
+#
# Ensure it is only ever shown once
global $showndate;
$showndate = false;
@@ -289,6 +303,14 @@ function getdom($domname)
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)
{
global $doctype, $title, $miner_font_family, $miner_font_size;
@@ -491,9 +513,12 @@ function getrigs()
#
function getsock($rig, $addr, $port)
{
- global $rigipsecurity;
+ global $rigport, $rigips, $rignames, $rigipsecurity;
global $haderror, $error, $socksndtimeoutsec, $sockrcvtimeoutsec;
+ $port = trim($port);
+ if (strlen($port) == 0)
+ $port = $rigport;
$error = null;
$socket = null;
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
@@ -534,6 +559,9 @@ function getsock($rig, $addr, $port)
socket_close($socket);
return null;
}
+ if ($rignames !== false && !isset($rigips[$addr]))
+ if (socket_getpeername($socket, $ip) == true)
+ $rigips[$addr] = $ip;
return $socket;
}
#
@@ -1536,39 +1564,67 @@ function process($cmds, $rig)
#
function rigname($rig, $rigname)
{
- global $rigs;
+ global $rigs, $rignames, $rigips;
if (isset($rigs[$rig]))
{
$parts = explode(':', $rigs[$rig], 3);
if (count($parts) == 3)
$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;
}
#
-function riginput($rig, $rigname)
+function riginput($rig, $rigname, $usebuttons)
{
$rigname = rigname($rig, $rigname);
- return "<input type=button value='$rigname' onclick='pr(\"&rig=$rig\",null)'>";
+ if ($usebuttons === true)
+ 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);
if ($rig === '')
$ri = ' ';
else
- $ri = riginput($rig, $rigname);
+ $ri = riginput($rig, $rigname, $usebuttons);
return "<td align=middle$class>$ri</td>";
}
#
function showrigs($anss, $headname, $rigname)
{
+ global $rigbuttons;
+
$dthead = array($headname => 1, 'STATUS' => 1, 'Description' => 1, 'When' => 1, 'API' => 1, 'CGMiner' => 1);
showhead('', $dthead);
@@ -1591,7 +1647,7 @@ function showrigs($anss, $headname, $rigname)
foreach ($dthead as $name => $x)
{
if ($item == 'STATUS' && $name == $headname)
- echo rigbutton($rig, $rigname.$rig, $when, null);
+ echo rigbutton($rig, $rigname.$rig, $when, null, $rigbuttons);
else
{
if (isset($row[$name]))
@@ -1610,7 +1666,7 @@ function showrigs($anss, $headname, $rigname)
function doforeach($cmd, $des, $sum, $head, $datetime)
{
global $miner, $port;
- global $error, $readonly, $notify, $rigs;
+ global $error, $readonly, $notify, $rigs, $rigbuttons;
global $warnfont, $warnoff, $dfmt;
global $rigerror;
@@ -1629,10 +1685,13 @@ function doforeach($cmd, $des, $sum, $head, $datetime)
continue;
$parts = explode(':', $rig, 3);
- if (count($parts) >= 2)
+ if (count($parts) >= 1)
{
$miner = $parts[0];
- $port = $parts[1];
+ if (count($parts) >= 2)
+ $port = $parts[1];
+ else
+ $port = '';
if (count($parts) > 2)
$name = $parts[2];
@@ -1747,7 +1806,7 @@ function doforeach($cmd, $des, $sum, $head, $datetime)
echo "<td align=right$class>Total:</td>";
}
else
- echo rigbutton($rig, "Rig $rig", $when, $row);
+ echo rigbutton($rig, "Rig $rig", $when, $row, $rigbuttons);
}
else
{
@@ -1780,7 +1839,7 @@ function refreshbuttons()
#
function pagebuttons($rig, $pg)
{
- global $readonly, $rigs, $userlist, $ses;
+ global $readonly, $rigs, $rigbuttons, $userlist, $ses;
global $allowcustompages, $customsummarypages;
if ($rig === null)
@@ -1819,10 +1878,12 @@ function pagebuttons($rig, $pg)
if ($userlist === null || isset($_SESSION[$ses]))
{
if ($prev !== null)
- echo riginput($prev, 'Prev').' ';
+ echo riginput($prev, 'Prev', true).' ';
+
echo "<input type=button value='Refresh' onclick='pr(\"$refresh\",null)'> ";
+
if ($next !== null)
- echo riginput($next, 'Next').' ';
+ echo riginput($next, 'Next', true).' ';
echo ' ';
if (count($rigs) > 1)
echo "<input type=button value='Summary' onclick='pr(\"\",null)'> ";
@@ -2184,6 +2245,8 @@ function secmatch($section, $field)
#
function customset($showfields, $sum, $section, $rig, $isbutton, $result, $total)
{
+ global $rigbuttons;
+
foreach ($result as $sec => $row)
{
$secname = preg_replace('/\d/', '', $sec);
@@ -2200,7 +2263,7 @@ function customset($showfields, $sum, $section, $rig, $isbutton, $result, $total
if ($isbutton)
- echo rigbutton($rig, $rig, $when, $row);
+ echo rigbutton($rig, $rig, $when, $row, $rigbuttons);
else
{
list($ignore, $class) = fmt('total', '', '', $when, $row);
@@ -2535,10 +2598,13 @@ function processcustompage($pagename, $sections, $sum, $ext, $namemap)
foreach ($rigs as $num => $rig)
{
$parts = explode(':', $rig, 3);
- if (count($parts) >= 2)
+ if (count($parts) >= 1)
{
$miner = $parts[0];
- $port = $parts[1];
+ if (count($parts) >= 2)
+ $port = $parts[1];
+ else
+ $port = '';
if (count($parts) > 2)
$name = $parts[2];
@@ -2896,10 +2962,13 @@ function display()
if ($rig != null and $rig != '' and $rig >= 0 and $rig < count($rigs))
{
$parts = explode(':', $rigs[$rig], 3);
- if (count($parts) >= 2)
+ if (count($parts) >= 1)
{
$miner = $parts[0];
- $port = $parts[1];
+ if (count($parts) >= 2)
+ $port = $parts[1];
+ else
+ $port = '';
if ($readonly !== true)
$preprocess = $arg;
@@ -2948,10 +3017,13 @@ function display()
if (count($rigs) == 1)
{
$parts = explode(':', $rigs[0], 3);
- if (count($parts) >= 2)
+ if (count($parts) >= 1)
{
$miner = $parts[0];
- $port = $parts[1];
+ if (count($parts) >= 2)
+ $port = $parts[1];
+ else
+ $port = '';
htmlhead($mcerr, true, 0);
doOne(0, $preprocess);
@@ -2968,10 +3040,13 @@ function display()
if ($rig != null and $rig != '' and $rig >= 0 and $rig < count($rigs))
{
$parts = explode(':', $rigs[$rig], 3);
- if (count($parts) >= 2)
+ if (count($parts) >= 1)
{
$miner = $parts[0];
- $port = $parts[1];
+ if (count($parts) >= 2)
+ $port = $parts[1];
+ else
+ $port = '';
htmlhead($mcerr, true, 0);
doOne($rig, $preprocess);