radd 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 84f6d38880accb181b5d1976dd49f1492e45cbd69a5e7c93ca3727b131a00698
4
- data.tar.gz: 6fcd72a269a6f52b99810912620ba7a243680827c01b43e9579efbeb4962d4d2
3
+ metadata.gz: 89f434326187f7616eb3f1c4c90b97ae0f509276885afa93f66ebdb45be2032c
4
+ data.tar.gz: 501b58d548f23284c3df02301ee278beb5011e3450fe731e701570f2f7b06f9c
5
5
  SHA512:
6
- metadata.gz: 7dac0c7f9dd9b61b1a28d47276be853867cb3055d0720bffcfe41028dae4a29d2f4b7ca930c35756206de76aaedcf4680b42c5af3e601491b3179a2660168a1e
7
- data.tar.gz: 41db151db1e4d9cdd156a71ea4ccb1e3abb16b63659a974bc98a35d48fb38269f1ad8308234a0b4b023634ee7fe457857ead1fdfeb1935b9661a968ff07dc605
6
+ metadata.gz: b80b94d5fb7e63a0ffa02e9f9d67a443f548e06adf9b22244543fc4579467fbd231579a335f106cc6e7e7091ef85a4a73cd2e505f7ffe917c719762a350f81d9
7
+ data.tar.gz: 1cac04ba43cfa863044ba3b5e3c37f8d718369cb753a65dc88ac1e64adf8f9eedbeb8ab02136d56e59758c1a9480dbdd00ea43668733e484f524a803419886c5
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/radd.svg)](http://badge.fury.io/rb/radd)
2
+ [![build](https://github.com/mtgrosser/radd/actions/workflows/build.yml/badge.svg)](https://github.com/mtgrosser/radd/actions/workflows/build.yml)
2
3
 
3
4
  # radd
4
5
 
@@ -15,7 +16,7 @@ gem install radd
15
16
 
16
17
  ```yaml
17
18
  # radd.yml
18
- origin: domains.example.com
19
+ origin: ddns.example.com
19
20
  ip: 10.1.2.3
20
21
  mname: ns.example.com
21
22
  rname: hostmaster.example.com
data/lib/radd/config.rb CHANGED
@@ -10,7 +10,7 @@ module Radd
10
10
  raise ConfigurationError, "could not open config file #{file_path}" unless file_path.file?
11
11
  config = YAML.load(file_path.read)
12
12
  raise ConfigurationError, 'origin missing' unless config['origin']
13
- @origin = config['origin']
13
+ @origin = Resolv::DNS::Name.create(config['origin'])
14
14
  raise ConfigurationError, 'invalid IP' unless Radd.valid_ip?(config['ip'])
15
15
  @ip = config['ip']
16
16
  uri = URI.parse("http://#{config['http']}")
@@ -6,18 +6,32 @@ module Radd
6
6
  end
7
7
 
8
8
  def process(name, resource_class, transaction)
9
- name = name.downcase
9
+ name = Resolv::DNS::Name.create(name.downcase)
10
10
  # NOTE: do not use case..when, as resource classes are not identical
11
11
  if Resolv::DNS::Resource::IN::A == resource_class
12
- ip = Radd.mname == name ? Radd.ip : Radd.query(name)
13
- return transaction.respond!(ip, ttl: Radd.ttl) if ip
12
+ if Radd.mname == name || Radd.origin == name
13
+ return respond_a(transaction, Radd.ip)
14
+ elsif name.subdomain_of?(Radd.origin)
15
+ return respond_a(transaction, Radd.query(name))
16
+ end
14
17
  elsif resource_class <= Resolv::DNS::Resource::SOA && Radd.origin == name
15
18
  # mname, rname, serial, refresh, retry_, expire, minimum
16
19
  return transaction.respond!(Radd.mname, Radd.rname, Radd.serial, 10800, 1800, 604800, 1800)
17
20
  elsif resource_class <= Resolv::DNS::Resource::NS && Radd.origin == name
18
21
  return transaction.respond!(Radd.mname)
19
22
  end
20
- transaction.fail!(:NXDomain)
23
+ transaction.fail!(:Refused)
21
24
  end
25
+
26
+ private
27
+
28
+ def respond_a(transaction, ip)
29
+ if ip
30
+ transaction.respond!(ip, ttl: Radd.ttl)
31
+ else
32
+ transaction.fail!(:NXDomain)
33
+ end
34
+ end
35
+
22
36
  end
23
37
  end
data/lib/radd/update.rb CHANGED
@@ -32,7 +32,7 @@ module Radd
32
32
  record.ip = ip
33
33
  record.save
34
34
  Radd.logger.info "Updated record #{record.name} to #{ip} from #{remote_ip}"
35
- [200, {'Content-Type' => 'text/plain'}, ["OK #{ip}"]]
35
+ [200, {'Content-Type' => 'text/plain'}, ["OK #{ip}\n"]]
36
36
  rescue RaddError => boom
37
37
  status = case boom
38
38
  when InvalidRequest, Sequel::ValidationFailed then 422
data/lib/radd/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Radd
2
- VERSION = '1.5.0'
2
+ VERSION = '1.6.0'
3
3
  end
data/lib/radd.rb CHANGED
@@ -63,7 +63,7 @@ module Radd
63
63
  end
64
64
 
65
65
  def fqdn2name(fqdn)
66
- if match = fqdn.downcase.match(/\A([a-z0-9-]{1,63})\.#{Regexp.escape(origin)}\z/)
66
+ if match = fqdn.to_s.downcase.match(/\A([a-z0-9-]{1,63})\.#{Regexp.escape(origin.to_s)}\z/)
67
67
  match.captures[0]
68
68
  end
69
69
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radd
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthias Grosser
@@ -177,6 +177,20 @@ dependencies:
177
177
  - - ">="
178
178
  - !ruby/object:Gem::Version
179
179
  version: '0'
180
+ - !ruby/object:Gem::Dependency
181
+ name: minitest
182
+ requirement: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - "~>"
185
+ - !ruby/object:Gem::Version
186
+ version: '5.0'
187
+ type: :development
188
+ prerelease: false
189
+ version_requirements: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - "~>"
192
+ - !ruby/object:Gem::Version
193
+ version: '5.0'
180
194
  description: Minimal dynamic DNS service
181
195
  email: mtgrosser@gmx.net
182
196
  executables:
@@ -192,17 +206,12 @@ files:
192
206
  - lib/radd/cli.rb
193
207
  - lib/radd/config.rb
194
208
  - lib/radd/db.rb
195
- - lib/radd/dns.rb
196
- - lib/radd/dns_service.rb
197
209
  - lib/radd/errors.rb
198
- - lib/radd/http.rb
199
- - lib/radd/http_service.rb
200
210
  - lib/radd/ip.rb
201
211
  - lib/radd/middleware.rb
202
212
  - lib/radd/nameserver.rb
203
213
  - lib/radd/record.rb
204
214
  - lib/radd/schema.rb
205
- - lib/radd/tasks.rb
206
215
  - lib/radd/update.rb
207
216
  - lib/radd/version.rb
208
217
  - lib/radd/webserver.rb
data/lib/radd/dns.rb DELETED
@@ -1,18 +0,0 @@
1
- class Radd::DNS < Async::DNS::Server
2
- def initialize
3
- super(Async::DNS::Endpoint.for(Radd.host, port: Radd.dns_port))
4
- end
5
-
6
- def process(name, resource_class, transaction)
7
- name = name.downcase
8
- if Resolv::DNS::Resource::IN::A == resource_class
9
- if Radd.domain == name
10
- ip = Radd.ip
11
- else
12
- ip = Radd.query(name)
13
- end
14
- end
15
- return transaction.respond!(ip, ttl: 300) if ip
16
- transaction.fail!(:NXDomain)
17
- end
18
- end
@@ -1,12 +0,0 @@
1
- class Radd::DNSService < Async::Service::GenericService
2
- def setup(container)
3
- super
4
-
5
- container.run(count: 1, restart: false) do |instance|
6
- instance.ready!
7
- puts "DNS service starting..."
8
-
9
- Radd::DNS.new.run
10
- end
11
- end
12
- end
data/lib/radd/http.rb DELETED
@@ -1,7 +0,0 @@
1
- class Radd::HTTP < Async::HTTP::Server
2
- def initialize
3
- endpoint = Async::HTTP::Endpoint.parse("http://#{Radd.host}:#{Radd.http_port}")
4
- middleware = Protocol::Rack::Adapter.new(Radd::App)
5
- super(middleware, endpoint)
6
- end
7
- end
@@ -1,12 +0,0 @@
1
- class Radd::HTTPService < Async::Service::GenericService
2
- def setup(container)
3
- super
4
-
5
- container.run(count: 1, restart: false) do |instance|
6
- instance.ready!
7
- puts "HTTP service starting..."
8
-
9
- Radd::HTTP.new.run
10
- end
11
- end
12
- end
data/lib/radd/tasks.rb DELETED
@@ -1,39 +0,0 @@
1
- namespace :radd do
2
- task :config do
3
- Radd::Cli.load_config
4
- end
5
-
6
- namespace :db do
7
- desc 'Create database'
8
- task create: :config do
9
- load './db/schema.rb'
10
- end
11
- end
12
-
13
- desc 'Add record'
14
- task add: :config do
15
- print "Enter name: "
16
- name = STDIN.gets.chomp
17
- print "Password: "
18
- password = STDIN.gets.chomp
19
- print "Re-type password: "
20
- password_confirmation = STDIN.gets.chomp
21
- raise "Password mismatch!" unless password == password_confirmation
22
- record = Radd::Record.new(password: password)
23
- record.name = name
24
- record.save
25
- puts "Added record '#{name}'\n"
26
- end
27
-
28
- desc 'List all records'
29
- task list: :config do
30
- puts
31
- records = Radd::Record.all
32
- tab = [records.map(&:name).map(&:size).max, 24].compact.max
33
- records.each do |record|
34
- puts "#{record.name.ljust(tab)} #{record.ip.to_s.ljust(15)} #{record.updated_at || 'never updated'}\n"
35
- end
36
- puts
37
- end
38
-
39
- end