Added the basic algorithm defined in MISC-5
Added the basic algorithm defined in MISC-5

--- a/fake_onion_ip.php
+++ b/fake_onion_ip.php
@@ -58,7 +58,10 @@
 
 	      if (isset($_SERVER['HTTP_'.$header]) && (!$reqvalue || $_SERVER['HTTP_'.$header] == $reqvalue)){
 		  $info_header=str_replace("-","_",strtoupper($this->plgParams->get('infoheaderName','X-Null-val')));
-		  $_SERVER['HTTP_X_FORWARDED_FOR'] = $this->calculateFakeIP($_SERVER['HTTP_'.$info_header]);
+		  $fakeip = $this->calculateFakeIP($_SERVER['HTTP_'.$info_header],$this->plgParams->get('fakeaddressspace','169.254'));
+		  $_SERVER['HTTP_X_FORWARDED_FOR'] = $fakeip;
+		  // For admin tools to pick up on it, we also need to set in REMOTE_ADDR
+		  $_SERVER['REMOTE_ADDR'] = $fakeip;
 	      }else{
 		  // Nothing to do
 		  return true;
@@ -66,9 +69,41 @@
 	}
 
 
-	protected function calculateFakeIP($info){
-	      // Temp test
-	      return '10.19.1.25';
+	/** Create a 'real' IP in the DHCP reserved address space (so there are no local clashes)
+	* Designed to be based on the client's source port, but any int within that range will probably do
+	*
+	* @arg sport - INT
+	* @arg pref - String - the first two octets of the IPv4 address to generate
+	*
+	* @return string
+	*/
+	protected function calculateFakeIP($sport,$pref){
+
+	      // Calculate the time to the nearest 10 minute block
+	      $second = time();
+	      $now = ceil($second/600)*600;
+	      $min = date('i',$now);
+
+
+	      // Calculate the fourth octet
+	      $portcalc = round(($sport/258),1);
+	      $oct4 = round($portcalc,0);
+
+	      // Use the decimal remainder of the calculation to work out what to add to our minute calculation
+	      $dec = ($portcalc - $oct4)*10;
+
+	      // Prevent negatives
+	      if ($oct4 > $portcalc){
+		      $dec = (($portcalc+1) - $oct4)*10;
+	      }else{
+		      $dec = ($portcalc - $oct4)*10;
+	      }
+
+	      // Round it and we have our third octet
+	      $oct3 = round($min + $dec);
+
+	      // Return our new IP
+	      return "$pref.$oct3.$oct4";
 	}
 
 }

--- a/fake_onion_ip.xml
+++ b/fake_onion_ip.xml
@@ -18,6 +18,7 @@
 		<fieldset name="basic">
 		  <field name="triggerheaderName" type="text" label="Trigger Header" description="Which Header Should be present for the plugin to trigger? Include an = if you want to require a specific value as well" default="X-EXAMPLE=foo" />
 		  <field name="infoheaderName" type="text" label="Data Header" description="Name of the header containing the identifying information (should be an int between 0>65535)" default="X-client-info" />
+		  <field name="fakeaddressspace" type="text" label="Address Space" description="We always use a /16 but what should the first two octets be?" default="169.254" />
 		  <field name="runonAdmin" type="list" label="Run on" default="0" description="Where should the plugin trigger?">
 		    <option value="0">Front-End Only</option>
 		    <option value="1">Back-End Only</option>