ruby-djbdns 0.0.1 → 0.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.
data/COPYING CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2006 Christopher Boumenot
1
+ Copyright (c) 2006-2008 Christopher Boumenot
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of
4
4
  this software and associated documentation files (the "Software"), to deal in
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/lib/djb.rb CHANGED
@@ -1,4 +1,4 @@
1
- # $Id: djb.rb 50 2006-12-21 02:41:47Z boumenot $
1
+ # $Hg: djb.rb,v d39b62a20f42 2008/02/22 21:24:37 boumenot $
2
2
 
3
3
  class File
4
4
  def File.write(filename, string, offset=0)
data/lib/djb/tinydns.rb CHANGED
@@ -1,5 +1,6 @@
1
- # $Id: tinydns.rb 49 2006-12-12 21:01:29Z boumenot $
1
+ # $Hg: tinydns.rb,v d39b62a20f42 2008/02/22 21:24:37 boumenot $
2
2
  require 'djb'
3
+ require 'ipaddr'
3
4
 
4
5
  module DJB
5
6
 
@@ -42,6 +43,7 @@ module DJB
42
43
  def add(entry)
43
44
  @lines << entry.to_s
44
45
  end
46
+ alias :<< :add
45
47
 
46
48
  def add_reverse(args)
47
49
  fqdn = args['ip'].split('.').reverse[1..3].join(".")
@@ -56,7 +58,7 @@ module DJB
56
58
  return @lines.join("\n")
57
59
  end
58
60
 
59
- def to_f
61
+ def to_file
60
62
  File.write(fn(), self.to_s)
61
63
  end
62
64
  end
@@ -74,6 +76,7 @@ module DJB
74
76
  def add(res)
75
77
  @resources << res.to_s + ":#{@name}"
76
78
  end
79
+ alias :<< :add
77
80
 
78
81
  def to_s
79
82
  return @resources.join("\n")
@@ -94,8 +97,8 @@ module DJB
94
97
  @fqdn = args['fqdn']
95
98
  end
96
99
 
97
- def encode(s)
98
- s.gsub(/[^0-9a-zA-Z]/) { |m| sprintf("\\%.3o", m[0]) }
100
+ def encode
101
+ data.gsub(/[^0-9a-zA-Z]/) { |m| sprintf("\\%.3o", m[0]) }
99
102
  end
100
103
 
101
104
  def to_s
@@ -130,7 +133,7 @@ module DJB
130
133
 
131
134
  @fields << @fqdn
132
135
  @fields << (args.has_key?('TypeValue') ? args['TypeValue'] : self.class::TypeValue)
133
- @fields << encode(@data)
136
+ @fields << encode
134
137
  @fields << @ttl
135
138
  @fields << @timestamp
136
139
  end
@@ -300,7 +303,7 @@ module DJB
300
303
  @data = @args['data']
301
304
 
302
305
  @fields << @fqdn
303
- @fields << encode(data)
306
+ @fields << encode
304
307
  @fields << @ttl
305
308
  @fields << @timestamp
306
309
  end
@@ -320,6 +323,14 @@ module DJB
320
323
 
321
324
  class AAAA < Generic
322
325
  TypeValue = 28
326
+
327
+ def encode
328
+ ipv6 = IPAddr.new(@data)
329
+ a = ipv6.to_string.gsub(':', '').scan(/../).inject([]) do |acc,x|
330
+ acc << sprintf('\\%.3o', x.to_i(16))
331
+ end
332
+ return a.join('')
333
+ end
323
334
  end
324
335
 
325
336
  class LOC < Generic
@@ -388,7 +399,7 @@ module DJB
388
399
  return s
389
400
  end
390
401
 
391
- def to_f
402
+ def to_file
392
403
  File.write(fn(), to_s())
393
404
  end
394
405
  end
data/sample/axfr.rb CHANGED
@@ -16,7 +16,7 @@ axfr.deny('172.16.100.5', '1.16.172.in-addr.arpa')
16
16
  puts axfr
17
17
 
18
18
  # print the axfr files to the _tcp_ file
19
- # axfr.to_f
19
+ # axfr.to_file
20
20
 
21
21
 
22
22
  # Local Variables:
data/sample/resolver.rb CHANGED
@@ -1,40 +1,41 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'djb/tinydns'
4
+ include DJB::TinyDNS
4
5
 
5
- tinydns = DJB::TinyDNS::Resolver.new('/etc/tinydns', '/usr/local/bin/svc')
6
+ tinydns = Resolver.new('/etc/tinydns', '/usr/local/bin/svc')
6
7
 
7
- tinydns.add(DJB::TinyDNS::NS::DelegateFrom.new({'fqdn' => 'example.net', 'ip' => '172.16.1.1'}))
8
- tinydns.add(DJB::TinyDNS::NS::DelegateFrom.new({'fqdn' => '1.16.172.in-addr.arpa', 'ip' => '172.16.1.1'}))
8
+ tinydns << NS::DelegateFrom.new({'fqdn' => 'example.net', 'ip' => '172.16.1.1'})
9
+ tinydns << NS::DelegateFrom.new({'fqdn' => '1.16.172.in-addr.arpa', 'ip' => '172.16.1.1'})
9
10
  # -or-
10
- # tinydns.add_reverse({'ip' => '172.16.1.1'})
11
-
12
- tinydns.add(DJB::TinyDNS::Host.new( {'fqdn' => 'ace.example.net', 'ip' => '172.16.1.1'}))
13
- tinydns.add(DJB::TinyDNS::Host.new( {'fqdn' => 'gary.example.net', 'ip' => '172.16.1.2'}))
14
- tinydns.add(DJB::TinyDNS::A.new( {'fqdn' => 'www.example.net', 'ip' => '172.16.1.1'}))
15
- tinydns.add(DJB::TinyDNS::A.new( {'fqdn' => 'ftp.example.net', 'ip' => '172.16.1.1'}))
16
- tinydns.add(DJB::TinyDNS::A.new( {'fqdn' => 'ssh.example.net', 'ip' => '172.16.1.1'}))
17
- tinydns.add(DJB::TinyDNS::A.new( {'fqdn' => 'tftp.example.net', 'ip' => '172.16.1.2'}))
18
- tinydns.add(DJB::TinyDNS::CNAME.new({'fqdn' => 'gary.example.net', 'alias' => 'rsh.example.net'}))
19
- tinydns.add(DJB::TinyDNS::CNAME.new({'fqdn' => 'gary.example.net', 'alias' => 'telnet.example.net'}))
20
- tinydns.add(DJB::TinyDNS::CNAME.new({'fqdn' => 'gary.example.net', 'alias' => 'ntp.example.net'}))
21
- tinydns.add(DJB::TinyDNS::MX.new( {'fqdn' => 'example.net', 'host' => 'gary.example.net', 'distance' => 10}))
22
-
23
- intranet = DJB::TinyDNS::Location.new('intranet', '10.0.0')
24
- intranet.add(DJB::TinyDNS::Host.new({'fqdn' => 'ace.example.net', 'ip' => '10.0.0.1'}))
25
- intranet.add(DJB::TinyDNS::Host.new({'fqdn' => 'gary.example.net', 'ip' => '10.0.0.2'}))
26
- tinydns.add(intranet)
27
-
28
- vpn = DJB::TinyDNS::Location.new('vpn', '192.168')
29
- vpn.add(DJB::TinyDNS::Host.new({'fqdn' => 'ace.example.net', 'ip' => '192.168.1.1'}))
30
- vpn.add(DJB::TinyDNS::Host.new({'fqdn' => 'gary.example.net', 'ip' => '192.168.1.2'}))
31
- tinydns.add(vpn)
11
+ # tinydns << _reverse({'ip' => '172.16.1.1'})
12
+
13
+ tinydns << Host.new( {'fqdn' => 'ace.example.net', 'ip' => '172.16.1.1'})
14
+ tinydns << Host.new( {'fqdn' => 'gary.example.net', 'ip' => '172.16.1.2'})
15
+ tinydns << A.new( {'fqdn' => 'www.example.net', 'ip' => '172.16.1.1'})
16
+ tinydns << A.new( {'fqdn' => 'ftp.example.net', 'ip' => '172.16.1.1'})
17
+ tinydns << A.new( {'fqdn' => 'ssh.example.net', 'ip' => '172.16.1.1'})
18
+ tinydns << A.new( {'fqdn' => 'tftp.example.net', 'ip' => '172.16.1.2'})
19
+ tinydns << CNAME.new({'fqdn' => 'gary.example.net', 'alias' => 'rsh.example.net'})
20
+ tinydns << CNAME.new({'fqdn' => 'gary.example.net', 'alias' => 'telnet.example.net'})
21
+ tinydns << CNAME.new({'fqdn' => 'gary.example.net', 'alias' => 'ntp.example.net'})
22
+ tinydns << MX.new( {'fqdn' => 'example.net', 'host' => 'gary.example.net', 'distance' => 10})
23
+
24
+ intranet = Location.new('intranet', '10.0.0')
25
+ intranet << Host.new({'fqdn' => 'ace.example.net', 'ip' => '10.0.0.1'})
26
+ intranet << Host.new({'fqdn' => 'gary.example.net', 'ip' => '10.0.0.2'})
27
+ tinydns << intranet
28
+
29
+ vpn = Location.new('vpn', '192.168')
30
+ vpn << Host.new({'fqdn' => 'ace.example.net', 'ip' => '192.168.1.1'})
31
+ vpn << Host.new({'fqdn' => 'gary.example.net', 'ip' => '192.168.1.2'})
32
+ tinydns << vpn
32
33
 
33
34
  # print the tinydns file to the screen
34
35
  puts tinydns
35
36
 
36
37
  # print the tinydns files to the _data_ file
37
- # tinydns.to_f
38
+ # tinydns.to_file
38
39
 
39
40
 
40
41
  # Local Variables:
data/test/axfr.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # $Id: axfr.rb 50 2006-12-21 02:41:47Z boumenot $
2
+ # $Hg: axfr.rb,v d39b62a20f42 2008/02/22 21:24:37 boumenot $
3
3
 
4
4
  require 'test/unit'
5
5
  require 'djb/tinydns'
data/test/resolver.rb CHANGED
@@ -1,19 +1,19 @@
1
1
  #!/usr/bin/env ruby
2
- # $Id: resolver.rb 50 2006-12-21 02:41:47Z boumenot $
2
+ # $Hg: resolver.rb,v d39b62a20f42 2008/02/22 21:24:37 boumenot $
3
3
 
4
4
  require 'test/unit'
5
5
  require 'djb/tinydns'
6
6
 
7
7
  EVERYTHING = {
8
- 'fqdn' => 'ace.example.net',
9
- 'ip' => '172.16.1.100',
10
- 'host' => 'gary.example.net',
11
- 'alias' => 'agd.example.net',
12
- 'mname' => 'dns.example.net',
13
- 'rname' => 'admin.example.net',
14
- 'distance' => 10,
15
- 'data' => 'Robert Smigel',
16
- 'TypeValue' => 1001,
8
+ 'fqdn' => 'ace.example.net',
9
+ 'ip' => '172.16.1.100',
10
+ 'host' => 'gary.example.net',
11
+ 'alias' => 'agd.example.net',
12
+ 'mname' => 'dns.example.net',
13
+ 'rname' => 'admin.example.net',
14
+ 'distance' => 10,
15
+ 'data' => '1234::4321',
16
+ 'TypeValue' => 1001,
17
17
  }
18
18
 
19
19
  def module_walk(clss)
@@ -25,70 +25,81 @@ def module_walk(clss)
25
25
  end
26
26
 
27
27
  class TC_Prefix < Test::Unit::TestCase
28
- def test_prefix
29
- e = {
30
- 'Host' => '=',
31
- 'Generic' => ':',
32
- 'A' => '+',
33
- 'NS::DelegateTo' => '&',
34
- 'NS::DelegateFrom' => '.',
35
- 'CNAME' => 'C',
36
- 'SOA' => 'Z',
37
- 'PTR' => '^',
38
- 'MX' => '@',
39
- 'TXT' => '\'',
28
+ def test_prefix
29
+ e = {
30
+ 'Host' => '=',
31
+ 'Generic' => ':',
32
+ 'A' => '+',
33
+ 'NS::DelegateTo' => '&',
34
+ 'NS::DelegateFrom' => '.',
35
+ 'CNAME' => 'C',
36
+ 'SOA' => 'Z',
37
+ 'PTR' => '^',
38
+ 'MX' => '@',
39
+ 'TXT' => '\'',
40
40
 
41
- 'AAAA' => ':',
42
- 'WKS' => ':',
43
- 'SRV' => ':',
44
- 'NULL' => ':',
45
- 'HINFO' => ':',
46
- 'MINFO' => ':',
47
- }
41
+ 'AAAA' => ':',
42
+ 'WKS' => ':',
43
+ 'SRV' => ':',
44
+ 'NULL' => ':',
45
+ 'HINFO' => ':',
46
+ 'MINFO' => ':',
47
+ }
48
48
 
49
- e.each do |k,expected|
50
- mod = module_walk("DJB::TinyDNS::#{k}")
51
- actual = mod.new(EVERYTHING).to_s[0].chr
52
- assert(actual == expected, "prefix: expected=#{expected}, actual=#{actual}")
49
+ e.each do |k,expected|
50
+ mod = module_walk("DJB::TinyDNS::#{k}")
51
+ actual = mod.new(EVERYTHING).to_s[0].chr
52
+ assert(actual == expected, "prefix: expected=#{expected}, actual=#{actual}")
53
+ end
53
54
  end
54
- end
55
55
  end
56
56
 
57
57
  class TC_Accessor < Test::Unit::TestCase
58
- def test_accessor
59
- e = {
60
- :ttl => %w{Host Generic A NS::DelegateTo NS::DelegateFrom CNAME SOA PTR MX TXT},
61
- :timestamp => %w{Host Generic A NS::DelegateTo NS::DelegateFrom CNAME SOA PTR MX TXT},
62
- :alias => %w{CNAME},
63
- :mname => %w{SOA},
64
- :rname => %w{SOA},
65
- :host => %w{NS::DelegateTo NS::DelegateFrom PTR MX},
66
- :distance => %w{MX},
67
- :data => %w{Generic TXT},
68
- :ip => %w{A NS::DelegateTo NS::DelegateFrom},
69
- }
58
+ def test_accessor
59
+ e = {
60
+ :ttl => %w{Host Generic A NS::DelegateTo NS::DelegateFrom CNAME SOA PTR MX TXT},
61
+ :timestamp => %w{Host Generic A NS::DelegateTo NS::DelegateFrom CNAME SOA PTR MX TXT},
62
+ :alias => %w{CNAME},
63
+ :mname => %w{SOA},
64
+ :rname => %w{SOA},
65
+ :host => %w{NS::DelegateTo NS::DelegateFrom PTR MX},
66
+ :distance => %w{MX},
67
+ :data => %w{Generic TXT},
68
+ :ip => %w{A NS::DelegateTo NS::DelegateFrom},
69
+ }
70
70
 
71
- e.each do |k,v|
72
- v.each do |c|
73
- mod = module_walk("DJB::TinyDNS::#{c}")
74
- assert(mod.new(EVERYTHING).respond_to?(k), "DJB::TinyDNS::#{c} does not respond to #{k}")
75
- end
76
- end
77
- end
71
+ e.each do |k,v|
72
+ v.each do |c|
73
+ mod = module_walk("DJB::TinyDNS::#{c}")
74
+ assert(mod.new(EVERYTHING).respond_to?(k), "DJB::TinyDNS::#{c} does not respond to #{k}")
75
+ end
76
+ end
77
+ end
78
+ end
78
79
 
79
- class TC_Location < Test::Unit::TestCase
80
+ class TC_Location < Test::Unit::TestCase
80
81
  def test_location
81
- loc = DJB::TinyDNS::Location.new('intranet', '192.168')
82
- loc.add(DJB::TinyDNS::Host.new(EVERYTHING))
82
+ loc = DJB::TinyDNS::Location.new('intranet', '192.168')
83
+ loc.add(DJB::TinyDNS::Host.new(EVERYTHING))
83
84
 
84
- first, second = loc.to_s.split("\n")
85
+ first, second = loc.to_s.split("\n")
85
86
 
86
- assert(/^%intranet/.match(first), "location: expected /^%intranet/, actual=#{first}")
87
- assert(/^\=/.match(second), "location: expected /^=.*/, actual #{second}")
87
+ assert(/^%intranet/.match(first), "location: expected /^%intranet/, actual=#{first}")
88
+ assert(/^\=/.match(second), "location: expected /^=.*/, actual #{second}")
88
89
  end
89
- end
90
+ end
90
91
 
92
+ class TC_ExpectedResult < Test::Unit::TestCase
93
+ def test_aaaa
94
+ exp = '\\022\\064\\126\\170\\232\\274\\015\\357\\000\\000\\000\\000\\000\\000\\376\\334'
95
+ quad = DJB::TinyDNS::AAAA.new({'fqdn' => 'www.example.net', 'data' => '1234:5678:9abc:def::fedc'})
91
96
 
97
+ a = quad.to_s.split(':')
98
+
99
+ assert_equal(a[1], 'www.example.net')
100
+ assert_equal(a[2], DJB::TinyDNS::AAAA::TypeValue.to_s)
101
+ assert_equal(a[3], exp)
102
+ end
92
103
  end
93
104
 
94
105
  # Local Variables:
data/test/runner.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # $Id: runner.rb 50 2006-12-21 02:41:47Z boumenot $
2
+ # $Hg: runner.rb,v d39b62a20f42 2008/02/22 21:24:37 boumenot $
3
3
 
4
4
  $: << File.dirname(__FILE__) + '/../lib'
5
5
  require 'test/unit'
@@ -8,10 +8,10 @@ if not (File.exists?('resolver.rb'))
8
8
  raise 'The test suite should only be run from the test directory.'
9
9
  end
10
10
 
11
- Dir.glob("#{File.dirname(__FILE__)}/*.rb").each() { |filename|
11
+ Dir.glob("#{File.dirname(__FILE__)}/*.rb").each() do |filename|
12
12
  next if filename == 'runner.rb'
13
13
  require(filename)
14
- }
14
+ end
15
15
 
16
16
  # Local Variables:
17
17
  # mode: ruby
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: ruby-djbdns
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.1
7
- date: 2006-12-30 00:00:00 -05:00
6
+ version: 0.0.2
7
+ date: 2008-02-22 00:00:00 -05:00
8
8
  summary: Ruby module to manage TinyDNS
9
9
  require_paths:
10
10
  - lib
@@ -25,27 +25,29 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
25
25
  platform: ruby
26
26
  signing_key:
27
27
  cert_chain:
28
+ post_install_message:
28
29
  authors:
29
30
  - Christopher Boumenot
30
31
  files:
31
- - sample
32
32
  - lib
33
- - VERSION
34
- - README
35
- - test
36
33
  - FILES
34
+ - pkg
37
35
  - COPYING
38
- - sample/axfr.rb
39
- - sample/resolver.rb
36
+ - README
37
+ - sample
38
+ - test
39
+ - VERSION
40
40
  - lib/djb.rb
41
41
  - lib/djb/tinydns.rb
42
+ - sample/resolver.rb
43
+ - sample/axfr.rb
42
44
  - test/resolver.rb
43
- - test/axfr.rb
44
45
  - test/runner.rb
46
+ - test/axfr.rb
45
47
  test_files:
46
48
  - test/resolver.rb
47
- - test/axfr.rb
48
49
  - test/runner.rb
50
+ - test/axfr.rb
49
51
  rdoc_options: []
50
52
 
51
53
  extra_rdoc_files: []