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
Instance Method Summary
collapse
Methods inherited from Base
#destroy, #hostname, #up_to_date, #update
Constructor Details
#initialize(env) ⇒ Dyndns
Returns a new instance of Dyndns.
6
7
8
9
10
11
12
|
# File 'lib/rubber/dns/dyndns.rb', line 6
def initialize(env)
super(env)
@dyndns_env = env.dns_providers.dyndns
@user, @pass = @dyndns_env.user, @dyndns_env.password
@update_url = @dyndns_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(host, ip) ⇒ Object
29
30
31
|
# File 'lib/rubber/dns/dyndns.rb', line 29
def create_host_record(host, ip)
puts "WARNING: No create record available for dyndns, you need to do so manually"
end
|
#destroy_host_record(host) ⇒ Object
33
34
35
|
# File 'lib/rubber/dns/dyndns.rb', line 33
def destroy_host_record(host)
puts "WARNING: No destroy record available for dyndns, you need to do so manually"
end
|
#host_exists?(host) ⇒ Boolean
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/rubber/dns/dyndns.rb', line 18
def host_exists?(host)
begin
Resolv::DNS.open(:nameserver => [nameserver], :search => [], :ndots => 1) do |dns|
dns.getresource(hostname(host), Resolv::DNS::Resource::IN::A)
end
rescue
raise "Domain needs to exist in dyndns as an A record before record can be updated"
end
return true
end
|
#nameserver ⇒ Object
14
15
16
|
# File 'lib/rubber/dns/dyndns.rb', line 14
def nameserver
"ns1.mydyndns.org"
end
|
#update_host_record(host, ip) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/rubber/dns/dyndns.rb', line 37
def update_host_record(host, ip)
host = hostname(host)
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
|