Skip to content

Instantly share code, notes, and snippets.

@gormih
Last active November 22, 2019 06:45
Show Gist options
  • Save gormih/47dd5b7876c7d1e0fd45cefaf1c042fc to your computer and use it in GitHub Desktop.
Save gormih/47dd5b7876c7d1e0fd45cefaf1c042fc to your computer and use it in GitHub Desktop.
from django.conf import settings
import datetime
class LogIPCookies(object):
def __init__(self):
print(u'http ip log cookies init')
@staticmethod
def process_request(request):
ip = request.META['REMOTE_ADDR']
if ip in getattr(settings, 'LOG_COOKIES_FOR_IPS'):
with open("cookies_log.txt", "a+") as text_file:
text_file.write('\n ip: %s \n time: %s \n path: %s \n Cookies: \n' % (ip, str(datetime.datetime.now()), str(request.get_full_path())))
for (header, value) in request.COOKIES.items():
text_file.write(' %s : %s \n' % (header, value))
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment