Class: Blend::Status::Domain

Inherits:
Object
  • Object
show all
Defined in:
lib/blend/status/domain.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, environment, domain) ⇒ Domain

Returns a new instance of Domain.



10
11
12
13
14
15
# File 'lib/blend/status/domain.rb', line 10

def initialize( project, environment, domain )
  @project = project
  @environment = environment
  @domain = domain
  @res = Dnsruby::Resolver.new
end

Instance Attribute Details

#domainObject

Returns the value of attribute domain.



8
9
10
# File 'lib/blend/status/domain.rb', line 8

def domain
  @domain
end

#environmentObject

Returns the value of attribute environment.



8
9
10
# File 'lib/blend/status/domain.rb', line 8

def environment
  @environment
end

#projectObject

Returns the value of attribute project.



8
9
10
# File 'lib/blend/status/domain.rb', line 8

def project
  @project
end

#resObject

Returns the value of attribute res.



8
9
10
# File 'lib/blend/status/domain.rb', line 8

def res
  @res
end

Class Method Details

.check(domain) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/blend/status/domain.rb', line 19

def check(domain)
  dc = self.new(domain)

  result = {}
  begin

    result[:registered] = dc.registered?
    result[:registrar] = dc.registrar
    result[:ssl] = dc.ssl
    result[:expires] = dc.expires
    result[:owner] = dc.owner
    result[:name_servers] = dc.name_servers
    result[:dns] = {
      ns: dc.ns,
      mx: dc.mx,
      cname: dc.cname,
      a: dc.a
    }

  rescue Dnsruby::ServFail => e
    result[:error] = "DomainChecker encountered #{e.to_s}: You might just need to retry this."
  end

  result
end

Instance Method Details

#aObject



128
129
130
# File 'lib/blend/status/domain.rb', line 128

def a
  lookup "A"
end

#check(key, method) ⇒ Object



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/blend/status/domain.rb', line 200

def check key, method
  ret = __send__( method )
  ret = false if ret.nil?
  ret = false if ret == []
  ret = ret.collect { |x| x[:name] || x['name'] }.join( "," ) if ret.is_a? Array

  pass = ret

  if( ret.is_a? Integer )
    if( method == :dyno_redundancy)
      pass = ret > 1
      ret = "#{ret} dynos"
    end
  end

  printf "%20s: ", key
  if( pass )
    printf "\u2713 #{ret}\n".encode('utf-8').green
  else
    printf "\u2718 #{ret}\n".encode('utf-8').red
  end
end

#cnameObject



136
137
138
# File 'lib/blend/status/domain.rb', line 136

def cname
  lookup "CNAME"
end

#expiresObject



61
62
63
# File 'lib/blend/status/domain.rb', line 61

def expires
  whois.expires_on
end

#get_data(array) ⇒ Object



164
165
166
# File 'lib/blend/status/domain.rb', line 164

def get_data array
  array[:domains].collect{ |x| x[:data] }
end

#heroku?Boolean

def records v

if v[:domains]
  v[:domains].collect { |x| x[:data] }
else
  []
end

end

Returns:

  • (Boolean)


188
189
190
191
192
193
194
195
196
197
198
# File 'lib/blend/status/domain.rb', line 188

def heroku?
  a_ips = a[:domains].select { |x| x[:domain] == @domain }.collect { |x| x[:data].to_s }.sort
  # puts a_ips
  return true if a_ips == ["174.129.212.2", "75.101.145.87", "75.101.163.44"] 
  

  # puts cname[:domains].to_s 
  # return false if cname[:domains].first[:data].to_s != "proxy.heroku.com"
  
  return true
end

#inbound_mailersObject



65
66
67
# File 'lib/blend/status/domain.rb', line 65

def inbound_mailers
  get_data(mx).sort { |a,b| a[0] <=> b[0]}
end

#lookup(type) ⇒ Object

Details



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/blend/status/domain.rb', line 103

def lookup( type )
  @results ||= {}
  if @results[type].nil?
    @results[type] = parse_answer( type )
    if type == "A" || type == "CNAME"
      @results[type] = parse_answer type, @results[type][:domains]
    end
  end

  # @results[type]
  #   @results = { domain: @domain }
  #   @results[:ns] = parse_answer( "NS" )
  #   @results[:a] = parse_answer( "A" )
  #   @results[:a] = parse_answer( "A", @results[:a][:domains] )
  #   @results[:cname] = parse_answer( "CNAME" )
  #   @results[:cname] = parse_answer( "CNAME", @results[:cname][:domains] )
  #   @results[:mx] = parse_answer( "MX" )
  # end
  @results[type]
end

#mxObject



132
133
134
# File 'lib/blend/status/domain.rb', line 132

def mx
  lookup "MX"
end

#name_serversObject



69
70
71
# File 'lib/blend/status/domain.rb', line 69

def name_servers
  get_data(ns)
end

#nsObject



124
125
126
# File 'lib/blend/status/domain.rb', line 124

def ns
  lookup "NS"
end

#ownerObject



57
58
59
# File 'lib/blend/status/domain.rb', line 57

def owner
  whois.registrant_contacts
end

#parse_answer(type, domains = false) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/blend/status/domain.rb', line 144

def parse_answer( type, domains = false )
  domain = @domain
  domain = "www.#{@domain}" if domains
  ret = {domains: []}
  ret = {domains: domains} if domains
  begin
    rr = @res.query( domain, type)
    # puts rr.answer
    rr.answer.each do |answer|
      ret[:domains] << { domain: domain, name:answer.name.to_s, ttl: answer.ttl, data: answer.rdata, type: answer.type } if answer.type == type
    end
  rescue Dnsruby::ResolvTimeout
    ret[:error] = :timeout
  rescue Dnsruby::NXDomain
    ret[:error] = :notfound
  end
  
  ret
end

#registered?Boolean

Find out meta data

Returns:

  • (Boolean)


49
50
51
# File 'lib/blend/status/domain.rb', line 49

def registered?
  whois.registered?
end

#registrarObject



53
54
55
# File 'lib/blend/status/domain.rb', line 53

def registrar
  whois.registrar
end

#sslObject



73
74
75
76
77
78
79
80
81
82
# File 'lib/blend/status/domain.rb', line 73

def ssl
  if @ssl.nil?
    c = HTTPClient.new
    c.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
    p = c.get( "https://#{domain}")
    @ssl = p.peer_cert
  end
  return nil if( ssl_common_name.nil? )
  @ssl
end

#ssl_common_nameObject



93
94
95
96
97
98
99
# File 'lib/blend/status/domain.rb', line 93

def ssl_common_name
  ssl if @ssl.nil?
  return nil if @ssl.nil?
  ret = (@ssl.subject.to_a.select { |x| x[0] == 'CN' }.first || [])[1]
  return nil if ( ret =~ /herokuapp/ )
  ret
end

#ssl_exists?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/blend/status/domain.rb', line 84

def ssl_exists?
  !ssl.nil?
end

#ssl_valid_untilObject



88
89
90
91
# File 'lib/blend/status/domain.rb', line 88

def ssl_valid_until
  return nil if ssl.nil?
  ssl.not_after
end

#whoisObject



140
141
142
# File 'lib/blend/status/domain.rb', line 140

def whois
  @whois ||= Whois.lookup @domain
end