rubydns 0.8.5 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -0
  3. data/Gemfile +0 -4
  4. data/README.md +16 -8
  5. data/Rakefile +6 -6
  6. data/{test/examples → examples}/dropping-dns.rb +0 -0
  7. data/lib/rubydns/handler.rb +133 -102
  8. data/lib/rubydns/message.rb +0 -1
  9. data/lib/rubydns/resolver.rb +135 -187
  10. data/lib/rubydns/server.rb +92 -86
  11. data/lib/rubydns/transaction.rb +24 -48
  12. data/lib/rubydns/{binary_string.rb → transport.rb} +38 -0
  13. data/lib/rubydns/version.rb +1 -1
  14. data/lib/rubydns.rb +15 -8
  15. data/rubydns.gemspec +5 -2
  16. data/{test/test_daemon.rb → spec/rubydns/daemon_spec.rb} +36 -48
  17. data/{test → spec/rubydns}/hosts.txt +0 -0
  18. data/{test/test_rules.rb → spec/rubydns/message_spec.rb} +26 -44
  19. data/spec/rubydns/passthrough_spec.rb +78 -0
  20. data/spec/rubydns/resolver_performance_spec.rb +110 -0
  21. data/spec/rubydns/resolver_spec.rb +144 -0
  22. data/spec/rubydns/rules_spec.rb +74 -0
  23. data/{test/performance → spec/rubydns/server}/benchmark.rb +0 -0
  24. data/{test/performance → spec/rubydns/server}/bind9/generate-local.rb +0 -0
  25. data/{test/performance → spec/rubydns/server}/bind9/local.zone +0 -0
  26. data/{test/performance → spec/rubydns/server}/bind9/named.conf +0 -0
  27. data/spec/rubydns/server/bind9/named.run +0 -0
  28. data/{test/performance → spec/rubydns/server}/million.rb +1 -3
  29. data/spec/rubydns/server/rubydns.stackprof +0 -0
  30. data/spec/rubydns/server_performance_spec.rb +136 -0
  31. data/spec/rubydns/slow_server_spec.rb +89 -0
  32. data/spec/rubydns/socket_spec.rb +77 -0
  33. data/{test/test_system.rb → spec/rubydns/system_spec.rb} +28 -22
  34. data/spec/rubydns/transaction_spec.rb +64 -0
  35. data/{test/test_truncation.rb → spec/rubydns/truncation_spec.rb} +22 -48
  36. metadata +91 -54
  37. data/test/examples/fortune-dns.rb +0 -107
  38. data/test/examples/geoip-dns.rb +0 -76
  39. data/test/examples/soa-dns.rb +0 -82
  40. data/test/examples/test-dns-1.rb +0 -77
  41. data/test/examples/test-dns-2.rb +0 -83
  42. data/test/examples/wikipedia-dns.rb +0 -112
  43. data/test/test_message.rb +0 -65
  44. data/test/test_passthrough.rb +0 -120
  45. data/test/test_resolver.rb +0 -106
  46. data/test/test_resolver_performance.rb +0 -123
  47. data/test/test_server_performance.rb +0 -134
  48. data/test/test_slow_server.rb +0 -125
@@ -20,66 +20,40 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  # THE SOFTWARE.
22
22
 
23
- require 'minitest/autorun'
24
-
25
23
  require 'rubydns'
26
24
  require 'rubydns/extensions/string'
27
25
 
28
- require 'process/daemon'
29
-
30
- class TruncatedServer < Process::Daemon
31
- SERVER_PORTS = [[:udp, '127.0.0.1', 5320], [:tcp, '127.0.0.1', 5320]]
32
-
33
- def working_directory
34
- File.expand_path("../tmp", __FILE__)
35
- end
36
-
26
+ module RubyDNS::TruncationSpec
27
+ SERVER_PORTS = [[:udp, '127.0.0.1', 5520], [:tcp, '127.0.0.1', 5520]]
37
28
  IN = Resolv::DNS::Resource::IN
38
29
 
39
- def startup
40
- # RubyDNS::log_bad_messages!("bad.log")
41
-
42
- # Start the RubyDNS server
43
- RubyDNS::run_server(:listen => SERVER_PORTS) do
44
- match("truncation", IN::TXT) do |transaction|
45
- text = "Hello World! " * 100
46
- transaction.respond!(*text.chunked)
47
- end
30
+ describe "RubyDNS Truncation Server" do
31
+ before(:all) do
32
+ Celluloid.shutdown
33
+ Celluloid.boot
48
34
 
49
- # Default DNS handler
50
- otherwise do |transaction|
51
- transaction.fail!(:NXDomain)
35
+ # Start the RubyDNS server
36
+ RubyDNS::run_server(:listen => SERVER_PORTS, asynchronous: true) do
37
+ match("truncation", IN::TXT) do |transaction|
38
+ text = "Hello World! " * 100
39
+ transaction.respond!(*text.chunked)
40
+ end
41
+
42
+ # Default DNS handler
43
+ otherwise do |transaction|
44
+ transaction.fail!(:NXDomain)
45
+ end
52
46
  end
53
47
  end
54
- end
55
- end
56
48
 
57
- class TruncationTest < MiniTest::Test
58
- def setup
59
- TruncatedServer.controller output: File.open("/dev/null", "w")
60
-
61
- TruncatedServer.start
62
- end
49
+ it "should use tcp because of large response" do
50
+ resolver = RubyDNS::Resolver.new(SERVER_PORTS)
63
51
 
64
- def teardown
65
- TruncatedServer.stop
66
- end
52
+ response = resolver.query("truncation", IN::TXT)
67
53
 
68
- IN = Resolv::DNS::Resource::IN
54
+ text = response.answer.first
69
55
 
70
- def test_tcp_failover
71
- resolver = RubyDNS::Resolver.new(TruncatedServer::SERVER_PORTS)
72
-
73
- EventMachine::run do
74
- resolver.query("truncation", IN::TXT) do |response|
75
- refute_kind_of RubyDNS::ResolutionFailure, response
76
-
77
- text = response.answer.first
78
-
79
- assert_equal "Hello World! " * 100, text[2].strings.join
80
-
81
- EventMachine::stop
82
- end
56
+ expect(text[2].strings.join).to be == ("Hello World! " * 100)
83
57
  end
84
58
  end
85
59
  end
metadata CHANGED
@@ -1,29 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubydns
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.5
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-24 00:00:00.000000000 Z
11
+ date: 2014-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: eventmachine
14
+ name: celluloid
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.0
19
+ version: 0.16.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.0.0
26
+ version: 0.16.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: celluloid-io
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.16.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.16.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: timers
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 4.0.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 4.0.1
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: bundler
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +72,28 @@ dependencies:
44
72
  requirements:
45
73
  - - "~>"
46
74
  - !ruby/object:Gem::Version
47
- version: 0.5.3
75
+ version: 0.5.5
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.5.5
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.0.0
48
90
  type: :development
49
91
  prerelease: false
50
92
  version_requirements: !ruby/object:Gem::Requirement
51
93
  requirements:
52
94
  - - "~>"
53
95
  - !ruby/object:Gem::Version
54
- version: 0.5.3
96
+ version: 3.0.0
55
97
  - !ruby/object:Gem::Dependency
56
98
  name: rake
57
99
  requirement: !ruby/object:Gem::Requirement
@@ -87,8 +129,8 @@ files:
87
129
  - README.md
88
130
  - Rakefile
89
131
  - bin/rubydns-check
132
+ - examples/dropping-dns.rb
90
133
  - lib/rubydns.rb
91
- - lib/rubydns/binary_string.rb
92
134
  - lib/rubydns/chunked.rb
93
135
  - lib/rubydns/extensions/resolv.rb
94
136
  - lib/rubydns/extensions/string.rb
@@ -99,31 +141,29 @@ files:
99
141
  - lib/rubydns/server.rb
100
142
  - lib/rubydns/system.rb
101
143
  - lib/rubydns/transaction.rb
144
+ - lib/rubydns/transport.rb
102
145
  - lib/rubydns/version.rb
103
146
  - rubydns.gemspec
104
- - test/examples/dropping-dns.rb
105
- - test/examples/fortune-dns.rb
106
- - test/examples/geoip-dns.rb
107
- - test/examples/soa-dns.rb
108
- - test/examples/test-dns-1.rb
109
- - test/examples/test-dns-2.rb
110
- - test/examples/wikipedia-dns.rb
111
- - test/hosts.txt
112
- - test/performance/benchmark.rb
113
- - test/performance/bind9/generate-local.rb
114
- - test/performance/bind9/local.zone
115
- - test/performance/bind9/named.conf
116
- - test/performance/million.rb
117
- - test/test_daemon.rb
118
- - test/test_message.rb
119
- - test/test_passthrough.rb
120
- - test/test_resolver.rb
121
- - test/test_resolver_performance.rb
122
- - test/test_rules.rb
123
- - test/test_server_performance.rb
124
- - test/test_slow_server.rb
125
- - test/test_system.rb
126
- - test/test_truncation.rb
147
+ - spec/rubydns/daemon_spec.rb
148
+ - spec/rubydns/hosts.txt
149
+ - spec/rubydns/message_spec.rb
150
+ - spec/rubydns/passthrough_spec.rb
151
+ - spec/rubydns/resolver_performance_spec.rb
152
+ - spec/rubydns/resolver_spec.rb
153
+ - spec/rubydns/rules_spec.rb
154
+ - spec/rubydns/server/benchmark.rb
155
+ - spec/rubydns/server/bind9/generate-local.rb
156
+ - spec/rubydns/server/bind9/local.zone
157
+ - spec/rubydns/server/bind9/named.conf
158
+ - spec/rubydns/server/bind9/named.run
159
+ - spec/rubydns/server/million.rb
160
+ - spec/rubydns/server/rubydns.stackprof
161
+ - spec/rubydns/server_performance_spec.rb
162
+ - spec/rubydns/slow_server_spec.rb
163
+ - spec/rubydns/socket_spec.rb
164
+ - spec/rubydns/system_spec.rb
165
+ - spec/rubydns/transaction_spec.rb
166
+ - spec/rubydns/truncation_spec.rb
127
167
  homepage: http://www.codeotaku.com/projects/rubydns
128
168
  licenses:
129
169
  - MIT
@@ -149,26 +189,23 @@ signing_key:
149
189
  specification_version: 4
150
190
  summary: An easy to use DNS server and resolver for Ruby.
151
191
  test_files:
152
- - test/examples/dropping-dns.rb
153
- - test/examples/fortune-dns.rb
154
- - test/examples/geoip-dns.rb
155
- - test/examples/soa-dns.rb
156
- - test/examples/test-dns-1.rb
157
- - test/examples/test-dns-2.rb
158
- - test/examples/wikipedia-dns.rb
159
- - test/hosts.txt
160
- - test/performance/benchmark.rb
161
- - test/performance/bind9/generate-local.rb
162
- - test/performance/bind9/local.zone
163
- - test/performance/bind9/named.conf
164
- - test/performance/million.rb
165
- - test/test_daemon.rb
166
- - test/test_message.rb
167
- - test/test_passthrough.rb
168
- - test/test_resolver.rb
169
- - test/test_resolver_performance.rb
170
- - test/test_rules.rb
171
- - test/test_server_performance.rb
172
- - test/test_slow_server.rb
173
- - test/test_system.rb
174
- - test/test_truncation.rb
192
+ - spec/rubydns/daemon_spec.rb
193
+ - spec/rubydns/hosts.txt
194
+ - spec/rubydns/message_spec.rb
195
+ - spec/rubydns/passthrough_spec.rb
196
+ - spec/rubydns/resolver_performance_spec.rb
197
+ - spec/rubydns/resolver_spec.rb
198
+ - spec/rubydns/rules_spec.rb
199
+ - spec/rubydns/server/benchmark.rb
200
+ - spec/rubydns/server/bind9/generate-local.rb
201
+ - spec/rubydns/server/bind9/local.zone
202
+ - spec/rubydns/server/bind9/named.conf
203
+ - spec/rubydns/server/bind9/named.run
204
+ - spec/rubydns/server/million.rb
205
+ - spec/rubydns/server/rubydns.stackprof
206
+ - spec/rubydns/server_performance_spec.rb
207
+ - spec/rubydns/slow_server_spec.rb
208
+ - spec/rubydns/socket_spec.rb
209
+ - spec/rubydns/system_spec.rb
210
+ - spec/rubydns/transaction_spec.rb
211
+ - spec/rubydns/truncation_spec.rb
@@ -1,107 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: utf-8
3
-
4
- # Copyright, 2009, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy
7
- # of this software and associated documentation files (the "Software"), to deal
8
- # in the Software without restriction, including without limitation the rights
9
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- # copies of the Software, and to permit persons to whom the Software is
11
- # furnished to do so, subject to the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be included in
14
- # all copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
- # THE SOFTWARE.
23
-
24
- require 'rubygems'
25
-
26
- require 'process/daemon'
27
-
28
- require 'rubygems'
29
-
30
- require 'rubydns'
31
- require 'rubydns/extensions/string'
32
-
33
- require 'digest/md5'
34
-
35
- # You might need to change the user name "daemon". This can be a user name or a user id.
36
- RUN_AS = "daemon"
37
-
38
- if RExec.current_user != "root"
39
- $stderr.puts "Sorry, this command needs to be run as root!"
40
- exit 1
41
- end
42
-
43
- # To use, start the daemon and try:
44
- # dig @localhost fortune CNAME
45
- class FortuneDNS < Process::Daemon
46
- Name = Resolv::DNS::Name
47
- IN = Resolv::DNS::Resource::IN
48
-
49
- def startup
50
- # Don't buffer output (for debug purposes)
51
- $stderr.sync = true
52
-
53
- cache = {}
54
- stats = {:requested => 0}
55
-
56
- # Start the RubyDNS server
57
- RubyDNS::run_server do
58
- on(:start) do
59
- RExec.change_user(RUN_AS)
60
- if ARGV.include?("--debug")
61
- @logger.level = Logger::DEBUG
62
- else
63
- @logger.level = Logger::WARN
64
- end
65
- end
66
-
67
- match(/stats\.fortune/, IN::TXT) do |transaction|
68
- $stderr.puts "Sending stats: #{stats.inspect}"
69
- transaction.respond!(stats.inspect)
70
- end
71
-
72
- match(/(.+)\.fortune/, IN::TXT) do |transaction|
73
- fortune = cache[match[1]]
74
- stats[:requested] += 1
75
-
76
- if fortune
77
- transaction.respond!(*fortune.chunked)
78
- else
79
- transaction.fail!(:NXDomain)
80
- end
81
- end
82
-
83
- match(/fortune/, [IN::CNAME, IN::TXT]) do |transaction|
84
- fortune = `fortune`.gsub(/\s+/, " ").strip
85
- checksum = Digest::MD5.hexdigest(fortune)
86
- cache[checksum] = fortune
87
-
88
- transaction.respond!("Text Size: #{fortune.size} Byte Size: #{fortune.bytesize}", :resource_class => IN::TXT, :ttl => 0)
89
- transaction.respond!(Name.create(checksum + ".fortune"), :resource_class => IN::CNAME, :ttl => 0)
90
- end
91
-
92
- match(/short.fortune/, IN::TXT) do |match, transation|
93
- fortune = `fortune -s`.gsub(/\s+/, " ").strip
94
-
95
- transaction.respond!(*fortune.chunked, :ttl => 0)
96
- end
97
-
98
- # Default DNS handler
99
- otherwise do |transaction|
100
- transaction.fail!(:NXDomain)
101
- end
102
- end
103
- end
104
- end
105
-
106
- # RExec daemon runner
107
- FortuneDNS.daemonize
@@ -1,76 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # Copyright, 2009, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
22
-
23
- require 'geoip'
24
-
25
- require 'process-daemon'
26
-
27
- require 'rubydns'
28
- require 'rubydns/system'
29
-
30
- INTERFACES = [
31
- [:udp, "0.0.0.0", 5300]
32
- ]
33
-
34
- # This daemon requires the file downloaded from http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
35
- # For more information, please see http://www.maxmind.com/en/geolite and http://geoip.rubyforge.org
36
-
37
- class GeoIPDNSDaemon < Process::Daemon
38
- Name = Resolv::DNS::Name
39
- IN = Resolv::DNS::Resource::IN
40
- R = RubyDNS::Resolver.new(RubyDNS::System::nameservers)
41
- GEO = GeoIP.new(File.expand_path('../GeoLiteCountry.dat', __FILE__))
42
-
43
- def startup
44
- RubyDNS::run_server(:listen => INTERFACES) do
45
- match(//, IN::A) do |transaction|
46
- location = nil
47
- peer = transaction.options[:connection].peername[0]
48
-
49
- if peer
50
- logger.debug "Looking up geographic information for peer #{peer}"
51
- location = GEO.country(peer[0])
52
- end
53
-
54
- if location
55
- logger.debug "Found location #{location}"
56
- end
57
-
58
- case location.continent_code
59
- when "EU"
60
- transaction.respond!("1.1.1.1")
61
- when "CN", "JP"
62
- transaction.respond!("1.1.2.1")
63
- else
64
- transaction.respond!("1.1.3.1")
65
- end
66
- end
67
-
68
- # Default DNS handler
69
- otherwise do |transaction|
70
- transaction.passthrough!(R)
71
- end
72
- end
73
- end
74
- end
75
-
76
- GeoIPDNSDaemon.daemonize
@@ -1,82 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # Copyright, 2009, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
22
-
23
- require 'rubygems'
24
- require 'rubydns'
25
-
26
- $R = Resolv::DNS.new
27
- Name = Resolv::DNS::Name
28
- IN = Resolv::DNS::Resource::IN
29
-
30
- RubyDNS::run_server(:listen => [[:udp, "0.0.0.0", 5400]]) do
31
- # SOA Record
32
- # dig @localhost -p 5300 SOA mydomain.org
33
- match("mydomain.org", IN::SOA) do |transaction|
34
- #
35
- # For more details about these headers please see:
36
- # http://www.ripe.net/ripe/docs/ripe-203.html
37
- #
38
-
39
- transaction.respond!(
40
- Name.create("ns.mydomain.org."), # Master Name
41
- Name.create("admin.mydomain.org."), # Responsible Name
42
- File.mtime(__FILE__).to_i, # Serial Number
43
- 1200, # Refresh Time
44
- 900, # Retry Time
45
- 3600000, # Maximum TTL / Expiry Time
46
- 172800 # Minimum TTL
47
- )
48
-
49
- transaction.append_query!(transaction.question, IN::NS, :section => :authority)
50
- end
51
-
52
- # Default NS record
53
- # dig @localhost -p 5300 mydomain.org NS
54
- match("mydomain.org", IN::NS) do |transaction|
55
- transaction.respond!(Name.create("ns.mydomain.org."))
56
- end
57
-
58
- # For this exact address record, return an IP address
59
- # dig @localhost -p 5300 CNAME bob.mydomain.org
60
- match(/([^.]+).mydomain.org/, IN::CNAME) do |transaction|
61
- transaction.respond!(Name.create("www.mydomain.org"))
62
- transaction.append_query!("www.mydomain.org", IN::A)
63
- end
64
-
65
- match("80.0.0.10.in-addr.arpa", IN::PTR) do |transaction|
66
- transaction.respond!(Name.create("www.mydomain.org."))
67
- end
68
-
69
- match("www.mydomain.org", IN::A) do |transaction|
70
- transaction.respond!("10.0.0.80")
71
- end
72
-
73
- match("ns.mydomain.org", IN::A) do |transaction|
74
- transaction.respond!("10.0.0.10")
75
- end
76
-
77
- # Default DNS handler
78
- otherwise do |transaction|
79
- # Non-Existant Domain
80
- transaction.fail!(:NXDomain)
81
- end
82
- end
@@ -1,77 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # Copyright, 2009, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
22
-
23
- require 'rubygems'
24
- require 'rubydns'
25
- require 'rubydns/system'
26
-
27
- # You can specify other DNS servers easily
28
- # $R = Resolv::DNS.new(:nameserver => ["xx.xx.1.1", "xx.xx.2.2"])
29
-
30
- R = RubyDNS::Resolver.new(RubyDNS::System::nameservers)
31
- Name = Resolv::DNS::Name
32
- IN = Resolv::DNS::Resource::IN
33
-
34
- RubyDNS::run_server do
35
- # % dig +nocmd +noall +answer @localhost ANY dev.mydomain.org
36
- # dev.mydomain.org. 16000 IN A 10.0.0.80
37
- # dev.mydomain.org. 16000 IN MX 10 mail.mydomain.org.
38
- match(/dev.mydomain.org/, IN::ANY) do |transaction|
39
- transaction.append_question!
40
-
41
- [IN::A, IN::CNAME, IN::MX].each do |resource_class|
42
- logger.debug "Appending query for #{resource_class}..."
43
- transaction.append_query!(transaction.name, resource_class)
44
- end
45
- end
46
-
47
- # For this exact address record, return an IP address
48
- match("dev.mydomain.org", IN::A) do |transaction|
49
- transaction.respond!("10.0.0.80")
50
- end
51
-
52
- match("80.0.0.10.in-addr.arpa", IN::PTR) do |transaction|
53
- transaction.respond!(Name.create("dev.mydomain.org."))
54
- end
55
-
56
- match("dev.mydomain.org", IN::MX) do |transaction|
57
- transaction.respond!(10, Name.create("mail.mydomain.org."))
58
- end
59
-
60
- match(/^test([0-9]+).mydomain.org$/, IN::A) do |transaction, match_data|
61
- offset = match_data[1].to_i
62
-
63
- if offset > 0 && offset < 10
64
- logger.info "Responding with address #{"10.0.0." + (90 + offset).to_s}..."
65
- transaction.respond!("10.0.0." + (90 + offset).to_s)
66
- else
67
- logger.info "Address out of range: #{offset}!"
68
- false
69
- end
70
- end
71
-
72
- # Default DNS handler
73
- otherwise do |transaction|
74
- logger.info "Passing DNS request upstream..."
75
- transaction.passthrough!(R)
76
- end
77
- end