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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f4010f034b073cecd51a4ea2045ce298b0530097
4
- data.tar.gz: f6186728d3d684cd2c00f145f3388387a5fcb38e
2
+ SHA256:
3
+ metadata.gz: b68dbef72ac3c56cca16121d5e09ac0f50b601fb7c23660eafab7dbf1b695e1f
4
+ data.tar.gz: 599604de9a1f63f192052756bd6125331a165c4bee0d704d83b931bf0b85395b
5
5
  SHA512:
6
- metadata.gz: 78c3b49ef16d3833aac7c313d7cc7176209013f855627097d3f4ba7cf0db52bbbc3cccc73bf6fc321c8250363a86cbd99e2eeb0d71882cbbbb6998680a60b8d1
7
- data.tar.gz: f1d4057c218c18e07173dfd4c3e2b84e51dcada6a2f26678fb28949b4d1df9092e99cce673c8602c21b60e64a004915296725c3aaec5ef4988e4a31f9ffc7dd6
6
+ metadata.gz: d44d54b225808fb7ccee61327d42f1fe7b39a3e09606e279103b6bbae12ad4489b9095784123200c398983cff9d1c166b342ad51f0bbec9cf361eb7c7bc8c30d
7
+ data.tar.gz: fc2e9354e124f7649b0499fa25ada6cfffc6760db970823e02a7e89cbfe2e69988e5ea2119aa78ff440a252d9e4b445f73c3c31a85f5f19664b3677f046b459a
data/README.md CHANGED
@@ -1,12 +1,11 @@
1
1
  # RubyDNS
2
2
 
3
- [![Gitter](https://badges.gitter.im/Join+Chat.svg)](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
- [![Build Status](https://travis-ci.org/ioquatix/rubydns.svg)](https://travis-ci.org/ioquatix/rubydns)
8
- [![Code Climate](https://codeclimate.com/github/ioquatix/rubydns.svg)](https://codeclimate.com/github/ioquatix/rubydns)
9
- [![Coverage Status](https://coveralls.io/repos/ioquatix/rubydns/badge.svg)](https://coveralls.io/r/ioquatix/rubydns)
5
+ [![Build Status](https://travis-ci.org/socketry/rubydns.svg)](https://travis-ci.org/socketry/rubydns)
6
+ [![Code Climate](https://codeclimate.com/github/socketry/rubydns.svg)](https://codeclimate.com/github/socketry/rubydns)
7
+ [![Coverage Status](https://coveralls.io/repos/socketry/rubydns/badge.svg)](https://coveralls.io/r/socketry/rubydns)
8
+ [![Gitter](https://badges.gitter.im/join.svg)](https://gitter.im/socketry/rubydns)
10
9
 
11
10
  [![RubyDNS Introduction](http://img.youtube.com/vi/B9ygq0xh3HQ/maxresdefault.jpg)](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
 
@@ -3,5 +3,7 @@ source 'https://rubygems.org'
3
3
  gem 'rubydns', path: '../'
4
4
  gem "process-daemon"
5
5
  gem 'nokogiri'
6
- gem 'http'
6
+
7
+ gem 'async-http'
8
+
7
9
  gem 'geoip'
@@ -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 'http'
36
-
37
- # You might need to change the user name "daemon". This can be a user name
38
- # or a user id.
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
- "http://en.wikipedia.org/w/api.php?action=parse&page=#{CGI.escape title}&prop=text&section=0&format=json"
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
- return Nokogiri::HTML(document['parse']['text']['*']).css('p')[0].text
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 < Process::Daemon
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
- url = Wikipedia.summary_url(title)
92
- response = HTTP.get(url) # socket_class: ... is not yet supported.
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.daemonize
120
+ wikipedia_dns = WikipediaDNS.new
121
+ wikipedia_dns.startup
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module RubyDNS
22
- VERSION = '2.0.1'
22
+ VERSION = '2.0.2'
23
23
  end
@@ -1,7 +1,5 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
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 is a high-performance DNS server which can be easily integrated into
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 = "http://www.codeotaku.com/projects/rubydns"
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.1
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: 2017-07-30 00:00:00.000000000 Z
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 is a high-performance DNS server which can be easily integrated
84
- into\n\t\tother projects or used as a stand-alone daemon. By default it uses\n\t\trule-based
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: http://www.codeotaku.com/projects/rubydns
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.12
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.