? bootstrap.inc?r1=1.214 ? bootstrap.inc?r1=1.214&r2=1.215&view=patch ? cluster-ip_0.patch ? ip_address.patch ? includes/bootstrap.test Index: includes/bootstrap.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v retrieving revision 1.206.2.4 diff -u -p -r1.206.2.4 bootstrap.inc --- includes/bootstrap.inc 18 Aug 2008 18:56:30 -0000 1.206.2.4 +++ includes/bootstrap.inc 21 Aug 2008 21:39:34 -0000 @@ -1133,25 +1133,39 @@ function language_default($property = NU /** * If Drupal is behind a reverse proxy, we use the X-Forwarded-For header - * instead of $_SERVER['REMOTE_ADDR'], which would be the IP address - * of the proxy server, and not the client's. + * instead of $_SERVER['REMOTE_ADDR'], which would be the IP address of + * the proxy server, and not the client's. If Drupal is run in a cluster + * we use the X-Cluster-Client-Ip header instead. * + * @param $reset + * Reset the current ip address saved in static * @return - * IP address of client machine, adjusted for reverse proxy. + * IP address of client machine, adjusted for reverse proxy and/or cluster + * environments. */ -function ip_address() { +function ip_address($reset = false) { static $ip_address = NULL; - if (!isset($ip_address)) { + if (!isset($ip_address) || $reset) { $ip_address = $_SERVER['REMOTE_ADDR']; - if (variable_get('reverse_proxy', 0) && array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) { - // If an array of known reverse proxy IPs is provided, then trust - // the XFF header if request really comes from one of them. - $reverse_proxy_addresses = variable_get('reverse_proxy_addresses', array()); - if (!empty($reverse_proxy_addresses) && in_array($ip_address, $reverse_proxy_addresses, TRUE)) { - // If there are several arguments, we need to check the most - // recently added one, i.e. the last one. - $ip_address = array_pop(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])); + + if (variable_get('reverse_proxy', 0)) { + if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) { + // If an array of known reverse proxy IPs is provided, then trust + // the XFF header if request really comes from one of them. + $reverse_proxy_addresses = variable_get('reverse_proxy_addresses', array()); + if (!empty($reverse_proxy_addresses) && in_array($ip_address, $reverse_proxy_addresses, TRUE)) { + // If there are several arguments, we need to check the most + // recently added one, i.e. the last one. + $ip_address = array_pop(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])); + } + } + + // When Drupal is run in a cluster environment, REMOTE_ADDR contains the IP + // address of a server in the cluster, while the IP address of the client is + // stored in HTTP_X_CLUSTER_CLIENT_IP. + if (array_key_exists('HTTP_X_CLUSTER_CLIENT_IP', $_SERVER)) { + $ip_address = $_SERVER['HTTP_X_CLUSTER_CLIENT_IP']; } } }