zonefile 1.02 → 1.03

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ 1.00 - Initial Release
2
+ 1.01 - Fixes
3
+ 1.02 - Fixes
4
+ 1.03 - Fixes TXT records, quotes are not treated anymore
@@ -106,7 +106,15 @@ class Zonefile
106
106
  zf.split(/\n/).map do |line|
107
107
  r = line.gsub(/\t/, ' ')
108
108
  r = r.gsub(/\s+/, ' ')
109
- r = r.gsub(/\;.*$/, '')
109
+ # FIXME: this is ugly and not accurate, couldn't find proper regex:
110
+ # Don't strip ';' if it's quoted. Happens a lot in TXT records.
111
+ (0..(r.length - 1)).find_all { |i| r[i].chr == ';' }.each do |comment_idx|
112
+ if !r[(comment_idx+1)..-1].index(/['"]/) then
113
+ r = r[0..(comment_idx-1)]
114
+ break
115
+ end
116
+ end
117
+ r
110
118
  end.delete_if { |line| line.empty? || line[0].chr == ';'}.join("\n")
111
119
  end
112
120
 
@@ -228,8 +236,8 @@ class Zonefile
228
236
  (#{valid_name})
229
237
  /ix
230
238
  add_record('ptr', :name => $1, :class => $3, :ttl => $2, :host => $4)
231
- elsif line =~ /(#{valid_name})? \s #{ttl_cls} TXT \s \"([^\"]*)\"/ix
232
- add_record('txt', :name => $1, :ttl => $2, :class => $3, :text => $4)
239
+ elsif line =~ /^(#{valid_name})? \s* #{ttl_cls} TXT \s+ (.*)$/ix
240
+ add_record('txt', :name => $1, :ttl => $2, :class => $3, :text => $4.strip)
233
241
  elsif line =~ /\$TTL\s+(#{rr_ttl})/i
234
242
  @ttl = $1
235
243
  end
@@ -250,8 +258,6 @@ class Zonefile
250
258
  ; Database file #{@filename || 'unknown'} for #{@origin || 'unknown'} zone.
251
259
  ; Zone version: #{self.soa[:serial]}
252
260
  ;
253
- #{@origin ? "$ORIGIN #{@origin}" : ''}
254
- #{@ttl ? "$TTL #{@ttl}" : ''}
255
261
  #{self.soa[:origin]} #{self.soa[:ttl]} IN SOA #{self.soa[:primary]} #{self.soa[:email]} (
256
262
  #{self.soa[:serial]} ; serial number
257
263
  #{self.soa[:refresh]} ; refresh
@@ -259,6 +265,10 @@ class Zonefile
259
265
  #{self.soa[:expire]} ; expire
260
266
  #{self.soa[:minimumTTL]} ; minimum TTL
261
267
  )
268
+
269
+ #{@origin ? "$ORIGIN #{@origin}" : ''}
270
+ #{@ttl ? "$TTL #{@ttl}" : ''}
271
+
262
272
  ; Zone NS Records
263
273
  ENDH
264
274
  self.ns.each do |ns|
@@ -269,21 +279,32 @@ ENDH
269
279
  out << "#{mx[:name]} #{mx[:ttl]} #{mx[:class]} MX #{mx[:pri]} #{mx[:host]}\n"
270
280
  end
271
281
 
282
+ out << "\n; Zone A Records\n" unless self.a.empty?
272
283
  self.a.each do |a|
273
284
  out << "#{a[:name]} #{a[:ttl]} #{a[:class]} A #{a[:host]}\n"
274
285
  end
286
+
287
+ out << "\n; Zone CNAME Records\n" unless self.cname.empty?
275
288
  self.cname.each do |cn|
276
289
  out << "#{cn[:name]} #{cn[:ttl]} #{cn[:class]} CNAME #{cn[:host]}\n"
277
290
  end
291
+
292
+ out << "\n; Zone AAAA Records\n" unless self.a4.empty?
278
293
  self.a4.each do |a4|
279
294
  out << "#{a4[:name]} #{a4[:ttl]} #{a4[:class]} AAAA #{a4[:host]}\n"
280
295
  end
296
+
297
+ out << "\n; Zone TXT Records\n" unless self.txt.empty?
281
298
  self.txt.each do |tx|
282
- out << "#{tx[:name]} #{tx[:ttl]} #{tx[:class]} TXT \"#{tx[:text]}\"\n"
299
+ out << "#{tx[:name]} #{tx[:ttl]} #{tx[:class]} TXT #{tx[:text]}\n"
283
300
  end
301
+
302
+ out << "\n; Zone SRV Records\n" unless self.srv.empty?
284
303
  self.srv.each do |srv|
285
304
  out << "#{srv[:name]} #{srv[:ttl]} #{srv[:class]} SRV #{srv[:pri]} #{srv[:weight]} #{srv[:port]} #{srv[:host]}\n"
286
305
  end
306
+
307
+ out << "\n; Zone PTR Records\n" unless self.ptr.empty?
287
308
  self.ptr.each do |ptr|
288
309
  out << "#{ptr[:name]} #{ptr[:ttl]} #{ptr[:class]} PTR #{ptr[:host]}\n"
289
310
  end
@@ -23,12 +23,13 @@ www IN A 127.0.0.1
23
23
  43200 IN A 10.0.0.3
24
24
  IN MX 10 10.0.0.4
25
25
  A 10.0.0.5
26
- TXT "web server"
26
+ TXT "web;server"
27
27
  foo IN A 10.0.0.6
28
28
  mini A 10.0.0.7
29
29
  icarus IN AAAA fe80::0260:83ff:fe7c:3a2a
30
30
  soup IN TXT "This is a text message"
31
- txta TXT "This is another text message"
31
+ txta TXT "t=y; o=-" ; Nasty Comment
32
+ _kerberos IN TXT maxnet.ao
32
33
  _sip._tcp.example.com. 86400 IN SRV 0 5 5060 sipserver.example.com.
33
34
  12.23.21.23.in-addr.arpa IN PTR www.myhost.example.com.
34
35
 
@@ -99,11 +99,17 @@ class TC_Zonefile < Test::Unit::TestCase
99
99
  end
100
100
 
101
101
  def test_txt
102
- assert_equal 'web server', @zf.txt[0][:text]
102
+ puts @zf.txt.inspect
103
+ assert_equal '"web;server"', @zf.txt[0][:text]
103
104
  assert_equal 'IN', @zf.txt[1][:class]
104
105
  assert_equal 'soup', @zf.txt[1][:name]
105
106
  assert_equal 'txta', @zf.txt[2][:name]
106
- assert_equal 3, @zf.txt.size
107
+ assert_equal 'IN', @zf.txt[3][:class]
108
+ assert_equal "\"t=y; o=-\"", @zf.txt[2][:text]
109
+ assert_equal 'maxnet.ao', @zf.txt[3][:text]
110
+ assert_equal '_kerberos', @zf.txt[3][:name]
111
+
112
+ assert_equal 4, @zf.txt.size
107
113
  begin
108
114
  @swap_txt = true
109
115
  swap
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zonefile
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 2
9
- version: "1.02"
8
+ - 3
9
+ version: "1.03"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Martin Boese
@@ -14,11 +14,14 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-10-03 00:00:00 +01:00
17
+ date: 2011-10-12 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
21
- description:
21
+ description: |-
22
+ A library that can create, read, write, modify BIND compatible Zonefiles (RFC1035).
23
+ Warning: It probably works for most cases, but it might not be able to read all files
24
+ even if they are valid for bind.
22
25
  email: martin@internet.ao
23
26
  executables: []
24
27
 
@@ -31,6 +34,7 @@ files:
31
34
  - lib/zonefile.rb
32
35
  - tests/test-zone.db
33
36
  - tests/zonefile.rb
37
+ - CHANGELOG
34
38
  has_rdoc: true
35
39
  homepage: http://zonefile.rubyforge.org/
36
40
  licenses: []