Class: Antispam::Blacklists::Httpbl
- Inherits:
-
Object
- Object
- Antispam::Blacklists::Httpbl
- Defined in:
- lib/antispam/blacklists/httpbl.rb
Class Method Summary collapse
-
.check(ip, key, verbose) ⇒ Object
Returns a threat-level number, or 0 if no threat / no result.
- .get_old_result(ip) ⇒ Object
- .update_old_result(ip, threat) ⇒ Object
Class Method Details
.check(ip, key, verbose) ⇒ Object
Returns a threat-level number, or 0 if no threat / no result.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/antispam/blacklists/httpbl.rb', line 6 def self.check(ip, key, verbose) threat = 0 begin old_result = get_old_result(ip) if old_result Rails.logger.info "Returning old result for #{ip}." if verbose return get_old_result(ip) end check = ip.split('.').reverse.join('.') host = key + '.' + check + ".dnsbl.httpbl.org" address = Resolv::getaddress(host) z,days,threat,iptype = address.split('.') Rails.logger.info "Spam located: #{iptype} type at #{threat} threat. (#{ip} - #{address})" if verbose threat = threat.to_i # Create or update if (threat > 30) Rails.logger.info "Spamcheck: Very high, over 30!" if verbose end rescue Exception => e case e when Resolv::ResolvError #Not spam! This blacklist gives an error when there's no spam threat. Rails.logger.info "Spamcheck: OK! Resolve error means the httpbl does not consider this spam." if verbose when Interrupt #Something broke while trying to check blacklist. Rails.logger.info "Spamcheck: Interrupt when trying to resolve http blacklist. Possible timeout?" if verbose else # Time Out Rails.logger.info "Spamcheck: There was an error, possibly a time out, when checking this IP." if verbose Rails.logger.info e.to_s if verbose end end update_old_result(ip, threat) return threat end |