dns_one 0.4.52 → 0.4.53
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/lib/dns_one/backend/http_bell.rb +54 -16
- data/lib/dns_one/util.rb +2 -0
- data/lib/dns_one/version.rb +1 -1
- data/lib/dns_one/zone_search.rb +8 -8
- data/util/sample_conf.yml +4 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ff52cd75b1db5bec370f515b509df7e29a05d99
|
4
|
+
data.tar.gz: 9685f288aecc2a805bb3a982383a1b596017bd1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07e22468f0192d6cac46a61480e09c16ef404fa794e19b1839406a63aed91a87477f624c5078d756c9c6b05208e3c0aba4f394df9da265b6ed71aa5138bcb0a2
|
7
|
+
data.tar.gz: 01e593ffaa49a0fe264ab18a76f9f4fc33a608d60faf674ab8fb0df7f88d59c56fce1d14ec96419b3098a1b1232bcf3baf859b45472078771dfe1db721a966f1
|
@@ -1,4 +1,9 @@
|
|
1
1
|
|
2
|
+
# HTTPBell
|
3
|
+
# At initialization:
|
4
|
+
# 1) Fetches all domains from @conf[:http_bell_url] and keeps in memory
|
5
|
+
# 2) Open TCP port @conf[:http_bell_port] and fetches new domains incrementally upon connect(2)
|
6
|
+
|
2
7
|
module DnsOne; module Backend; class HTTPBell < Base
|
3
8
|
|
4
9
|
def initialize conf
|
@@ -20,26 +25,55 @@ module DnsOne; module Backend; class HTTPBell < Base
|
|
20
25
|
private
|
21
26
|
|
22
27
|
def update
|
23
|
-
|
28
|
+
log_update :start
|
24
29
|
|
25
|
-
|
26
|
-
|
27
|
-
recs = `curl #{url}`
|
28
|
-
.split("\n")
|
29
|
-
.map{ |r|
|
30
|
-
r.strip.split /\s+/
|
31
|
-
}
|
30
|
+
recs = fetch
|
32
31
|
|
33
32
|
recs.each do |rec|
|
34
33
|
id, domain = rec
|
35
|
-
id = id.to_i
|
36
34
|
@domains[domain] = @conf[:http_bell_record_set]
|
37
35
|
if !@last_id || @last_id < id
|
38
36
|
@last_id = id
|
39
37
|
end
|
40
38
|
end
|
41
39
|
|
42
|
-
|
40
|
+
log_update :end, recs
|
41
|
+
end
|
42
|
+
|
43
|
+
def fetch
|
44
|
+
last_id = @last_id || 0
|
45
|
+
|
46
|
+
url = @conf[:http_bell_url].sub '$id', last_id.to_s
|
47
|
+
|
48
|
+
recs = `curl #{url}`
|
49
|
+
.split(/\n+/)
|
50
|
+
.map{ |r|
|
51
|
+
id, domain = r.strip.split /\s+/
|
52
|
+
if id !~ /^\d+$/ || domain !~ Util::DOM_REGEX
|
53
|
+
Log.w "invalid line '#{r}'"
|
54
|
+
nil
|
55
|
+
else
|
56
|
+
[id.to_i, domain.downcase]
|
57
|
+
end
|
58
|
+
}.compact
|
59
|
+
|
60
|
+
recs
|
61
|
+
end
|
62
|
+
|
63
|
+
def log_update point, recs = nil
|
64
|
+
case point
|
65
|
+
when :start
|
66
|
+
@log_update_t0 = Time.now
|
67
|
+
Log.i "update`ing..."
|
68
|
+
when :end
|
69
|
+
show_num = 10
|
70
|
+
dots = '...' if recs.size > show_num
|
71
|
+
zones = recs[0, show_num].map(&:first).join(', ')
|
72
|
+
dt = '%.2f' % (Time.now - @log_update_t0)
|
73
|
+
Log.d "#{recs.size} zone(s) added in #{dt}s: #{zones}#{dots}"
|
74
|
+
else
|
75
|
+
Log.e "Wrong param #{point} for log_update"
|
76
|
+
end
|
43
77
|
end
|
44
78
|
|
45
79
|
def listen_updater_bell
|
@@ -48,14 +82,18 @@ module DnsOne; module Backend; class HTTPBell < Base
|
|
48
82
|
end
|
49
83
|
require "socket"
|
50
84
|
dts = TCPServer.new '0.0.0.0', @conf[:http_bell_port]
|
85
|
+
allow_ips = @conf[:http_bell_allow_ips]
|
51
86
|
Thread.new do
|
52
87
|
loop do
|
53
|
-
Thread.start(dts.accept) do |
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
88
|
+
Thread.start(dts.accept) do |client|
|
89
|
+
client.close
|
90
|
+
if !allow_ips || allow_ips.include?(client.peeraddr)
|
91
|
+
update
|
92
|
+
else
|
93
|
+
Log.w "Ignoring bell ring from #{client.peeraddr}."
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
59
97
|
end
|
60
98
|
end
|
61
99
|
|
data/lib/dns_one/util.rb
CHANGED
data/lib/dns_one/version.rb
CHANGED
data/lib/dns_one/zone_search.rb
CHANGED
@@ -8,7 +8,6 @@ require 'dns_one/backend/db'
|
|
8
8
|
module DnsOne; class ZoneSearch
|
9
9
|
include Singleton
|
10
10
|
|
11
|
-
DOM_REGEX = /^[a-z0-9]+([\-\.][a-z0-9]+)*\.[a-z]{2,32}$/i
|
12
11
|
Name = Resolv::DNS::Name
|
13
12
|
IN = Resolv::DNS::Resource::IN
|
14
13
|
|
@@ -27,7 +26,7 @@ module DnsOne; class ZoneSearch
|
|
27
26
|
end
|
28
27
|
|
29
28
|
def query dom_name, res_class, ip_address
|
30
|
-
return unless dom_name =~ DOM_REGEX
|
29
|
+
return unless dom_name =~ Util::DOM_REGEX
|
31
30
|
|
32
31
|
dom_name = dom_name.dup
|
33
32
|
res_class_short = Util.last_mod res_class # :A, :NS, found in conf.yml:record_sets items
|
@@ -99,10 +98,6 @@ module DnsOne; class ZoneSearch
|
|
99
98
|
dom_name, use_cache = check_debug_tags dom_name
|
100
99
|
dom_name = normalize_domain dom_name
|
101
100
|
|
102
|
-
if @ignore_subdomains_re
|
103
|
-
dom_name.sub! @ignore_subdomains_re, ''
|
104
|
-
end
|
105
|
-
|
106
101
|
enabled_cache = use_cache && @backend.allow_cache
|
107
102
|
|
108
103
|
if enabled_cache and rec_set = @cache.find(dom_name)
|
@@ -117,8 +112,13 @@ module DnsOne; class ZoneSearch
|
|
117
112
|
end
|
118
113
|
|
119
114
|
def normalize_domain dom_name
|
120
|
-
dom_name.
|
121
|
-
|
115
|
+
dom_name = dom_name.dup
|
116
|
+
|
117
|
+
dom_name.sub! @ignore_subdomains_re, '' if @ignore_subdomains_re
|
118
|
+
dom_name.downcase!
|
119
|
+
dom_name.sub! /\.home$/i, ''
|
120
|
+
|
121
|
+
dom_name
|
122
122
|
end
|
123
123
|
|
124
124
|
def check_debug_tags dom_name
|
data/util/sample_conf.yml
CHANGED