Make dnsbl_check respond more intelligently
Thanks to Toby Bartels for pointing out the deficiencies of the previous version.
This commit is contained in:
parent
dcfe870a02
commit
70aa50ad4b
12
vendor/plugins/dnsbl_check/lib/dnsbl_check.rb
vendored
12
vendor/plugins/dnsbl_check/lib/dnsbl_check.rb
vendored
|
@ -18,11 +18,14 @@
|
||||||
#
|
#
|
||||||
# Version 1.3
|
# Version 1.3
|
||||||
# http://www.spacebabies.nl/dnsbl_check
|
# http://www.spacebabies.nl/dnsbl_check
|
||||||
|
#
|
||||||
|
# Modified by Jacques Distler, to give a more informative (and valid) response (2/28/2010).
|
||||||
require 'resolv'
|
require 'resolv'
|
||||||
|
|
||||||
module DNSBL_Check
|
module DNSBL_Check
|
||||||
$dnsbl_passed ||= []
|
$dnsbl_passed ||= []
|
||||||
DNSBLS = %w{bl.spamcop.net sbl-xbl.spamhaus.org}
|
DNSBLS = {'bl.spamcop.net' => 'http://www.spamcop.net/w3m?action=checkblock&ip=',
|
||||||
|
'sbl-xbl.spamhaus.org' => 'http://www.spamhaus.org/query/bl?ip='}
|
||||||
|
|
||||||
private
|
private
|
||||||
# Filter to check if the client is listed. This will be run before all requests.
|
# Filter to check if the client is listed. This will be run before all requests.
|
||||||
|
@ -31,16 +34,18 @@ module DNSBL_Check
|
||||||
return true if $dnsbl_passed.include? request.remote_addr
|
return true if $dnsbl_passed.include? request.remote_addr
|
||||||
|
|
||||||
passed = true
|
passed = true
|
||||||
|
ban_help = ''
|
||||||
threads = []
|
threads = []
|
||||||
request.remote_addr =~ /(\d+).(\d+).(\d+).(\d+)/
|
request.remote_addr =~ /(\d+).(\d+).(\d+).(\d+)/
|
||||||
|
|
||||||
# Check the remote address against each dnsbl in a separate thread
|
# Check the remote address against each dnsbl in a separate thread
|
||||||
DNSBLS.each do |dnsbl|
|
DNSBLS.each_key do |dnsbl|
|
||||||
threads << Thread.new("#$4.#$3.#$2.#$1.#{dnsbl}") do |host|
|
threads << Thread.new("#$4.#$3.#$2.#$1.#{dnsbl}") do |host|
|
||||||
logger.warn("Checking DNSBL #{host}")
|
logger.warn("Checking DNSBL #{host}")
|
||||||
addr = Resolv.getaddress("#{host}") rescue ''
|
addr = Resolv.getaddress("#{host}") rescue ''
|
||||||
if addr[0,7]=="127.0.0"
|
if addr[0,7]=="127.0.0"
|
||||||
logger.info("#{request.remote_addr} found using DNSBL #{host}")
|
logger.info("#{request.remote_addr} found using DNSBL #{host}")
|
||||||
|
ban_help << " See <a href='#{DNSBLS[host]}#{request.remote_addr}'>here</a> for more information."
|
||||||
passed = false
|
passed = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -53,7 +58,8 @@ module DNSBL_Check
|
||||||
$dnsbl_passed.push request.remote_addr
|
$dnsbl_passed.push request.remote_addr
|
||||||
logger.warn("#{request.remote_addr} added to DNSBL passed cache")
|
logger.warn("#{request.remote_addr} added to DNSBL passed cache")
|
||||||
else
|
else
|
||||||
render :text => 'Access denied', :status => 403
|
render( :text => "Access denied. Your IP address, #{request.remote_addr}, was found on one or more DNSBL" +
|
||||||
|
" blocking list(s).#{ban_help}", :status => 403, :layout => 'error')
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue