Feature I'd like to see:

Not all web hosts determine the IP address the same way. Some use REMOTE_ADDR, some use HTTP_X_CLUSTER_CLIENT_IP, etc.

I'm proposing a hook for over-riding the default ip_address api call, so small modules could be written to provide this information without having to hack it into the core, in the event of a different IP addressing scheme..

-Myke

Comments

dave reid’s picture

What's wrong with the current implementation? It provides support for both REMOTE_ADDR, HTTP_X_CLUSTER_CLIENT_IP and HTTP_X_FORWARDED_FOR.

myke’s picture

There are other situations where the IP address could end up in a variable besides those.

HTTP_CLIENT_IP is one of them.. (Some proxies use that one..)

But yes, I do love the Drupal 7 implementation so far, I just wish it had a hook so it could be overridden..

-Myke

damien tournoud’s picture

A hook probably won't fly here (ip_address() has to be callable early in the bootstrap process), but we could define an override function, like drupal_mail_wrapper().

myke’s picture

(Hadn't thought about that aspect of it.. =) ) an override function would be good.. For those instances where things need to be customized a little..

-Myke

markus_petrux’s picture

If you're under an environment that is not supported, for whatever reason, one thing you can do is override REMOTE_ADDR from settings.php ;-)

damien tournoud’s picture

@markus_petrux: right.

Maybe that should be documented somewhere?

myke’s picture

How exactly is this done?

-Myke

markus_petrux’s picture

In example, I implemented what ip_address() does since Drupal 6, for a Drupal 5 based site, just adding code at the bottom of my settings.php.

If you're behind a cluster that uses the X-Cluster-Client-Ip header, you can do something similar. But please, don't forget to check $_SERVER['REMOTE_ADDR'] against a whitelist of addresses, otherwise if someone spoofs the header and accesses the site directly (bypassing the cluster), it can make the site see any IP address!

See comment #14 here:

http://drupal.org/node/258397#comment-1089311

markus_petrux’s picture

hmm... maybe I was not clear enough on how it can be done.

settings.php is invoked from conf_init() which happens on the first phase of Drupal bootstrap, and just after PHP superglobals have been sanitized. This is also before ip_address() is used.

Since ip_address() reads the contents of $_SERVER['REMOTE_ADDR'] to obtain the client IP address, you have the chance to include code in your settings.php script to override the value of $_SERVER['REMOTE_ADDR'] with whatever you may need. So you can validate the X-Cluster-Client-Ip header and use that value to set $_SERVER['REMOTE_ADDR'] that is what ip_address() will see later.

dave reid’s picture

Status: Active » Closed (won't fix)

Sounds like this is a won't fix then.