Class: Rubber::Dns::Dyndns
- Inherits:
-
Base
- Object
- Base
- Rubber::Dns::Dyndns
show all
- Defined in:
- lib/rubber/dns/dyndns.rb
Instance Attribute Summary
Attributes inherited from Base
#env, #provider_env, #provider_name
Instance Method Summary
collapse
Methods inherited from Base
#destroy, #host_records_equal?, #setup_opts, #update
Constructor Details
#initialize(env) ⇒ Dyndns
Returns a new instance of Dyndns.
6
7
8
9
10
11
|
# File 'lib/rubber/dns/dyndns.rb', line 6
def initialize(env)
super(env, 'dyndns')
@user, @pass = provider_env.user, provider_env.password
@update_url = provider_env.update_url || 'https://members.dyndns.org/nic/update?hostname=%host%&myip=%ip%'
@update_url = @update_url.gsub(/%([^%]+)%/, '#{\1}')
end
|
Instance Method Details
#create_host_record(opts = {}) ⇒ Object
40
41
42
|
# File 'lib/rubber/dns/dyndns.rb', line 40
def create_host_record(opts={})
puts "WARNING: No create record available for dyndns, you need to do so manually"
end
|
#destroy_host_record(opts = {}) ⇒ Object
44
45
46
|
# File 'lib/rubber/dns/dyndns.rb', line 44
def destroy_host_record(opts={})
puts "WARNING: No destroy record available for dyndns, you need to do so manually"
end
|
#find_host_records(opts = {}) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/rubber/dns/dyndns.rb', line 26
def find_host_records(opts={})
opts = setup_opts(opts, [:host, :domain])
hostname = "#{opts[:host]}.#{opts[:domain]}"
begin
Resolv::DNS.open(:nameserver => [nameserver], :search => [], :ndots => 1) do |dns|
r = dns.getresource(hostname, Resolv::DNS::Resource::IN::A)
result = [{:host =>host, :data => r.address}]
end
rescue
raise "Domain needs to exist in dyndns as an A record before record can be updated"
end
return true
end
|
#nameserver ⇒ Object
13
14
15
|
# File 'lib/rubber/dns/dyndns.rb', line 13
def nameserver
"ns1.mydyndns.org"
end
|
#up_to_date(host, ip) ⇒ Object
17
18
19
20
21
22
23
24
|
# File 'lib/rubber/dns/dyndns.rb', line 17
def up_to_date(host, ip)
current_ip = nil
Resolv::DNS.open(:nameserver => [nameserver], :search => [], :ndots => 1) do |dns|
current_ip = dns.getaddress("#{host}.#{provider_env.domain}").to_s rescue nil
end
return ip == current_ip
end
|
#update_host_record(old_opts = {}, new_opts = {}) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/rubber/dns/dyndns.rb', line 48
def update_host_record(old_opts={}, new_opts={})
old_opts = setup_opts(opts, [:host, :domain])
new_opts = setup_opts(opts, [:data])
host = hostname(old_opts[:host])
ip = new_opts[:data]
update_url = eval('%Q{' + @update_url + '}')
= {
"User-Agent" => "Capistrano - Rubber - 0.1"
}
uri = URI.parse(update_url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true if uri.scheme == "https"
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
req = Net::HTTP::Get.new(update_url.gsub(/.*:\/\/[^\/]*/, ''), )
req.basic_auth @user, @pass
resp = http.request(req)
puts "DynDNS Update result: #{resp.body}"
end
|