Browse Source

Merge commit '4185b7d' into cg_merges_20131023a

Conflicts:
	README.RPC
Luke Dashjr 12 years ago
parent
commit
1ff7023e5e
2 changed files with 72 additions and 2 deletions
  1. 20 0
      README.RPC
  2. 52 2
      miner.php

+ 20 - 0
README.RPC

@@ -1541,6 +1541,7 @@ The example given:
 With BFGMiner 2.10.1 and later, miner.php includes an extension to the custom
 pages that allows you to apply SQL style commands to the data: where, group,
 and having
+BFGMiner 3.4.0 also includes another option 'gen'
 
 As an example, miner.php includes a more complex custom page called 'Pools'
 this includes the extension:
@@ -1552,6 +1553,7 @@ $poolsext = array(
                          'POOL.Stratum Active'),
         'calc' => array('STATS.Bytes Sent' => 'sum',
                         'STATS.Bytes Recv' => 'sum'),
+        'gen' => array('AvShr', 'POOL.Difficulty Accepted/max(POOL.Accepted,1)),
         'having' => array(array('STATS.Bytes Recv', '>', 0)))
 );
 
@@ -1603,3 +1605,21 @@ The first 4 are as expected - the numerical sum, average, minimum or maximum
  of course any valid 'DEVS.Xyz' would give the same 'count' value
 'any' is effectively random: the field value in the 1st row of the grouped data
 An unrecognised 'function' uses 'any'
+
+A 'gen' allows you to generate new fields from any php valid function of any
+of the other fields
+ e.g. 'gen' => array('AvShr', 'POOL.Difficulty Accepted/max(POOL.Accepted,1)),
+will generate a new field called GEN.AvShr that is the function shown, which
+in this case is the average difficulty of each share submitted
+
+THERE IS A SECURITY RISK WITH HOW GEN WORKS
+It simply replaces all the variables with their values and then requests PHP
+the execute the formula - thus if a field value returned from a BFGMiner API
+request contained PHP code, it could be executed by your web server
+Of course BFGMiner doesn't do this, but if you do not control the BFGMiner that
+returns the data in the API calls, someone could modify BFGMiner to return a
+PHP string in a field you use in 'gen'
+Thus use 'gen' at your own risk
+If someone feels the urge to write a mathematical interpreter in PHP to get
+around this risk, feel free to write one and submit it to the API author for
+consideration

+ 52 - 2
miner.php

@@ -2380,7 +2380,52 @@ function processcompare($which, $ext, $section, $res)
  return $res;
 }
 #
-function processext($ext, $section, $res)
+function ss($a, $b)
+{
+ $la = strlen(a);
+ $lb = strlen(b);
+ if ($la != $lb)
+	return $la - $lb;
+ return strcmp($a, $b);
+}
+#
+function genfld($row, $calc)
+{
+ uksort($row, "ss");
+
+ foreach ($row as $name => $value)
+	if (strstr($calc, $name) !== FALSE)
+		$calc = str_replace($name, $value, $calc);
+
+ eval("\$val = $calc;");
+
+ return $val;
+}
+#
+function dogen($ext, $section, &$res, &$fields)
+{
+ $gen = $ext[$section]['gen'];
+
+ foreach ($gen as $fld => $calc)
+	$fields[] = "GEN.$fld";
+
+ foreach ($res as $rig => $result)
+	foreach ($result as $sec => $row)
+	{
+		$secname = preg_replace('/\d/', '', $sec);
+		if (secmatch($section, $secname))
+			foreach ($gen as $fld => $calc)
+			{
+				$name = "GEN.$fld";
+
+				$val = genfld($row, $calc);
+
+				$res[$rig][$sec][$name] = $val;
+			}
+	}
+}
+#
+function processext($ext, $section, $res, &$fields)
 {
  $res = processcompare('where', $ext, $section, $res);
 
@@ -2449,6 +2494,10 @@ function processext($ext, $section, $res)
 	}
  }
 
+ // Generated fields (functions of other fields)
+ if (isset($ext[$section]['gen']))
+	dogen($ext, $section, $res, $fields);
+
  return processcompare('having', $ext, $section, $res);
 }
 #
@@ -2545,7 +2594,8 @@ function processcustompage($pagename, $sections, $sum, $ext, $namemap)
 
 		if (isset($results[$sectionmap[$section]]))
 		{
-			$rigresults = processext($ext, $section, $results[$sectionmap[$section]]);
+			$rigresults = processext($ext, $section, $results[$sectionmap[$section]], $fields);
+
 			$showfields = array();
 			$showhead = array();
 			foreach ($fields as $field)