Primitive spam filter
This commit is contained in:
parent
9f36bd59a9
commit
7ab0f052f3
|
@ -176,6 +176,9 @@ class WikiController < ApplicationController
|
||||||
cookies['author'] = @params['author']
|
cookies['author'] = @params['author']
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
check_for_spam(@params['content'], remote_ip)
|
||||||
|
check_blocked_ips(remote_ip)
|
||||||
|
|
||||||
if @page
|
if @page
|
||||||
wiki.revise_page(@web_name, @page_name, @params['content'], Time.now,
|
wiki.revise_page(@web_name, @page_name, @params['content'], Time.now,
|
||||||
Author.new(@params['author'], remote_ip))
|
Author.new(@params['author'], remote_ip))
|
||||||
|
@ -228,6 +231,25 @@ class WikiController < ApplicationController
|
||||||
|
|
||||||
private
|
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)
|
def convert_tex_to_pdf(tex_path)
|
||||||
# TODO remove earlier PDF files with the same prefix
|
# TODO remove earlier PDF files with the same prefix
|
||||||
# TODO handle gracefully situation where pdflatex is not available
|
# TODO handle gracefully situation where pdflatex is not available
|
||||||
|
|
|
@ -2,3 +2,14 @@ Dependencies.mechanism = :require
|
||||||
ActionController::Base.consider_all_requests_local = false
|
ActionController::Base.consider_all_requests_local = false
|
||||||
ActionController::Base.perform_caching = 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
|
||||||
|
|
Loading…
Reference in a new issue