bind9mgr 0.3.13 → 0.3.14
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/lib/bind9mgr.rb +1 -1
- data/lib/parser.rb +27 -14
- data/spec/parser_spec.rb +16 -0
- metadata +2 -2
data/History.txt
CHANGED
data/lib/bind9mgr.rb
CHANGED
data/lib/parser.rb
CHANGED
@@ -1,6 +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
|
3
|
+
TYPES = %w{A CNAME PTR NS} # SOA, MX, TXT, SRV - are different
|
4
4
|
class Parser
|
5
5
|
|
6
6
|
attr_reader :state
|
@@ -10,26 +10,40 @@ module Bind9mgr
|
|
10
10
|
@state = :start
|
11
11
|
@result = Zone.new
|
12
12
|
|
13
|
+
@SHARED_RULES = {
|
14
|
+
:txt => Proc.new{ |t| t == 'TXT' ? update_last_rr(nil, nil, nil, t, nil) : false },
|
15
|
+
:mx => Proc.new{ |t| t == 'MX' ? update_last_rr(nil, nil, nil, t, nil) : false },
|
16
|
+
:srv => Proc.new{ |t| t == 'SRV' ? update_last_rr(nil, nil, nil, t, nil) : false }
|
17
|
+
}
|
18
|
+
|
13
19
|
@STATE_RULES =
|
14
20
|
# [current_state, target_state, proc to perform(token will be passe in)
|
15
|
-
[ [:
|
16
|
-
[:origin, :last_token_in_a_row, Proc.new{ |t| set_origin t }],
|
17
|
-
[:start, :ttl, Proc.new{ |t| t == '$TTL' }],
|
21
|
+
[ [:origin, :last_token_in_a_row, Proc.new{ |t| set_origin t }],
|
18
22
|
[:ttl, :last_token_in_a_row, Proc.new{ |t| set_ttl t }],
|
19
23
|
[:last_token_in_a_row, :start, Proc.new{ |t| t == "\n" ? true : false }],
|
20
|
-
[:start, :type, Proc.new{ |t| TYPES.include?(t) ? add_rr(nil, nil, nil, t, nil) : false }],
|
21
|
-
[:start, :klass, Proc.new{ |t| KLASSES.include?(t) ? add_rr(nil, nil, t, nil, nil) : false }],
|
22
|
-
[:start, :rttl, Proc.new{ |t| t.match(/^\d+$/) ? add_rr(nil, t, nil, nil, nil) : false }],
|
23
|
-
[:start, :owner, Proc.new{ |t| add_rr(t, nil, nil, nil, nil) }],
|
24
24
|
[:owner, :rttl, Proc.new{ |t| t.match(/^\d+$/) ? update_last_rr(nil, t, nil, nil, nil) : false }],
|
25
25
|
[:owner, :klass, Proc.new{ |t| KLASSES.include?(t) ? update_last_rr(nil, nil, t, nil, nil) : false }],
|
26
26
|
[:owner, :type, Proc.new{ |t| TYPES.include?(t) ? update_last_rr(nil, nil, nil, t, nil) : false }],
|
27
|
-
[:owner, :mx,
|
28
|
-
[:owner, :
|
27
|
+
[:owner, :mx, @SHARED_RULES[:mx]],
|
28
|
+
[:owner, :srv, @SHARED_RULES[:srv]],
|
29
|
+
[:owner, :txt, @SHARED_RULES[:txt]],
|
29
30
|
[:rttl, :klass, Proc.new{ |t| KLASSES.include?(t) ? update_last_rr(nil, nil, t, nil, nil) : false }],
|
31
|
+
[:rttl, :txt, @SHARED_RULES[:txt]],
|
32
|
+
[:rttl, :srv, @SHARED_RULES[:srv]],
|
33
|
+
[:klass, :mx, @SHARED_RULES[:mx]],
|
34
|
+
[:klass, :txt, @SHARED_RULES[:txt]],
|
35
|
+
[:klass, :srv, @SHARED_RULES[:srv]],
|
30
36
|
[:klass, :type, Proc.new{ |t| TYPES.include?(t) ? update_last_rr(nil, nil, nil, t, nil) : false }],
|
31
|
-
[:type, :last_token_in_a_row, Proc.new{ |t| update_last_rr(nil, nil, nil, nil, t) }],
|
32
37
|
[:klass, :soa, Proc.new{ |t| t == 'SOA' ? update_last_rr(nil, nil, nil, t, nil) : false }],
|
38
|
+
[:type, :last_token_in_a_row, Proc.new{ |t| update_last_rr(nil, nil, nil, nil, t) }],
|
39
|
+
[:start, :type, Proc.new{ |t| TYPES.include?(t) ? add_rr(nil, nil, nil, t, nil) : false }],
|
40
|
+
[:start, :klass, Proc.new{ |t| KLASSES.include?(t) ? add_rr(nil, nil, t, nil, nil) : false }],
|
41
|
+
[:start, :rttl, Proc.new{ |t| t.match(/^\d+$/) ? add_rr(nil, t, nil, nil, nil) : false }],
|
42
|
+
[:start, :origin, Proc.new{ |t| t == '$ORIGIN' }],
|
43
|
+
[:start, :ttl, Proc.new{ |t| t == '$TTL' }],
|
44
|
+
[:start, :srv, @SHARED_RULES[:srv]],
|
45
|
+
[:start, :txt, @SHARED_RULES[:txt]],
|
46
|
+
[:start, :owner, Proc.new{ |t| add_rr(t, nil, nil, nil, nil) }],
|
33
47
|
[:soa, :last_token_in_a_row, Proc.new{ |t| rdata = [t] + @tokens.shift(@tokens.index(')'))
|
34
48
|
rdata.select!{|tt| tt != "\n" }
|
35
49
|
raise ParserError, "Zone parsing error: parentices expected in SOA record.\n#{@content}" if (rdata[2] != '(') && (@tokens.first != ')')
|
@@ -43,8 +57,8 @@ module Bind9mgr
|
|
43
57
|
update_last_rr(nil, nil, nil, nil, rdata)
|
44
58
|
@tokens.shift
|
45
59
|
}],
|
46
|
-
[:klass, :mx, Proc.new{ |t| t == 'MX' ? update_last_rr(nil, nil, nil, t, nil) : false }],
|
47
60
|
[:mx, :last_token_in_a_row, Proc.new{ |t| update_last_rr(nil, nil, nil, nil, [t] + [@tokens.shift]) }],
|
61
|
+
[:srv, :last_token_in_a_row, Proc.new{ |t| update_last_rr(nil, nil, nil, nil, [t] + [@tokens.shift(3)]) }],
|
48
62
|
[: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
|
49
63
|
]
|
50
64
|
end
|
@@ -84,6 +98,7 @@ module Bind9mgr
|
|
84
98
|
private
|
85
99
|
|
86
100
|
def tokenize str
|
101
|
+
str.squeeze!("\n\t\r")
|
87
102
|
dirty_tokens = str.gsub(/;.*$/, '').split(/[ \t\r]/)
|
88
103
|
|
89
104
|
puts dirty_tokens.inspect
|
@@ -91,8 +106,6 @@ module Bind9mgr
|
|
91
106
|
tokens = []
|
92
107
|
dirty_tokens.each do |t|
|
93
108
|
|
94
|
-
|
95
|
-
|
96
109
|
if t.index("\n")
|
97
110
|
puts "n found: #{t.inspect}"
|
98
111
|
while t.index("\n") do
|
data/spec/parser_spec.rb
CHANGED
@@ -21,6 +21,22 @@ www CNAME @
|
|
21
21
|
cloud.ru. IN A 192.168.1.1
|
22
22
|
human-txt TXT 'this is text with spases'
|
23
23
|
|
24
|
+
|
25
|
+
|
26
|
+
dev-office 300 IN TXT 'v=spf1 mx mx:mail.dev-office.o7russia.ru ~all'
|
27
|
+
dev-office2 300 TXT 'v=spf2 mx mx:mail.dev-office.o7russia.ru ~all'
|
28
|
+
dev-office3 IN TXT 'v=spf3 mx mx:mail.dev-office.o7russia.ru ~all'
|
29
|
+
dev-office4 TXT 'v=spf4 mx mx:mail.dev-office.o7russia.ru ~all'
|
30
|
+
TXT 'v=spf5 mx mx:mail.dev-office.o7russia.ru ~all'
|
31
|
+
|
32
|
+
test-srv 444 IN SRV 0 1 555 46.61.233.44
|
33
|
+
test-srv2 444 SRV 0 2 555 46.61.233.44
|
34
|
+
test-srv3 IN SRV 0 3 555 46.61.233.44
|
35
|
+
test-srv4 SRV 0 4 555 46.61.233.44
|
36
|
+
SRV 0 5 555 46.61.233.44
|
37
|
+
|
38
|
+
_sip._tls.dev-office SRV 0 5 443 sip.dev-office
|
39
|
+
|
24
40
|
NS ns2.cloud.ru
|
25
41
|
manager IN A 192.168.1.20
|
26
42
|
director IN A 192.168.1.23
|
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.14
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-03-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdoc
|