Advertisement:

Author Topic: How to restore original IP in SMF while using CloudFlare?  (Read 7664 times)

Offline jackc

  • Newbie
  • *
  • Posts: 3
How to restore original IP in SMF while using CloudFlare?
« 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'];
}

Offline margarett

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 19,759
  • Gender: Male
Re: How to restore original IP in SMF while using CloudFlare?
« Reply #1 on: January 15, 2015, 08:39:29 AM »
IIRC, CF has a SMF mod at their site that fixes this issue ;)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

Quote
Over 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Offline Bob Perry of Web Presence Consulting

  • Sophist Member
  • *****
  • Posts: 1,024
  • Gender: Male
  • (T)ogether (E)veryone (A)chieves (M)ore
    • Bobert921 on Facebook
    • https://www.linkedin.com/in/bperry921/ on LinkedIn
    • @bperry921 on Twitter
    • Web Presence Consulting
Re: How to restore original IP in SMF while using CloudFlare?
« Reply #2 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....
Best Regards,
Bob Perry



"The world is moving so fast these days that the man who says it can't be done is generally interrupted by someone doing it." Elbert Hubbard

Offline butchs

  • SMF Hero
  • ******
  • Posts: 1,734
  • Lost 7GB bandwidth!
    • EastCoastRollingThunder
Re: How to restore original IP in SMF while using CloudFlare?
« Reply #3 on: January 25, 2015, 06:09:34 PM »
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.
« Last Edit: January 25, 2015, 06:34:39 PM by butchs »
I have been truly inspired by the SUGGESTIONS as I sit on my throne and contemplate the wisdom imposed upon me.

Offline 1985

  • Semi-Newbie
  • *
  • Posts: 12
Re: How to restore original IP in SMF while using CloudFlare?
« Reply #4 on: October 12, 2016, 06:38:53 AM »
How about this?

Code: [Select]
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
Code: [Select]
<?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?


Offline butchs

  • SMF Hero
  • ******
  • Posts: 1,734
  • Lost 7GB bandwidth!
    • EastCoastRollingThunder
I have been truly inspired by the SUGGESTIONS as I sit on my throne and contemplate the wisdom imposed upon me.

Offline solarisjedi

  • Newbie
  • *
  • Posts: 5
  • Gender: Male
Re: How to restore original IP in SMF while using CloudFlare?
« Reply #6 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

Code: [Select]
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.

Offline albertlast

  • Development Contributor
  • Full Member
  • *
  • Posts: 648
Re: How to restore original IP in SMF while using CloudFlare?
« Reply #7 on: July 11, 2019, 01:29:56 PM »

Offline vbgamer45

  • Customizer
  • SMF Super Hero
  • *
  • Posts: 23,549
    • smfhacks on Facebook
    • VBGAMER45 on GitHub
    • @createaforum on Twitter
    • SMF For Free
Re: How to restore original IP in SMF while using CloudFlare?
« Reply #8 on: July 11, 2019, 01:31:16 PM »
Nice, great idea! Thanks!
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 73,189
Re: How to restore original IP in SMF while using CloudFlare?
« Reply #9 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...
No good deed goes unpunished
All helpful urges should be circumvented

Offline albertlast

  • Development Contributor
  • Full Member
  • *
  • Posts: 648
Re: How to restore original IP in SMF while using CloudFlare?
« Reply #10 on: July 11, 2019, 02:03:40 PM »
To had this on auto detection didn't sound wrong to my eyes.

Offline Massl

  • Jr. Member
  • **
  • Posts: 338
Re: How to restore original IP in SMF while using CloudFlare?
« Reply #11 on: April 26, 2021, 04:32:19 AM »
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

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 60,355
  • Gender: Male
    • Kindred-999 on GitHub
Re: How to restore original IP in SMF while using CloudFlare?
« Reply #12 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...
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Offline Massl

  • Jr. Member
  • **
  • Posts: 338
Re: How to restore original IP in SMF while using CloudFlare?
« Reply #13 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.


Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 60,355
  • Gender: Male
    • Kindred-999 on GitHub
Re: How to restore original IP in SMF while using CloudFlare?
« Reply #14 on: April 26, 2021, 10:24:29 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.
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Offline Massl

  • Jr. Member
  • **
  • Posts: 338
Re: How to restore original IP in SMF while using CloudFlare?
« Reply #15 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?

Offline Massl

  • Jr. Member
  • **
  • Posts: 338
Re: How to restore original IP in SMF while using CloudFlare?
« Reply #16 on: April 26, 2021, 10:45:11 AM »

Offline simplengmakina

  • Semi-Newbie
  • *
  • Posts: 26
Re: How to restore original IP in SMF while using CloudFlare?
« Reply #17 on: May 24, 2021, 12:59:39 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!