miner.php allow pool inputs: delete, addpool, poolpriority
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
diff --git a/miner.php b/miner.php
index 08a419e..3ec9c87 100644
--- a/miner.php
+++ b/miner.php
@@ -3,7 +3,7 @@ session_start();
#
global $miner, $port, $readonly, $notify, $rigs;
global $socksndtimeoutsec, $sockrcvtimeoutsec;
-global $checklastshare, $hidefields;
+global $checklastshare, $poolinputs, $hidefields;
global $ignorerefresh, $changerefresh, $autorefresh;
global $allowcustompages, $customsummarypages;
global $miner_font_family, $miner_font_size;
@@ -23,13 +23,18 @@ $readonly = false;
# coz it doesn't have notify - it just shows the error status table
$notify = true;
#
-# set $checklastshare to true to do the following checks:
+# Set $checklastshare to true to do the following checks:
# If a device's last share is 12x expected ago then display as an error
# If a device's last share is 8x expected ago then display as a warning
# If either of the above is true, also display the whole line highlighted
# This assumes shares are 1 difficulty shares
$checklastshare = true;
#
+# Set $poolinputs to true to show the input fields for adding a pool
+# and changing the pool priorities
+# N.B. also if $readonly is true, it will not display the fields
+$poolinputs = false;
+#
# Set $rigs to an array of your cgminer rigs that are running
# format: 'IP:Port' or 'Host:Port' or 'Host:Port:Name'
# If you only have one rig, it will just show the detail of that rig
@@ -197,7 +202,7 @@ function getdom($domname)
function htmlhead($checkapi, $rig, $pg = null)
{
global $miner_font_family, $miner_font_size;
- global $error, $readonly, $here;
+ global $error, $readonly, $poolinputs, $here;
global $ignorerefresh, $autorefresh;
$extraparams = '';
@@ -252,6 +257,8 @@ if ($ignorerefresh == false)
echo "function prc(a,m){pr('&arg='+a,m)}
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)}
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";
+ if ($poolinputs === true)
+ 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";
}
?>
</script>
@@ -315,6 +322,46 @@ function readsockline($socket)
return $line;
}
#
+function api_convert_escape($str)
+{
+ $res = '';
+ $len = strlen($str);
+ for ($i = 0; $i < $len; $i++)
+ {
+ $ch = substr($str, $i, 1);
+ if ($ch != '\\' || $i == ($len-1))
+ $res .= $ch;
+ else
+ {
+ $i++;
+ $ch = substr($str, $i, 1);
+ switch ($ch)
+ {
+ case '|':
+ $res .= "\1";
+ break;
+ case '\\':
+ $res .= "\2";
+ break;
+ case '=':
+ $res .= "\3";
+ break;
+ case ',':
+ $res .= "\4";
+ break;
+ default:
+ $res .= $ch;
+ }
+ }
+ }
+ return $res;
+}
+#
+function revert($str)
+{
+ return str_replace(array("\1", "\2", "\3", "\4"), array("|", "\\", "=", ","), $str);
+}
+#
function api($cmd)
{
global $haderror, $error;
@@ -336,6 +383,8 @@ function api($cmd)
# print "$cmd returned '$line'\n";
+ $line = api_convert_escape($line);
+
$data = array();
$objs = explode('|', $line);
@@ -373,7 +422,7 @@ function api($cmd)
continue;
if (count($id) == 2)
- $data[$name][$id[0]] = $id[1];
+ $data[$name][$id[0]] = revert($id[1]);
else
$data[$name][$counter] = $id[0];
@@ -448,6 +497,9 @@ function classlastshare($when, $alldata, $warnclass, $errorclass)
if (!isset($alldata['MHS av']))
return '';
+ if ($alldata['MHS av'] == 0)
+ return '';
+
if (!isset($alldata['Last Share Time']))
return '';
@@ -484,6 +536,10 @@ function fmt($section, $name, $value, $when, $alldata)
$ret = $value;
$class = '';
+ $nams = explode('.', $name);
+ if (count($nams) > 1)
+ $name = $nams[count($nams)-1];
+
if ($value === null)
$ret = $b;
else
@@ -491,6 +547,7 @@ function fmt($section, $name, $value, $when, $alldata)
{
case 'GPU.Last Share Time':
case 'PGA.Last Share Time':
+ case 'DEVS.Last Share Time':
if ($value == 0
|| (isset($alldata['Last Share Pool']) && $alldata['Last Share Pool'] == -1))
{
@@ -511,6 +568,7 @@ function fmt($section, $name, $value, $when, $alldata)
break;
case 'GPU.Last Share Pool':
case 'PGA.Last Share Pool':
+ case 'DEVS.Last Share Pool':
if ($value == -1)
{
$ret = 'None';
@@ -573,6 +631,7 @@ function fmt($section, $name, $value, $when, $alldata)
break;
case 'GPU.Utility':
case 'PGA.Utility':
+ case 'DEVS.Utility':
case 'SUMMARY.Utility':
case 'total.Utility':
$ret = $value.'/m';
@@ -593,18 +652,24 @@ function fmt($section, $name, $value, $when, $alldata)
}
break;
case 'PGA.Temperature':
- $ret = $value.'°C';
- break;
case 'GPU.Temperature':
+ case 'DEVS.Temperature':
$ret = $value.'°C';
+ if (!isset($alldata['GPU']))
+ break;
case 'GPU.GPU Clock':
+ case 'DEVS.GPU Clock':
case 'GPU.Memory Clock':
+ case 'DEVS.Memory Clock':
case 'GPU.GPU Voltage':
+ case 'DEVS.GPU Voltage':
case 'GPU.GPU Activity':
+ case 'DEVS.GPU Activity':
if ($value == 0)
$class = $warnclass;
break;
case 'GPU.Fan Percent':
+ case 'DEVS.Fan Percent':
if ($value == 0)
$class = $warnclass;
else
@@ -617,6 +682,7 @@ function fmt($section, $name, $value, $when, $alldata)
}
break;
case 'GPU.Fan Speed':
+ case 'DEVS.Fan Speed':
if ($value == 0)
$class = $warnclass;
else
@@ -632,6 +698,7 @@ function fmt($section, $name, $value, $when, $alldata)
break;
case 'GPU.MHS av':
case 'PGA.MHS av':
+ case 'DEVS.MHS av':
case 'SUMMARY.MHS av':
case 'total.MHS av':
$parts = explode('.', $value, 2);
@@ -658,6 +725,7 @@ function fmt($section, $name, $value, $when, $alldata)
break;
case 'GPU.Total MH':
case 'PGA.Total MH':
+ case 'DEVS.Total MH':
case 'SUMMARY.Total MH':
case 'total.Total MH':
case 'SUMMARY.Getworks':
@@ -665,11 +733,13 @@ function fmt($section, $name, $value, $when, $alldata)
case 'total.Getworks':
case 'GPU.Accepted':
case 'PGA.Accepted':
+ case 'DEVS.Accepted':
case 'SUMMARY.Accepted':
case 'POOL.Accepted':
case 'total.Accepted':
case 'GPU.Rejected':
case 'PGA.Rejected':
+ case 'DEVS.Rejected':
case 'SUMMARY.Rejected':
case 'POOL.Rejected':
case 'total.Rejected':
@@ -687,12 +757,14 @@ function fmt($section, $name, $value, $when, $alldata)
break;
case 'GPU.Status':
case 'PGA.Status':
+ case 'DEVS.Status':
case 'POOL.Status':
if ($value != 'Alive')
$class = $errorclass;
break;
case 'GPU.Enabled':
case 'PGA.Enabled':
+ case 'DEVS.Enabled':
if ($value != 'Y')
$class = $warnclass;
break;
@@ -727,7 +799,8 @@ function fmt($section, $name, $value, $when, $alldata)
global $poolcmd;
$poolcmd = array( 'Switch to' => 'switchpool',
'Enable' => 'enablepool',
- 'Disable' => 'disablepool' );
+ 'Disable' => 'disablepool',
+ 'Remove' => 'removepool' );
#
function showhead($cmd, $values, $justnames = false)
{
@@ -938,6 +1011,43 @@ function processgpus($rig)
}
}
#
+function showpoolinputs($rig, $ans)
+{
+ global $readonly, $poolinputs;
+
+ if ($readonly === true || $poolinputs === false)
+ return;
+
+ newtable();
+ newrow();
+
+ $inps = array('Pool URL' => array('purl', 20),
+ 'Worker Name' => array('pwork', 10),
+ 'Worker Password' => array('ppass', 10));
+ $b = ' ';
+
+ echo "<td align=right class=h> Add a pool: </td><td>";
+
+ foreach ($inps as $text => $name)
+ echo "$text: <input name='".$name[0]."' id='".$name[0]."' value='' type=text size=".$name[1]."> ";
+
+ echo "</td><td align=middle><input type=button value='Add' onclick='pla($rig)'></td>";
+
+ endrow();
+
+ if (count($ans) > 1)
+ {
+ newrow();
+
+ echo '<td align=right class=h> Set pool priorities: </td>';
+ echo "<td> Comma list of pool numbers: <input type=text name=prio id=prio size=20>";
+ echo "</td><td align=middle><input type=button value='Set' onclick='psp($rig)'></td>";
+
+ endrow();
+ }
+ endtable();
+}
+#
function process($cmds, $rig)
{
global $error, $devs;
@@ -957,12 +1067,15 @@ function process($cmds, $rig)
{
details($cmd, $process, $rig);
+ if ($cmd == 'devs')
+ $devs = $process;
+
+ if ($cmd == 'pools')
+ showpoolinputs($rig, $process);
+
# Not after the last one
if (--$count > 0)
otherrow('<td><br><br></td>');
-
- if ($cmd == 'devs')
- $devs = $process;
}
}
}
@@ -1419,6 +1532,9 @@ function joinsections($sections, $results, $errors)
$sectionmap[$section] = $section;
$results[$section] = joinall($both[0], $both[1], $results);
break;
+ default:
+ $errors[] = "Error: Invalid section '$section'";
+ break;
}
break;
case 'DEVS':
@@ -1430,6 +1546,9 @@ function joinsections($sections, $results, $errors)
$sectionmap[$section] = $section;
$results[$section] = joinfields($both[0], $both[1], $join, $results);
break;
+ default:
+ $errors[] = "Error: Invalid section '$section'";
+ break;
}
break;
default: