Nicolae Claudius
11 years ago
5 changed files with 38 additions and 2 deletions
@ -1,8 +1,12 @@
|
||||
class BlacklistedDomain < ActiveRecord::Base |
||||
# attr_accessible :name |
||||
|
||||
def self.include?(name) |
||||
scope :of, ->(domain_name) { |
||||
where("blacklisted_domains.name = ? OR ? LIKE CONCAT('%.', blacklisted_domains.name)", |
||||
name, name).exists? |
||||
domain_name, domain_name) |
||||
} |
||||
|
||||
def self.include?(domain_name) |
||||
of(domain_name).exists? || Dnsbl.include?(domain_name) |
||||
end |
||||
end |
||||
|
@ -0,0 +1,15 @@
|
||||
class Dnsbl |
||||
PROVIDER = '.in.dnsbl.org' |
||||
@dns = Resolv::DNS.new |
||||
|
||||
def self.include?(domain_name) |
||||
query(domain_name) != nil |
||||
end |
||||
|
||||
def self.query(domain_name) |
||||
@dns.getresource(domain_name + PROVIDER, Resolv::DNS::Resource::IN::A) |
||||
rescue Resolv::ResolvError |
||||
nil |
||||
end |
||||
|
||||
end |
@ -0,0 +1,15 @@
|
||||
require 'spec_helper' |
||||
|
||||
describe Dnsbl do |
||||
include_context "data" |
||||
|
||||
it "queries correctly" do |
||||
Dnsbl.query('does-not-exist-domain-1234567890.net') == nil |
||||
end |
||||
|
||||
it "distinguishes bad domains from good ones" do |
||||
Dnsbl.include?('place4porn.net').should == true |
||||
Dnsbl.include?('entrydns.net').should == false |
||||
end |
||||
|
||||
end |
Loading…
Reference in new issue