dirndl 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/bin/dirndl +6 -0
- data/dirndl.gemspec +23 -0
- data/lib/dirndl.rb +21 -0
- data/lib/dirndl/command_line.rb +43 -0
- data/lib/dirndl/resolver.rb +35 -0
- data/lib/dirndl/version.rb +3 -0
- metadata +78 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/dirndl
ADDED
data/dirndl.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "dirndl/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "dirndl"
|
7
|
+
s.version = Dirndl::VERSION
|
8
|
+
s.authors = ["Craig R Webster"]
|
9
|
+
s.email = ["craig@barkingiguana.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{A terribly naive DNS zone server}
|
12
|
+
s.description = %q{Use Latte and DNS::Zonefile to serve text based zonefiles via DNS. This is a toy project, I don't intend to use it in production anywhere.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "dirndl"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_runtime_dependency "latte"
|
22
|
+
s.add_runtime_dependency "dns-zonefile", ">= 1.0.0"
|
23
|
+
end
|
data/lib/dirndl.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "pethau"
|
2
|
+
|
3
|
+
class Object
|
4
|
+
include Pethau::InitializeWith
|
5
|
+
include Pethau::DefaultValueOf
|
6
|
+
include Pethau::PrivateAttrAccessor
|
7
|
+
end
|
8
|
+
|
9
|
+
require "logger"
|
10
|
+
require "optparse"
|
11
|
+
require "ostruct"
|
12
|
+
|
13
|
+
require "latte"
|
14
|
+
require "dns/zonefile"
|
15
|
+
|
16
|
+
require "dirndl/version"
|
17
|
+
require "dirndl/resolver"
|
18
|
+
require "dirndl/command_line"
|
19
|
+
|
20
|
+
module Dirndl
|
21
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Dirndl
|
2
|
+
class CommandLine
|
3
|
+
initialize_with :arguments
|
4
|
+
|
5
|
+
def parse_arguments
|
6
|
+
parsed = { addresses: [] }
|
7
|
+
OptionParser.new do |o|
|
8
|
+
o.on '-l', '--listen ADDRESS', 'Serve DNS on this address' do |addr|
|
9
|
+
address = Latte::Address.new addr
|
10
|
+
parsed[:addresses] << address
|
11
|
+
parsed[:addresses].uniq!
|
12
|
+
end
|
13
|
+
|
14
|
+
o.on '-z', '--zone-db PATH', 'Path to the root of the zone db' do |path|
|
15
|
+
parsed[:zone_db] = path
|
16
|
+
end
|
17
|
+
|
18
|
+
o.separator ''
|
19
|
+
o.separator 'Common options:'
|
20
|
+
|
21
|
+
o.on_tail '-h', '--help', 'Show this message' do
|
22
|
+
puts o
|
23
|
+
exit
|
24
|
+
end
|
25
|
+
|
26
|
+
o.on_tail '--version', 'Show version' do
|
27
|
+
puts Dirndl::VERSION
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
end.parse arguments
|
31
|
+
OpenStruct.new parsed
|
32
|
+
end
|
33
|
+
|
34
|
+
def execute
|
35
|
+
arguments = parse_arguments
|
36
|
+
resolver = Resolver.new arguments.zone_db
|
37
|
+
logger = Logger.new STDOUT
|
38
|
+
server = Latte::Server.new resolver, logger
|
39
|
+
server.listen_on *arguments.addresses
|
40
|
+
server.run
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Dirndl
|
2
|
+
class Resolver
|
3
|
+
initialize_with :zone_db_root_path
|
4
|
+
|
5
|
+
def call query, response
|
6
|
+
zone = load_zone_for query.human_qname
|
7
|
+
return unless zone
|
8
|
+
zone.records_of(DNS::Zonefile::A).each do |rr|
|
9
|
+
next unless rr.host == query.human_qname
|
10
|
+
answer = "#{rr.host} #{rr.klass} A #{rr.ttl} #{rr.address}"
|
11
|
+
response.add answer
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def load_zone_for qname
|
16
|
+
parts = qname.split /\./
|
17
|
+
parts.reverse!
|
18
|
+
zone_file_path = parts.inject(zone_db_root_path) { |path, part|
|
19
|
+
file = File.join path, "#{part}.zone"
|
20
|
+
if File.exists? file
|
21
|
+
file
|
22
|
+
else
|
23
|
+
|
24
|
+
if path !~ /\.zone$/
|
25
|
+
File.join path, part
|
26
|
+
else
|
27
|
+
path
|
28
|
+
end
|
29
|
+
end
|
30
|
+
}
|
31
|
+
return unless zone_file_path =~ /\.zone$/
|
32
|
+
DNS::Zonefile.load File.read(zone_file_path)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dirndl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Craig R Webster
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-26 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: latte
|
16
|
+
requirement: &70207096539080 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70207096539080
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: dns-zonefile
|
27
|
+
requirement: &70207096538580 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.0.0
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70207096538580
|
36
|
+
description: Use Latte and DNS::Zonefile to serve text based zonefiles via DNS. This
|
37
|
+
is a toy project, I don't intend to use it in production anywhere.
|
38
|
+
email:
|
39
|
+
- craig@barkingiguana.com
|
40
|
+
executables:
|
41
|
+
- dirndl
|
42
|
+
extensions: []
|
43
|
+
extra_rdoc_files: []
|
44
|
+
files:
|
45
|
+
- .gitignore
|
46
|
+
- Gemfile
|
47
|
+
- Rakefile
|
48
|
+
- bin/dirndl
|
49
|
+
- dirndl.gemspec
|
50
|
+
- lib/dirndl.rb
|
51
|
+
- lib/dirndl/command_line.rb
|
52
|
+
- lib/dirndl/resolver.rb
|
53
|
+
- lib/dirndl/version.rb
|
54
|
+
homepage: ''
|
55
|
+
licenses: []
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project: dirndl
|
74
|
+
rubygems_version: 1.8.10
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: A terribly naive DNS zone server
|
78
|
+
test_files: []
|