dns_one 0.4.2 → 0.4.3

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
  SHA1:
3
- metadata.gz: 1cf333022498bfdecb773415f6a7c3b370349573
4
- data.tar.gz: 732d0765d3be07b1f9056e2ab17cfa4b41636b63
3
+ metadata.gz: 218dc35c2add52a6bc28230581cf23c36d9ddf3f
4
+ data.tar.gz: 1de9365403cb1cb20d0ae24858dfbfc06299fd05
5
5
  SHA512:
6
- metadata.gz: ce64e58c10cc148b607493fa761da7290487992f6439168a1d8703d686a74e3afd0681fc5fb47d40dfecc40fc903de0abd6e33c5e24ff35a26fc44fe52a8b684
7
- data.tar.gz: 2f3a2c80f77715a02a39a29b6c034703c6dfbad4edd715a68c9741204dbea2adba53b7aad7300f0f59a1349757098b5f9c31da2b6df15ba035db5696064fc6d3
6
+ metadata.gz: 6e5e40f70701eb9b81e829d46a40d60492b83cf35d918c4a9ce02ea9d63638b5581bf6b88b8229ca1ed7b459a7b1657ead42f34699af88c1107b56be516fe75f
7
+ data.tar.gz: 13485f2609f753e5ce53c6d78e33551e0e8fdda428edf577b15f277259cbdae469779d1176c9d18f3851993cc024b64361e39896cd7a0e190d76853fa0cf4ae4
data/README.md CHANGED
@@ -34,6 +34,12 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
34
34
 
35
35
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
36
36
 
37
+ ## Compatibility
38
+
39
+ IPV6 error in Ruby 2.3.0:
40
+
41
+ variables address, a1 and a2 should`nt be frozen in 2.3.0/lib/ruby/2.3.0/resolv.rb
42
+
37
43
  ## Contributing
38
44
 
39
45
  Bug reports and pull requests are welcome on GitHub at https://github.com/tomlobato/dns_one.
@@ -1,10 +1,14 @@
1
+ # Core
2
+ require 'syslog'
3
+ require 'syslog/logger'
1
4
 
5
+ # Gems
2
6
  require 'rubydns'
3
7
  require 'active_record'
4
8
  require 'yaml'
5
9
  require 'rexec'
6
- require 'syslog'
7
- require 'syslog/logger'
10
+
11
+ # DnsOne
8
12
 
9
13
  require "dns_one/core_extensions"
10
14
  require "dns_one/log"
@@ -36,7 +40,7 @@ module DnsOne; class DnsOne
36
40
 
37
41
  # check_root
38
42
  begin
39
- Dir.chdir WORK_DIR
43
+ Dir.chdir (@conf.config[:work_dir] || WORK_DIR)
40
44
  rescue => e
41
45
  Log.w "Cannot change working dir to #{WORK_DIR}. Will continue in #{Dir.pwd}."
42
46
  end
@@ -54,6 +58,8 @@ module DnsOne; class DnsOne
54
58
  conf = YAML.load_file conf_file
55
59
  conf.deep_symbolize_keys!
56
60
 
61
+ conf[:config] ||= {}
62
+
57
63
  OpenStruct.new conf
58
64
  end
59
65
 
@@ -1,4 +1,4 @@
1
- module Backend; class DB
1
+ module Backend; class BackendDB
2
2
  def initialize conf
3
3
  @query = conf.delete :query
4
4
  @db_conf = conf
@@ -32,6 +32,10 @@ module Backend; class DB
32
32
  record_values&.first
33
33
  end
34
34
 
35
+ def allow_cache
36
+ true
37
+ end
38
+
35
39
  private
36
40
 
37
41
  def build_query dom_name
@@ -1,22 +1,31 @@
1
1
 
2
- module Backend; class File
2
+ module Backend; class BackendFile
3
3
  def initialize file
4
4
  @domain_map = {}
5
- load_file file
5
+ load file
6
6
  end
7
7
 
8
8
  def find dom_name
9
9
  @domain_map[dom_name.downcase]
10
10
  end
11
11
 
12
+ def allow_cache
13
+ false
14
+ end
15
+
12
16
  private
13
17
 
14
- def load
18
+ def load file
15
19
  File.open(file).each_line do |line|
20
+ line.strip!
16
21
  domain_name, rec_set_name = line
17
- .strip
18
22
  .split(/[,\s]+/)
19
- @domain_map[domain_name.strip.downcase] = rec_set_name&.strip || ''
23
+ if domain_name and not domain_name.empty?
24
+ @domain_map[domain_name.strip.downcase] = rec_set_name&.strip || ''
25
+ else
26
+ Log.w "Ignoring #{file} line: #{line}"
27
+ end
20
28
  end
21
29
  end
30
+
22
31
  end; end
@@ -1,3 +1,3 @@
1
1
  module DnsOne
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
@@ -29,6 +29,10 @@ module DnsOne; class ZoneSearch
29
29
  Log.d "record set name #{ rec_set_name ? 'found' : 'not_found' }"
30
30
  rec_set_name or return
31
31
 
32
+ if rec_set_name == ''
33
+ rec_set_name = @conf.record_sets.keys.first.to_s
34
+ end
35
+
32
36
  rec_set = @conf.record_sets[rec_set_name.to_sym]
33
37
  Log.d "record set #{ rec_set ? 'found' : 'not found' }"
34
38
  rec_set or return
@@ -55,16 +59,17 @@ module DnsOne; class ZoneSearch
55
59
  def set_backend
56
60
  if file = @conf.backend[:file]
57
61
  unless File.exists? file
58
- Util.die "Configuration file #{file} not found."
62
+ Util.die "Domain list file #{file} not found."
59
63
  end
60
- Backend::File.new file
64
+ Backend::BackendFile.new file
61
65
  else
62
- Backend::DB.new @conf.backend
66
+ Backend::BackendDB.new @conf.backend
63
67
  end
64
68
  end
65
69
 
66
70
  def find_record_set dom_name
67
- use_cache = dom_name !~ /^NC/
71
+ use_cache = true
72
+ use_cache = false if dom_name =~ /^NC/
68
73
  dom_name.sub! /^NC/, ''
69
74
 
70
75
  dom_name.downcase!
@@ -75,12 +80,16 @@ module DnsOne; class ZoneSearch
75
80
  dom_name.sub! @ignore_subdomains_re, ''
76
81
  end
77
82
 
78
- if use_cache and rec_set = @cache.find(dom_name)
83
+ enabled_cache = use_cache && @backend.allow_cache
84
+
85
+ if enabled_cache and rec_set = @cache.find(dom_name)
79
86
  Log.d "found in cache"
80
87
  rec_set
81
88
  else
82
89
  if rec_set = @backend.find(dom_name)
83
- @cache.add dom_name, rec_set if use_cache
90
+ if enabled_cache
91
+ @cache.add dom_name, rec_set
92
+ end
84
93
  rec_set
85
94
  end
86
95
  end
@@ -1,8 +1,8 @@
1
1
 
2
2
  config:
3
- run_as: dnsserver # required (adduser dnsserver)
4
- # cache_max: 100000 # optional, defaults to 10000
5
- ignore_subdomains: www en it es pt ru fr at
3
+ run_as: dnsserver # optional, but highly recommended! adduser --system dnsserver
4
+ ignore_subdomains: www en it es pt ru fr at # optional
5
+ # cache_max: 100000 # optional, defaults to 10000
6
6
 
7
7
  backend:
8
8
  ##############
@@ -12,14 +12,17 @@ backend:
12
12
  username: db_user
13
13
  password: db_pass
14
14
  pool: 20
15
+
15
16
  adapter: postgresql
16
17
  host: my-pg-db.com
17
18
  port: 5432
19
+
18
20
  # adapter: mysql2
19
21
  # host: my-mysql-db.com
20
22
  # port: 3306
21
23
  # # socket: /var/run/mysqld/mysqld.sock"
22
- query: SELECT 'set1' FROM domains WHERE url = $domain LIMIT 1
24
+
25
+ query: SELECT 'my_set_1' FROM domains WHERE url = $domain LIMIT 1
23
26
  # query: SELECT domains.record_set FROM domains WHERE domain_name = $domain LIMIT 1
24
27
 
25
28
  # or...
@@ -28,9 +31,9 @@ backend:
28
31
  # File backend #
29
32
  ################
30
33
 
31
- # file: /etc/dns_one/domain.csv
34
+ # file: /etc/dns_one/domains.csv
32
35
 
33
- # domain.csv example (set is optional, if missing the first record_set will be used)):
36
+ # domains.csv example (set is optional, if missing the first record_set will be used)):
34
37
  # mydomain.com set1
35
38
  # myotherdomain.com
36
39
  # myotherdomain2.com
@@ -38,7 +41,7 @@ backend:
38
41
 
39
42
  record_sets:
40
43
 
41
- set1:
44
+ my_set_1:
42
45
  A: 123.234.345.456
43
46
  AAAA: 1234:3c00::f03c:91fa:fec2:15df
44
47
  NS:
@@ -54,7 +57,7 @@ record_sets:
54
57
  - 200 # minimum The minimum number of seconds to be used for TTL values in RRs.
55
58
  # More about SOA fields on http://ruby-doc.org/stdlib-2.0.0/libdoc/resolv/rdoc/Resolv/DNS/Resource/SOA.html
56
59
 
57
- set2:
60
+ my_other_set:
58
61
  A: 32.34.54.56
59
62
  AAAA: 9034:3c00::f03c:91fb:fec2:15d0
60
63
  NS:
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dns_one
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Lobato
@@ -166,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
166
  version: '0'
167
167
  requirements: []
168
168
  rubyforge_project:
169
- rubygems_version: 2.5.1
169
+ rubygems_version: 2.5.2
170
170
  signing_key:
171
171
  specification_version: 4
172
172
  summary: DNS server for many zones sharing only one or few records, written in Ruby.