Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

tools for dealing with spammers

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

0 comments on commit 0061115

Please sign in to comment.
Something went wrong with that request. Please try again.