bind9mgr 0.3.12 → 0.3.13
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/History.txt +5 -0
- data/lib/bind9mgr.rb +1 -1
- data/lib/parser.rb +43 -8
- data/spec/parser_spec.rb +13 -1
- metadata +27 -6
data/History.txt
CHANGED
data/lib/bind9mgr.rb
CHANGED
data/lib/parser.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module Bind9mgr
|
2
|
-
|
2
|
+
# this TYPES will be parsed with simplified state_rules chain
|
3
|
+
TYPES = %w{A CNAME PTR NS SRV} # SOA, MX, TXT - are different
|
3
4
|
class Parser
|
4
5
|
|
5
6
|
attr_reader :state
|
@@ -12,9 +13,10 @@ module Bind9mgr
|
|
12
13
|
@STATE_RULES =
|
13
14
|
# [current_state, target_state, proc to perform(token will be passe in)
|
14
15
|
[ [:start, :origin, Proc.new{ |t| t == '$ORIGIN' }],
|
15
|
-
[:origin, :
|
16
|
+
[:origin, :last_token_in_a_row, Proc.new{ |t| set_origin t }],
|
16
17
|
[:start, :ttl, Proc.new{ |t| t == '$TTL' }],
|
17
|
-
[:ttl, :
|
18
|
+
[:ttl, :last_token_in_a_row, Proc.new{ |t| set_ttl t }],
|
19
|
+
[:last_token_in_a_row, :start, Proc.new{ |t| t == "\n" ? true : false }],
|
18
20
|
[:start, :type, Proc.new{ |t| TYPES.include?(t) ? add_rr(nil, nil, nil, t, nil) : false }],
|
19
21
|
[:start, :klass, Proc.new{ |t| KLASSES.include?(t) ? add_rr(nil, nil, t, nil, nil) : false }],
|
20
22
|
[:start, :rttl, Proc.new{ |t| t.match(/^\d+$/) ? add_rr(nil, t, nil, nil, nil) : false }],
|
@@ -23,11 +25,13 @@ module Bind9mgr
|
|
23
25
|
[:owner, :klass, Proc.new{ |t| KLASSES.include?(t) ? update_last_rr(nil, nil, t, nil, nil) : false }],
|
24
26
|
[:owner, :type, Proc.new{ |t| TYPES.include?(t) ? update_last_rr(nil, nil, nil, t, nil) : false }],
|
25
27
|
[:owner, :mx, Proc.new{ |t| t == 'MX' ? update_last_rr(nil, nil, nil, t, nil) : false }],
|
28
|
+
[:owner, :txt, Proc.new{ |t| t == 'TXT' ? update_last_rr(nil, nil, nil, t, nil) : false }],
|
26
29
|
[:rttl, :klass, Proc.new{ |t| KLASSES.include?(t) ? update_last_rr(nil, nil, t, nil, nil) : false }],
|
27
30
|
[:klass, :type, Proc.new{ |t| TYPES.include?(t) ? update_last_rr(nil, nil, nil, t, nil) : false }],
|
28
|
-
[:type, :
|
31
|
+
[:type, :last_token_in_a_row, Proc.new{ |t| update_last_rr(nil, nil, nil, nil, t) }],
|
29
32
|
[:klass, :soa, Proc.new{ |t| t == 'SOA' ? update_last_rr(nil, nil, nil, t, nil) : false }],
|
30
|
-
[:soa, :
|
33
|
+
[:soa, :last_token_in_a_row, Proc.new{ |t| rdata = [t] + @tokens.shift(@tokens.index(')'))
|
34
|
+
rdata.select!{|tt| tt != "\n" }
|
31
35
|
raise ParserError, "Zone parsing error: parentices expected in SOA record.\n#{@content}" if (rdata[2] != '(') && (@tokens.first != ')')
|
32
36
|
rdata.delete_at(2)
|
33
37
|
@result.options[:support_email] = rdata[1]
|
@@ -40,7 +44,8 @@ module Bind9mgr
|
|
40
44
|
@tokens.shift
|
41
45
|
}],
|
42
46
|
[:klass, :mx, Proc.new{ |t| t == 'MX' ? update_last_rr(nil, nil, nil, t, nil) : false }],
|
43
|
-
[:mx, :
|
47
|
+
[:mx, :last_token_in_a_row, Proc.new{ |t| update_last_rr(nil, nil, nil, nil, [t] + [@tokens.shift]) }],
|
48
|
+
[:txt, :last_token_in_a_row, Proc.new{ |t| update_last_rr(nil, nil, nil, nil, ([t] + [@tokens.shift(@tokens.index("\n"))]).join(" ")) }] # '\t' symbol is lost here! may be a BUG
|
44
49
|
]
|
45
50
|
end
|
46
51
|
|
@@ -48,6 +53,8 @@ module Bind9mgr
|
|
48
53
|
@content = str # for debugging
|
49
54
|
@tokens = tokenize( str )
|
50
55
|
|
56
|
+
puts @tokens.inspect
|
57
|
+
|
51
58
|
cntr = 0
|
52
59
|
while @tokens.size > 0
|
53
60
|
token = @tokens.shift
|
@@ -65,7 +72,7 @@ module Bind9mgr
|
|
65
72
|
@state = current_edge[1] if flag
|
66
73
|
end
|
67
74
|
|
68
|
-
raise( ParserError, "no successful rules found. cur_state: #{@state}, token: #{token}" ) unless flag
|
75
|
+
raise( ParserError, "no successful rules found. cur_state: #{@state}, token: #{token}, next tokens: #{@tokens.inspect}" ) unless flag
|
69
76
|
cntr += 1
|
70
77
|
end
|
71
78
|
|
@@ -77,7 +84,35 @@ module Bind9mgr
|
|
77
84
|
private
|
78
85
|
|
79
86
|
def tokenize str
|
80
|
-
str.gsub(/;.*$/, '').split(
|
87
|
+
dirty_tokens = str.gsub(/;.*$/, '').split(/[ \t\r]/)
|
88
|
+
|
89
|
+
puts dirty_tokens.inspect
|
90
|
+
|
91
|
+
tokens = []
|
92
|
+
dirty_tokens.each do |t|
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
if t.index("\n")
|
97
|
+
puts "n found: #{t.inspect}"
|
98
|
+
while t.index("\n") do
|
99
|
+
i = t.index("\n")-1
|
100
|
+
puts "slice: #{i}, #{t.slice(0..(i >= 0 ? i : 0))}"
|
101
|
+
tokens << t.slice!(0..i) if i >= 0
|
102
|
+
puts "after slice: #{t.inspect}"
|
103
|
+
tokens << "\n"
|
104
|
+
puts "cut:" + t.slice!(0..0).inspect
|
105
|
+
end
|
106
|
+
puts "add after cut:#{t.inspect}"
|
107
|
+
tokens << t
|
108
|
+
else
|
109
|
+
puts "just add:#{t}"
|
110
|
+
tokens << t
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
tokens.select{|s|s.length > 0}
|
81
116
|
end
|
82
117
|
|
83
118
|
def get_options
|
data/spec/parser_spec.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Bind9mgr::Parser do
|
4
|
+
|
5
|
+
# first rrs are used by index at some tests so dont change their sequence
|
4
6
|
let(:test_zone) do
|
5
|
-
%
|
7
|
+
%Q{$ORIGIN cloud.ru.
|
6
8
|
$TTL 86400 ; 1 day
|
7
9
|
@ IN SOA cloud.ru. root.cloud.ru. (
|
8
10
|
2011083002 ; serial
|
@@ -17,6 +19,8 @@ nfsstorage IN CNAME ns
|
|
17
19
|
mail IN MX 40 192.168.1.33
|
18
20
|
www CNAME @
|
19
21
|
cloud.ru. IN A 192.168.1.1
|
22
|
+
human-txt TXT 'this is text with spases'
|
23
|
+
|
20
24
|
NS ns2.cloud.ru
|
21
25
|
manager IN A 192.168.1.20
|
22
26
|
director IN A 192.168.1.23
|
@@ -97,6 +101,14 @@ esx1 IN A 192.168.1.2
|
|
97
101
|
rr.rdata.should eql('192.168.1.200')
|
98
102
|
end
|
99
103
|
|
104
|
+
it "should parse TXT records" do
|
105
|
+
rr = @result.records[7]
|
106
|
+
rr.type.should == 'TXT'
|
107
|
+
rr.owner.should eql('human-txt')
|
108
|
+
rr.klass.should eql(nil)
|
109
|
+
rr.rdata.should eql("'this is text with spases'")
|
110
|
+
end
|
111
|
+
|
100
112
|
it "should parse MX records(and mx priority!)" do
|
101
113
|
rr = @result.records[4]
|
102
114
|
rr.type.should == 'MX'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bind9mgr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.13
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,19 +9,40 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rdoc
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.10'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.10'
|
14
30
|
- !ruby/object:Gem::Dependency
|
15
31
|
name: hoe
|
16
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
17
33
|
none: false
|
18
34
|
requirements:
|
19
35
|
- - ~>
|
20
36
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
37
|
+
version: '3.5'
|
22
38
|
type: :development
|
23
39
|
prerelease: false
|
24
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.5'
|
25
46
|
description: This gem contains some classes to manage bind9 zone files
|
26
47
|
email:
|
27
48
|
- mikhail@mad-box.ru
|
@@ -72,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
93
|
version: '0'
|
73
94
|
requirements: []
|
74
95
|
rubyforge_project: bind9mgr
|
75
|
-
rubygems_version: 1.8.
|
96
|
+
rubygems_version: 1.8.24
|
76
97
|
signing_key:
|
77
98
|
specification_version: 3
|
78
99
|
summary: This gem contains some classes to manage bind9 zone files
|