mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Merge branch 'master' into offline
* master: Scheduling stale feeds for flat feed users, too. Normalizing user agents for better detectibility. Blocking dumb client apps without user agents. Adding user agent logging for api logins.
This commit is contained in:
commit
47b32be408
5 changed files with 45 additions and 24 deletions
|
@ -23,14 +23,18 @@ from utils.feed_functions import relative_timesince
|
|||
def login(request):
|
||||
code = -1
|
||||
errors = None
|
||||
|
||||
if request.method == "POST":
|
||||
user_agent = request.environ.get('HTTP_USER_AGENT', '')
|
||||
|
||||
if not user_agent:
|
||||
errors = dict(user_agent="You must set a user agent to login.")
|
||||
logging.user(request, "~FG~BB~SK~FRBlocked ~FGAPI Login~SN~FW: %s" % user_agent)
|
||||
elif request.method == "POST":
|
||||
form = LoginForm(data=request.POST)
|
||||
if form.errors:
|
||||
errors = form.errors
|
||||
if form.is_valid():
|
||||
login_user(request, form.get_user())
|
||||
logging.user(request, "~FG~BB~SKAPI Login~FW")
|
||||
logging.user(request, "~FG~BB~SKAPI Login~SN~FW: %s" % user_agent)
|
||||
code = 1
|
||||
else:
|
||||
errors = dict(method="Invalid method. Use POST. You used %s" % request.method)
|
||||
|
|
|
@ -19,6 +19,10 @@ class LastSeenMiddleware(object):
|
|||
if request.user.profile.last_seen_on < hour_ago:
|
||||
logging.user(request, "~FG~BBRepeat visitor: ~SB%s (%s)" % (
|
||||
request.user.profile.last_seen_on, ip))
|
||||
elif settings.DEBUG:
|
||||
logging.user(request, "~FG~BBRepeat visitor (ignored): ~SB%s (%s)" % (
|
||||
request.user.profile.last_seen_on, ip))
|
||||
|
||||
# if request.user.profile.last_seen_on < SUBSCRIBER_EXPIRE:
|
||||
# request.user.profile.refresh_stale_feeds()
|
||||
request.user.profile.last_seen_on = datetime.datetime.utcnow()
|
||||
|
|
|
@ -129,7 +129,7 @@ class UserSubscription(models.Model):
|
|||
else:
|
||||
max_score = 0
|
||||
|
||||
if settings.DEBUG:
|
||||
if settings.DEBUG and False:
|
||||
debug_stories = r.zrevrange(unread_ranked_stories_key, 0, -1, withscores=True)
|
||||
print " ---> Unread all stories (%s - %s) %s stories: %s" % (
|
||||
min_score,
|
||||
|
|
|
@ -313,12 +313,25 @@ def load_feeds_flat(request):
|
|||
folders = []
|
||||
|
||||
user_subs = UserSubscription.objects.select_related('feed').filter(user=user, active=True)
|
||||
day_ago = datetime.datetime.now() - datetime.timedelta(days=1)
|
||||
scheduled_feeds = []
|
||||
|
||||
for sub in user_subs:
|
||||
if update_counts and sub.needs_unread_recalc:
|
||||
sub.calculate_feed_scores(silent=True)
|
||||
feeds[sub.feed_id] = sub.canonical(include_favicon=include_favicons)
|
||||
if not sub.feed.active and not sub.feed.has_feed_exception:
|
||||
scheduled_feeds.append(sub.feed.pk)
|
||||
elif sub.feed.active_subscribers <= 0:
|
||||
scheduled_feeds.append(sub.feed.pk)
|
||||
elif sub.feed.next_scheduled_update < day_ago:
|
||||
scheduled_feeds.append(sub.feed.pk)
|
||||
|
||||
if len(scheduled_feeds) > 0 and request.user.is_authenticated():
|
||||
logging.user(request, "~SN~FMTasking the scheduling immediate fetch of ~SB%s~SN feeds..." %
|
||||
len(scheduled_feeds))
|
||||
ScheduleImmediateFetches.apply_async(kwargs=dict(feed_ids=scheduled_feeds))
|
||||
|
||||
if folders:
|
||||
folders = json.decode(folders.folders)
|
||||
|
||||
|
|
|
@ -72,45 +72,45 @@ def generate_secret_token(phrase, size=12):
|
|||
return hashlib.sha1("".join(info)).hexdigest()[:size]
|
||||
|
||||
def extract_user_agent(request):
|
||||
user_agent = request.environ.get('HTTP_USER_AGENT', '')
|
||||
user_agent = request.environ.get('HTTP_USER_AGENT', '').lower()
|
||||
platform = '------'
|
||||
if 'iPad App' in user_agent:
|
||||
if 'ipad app' in user_agent:
|
||||
platform = 'iPad'
|
||||
elif 'iPhone App' in user_agent:
|
||||
elif 'iphone app' in user_agent:
|
||||
platform = 'iPhone'
|
||||
elif 'Blar' in user_agent:
|
||||
elif 'blar' in user_agent:
|
||||
platform = 'Blar'
|
||||
elif 'Android' in user_agent:
|
||||
elif 'android' in user_agent:
|
||||
platform = 'Androd'
|
||||
elif 'Metroblur' in user_agent:
|
||||
elif 'metroblur' in user_agent:
|
||||
platform = 'Metrob'
|
||||
elif 'Pluggio' in user_agent:
|
||||
elif 'pluggio' in user_agent:
|
||||
platform = 'Plugio'
|
||||
elif 'MSIE' in user_agent:
|
||||
elif 'msie' in user_agent:
|
||||
platform = 'IE'
|
||||
if 'MSIE 9' in user_agent:
|
||||
if 'msie 9' in user_agent:
|
||||
platform += '9'
|
||||
elif 'MSIE 10' in user_agent:
|
||||
elif 'msie 10' in user_agent:
|
||||
platform += '10'
|
||||
elif 'MSIE 8' in user_agent:
|
||||
elif 'msie 8' in user_agent:
|
||||
platform += '8'
|
||||
elif 'Chrome' in user_agent:
|
||||
elif 'chrome' in user_agent:
|
||||
platform = 'Chrome'
|
||||
elif 'Safari' in user_agent:
|
||||
elif 'safari' in user_agent:
|
||||
platform = 'Safari'
|
||||
elif 'MeeGo' in user_agent:
|
||||
elif 'meego' in user_agent:
|
||||
platform = 'MeeGo'
|
||||
elif 'Firefox' in user_agent:
|
||||
elif 'firefox' in user_agent:
|
||||
platform = 'FF'
|
||||
elif 'Opera' in user_agent:
|
||||
elif 'opera' in user_agent:
|
||||
platform = 'Opera'
|
||||
elif 'WP7' in user_agent:
|
||||
elif 'wp7' in user_agent:
|
||||
platform = 'WP7'
|
||||
elif 'WP8' in user_agent:
|
||||
elif 'wp8' in user_agent:
|
||||
platform = 'WP8'
|
||||
elif 'Tafiti' in user_agent:
|
||||
elif 'tafiti' in user_agent:
|
||||
platform = 'Tafiti'
|
||||
elif 'ReadKit' in user_agent:
|
||||
elif 'readkit' in user_agent:
|
||||
platform = 'ReadKt'
|
||||
|
||||
return platform
|
||||
|
|
Loading…
Add table
Reference in a new issue