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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b253e07948277570f96219b31ca73e7f811a269a
4
- data.tar.gz: ed8c82eeea3442fd17dc4ba15629762f070ff647
3
+ metadata.gz: 8ff52cd75b1db5bec370f515b509df7e29a05d99
4
+ data.tar.gz: 9685f288aecc2a805bb3a982383a1b596017bd1d
5
5
  SHA512:
6
- metadata.gz: e65d63e6b8b2b7ba9ee1c5861f01e99126d973cc0c629e46445dc6734200b6ed60902b30177660ac280fdfd23e88284d9400c8a8d90ac66bf2a87610be2d541a
7
- data.tar.gz: 16d1654dbae7fef7a1d6beb9f3485313aaf33e0d40569040db42a32cd1932b5036b8b3242e2827fce818ab62036633694dfbdc12e052d577b0ce7f6e8a114a3a
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
- last_id = @last_id || 0
28
+ log_update :start
24
29
 
25
- url = @conf[:http_bell_url].sub '$id', last_id.to_s
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
- Log.d "#{recs.size} new domains added."
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 |s|
54
- s.close
55
- Log.i "update`ing..."
56
- update
57
- end
58
- end
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
 
@@ -1,5 +1,7 @@
1
1
  module DnsOne; class Util; class << self
2
2
 
3
+ DOM_REGEX = /^[a-z0-9]+([\-\.][a-z0-9]+)*\.[a-z]{2,32}$/i
4
+
3
5
  def die msg
4
6
  Log.f msg
5
7
  exit 1
@@ -1,3 +1,3 @@
1
1
  module DnsOne
2
- VERSION = "0.4.52"
2
+ VERSION = "0.4.53"
3
3
  end
@@ -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.downcase
121
- .sub(/\.home$/i, '')
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
@@ -31,7 +31,10 @@ backend:
31
31
  http_bell_url: https://dnsapi.mysite.com/dns/fetch_since?id=$id
32
32
  http_bell_record_set: my_set_1
33
33
  http_bell_port: 27861
34
-
34
+ http_bell_allow_ips:
35
+ - 1.2.3.4
36
+ - 2.3.4.5
37
+
35
38
  ################
36
39
  # File backend #
37
40
 
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.52
4
+ version: 0.4.53
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Lobato