Skip to content

Instantly share code, notes, and snippets.

@agusmakmun
Last active November 25, 2016 12:11
Show Gist options
  • Save agusmakmun/09f17c2162c27a3fcc9a10fbe446b56e to your computer and use it in GitHub Desktop.
Save agusmakmun/09f17c2162c27a3fcc9a10fbe446b56e to your computer and use it in GitHub Desktop.
# From: http://django-admin-honeypot.readthedocs.io/en/latest/manual/faq.html#why-is-the-ip-address-logged-as-127-0-0-1
class RemoteAddrMiddleware(object):
def process_request(self, request):
if 'HTTP_X_FORWARDED_FOR' in request.META:
ip = request.META['HTTP_X_FORWARDED_FOR'].split(',')[0].strip()
request.META['REMOTE_ADDR'] = ip
# force all conditions
# https://github.com/dmpayton/django-admin-honeypot/issues/6#issue-13552309
redirect_conditions = [
request.user.is_authenticated(),
request.user.is_active,
request.user.is_staff,
]
if all(redirect_conditions):
return redirect(somewhere_else)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment