mirror of
https://github.com/viq/NewsBlur.git
synced 2025-04-13 09:38:09 +00:00
Banning Feed Reader Background app, as it's causing a ton of bogus requests.
This commit is contained in:
parent
34dec1f322
commit
3f786a65c6
4 changed files with 26 additions and 3 deletions
|
@ -3,10 +3,11 @@ import re
|
|||
import random
|
||||
import time
|
||||
from utils import log as logging
|
||||
from django.http import HttpResponse
|
||||
from django.conf import settings
|
||||
from django.db import connection
|
||||
from django.template import Template, Context
|
||||
|
||||
from utils import json_functions as json
|
||||
|
||||
class LastSeenMiddleware(object):
|
||||
def process_response(self, request, response):
|
||||
|
@ -175,3 +176,21 @@ class ServerHostnameMiddleware:
|
|||
class TimingMiddleware:
|
||||
def process_request(self, request):
|
||||
setattr(request, 'start_time', time.time())
|
||||
|
||||
BANNED_USER_AGENTS = (
|
||||
'feed reader-background',
|
||||
'feed reader-windows',
|
||||
)
|
||||
class UserAgentBanMiddleware:
|
||||
def process_request(self, request):
|
||||
user_agent = request.environ.get('HTTP_USER_AGENT', 'missing').lower()
|
||||
if any(ua in user_agent for ua in BANNED_USER_AGENTS):
|
||||
data = {
|
||||
'error': 'User agent banned: %s' % user_agent,
|
||||
'code': -1
|
||||
}
|
||||
logging.user(request, "~FB~SN~BBBanned UA: ~SB%s" % (user_agent))
|
||||
|
||||
return HttpResponse(json.encode(data), status=403, mimetype='text/json')
|
||||
|
||||
|
||||
|
|
|
@ -261,7 +261,10 @@ class Profile(models.Model):
|
|||
transaction = PayPalIPN.objects.filter(custom=self.user.username,
|
||||
txn_type='subscr_payment')[0]
|
||||
refund = paypal.refund_transaction(transaction.txn_id)
|
||||
refunded = int(float(refund['raw']['TOTALREFUNDEDAMOUNT'][0]))
|
||||
try:
|
||||
refunded = int(float(refund['raw']['TOTALREFUNDEDAMOUNT'][0]))
|
||||
except KeyError:
|
||||
refunded = int(transaction.amount)
|
||||
logging.user(self.user, "~FRRefunding paypal payment: $%s" % refunded)
|
||||
self.cancel_premium()
|
||||
|
||||
|
|
|
@ -103,6 +103,7 @@ MIDDLEWARE_CLASSES = (
|
|||
'apps.profile.middleware.TimingMiddleware',
|
||||
'apps.profile.middleware.LastSeenMiddleware',
|
||||
'apps.profile.middleware.SQLLogToConsoleMiddleware',
|
||||
'apps.profile.middleware.UserAgentBanMiddleware',
|
||||
'subdomains.middleware.SubdomainMiddleware',
|
||||
'apps.profile.middleware.SimpsonsMiddleware',
|
||||
'apps.profile.middleware.ServerHostnameMiddleware',
|
||||
|
|
|
@ -4,6 +4,7 @@ from datetime import datetime, timedelta
|
|||
import functools
|
||||
import hashlib
|
||||
|
||||
|
||||
class ratelimit(object):
|
||||
"Instances of this class can be used as decorators"
|
||||
# This class is designed to be sub-classed
|
||||
|
@ -84,7 +85,6 @@ class ratelimit(object):
|
|||
return key
|
||||
|
||||
def disallowed(self, request):
|
||||
"Over-ride this method if you want to log incidents"
|
||||
return HttpResponse('Rate limit exceeded', status=429)
|
||||
|
||||
def expire_after(self):
|
||||
|
|
Loading…
Add table
Reference in a new issue