fabiocaccamo/django-maintenance-mode

Way to add subnets on ip addresses to ignore

davidgomezcol opened this issue · 7 comments

Python version
3.8

Django version
1.11

Package version
0.14.0

Current behavior (bug description)
Is there a way to add the subnets to the ip addresses to ignore when maintenance mode is active?

to something like this? because i tried this way and it's not working for me:

MAINTENANCE_MODE_IGNORE_URLS = ('192.168.0.0/32',)

Expected behavior
192.168.0.0/32

@davidgomezcol as documentation says:

# list of urls that will not be affected by the maintenance-mode
# urls will be used to compile regular expressions objects
MAINTENANCE_MODE_IGNORE_URLS = ()

So you just need to "prepare" your url for regex usage:

MAINTENANCE_MODE_IGNORE_URLS = ('192\.168\.0\.0\/32',)

Great! thank you very much! didn't mean to put this as a bug, but github didn't give me another option. Thank you for you quick reply..

Don't worry!

Hello!.. I'm adding my ip addresses like this.. but it doesn't seem to work.. i'm still having 503's after this.. and there's a bunch of them.. i'm just sharing you a little.. there's about of 200 ip addresses that i need to add there..
MAINTENANCE_MODE_IGNORE_IP_ADDRESSES = ( '31\.186\.232\.0\/24', '34\.90\.192\.162', '37\.230\.97\.9', '63\.251\.76\.0\/25',)

I tested both ways and is not working for me... --- > MAINTENANCE_MODE_IGNORE_URLS

Sorry, but there is some confusion here:

  • MAINTENANCE_MODE_IGNORE_URLS check a match in the url path, excluding the domain name.
  • MAINTENANCE_MODE_IGNORE_IP_ADDRESSES check a match in the client ip returned by MAINTENANCE_MODE_GET_CLIENT_IP_ADDRESS (see the README).

So, in your case you should add ip-addresses to MAINTENANCE_MODE_IGNORE_IP_ADDRESSES (without escaping them) and write your own custom MAINTENANCE_MODE_GET_CLIENT_IP_ADDRESS function.

I'm using django-ipware to get the user ip address.. the problem is that i have is with this kind of ip addresses 23.64.0.0/14 that could be a bunch of them, so if django-ipware grabs the ip address for example 23.67.255.255 that would be in the list of ip address from 23.64.0.0/14. I thought that probably this could have an internal function that handles that kind of situation, where can be a added this way.. i have a large list of ip addresses that i need to add like that..

You should write your own function wrapping ipware.