Class: HAST::Verifier

Inherits:
Object
  • Object
show all
Defined in:
lib/hast/verifier.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, domains, type, &output_block) ⇒ Verifier

Returns a new instance of Verifier.



12
13
14
15
16
17
18
19
# File 'lib/hast/verifier.rb', line 12

def initialize(config, domains, type, &output_block)
  @config = config
  @domains = domains
  @type = type
  @output_block = output_block
  @dns = Net::DNS::Resolver.new
  @dns.nameservers = [@config['dns']['primary'], @config['dns']['secondary']].compact
end

Class Method Details

.run(config, domains, type, &output_block) ⇒ Object



6
7
8
9
# File 'lib/hast/verifier.rb', line 6

def run(config, domains, type, &output_block)
  instance = self.new(config, domains, type, &output_block)
  instance.verify_domains
end

Instance Method Details

#verify_domainsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/hast/verifier.rb', line 21

def verify_domains
  @domains.each do |domain|
    if @config['dns']['disable']
      ips = nil
    else
      case @type
      when :web
        ips = get_server_ips(domain)
        expected_ip = @config['apache']['ip']
      when :mail
        ips = get_mailserver_ips(domain)
        expected_ip = @config['postfix']['ip']
      end
    end

    if ips.nil?
      @output_block.call domain, max_length, :unknown
    elsif ips.empty?
      @output_block.call domain, max_length, :inactive
    elsif ips.include? expected_ip
      @output_block.call domain, max_length, :active
    else
      @output_block.call domain, max_length, :other, ips
    end
  end
end