Permalink
Browse files

tools for dealing with spammers

  • Loading branch information...
1 parent 2c0281a commit 00611156ac2ede435eedf1f359716baa8cae543c Justine Tunney committed Nov 18, 2011
Showing with 79 additions and 9 deletions.
  1. +9 −9 occupywallst/api.py
  2. +6 −0 occupywallst/settings.py
  3. +27 −0 recalculate.sh
  4. +37 −0 reports.sh
View
@@ -508,20 +508,20 @@ def comment_vote(user, comment, vote, **kwargs):
allow an IP to vote once. We track these votes in a
non-persistant cache because we don't want to log IP addresses.
"""
+ if not (user and user.id):
+ raise APIException(_("not logged in"))
if not isinstance(comment, db.Comment):
try:
comment = db.Comment.objects.get(id=comment, is_deleted=False)
except db.Comment.DoesNotExist:
raise APIException(_("comment not found"))
- if not (user and user.id):
- raise APIException(_("not logged in"))
- # ip = _try_to_get_ip(kwargs)
- # if ip:
- # key = "vote_comment_%s__%s" % (comment.id, ip)
- # if cache.get(key, False):
- # raise APIException(_("you already voted"))
- # else:
- # cache.set(key, True)
+ if not settings.DEBUG and not user.is_staff:
+ for tdelta, maxvotes in settings.OWS_LIMIT_VOTES:
+ votes = (db.CommentVote.objects
+ .filter(user=user, time__gt=datetime.now() - tdelta)
+ .count())
+ if votes > maxvotes:
+ raise APIException(_("you're voting too much"))
if vote == "up":
comment.upvote(user)
elif vote == "down":
@@ -9,6 +9,7 @@
import os
import sys
+from datetime import timedelta
from os.path import abspath, dirname, join, exists
project_root = dirname(abspath(__file__))
@@ -34,6 +35,11 @@
OWS_LIMIT_THREAD = 60 * 30 # thirty minutes
OWS_LIMIT_COMMENT = 60 * 3 # three minutes
OWS_LIMIT_SIGNUP = 60 * 60 * 30 # three hours
+OWS_LIMIT_VOTES = (
+ (timedelta(hours=1), 100), # max 100 votes in an hour
+ (timedelta(days=1), 500), # max 500 votes in a day
+)
+
OWS_MAX_COMMENT_DEPTH = 15
OWS_MAX_PRIVMSG_USER_DAY = 7
OWS_NOTIFY_PUB_ADDR = ('127.0.0.1', 9010)
View
@@ -0,0 +1,27 @@
+#!/bin/bash
+#
+# i recalculate counter fields in database to ensure their
+# correctness. sometimes stuff like comment karma can get out of sync
+# if users are purged from the database or a software bug occurs.
+# this script should be run periodically to fix that.
+#
+# to use me run "crontab -e" and add:
+#
+# @hourly nice recalculate.sh ows
+#
+
+DB=$1
+[[ $DB ]] || exit 1
+
+cat <<EOF | psql -q $DB
+update occupywallst_comment as C
+ set ups = coalesce((select count(*)
+ from occupywallst_commentvote
+ where comment_id = C.id and vote = 1), 0),
+ downs = coalesce((select count(*)
+ from occupywallst_commentvote
+ where comment_id = C.id and vote = -1), 0),
+ karma = coalesce((select sum(vote)
+ from occupywallst_commentvote
+ where comment_id = C.id), 0);
+EOF
View
@@ -0,0 +1,37 @@
+#!/bin/bash
+#
+# i generate text file reports to help you track down abuse. it's a
+# good idea to have them generated to a secret folder on your
+# webserver.
+#
+# to use me run "crontab -e" and add:
+#
+# @hourly nice reports.sh ows /var/www/reports
+#
+
+DB=$1
+DEST=$2
+THRESHOLD=$3
+
+[[ $DB ]] || exit 1
+[[ -d $DEST ]] || exit 1
+[[ $THRESHOLD ]] || THRESHOLD=20
+
+for HOURS in 1 4 12 24 48; do
+cat <<EOF | psql $DB >$DEST/voting-${HOURS}hours.txt
+select (select username from auth_user where id = uid) as name,
+ vote_count,
+ (select count(*)
+ from occupywallst_article
+ where author_id = uid) as article_count_all_time,
+ (select count(*)
+ from occupywallst_comment
+ where user_id = uid) as comment_count_all_time
+ from (select user_id as uid, count(*) as vote_count
+ from occupywallst_commentvote
+ where time > now() - interval '$HOURS hour'
+ group by uid
+ order by vote_count desc) as A
+ where vote_count > $THRESHOLD;
+EOF
+done

0 comments on commit 0061115

Please sign in to comment.