dnsomatic 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/dnsomatic +3 -1
- data/lib/dnsomatic.rb +18 -19
- data/lib/dnsomatic/config.rb +59 -59
- data/lib/dnsomatic/iplookup.rb +29 -29
- data/lib/dnsomatic/logger.rb +1 -1
- data/lib/dnsomatic/open-uri.rb +683 -0
- data/lib/dnsomatic/opts.rb +63 -63
- data/lib/dnsomatic/updater.rb +17 -14
- metadata +17 -16
data/lib/dnsomatic/opts.rb
CHANGED
@@ -22,70 +22,70 @@ module DNSOMatic
|
|
22
22
|
def parse(args)
|
23
23
|
setdefaults()
|
24
24
|
begin
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
#
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
25
|
+
opts = OptionParser.new do |o|
|
26
|
+
o.on('-m', '--minimum SEC', 'The minimum time between updates (def: 30m)') do |i|
|
27
|
+
@@opts.minimum = i.to_i
|
28
|
+
end
|
29
|
+
|
30
|
+
o.on('-M', '--maximum SEC', 'The maximum time between updates (def: 15d)') do |i|
|
31
|
+
@@opts.maximum = i.to_i
|
32
|
+
end
|
33
|
+
#
|
34
|
+
#making this an option (off by default) means we can operate
|
35
|
+
#completely silently by default.
|
36
|
+
o.on('-a', '--alert', 'Emit an alert if the IP is updated') do |a|
|
37
|
+
@@opts.alert = true
|
38
|
+
end
|
39
|
+
|
40
|
+
o.on('-n', '--name NAME', 'Only update host stanza NAME') do |n|
|
41
|
+
@@opts.name = n
|
42
|
+
end
|
43
|
+
|
44
|
+
o.on('-d', '--display-config', 'Display the configuration and exit') do
|
45
|
+
@@opts.showcf = true
|
46
|
+
end
|
47
|
+
|
48
|
+
o.on('-c', '--config FILE', 'Use an alternate config file') do |f|
|
49
|
+
@@opts.cf = f
|
50
|
+
end
|
51
|
+
|
52
|
+
o.on('-f', '--force', 'Force an update, even if IP is unchanged') do
|
53
|
+
@@opts.force = true
|
54
|
+
end
|
55
|
+
|
56
|
+
o.on('-p', '--print', 'Output the update URLs. No action taken') do
|
57
|
+
@@opts.print = true
|
58
|
+
end
|
59
|
+
|
60
|
+
o.on('-v', '--verbose', 'Display runtime messages') do
|
61
|
+
@@opts.verbose = true
|
62
|
+
end
|
63
|
+
|
64
|
+
o.on('-V', '--version', 'Display version and exit') do
|
65
|
+
DNSOMatic::Logger.warn(DNSOMatic::VERSION)
|
66
|
+
exit
|
67
|
+
end
|
68
|
+
|
69
|
+
o.on('-x', '--debug', 'Output additional info in error situations') do
|
70
|
+
@@opts.debug = true
|
71
|
+
end
|
72
|
+
|
73
|
+
o.on('-h', '--help', 'Display this help text') do
|
74
|
+
DNSOMatic::Logger.warn(o)
|
75
|
+
exit
|
76
|
+
end
|
77
|
+
end
|
78
|
+
opts.parse!(args)
|
79
|
+
|
80
|
+
if args.size > 0
|
81
|
+
raise(DNSOMatic::Error, "Extra arguments given: #{args.join(', ')}")
|
82
|
+
end
|
83
83
|
|
84
84
|
rescue OptionParser::ParseError => e
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
85
|
+
msg = "Extra/Unknown arguments used:\n"
|
86
|
+
msg += "\t#{e.message}\n"
|
87
|
+
msg += "Remaining args: #{args.join(', ')}\n" if args.size > 0
|
88
|
+
raise(DNSOMatic::Error, msg)
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
@@ -106,7 +106,7 @@ module DNSOMatic
|
|
106
106
|
@@opts.print = false
|
107
107
|
@@opts.verbose = false
|
108
108
|
@@opts.minimum = 1800 #30 minutes
|
109
|
-
@@opts.maximum = 1296000
|
109
|
+
@@opts.maximum = 1296000 #15 days
|
110
110
|
@@opts.debug = false
|
111
111
|
@@opts.alert = false
|
112
112
|
end
|
data/lib/dnsomatic/updater.rb
CHANGED
@@ -24,20 +24,23 @@ module DNSOMatic
|
|
24
24
|
# By default, the we'll honour the changed? status of the IPStatus object
|
25
25
|
# returned to us, but if force is set to true, we'll send the update
|
26
26
|
# request anyway.
|
27
|
-
def update(force = false)
|
27
|
+
def update(force = false)
|
28
|
+
url = upd_url()
|
29
|
+
|
30
|
+
DNSOMatic::Logger.log("Updating with URL: #{url}")
|
28
31
|
|
29
32
|
if !@ipstatus.changed? and !force
|
30
|
-
|
33
|
+
Logger::log("No change in IP detected for #{@config['hostname']}. Not updating.")
|
31
34
|
else
|
32
|
-
|
33
|
-
|
35
|
+
Logger::alert("Updating IP for #{@config['hostname']} to #{@ipstatus.ip}.")
|
36
|
+
update = DNSOMatic::http_fetch(url)
|
34
37
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
if !update.match(/^good\s+#{@ipstatus.ip}$/)
|
39
|
+
msg = "Error updating host definition for #{@config['hostname']}\n"
|
40
|
+
msg += "Results:\n#{update}\n"
|
41
|
+
msg += "Error codes at: https://www.dnsomatic.com/wiki/api"
|
42
|
+
raise(DNSOMatic::Error, msg)
|
43
|
+
end
|
41
44
|
end
|
42
45
|
|
43
46
|
true
|
@@ -56,7 +59,7 @@ module DNSOMatic
|
|
56
59
|
def to_s
|
57
60
|
upd_url
|
58
61
|
end
|
59
|
-
|
62
|
+
|
60
63
|
private
|
61
64
|
def upd_url
|
62
65
|
opt_params = %w(wildcard mx backmx offline)
|
@@ -69,9 +72,9 @@ module DNSOMatic
|
|
69
72
|
url = "https://#{u}:#{p}@updates.dnsomatic.com/nic/update?"
|
70
73
|
name_ip = "hostname=#{@config['hostname']}&myip=#{@ipstatus.ip}"
|
71
74
|
url += opt_params.inject(name_ip) do |params, curp|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
+
val = @config[curp]
|
76
|
+
next if val.eql?('') or val.nil?
|
77
|
+
params += "&#{curp}=#{val}"
|
75
78
|
end
|
76
79
|
url
|
77
80
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dnsomatic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Walton
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-10-03 00:00:00 -04:00
|
13
13
|
default_executable: dnsomatic
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -23,29 +23,30 @@ extra_rdoc_files: []
|
|
23
23
|
|
24
24
|
files:
|
25
25
|
- bin/dnsomatic
|
26
|
+
- lib/dnsomatic.rb
|
26
27
|
- lib/dnsomatic
|
27
|
-
- lib/dnsomatic/updater.rb
|
28
28
|
- lib/dnsomatic/logger.rb
|
29
29
|
- lib/dnsomatic/iplookup.rb
|
30
|
-
- lib/dnsomatic/
|
30
|
+
- lib/dnsomatic/updater.rb
|
31
31
|
- lib/dnsomatic/config.rb
|
32
|
-
- lib/dnsomatic.rb
|
33
|
-
-
|
34
|
-
- tests/
|
35
|
-
- tests/test_logger.rb
|
36
|
-
- tests/test_updater.rb
|
32
|
+
- lib/dnsomatic/open-uri.rb
|
33
|
+
- lib/dnsomatic/opts.rb
|
34
|
+
- tests/test_config.rb
|
37
35
|
- tests/all_tests.rb
|
36
|
+
- tests/test_opts.rb
|
37
|
+
- tests/test_ipstatus.rb
|
38
|
+
- tests/test_iplookup.rb
|
38
39
|
- tests/confs
|
39
40
|
- tests/confs/1_stanza_no_defs_no_u_p.cf
|
40
|
-
- tests/confs/
|
41
|
-
- tests/confs/
|
41
|
+
- tests/confs/3_stanzas_no_def_no_u_p.cf
|
42
|
+
- tests/confs/defs_with_bad_mx_set.cf
|
42
43
|
- tests/confs/3_good_stanzas.cf
|
44
|
+
- tests/confs/defs_with_mx_set.cf
|
45
|
+
- tests/confs/working_only_defs.cf
|
43
46
|
- tests/confs/empty_conf.cf
|
44
47
|
- tests/confs/defs_with_override_ipfetch.cf
|
45
|
-
- tests/
|
46
|
-
- tests/
|
47
|
-
- tests/test_config.rb
|
48
|
-
- tests/test_iplookup.rb
|
48
|
+
- tests/test_logger.rb
|
49
|
+
- tests/test_updater.rb
|
49
50
|
has_rdoc: true
|
50
51
|
homepage: http://rubyforge.org/projects/dnsomatic
|
51
52
|
post_install_message:
|
@@ -68,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
69
|
requirements: []
|
69
70
|
|
70
71
|
rubyforge_project: http://rubyforge.org/projects/dnsomatic
|
71
|
-
rubygems_version: 1.
|
72
|
+
rubygems_version: 1.3.1
|
72
73
|
signing_key:
|
73
74
|
specification_version: 2
|
74
75
|
summary: A DNS-O-Matic Update Client
|