radd 1.5.2 → 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: 8ce6277f2c17ee82c7e873be185b142c0bf8cd4fcfe5faf7b6287360e9a5de77
4
- data.tar.gz: 9bcb6d8caa6fd25c73dd284ad556ec3be6071b38bca02adbe4b2a0ee24edf0b2
3
+ metadata.gz: 89f434326187f7616eb3f1c4c90b97ae0f509276885afa93f66ebdb45be2032c
4
+ data.tar.gz: 501b58d548f23284c3df02301ee278beb5011e3450fe731e701570f2f7b06f9c
5
5
  SHA512:
6
- metadata.gz: 529ba3c5d7129dc4ba5e783c75e82617ee095578558e7dc23c54ea1aa7439e9c02a5410bf7e40257dcaeff2162e59cc0ee055c9626d11a51ce09b6557124f744
7
- data.tar.gz: d102da674aea8d27f70cca080c197ac5646e3786327d37e2ed25ab0e216eed128b5b2d2ba9bd5b5987cffce2eae50801eeb58037be1ed8ef9dc8468a1da460d6
6
+ metadata.gz: b80b94d5fb7e63a0ffa02e9f9d67a443f548e06adf9b22244543fc4579467fbd231579a335f106cc6e7e7091ef85a4a73cd2e505f7ffe917c719762a350f81d9
7
+ data.tar.gz: 1cac04ba43cfa863044ba3b5e3c37f8d718369cb753a65dc88ac1e64adf8f9eedbeb8ab02136d56e59758c1a9480dbdd00ea43668733e484f524a803419886c5
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, Radd.origin].include?(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/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Radd
2
- VERSION = '1.5.2'
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.2
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthias Grosser
@@ -206,17 +206,12 @@ files:
206
206
  - lib/radd/cli.rb
207
207
  - lib/radd/config.rb
208
208
  - lib/radd/db.rb
209
- - lib/radd/dns.rb
210
- - lib/radd/dns_service.rb
211
209
  - lib/radd/errors.rb
212
- - lib/radd/http.rb
213
- - lib/radd/http_service.rb
214
210
  - lib/radd/ip.rb
215
211
  - lib/radd/middleware.rb
216
212
  - lib/radd/nameserver.rb
217
213
  - lib/radd/record.rb
218
214
  - lib/radd/schema.rb
219
- - lib/radd/tasks.rb
220
215
  - lib/radd/update.rb
221
216
  - lib/radd/version.rb
222
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