rubydns 2.0.1 → 2.0.2
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 +5 -5
- data/README.md +8 -9
- data/examples/Gemfile +3 -1
- data/examples/wikipedia-dns.rb +40 -26
- data/lib/rubydns/version.rb +1 -1
- data/rubydns.gemspec +4 -13
- metadata +6 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b68dbef72ac3c56cca16121d5e09ac0f50b601fb7c23660eafab7dbf1b695e1f
|
4
|
+
data.tar.gz: 599604de9a1f63f192052756bd6125331a165c4bee0d704d83b931bf0b85395b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d44d54b225808fb7ccee61327d42f1fe7b39a3e09606e279103b6bbae12ad4489b9095784123200c398983cff9d1c166b342ad51f0bbec9cf361eb7c7bc8c30d
|
7
|
+
data.tar.gz: fc2e9354e124f7649b0499fa25ada6cfffc6760db970823e02a7e89cbfe2e69988e5ea2119aa78ff440a252d9e4b445f73c3c31a85f5f19664b3677f046b459a
|
data/README.md
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
# RubyDNS
|
2
2
|
|
3
|
-
[](https://gitter.im/ioquatix/rubydns?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
4
|
-
|
5
3
|
RubyDNS is a high-performance DNS server which can be easily integrated into other projects or used as a stand-alone daemon. By default it uses rule-based pattern matching. Results can be hard-coded, computed, fetched from a remote DNS server or fetched from a local cache, depending on requirements.
|
6
4
|
|
7
|
-
[](https://travis-ci.org/socketry/rubydns)
|
6
|
+
[](https://codeclimate.com/github/socketry/rubydns)
|
7
|
+
[](https://coveralls.io/r/socketry/rubydns)
|
8
|
+
[](https://gitter.im/socketry/rubydns)
|
10
9
|
|
11
10
|
[](https://www.youtube.com/watch?v=B9ygq0xh3HQ&feature=youtu.be&hd=1 "RubyDNS Introduction")
|
12
11
|
|
@@ -80,12 +79,12 @@ class MyServer < Async::DNS::Server
|
|
80
79
|
end
|
81
80
|
|
82
81
|
Async::Reactor.run do
|
83
|
-
task = MyServer.run
|
82
|
+
task = MyServer.new.run
|
84
83
|
|
85
|
-
# ... do other things
|
84
|
+
# ... do other things, e.g. run specs/tests
|
86
85
|
|
87
|
-
# Shut down the server
|
88
|
-
task.stop
|
86
|
+
# Shut down the server manually if required, otherwise it will run indefinitely.
|
87
|
+
# task.stop
|
89
88
|
end
|
90
89
|
```
|
91
90
|
|
data/examples/Gemfile
CHANGED
data/examples/wikipedia-dns.rb
CHANGED
@@ -23,35 +23,43 @@
|
|
23
23
|
|
24
24
|
require 'rubydns'
|
25
25
|
|
26
|
-
require 'process/daemon'
|
27
|
-
require 'process/daemon/privileges'
|
28
|
-
|
29
26
|
require 'cgi'
|
30
|
-
require 'nokogiri'
|
31
27
|
require 'json'
|
32
28
|
|
33
29
|
require 'digest/md5'
|
34
30
|
|
35
|
-
require '
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
RUN_AS = 'daemon'
|
40
|
-
|
41
|
-
if Process::Daemon::Privileges.current_user != 'root'
|
42
|
-
$stderr.puts 'Sorry, this command needs to be run as root!'
|
43
|
-
exit 1
|
44
|
-
end
|
31
|
+
require 'async/logger'
|
32
|
+
require 'async/http/client'
|
33
|
+
require 'async/dns/extensions/string'
|
34
|
+
require 'async/http/url_endpoint'
|
45
35
|
|
46
36
|
# Encapsulates the logic for fetching information from Wikipedia.
|
47
37
|
module Wikipedia
|
38
|
+
ENDPOINT = Async::HTTP::URLEndpoint.parse("https://en.wikipedia.org")
|
39
|
+
|
40
|
+
def self.lookup(title, logger: nil)
|
41
|
+
client = Async::HTTP::Client.new([ENDPOINT])
|
42
|
+
url = self.summary_url(title)
|
43
|
+
|
44
|
+
logger&.info "Making request to #{ENDPOINT} for #{url}."
|
45
|
+
response = client.get(url, {'Host' => ENDPOINT.hostname})
|
46
|
+
logger&.info "Got response #{response.inspect}."
|
47
|
+
|
48
|
+
if response.status == 301
|
49
|
+
return lookup(response.headers['HTTP_LOCATION'])
|
50
|
+
else
|
51
|
+
return self.extract_summary(response.body).force_encoding('ASCII-8BIT')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
48
55
|
def self.summary_url(title)
|
49
|
-
"
|
56
|
+
"/api/rest_v1/page/summary/#{CGI.escape title}"
|
50
57
|
end
|
51
58
|
|
52
59
|
def self.extract_summary(json_text)
|
53
60
|
document = JSON.parse(json_text)
|
54
|
-
|
61
|
+
|
62
|
+
return document['extract']
|
55
63
|
rescue
|
56
64
|
return 'Invalid Article.'
|
57
65
|
end
|
@@ -59,9 +67,14 @@ end
|
|
59
67
|
|
60
68
|
# A DNS server that queries Wikipedia and returns summaries for
|
61
69
|
# specifically crafted queries.
|
62
|
-
class WikipediaDNS
|
70
|
+
class WikipediaDNS
|
63
71
|
Name = Resolv::DNS::Name
|
64
72
|
IN = Resolv::DNS::Resource::IN
|
73
|
+
|
74
|
+
INTERFACES = [
|
75
|
+
[:udp, '::', 5300],
|
76
|
+
[:tcp, '::', 5300],
|
77
|
+
]
|
65
78
|
|
66
79
|
def startup
|
67
80
|
# Don't buffer output (for debug purposes)
|
@@ -70,14 +83,17 @@ class WikipediaDNS < Process::Daemon
|
|
70
83
|
stats = { requested: 0 }
|
71
84
|
|
72
85
|
# Start the RubyDNS server
|
73
|
-
RubyDNS.run_server do
|
86
|
+
RubyDNS.run_server(INTERFACES) do
|
74
87
|
on(:start) do
|
75
|
-
Process::Daemon::Privileges.change_user(RUN_AS)
|
88
|
+
# Process::Daemon::Privileges.change_user(RUN_AS)
|
89
|
+
|
76
90
|
if ARGV.include?('--debug')
|
77
91
|
@logger.level = Logger::DEBUG
|
78
92
|
else
|
79
93
|
@logger.level = Logger::WARN
|
80
94
|
end
|
95
|
+
|
96
|
+
@logger.info "Starting Wikipedia DNS..."
|
81
97
|
end
|
82
98
|
|
83
99
|
match(/stats\.wikipedia/, IN::TXT) do |transaction|
|
@@ -87,12 +103,9 @@ class WikipediaDNS < Process::Daemon
|
|
87
103
|
match(/(.+)\.wikipedia/, IN::TXT) do |transaction, match_data|
|
88
104
|
title = match_data[1]
|
89
105
|
stats[:requested] += 1
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
summary =
|
95
|
-
Wikipedia.extract_summary(response).force_encoding('ASCII-8BIT')
|
106
|
+
|
107
|
+
summary = Wikipedia.lookup(title, logger: @logger)
|
108
|
+
|
96
109
|
transaction.respond!(*summary.chunked)
|
97
110
|
end
|
98
111
|
|
@@ -104,4 +117,5 @@ class WikipediaDNS < Process::Daemon
|
|
104
117
|
end
|
105
118
|
end
|
106
119
|
|
107
|
-
WikipediaDNS.
|
120
|
+
wikipedia_dns = WikipediaDNS.new
|
121
|
+
wikipedia_dns.startup
|
data/lib/rubydns/version.rb
CHANGED
data/rubydns.gemspec
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'rubydns/version'
|
1
|
+
|
2
|
+
require_relative 'lib/rubydns/version'
|
5
3
|
|
6
4
|
Gem::Specification.new do |spec|
|
7
5
|
spec.name = "rubydns"
|
@@ -9,17 +7,10 @@ Gem::Specification.new do |spec|
|
|
9
7
|
spec.authors = ["Samuel Williams"]
|
10
8
|
spec.email = ["samuel.williams@oriontransfer.co.nz"]
|
11
9
|
spec.description = <<-EOF
|
12
|
-
RubyDNS
|
13
|
-
other projects or used as a stand-alone daemon. By default it uses
|
14
|
-
rule-based pattern matching. Results can be hard-coded, computed, fetched from
|
15
|
-
a remote DNS server or fetched from a local cache, depending on requirements.
|
16
|
-
|
17
|
-
In addition, RubyDNS includes a high-performance asynchronous DNS resolver
|
18
|
-
built on top of Celluloid. This module can be used by itself in client
|
19
|
-
applications without using the full RubyDNS server stack.
|
10
|
+
RubyDNS provides a rule-based DSL for implementing DNS servers, built on top of `Async::DNS`.
|
20
11
|
EOF
|
21
12
|
spec.summary = "An easy to use DNS server and resolver for Ruby."
|
22
|
-
spec.homepage = "
|
13
|
+
spec.homepage = "https://github.com/socketry/rubydns"
|
23
14
|
spec.license = "MIT"
|
24
15
|
|
25
16
|
spec.files = `git ls-files`.split($/)
|
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: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async-dns
|
@@ -80,13 +80,8 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
description: "\t\tRubyDNS
|
84
|
-
|
85
|
-
pattern matching. Results can be hard-coded, computed, fetched from\n\t\ta remote
|
86
|
-
DNS server or fetched from a local cache, depending on requirements.\n\n\t\tIn addition,
|
87
|
-
RubyDNS includes a high-performance asynchronous DNS resolver\n\t\tbuilt on top
|
88
|
-
of Celluloid. This module can be used by itself in client\n\t\tapplications without
|
89
|
-
using the full RubyDNS server stack.\n"
|
83
|
+
description: "\t\tRubyDNS provides a rule-based DSL for implementing DNS servers,
|
84
|
+
built on top of `Async::DNS`.\n"
|
90
85
|
email:
|
91
86
|
- samuel.williams@oriontransfer.co.nz
|
92
87
|
executables:
|
@@ -125,7 +120,7 @@ files:
|
|
125
120
|
- spec/rubydns/passthrough_spec.rb
|
126
121
|
- spec/rubydns/rules_spec.rb
|
127
122
|
- spec/spec_helper.rb
|
128
|
-
homepage:
|
123
|
+
homepage: https://github.com/socketry/rubydns
|
129
124
|
licenses:
|
130
125
|
- MIT
|
131
126
|
metadata: {}
|
@@ -145,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
140
|
version: '0'
|
146
141
|
requirements: []
|
147
142
|
rubyforge_project:
|
148
|
-
rubygems_version: 2.6
|
143
|
+
rubygems_version: 2.7.6
|
149
144
|
signing_key:
|
150
145
|
specification_version: 4
|
151
146
|
summary: An easy to use DNS server and resolver for Ruby.
|