From 70aa50ad4b2285a46b5dcf61309acdff35b61cf2 Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Sun, 28 Feb 2010 19:23:37 -0600 Subject: [PATCH] Make dnsbl_check respond more intelligently Thanks to Toby Bartels for pointing out the deficiencies of the previous version. --- vendor/plugins/dnsbl_check/lib/dnsbl_check.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/vendor/plugins/dnsbl_check/lib/dnsbl_check.rb b/vendor/plugins/dnsbl_check/lib/dnsbl_check.rb index c795a0c4..a3bd44d1 100644 --- a/vendor/plugins/dnsbl_check/lib/dnsbl_check.rb +++ b/vendor/plugins/dnsbl_check/lib/dnsbl_check.rb @@ -18,11 +18,14 @@ # # Version 1.3 # http://www.spacebabies.nl/dnsbl_check +# +# Modified by Jacques Distler, to give a more informative (and valid) response (2/28/2010). require 'resolv' module DNSBL_Check $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 # 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 passed = true + ban_help = '' threads = [] request.remote_addr =~ /(\d+).(\d+).(\d+).(\d+)/ # 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| logger.warn("Checking DNSBL #{host}") addr = Resolv.getaddress("#{host}") rescue '' if addr[0,7]=="127.0.0" logger.info("#{request.remote_addr} found using DNSBL #{host}") + ban_help << " See here for more information." passed = false end end @@ -53,7 +58,8 @@ module DNSBL_Check $dnsbl_passed.push request.remote_addr logger.warn("#{request.remote_addr} added to DNSBL passed cache") 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 end end