rubydns 0.6.2 → 0.6.3
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 +8 -8
- data/lib/rubydns/transaction.rb +9 -2
- data/lib/rubydns/version.rb +1 -1
- data/test/examples/wikipedia-dns.rb +119 -0
- data/test/test_passthrough.rb +24 -0
- data/test/test_resolver.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MGQ5MTRkMjlkNDRiZGQ2OGIxYzc4NWZhMGY1YzQxYTdkNTIyMGE5Ng==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YTAzYWRhYTQxZWY0MGI3NTAyNmE1OTIzZmYwNThjODY3NTYwODNhNA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NzA1NTM4MmVkYTQ5YmQ0NjU3MmMyOWVlZGVjMWY0MmI5ZDg0OWYxZDMzYzQz
|
10
|
+
NWU4YTM5MTE5N2IwZGYxYTJhMDk0NGQyYjNjNGNlZDVkYWFmNGNkYjYyYWM4
|
11
|
+
ZTk4ZWI0NzI1MjNkYjVjNTI2MTc2MWJkMzNmOGU0OTJhM2EzZTA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NTlkYzgxNzFmY2IwM2I3NTdmMjExOTAzODIwZGY3YjMwZDQ0Y2E2ZTc2MDQ3
|
14
|
+
NDE0MWUzZTJmZDg1ZGIxYTRkMzU3MzhiMjBjZDM1ZTM4NTQzODcwOTRkODE1
|
15
|
+
ZWJmYzBhMzA1MWNlMzA5MjZiZjVhZGRiMmIzZDg0MTVmMmVhOWM=
|
data/lib/rubydns/transaction.rb
CHANGED
@@ -115,12 +115,19 @@ module RubyDNS
|
|
115
115
|
#
|
116
116
|
# A second argument, options, provides some control over the passthrough process.
|
117
117
|
# :force => true, ensures that the query will occur even if recursion is not requested.
|
118
|
+
# :name => resource_name, override the name for the request as it is passed to
|
119
|
+
# the resolver. Implies :force.
|
120
|
+
# :resource_class => class, overried the resource class for a request as it is passed
|
121
|
+
# to the resolver.
|
118
122
|
def passthrough(resolver, options = {}, &block)
|
119
|
-
if @query.rd || options[:force]
|
123
|
+
if @query.rd || options[:force] || options[:name]
|
120
124
|
# Resolver is asynchronous, so we are now deferred:
|
121
125
|
defer!
|
122
126
|
|
123
|
-
|
127
|
+
query_name = options[:name] || name
|
128
|
+
query_resource_class = options[:resource_class] || resource_class
|
129
|
+
|
130
|
+
resolver.query(query_name, query_resource_class) do |response|
|
124
131
|
case response
|
125
132
|
when RubyDNS::Message
|
126
133
|
yield response
|
data/lib/rubydns/version.rb
CHANGED
@@ -0,0 +1,119 @@
|
|
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 'rexec'
|
27
|
+
require 'rexec/daemon'
|
28
|
+
|
29
|
+
require 'rubygems'
|
30
|
+
|
31
|
+
require 'rubydns'
|
32
|
+
require 'rubydns/extensions/string'
|
33
|
+
|
34
|
+
require 'em-http'
|
35
|
+
require 'cgi'
|
36
|
+
require 'nokogiri'
|
37
|
+
require 'json'
|
38
|
+
|
39
|
+
require 'digest/md5'
|
40
|
+
|
41
|
+
# You might need to change the user name "daemon". This can be a user name or a user id.
|
42
|
+
RUN_AS = "daemon"
|
43
|
+
|
44
|
+
if RExec.current_user != "root"
|
45
|
+
$stderr.puts "Sorry, this command needs to be run as root!"
|
46
|
+
exit 1
|
47
|
+
end
|
48
|
+
|
49
|
+
module Wikipedia
|
50
|
+
def self.summary_url(title)
|
51
|
+
"http://en.wikipedia.org/w/api.php?action=parse&page=#{CGI.escape title}&prop=text§ion=0&format=json"
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.extract_summary(json_text)
|
55
|
+
document = JSON::parse(json_text)
|
56
|
+
return Nokogiri::HTML(document["parse"]["text"]["*"]).css('p')[0].text
|
57
|
+
rescue
|
58
|
+
return "Invalid Article."
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# To use, start the daemon and try:
|
63
|
+
# dig @localhost fortune CNAME
|
64
|
+
class WikipediaDNS < RExec::Daemon::Base
|
65
|
+
@@base_directory = File.dirname(__FILE__)
|
66
|
+
|
67
|
+
Name = Resolv::DNS::Name
|
68
|
+
IN = Resolv::DNS::Resource::IN
|
69
|
+
|
70
|
+
def self.run
|
71
|
+
# Don't buffer output (for debug purposes)
|
72
|
+
$stderr.sync = true
|
73
|
+
|
74
|
+
cache = {}
|
75
|
+
stats = {:requested => 0}
|
76
|
+
|
77
|
+
# Start the RubyDNS server
|
78
|
+
RubyDNS::run_server do
|
79
|
+
on(:start) do
|
80
|
+
RExec.change_user(RUN_AS)
|
81
|
+
if ARGV.include?("--debug")
|
82
|
+
@logger.level = Logger::DEBUG
|
83
|
+
else
|
84
|
+
@logger.level = Logger::WARN
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
match(/stats\.wikipedia/, IN::TXT) do |transaction|
|
89
|
+
transaction.respond!(*stats.inspect.chunked)
|
90
|
+
end
|
91
|
+
|
92
|
+
match(/(.+)\.wikipedia/, IN::TXT) do |transaction, match_data|
|
93
|
+
title = match_data[1]
|
94
|
+
stats[:requested] += 1
|
95
|
+
|
96
|
+
transaction.defer!
|
97
|
+
|
98
|
+
http = EventMachine::HttpRequest.new(Wikipedia.summary_url(title)).get
|
99
|
+
|
100
|
+
http.callback do
|
101
|
+
summary = Wikipedia.extract_summary(http.response)
|
102
|
+
transaction.respond!(*summary.chunked)
|
103
|
+
end
|
104
|
+
|
105
|
+
http.errback do
|
106
|
+
transaction.failure!(:ServFail)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# Default DNS handler
|
111
|
+
otherwise do |transaction|
|
112
|
+
transaction.failure!(:NXDomain)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# RExec daemon runner
|
119
|
+
WikipediaDNS.daemonize
|
data/test/test_passthrough.rb
CHANGED
@@ -43,6 +43,10 @@ class TestPassthroughServer < RExec::Daemon::Base
|
|
43
43
|
transaction.passthrough!(resolver)
|
44
44
|
end
|
45
45
|
|
46
|
+
match(/a-(.*\.org)/) do |transaction, match_data|
|
47
|
+
transaction.passthrough!(resolver, :name => match_data[1])
|
48
|
+
end
|
49
|
+
|
46
50
|
# Default DNS handler
|
47
51
|
otherwise do |transaction|
|
48
52
|
transaction.failure!(:NXDomain)
|
@@ -75,6 +79,26 @@ class PassthroughTest < Test::Unit::TestCase
|
|
75
79
|
end
|
76
80
|
end
|
77
81
|
|
82
|
+
assert answer != nil
|
83
|
+
assert answer.count > 0
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_basic_dns_prefix
|
87
|
+
answer = nil
|
88
|
+
|
89
|
+
assert_equal :running, RExec::Daemon::ProcessFile.status(TestPassthroughServer)
|
90
|
+
|
91
|
+
EventMachine.run do
|
92
|
+
resolver = RubyDNS::Resolver.new(TestPassthroughServer::SERVER_PORTS)
|
93
|
+
|
94
|
+
resolver.query("a-slashdot.org") do |response|
|
95
|
+
answer = response.answer.first
|
96
|
+
|
97
|
+
EventMachine.stop
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
assert answer != nil
|
78
102
|
assert answer.count > 0
|
79
103
|
end
|
80
104
|
end
|
data/test/test_resolver.rb
CHANGED
@@ -35,7 +35,7 @@ class ResolverTest < Test::Unit::TestCase
|
|
35
35
|
end
|
36
36
|
|
37
37
|
EventMachine::run do
|
38
|
-
resolver.query('
|
38
|
+
resolver.query('foobar.oriontransfer.org') do |response|
|
39
39
|
assert_equal response.rcode, Resolv::DNS::RCode::NXDomain
|
40
40
|
EventMachine::stop
|
41
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubydns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rexec
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- test/examples/soa-dns.rb
|
84
84
|
- test/examples/test-dns-1.rb
|
85
85
|
- test/examples/test-dns-2.rb
|
86
|
+
- test/examples/wikipedia-dns.rb
|
86
87
|
- test/helper.rb
|
87
88
|
- test/hosts.txt
|
88
89
|
- test/test_daemon.rb
|
@@ -123,6 +124,7 @@ test_files:
|
|
123
124
|
- test/examples/soa-dns.rb
|
124
125
|
- test/examples/test-dns-1.rb
|
125
126
|
- test/examples/test-dns-2.rb
|
127
|
+
- test/examples/wikipedia-dns.rb
|
126
128
|
- test/helper.rb
|
127
129
|
- test/hosts.txt
|
128
130
|
- test/test_daemon.rb
|