Basic framework for MISC-5 - will allow testing the viability against the existing tools
Basic framework for MISC-5 - will allow testing the viability against the existing tools

file:b/fake_onion_ip.php (new)
--- /dev/null
+++ b/fake_onion_ip.php
@@ -1,1 +1,76 @@
+<?php
+/**
+ * @package     fake_onion_ip.plugin
+ *
+ * @copyright   Copyright (C) 2015 B Tasker. All rights reserved.
+ * @license     GNU General Public License version 2 or later; see LICENSE.txt
+ *
+ * See http://projects.bentasker.co.uk/jira_projects/browse/MISC-5.html to see what this plugin was built for
+ */
 
+defined('_JEXEC') or die;
+
+
+/**
+ * Plugin to send a custom header if specific conditions are met
+ *
+ */
+class plgSystemfake_onion_ip extends JPlugin
+{
+
+	protected $plugin;
+	protected $plgParams;
+	var $debug = array();
+
+
+	function __construct(&$subject, $config){
+	    parent::__construct ( $subject, $config );
+	    $this->plugin = JPluginHelper::getPlugin ( 'system', 'fake_onion_ip' );
+	    $this->plgParams = new JRegistry ( $this->plugin->params );
+	}
+
+
+	/**
+	 * Plugin to change the IP address that protections such as admin tools will see
+	 *
+	 * @return void;
+	 */
+	public function onAfterInitialise()
+	{
+	      $app = JFactory::getApplication();
+	      $runon = $this->plgParams->get('runonAdmin',2);
+	      $isAdmin = $app->isAdmin();
+
+	      if ($isAdmin && $runon == '0'){
+		    return true;
+	      }
+
+	      $trigger = $this->plgParams->get('triggerheaderName','X-Example-Null');
+	      $reqvalue = false;
+
+	      if (stristr($trigger,"=")){
+		    $split = explode("=",$trigger);
+		    $reqvalue = $split[1];
+		    $trigger = $split[0];
+	      }
+
+	      $header = str_replace("-","_",strtoupper($trigger));
+
+	      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]);
+	      }else{
+		  // Nothing to do
+		  return true;
+	      }
+	}
+
+
+	protected function calculateFakeIP($info){
+	      // Temp test
+	      return '10.19.1.25';
+	}
+
+}
+
+

file:b/fake_onion_ip.xml (new)
--- /dev/null
+++ b/fake_onion_ip.xml
@@ -1,1 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<extension version="3.0" type="plugin" group="system" method="upgrade">
+	<name>Fake IP Generator</name>
+	<author>B Tasker</author>
+	<creationDate>May 2015</creationDate>
+	<copyright>Copyright (C) 2015 - B Tasker</copyright>
+	<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
+	<authorEmail>fkonionipplg@bentasker.co.uk</authorEmail>
+	<authorUrl>www.bentasker.co.uk</authorUrl>
+	<version>1.0.1</version>
+	<description>Plugin to generate a 'source' IP based on information sent from downstream (for the benefit of Admin Tools WAF and similar mechanisms)</description>
+	<files>
+		<filename plugin="fake_onion_ip">fake_onion_ip.php</filename>
+	</files>
+	
+	<config>
+	  <fields name="params">
+		<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="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>
+		    <option value="2">Front and Back-End</option>
+		  </field>
+		</fieldset>
+	  </fields>
+	</config>	
+</extension>