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 +4 -4
- data/README.md +2 -2
- data/dns_one.gemspec +1 -1
- data/lib/dns_one/backend/db.rb +6 -4
- data/lib/dns_one/backend/file.rb +4 -3
- data/lib/dns_one/cli.rb +7 -2
- data/lib/dns_one/core_ext/hash.rb +5 -0
- data/lib/dns_one/server.rb +3 -1
- data/lib/dns_one/setup.rb +1 -1
- data/lib/dns_one/version.rb +1 -1
- data/lib/dns_one/zone_search.rb +8 -4
- data/lib/dns_one.rb +75 -84
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 77fd667f7117637e11933cd243928f1a0642220a
|
|
4
|
+
data.tar.gz: fcc9de0cf0843db0f7d76560bedabea8e5e13576
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
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
|
|
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
|
|
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
|
|
data/lib/dns_one/backend/db.rb
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
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 "
|
|
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.
|
|
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
|
data/lib/dns_one/backend/file.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
|
|
2
|
-
module Backend; class
|
|
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(
|
|
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
|
|
data/lib/dns_one/server.rb
CHANGED
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
|
|
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
|
|
data/lib/dns_one/version.rb
CHANGED
data/lib/dns_one/zone_search.rb
CHANGED
|
@@ -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 ?
|
|
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::
|
|
81
|
+
Backend::File.new file
|
|
78
82
|
else
|
|
79
|
-
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
def
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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.
|
|
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-
|
|
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
|
|
98
|
-
|
|
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
|