dyndnsd 2.2.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38018d9a0981b3c2a641440f3848eebadac2ca688e22cd3d3f48dca362ecbb72
4
- data.tar.gz: 98685b2439de5962c7e6ebb6aee708e361541f2cc9be83f4f21b28fe8f8af873
3
+ metadata.gz: 2003e75744105357e1470d1f76b3c8d2eac5216d5798254d7422cf3b708dc44d
4
+ data.tar.gz: caf21fc198d0e05acb5e11fc08c10c51adb0aad6c40871c9c3ccb35013895855
5
5
  SHA512:
6
- metadata.gz: 1057f502a1bbe3e99c6282747765bc25d7e9a2f37c7409e50969847fe353e877c6eefb698099bf148543a6412cd0c6e33df3039a0099551391c8dfb0cdb5e80f
7
- data.tar.gz: dcce864fad0992c9868394000286cb6200512e1103017d373358aa3c71c89a94e27796c8bfd11a11ec96fe6d63fc3318938942621178cf111879863fad7347cf
6
+ metadata.gz: 7dbfe6c72d92bc7d78a2e4060988919fa8f5eedf5e10abb1a0f199e18eeb6c3b3f40a647016f8e5c52fa0edc25318ef6215daba78ceedc04848ef448bfe6860a
7
+ data.tar.gz: db34bc86ee30473a26432eb44465da987ac6ef99bd19c9b21087bdb97713976e333c3349b8d90f79d7c80e15c011fb725c84f614c83e06e61d1496b28e3e5103
@@ -1,5 +1,30 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.1.0 (August 19, 2020)
4
+
5
+ IMPROVEMENTS:
6
+
7
+ - Add officially maintained [Docker image for dyndnsd](https://hub.docker.com/r/cmur2/dyndnsd)
8
+
9
+ ## 3.0.0 (July 29, 2020)
10
+
11
+ IMPROVEMENTS:
12
+
13
+ - Drop EOL Ruby 2.4 and lower support, now minimum version supported is Ruby 2.5
14
+
15
+ ## 2.3.1 (July 27, 2020)
16
+
17
+ IMPROVEMENTS:
18
+
19
+ - Fix annoying error message `log writing failed. can't be called from trap context` on shutdown by not attempting to log redundant information there
20
+
21
+ ## 2.3.0 (July 20, 2020)
22
+
23
+ IMPROVEMENTS:
24
+
25
+ - Allow enabling debug logging
26
+ - Add updater that uses [DNS zone transfers via AXFR (RFC5936)](https://tools.ietf.org/html/rfc5936) to allow any secondary nameserver(s) to fetch the zone contents after (optionally) receiving a [DNS NOTIFY (RFC1996)](https://tools.ietf.org/html/rfc1996) request
27
+
3
28
  ## 2.2.0 (March 6, 2020)
4
29
 
5
30
  IMPROVEMENTS:
data/README.md CHANGED
@@ -4,16 +4,20 @@
4
4
 
5
5
  A small, lightweight and extensible DynDNS server written with Ruby and Rack.
6
6
 
7
+
7
8
  ## Description
8
9
 
9
- dyndnsd.rb aims to implement a small [DynDNS-compliant](https://help.dyn.com/remote-access-api/) server in Ruby supporting IPv4 and IPv6 addresses. It has an integrated user and hostname database in it's configuration file that is used for authentication and authorization. Besides talking the DynDNS protocol it is able to invoke a so-called *updater*, a small Ruby module that takes care of supplying the current hostname => ip mapping to a DNS server.
10
+ dyndnsd.rb aims to implement a small [DynDNS-compliant](https://help.dyn.com/remote-access-api/) server in Ruby supporting IPv4 and IPv6 addresses. It has an integrated user and hostname database in its configuration file that is used for authentication and authorization. Besides talking the DynDNS protocol it is able to invoke a so-called *updater*, a small Ruby module that takes care of supplying the current hostname => ip mapping to a DNS server.
10
11
 
11
- There is currently one updater shipped with dyndnsd.rb `command_with_bind_zone` that writes out a zone file in BIND syntax onto the current system and invokes a user-supplied command afterwards that is assumed to trigger the DNS server (not necessarily BIND since it's zone files are read by other DNS servers, too) to reload it's zone configuration.
12
+ There are currently two updaters shipped with dyndnsd.rb:
13
+ - `zone_transfer_server` that uses [DNS zone transfers via AXFR (RFC5936)](https://tools.ietf.org/html/rfc5936) to allow any secondary nameserver(s) to fetch the zone contents after (optionally) receiving a [DNS NOTIFY (RFC1996)](https://tools.ietf.org/html/rfc1996) request
14
+ - `command_with_bind_zone` that writes out a zone file in BIND syntax onto the current system and invokes a user-supplied command afterwards that is assumed to trigger the DNS server (not necessarily BIND since its zone files are read by other DNS servers, too) to reload its zone configuration
12
15
 
13
16
  Because of the mechanisms used, dyndnsd.rb is known to work only on \*nix systems.
14
17
 
15
18
  See the [changelog](CHANGELOG.md) before upgrading. The older version 1.x of dyndnsd.rb is still available on [branch dyndnsd-1.x](https://github.com/cmur2/dyndnsd/tree/dyndnsd-1.x).
16
19
 
20
+
17
21
  ## General Usage
18
22
 
19
23
  Install the gem:
@@ -25,14 +29,16 @@ Create a configuration file in YAML format somewhere:
25
29
  ```yaml
26
30
  # listen address and port
27
31
  host: "0.0.0.0"
28
- port: "80"
29
- # optional: drop priviliges in case you want to but you may need sudo for external commands
32
+ port: 80
33
+ # optional: drop privileges in case you want to but you may need sudo for external commands
30
34
  user: "nobody"
31
35
  group: "nogroup"
32
- # logfile is optional, logs to STDOUT else
36
+ # logfile is optional, logs to STDOUT otherwise
33
37
  logfile: "dyndnsd.log"
34
- # interal database file
38
+ # internal database file
35
39
  db: "db.json"
40
+ # enable debug mode?
41
+ debug: false
36
42
  # all hostnames are required to be cool-name.example.org
37
43
  domain: "example.org"
38
44
  # configure the updater, here we use command_with_bind_zone, params are updater-specific
@@ -58,17 +64,98 @@ users:
58
64
 
59
65
  Run dyndnsd.rb by:
60
66
 
61
- dyndnsd /path/to/config.yaml
67
+ ```bash
68
+ dyndnsd /path/to/config.yml
69
+ ```
70
+
71
+
72
+ ### Docker image
73
+
74
+ There is an officially maintained [Docker image for dyndnsd](https://hub.docker.com/r/cmur2/dyndnsd) available at Dockerhub. The goal is to have a minimal secured image available (currently based on Alpine) that works well for the `zone_transfer_server` updater use case.
75
+
76
+ Users can make extensions by deriving from the official Docker image or building their own.
77
+
78
+ The Docker image consumes the same configuration file in YAML format as the gem, inside the container it needs to be mounted/available as `/etc/dyndnsd/config.yml`. the following YAML should be used as a base and extended with user's settings:
79
+
80
+ ```yaml
81
+ host: "0.0.0.0"
82
+ port: 8080
83
+ # omit the logfile: option so logging to STDOUT will happen automatically
84
+ db: "/var/lib/dyndnsd/db.json"
85
+
86
+ # User's settings for updater and permissions follow here!
87
+ ```
88
+
89
+ more ports might be needed depending on if DNS zone transfer is needed
90
+
91
+ Run the Docker image exposing the DynDNS-API on host port 8080 via:
92
+
93
+ ```bash
94
+ docker run -d --name dyndnsd \
95
+ -p 8080:8080 \
96
+ -v /host/path/to/dyndnsd/config.yml:/etc/dyndnsd/config.yml \
97
+ -v /host/ptherpath/to/dyndnsd/datadir:/var/lib/dyndnsd \
98
+ cmur2/dyndnsd:vX.Y.Z
99
+ ```
100
+
101
+ *Note*: You may need to expose more then just port 8080 e.g. if you use the `zone_transfer_server` which can be done by appending additional `-p 5353:5353` flags to the `docker run` command.
102
+
103
+
104
+
105
+ ## Using dyndnsd.rb with any nameserver via DNS zone transfers (AXFR)
106
+
107
+ By using [DNS zone transfers via AXFR (RFC5936)](https://tools.ietf.org/html/rfc5936) any secondary nameserver can retrieve the DNS zone contents from dyndnsd.rb and serve them to clients.
108
+ To speedup propagation after changes dyndnsd.rb can issue a [DNS NOTIFY (RFC1996)](https://tools.ietf.org/html/rfc1996) to inform the nameserver that the DNS zone contents changed and should be fetched even before the time indicated in the SOA record is up.
109
+ Currently dyndnsd.rb does not support any authentication for incoming DNS zone transfer requests so it should be isolated from the internet on these ports.
110
+
111
+ This approach has several advantages:
112
+ - dyndnsd.rb can be used in *hidden primary* fashion isolated from client's DNS traffic and does not need to implement full nameserver features
113
+ - any existing, production-grade, caching, geo-replicated nameserver setup can be used to pull DNS zone contents from the *hidden primary* dyndnsd.rb and serve it to clients
114
+ - any nameserver(s) and dyndnsd.rb do not need to be located on the same host
115
+
116
+ Example dyndnsd.rb configuration:
117
+
118
+ ```yaml
119
+ host: "0.0.0.0"
120
+ port: 8245 # the DynDNS.com alternative HTTP port
121
+ db: "/opt/dyndnsd/db.json"
122
+ domain: "dyn.example.org"
123
+ updater:
124
+ name: "zone_transfer_server"
125
+ params:
126
+ # endpoint(s) to listen for incoming zone transfer (AXFR) requests, default 0.0.0.0@53
127
+ server_listens:
128
+ - 127.0.0.1@5300
129
+ # where to send DNS NOTIFY request(s) to on zone content change
130
+ send_notifies:
131
+ - '127.0.0.1'
132
+ # TTL for all records in the zone (in seconds)
133
+ zone_ttl: 300 # 5m
134
+ # zone's NS record(s) (at least one)
135
+ zone_nameservers:
136
+ - "dns.example.org."
137
+ # info for zone's SOA record
138
+ zone_email_address: "admin.example.org."
139
+ # zone's additional A/AAAA records
140
+ zone_additional_ips:
141
+ - "127.0.0.1"
142
+ users:
143
+ foo:
144
+ password: "secret"
145
+ hosts:
146
+ - foo.example.org
147
+ ```
148
+
62
149
 
63
- ## Using dyndnsd.rb with [NSD](https://www.nlnetlabs.nl/nsd/)
150
+ ## Using dyndnsd.rb with [NSD](https://www.nlnetlabs.nl/projects/nsd/about/)
64
151
 
65
- NSD is a nice opensource, authoritative-only, low-memory DNS server that reads BIND-style zone files (and converts them into it's own database) and has a simple config file.
152
+ NSD is a nice, open source, authoritative-only, low-memory DNS server that reads BIND-style zone files (and converts them into its own database) and has a simple configuration file.
66
153
 
67
- A feature NSD is lacking is the [Dynamic DNS update](https://tools.ietf.org/html/rfc2136) functionality BIND offers but one can fake it using the following dyndnsd.rb config:
154
+ A feature NSD is lacking is the [Dynamic DNS update (RFC2136)](https://tools.ietf.org/html/rfc2136) functionality BIND offers but one can fake it using the following dyndnsd.rb configuration:
68
155
 
69
156
  ```yaml
70
157
  host: "0.0.0.0"
71
- port: "8245" # the DynDNS.com alternative HTTP port
158
+ port: 8245 # the DynDNS.com alternative HTTP port
72
159
  db: "/opt/dyndnsd/db.json"
73
160
  domain: "dyn.example.org"
74
161
  updater:
@@ -88,17 +175,20 @@ users:
88
175
  foo:
89
176
  password: "secret"
90
177
  hosts:
91
- - foo.example.org
178
+ - foo.example.org
92
179
  ```
93
180
 
94
181
  Start dyndnsd.rb before NSD to make sure the zone file exists else NSD complains.
95
182
 
183
+
96
184
  ## Using dyndnsd.rb with X
97
185
 
98
186
  Please provide ideas if you are using dyndnsd.rb with other DNS servers :)
99
187
 
188
+
100
189
  ## Advanced topics
101
190
 
191
+
102
192
  ### Update URL
103
193
 
104
194
  The update URL you want to tell your clients (humans or scripts ^^) consists of the following
@@ -111,10 +201,11 @@ where:
111
201
  * USER and PASSWORD are needed for HTTP Basic Auth and valid combinations are defined in your config.yaml
112
202
  * DOMAIN should match what you defined in your config.yaml as domain but may be anything else when using a webserver as proxy
113
203
  * PORT depends on your (webserver/proxy) settings
114
- * HOSTNAMES is a required list of comma separated FQDNs (they all have to end with your config.yaml domain) the user wants to update
204
+ * HOSTNAMES is a required list of comma-separated FQDNs (they all have to end with your config.yaml domain) the user wants to update
115
205
  * MYIP is optional and the HTTP client's IP address will be used if missing
116
206
  * MYIP6 is optional but if present also requires presence of MYIP
117
207
 
208
+
118
209
  ### IP address determination
119
210
 
120
211
  The following rules apply:
@@ -123,15 +214,20 @@ The following rules apply:
123
214
  * use any IP address provided via the X-Real-IP header e.g. when used behind HTTP reverse proxy such as nginx, or
124
215
  * use any IP address used by the connecting HTTP client
125
216
 
126
- If you want to provide an additional IPv6 address as myip6 parameter the myip parameter containing an IPv4 address has to be present, too! No automatism is applied then.
217
+ If you want to provide an additional IPv6 address as myip6 parameter, the myip parameter containing an IPv4 address has to be present, too! No automatism is applied then.
218
+
127
219
 
128
220
  ### SSL, multiple listen ports
129
221
 
130
222
  Use a webserver as a proxy to handle SSL and/or multiple listen addresses and ports. DynDNS.com provides HTTP on port 80 and 8245 and HTTPS on port 443.
131
223
 
132
- ### Init scripts
133
224
 
134
- The [Debian 6 init.d script](init.d/debian-6-dyndnsd) assumes that dyndnsd.rb is installed into the system ruby (no RVM support) and the config.yaml is at /opt/dyndnsd/config.yaml. Modify to your needs.
225
+ ### Startup
226
+
227
+ There is a [Dockerfile](docs/Dockerfile) that can be used to build a Docker image for running dyndnsd.rb.
228
+
229
+ The [Debian 6 init.d script](docs/debian-6-init-dyndnsd) assumes that dyndnsd.rb is installed into the system ruby (no RVM support) and the config.yaml is at /opt/dyndnsd/config.yaml. Modify to your needs.
230
+
135
231
 
136
232
  ### Monitoring
137
233
 
@@ -139,7 +235,7 @@ For monitoring dyndnsd.rb uses the [metriks](https://github.com/eric/metriks) fr
139
235
 
140
236
  ```yaml
141
237
  host: "0.0.0.0"
142
- port: "8245" # the DynDNS.com alternative HTTP port
238
+ port: 8245 # the DynDNS.com alternative HTTP port
143
239
  db: "/opt/dyndnsd/db.json"
144
240
  domain: "dyn.example.org"
145
241
  # configure the Graphite backend to be used instead of proctitle
@@ -172,14 +268,16 @@ users:
172
268
  password: "ihavenohosts"
173
269
  ```
174
270
 
271
+
175
272
  ### Tracing (experimental)
176
273
 
177
- For tracing dyndnsd.rb is instrumented using the [OpenTracing](http://opentracing.io/) framework and will emit span tracing data for the most important operations happening during the request/response cycle. Using a middleware for Rack allows handling incoming OpenTracing span information properly.
274
+ For tracing, dyndnsd.rb is instrumented using the [OpenTracing](http://opentracing.io/) framework and will emit span tracing data for the most important operations happening during the request/response cycle. Using a middleware for Rack allows handling incoming OpenTracing span information properly.
275
+
178
276
  Currently only one OpenTracing-compatible tracer implementation named [CNCF Jaeger](https://github.com/jaegertracing/jaeger) can be configured to use with dyndnsd.rb.
179
277
 
180
278
  ```yaml
181
279
  host: "0.0.0.0"
182
- port: "8245" # the DynDNS.com alternative HTTP port
280
+ port: 8245 # the DynDNS.com alternative HTTP port
183
281
  db: "/opt/dyndnsd/db.json"
184
282
  domain: "dyn.example.org"
185
283
  # enable and configure tracing using the (currently only) tracer jaeger
@@ -210,6 +308,7 @@ users:
210
308
  password: "ihavenohosts"
211
309
  ```
212
310
 
311
+
213
312
  ## License
214
313
 
215
314
  dyndnsd.rb is licensed under the Apache License, Version 2.0. See LICENSE for more information.
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'date'
3
4
  require 'etc'
4
5
  require 'logger'
5
6
  require 'ipaddr'
@@ -13,6 +14,7 @@ require 'rack/tracer'
13
14
 
14
15
  require 'dyndnsd/generator/bind'
15
16
  require 'dyndnsd/updater/command_with_bind_zone'
17
+ require 'dyndnsd/updater/zone_transfer_server'
16
18
  require 'dyndnsd/responder/dyndns_style'
17
19
  require 'dyndnsd/responder/rest_style'
18
20
  require 'dyndnsd/database'
@@ -56,9 +58,9 @@ module Dyndnsd
56
58
  @db.load
57
59
  @db['serial'] ||= 1
58
60
  @db['hosts'] ||= {}
61
+ @updater.update(@db)
59
62
  if @db.changed?
60
63
  @db.save
61
- @updater.update(@db)
62
64
  end
63
65
  end
64
66
 
@@ -79,7 +81,7 @@ module Dyndnsd
79
81
  end
80
82
 
81
83
  # @param env [Hash{String => String}]
82
- # @return [Array{Integer,Hash{String => String},Array{String}}]
84
+ # @return [Array{Integer,Hash{String => String},Array<String>}]
83
85
  def call(env)
84
86
  return [422, {'X-DynDNS-Response' => 'method_forbidden'}, []] if env['REQUEST_METHOD'] != 'GET'
85
87
  return [422, {'X-DynDNS-Response' => 'not_found'}, []] if env['PATH_INFO'] != '/nic/update'
@@ -133,7 +135,7 @@ module Dyndnsd
133
135
  private
134
136
 
135
137
  # @param params [Hash{String => String}]
136
- # @return [Array{String}]
138
+ # @return [Array<String>]
137
139
  def extract_v4_and_v6_address(params)
138
140
  return [] if !(params['myip'])
139
141
  begin
@@ -147,7 +149,7 @@ module Dyndnsd
147
149
 
148
150
  # @param env [Hash{String => String}]
149
151
  # @param params [Hash{String => String}]
150
- # @return [Array{String}]
152
+ # @return [Array<String>]
151
153
  def extract_myips(env, params)
152
154
  # require presence of myip parameter as valid IPAddr (v4) and valid myip6
153
155
  return extract_v4_and_v6_address(params) if params.key?('myip6')
@@ -163,8 +165,8 @@ module Dyndnsd
163
165
  end
164
166
 
165
167
  # @param hostnames [String]
166
- # @param myips [Array{String}]
167
- # @return [Array{Symbol}]
168
+ # @param myips [Array<String>]
169
+ # @return [Array<Symbol>]
168
170
  def process_changes(hostnames, myips)
169
171
  changes = []
170
172
  Helper.span('process_changes') do |span|
@@ -193,13 +195,13 @@ module Dyndnsd
193
195
  def update_db
194
196
  @db['serial'] += 1
195
197
  Dyndnsd.logger.info "Committing update ##{@db['serial']}"
196
- @db.save
197
198
  @updater.update(@db)
199
+ @db.save
198
200
  Metriks.meter('updates.committed').mark
199
201
  end
200
202
 
201
203
  # @param env [Hash{String => String}]
202
- # @return [Array{Integer,Hash{String => String},Array{String}}]
204
+ # @return [Array{Integer,Hash{String => String},Array<String>}]
203
205
  def handle_dyndns_request(env)
204
206
  params = Rack::Utils.parse_query(env['QUERY_STRING'])
205
207
 
@@ -244,21 +246,20 @@ module Dyndnsd
244
246
  if config['logfile']
245
247
  Dyndnsd.logger = Logger.new(config['logfile'])
246
248
  else
247
- Dyndnsd.logger = Logger.new(STDOUT)
249
+ Dyndnsd.logger = Logger.new($stdout)
248
250
  end
249
251
 
250
252
  Dyndnsd.logger.progname = 'dyndnsd'
251
253
  Dyndnsd.logger.formatter = LogFormatter.new
254
+ Dyndnsd.logger.level = config['debug'] ? Logger::DEBUG : Logger::INFO
252
255
  end
253
256
 
254
257
  # @return [void]
255
258
  private_class_method def self.setup_traps
256
259
  Signal.trap('INT') do
257
- Dyndnsd.logger.info 'Quitting...'
258
260
  Rack::Handler::WEBrick.shutdown
259
261
  end
260
262
  Signal.trap('TERM') do
261
- Dyndnsd.logger.info 'Quitting...'
262
263
  Rack::Handler::WEBrick.shutdown
263
264
  end
264
265
  end
@@ -313,7 +314,12 @@ module Dyndnsd
313
314
  private_class_method def self.setup_rack(config)
314
315
  # configure daemon
315
316
  db = Database.new(config['db'])
316
- updater = Updater::CommandWithBindZone.new(config['domain'], config.dig('updater', 'params')) if config.dig('updater', 'name') == 'command_with_bind_zone'
317
+ case config.dig('updater', 'name')
318
+ when 'command_with_bind_zone'
319
+ updater = Updater::CommandWithBindZone.new(config['domain'], config.dig('updater', 'params'))
320
+ when 'zone_transfer_server'
321
+ updater = Updater::ZoneTransferServer.new(config['domain'], config.dig('updater', 'params'))
322
+ end
317
323
  daemon = Daemon.new(config, db, updater)
318
324
 
319
325
  # configure rack
@@ -4,13 +4,13 @@ module Dyndnsd
4
4
  module Generator
5
5
  class Bind
6
6
  # @param domain [String]
7
- # @param config [Hash{String => Object}]
8
- def initialize(domain, config)
7
+ # @param updater_params [Hash{String => Object}]
8
+ def initialize(domain, updater_params)
9
9
  @domain = domain
10
- @ttl = config['ttl']
11
- @dns = config['dns']
12
- @email_addr = config['email_addr']
13
- @additional_zone_content = config['additional_zone_content']
10
+ @ttl = updater_params['ttl']
11
+ @dns = updater_params['dns']
12
+ @email_addr = updater_params['email_addr']
13
+ @additional_zone_content = updater_params['additional_zone_content']
14
14
  end
15
15
 
16
16
  # @param db [Dyndnsd::Database]
@@ -27,7 +27,7 @@ module Dyndnsd
27
27
  ips.each do |ip|
28
28
  ip = IPAddr.new(ip).native
29
29
  type = ip.ipv6? ? 'AAAA' : 'A'
30
- name = hostname.chomp('.' + @domain)
30
+ name = hostname.chomp(".#{@domain}")
31
31
  out << "#{name} IN #{type} #{ip}"
32
32
  end
33
33
  end
@@ -9,7 +9,7 @@ module Dyndnsd
9
9
  end
10
10
 
11
11
  # @param env [Hash{String => String}]
12
- # @return [Array{Integer,Hash{String => String},Array{String}}]
12
+ # @return [Array{Integer,Hash{String => String},Array<String>}]
13
13
  def call(env)
14
14
  @app.call(env).tap do |status_code, headers, body|
15
15
  if headers.key?('X-DynDNS-Response')
@@ -24,30 +24,32 @@ module Dyndnsd
24
24
 
25
25
  # @param status_code [Integer]
26
26
  # @param headers [Hash{String => String}]
27
- # @param body [Array{String}]
28
- # @return [Array{Integer,Hash{String => String},Array{String}}]
27
+ # @param body [Array<String>]
28
+ # @return [Array{Integer,Hash{String => String},Array<String>}]
29
29
  def decorate_dyndnsd_response(status_code, headers, body)
30
- if status_code == 200
30
+ case status_code
31
+ when 200
31
32
  [200, {'Content-Type' => 'text/plain'}, [get_success_body(body[0], body[1])]]
32
- elsif status_code == 422
33
+ when 422
33
34
  error_response_map[headers['X-DynDNS-Response']]
34
35
  end
35
36
  end
36
37
 
37
38
  # @param status_code [Integer]
38
39
  # @param headers [Hash{String => String}]
39
- # @param _body [Array{String}]
40
- # @return [Array{Integer,Hash{String => String},Array{String}}]
40
+ # @param _body [Array<String>]
41
+ # @return [Array{Integer,Hash{String => String},Array<String>}]
41
42
  def decorate_other_response(status_code, headers, _body)
42
- if status_code == 400
43
+ case status_code
44
+ when 400
43
45
  [status_code, headers, ['Bad Request']]
44
- elsif status_code == 401
46
+ when 401
45
47
  [status_code, headers, ['badauth']]
46
48
  end
47
49
  end
48
50
 
49
- # @param changes [Array{Symbol}]
50
- # @param myips [Array{String}]
51
+ # @param changes [Array<Symbol>]
52
+ # @param myips [Array<String>]
51
53
  # @return [String]
52
54
  def get_success_body(changes, myips)
53
55
  changes.map { |change| "#{change} #{myips.join(' ')}" }.join("\n")
@@ -9,7 +9,7 @@ module Dyndnsd
9
9
  end
10
10
 
11
11
  # @param env [Hash{String => String}]
12
- # @return [Array{Integer,Hash{String => String},Array{String}}]
12
+ # @return [Array{Integer,Hash{String => String},Array<String>}]
13
13
  def call(env)
14
14
  @app.call(env).tap do |status_code, headers, body|
15
15
  if headers.key?('X-DynDNS-Response')
@@ -24,30 +24,32 @@ module Dyndnsd
24
24
 
25
25
  # @param status_code [Integer]
26
26
  # @param headers [Hash{String => String}]
27
- # @param body [Array{String}]
28
- # @return [Array{Integer,Hash{String => String},Array{String}}]
27
+ # @param body [Array<String>]
28
+ # @return [Array{Integer,Hash{String => String},Array<String>}]
29
29
  def decorate_dyndnsd_response(status_code, headers, body)
30
- if status_code == 200
30
+ case status_code
31
+ when 200
31
32
  [200, {'Content-Type' => 'text/plain'}, [get_success_body(body[0], body[1])]]
32
- elsif status_code == 422
33
+ when 422
33
34
  error_response_map[headers['X-DynDNS-Response']]
34
35
  end
35
36
  end
36
37
 
37
38
  # @param status_code [Integer]
38
39
  # @param headers [Hash{String => String}]
39
- # @param _body [Array{String}]
40
- # @return [Array{Integer,Hash{String => String},Array{String}}]
40
+ # @param _body [Array<String>]
41
+ # @return [Array{Integer,Hash{String => String},Array<String>}]
41
42
  def decorate_other_response(status_code, headers, _body)
42
- if status_code == 400
43
+ case status_code
44
+ when 400
43
45
  [status_code, headers, ['Bad Request']]
44
- elsif status_code == 401
46
+ when 401
45
47
  [status_code, headers, ['Unauthorized']]
46
48
  end
47
49
  end
48
50
 
49
- # @param changes [Array{Symbol}]
50
- # @param myips [Array{String}]
51
+ # @param changes [Array<Symbol>]
52
+ # @param myips [Array<String>]
51
53
  # @return [String]
52
54
  def get_success_body(changes, myips)
53
55
  changes.map { |change| change == :good ? "Changed to #{myips.join(' ')}" : "No change needed for #{myips.join(' ')}" }.join("\n")
@@ -28,11 +28,9 @@ module Dyndnsd
28
28
  sleep @interval
29
29
 
30
30
  Thread.new do
31
- begin
32
- write
33
- rescue StandardError => e
34
- @on_error[e] rescue nil
35
- end
31
+ write
32
+ rescue StandardError => e
33
+ @on_error[e] rescue nil
36
34
  end
37
35
  end
38
36
  end
@@ -96,8 +94,8 @@ module Dyndnsd
96
94
  # @param file [String]
97
95
  # @param base_name [String]
98
96
  # @param metric [Object]
99
- # @param keys [Array{Symbol}]
100
- # @param snapshot_keys [Array{Symbol}]
97
+ # @param keys [Array<Symbol>]
98
+ # @param snapshot_keys [Array<Symbol>]
101
99
  # @return [void]
102
100
  def write_metric(file, base_name, metric, keys, snapshot_keys = [])
103
101
  time = Time.now.to_i
@@ -4,16 +4,19 @@ module Dyndnsd
4
4
  module Updater
5
5
  class CommandWithBindZone
6
6
  # @param domain [String]
7
- # @param config [Hash{String => Object}]
8
- def initialize(domain, config)
9
- @zone_file = config['zone_file']
10
- @command = config['command']
11
- @generator = Generator::Bind.new(domain, config)
7
+ # @param updater_params [Hash{String => Object}]
8
+ def initialize(domain, updater_params)
9
+ @zone_file = updater_params['zone_file']
10
+ @command = updater_params['command']
11
+ @generator = Generator::Bind.new(domain, updater_params)
12
12
  end
13
13
 
14
14
  # @param db [Dyndnsd::Database]
15
15
  # @return [void]
16
16
  def update(db)
17
+ # do not regenerate zone file (assumed to be persistent) if DB did not change
18
+ return if !db.changed?
19
+
17
20
  Helper.span('updater_update') do |span|
18
21
  span.set_tag('dyndnsd.updater.name', self.class.name&.split('::')&.last || 'None')
19
22
 
@@ -0,0 +1,158 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'resolv'
4
+ require 'securerandom'
5
+
6
+ require 'async/dns'
7
+
8
+ module Dyndnsd
9
+ module Updater
10
+ class ZoneTransferServer
11
+ DEFAULT_SERVER_LISTENS = ['0.0.0.0@53'].freeze
12
+
13
+ # @param domain [String]
14
+ # @param updater_params [Hash{String => Object}]
15
+ def initialize(domain, updater_params)
16
+ @domain = domain
17
+
18
+ @server_listens = self.class.parse_endpoints(updater_params['server_listens'] || DEFAULT_SERVER_LISTENS)
19
+ @notify_targets = (updater_params['send_notifies'] || []).map { |e| self.class.parse_endpoints([e]) }
20
+
21
+ @zone_rr_ttl = updater_params['zone_ttl']
22
+ @zone_nameservers = updater_params['zone_nameservers'].map { |n| Resolv::DNS::Name.create(n) }
23
+ @zone_email_address = Resolv::DNS::Name.create(updater_params['zone_email_address'])
24
+ @zone_additional_ips = updater_params['zone_additional_ips'] || []
25
+
26
+ @server = ZoneTransferServerHelper.new(@server_listens, @domain)
27
+
28
+ # run Async::DNS server in background thread
29
+ Thread.new do
30
+ @server.run
31
+ end
32
+ end
33
+
34
+ # @param db [Dyndnsd::Database]
35
+ # @return [void]
36
+ def update(db)
37
+ Helper.span('updater_update') do |span|
38
+ span.set_tag('dyndnsd.updater.name', self.class.name&.split('::')&.last || 'None')
39
+
40
+ soa_rr = Resolv::DNS::Resource::IN::SOA.new(
41
+ @zone_nameservers[0], @zone_email_address,
42
+ db['serial'],
43
+ 10_800, # 3h
44
+ 300, # 5m
45
+ 604_800, # 1w
46
+ 3_600 # 1h
47
+ )
48
+
49
+ default_options = {ttl: @zone_rr_ttl}
50
+
51
+ # array containing all resource records for an AXFR request in the right order
52
+ rrs = []
53
+ # AXFR responses need to start with zone's SOA RR
54
+ rrs << [soa_rr, default_options]
55
+
56
+ # return RRs for all of the zone's nameservers
57
+ @zone_nameservers.each do |ns|
58
+ rrs << [Resolv::DNS::Resource::IN::NS.new(ns), default_options]
59
+ end
60
+
61
+ # return A/AAAA RRs for all additional IPv4s/IPv6s for the domain itself
62
+ @zone_additional_ips.each do |ip|
63
+ rrs << [create_addr_rr_for_ip(ip), default_options]
64
+ end
65
+
66
+ # return A/AAAA RRs for the dyndns hostnames
67
+ db['hosts'].each do |hostname, ips|
68
+ ips.each do |ip|
69
+ rrs << [create_addr_rr_for_ip(ip), default_options.merge({name: hostname})]
70
+ end
71
+ end
72
+
73
+ # AXFR responses need to end with zone's SOA RR again
74
+ rrs << [soa_rr, default_options]
75
+
76
+ # point Async::DNS server thread's variable to this new RR array
77
+ @server.axfr_rrs = rrs
78
+
79
+ # only send DNS NOTIFY if there really was a change
80
+ if db.changed?
81
+ send_dns_notify
82
+ end
83
+ end
84
+ end
85
+
86
+ # converts into suitable parameter form for Async::DNS::Resolver or Async::DNS::Server
87
+ #
88
+ # @param endpoint_list [Array<String>]
89
+ # @return [Array{Array{Object}}]
90
+ def self.parse_endpoints(endpoint_list)
91
+ endpoint_list.map { |addr_string| addr_string.split('@') }
92
+ .map { |addr_parts| [addr_parts[0], addr_parts[1].to_i || 53] }
93
+ .map { |addr| [:tcp, :udp].map { |type| [type] + addr } }
94
+ .flatten(1)
95
+ end
96
+
97
+ private
98
+
99
+ # creates correct Resolv::DNS::Resource object for IP address type
100
+ #
101
+ # @param ip_string [String]
102
+ # @return [Resolv::DNS::Resource::IN::A,Resolv::DNS::Resource::IN::AAAA]
103
+ def create_addr_rr_for_ip(ip_string)
104
+ ip = IPAddr.new(ip_string).native
105
+
106
+ if ip.ipv6?
107
+ Resolv::DNS::Resource::IN::AAAA.new(ip.to_s)
108
+ else
109
+ Resolv::DNS::Resource::IN::A.new(ip.to_s)
110
+ end
111
+ end
112
+
113
+ # https://tools.ietf.org/html/rfc1996
114
+ #
115
+ # @return [void]
116
+ def send_dns_notify
117
+ Async::Reactor.run do
118
+ @notify_targets.each do |notify_target|
119
+ target = Async::DNS::Resolver.new(notify_target)
120
+
121
+ # assemble DNS NOTIFY message
122
+ request = Resolv::DNS::Message.new(SecureRandom.random_number(2**16))
123
+ request.opcode = Resolv::DNS::OpCode::Notify
124
+ request.add_question("#{@domain}.", Resolv::DNS::Resource::IN::SOA)
125
+
126
+ _response = target.dispatch_request(request)
127
+ end
128
+ end
129
+ end
130
+ end
131
+
132
+ class ZoneTransferServerHelper < Async::DNS::Server
133
+ attr_accessor :axfr_rrs
134
+
135
+ def initialize(endpoints, domain)
136
+ super(endpoints, logger: Dyndnsd.logger)
137
+ @domain = domain
138
+ end
139
+
140
+ # @param name [String]
141
+ # @param resource_class [Resolv::DNS::Resource]
142
+ # Since solargraph cannot parse this: param transaction [Async::DNS::Transaction]
143
+ # @return [void]
144
+ def process(name, resource_class, transaction)
145
+ if name != @domain || resource_class != Resolv::DNS::Resource::Generic::Type252_Class1
146
+ transaction.fail!(:NXDomain)
147
+ return
148
+ end
149
+
150
+ # https://tools.ietf.org/html/rfc5936
151
+ transaction.append_question!
152
+ @axfr_rrs.each do |rr|
153
+ transaction.add([rr[0]], rr[1])
154
+ end
155
+ end
156
+ end
157
+ end
158
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dyndnsd
4
- VERSION = '2.2.0'
4
+ VERSION = '3.1.0'
5
5
  end
metadata CHANGED
@@ -1,29 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dyndnsd
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Nicolai
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-06 00:00:00.000000000 Z
11
+ date: 2020-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: async-dns
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.2.0
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: jaeger-client
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: 0.10.0
33
+ version: 1.0.0
20
34
  type: :runtime
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: 0.10.0
40
+ version: 1.0.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: metriks
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +114,14 @@ dependencies:
100
114
  requirements:
101
115
  - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: 0.6.0
117
+ version: 0.7.0
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: 0.6.0
124
+ version: 0.7.0
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: rack-test
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -156,14 +170,14 @@ dependencies:
156
170
  requirements:
157
171
  - - "~>"
158
172
  - !ruby/object:Gem::Version
159
- version: 0.80.0
173
+ version: 0.89.0
160
174
  type: :development
161
175
  prerelease: false
162
176
  version_requirements: !ruby/object:Gem::Requirement
163
177
  requirements:
164
178
  - - "~>"
165
179
  - !ruby/object:Gem::Version
166
- version: 0.80.0
180
+ version: 0.89.0
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: solargraph
169
183
  requirement: !ruby/object:Gem::Requirement
@@ -193,7 +207,6 @@ files:
193
207
  - LICENSE
194
208
  - README.md
195
209
  - exe/dyndnsd
196
- - init.d/debian-6-dyndnsd
197
210
  - lib/dyndnsd.rb
198
211
  - lib/dyndnsd/database.rb
199
212
  - lib/dyndnsd/generator/bind.rb
@@ -202,6 +215,7 @@ files:
202
215
  - lib/dyndnsd/responder/rest_style.rb
203
216
  - lib/dyndnsd/textfile_reporter.rb
204
217
  - lib/dyndnsd/updater/command_with_bind_zone.rb
218
+ - lib/dyndnsd/updater/zone_transfer_server.rb
205
219
  - lib/dyndnsd/version.rb
206
220
  homepage: https://github.com/cmur2/dyndnsd
207
221
  licenses:
@@ -218,14 +232,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
218
232
  requirements:
219
233
  - - ">="
220
234
  - !ruby/object:Gem::Version
221
- version: '2.3'
235
+ version: '2.5'
222
236
  required_rubygems_version: !ruby/object:Gem::Requirement
223
237
  requirements:
224
238
  - - ">="
225
239
  - !ruby/object:Gem::Version
226
240
  version: '0'
227
241
  requirements: []
228
- rubygems_version: 3.0.6
242
+ rubygems_version: 3.1.2
229
243
  signing_key:
230
244
  specification_version: 4
231
245
  summary: dyndnsd.rb
@@ -1,43 +0,0 @@
1
- #! /bin/sh
2
- ### BEGIN INIT INFO
3
- # Provides: dyndnsd
4
- # Required-Start: $remote_fs $syslog
5
- # Required-Stop: $remote_fs $syslog
6
- # Default-Start: 2 3 4 5
7
- # Default-Stop: 0 1 6
8
- # Short-Description: Handle dyndnsd.rb gem
9
- ### END INIT INFO
10
-
11
- # using the system ruby's gem binaries directory
12
- DAEMON="/var/lib/gems/1.8/bin/dyndnsd"
13
-
14
- CONFIG_FILE="/opt/dyndnsd/config.yaml"
15
-
16
- DAEMON_OPTS="$CONFIG_FILE"
17
-
18
- test -x $DAEMON || exit 0
19
-
20
- . /lib/lsb/init-functions
21
-
22
- case "$1" in
23
- start)
24
- log_daemon_msg "Starting dyndnsd.rb" "dyndnsd"
25
- start-stop-daemon --start --quiet --oknodo --make-pidfile --pidfile "/var/run/dyndnsd.pid" --background --exec $DAEMON -- $DAEMON_OPTS
26
- log_end_msg $?
27
- ;;
28
- stop)
29
- log_daemon_msg "Stopping dyndnsd.rb" "dyndnsd"
30
- start-stop-daemon --stop --quiet --oknodo --pidfile "/var/run/dyndnsd.pid"
31
- log_end_msg $?
32
- ;;
33
- restart|force-reload)
34
- log_daemon_msg "Restarting dyndnsd.rb" "dyndnsd"
35
- start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile "/var/run/dyndsd.pid"
36
- start-stop-daemon --start --quiet --oknodo --make-pidfile --pidfile "/var/run/dyndnsd.pid" --background --exec $DAEMON -- $DAEMON_OPTS
37
- log_end_msg $?
38
- ;;
39
- *)
40
- log_action_msg "Usage: $0 {start|stop|restart|force-reload}"
41
- exit 2
42
- ;;
43
- esac