Changeset 777776
- Timestamp:
- 09/24/2013 03:26:13 PM (13 years ago)
- Location:
- incapsula/trunk
- Files:
-
- 2 edited
-
incapsula.php (modified) (2 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
incapsula/trunk/incapsula.php
r765629 r777776 4 4 Plugin URI: http://wordpress.org/extend/plugins/incapsula/ 5 5 Description: The Incapsula plugin will make sure that any reference to the user IP in your WordPress will use the correct IP address when your site is safeguarded by Incapsula 6 Version: 1. 36 Version: 1.4 7 7 Author: Incapsula 8 8 Author URI: http://www.incapsula.com … … 17 17 //name of HTTP header with an initial IP 18 18 define('HEADER_NAME','HTTP_INCAP_CLIENT_IP'); 19 add_action("init", "incap_set_ip",-9999999); 19 20 20 try { 21 //echo('incap header: ['.$_SERVER[HEADER_NAME].']'.'<br />'); 22 //stop process if there is no header 23 if (empty($_SERVER[HEADER_NAME])) throw new Exception('No header defined', 1); 24 25 //validate header value 26 if (function_exists('filter_var')) { 27 $ip = filter_var($_SERVER[HEADER_NAME], FILTER_VALIDATE_IP); 28 if (false === $ip) throw new Exception('The value is not a valid IP address', 2); 21 function incap_set_ip() 22 { 23 try 24 { 25 //echo('incap header: ['.$_SERVER[HEADER_NAME].']'.'<br />'); 26 27 //stop process if there is no header 28 if (empty($_SERVER[HEADER_NAME])) throw new Exception('No header defined', 1); 29 30 //validate header value 31 if (function_exists('filter_var')) 32 { 33 $ip = filter_var($_SERVER[HEADER_NAME], FILTER_VALIDATE_IP); 34 if (false === $ip) throw new Exception('The value is not a valid IP address', 2); 35 } 36 else 37 { 38 $ip = trim($_SERVER[HEADER_NAME]); 39 if (false === preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $ip)) throw new Exception('The value is not a valid IP address', 2); 40 } 41 // 42 //At this point the initial IP value is exist and validated 43 //echo('IP: ['.$ip.']'.'<br />'); 44 $_SERVER['REMOTE_ADDR'] = $ip; 29 45 } 30 else {31 $ip = trim($_SERVER[HEADER_NAME]);32 if (false === preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $ip)) throw new Exception('The value is not a valid IP address', 2);46 catch (Exception $e) 47 { 48 //echo('exeption: ['.$e.']'.'<br />'); 33 49 } 34 //echo('IP: ['.$ip.']'.'<br />');35 //At this point the initial IP value is exist and validated36 $_SERVER['REMOTE_ADDR'] = $ip;37 } catch (Exception $e){38 //echo('exeption: ['.$e.']'.'<br />');39 50 } 40 51 41 /**42 * Makes the pluging run first in order.43 */44 function this_plugin_first() {45 // ensure path to this file is via main wp plugin path46 $wp_path_to_this_file = preg_replace('/(.*)plugins\/(.*)$/', WP_PLUGIN_DIR."/$2", __FILE__);47 echo('this_plugin_first');48 $this_plugin = plugin_basename(trim($wp_path_to_this_file));49 $active_plugins = get_option('active_plugins');50 $this_plugin_key = array_search($this_plugin, $active_plugins);51 if ($this_plugin_key) { // if it's 0 it's the first plugin already, no need to continue52 array_splice($active_plugins, $this_plugin_key, 1);53 array_unshift($active_plugins, $this_plugin);54 update_option('active_plugins', $active_plugins);55 }56 }57 add_action("activated_plugin", "this_plugin_first");58 52 ?> -
incapsula/trunk/readme.txt
r768525 r777776 4 4 Requires at least: 2.8 5 5 Tested up to: 3.6 6 Stable tag: 1. 36 Stable tag: 1.4 7 7 8 8 This plugin ensures that your WordPress website runs optimally using Incapsula. … … 18 18 19 19 * The plugin sets the value of $_SERVER['REMOTE_ADDR'] according to the client IP value reported by the Incapsula proxy. 20 * The plugin will automatically position itself to execute first so that all other plugins that require the originating IP, continue to operate as usual.20 * The plugin will execute with a high priority, to make sure it runs as early as possible. 21 21 22 22 ABOUT INCAPSULA: … … 33 33 34 34 == Changelog == 35 36 = 1.4 = 37 * Instead of fiddling with the plugins' order on the $active_plugins record as before, the plugin now runs on the "init" hook, with a very high priority (set to -9999999). 35 38 36 39 = 1.3 =
Note: See TracChangeset
for help on using the changeset viewer.