Suggestion: Optionally log X-Forwarded-For

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
Zugschlus
Regular
Posts: 144
Joined: Sun Feb 05, 2006 12:54 am
Location: St. Ilgen, Germany
Contact:

Suggestion: Optionally log X-Forwarded-For

Post by Zugschlus »

Hi,

the apache that runs my s9y is located behind a reverse proxy. It therefore logs all access as originating from 127.0.0.1.

I would like to have an option making s9y log the IP addresses given in the X-Forwarded-For-Header of the http request instead or additional to the client IP address. Statistics should use the address from X-Forwarded-For as default, falling back to client IP if that header is not present.
--
Marc Haber, St. Ilgen, Germany
https://blog.zugschlus.de/ - nach langer Pause jetzt wieder online
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Suggestion: Optionally log X-Forwarded-For

Post by garvinhicking »

You should be able to easily get this by replacing "REMOTE_ADDR" with "X_FORWARDED_FOR" in the source code, right?

I have never used any reverse proxy, so I know nothing about that stuff.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Zugschlus
Regular
Posts: 144
Joined: Sun Feb 05, 2006 12:54 am
Location: St. Ilgen, Germany
Contact:

Re: Suggestion: Optionally log X-Forwarded-For

Post by Zugschlus »

garvinhicking wrote:You should be able to easily get this by replacing "REMOTE_ADDR" with "X_FORWARDED_FOR" in the source code, right?
I don't know enough about php to comment about this, but the final code should probably have something like "if defined X_FORWARDED_FOR { return X_FORWARDED_FOR } else { return REMOTE_ADDR }"

Otherwise, for examples, all comments and trackback show up as being made from the IP address of the reverse proxy, which makes spam filters ineffective.
--
Marc Haber, St. Ilgen, Germany
https://blog.zugschlus.de/ - nach langer Pause jetzt wieder online
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Suggestion: Optionally log X-Forwarded-For

Post by garvinhicking »

Please try to replace all "REMOTE_ADDR" in your serendipity files with "X_FORWARDED_FOR" on a global replace (case sensitive). I have no possibilities to check if this works; if it does, I can include a more verbose patch that will first check if X_FORWARDED_FOR is set.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Post Reply