Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Topic started by: C. Davis on November 04, 2015, 11:55:17 PM

Title: Cloudflare IP Referral Support
Post by: C. Davis on November 04, 2015, 11:55:17 PM
Link to Mod (http://custom.simplemachines.org/mods/index.php?mod=4072)

Introduction
Some of you may have been wanting to use Cloudflare with your forums and noticed that it uses the IP of your server as the $_SERVER["REMOTE_ADDR"] causing issues with banning people and even displaying people's IPs. I've found a VERY simple work around and implemented it in this simple mod. It pretty much checks if the Remote address is your server IP or inside of cloudflare's ip range that they own, it will change the $_SERVER["REMOTE_ADDR"] to the Cloudflare user address.

The IP ranges in the list come from here: https://www.cloudflare.com/ips

As far as I'm aware it is 100% working.

Installation Instructions

If you do not have Tapatalk installed, use only cloudflare_ip_refferal_support_v1.zip

If you have Tapatalk, use only cloudflare_ip_refferal_support_tapatalk_v1.zip

Changelog
v1.2-
Cloudflare IPs changed into an array

v1-
Initial Release

License
Code: [Select]
The MIT License (MIT)

Copyright (c) 2015 Connor Davis

Permission is hereby granted,
free of charge, to any person obtaining a copy
of this software and associated
documentation files (the "Software"), to deal
in the Software without restriction,
including without limitation the rights
to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell
copies of the Software, and to permit persons
to whom the Software is
furnished to do so, subject to the following conditions:


The above copyright notice and this permission notice shall be included in
all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED
"AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE
SOFTWARE.
Title: Re: Cloudflare IP Referral Support
Post by: dougiefresh on November 05, 2015, 04:18:50 PM
@C. Davis: Nice mod!  I noticed that you had two versions of the same mod, so I did a comparsion between both versions and found that you can merge both versions by changing this:
Code: (Find) [Select]
<file name="$boarddir/mobiquo/mobiquo.php">to this:
Code: (Replace) [Select]
<file name="$boarddir/mobiquo/mobiquo.php" error="skip">This enables you to only distribute one package for both situations.  Hope this helps you!
Title: Re: Cloudflare IP Referral Support
Post by: Mojohaza1 on December 16, 2015, 11:13:59 PM
I installed this last week and initially all semed to be working fine then I notice one user has an IP of "0.0.0.0" showing in the users online section.

This or some other factor seems to make it generate literally tens of errors per minute.


Just a taste
Code: [Select]
8: Undefined offset: 3
?topic=12446.0 Today at 12:23:38 am
8: Undefined offset: 2
?topic=12446.0 Today at 12:23:38 am
8: Undefined offset: 1
?topic=12446.0 Today at 12:23:38 am
8: Undefined offset: 3
?topic=12446.0 Today at 12:23:38 am
8: Undefined offset: 2
?topic=12446.0 Today at 12:23:38 am

Code: [Select]
More precisely: Undefined offset: 3
File: (removed the start) /Themes/default/smfhacks_templates/global-hf.template.php (main sub template - eval?)
Line: 382

When I uninstall the mod the errors instantly stop.

Conflict with another of my mods probably?

Also, your description says download v1 zip, your change log says you're at v1.2 and the actual latest version is 1.3 according to the mods page.
Make it clearer?
Title: Re: Cloudflare IP Referral Support
Post by: N64dude on February 26, 2016, 02:43:14 PM
I installed this and my forum comes up with this

Fatal error: Cannot redeclare ip_in_network() (previously declared in /home/thexephy/public_html/originalforum/index.php:5) in /home/thexephy/public_html/originalforum/index.php on line 92

how can i fix this so i can tell my friend who created my forum, to sort it out for me.
Title: Re: Cloudflare IP Referral Support
Post by: Kindred on February 26, 2016, 04:04:24 PM
you appear to have installed the mod twice.

You will have to manually remove the duplicated code (probably from several areas)
Title: Re: Cloudflare IP Referral Support
Post by: Vagrancy on August 18, 2016, 07:42:32 AM
I get the 0.0.0.0 address too (currently for only 1 account), both on Who's Online and in Track User. No errors have been generated as of yet, however.
Title: Re: Cloudflare IP Referral Support
Post by: chrishicks on August 18, 2016, 08:23:55 AM
I'm 99.99% sure a 0.0.0.0 IP is when a user is on IPv6. If I use my account through my VPN I will have an actual IP because I connect to my site via IPv4 and when I turn off the VPN I connect with IPv6. I've tested this using a few Firefox add-ons and can easily reproduce it with other browsers and computers in the house as well. In your Cloudflare settings(Network - IPv6 Compatibility) you can turn off IPv6 if you want to test it to see if that helps with the 0.0.0.0 issue. It never bothered me so I never disabled the setting myself so I can't say for sure if it's the exact problem/solution but it's worth a try.
Title: Re: Cloudflare IP Referral Support
Post by: Vagrancy on August 18, 2016, 11:55:09 AM
Nice find, I will check that out immediately.
Title: Re: Cloudflare IP Referral Support
Post by: MultiformeIngegno on November 30, 2016, 07:38:07 AM
Are the ranges hardcoded or taken from here?
https://www.cloudflare.com/ips/

Because CF will be updating the ranges soon:
https://support.cloudflare.com/hc/en-us/articles/200172456-CloudFlare-is-now-broadcasting-from-new-IP-ranges-
Title: Re: Cloudflare IP Referral Support
Post by: chrishicks on December 01, 2016, 03:04:51 PM
Looking at the IPs in their list the only new one I see is 131.0.72.0/22(since this mod only uses IPv4). I just added the following to the code for the mod in index.php.

Code: [Select]
'15' => array(
'ip' => '131.0.72.0',
'range' => '22'
),

Title: Re: Cloudflare IP Referral Support
Post by: mrhope on February 02, 2021, 11:00:22 PM
It doesn't appear that C. Davis is still active. However, I was planning on testing this mod tomorrow and thought it would be worth mentioning that on the Cloudflare IP page (https://www.cloudflare.com/ips/), the following IP range was removed.

Quote
Jun 7, 2017: 199.27.128.0/21 removed from ips-v4

Also, they have a new IP range (131.0.72.0/22). So, element 14 of the array should be updated to the following code.

Code: [Select]
'14' => array(
    'ip' => '131.0.72.0',
    'range' => '22'
),

If anyone has a suggestion on a better Cloudflare IP mod that's maintained, I'd also welcome suggestions.
Title: Re: Cloudflare IP Referral Support
Post by: mrhope on February 04, 2021, 05:35:55 PM
Attempting to install this with 2.0.18 I get the following error.

Quote
Incorrect string value: '''' for function inet_aton
File: /home/hope/public_html/forum/Sources/Subs.php
Line: 2650

Note: It appears that your database may require an upgrade. Your forum's files are currently at version SMF 2.0.18, while your database is at version 2.0.10. The above error might possibly go away if you execute the latest version of upgrade.php.
Title: Re: Cloudflare IP Referral Support
Post by: vbgamer45 on February 04, 2021, 05:47:14 PM
That is normally an IPv6 error SMF 2.0.x doesn't support it by default

You can also fork this as your own mod too the license for the mod allows it.
Title: Re: Cloudflare IP Referral Support
Post by: mrhope on February 04, 2021, 07:11:36 PM
Thank you, you're right that error is related to IPv6 and CloudFlare no longer allows you to disable IPv6.

Quote
Why can’t I turn off IPv6?
At Cloudflare we believe in being good to the Internet and good to our customers. By moving on from the legacy world of IPv4-only to the modern-day world where IPv4 and IPv6 are treated equally, we believe we are doing exactly that. In the Cloudflare dashboard, IPv6 is no longer something you can toggle on and off, it’s always just on.

So, I don't think I'd want to fork this mod since SMF does not support IPv6 by default. Is there a method of suggesting this mod get removed. Without IPv6 support, this mod isn't going to resolve issues for anyone running Cloudflare.
Title: Re: Cloudflare IP Referral Support
Post by: vbgamer45 on February 04, 2021, 07:55:17 PM
There is a mod that adds ipv6 to smf 2.0.x https://custom.simplemachines.org/mods/index.php?mod=3051

Otherwise SMF 2.1 would be the way to go