anti-spam
This commit is contained in:
parent
18b879be14
commit
03b411e433
2 changed files with 25 additions and 1 deletions
|
@ -25,6 +25,8 @@ queue = Queue()
|
||||||
proc = None
|
proc = None
|
||||||
env = None
|
env = None
|
||||||
|
|
||||||
|
# store client IP in memory until classification
|
||||||
|
client_ips = {}
|
||||||
|
|
||||||
class Processor(Thread):
|
class Processor(Thread):
|
||||||
|
|
||||||
|
@ -68,6 +70,7 @@ def new_comment(data):
|
||||||
author_site = data.get('site', '').strip()
|
author_site = data.get('site', '').strip()
|
||||||
message = data.get('message', '')
|
message = data.get('message', '')
|
||||||
subscribe = data.get('subscribe', '')
|
subscribe = data.get('subscribe', '')
|
||||||
|
clientip = data.get('clientip', '')
|
||||||
|
|
||||||
# private mode: email contains gravar md5 hash
|
# private mode: email contains gravar md5 hash
|
||||||
if config.security['private']:
|
if config.security['private']:
|
||||||
|
@ -108,6 +111,9 @@ def new_comment(data):
|
||||||
email_body = get_template('new_comment').render(
|
email_body = get_template('new_comment').render(
|
||||||
url=article_url, comment=comment_text)
|
url=article_url, comment=comment_text)
|
||||||
|
|
||||||
|
if clientip:
|
||||||
|
client_ips[comment.ip] = clientip
|
||||||
|
|
||||||
# send email
|
# send email
|
||||||
subject = '%s: [%d:%s]' % (site.name, comment.id, token)
|
subject = '%s: [%d:%s]' % (site.name, comment.id, token)
|
||||||
mail(site.admin_email, subject, email_body)
|
mail(site.admin_email, subject, email_body)
|
||||||
|
@ -156,7 +162,19 @@ def reply_comment_email(data):
|
||||||
send_delete_command(data)
|
send_delete_command(data)
|
||||||
|
|
||||||
# safe logic: no answer or unknown answer is a go for publishing
|
# safe logic: no answer or unknown answer is a go for publishing
|
||||||
if message[:2].upper() == 'NO':
|
if message[:2].upper() in ('NO','SP'):
|
||||||
|
|
||||||
|
# put a log to help fail2ban
|
||||||
|
if message[:2].upper() == 'SP': # SPAM
|
||||||
|
if comment_id in client_ips:
|
||||||
|
logger.info('SPAM comment from %s: %d' % (client_ips[comment_id], comment_id))
|
||||||
|
else:
|
||||||
|
logger.info('cannot identify SPAM source: %d' % comment_id)
|
||||||
|
|
||||||
|
# forget client IP
|
||||||
|
if comment_id in client_ips:
|
||||||
|
del client_ips[comment_id]
|
||||||
|
|
||||||
# report event
|
# report event
|
||||||
report_rejected(comment)
|
report_rejected(comment)
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,13 @@ def new_form_comment():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = request.form
|
data = request.form
|
||||||
|
|
||||||
|
# add client IP if provided by HTTP proxy
|
||||||
logger.info('headers: {}'.format(request.headers))
|
logger.info('headers: {}'.format(request.headers))
|
||||||
|
if 'X-Forwarded-For' in request.headers:
|
||||||
|
data['clientip'] = request.headers['X-Forwarded-For']
|
||||||
|
|
||||||
|
# log
|
||||||
logger.info(data)
|
logger.info(data)
|
||||||
|
|
||||||
# validate token: retrieve site entity
|
# validate token: retrieve site entity
|
||||||
|
|
Loading…
Add table
Reference in a new issue