dns-catalog_zone 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +1 -0
  4. data/.coveralls.yml +2 -0
  5. data/.gitignore +13 -0
  6. data/.rspec +1 -0
  7. data/.travis.yml +11 -0
  8. data/Gemfile +9 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.jp.md +115 -0
  11. data/README.md +113 -0
  12. data/Rakefile +8 -0
  13. data/bin/catz +33 -0
  14. data/certs/mimuret.pem +21 -0
  15. data/dns-catalog_zone.gemspec +33 -0
  16. data/lib/dns/catalog_zone.rb +40 -0
  17. data/lib/dns/catalog_zone/catalog_zone.rb +125 -0
  18. data/lib/dns/catalog_zone/cli.rb +88 -0
  19. data/lib/dns/catalog_zone/config.rb +83 -0
  20. data/lib/dns/catalog_zone/errors.rb +32 -0
  21. data/lib/dns/catalog_zone/helper.rb +98 -0
  22. data/lib/dns/catalog_zone/master.rb +47 -0
  23. data/lib/dns/catalog_zone/output.rb +44 -0
  24. data/lib/dns/catalog_zone/output/base.rb +42 -0
  25. data/lib/dns/catalog_zone/output/file.rb +57 -0
  26. data/lib/dns/catalog_zone/output/stdout.rb +41 -0
  27. data/lib/dns/catalog_zone/prefixes.rb +45 -0
  28. data/lib/dns/catalog_zone/provider.rb +46 -0
  29. data/lib/dns/catalog_zone/provider/base.rb +66 -0
  30. data/lib/dns/catalog_zone/provider/knot.rb +278 -0
  31. data/lib/dns/catalog_zone/provider/nsd.rb +106 -0
  32. data/lib/dns/catalog_zone/provider/yadifa.rb +139 -0
  33. data/lib/dns/catalog_zone/source.rb +47 -0
  34. data/lib/dns/catalog_zone/source/axfr.rb +54 -0
  35. data/lib/dns/catalog_zone/source/base.rb +59 -0
  36. data/lib/dns/catalog_zone/source/file.rb +49 -0
  37. data/lib/dns/catalog_zone/version.rb +27 -0
  38. data/lib/dns/catalog_zone/zone.rb +39 -0
  39. data/share/CatalogZone +24 -0
  40. data/share/knotd-catalog.sh +32 -0
  41. data/share/nsd-catalog.sh +37 -0
  42. data/share/yadifad-catalog.sh +34 -0
  43. metadata +183 -0
  44. metadata.gz.sig +0 -0
@@ -0,0 +1,44 @@
1
+ # The MIT License (MIT)
2
+ #
3
+ # Copyright (c) 2016 Manabu Sonoda
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require 'dns/catalog_zone/output/base'
24
+
25
+ module Dns
26
+ module CatalogZone
27
+ # output module
28
+ module Output
29
+ class << self
30
+ def create(setting)
31
+ type = setting.output
32
+ class_name = "Dns::CatalogZone::Output::#{type.ucc}"
33
+ begin
34
+ require "dns/catalog_zone/output/#{type}"
35
+ output = Object.const_get(class_name).new(setting)
36
+ rescue NameError
37
+ raise Dns::CatalogZone::ValidateError, "can't find #{class_name}"
38
+ end
39
+ output
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,42 @@
1
+ # The MIT License (MIT)
2
+ #
3
+ # Copyright (c) 2016 Manabu Sonoda
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ module Dns
24
+ module CatalogZone
25
+ module Output
26
+ class Base
27
+ # @return [Array<Gem::Dependency>] Array of supported Chef versions
28
+ attr_reader :rrsets
29
+ def initialize(setting)
30
+ @setting = setting
31
+ end
32
+
33
+ def output(str)
34
+ end
35
+
36
+ def validate
37
+ true
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,57 @@
1
+ # The MIT License (MIT)
2
+ #
3
+ # Copyright (c) 2016 Manabu Sonoda
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ module Dns
24
+ module CatalogZone
25
+ module Output
26
+ class File < Base
27
+ def initialize(setting)
28
+ @setting = setting
29
+ end
30
+
31
+ def output(str)
32
+ tmp_file = Tempfile.create('catalog_zone')
33
+ path = tmp_file.path
34
+ tmp_file.print(str)
35
+ tmp_file.close
36
+ FileUtils.mv(path, @setting.output_path)
37
+ rescue
38
+ raise "can't write #{@setting.output_path}"
39
+ ensure
40
+ File.unlink(path) if File.exist?(path)
41
+ end
42
+
43
+ def validate
44
+ raise Dns::CatalogZone::ValidateError,
45
+ 'source type file is output_path' unless @setting.output_path
46
+ realpath = ::File.expand_path(@setting.output_path)
47
+ realdirpath = ::File.dirname(realpath)
48
+
49
+ raise Dns::CatalogZone::CantOutput,
50
+ 'output_path is not writable' unless ::File.writable?(realpath) || \
51
+ ::File.writable?(realdirpath)
52
+ true
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,41 @@
1
+ # The MIT License (MIT)
2
+ #
3
+ # Copyright (c) 2016 Manabu Sonoda
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ module Dns
24
+ module CatalogZone
25
+ module Output
26
+ class Stdout < Base
27
+ def initialize(setting)
28
+ @setting = setting
29
+ end
30
+
31
+ def output(str)
32
+ print str
33
+ end
34
+
35
+ def validate
36
+ true
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,45 @@
1
+ # The MIT License (MIT)
2
+ #
3
+ # Copyright (c) 2016 Manabu Sonoda
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ module Dns
24
+ module CatalogZone
25
+ # Prefixes module
26
+ class Prefixes
27
+ include Dns::CatalogZone
28
+
29
+ attr_reader :prefixes
30
+ def initialize(prefixes = [])
31
+ @prefixes = prefixes
32
+ end
33
+
34
+ def add_prefixes(prefixes)
35
+ prefixes.prefixes.each do |prefix|
36
+ @prefixes.push(prefix)
37
+ end
38
+ self
39
+ end
40
+ def parse_apl(rr)
41
+ add_prefixes(rr.prefixes) if apl_rr?(rr)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,46 @@
1
+ # The MIT License (MIT)
2
+ #
3
+ # Copyright (c) 2016 Manabu Sonoda
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require 'dns/catalog_zone/provider/base'
24
+
25
+ module Dns
26
+ module CatalogZone
27
+ # Provider module
28
+ module Provider
29
+ class << self
30
+ def create(setting)
31
+ type = setting.software
32
+ class_name = "Dns::CatalogZone::Provider::#{type.ucc}"
33
+ begin
34
+ require "dns/catalog_zone/provider/#{type}"
35
+ provider = Object.const_get(class_name).new(setting)
36
+ rescue LoadError
37
+ raise Dns::CatalogZone::ValidateError, "can't find #{class_name}"
38
+ rescue NameError
39
+ raise Dns::CatalogZone::ValidateError, "can't find #{class_name}"
40
+ end
41
+ provider
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,66 @@
1
+ # The MIT License (MIT)
2
+ #
3
+ # Copyright (c) 2016 Manabu Sonoda
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ module Dns
24
+ module CatalogZone
25
+ module Provider
26
+ class Base
27
+ def initialize(setting)
28
+ @setting = setting
29
+ @output = ''
30
+ end
31
+
32
+ def write
33
+ @output
34
+ end
35
+
36
+ def output(msg)
37
+ @output += msg if msg
38
+ end
39
+
40
+ def output_r(msg = nil)
41
+ @output += "#{msg}\n" if msg
42
+ end
43
+
44
+ def make(_catalog_zone)
45
+ true
46
+ end
47
+
48
+ def reconfig
49
+ true
50
+ end
51
+
52
+ def reload
53
+ true
54
+ end
55
+
56
+ def validate
57
+ true
58
+ end
59
+
60
+ def zonepath(zone)
61
+ Dns::CatalogZone.convert_path(@setting.zonepath, zone.zonename)
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,278 @@
1
+ # The MIT License (MIT)
2
+ #
3
+ # Copyright (c) 2016 Manabu Sonoda
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ module Dns
24
+ module CatalogZone
25
+ module Provider
26
+ class Knot < Base
27
+ # Dns::CatalogZone::Provider::Knot::Attribute
28
+ class Attribute
29
+ def initialize(hash)
30
+ @output = ''
31
+ hash.each do |key, value|
32
+ public_send("#{key}=", value) if respond_to?("#{key}=")
33
+ end
34
+ end
35
+
36
+ def output_r(msg = nil)
37
+ @output += "#{msg}\n" if msg
38
+ end
39
+ end
40
+ # Dns::CatalogZone::Provider::Knot::Template
41
+ class Template < Attribute
42
+ attr_accessor :id, :storage, :masters, :acls
43
+ def initialize(hash)
44
+ super(hash)
45
+ @masters = []
46
+ @acls = []
47
+ @notifies = []
48
+ end
49
+
50
+ def add_acl(label)
51
+ @acls.push(label)
52
+ end
53
+
54
+ def add_master(label)
55
+ @masters.push(label)
56
+ end
57
+
58
+ def add_notify(label)
59
+ @notifies.push(label)
60
+ end
61
+
62
+ def print
63
+ output_r " - id: #{@id}"
64
+ output_r " master: [#{@masters.join(', ')}]" unless @masters.empty?
65
+ output_r " notify: [#{@notifies.join(', ')}]" unless @notifies.empty?
66
+ output_r " acl: [#{@acls.join(', ')}]" unless @acls.empty?
67
+
68
+ @output
69
+ end
70
+ end
71
+ # Dns::CatalogZone::Provider::Knot::Acl
72
+ class Acl < Attribute
73
+ attr_accessor :id, :address, :action, :key
74
+ def initialize(hash)
75
+ super(hash)
76
+ @addresses = []
77
+ end
78
+
79
+ def add_address(address)
80
+ @addresses.push(address)
81
+ end
82
+
83
+ def print
84
+ output_r " - id: #{@id}"
85
+ output_r " address: [ #{@addresses.join(', ')} ]" unless @addresses.empty?
86
+ output_r " tsig: #{@key}" if @key
87
+ output_r " action: #{@action}"
88
+
89
+ @output
90
+ end
91
+ end
92
+ # Dns::CatalogZone::Provider::Knot::Remote
93
+ class Remote < Attribute
94
+ def initialize(hash)
95
+ super(hash)
96
+ @addresses = []
97
+ end
98
+
99
+ def add_address(address)
100
+ @addresses.push(address)
101
+ end
102
+ attr_accessor :id, :address, :key
103
+ def print
104
+ output_r " - id: #{@id}"
105
+ output_r " address: [ #{@addresses.join(', ')} ]" unless @addresses.empty?
106
+ output_r " tsig: #{@key}" if @key
107
+
108
+ @output
109
+ end
110
+ end
111
+ # Dns::CatalogZone::Provider::Knot::Zone
112
+ class Zone < Template
113
+ attr_accessor :domain, :template, :storage, :file
114
+ def print
115
+ output_r " - domain: #{@domain.to_s + '.'}"
116
+ output_r " storage: #{storage}"
117
+ output_r " file: #{file}"
118
+ output_r " master: [#{@masters.join(', ')}]" unless @masters.empty?
119
+ output_r " notify: [#{@notifies.join(', ')}]" unless @notifies.empty?
120
+ output_r " acl: [#{@acls.join(', ')}]" unless @acls.empty?
121
+ output_r " template: #{template}"
122
+
123
+ @output
124
+ end
125
+
126
+ def template
127
+ @template || 'catalog-zone'
128
+ end
129
+ end
130
+ def initialize(setting)
131
+ @setting = setting
132
+ end
133
+ def make(catalog_zone)
134
+ @output = ''
135
+ @templates = []
136
+ @acls = []
137
+ @remotes = []
138
+ @zones = []
139
+ global_config(catalog_zone)
140
+ zones_config(catalog_zone)
141
+ make_output
142
+ end
143
+
144
+ def make_output
145
+ output_r 'acl:'
146
+ @acls.each do |acl|
147
+ output_r acl.print
148
+ end
149
+ output_r 'remote:'
150
+ @remotes.each do |remote|
151
+ output_r remote.print
152
+ end
153
+ output_r 'template:'
154
+ @templates.each do |template|
155
+ output_r template.print
156
+ end
157
+ output_r 'zone:'
158
+ @zones.each do |zone|
159
+ output_r zone.print
160
+ end
161
+ end
162
+
163
+ def reconfig
164
+ system("#{control} reload")
165
+ end
166
+
167
+ private
168
+ def control
169
+ @setting['control'] || "knotc"
170
+ end
171
+ def add_template(template)
172
+ @templates.push(template)
173
+ end
174
+
175
+ def add_remote(remote)
176
+ @remotes.push(remote)
177
+ end
178
+
179
+ def add_acl(acl)
180
+ @acls.push(acl)
181
+ end
182
+
183
+ def add_zone(zone)
184
+ @zones.push(zone)
185
+ end
186
+
187
+ def mkl(prefix, label)
188
+ label = "#{prefix}-#{label}"
189
+ label.tr!('.', '-')
190
+ label.gsub!(/-$/, 'global')
191
+
192
+ label
193
+ end
194
+
195
+ def global_config(catalog_zone)
196
+ template = Template.new(id: 'catalog-zone')
197
+
198
+ add_template(template)
199
+ catalog_zone.masters.each_pair do |label, master|
200
+ output_master(master, template, label)
201
+ end
202
+ catalog_zone.notifies.each_pair do |label, notify|
203
+ output_notify(notify, template, label)
204
+ end
205
+ catalog_zone.allow_transfers.each_pair do |_label, prefixes|
206
+ output_prefixes(prefixes, template, 'allow-transfer')
207
+ end
208
+ end
209
+
210
+ def output_master(master, template, label)
211
+ return if master.addresses.empty?
212
+
213
+ # for request axfr
214
+ remote = Remote.new(id: mkl('master', label), tsig: master.tsig)
215
+ # for allow notify
216
+ acl = Acl.new(id: mkl('notify', label), action: 'notify', key: master.tsig)
217
+ master.addresses.each do |addr|
218
+ remote.add_address(addr)
219
+ acl.add_address(addr)
220
+ end
221
+ template.add_acl(mkl('notify', label))
222
+ template.add_master(mkl('master', label))
223
+ add_acl(acl)
224
+ add_remote(remote)
225
+ end
226
+
227
+ def output_notify(notify, template, label)
228
+ return if notify.addresses.empty?
229
+ # for send notify
230
+ remote = Remote.new(id: mkl('notify', label), tsig: notify.tsig)
231
+ # for allow transfer
232
+ acl = Acl.new(id: mkl('transfer', label), action: 'transfer', key: notify.tsig)
233
+ notify.addresses.each do |addr|
234
+ remote.add_address(addr)
235
+ acl.add_address(addr)
236
+ end
237
+ template.add_notify(mkl('notify', label))
238
+ template.add_acl(mkl('transfer', label))
239
+ add_acl(acl)
240
+ add_remote(remote)
241
+ end
242
+
243
+ def output_prefixes(prefixes, template, label)
244
+ acl = Acl.new(id: mkl('acl', label), action: 'transfer')
245
+
246
+ prefixes.prefixes.each do |prefix|
247
+ acl.add_address("#{prefix.address}/#{prefix.prefix_length}")
248
+ end
249
+ add_acl(acl)
250
+ template.add_acl(mkl('acl', label))
251
+ end
252
+
253
+ def zones_config(catalog_zone)
254
+ catalog_zone.zones.each_pair do |_hash, zone|
255
+ zone_path = zonepath(zone)
256
+ storage = ::File.dirname(zone_path)
257
+ file = ::File.basename(zone_path)
258
+
259
+ kzone = Zone.new(domain: zone.zonename,
260
+ storage: storage,
261
+ file: file)
262
+
263
+ add_zone(kzone)
264
+ zone.masters.each_pair do |label, master|
265
+ output_master(master, kzone, "#{zone.zonename}-#{label}")
266
+ end
267
+ zone.notifies.each_pair do |label, notify|
268
+ output_notify(notify, kzone, "#{zone.zonename}-#{label}")
269
+ end
270
+ zone.allow_transfers.each_pair do |label, prefixes|
271
+ output_prefixes(prefixes, kzone, "#{zone.zonename}-#{label}")
272
+ end
273
+ end
274
+ end
275
+ end
276
+ end
277
+ end
278
+ end