def process_response(self, request, response): """Sets "Ok" cookie on unknown users.""" if COOKIE_KEY not in request.COOKIES: # Unknown user, set cookie and go on... response.set_cookie(COOKIE_KEY, COOKIE_PASS, httponly=True, expires=datetime.now()+timedelta(days=30)) # Only logged if we have to set the PASS cookie if DJANGOSPAM_LOG: logger.log("PASS RESPONSE", request.method, request.path_info, request.META.get("HTTP_USER_AGENT", "undefined")) return response
def spammer_view(request): """View for setting cookies on spammers.""" # Permits use of CSRF middleware context = RequestContext(request, {}) template = Template("") response = HttpResponse(template.render(context)) # Sets a cookie with a 10 years lifetime, accessible only via HTTP: response.set_cookie(COOKIE_KEY, value=COOKIE_SPAM, httponly=True, expires=datetime.now()+timedelta(days=3650)) if DJANGOSPAM_LOG: log("BLOCK RESPONSE", request.method, request.path_info, request.META.get("HTTP_USER_AGENT", "undefined")) return response
def process_request(self, request): """Discovers if a request is from a knwon spam bot and denies access.""" if COOKIE_KEY in request.COOKIES and \ request.COOKIES[COOKIE_KEY] == COOKIE_SPAM: # Is a known spammer. response = HttpResponse("") # We do not reveal why it has been forbbiden: response.status_code = 404 if DJANGOSPAM_LOG: logger.log("SPAM REQUEST", request.method, request.path_info, request.META.get("HTTP_USER_AGENT", "undefined")) return response if DJANGOSPAM_LOG: logger.log("PASS REQUEST", request.method, request.path_info, request.META.get("HTTP_USER_AGENT", "undefined")) return None
def spammer_view(request): """View for setting cookies on spammers.""" # Permits use of CSRF middleware context = RequestContext(request, {}) template = Template("") response = HttpResponse(template.render(context)) # Sets a cookie with a 10 years lifetime, accessible only via HTTP: response.set_cookie(COOKIE_KEY, value=COOKIE_SPAM, httponly=True, expires=datetime.now() + timedelta(days=3650)) if DJANGOSPAM_LOG: log("BLOCK RESPONSE", request.method, request.path_info, request.META.get("HTTP_USER_AGENT", "undefined")) return response
def spammer_view(request): """ Sets cookie so that ALL pages do not appear upon access. Also bans the user, for good measure :) """ response = HttpResponse("Thanks! For posting to an invisible field, " + "you are now banned!") # Sets a cookie with a 10 years lifetime, accessible only via HTTP: response.set_cookie(COOKIE_KEY, value=COOKIE_SPAM, httponly=True, expires=datetime.now()+timedelta(days=3650)) if DJANGOSPAM_LOG: log("BLOCK RESPONSE", request.method, request.path_info, request.META.get("HTTP_USER_AGENT", "undefined")) # AC: 8/9 - Ban the user request.user.akismet_hits = 1000 request.user.is_active = False request.user.save() return response
def spammer_view(request): """ Sets cookie so that ALL pages do not appear upon access. Also bans the user, for good measure :) """ response = HttpResponse("Thanks! For posting to an invisible field, " + "you are now banned!") # Sets a cookie with a 10 years lifetime, accessible only via HTTP: response.set_cookie(COOKIE_KEY, value=COOKIE_SPAM, httponly=True, expires=datetime.now() + timedelta(days=3650)) if DJANGOSPAM_LOG: log("BLOCK RESPONSE", request.method, request.path_info, request.META.get("HTTP_USER_AGENT", "undefined")) # AC: 8/9 - Ban the user request.user.akismet_hits = 1000 request.user.is_active = False request.user.save() return response