Primitive spam filter

This commit is contained in:
Rick Okin 2005-08-09 01:58:16 +00:00
parent 9f36bd59a9
commit 7ab0f052f3
2 changed files with 34 additions and 1 deletions

View file

@ -176,6 +176,9 @@ class WikiController < ApplicationController
cookies['author'] = @params['author']
begin
check_for_spam(@params['content'], remote_ip)
check_blocked_ips(remote_ip)
if @page
wiki.revise_page(@web_name, @page_name, @params['content'], Time.now,
Author.new(@params['author'], remote_ip))
@ -227,7 +230,26 @@ class WikiController < ApplicationController
private
def check_blocked_ips(ip)
if defined? BLOCKED_IPS and not BLOCKED_IPS.nil?
BLOCKED_IPS.each do |blocked_ip|
raise Instiki::ValidationError.new('Revision rejected by spam filter') if ip == blocked_ip
end
end
end
def check_for_spam(new_content, ip)
if defined? SPAM_PATTERNS and not SPAM_PATTERNS.nil?
SPAM_PATTERNS.each do |pattern|
if new_content =~ pattern
logger.info "Spam attempt from IP address #{ip}"
raise Instiki::ValidationError.new('Revision rejected by spam filter')
end
end
end
end
def convert_tex_to_pdf(tex_path)
# TODO remove earlier PDF files with the same prefix
# TODO handle gracefully situation where pdflatex is not available

View file

@ -2,3 +2,14 @@ Dependencies.mechanism = :require
ActionController::Base.consider_all_requests_local = false
ActionController::Base.perform_caching = false
spam_patterns_filename = RAILS_ROOT + '/config/spam_patterns.txt'
if File.exists? spam_patterns_filename
SPAM_PATTERNS = File.readlines(spam_patterns_filename).select { |line| line != '' }.map {
|line| Regexp.new(line) }
end
blocked_ips_filename = RAILS_ROOT + '/config/blocked_ips.txt'
if File.exists? blocked_ips_filename
BLOCKED_IPS = File.readlines(blocked_ips_filename).select { |line| line != '' }
end