Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: jackc on January 15, 2015, 08:34:46 AM

Title: How to restore original IP in SMF while using CloudFlare?
Post by: jackc on January 15, 2015, 08:34:46 AM
I have tried the Bad Behavior mod but it doesn't work. Bad Behavior mod settings:

Enable Reverse Proxy: On
IP call to Reverse Proxy: CF-Connecting-IP

Also see someone else with this problem: http://www.simplemachines.org/community/index.php?topic=532447.msg3783480#msg3783480


I do not want to debate the usefulness of CloudFlare here.

Edit: Adding this to the top of my index.php file fixed it without the need for a mod:

if($_SERVER['HTTP_CF_CONNECTING_IP']){
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
}
Title: Re: How to restore original IP in SMF while using CloudFlare?
Post by: margarett on January 15, 2015, 08:39:29 AM
IIRC, CF has a SMF mod at their site that fixes this issue ;)
Title: Re: How to restore original IP in SMF while using CloudFlare?
Post by: Bob Perry of Web Presence Consulting on January 17, 2015, 05:20:40 PM
Thank you guys for this, useful... I'm with yall, still evaluating how useful CF is myself... we'll watch it for a while longer here....
Title: Re: How to restore original IP in SMF while using CloudFlare?
Post by: butchs on January 25, 2015, 06:09:34 PM
Quote from: jackc on January 15, 2015, 08:34:46 AM
I have tried the Bad Behavior mod but it doesn't work. Bad Behavior mod settings:

That setting in Bad Behavior is only for when Bad Behavior does a search.  The settings allow the correct IP address to show up in the Bad Behavior visitor log.  The Bad Behavior setting has absolutely nothing to do with any other log that is not part of the mod.

You will need the Cloud Flare for SMF mod to view SMF logs.
Title: Re: How to restore original IP in SMF while using CloudFlare?
Post by: 1985 on October 12, 2016, 06:38:53 AM
How about this?

https://support.cloudflare.com/hc/en-us/articles/200170876-I-can-t-install-mod-cloudflare-and-there-s-no-plugin-to-restore-original-visitor-IP-What-should-I-do-

"If you can't install mod_cloudflare, or if there is no plugin available for your CMS platform to restore original visitor IP, you would want to put this code in your site in or before the <body>:"
Damon August 21, 2016 14:19
<?php if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) 
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
?>


Can it use for smf? and what file should be fix?

Title: Re: How to restore original IP in SMF while using CloudFlare?
Post by: butchs on January 04, 2017, 06:41:07 PM
You can find the CF mode here:
http://www.simplemachines.org/community/index.php?topic=468525.msg3275201#msg3275201
Title: Re: How to restore original IP in SMF while using CloudFlare?
Post by: solarisjedi on July 09, 2019, 03:19:05 AM
Thought I would add to the thread here, I realize it's old, but this comes up on google results.

Put this in Sources/QueryString.php just before where it checks if $_SERVER['REMOTE_ADDR'] is set. On SMF 2.1 RC2 this is line 251

if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
}


This will make the entire board compatible with cloudflare without any other mods or server config as QueryStrings is the first Source loaded.
Title: Re: How to restore original IP in SMF while using CloudFlare?
Post by: albertlast on July 11, 2019, 01:29:56 PM
A pr got open to this for 2.1
https://github.com/SimpleMachines/SMF2.1/pull/5732
Title: Re: How to restore original IP in SMF while using CloudFlare?
Post by: vbgamer45 on July 11, 2019, 01:31:16 PM
Nice, great idea! Thanks!
Title: Re: How to restore original IP in SMF while using CloudFlare?
Post by: Arantor on July 11, 2019, 01:59:40 PM
2.1 has functionality for this in the Security page... where you can select which one you want to use, including CloudFlare...
Title: Re: How to restore original IP in SMF while using CloudFlare?
Post by: albertlast on July 11, 2019, 02:03:40 PM
To had this on auto detection didn't sound wrong to my eyes.
Title: Re: How to restore original IP in SMF while using CloudFlare?
Post by: Massl on April 26, 2021, 04:32:19 AM
Quote from: albertlast on July 11, 2019, 01:29:56 PM
A pr got open to this for 2.1
https://github.com/SimpleMachines/SMF2.1/pull/5732

Hi, has been included in RC3?
Even if I select "Reverse Proxy IP Header: CF-Connecting-IP" with 2.1 RC3 I only see cloudflare IP.
Thanks
Title: Re: How to restore original IP in SMF while using CloudFlare?
Post by: Kindred on April 26, 2021, 08:22:20 AM
what version of RC3 are you testing?   the distributed one form this site or the one from GitHub that is almost RC4?

According to the merge note, it was not merged until October...
Title: Re: How to restore original IP in SMF while using CloudFlare?
Post by: Massl on April 26, 2021, 08:46:53 AM
Hi Kindred, I'm using the distributed one form this site.

There is the option but it doesn't work correctly.

(https://postimg.cc/NLt7dtnL)
Title: Re: How to restore original IP in SMF while using CloudFlare?
Post by: Kindred on April 26, 2021, 10:24:29 AM
Quote from: Massl on April 26, 2021, 08:46:53 AM
Hi Kindred, I'm using the distributed one form this site.


yup, and that is the "issue" -- that release was made before the merge.

There have been several hundred commits since the RC3 release on this site. During Beta dn RC time-periods, the download from GitHuib is almost always a better option.
Title: Re: How to restore original IP in SMF while using CloudFlare?
Post by: Massl on April 26, 2021, 10:36:32 AM
OK, I applied this change https://github.com/SimpleMachines/SMF2.1/pull/5732/commits/5a5dee8e33e66fff883ba587e3c98418dede6d97 to QueryString.php but it still doesn't work.
I also cleared the cache (SMF + CF)

Can you confirm that with the github version it works correctly?
Title: Re: How to restore original IP in SMF while using CloudFlare?
Post by: Massl on April 26, 2021, 10:45:11 AM
Downloaded the git version and I always see IP cloudflare!
If I revert this
https://github.com/SimpleMachines/SMF2.1/pull/5732/commits/5a5dee8e33e66fff883ba587e3c98418dede6d97
to
https://github.com/SimpleMachines/SMF2.1/pull/5732/commits/37eeccc1f24f9d503c3bf3393e9e063e02b23eed
everything works perfectly and I see the correct IP.

Title: Re: How to restore original IP in SMF while using CloudFlare?
Post by: simplengmakina on May 24, 2021, 12:59:39 AM
Quote from: Massl on April 26, 2021, 10:45:11 AM
Downloaded the git version and I always see IP cloudflare!
If I revert this
https://github.com/SimpleMachines/SMF2.1/pull/5732/commits/5a5dee8e33e66fff883ba587e3c98418dede6d97
to
https://github.com/SimpleMachines/SMF2.1/pull/5732/commits/37eeccc1f24f9d503c3bf3393e9e063e02b23eed
everything works perfectly and I see the correct IP.

Finally! A perfect fix! Thank you for this!
Title: Re: How to restore original IP in SMF while using CloudFlare?
Post by: Massl on August 04, 2021, 12:47:12 PM
Also with RC4 I see only Cloudflare IPs, has anyone tested this bug?
Title: Re: How to restore original IP in SMF while using CloudFlare?
Post by: SD-X on February 16, 2022, 11:32:11 AM
Quote from: Massl on August 04, 2021, 12:47:12 PMAlso with RC4 I see only Cloudflare IPs, has anyone tested this bug?
I hate to bump this, but even in 2.1.1 this is still an issue for me too. None of the RC's ever resolved it for me after the feature was added either.

I can also confirm that using RC4 prior did not fix it.
Title: Re: How to restore original IP in SMF while using CloudFlare?
Post by: Arantor on February 16, 2022, 11:58:07 AM
Did you configure the relevant settings?
Title: Re: How to restore original IP in SMF while using CloudFlare?
Post by: SD-X on February 20, 2022, 11:57:40 PM
Quote from: Arantor on February 16, 2022, 11:58:07 AMDid you configure the relevant settings?
I've tried manually setting the proxy types, as well as using the auto feature. Beyond that, I've been having extreme difficulty finding any information on the subject outside of this topic. I do see the field for setting specific proxy servers for security purposes, but the wording appears to make that optional for better security, and I haven't messed with it yet because I would prefer to get the actual system working first before messing with it more. ;D
Title: Re: How to restore original IP in SMF while using CloudFlare?
Post by: shawnb61 on February 21, 2022, 12:21:23 AM
I swear shadav had a post on this outlining a fix for CloudFlare but I cannot find it.

@shadav?  Are you aware of a fix for IPs under Cloudflare?  Or did you fix it by a call to Cloudflare?
Title: Re: How to restore original IP in SMF while using CloudFlare?
Post by: shadav on February 22, 2022, 12:37:11 AM
lol I think you are thinking about my modem connection issues where I had to change my dns settings use cloudflare ip address or another service because my internet provider (xfinity) sucks

for me on cloudflare I had to turn off Rocket Loader under the optimization settings other wise it messed up my sites (couldn't use the menu, etc)
also turn off Mobile Redirect

as for ip, I don't recall off the top of my head
running a quick search there's this mod for 2.0.x
Cloudflare IP Referral Support (https://simplemachines.org/community/index.php?topic=540940.0)
Title: Re: How to restore original IP in SMF while using CloudFlare?
Post by: SD-X on February 23, 2022, 05:44:48 PM
Quote from: shadav on February 22, 2022, 12:37:11 AMlol I think you are thinking about my modem connection issues where I had to change my dns settings use cloudflare ip address or another service because my internet provider (xfinity) sucks
Well hey, something we have in common. ;D

Quote from: shadav on February 22, 2022, 12:37:11 AMas for ip, I don't recall off the top of my head
running a quick search there's this mod for 2.0.x
Cloudflare IP Referral Support (https://simplemachines.org/community/index.php?topic=540940.0)
Unfortunately that only affects 2.0.x though. 2.1.x is supposed to have support for this built in.

Quote from: shawnb61 on February 21, 2022, 12:21:23 AMI swear shadav had a post on this outlining a fix for CloudFlare but I cannot find it.
By any chance are you referring to using these headers?:
https://developers.cloudflare.com/fundamentals/get-started/http-request-headers