radd 1.3.0 → 1.4.1

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: aff371d343007b06413d5aeffa546a25824130d0ef8052b1ae7d300f97b665c7
4
- data.tar.gz: cb860484d7cb6ad5531be423bffbdabecd96bdc5e9544fe97489cd747a6237f5
3
+ metadata.gz: f979c2d87f1f25eb5c780da9d4d5ecb0543c299bee5d7e73a046825357759d1f
4
+ data.tar.gz: 8f92e1c1018b4a5ea9f86e138f3a439e4bd76eaadbfe4ab78a91ecc15d12b33f
5
5
  SHA512:
6
- metadata.gz: 3eef89dbaad0dfc736443237743a9123452df584cb3c60f1f09a8fe83efe13ba70de21bd1c4ee7fd0e9043477250ed03d08e2a3652cbf4db39f47ac9202b0a36
7
- data.tar.gz: 5c822bafd10f4fde3714a7eea8051bce9e34197f261ed6eeb8d452ec1a87c0688cd4b6a48ddf1fffdecfc1e71f5976ef850f699bbd7a064d98df07fdd939be53
6
+ metadata.gz: b7e11faf5690621e6027d2356c7ee403488fabf29caa0d5007a2e8d6b8ed8319f3b3ce8373e2f0f97905516f0eea9c263f824da406b067ab188ce0c8936d9fdf
7
+ data.tar.gz: 64f91eb6deccbaf8932960b620f65b1f87807c19d7a6492e44a8fa836608cfefe226b25ffde0d3bdec69434742e38bd3e5086bd1f251f11e5c17e451aa2e449f
data/README.md CHANGED
@@ -1,12 +1,39 @@
1
- radd
2
- ====
1
+ # radd
3
2
 
4
3
  Minimal dynamic DNS service
5
4
 
6
- rake radd:db:create
7
5
 
8
- rake radd:add
6
+ ## Installation
9
7
 
10
- rake radd:list
8
+ ```
9
+ gem install radd
10
+ ```
11
11
 
12
- rake radd:delete
12
+ ## Configuration
13
+
14
+ ```yaml
15
+ # radd.yml
16
+ ip: 10.1.2.3
17
+ http: 127.0.0.1:3000
18
+ dns: 0.0.0.0:53
19
+ domain: example.com
20
+ mname: ns.example.com
21
+ rname: hostmaster.example.com
22
+ db: radd.sqlite3
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ```
28
+ radd COMMAND [--config FILE]
29
+ ```
30
+
31
+ You must specify one of the following commands:
32
+
33
+ ```
34
+ setup Create the database
35
+ add Add new record
36
+ delete Delete record
37
+ list List available records
38
+ start Run the server
39
+ ```
data/lib/radd/cli.rb CHANGED
@@ -21,11 +21,17 @@ module Radd::Cli
21
21
 
22
22
  def run
23
23
  command = ARGV.shift
24
- unless COMMANDS.include?(command)
24
+ if COMMANDS.include?(command)
25
+ send(command)
26
+ elsif command.nil?
27
+ help
28
+ exit 1
29
+ elsif '--help' == command
30
+ help
31
+ else
25
32
  puts "Unknown command #{command}"
26
- exit(1)
33
+ exit 1
27
34
  end
28
- send(command)
29
35
  end
30
36
 
31
37
  def help
@@ -37,6 +43,7 @@ module Radd::Cli
37
43
 
38
44
  setup Create the database
39
45
  add Add new record
46
+ delete Delete record
40
47
  list List available records
41
48
  start Run the server
42
49
 
data/lib/radd/config.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  module Radd
2
2
 
3
3
  class << self
4
- attr_reader :domain, :ip, :db, :http_host, :http_port, :dns_host, :dns_port, :ttl
4
+ attr_reader :domain, :ip, :db, :http_host, :http_port, :dns_host, :dns_port, :ttl,
5
+ :mname, :rname
5
6
 
6
7
  def configure!(file, skip_models: false, skip_db: false)
7
8
  file_path = Pathname.new(file || 'radd.yml')
@@ -20,6 +21,9 @@ module Radd
20
21
  @dns_port = uri.port || 53
21
22
  raise ConfigurationError, 'invalid TTL' if config['ttl'] && config['ttl'] < 1
22
23
  @ttl = config['ttl'] || 300
24
+ raise ConfigurationError, 'master name missing' unless config['mname']
25
+ @mname = config['mname'].split('.').freeze
26
+ @rname = encode_email(config['rname'] || "hostmaster@#{domain}").freeze
23
27
  db_path = Pathname.new(config['db'] || 'radd.sqlite3')
24
28
  db_path = Radd.root + db_path unless db_path.absolute?
25
29
  @db = db_path
@@ -35,6 +39,13 @@ module Radd
35
39
  def valid_ip?(ip)
36
40
  !!(ip && ip.match(Resolv::IPv4::Regex))
37
41
  end
42
+
43
+ private
44
+
45
+ def encode_email(email)
46
+ addr, domain = email.split('@')
47
+ [addr, *domain.split('.')]
48
+ end
38
49
  end
39
-
50
+
40
51
  end
@@ -1,18 +1,21 @@
1
- class Radd::Nameserver < Async::DNS::Server
2
- def initialize
3
- super(Async::DNS::Endpoint.for(Radd.dns_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)
1
+ module Radd
2
+ class Nameserver < Async::DNS::Server
3
+
4
+ def initialize
5
+ super(Async::DNS::Endpoint.for(Radd.dns_host, port: Radd.dns_port))
6
+ end
7
+
8
+ def process(name, resource_class, transaction)
9
+ name = name.downcase
10
+ # NOTE: do not use case..when, as resource classes are not identical
11
+ if Resolv::DNS::Resource::IN::A == resource_class
12
+ ip = Radd.domain == name ? Radd.ip : Radd.query(name)
13
+ return transaction.respond!(ip, ttl: Radd.ttl) if ip
14
+ elsif resource_class <= Resolv::DNS::Resource::SOA && Radd.domain == name
15
+ # mname, rname, serial, refresh, retry_, expire, minimum
16
+ return transaction.respond!(Radd.mname, Radd.rname, Radd.serial, 10800, 1800, 604800, 1800)
13
17
  end
18
+ transaction.fail!(:NXDomain)
14
19
  end
15
- return transaction.respond!(ip, ttl: Radd.ttl) if ip
16
- transaction.fail!(:NXDomain)
17
20
  end
18
21
  end
data/lib/radd/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Radd
2
- VERSION = '1.3.0'
2
+ VERSION = '1.4.1'
3
3
  end
data/lib/radd.rb CHANGED
@@ -52,6 +52,10 @@ module Radd
52
52
  record.ip
53
53
  end
54
54
 
55
+ def serial
56
+ Radd.db&.stat&.mtime.to_i
57
+ end
58
+
55
59
  private
56
60
 
57
61
  def config
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.3.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthias Grosser