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 random
|
||||||
import time
|
import time
|
||||||
from utils import log as logging
|
from utils import log as logging
|
||||||
|
from django.http import HttpResponse
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
from django.template import Template, Context
|
from django.template import Template, Context
|
||||||
|
from utils import json_functions as json
|
||||||
|
|
||||||
class LastSeenMiddleware(object):
|
class LastSeenMiddleware(object):
|
||||||
def process_response(self, request, response):
|
def process_response(self, request, response):
|
||||||
|
@ -175,3 +176,21 @@ class ServerHostnameMiddleware:
|
||||||
class TimingMiddleware:
|
class TimingMiddleware:
|
||||||
def process_request(self, request):
|
def process_request(self, request):
|
||||||
setattr(request, 'start_time', time.time())
|
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,
|
transaction = PayPalIPN.objects.filter(custom=self.user.username,
|
||||||
txn_type='subscr_payment')[0]
|
txn_type='subscr_payment')[0]
|
||||||
refund = paypal.refund_transaction(transaction.txn_id)
|
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)
|
logging.user(self.user, "~FRRefunding paypal payment: $%s" % refunded)
|
||||||
self.cancel_premium()
|
self.cancel_premium()
|
||||||
|
|
||||||
|
|
|
@ -103,6 +103,7 @@ MIDDLEWARE_CLASSES = (
|
||||||
'apps.profile.middleware.TimingMiddleware',
|
'apps.profile.middleware.TimingMiddleware',
|
||||||
'apps.profile.middleware.LastSeenMiddleware',
|
'apps.profile.middleware.LastSeenMiddleware',
|
||||||
'apps.profile.middleware.SQLLogToConsoleMiddleware',
|
'apps.profile.middleware.SQLLogToConsoleMiddleware',
|
||||||
|
'apps.profile.middleware.UserAgentBanMiddleware',
|
||||||
'subdomains.middleware.SubdomainMiddleware',
|
'subdomains.middleware.SubdomainMiddleware',
|
||||||
'apps.profile.middleware.SimpsonsMiddleware',
|
'apps.profile.middleware.SimpsonsMiddleware',
|
||||||
'apps.profile.middleware.ServerHostnameMiddleware',
|
'apps.profile.middleware.ServerHostnameMiddleware',
|
||||||
|
|
|
@ -4,6 +4,7 @@ from datetime import datetime, timedelta
|
||||||
import functools
|
import functools
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
|
|
||||||
class ratelimit(object):
|
class ratelimit(object):
|
||||||
"Instances of this class can be used as decorators"
|
"Instances of this class can be used as decorators"
|
||||||
# This class is designed to be sub-classed
|
# This class is designed to be sub-classed
|
||||||
|
@ -84,7 +85,6 @@ class ratelimit(object):
|
||||||
return key
|
return key
|
||||||
|
|
||||||
def disallowed(self, request):
|
def disallowed(self, request):
|
||||||
"Over-ride this method if you want to log incidents"
|
|
||||||
return HttpResponse('Rate limit exceeded', status=429)
|
return HttpResponse('Rate limit exceeded', status=429)
|
||||||
|
|
||||||
def expire_after(self):
|
def expire_after(self):
|
||||||
|
|
Loading…
Add table
Reference in a new issue