Module: Legitbot::Validators::Domains::ClassMethods
Overview
Instance Method Summary
collapse
#resolver, #resolver_config
Instance Method Details
#check_domains? ⇒ Boolean
33
34
35
|
# File 'lib/legitbot/validators/domains.rb', line 33
def check_domains?
instance_variable_defined?(:@valid_domains)
end
|
#domains(*list, reverse: true) ⇒ Object
28
29
30
31
|
# File 'lib/legitbot/validators/domains.rb', line 28
def domains(*list, reverse: true)
@valid_domains = list.flatten.map { |d| Resolv::DNS::Name.create(d) }
@validate_reverse_record = reverse
end
|
#find_subdomain_record(domains) ⇒ Object
57
58
59
60
61
|
# File 'lib/legitbot/validators/domains.rb', line 57
def find_subdomain_record(domains)
domains.find do |d|
@valid_domains.any? { |vd| d.subdomain_of?(vd) }
end
end
|
#reverse_domains(ip) ⇒ Object
51
52
53
54
55
|
# File 'lib/legitbot/validators/domains.rb', line 51
def reverse_domains(ip)
resolver.getnames(ip)
rescue Resolv::ResolvError
nil
end
|
#reverse_ip(record) ⇒ Object
63
64
65
66
67
68
69
|
# File 'lib/legitbot/validators/domains.rb', line 63
def reverse_ip(record)
return nil if record.nil?
resolver.getaddress(record.to_s).to_s
rescue Resolv::ResolvError
nil
end
|
#valid_domain?(ip) ⇒ Boolean
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/legitbot/validators/domains.rb', line 37
def valid_domain?(ip)
return true unless check_domains?
return true if @valid_domains.empty?
domains = reverse_domains(ip)
return false if domains.empty?
record = find_subdomain_record(domains)
return false unless record
return true unless @validate_reverse_record
ip == reverse_ip(record)
end
|