dns_one 0.4.23 → 0.4.24

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
  SHA1:
3
- metadata.gz: d5cb35b5104c43ec13d3da598213eec62d8fa2d5
4
- data.tar.gz: d332ea5cc00a4aa2cc313203e013b1651147c25a
3
+ metadata.gz: 77fd667f7117637e11933cd243928f1a0642220a
4
+ data.tar.gz: fcc9de0cf0843db0f7d76560bedabea8e5e13576
5
5
  SHA512:
6
- metadata.gz: e780b6cb698f972161400c5b2a28f73674739831fb6cd11e986686380335f9bcb317bfc4921cef7fdb63cc1b2ca80efe8fd51ededd0769c2c6f9f020a7f9f622
7
- data.tar.gz: e6fa0be1ecf1cd19888074459b5f890061b7a8f78a7b45093e249d1cc783116ee5be40663463b35a67f061518fcaddd288ed5ae3d02653c54cd846f959a8fdf6
6
+ metadata.gz: f29ab0a236819c202ec1eec373fc24c3e7e4ddc49f06aa9f87a2600f056200b5721ed7fb1b9904cebe811beac0ad3c1664f0b9854b3a34adfc49087937798597
7
+ data.tar.gz: 22a61d2f79b2b1d89a1152e21ebe3f2af10b7367f22a2887670d6d0d323f9526ecdf45e08aacc92e887290c49184bd87157fbf85e53521fbbb04162a728aba22
data/README.md CHANGED
@@ -6,9 +6,9 @@
6
6
 
7
7
  By [Bettercall.io](https://bettercall.io/).
8
8
 
9
- Instead having a complex data schema to assign record sets to individual DNS zones, dns_one assigns one or few record to many zones.
9
+ Instead having a complex data schema to assign record sets to DNS zones, dns_one assigns one or a few record sets to many zones.
10
10
 
11
- Configure your zones in YML files and fetch your domains from a database or YML backend.
11
+ Configure your record sets in YML files and fetch your domains from a database or YML backend.
12
12
 
13
13
  ## Installation
14
14
 
data/dns_one.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["tomlobato@gmail.com"]
11
11
 
12
12
  spec.summary = %q{DNS server for many zones sharing only one or few records, written in Ruby.}
13
- spec.description = %q{Instead having a complex data schema to assign record sets to individual DNS zones, dns_one assigns one or few record to many zones. Configure your zones in YML files and fetch your domains from a database or YML backend.}
13
+ spec.description = %q{Instead having a complex data schema to assign record sets to DNS zones, dns_one assigns one or a few record sets to many zones. Configure your record sets in YML files and fetch your domains from a database or YML backend.}
14
14
  spec.homepage = "https://tomlobato.github.io/dns_one/"
15
15
  spec.license = "MIT"
16
16
 
@@ -1,4 +1,6 @@
1
- module Backend; class BackendDB
1
+
2
+ module DnsOne; module Backend; class DB
3
+
2
4
  def initialize conf
3
5
  @query = conf.delete :query
4
6
  @conf = conf
@@ -18,13 +20,13 @@ module Backend; class BackendDB
18
20
  end
19
21
 
20
22
  rescue ActiveRecord::StatementInvalid => e
21
- Log.e "Query error. Trying to reconnect. Details:\n#{e.desc}"
23
+ Log.e "SQL query error. Trying to reconnect #{tries}. Details:\n#{e.desc}"
22
24
  # http://geoff.evason.name/2015/01/18/postgres-ssl-connection-has-been-closed-unexpectedly
23
25
  ActiveRecord::Base.connection.reconnect!
24
26
  find dom_name, (tries+1)
25
27
 
26
28
  rescue => e
27
- Log.exc e
29
+ Log.e "SQL query error. Details:\n#{e.desc}"
28
30
  end
29
31
 
30
32
  first_record = res&.first
@@ -68,4 +70,4 @@ module Backend; class BackendDB
68
70
  end
69
71
  end
70
72
 
71
- end; end
73
+ end; end; end
@@ -1,5 +1,6 @@
1
1
 
2
- module Backend; class BackendFile
2
+ module DnsOne; module Backend; class File
3
+
3
4
  def initialize file
4
5
  @domain_map = {}
5
6
  load file
@@ -16,7 +17,7 @@ module Backend; class BackendFile
16
17
  private
17
18
 
18
19
  def load file
19
- File.open(file).each_line do |line|
20
+ ::File.open(file).each_line do |line|
20
21
  line.strip!
21
22
  domain_name, rec_set_name = line
22
23
  .split(/[,\s]+/)
@@ -28,4 +29,4 @@ module Backend; class BackendFile
28
29
  end
29
30
  end
30
31
 
31
- end; end
32
+ end; end; end
data/lib/dns_one/cli.rb CHANGED
@@ -5,6 +5,8 @@ require "dns_one/setup"
5
5
 
6
6
  class DnsOne::CLI < Thor
7
7
 
8
+ default_task :run_srv
9
+
8
10
  # RUN
9
11
 
10
12
  desc "run", "run server"
@@ -12,9 +14,12 @@ class DnsOne::CLI < Thor
12
14
  option :log
13
15
  option :work_dir
14
16
  def run_srv
15
- DnsOne::DnsOne.new(conf_file: options[:conf], log_file: options[:log], work_dir: options[:work_dir]).start
17
+ DnsOne::DnsOne.new(
18
+ conf_file: options[:conf],
19
+ log_file: options[:log],
20
+ work_dir: options[:work_dir]
21
+ ).start
16
22
  end
17
- default_task :run_srv
18
23
 
19
24
  # INSTALL
20
25
 
@@ -0,0 +1,5 @@
1
+ class Hash
2
+ def symbolize_keys
3
+ each_with_object({}) { |(k, v), h| h[k.to_sym] = v.is_a?(Hash) ? v.symbolize_keys : v }
4
+ end
5
+ end
@@ -1,5 +1,7 @@
1
1
 
2
- module DnsOne; class Server # < RExec::Daemon::Base
2
+ require "dns_one/zone_search"
3
+
4
+ module DnsOne; class Server
3
5
 
4
6
  DEFAULT_RUN_AS = "dnsone"
5
7
 
data/lib/dns_one/setup.rb CHANGED
@@ -71,7 +71,7 @@ module DnsOne; class Setup
71
71
  puts "Now:"
72
72
  puts "1) Edit #{DnsOne::DEFAULT_CONF_FILE}. You can run 'ruby -Ilib/ exe/dns_one --conf util/dev_conf.yml --log=/dev/stdout' to test and adjust your configuration."
73
73
  puts "2) After configure run 'dns_one start'."
74
- puts "See startup or logs with 'tail -f /var/log/syslog'"
74
+ puts "See startup logs with 'tail -f /var/log/syslog'"
75
75
  puts "See run logs with 'tail -f #{DnsOne::DEFAULT_LOG_FILE}'"
76
76
  end
77
77
 
@@ -1,3 +1,3 @@
1
1
  module DnsOne
2
- VERSION = "0.4.23"
2
+ VERSION = "0.4.24"
3
3
  end
@@ -1,4 +1,8 @@
1
1
 
2
+ require "dns_one/cache"
3
+ require 'dns_one/backend/file'
4
+ require 'dns_one/backend/db'
5
+
2
6
  module DnsOne; class ZoneSearch
3
7
  include Singleton
4
8
 
@@ -26,7 +30,7 @@ module DnsOne; class ZoneSearch
26
30
  records = []
27
31
 
28
32
  rec_set_name = find_record_set dom_name
29
- Log.d "domain #{ rec_set_name ? 'found' : 'not found' }"
33
+ Log.d "domain #{ rec_set_name ? "found, rec_set_name = '#{rec_set_name}'" : 'not found' }"
30
34
  return unless rec_set_name
31
35
 
32
36
  # use first record set if rec_set_name == ''
@@ -71,12 +75,12 @@ module DnsOne; class ZoneSearch
71
75
 
72
76
  def set_backend
73
77
  if file = @conf[:backend][:file]
74
- unless File.exists? file
78
+ unless ::File.exists? file
75
79
  Util.die "Domain list file #{file} not found."
76
80
  end
77
- Backend::BackendFile.new file
81
+ Backend::File.new file
78
82
  else
79
- Backend::BackendDB.new @conf[:backend]
83
+ Backend::DB.new @conf[:backend]
80
84
  end
81
85
  end
82
86
 
data/lib/dns_one.rb CHANGED
@@ -2,108 +2,99 @@
2
2
  require 'syslog'
3
3
  require 'syslog/logger'
4
4
  require 'ostruct'
5
- require 'yaml'
6
5
  require 'singleton'
7
6
 
8
7
  # Gems
9
8
  require 'rexec'
10
9
  require 'rubydns'
10
+ require 'yaml'
11
11
 
12
12
  # DnsOne
13
13
 
14
14
  require "dns_one/core_ext/exception"
15
15
  require "dns_one/core_ext/string"
16
16
  require "dns_one/core_ext/blank"
17
+ require "dns_one/core_ext/hash"
17
18
 
18
19
  require "dns_one/log"
19
20
  require "dns_one/util"
20
-
21
21
  require "dns_one/server"
22
- require "dns_one/setup"
23
- require "dns_one/cache"
24
- require "dns_one/zone_search"
25
-
26
- require 'dns_one/backend/file'
27
- require 'dns_one/backend/db'
28
22
 
29
23
  module DnsOne; class DnsOne
30
24
 
31
- DEFAULT_LOG_FILE = "/var/log/dns_one.log"
32
- DEFAULT_CONF_FILE = '/etc/dns_one/conf.yml'
33
- WORK_DIR = "/var/local/dns_one"
34
-
35
- CONF_DIR = "/etc/dns_one"
36
- SYSLOG_NAME = 'dns_one'
37
-
38
- def initialize conf_file: nil, log_file: nil, work_dir: nil
39
- cmd_log_file = log_file
40
- log_file ||= DEFAULT_LOG_FILE
41
- Log.setup log_file, SYSLOG_NAME
42
-
43
- conf_file ||= DEFAULT_CONF_FILE
44
- @conf_all = parse_conf conf_file
45
- @conf = @conf_all.main
46
-
47
- work_dir ||= WORK_DIR
48
-
49
- # Redefine log file if set in conf file
50
- unless cmd_log_file
51
- if f = @conf[:log_file].presence
52
- unless Log.change_log_file f
53
- Log.w "Unable to change logfile to #{f}. Will continue with #{Log.log_file_desc}."
54
- end
55
- end
56
- end
57
-
58
- begin
59
- Dir.chdir work_dir
60
- rescue => e
61
- Log.w "Cannot change working dir to #{WORK_DIR}. Will continue in #{Dir.pwd}."
62
- end
63
- end
64
-
65
- def start
66
- Server.new(@conf_all.server, @conf_all.zone_search).run
67
- end
68
-
69
- private
70
- def symbolize_keys(hash)
71
- hash.each_with_object({}) { |(k, v), h| h[k.to_sym] = v.is_a?(Hash) ? symbolize_keys(v) : v }
72
- end
73
- def parse_conf conf_file
74
- check_conf_file conf_file
75
-
76
- conf = YAML.load_file conf_file
77
- conf = symbolize_keys conf
78
-
79
- OpenStruct.new(
80
- main: {
81
- work_dir: conf[:config][:work_dir],
82
- log_file: conf[:config][:log_file]
83
- },
84
- server: {
85
- run_as: conf[:config][:run_as]
86
- },
87
- zone_search: {
88
- ignore_subdomains: conf[:config][:ignore_subdomains],
89
- cache_max: conf[:config][:cache_max],
90
- record_sets: conf[:record_sets],
91
- backend: conf[:backend]
92
- }
93
- )
94
- end
95
-
96
- def check_conf_file conf_file
97
- unless File.readable? conf_file
98
- Util.die "Conf file #{conf_file} not found or unreadable. Aborting."
99
- end
100
-
101
- conf_stat = File.stat conf_file
102
-
103
- unless conf_stat.mode.to_s(8) =~ /0600$/
104
- Util.die "Conf file #{conf_file} must have mode 0600. Aborting."
105
- end
106
- end
25
+ DEFAULT_LOG_FILE = "/var/log/dns_one.log"
26
+ DEFAULT_CONF_FILE = '/etc/dns_one/conf.yml'
27
+ WORK_DIR = "/var/local/dns_one"
28
+ CONF_DIR = "/etc/dns_one"
29
+ SYSLOG_NAME = 'dns_one'
30
+
31
+ def initialize conf_file: nil, log_file: nil, work_dir: nil
32
+ cmd_log_file = log_file
33
+ log_file ||= DEFAULT_LOG_FILE
34
+ Log.setup log_file, SYSLOG_NAME
35
+
36
+ conf_file ||= DEFAULT_CONF_FILE
37
+ @conf_all = parse_conf conf_file
38
+ @conf = @conf_all.main
39
+
40
+ work_dir ||= WORK_DIR
41
+
42
+ # Redefine log file if set in conf file
43
+ unless cmd_log_file
44
+ if f = @conf[:log_file].presence
45
+ unless Log.change_log_file f
46
+ Log.w "Unable to change logfile to #{f}. Will continue with #{Log.log_file_desc}."
47
+ end
48
+ end
49
+ end
50
+
51
+ begin
52
+ Dir.chdir work_dir
53
+ rescue => e
54
+ Log.w "Cannot change working dir to #{WORK_DIR}. Will continue in #{Dir.pwd}."
55
+ end
56
+ end
57
+
58
+ def start
59
+ Server.new(@conf_all.server, @conf_all.zone_search).run
60
+ end
61
+
62
+ private
63
+
64
+ def parse_conf conf_file
65
+ check_conf_file conf_file
66
+
67
+ conf = YAML.load_file conf_file
68
+ conf = conf.symbolize_keys
69
+
70
+ OpenStruct.new(
71
+ main: {
72
+ work_dir: conf[:config][:work_dir],
73
+ log_file: conf[:config][:log_file]
74
+ },
75
+ server: {
76
+ run_as: conf[:config][:run_as]
77
+ },
78
+ zone_search: {
79
+ ignore_subdomains: conf[:config][:ignore_subdomains],
80
+ cache_max: conf[:config][:cache_max],
81
+ record_sets: conf[:record_sets],
82
+ backend: conf[:backend]
83
+ }
84
+ )
85
+ end
86
+
87
+ def check_conf_file conf_file
88
+ unless File.readable? conf_file
89
+ Util.die "Conf file #{conf_file} not found or unreadable. Aborting."
90
+ end
91
+
92
+ conf_stat = File.stat conf_file
93
+
94
+ unless conf_stat.mode.to_s(8) =~ /0600$/
95
+ Util.die "Conf file #{conf_file} must have mode 0600. Aborting."
96
+ end
97
+ end
107
98
 
108
99
  end; end
109
100
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dns_one
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.23
4
+ version: 0.4.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Lobato
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-27 00:00:00.000000000 Z
11
+ date: 2017-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,8 +94,8 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '1.6'
97
- description: Instead having a complex data schema to assign record sets to individual
98
- DNS zones, dns_one assigns one or few record to many zones. Configure your zones
97
+ description: Instead having a complex data schema to assign record sets to DNS zones,
98
+ dns_one assigns one or a few record sets to many zones. Configure your record sets
99
99
  in YML files and fetch your domains from a database or YML backend.
100
100
  email:
101
101
  - tomlobato@gmail.com
@@ -124,6 +124,7 @@ files:
124
124
  - lib/dns_one/cli.rb
125
125
  - lib/dns_one/core_ext/blank.rb
126
126
  - lib/dns_one/core_ext/exception.rb
127
+ - lib/dns_one/core_ext/hash.rb
127
128
  - lib/dns_one/core_ext/string.rb
128
129
  - lib/dns_one/log.rb
129
130
  - lib/dns_one/server.rb