DNS/Server.pm

filter: Statementstmt 3.8% 33 / 860 Branchbran 0.0% 0 / 606 Conditioncond 0.0% 0 / 168 MC/DCmcdc 0.0% 0 / 98 Subroutinesub 34.6% 9 / 26 Podpod 100% 13 / 13 totaltotal 3.1% 55 / 1771 CC 432 SCAR 70.0
CC
432
Cov
2%
_ParseZoneContent
3192.0
_ParseZoneFile
1722.0
CreateZone
1406.0
CRAP 1102.0
↑ Summary DNS/CLI.pm »
1 package Lim::Plugin::DNS::Server;
2  
3 1 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use Fcntl qw(:seek);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use IO::File ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Digest::SHA ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Lim::Plugin::DNS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Lim::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use base qw(Lim::Component::Server);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 =encoding utf8
17  
18 =head1 NAME
19  
20 Lim::Plugin::DNS::Server - Server class for DNS Manager Lim plugin
21  
22 =head1 VERSION
23  
24 See L<Lim::Plugin::DNS> for version.
25  
26 =cut
27  
28 1 our $VERSION = $Lim::Plugin::DNS::VERSION;
29  
30 # http://www.iana.org/assignments/dns-parameters
31 1 our %_CLASS = (
32 IN => 1,
33 CH => 1,
34 HS => 1
35 );
36 1 our %_CLASS_NAME = ();
37 1 our %_TYPE = (
38 A => 1,
39 NS => 1,
40 MD => 1,
41 MF => 1,
42 CNAME => 1,
43 SOA => 1,
44 MB => 1,
45 MG => 1,
46 MR => 1,
47 NULL => 1,
48 WKS => 1,
49 PTR => 1,
50 HINFO => 1,
51 MINFO => 1,
52 MX => 1,
53 TXT => 1,
54 RP => 1,
55 AFSDB => 1,
56 X25 => 1,
57 ISDN => 1,
58 RT => 1,
59 NSAP => 1,
60 'NSAP-PTR' => 1,
61 SIG => 1,
62 KEY => 1,
63 PX => 1,
64 GPOS => 1,
65 AAAA => 1,
66 LOC => 1,
67 NXT => 1,
68 EID => 1,
69 NIMLOC => 1,
70 SRV => 1,
71 ATMA => 1,
72 NAPTR => 1,
73 KX => 1,
74 CERT => 1,
75 A6 => 1,
76 DNAME => 1,
77 SINK => 1,
78 OPT => 1,
79 APL => 1,
80 DS => 1,
81 SSHFP => 1,
82 IPSECKEY => 1,
83 RRSIG => 1,
84 NSEC => 1,
85 DNSKEY => 1,
86 DHCID => 1,
87 NSEC3 => 1,
88 NSEC3PARAM => 1,
89 TLSA => 1,
90 HIP => 1,
91 NINFO => 1,
92 RKEY => 1,
93 TALINK => 1,
94 CDS => 1,
95 SPF => 1,
96 UINFO => 1,
97 UID => 1,
98 GID => 1,
99 UNSPEC => 1,
100 NID => 1,
101 L32 => 1,
102 L64 => 1,
103 LP => 1,
104 TKEY => 1,
105 TSIG => 1,
106 IXFR => 1,
107 AXFR => 1,
108 MAILB => 1,
109 MAILA => 1,
110 '*' => 1,
111 URI => 1,
112 CAA => 1,
113 TA => 1,
114 DLV => 1,
115 NB => 1,
116 NBSTAT => 1
117 );
118 1 our %_TYPE_NAME = ();
119  
120 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
121 1 %_CLASS_NAME = reverse %_CLASS;
122 1 %_TYPE_NAME = reverse %_TYPE;
123 }
124  
125 =head1 SYNOPSIS
126  
127 use Lim::Plugin::DNS;
128  
129 # Create a Server object
130 $server = Lim::Plugin::DNS->Server;
131  
132 =head1 CONFIGURATION
133  
134 TODO
135  
136 =cut
137  
138 1 our %ZoneFilePath = (
139 #
140 # OpenDNSSEC
141 #
142 OpenDNSSEC => {
143 '/var/opendnssec/unsigned' => {
144 writable => 1,
145 creatable => 1
146 },
147 '/var/opendnssec/signed' => {
148 writable => 0
149 },
150 '/var/lib/opendnssec/unsigned' => {
151 writable => 1,
152 creatable => 1
153 },
154 '/var/llb/opendnssec/signed' => {
155 writable => 0
156 }
157 },
158 #
159 # BIND
160 #
161 BIND => {
162 '/var/bind' => {
163 writable => 1,
164 creatable => 1
165 },
166 '/var/lib/bind' => {
167 writable => 1,
168 creatable => 1
169 },
170 '/var/cache/bind' => {
171 writable => 0
172 },
173 '/etc/bind' => {
174 writable => 1,
175 match => qr/(?:^db\.|\.db$)/o
176 },
177 '/var/named' => {
178 writable => 1,
179 creatable => 1
180 },
181 '/var/lib/named' => {
182 writable => 1,
183 creatable => 1
184 },
185 '/var/cache/named' => {
186 writable => 0
187 },
188 '/etc/named' => {
189 writable => 1,
190 match => qr/(?:^db\.|\.db$)/o
191 }
192 }
193 #
194 # NSD, Knot, Yadifa, PowerDNS. djbdns
195 #
196 );
197  
198 =head1 INTERNAL METHODS
199  
200 These are only internal methods and should not be used externally.
201  
202 =over 4
203  
204 =item $server->_ScanZoneFile
205  
206 Scan for zone files based on configuration and returns a hash reference.
207  
208 $hash_ref->{<software>}->{<full path file name>} = {
209 name => <full path file name>,
210 software => <the software related to the zone file>,
211 short => <file name>,
212 write => <true if writable>,
213 read => <true if readable>
214 };
215  
216 =cut
217  
218 0 ▶sub _ScanZoneFile {
Subroutine _ScanZoneFile: not called CC=14 SCAR=53.5
219 0 my ($self) = @_;
220 0 my %file;
221
222 0 foreach my $software (keys %ZoneFilePath) {
223 0 foreach my $path (keys %{$ZoneFilePath{$software}}) {
224 0 my $entry = $ZoneFilePath{$software}->{$path};
225 0 $path =~ s/\/+$//o;
226
227 0 ▶ unless (opendir(DIR, $path)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (opendir DIR, $path) 0 0 0
228 0 next;
229 }
230
231 0 ▶ while (defined (my $file = readdir(DIR))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $file = readdir DIR)) 0 0 0
232 0 ▶ unless (-f $path.'/'.$file and $file !~ /^\./o) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $path . '/' . $file and not $file =~ /^\./ou) 0 0 0
Condition0%0/3
-f $path . '/' . $file and not $file =~ /^\./ou
!ll&&!rl&&r
000
MC/DC0%0/2
-f $path . '/' . $file and not $file =~ /^\./ou
-f $path . '/' . $file not $file =~ /^\./ou
Truth table0%0/3
A and not(B)
A= -f $path . '/' . $fileB= not $file =~ /^\./ou
ABresult
0X0
100
111
233 0 next;
234 }
235 0 ▶ if (exists $entry->{match} and $file !~ $entry->{match}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $entry->{"match"} and not $file =~ /$entry->{"match"}/u) 0 0 0
Condition0%0/3
exists $entry->{"match"} and not $file =~ /$entry->{"match"}/u
!ll&&!rl&&r
000
MC/DC0%0/2
exists $entry->{"match"} and not $file =~ /$entry->{"match"}/u
exists $entry->{"match"} not $file =~ /$entry->{"match"}/u
Truth table0%0/3
A and not(B)
A= exists $entry->{"match"}B= not $file =~ /$entry->{"match"}/u
ABresult
0X0
100
111
236 0 next;
237 }
238
239 0 ▶ if (defined ($_ = Lim::Util::FileWritable($path.'/'.$file))) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined($_ = Lim::Util::FileWritable($path . '/' . $file))) { } 0 0 0
elsif (defined($_ = Lim::Util::FileReadable($path . '/' . $file))) { } 0 0 0
240 0 ▶ my $write = $entry->{writable} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$entry->{'writable'} ? : 0 0 0
241
242 0 ▶ if (exists $file{$software}->{$_}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $file{$software}{$_}) 0 0 0
243 0 $file{$software}->{$_}->{write} = $write;
244 0 next;
245 }
246
247 0 $file{$software}->{$_} = {
248 name => $_,
249 software => $software,
250 short => $file,
251 write => $write,
252 read => 1
253 };
254 }
255 elsif (defined ($_ = Lim::Util::FileReadable($path.'/'.$file))) {
256 0 ▶ if (exists $file{$software}->{$_}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $file{$software}{$_}) 0 0 0
257 0 next;
258 }
259
260 0 $file{$software}->{$_} = {
261 name => $_,
262 software => $software,
263 short => $file,
264 write => 0,
265 read => 1
266 };
267 }
268 }
269 0 closedir(DIR);
270 }
271 }
272
273 0 return \%file;
274 }
275  
276 =item $server->_ParseZoneFile($file, $option, $rr)
277  
278 Parse a zone file and returns the content into C<$option> and/or C<$rr>. C<$option> and
279 C<$rr> can be a hash or array reference.
280  
281 # $option as an array reference
282 $option = [
283 {
284 name => <option name>,
285 value => <option value>
286 },
287 ...
288 ];
289
290 # $option as a hash reference
291 $option->{<option name>} = <option value>;
292
293 # $rr as an array reference
294 $rr = [
295 {
296 name => <rr name>,
297 ttl => <rr ttl>,
298 class => <rr class>,
299 type => <rr type>,
300 rdata => <rr rdata>
301 },
302 ...
303 ];
304
305 # $rr as a hash reference
306 $rr->{<rr name>} = [
307 {
308 ttl => <rr ttl>,
309 class => <rr class>,
310 type => <rr type>,
311 rdata => <rr rdata>
312 },
313 ...
314 ];
315  
316 =cut
317  
318 0 ▶sub _ParseZoneFile {
Subroutine _ParseZoneFile: not called CC=41 SCAR=74.5
319 0 my ($self, $file, $option, $rr) = @_;
320 0 my ($line, $last, $rr_hash, $rr_array, $option_hash, $option_array);
321
322 0 ▶ if (defined $rr) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rr) 0 0 0
323 0 ▶ if (ref($rr) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $rr eq 'HASH') { } 0 0 0
elsif (ref $rr eq 'ARRAY') { } 0 0 0
324 0 $rr_hash = $rr;
325 }
326 elsif (ref($rr) eq 'ARRAY') {
327 0 $rr_array = $rr;
328 }
329 }
330
331 0 ▶ if (defined $option) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $option) 0 0 0
332 0 ▶ if (ref($option) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $option eq 'HASH') { } 0 0 0
elsif (ref $option eq 'ARRAY') { } 0 0 0
333 0 $option_hash = $option;
334 }
335 elsif (ref($option) eq 'ARRAY') {
336 0 $option_array = $option;
337 }
338 }
339  
340 0 ▶ while (<$file>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $file)) 0 0 0
341 0 ▶ if (/^([^;]+[^;\s])/o) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^([^;]+[^;\s])/ou) 0 0 0
342 0 my $this = $1;
343
344 0 ▶ if (defined $line) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $line) { } 0 0 0
elsif ($this =~ /\(/ou and not $this =~ /\)/ou) { } 0 0 0
345 0 $line .= $this;
346 0 ▶ unless ($this =~ /\)/o) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($this =~ /\)/ou) 0 0 0
347 0 next;
348 }
349 }
350 ▶ elsif ($this =~ /\(/o and $this !~ /\)/o) {
Condition0%0/3
$this =~ /\(/ou and not $this =~ /\)/ou
!ll&&!rl&&r
000
MC/DC0%0/2
$this =~ /\(/ou and not $this =~ /\)/ou
$this =~ /\(/ou not $this =~ /\)/ou
Truth table0%0/3
A and not(B)
A= $this =~ /\(/ouB= not $this =~ /\)/ou
ABresult
0X0
100
111
351 0 $line .= $this;
352 0 next;
353 }
354 else {
355 0 $line = $this;
356 }
357  
358 0 my ($name, $ttl, $class, $type, $rdata);
359 {
360 0 my @parts = split(/\s+/o, $line);
361 0 $name = shift(@parts);
362
363 0 ▶ if ($name =~ /^\$/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^\$/ou) 0 0 0
364 0 $name =~ s/^\$//o;
365
366 0 ▶ if (defined $option_hash) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $option_hash) { } 0 0 0
elsif (defined $option_array) { } 0 0 0
367 0 $option_hash->{$name} = join(' ', @parts);
368 }
369 elsif (defined $option_array) {
370 0 push(@$option_array, {
371 name => $name,
372 value => join(' ', @parts)
373 })
374 }
375 0 undef($line);
376 0 next;
377 }
378
379 0 my $part = shift(@parts);
380 0 ▶ if (exists $_TYPE{$part} or $part =~ /^TYPE\d+$/o) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Lim::Plugin::DNS::Server::_TYPE{$part} or $part =~ /^TYPE\d+$/ou) { } 0 0 0
Condition0%0/3
exists $Lim::Plugin::DNS::Server::_TYPE{$part} or $part =~ /^TYPE\d+$/ou
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $Lim::Plugin::DNS::Server::_TYPE{$part} or $part =~ /^TYPE\d+$/ou
exists $Lim::Plugin::DNS::Server::_TYPE{$part} $part =~ /^TYPE\d+$/ou
Truth table0%0/3
A or B
A= exists $Lim::Plugin::DNS::Server::_TYPE{$part}B= $part =~ /^TYPE\d+$/ou
ABresult
1X1
011
000
381 0 $type = $part;
382 }
383 else {
384 0 ▶ if ($part =~ /^\d+[YyMmWwDdHhSs]?$/o) {
Branch: 2 branches
BranchTrueFalseTotal
if ($part =~ /^\d+[YyMmWwDdHhSs]?$/ou) { } 0 0 0
elsif (exists $Lim::Plugin::DNS::Server::_CLASS{$part} or $part =~ /^CLASS\d+$/ou) { } 0 0 0
385 0 $ttl = $part;
386 }
387 ▶ elsif (exists $_CLASS{$part} or $part =~ /^CLASS\d+$/o) {
Condition0%0/3
exists $Lim::Plugin::DNS::Server::_CLASS{$part} or $part =~ /^CLASS\d+$/ou
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $Lim::Plugin::DNS::Server::_CLASS{$part} or $part =~ /^CLASS\d+$/ou
exists $Lim::Plugin::DNS::Server::_CLASS{$part} $part =~ /^CLASS\d+$/ou
Truth table0%0/3
A or B
A= exists $Lim::Plugin::DNS::Server::_CLASS{$part}B= $part =~ /^CLASS\d+$/ou
ABresult
1X1
011
000
388 0 $class = $part;
389 }
390 else {
391 0 undef($line);
392 0 next;
393 }
394
395 0 $part = shift(@parts);
396 0 ▶ if (exists $_TYPE{$part} or $part =~ /^TYPE\d+$/o) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Lim::Plugin::DNS::Server::_TYPE{$part} or $part =~ /^TYPE\d+$/ou) { } 0 0 0
Condition0%0/3
exists $Lim::Plugin::DNS::Server::_TYPE{$part} or $part =~ /^TYPE\d+$/ou
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $Lim::Plugin::DNS::Server::_TYPE{$part} or $part =~ /^TYPE\d+$/ou
exists $Lim::Plugin::DNS::Server::_TYPE{$part} $part =~ /^TYPE\d+$/ou
Truth table0%0/3
A or B
A= exists $Lim::Plugin::DNS::Server::_TYPE{$part}B= $part =~ /^TYPE\d+$/ou
ABresult
1X1
011
000
397 0 $type = $part;
398 }
399 else {
400 0 ▶ if (!defined $ttl and $part =~ /^\d+[YyMmWwDdHhSs]?$/o) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $ttl and $part =~ /^\d+[YyMmWwDdHhSs]?$/ou) { } 0 0 0
elsif (not defined $class and exists $Lim::Plugin::DNS::Server::_CLASS{$part} || $part =~ /^CLASS\d+$/ou) { } 0 0 0
Condition0%0/3
not defined $ttl and $part =~ /^\d+[YyMmWwDdHhSs]?$/ou
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $ttl and $part =~ /^\d+[YyMmWwDdHhSs]?$/ou
not defined $ttl $part =~ /^\d+[YyMmWwDdHhSs]?$/ou
Truth table0%0/3
not(A) and B
A= not defined $ttlB= $part =~ /^\d+[YyMmWwDdHhSs]?$/ou
ABresult
0X0
100
111
401 0 $ttl = $part;
402 }
403 ▶ elsif (!defined $class and (exists $_CLASS{$part} or $part =~ /^CLASS\d+$/o)) {
Condition0%0/6
not defined $class and exists $Lim::Plugin::DNS::Server::_CLASS{$part} || $part =~ /^CLASS\d+$/ou
!ll&&!rl&&r
000
exists $Lim::Plugin::DNS::Server::_CLASS{$part} or $part =~ /^CLASS\d+$/ou
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $class and exists $Lim::Plugin::DNS::Server::_CLASS{$part} || $part =~ /^CLASS\d+$/ou
not defined $class exists $Lim::Plugin::DNS::Server::_CLASS{$part} $part =~ /^CLASS\d+$/ou
Truth table0%0/4
not(A) and B or C
A= not defined $classB= exists $Lim::Plugin::DNS::Server::_CLASS{$part}C= $part =~ /^CLASS\d+$/ou
ABCresult
0XX0
1000
11X1
1011
404 0 $class = $part;
405 }
406 else {
407 0 undef($line);
408 0 next;
409 }
410
411 0 $type = shift(@parts);
412 0 ▶ unless (exists $_TYPE{$type} or $type =~ /^TYPE\d+$/o) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Lim::Plugin::DNS::Server::_TYPE{$type} or $type =~ /^TYPE\d+$/ou) 0 0 0
Condition0%0/3
exists $Lim::Plugin::DNS::Server::_TYPE{$type} or $type =~ /^TYPE\d+$/ou
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $Lim::Plugin::DNS::Server::_TYPE{$type} or $type =~ /^TYPE\d+$/ou
exists $Lim::Plugin::DNS::Server::_TYPE{$type} $type =~ /^TYPE\d+$/ou
Truth table0%0/3
A or B
A= exists $Lim::Plugin::DNS::Server::_TYPE{$type}B= $type =~ /^TYPE\d+$/ou
ABresult
1X1
011
000
413 0 undef($line);
414 0 next;
415 }
416 }
417 }
418
419 0 $rdata = join(' ', @parts);
420 }
421  
422 0 ▶ if (defined $name and defined $type and defined $rdata) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name and defined $type and defined $rdata) 0 0 0
Condition0%0/6
defined $name and defined $type and defined $rdata
!ll&&!rl&&r
000
defined $name and defined $type
!ll&&!rl&&r
000
MC/DC0%0/3
defined $name and defined $type and defined $rdata
defined $name defined $type defined $rdata
Truth table0%0/4
A and B and C
A= defined $nameB= defined $typeC= defined $rdata
ABCresult
0XX0
10X0
1100
1111
423 0 ▶ unless ($name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name) { } 0 0 0
424 0 ▶ if (defined $last) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last) 0 0 0
425 0 $name = $last;
426 }
427 }
428 else {
429 0 $last = $name;
430 }
431  
432 0 ▶ if (defined $rr_hash) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $rr_hash) { } 0 0 0
elsif (defined $rr_array) { } 0 0 0
433 0 ▶ push(@{$rr_hash->{$name}}, {
Branch: 2 branches
BranchTrueFalseTotal
defined $ttl ? : 0 0 0
defined $class ? : 0 0 0
434 (defined $ttl ? (ttl => $ttl) : ()),
435 (defined $class ? (class => $class) : ()),
436 type => $type,
437 rdata => $rdata
438 });
439 }
440 elsif (defined $rr_array) {
441 0 ▶ push(@$rr_array, {
Branch: 2 branches
BranchTrueFalseTotal
defined $ttl ? : 0 0 0
defined $class ? : 0 0 0
442 name => $name,
443 (defined $ttl ? (ttl => $ttl) : ()),
444 (defined $class ? (class => $class) : ()),
445 type => $type,
446 rdata => $rdata
447 })
448 }
449 }
450 0 undef($line);
451 }
452 }
453 0 return 1;
454 }
455  
456 =item $server->_ParseZoneContent($content, $option, $rr)
457  
458 Parse a zone content from a string and returns the content into C<$option> and/or
459 C<$rr>. C<$option> and C<$rr> can be a hash or array reference.
460  
461 # $option as an array reference
462 $option = [
463 {
464 name => <option name>,
465 value => <option value>
466 },
467 ...
468 ];
469
470 # $option as a hash reference
471 $option->{<option name>} = <option value>;
472
473 # $rr as an array reference
474 $rr = [
475 {
476 name => <rr name>,
477 ttl => <rr ttl>,
478 class => <rr class>,
479 type => <rr type>,
480 rdata => <rr rdata>
481 },
482 ...
483 ];
484
485 # $rr as a hash reference
486 $rr->{<rr name>} = [
487 {
488 ttl => <rr ttl>,
489 class => <rr class>,
490 type => <rr type>,
491 rdata => <rr rdata>
492 },
493 ...
494 ];
495  
496 =cut
497  
498 0 ▶sub _ParseZoneContent {
Subroutine _ParseZoneContent: not called CC=56 SCAR=80.7
499 0 my ($self, $buf, $option, $rr) = @_;
500 0 my ($pre, $name, $ttl, $class, $type, $rdata, $last, $rr_hash, $rr_array, $option_hash, $option_array);
501 0 my $concat = 0;
502
503 0 ▶ if (defined $rr) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rr) 0 0 0
504 0 ▶ if (ref($rr) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $rr eq 'HASH') { } 0 0 0
elsif (ref $rr eq 'ARRAY') { } 0 0 0
505 0 $rr_hash = $rr;
506 }
507 elsif (ref($rr) eq 'ARRAY') {
508 0 $rr_array = $rr;
509 }
510 }
511
512 0 ▶ if (defined $option) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $option) 0 0 0
513 0 ▶ if (ref($option) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $option eq 'HASH') { } 0 0 0
elsif (ref $option eq 'ARRAY') { } 0 0 0
514 0 $option_hash = $option;
515 }
516 elsif (ref($option) eq 'ARRAY') {
517 0 $option_array = $option;
518 }
519 }
520  
521 0 while (1) {
522 0 ▶ if (!$concat) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $concat) { } 0 0 0
523 0 ▶ if ($buf =~ /\G[\r\n]*(\s*)([^;\s\r\n]+)/ogc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buf =~ /\G[\r\n]*(\s*)([^;\s\r\n]+)/cgou) { } 0 0 0
524 0 $pre = $1;
525 0 $name = $2;
526 0 ▶ if ($buf =~ /\G[\s\r\n]*([^;\s\r\n]+)/ogc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buf =~ /\G[\s\r\n]*([^;\s\r\n]+)/cgou) 0 0 0
527 0 $ttl = $1;
528 0 ▶ if ($buf =~ /\G[\s\r\n]*([^;\s\r\n]+)/ogc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buf =~ /\G[\s\r\n]*([^;\s\r\n]+)/cgou) 0 0 0
529 0 $class = $1;
530 0 ▶ if ($buf =~ /\G[\s\r\n]*([^;\s\r\n]+)/ogc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buf =~ /\G[\s\r\n]*([^;\s\r\n]+)/cgou) 0 0 0
531 0 $type = $1;
532 0 ▶ if ($buf =~ /\G[\s\r\n]*([^;\r\n]*[^;\s\r\n])/ogc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buf =~ /\G[\s\r\n]*([^;\r\n]*[^;\s\r\n])/cgou) 0 0 0
533 0 $rdata = $1;
534 }
535 }
536 }
537 }
538
539 0 $buf =~ /\G[^\r\n]*/ogc;
540 }
541 else {
542 0 ▶ unless ($buf =~ /\G[\r\n]*[^\r\n]*/ogc) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($buf =~ /\G[\r\n]*[^\r\n]*/cgou) 0 0 0
543 0 last;
544 }
545 0 next;
546 }
547  
548 0 ▶ if ($name =~ /^\$/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^\$/ou) 0 0 0
549 0 $name =~ s/^\$//o;
550
551 0 my $value;
552 0 ▶ if (defined $ttl) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ttl) 0 0 0
553 0 ▶ $value .= (defined $value ? ' ' : '').$ttl;
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 0 0 0
554 }
555 0 ▶ if (defined $class) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $class) 0 0 0
556 0 ▶ $value .= (defined $value ? ' ' : '').$class;
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 0 0 0
557 }
558 0 ▶ if (defined $type) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type) 0 0 0
559 0 ▶ $value .= (defined $value ? ' ' : '').$type;
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 0 0 0
560 }
561 0 ▶ if (defined $rdata) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rdata) 0 0 0
562 0 ▶ $value .= (defined $value ? ' ' : '').$rdata;
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 0 0 0
563 }
564  
565 0 ▶ if (defined $option_hash) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $option_hash) { } 0 0 0
elsif (defined $option_array) { } 0 0 0
566 0 $option_hash->{$name} = $value;
567 }
568 elsif (defined $option_array) {
569 0 push(@$option_array, {
570 name => $name,
571 value => $value
572 })
573 }
574 0 $pre = $name = $ttl = $class = $type = $rdata = undef;
575 0 next;
576 }
577
578 0 ▶ if (length($pre)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $pre) 0 0 0
579 0 ▶ if (defined $rdata) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rdata) { } 0 0 0
580 0 $rdata = $type . $rdata;
581 }
582 else {
583 0 $rdata = $type;
584 }
585 0 $type = $class;
586 0 $class = $ttl;
587 0 $ttl = $name;
588 0 undef($name);
589 }
590
591 0 ▶ if (exists $_TYPE{$ttl} or $ttl =~ /^TYPE\d+$/o) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Lim::Plugin::DNS::Server::_TYPE{$ttl} or $ttl =~ /^TYPE\d+$/ou) { } 0 0 0
Condition0%0/3
exists $Lim::Plugin::DNS::Server::_TYPE{$ttl} or $ttl =~ /^TYPE\d+$/ou
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $Lim::Plugin::DNS::Server::_TYPE{$ttl} or $ttl =~ /^TYPE\d+$/ou
exists $Lim::Plugin::DNS::Server::_TYPE{$ttl} $ttl =~ /^TYPE\d+$/ou
Truth table0%0/3
A or B
A= exists $Lim::Plugin::DNS::Server::_TYPE{$ttl}B= $ttl =~ /^TYPE\d+$/ou
ABresult
1X1
011
000
592 0 ▶ $rdata = $class .
Branch: 2 branches
BranchTrueFalseTotal
defined $type ? : 0 0 0
defined $rdata ? : 0 0 0
593 (defined $type ? ' '.$type : '') .
594 (defined $rdata ? ' '.$rdata : '');
595 0 $type = $ttl;
596 0 undef($ttl);
597 0 undef($class);
598 }
599 else {
600 0 ▶ if ($ttl =~ /^\d+[YyMmWwDdHhSs]?$/o) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ttl =~ /^\d+[YyMmWwDdHhSs]?$/ou) { } 0 0 0
elsif (exists $Lim::Plugin::DNS::Server::_CLASS{$ttl} or $ttl =~ /^CLASS\d+$/ou) { } 0 0 0
601 0 ▶ if (exists $_TYPE{$class} or $class =~ /^TYPE\d+$/o) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Lim::Plugin::DNS::Server::_TYPE{$class} or $class =~ /^TYPE\d+$/ou) { } 0 0 0
Condition0%0/3
exists $Lim::Plugin::DNS::Server::_TYPE{$class} or $class =~ /^TYPE\d+$/ou
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $Lim::Plugin::DNS::Server::_TYPE{$class} or $class =~ /^TYPE\d+$/ou
exists $Lim::Plugin::DNS::Server::_TYPE{$class} $class =~ /^TYPE\d+$/ou
Truth table0%0/3
A or B
A= exists $Lim::Plugin::DNS::Server::_TYPE{$class}B= $class =~ /^TYPE\d+$/ou
ABresult
1X1
011
000
602 0 ▶ $rdata = $type .
Branch: 1 branch
BranchTrueFalseTotal
defined $rdata ? : 0 0 0
603 (defined $rdata ? ' '.$rdata : '');
604 0 $type = $class;
605 0 undef($class);
606 }
607 else {
608 0 ▶ if (exists $_CLASS{$class} or $class =~ /^CLASS\d+$/o) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Lim::Plugin::DNS::Server::_CLASS{$class} or $class =~ /^CLASS\d+$/ou) { } 0 0 0
Condition0%0/3
exists $Lim::Plugin::DNS::Server::_CLASS{$class} or $class =~ /^CLASS\d+$/ou
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $Lim::Plugin::DNS::Server::_CLASS{$class} or $class =~ /^CLASS\d+$/ou
exists $Lim::Plugin::DNS::Server::_CLASS{$class} $class =~ /^CLASS\d+$/ou
Truth table0%0/3
A or B
A= exists $Lim::Plugin::DNS::Server::_CLASS{$class}B= $class =~ /^CLASS\d+$/ou
ABresult
1X1
011
000
609 0 $class = $class;
610 }
611 else {
612 0 $pre = $name = $ttl = $class = $type = $rdata = undef;
613 0 next;
614 }
615 }
616 }
617 ▶ elsif (exists $_CLASS{$ttl} or $ttl =~ /^CLASS\d+$/o) {
Condition0%0/3
exists $Lim::Plugin::DNS::Server::_CLASS{$ttl} or $ttl =~ /^CLASS\d+$/ou
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $Lim::Plugin::DNS::Server::_CLASS{$ttl} or $ttl =~ /^CLASS\d+$/ou
exists $Lim::Plugin::DNS::Server::_CLASS{$ttl} $ttl =~ /^CLASS\d+$/ou
Truth table0%0/3
A or B
A= exists $Lim::Plugin::DNS::Server::_CLASS{$ttl}B= $ttl =~ /^CLASS\d+$/ou
ABresult
1X1
011
000
618 0 ▶ if (exists $_TYPE{$class} or $class =~ /^TYPE\d+$/o) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Lim::Plugin::DNS::Server::_TYPE{$class} or $class =~ /^TYPE\d+$/ou) { } 0 0 0
Condition0%0/3
exists $Lim::Plugin::DNS::Server::_TYPE{$class} or $class =~ /^TYPE\d+$/ou
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $Lim::Plugin::DNS::Server::_TYPE{$class} or $class =~ /^TYPE\d+$/ou
exists $Lim::Plugin::DNS::Server::_TYPE{$class} $class =~ /^TYPE\d+$/ou
Truth table0%0/3
A or B
A= exists $Lim::Plugin::DNS::Server::_TYPE{$class}B= $class =~ /^TYPE\d+$/ou
ABresult
1X1
011
000
619 0 ▶ $rdata = $type .
Branch: 1 branch
BranchTrueFalseTotal
defined $rdata ? : 0 0 0
620 (defined $rdata ? ' '.$rdata : '');
621 0 $type = $class;
622 0 undef($class);
623 }
624 else {
625 0 ▶ if ($class =~ /^\d+[YyMmWwDdHhSs]?$/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class =~ /^\d+[YyMmWwDdHhSs]?$/ou) { } 0 0 0
626 }
627 else {
628 0 $pre = $name = $ttl = $class = $type = $rdata = undef;
629 0 next;
630 }
631 }
632
633 0 $_ = $ttl;
634 0 $ttl = $class;
635 0 $class = $_;
636 }
637 else {
638 0 $pre = $name = $ttl = $class = $type = $rdata = undef;
639 0 next;
640 }
641 }
642
643 0 ▶ if ($rdata =~ /\(/o and $rdata !~ /\)/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rdata =~ /\(/ou and not $rdata =~ /\)/ou) 0 0 0
Condition0%0/3
$rdata =~ /\(/ou and not $rdata =~ /\)/ou
!ll&&!rl&&r
000
MC/DC0%0/2
$rdata =~ /\(/ou and not $rdata =~ /\)/ou
$rdata =~ /\(/ou not $rdata =~ /\)/ou
Truth table0%0/3
A and not(B)
A= $rdata =~ /\(/ouB= not $rdata =~ /\)/ou
ABresult
0X0
100
111
644 0 $concat = 1;
645 0 next;
646 }
647 }
648 else {
649 0 ▶ if ($buf =~ /\G[\s\r\n]*([^;\r\n]*[^;\r\n\s])/ogc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buf =~ /\G[\s\r\n]*([^;\r\n]*[^;\r\n\s])/cgou) { } 0 0 0
650 0 $rdata .= ' '.$1;
651
652 0 ▶ unless ($1 =~ /\)/o) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($1 =~ /\)/ou) 0 0 0
653 0 next;
654 }
655 0 $concat = 0;
656 }
657 else {
658 0 ▶ unless ($buf =~ /\G[\r\n]*[^\r\n]*/ogc) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($buf =~ /\G[\r\n]*[^\r\n]*/cgou) 0 0 0
659 0 last;
660 }
661 0 next;
662 }
663 }
664
665 0 ▶ unless ($name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name) { } 0 0 0
666 0 ▶ unless (defined $last) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $last) 0 0 0
667 0 $pre = $name = $ttl = $class = $type = $rdata = undef;
668 0 next;
669 }
670 0 $name = $last;
671 }
672 else {
673 0 $last = $name;
674 }
675 0 ▶ if (defined $rr_hash) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $rr_hash) { } 0 0 0
elsif (defined $rr_array) { } 0 0 0
676 0 ▶ push(@{$rr_hash->{$name}}, {
Branch: 2 branches
BranchTrueFalseTotal
defined $ttl ? : 0 0 0
defined $class ? : 0 0 0
677 (defined $ttl ? (ttl => $ttl) : ()),
678 (defined $class ? (class => $class) : ()),
679 type => $type,
680 rdata => $rdata
681 });
682 }
683 elsif (defined $rr_array) {
684 0 ▶ push(@$rr_array, {
Branch: 2 branches
BranchTrueFalseTotal
defined $ttl ? : 0 0 0
defined $class ? : 0 0 0
685 name => $name,
686 (defined $ttl ? (ttl => $ttl) : ()),
687 (defined $class ? (class => $class) : ()),
688 type => $type,
689 rdata => $rdata
690 })
691 }
692
693 0 $pre = $name = $ttl = $class = $type = $rdata = undef;
694 }
695 0 return 1;
696 }
697  
698 =item $server->_WriteZoneFile($file, $rr, $option)
699  
700 Write the content of C<$rr> and C<$option> out to a zone file. A temporary file is
701 used and then renamed to the specified C<$file> once the writing is complete.
702  
703 The C<$rr> and C<$option> needs to be in the format specified by L<_ParseZoneFile> and
704 L<_ParseZoneContent>.
705  
706 =cut
707  
708 0 ▶sub _WriteZoneFile {
Subroutine _WriteZoneFile: not called CC=23 SCAR=63.1
709 0 my ($self, $file, $rr, $option) = @_;
710 0 my $tmp;
711
712 0 ▶ if (-f $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $file) { } 0 0 0
713 0 $tmp = Lim::Util::TempFileLikeThis($file);
714 }
715 else {
716 0 $tmp = Lim::Util::TempFile;
717 }
718 0 ▶ unless (defined $tmp) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tmp) 0 0 0
719 0 die 'Unable to create temporary file';
720 }
721
722 0 ▶ if (defined $option) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $option) 0 0 0
723 0 ▶ if (ref($option) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $option eq 'HASH') { } 0 0 0
elsif (ref $option eq 'ARRAY') { } 0 0 0
724 0 foreach my $name (keys %{$option}) {
725 0 print $tmp '$', $name, ' ', $option->{$name}, "\n";
726 }
727 }
728 elsif (ref($option) eq 'ARRAY') {
729 0 foreach (@$option) {
730 0 ▶ unless (ref($_) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $_ eq "HASH") 0 0 0
731 0 die 'Invalid option data structure';
732 }
733 0 print $tmp '$', $_->{name}, ' ', $_->{value}, "\n";
734 }
735 }
736 else {
737 0 die 'Invalid parameters';
738 }
739 }
740  
741 0 ▶ if (defined $rr) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rr) 0 0 0
742 0 ▶ if (ref($rr) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $rr eq 'HASH') { } 0 0 0
elsif (ref $rr eq 'ARRAY') { } 0 0 0
743 0 foreach my $name (keys %{$rr}) {
744 0 ▶ unless (ref($rr->{$name}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $rr->{$name} eq "ARRAY") 0 0 0
745 0 die 'Invalid rr data structure';
746 }
747 0 foreach (@{$rr->{$name}}) {
748 0 ▶ unless (ref($_) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $_ eq "HASH") 0 0 0
749 0 die 'Invalid rr data structure';
750 }
751
752 print $tmp join("\t",
753 $name,
754 exists $_->{ttl} ? $_->{ttl} : '',
755 exists $_->{class} ? uc($_->{class}) : '',
756 uc($_->{type}),
757 $_->{rdata}
758 0 ▶ ), "\n";
Branch: 2 branches
BranchTrueFalseTotal
exists $_->{'ttl'} ? : 0 0 0
exists $_->{'class'} ? : 0 0 0
759 }
760 }
761 }
762 elsif (ref($rr) eq 'ARRAY') {
763 0 foreach (@{$rr}) {
764 0 ▶ unless (ref($_) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $_ eq "HASH") 0 0 0
765 0 die 'Invalid rr data structure';
766 }
767
768 print $tmp join("\t",
769 $_->{name},
770 exists $_->{ttl} ? $_->{ttl} : '',
771 exists $_->{class} ? uc($_->{class}) : '',
772 uc($_->{type}),
773 $_->{rdata}
774 0 ▶ ), "\n";
Branch: 2 branches
BranchTrueFalseTotal
exists $_->{'ttl'} ? : 0 0 0
exists $_->{'class'} ? : 0 0 0
775 }
776 }
777 }
778
779 0 $tmp->flush;
780 0 $tmp->close;
781
782 0 ▶ unless (rename($tmp->filename, $file)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (rename $tmp->filename, $file) 0 0 0
783 0 die 'Unable to rename temporary file to real file';
784 }
785 0 return;
786 }
787  
788 =back
789  
790 =head1 METHODS
791  
792 These methods are called from the Lim framework and should not be used else
793 where.
794  
795 Please see L<Lim::Plugin::DNS> for full documentation of calls.
796  
797 =over 4
798  
799 =item $server->ReadZones(...)
800  
801 Get a list of all zones that can be managed by the plugin.
802  
803 =cut
804  
805 0 ▶sub ReadZones {
Subroutine ReadZones: not called CC=5 SCAR=34.0
Pod documented
806 0 my ($self, $cb) = @_;
807 0 my $files = $self->_ScanZoneFile;
808 0 my @zone;
809
810 0 foreach my $software (keys %$files) {
811 0 foreach my $file (values %{$files->{$software}}) {
812 push(@zone, {
813 file => $file->{name},
814 software => $software,
815 read => $file->{read},
816 write => $file->{write}
817 0 });
818 }
819 }
820
821 0 ▶ if (scalar @zone == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @zone == 1) { } 0 0 0
elsif (scalar @zone) { } 0 0 0
822 0 $self->Successful($cb, { zone => $zone[0] });
823 }
824 elsif (scalar @zone) {
825 0 $self->Successful($cb, { zone => \@zone });
826 }
827 else {
828 0 $self->Successful($cb);
829 }
830 }
831  
832 =item $server->CreateZone(...)
833  
834 Create a new zone file.
835  
836 =cut
837  
838 0 ▶sub CreateZone {
Subroutine CreateZone: not called CC=37 SCAR=72.5
Pod documented
839 0 my ($self, $cb, $q) = @_;
840  
841 0 ▶ foreach my $zone (ref($q->{zone}) eq 'ARRAY' ? @{$q->{zone}} : $q->{zone}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $q->{'zone'} eq 'ARRAY' ? : 0 0 0
842 0 my $file;
843
844 0 ▶ if ($zone->{file} !~ /\//o) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $zone->{'file'} =~ m[/]ou) { } 0 0 0
845 0 ▶ unless (exists $zone->{software}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $zone->{"software"}) 0 0 0
846 $self->Error($cb, Lim::Error->new(
847 code => 500,
848 0 message => 'Zone file '.$zone->{file}.' without path needs to specify what software it belongs to'
849 ));
850 0 return;
851 }
852 0 ▶ unless (exists $ZoneFilePath{$zone->{software}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Lim::Plugin::DNS::Server::ZoneFilePath{$zone->{"software"}}) 0 0 0
853 $self->Error($cb, Lim::Error->new(
854 code => 500,
855 message => 'Unknown software '.$zone->{software}.' specified for zone file '.$zone->{file}
856 0 ));
857 0 return;
858 }
859
860 0 foreach my $path (keys %{$ZoneFilePath{$zone->{software}}}) {
861 0 my $entry = $ZoneFilePath{$zone->{software}}->{$path};
862
863 0 ▶ if (exists $entry->{creatable} and $entry->{creatable}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $entry->{"creatable"} and $entry->{"creatable"}) 0 0 0
Condition0%0/3
exists $entry->{"creatable"} and $entry->{"creatable"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $entry->{"creatable"} and $entry->{"creatable"}
exists $entry->{"creatable"} $entry->{"creatable"}
Truth table0%0/3
A and B
A= exists $entry->{"creatable"}B= $entry->{"creatable"}
ABresult
0X0
100
111
864 0 ▶ if (exists $entry->{match}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $entry->{"match"}) 0 0 0
865 0 ▶ unless ($zone->{file} =~ $entry->{match}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($zone->{"file"} =~ /$entry->{"match"}/u) 0 0 0
866 0 next;
867 }
868 }
869 0 $file = $path .'/'. $zone->{file};
870 }
871 }
872 }
873 else {
874 0 ▶ if ($zone->{file} =~ /^(.+)\/([^\/]+)$/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zone->{"file"} =~ m[^(.+)/([^/]+)$]ou) 0 0 0
875 0 my ($path, $filename) = ($1, $2);
876
877 0 foreach my $software (keys %ZoneFilePath) {
878 0 ▶ if (exists $ZoneFilePath{$software}->{$path}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Lim::Plugin::DNS::Server::ZoneFilePath{$software}{$path}) 0 0 0
879 0 my $entry = $ZoneFilePath{$software}->{$path};
880  
881 0 ▶ if (exists $entry->{creatable} and $entry->{creatable}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $entry->{"creatable"} and $entry->{"creatable"}) 0 0 0
Condition0%0/3
exists $entry->{"creatable"} and $entry->{"creatable"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $entry->{"creatable"} and $entry->{"creatable"}
exists $entry->{"creatable"} $entry->{"creatable"}
Truth table0%0/3
A and B
A= exists $entry->{"creatable"}B= $entry->{"creatable"}
ABresult
0X0
100
111
882 0 ▶ if (exists $entry->{match}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $entry->{"match"}) 0 0 0
883 0 ▶ unless ($zone->{file} =~ $entry->{match}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($zone->{"file"} =~ /$entry->{"match"}/u) 0 0 0
884 0 next;
885 }
886 }
887 0 $file = $path .'/'. $filename;
888 }
889 }
890 }
891 }
892 }
893
894 0 ▶ unless (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $file) 0 0 0
895 $self->Error($cb, Lim::Error->new(
896 code => 500,
897 0 message => 'Zone file '.$zone->{file}.' invalid or restricted to be created on specified path'
898 ));
899 0 return;
900 }
901 0 ▶ if (-f $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $file) 0 0 0
902 $self->Error($cb, Lim::Error->new(
903 code => 500,
904 0 message => 'Zone file '.$zone->{file}.' already exists'
905 ));
906 0 return;
907 }
908 0 ▶ if (exists $zone->{content} and (exists $zone->{options} or exists $zone->{rr})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $zone->{"content"} and exists $zone->{"options"} || exists $zone->{"rr"}) 0 0 0
Condition0%0/6
exists $zone->{"content"} and exists $zone->{"options"} || exists $zone->{"rr"}
!ll&&!rl&&r
000
exists $zone->{"options"} or exists $zone->{"rr"}
l!l&&r!l&&!r
000
MC/DC0%0/3
exists $zone->{"content"} and exists $zone->{"options"} || exists $zone->{"rr"}
exists $zone->{"content"} exists $zone->{"options"} exists $zone->{"rr"}
Truth table0%0/4
A and B or C
A= exists $zone->{"content"}B= exists $zone->{"options"}C= exists $zone->{"rr"}
ABCresult
0XX0
1000
11X1
1011
909 $self->Error($cb, Lim::Error->new(
910 code => 500,
911 0 message => 'Zone file '.$zone->{file}.' can not specify content and also specify options or rr'
912 ));
913 0 return;
914 }
915
916 0 ▶ if (exists $zone->{content}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $zone->{'content'}) { } 0 0 0
917 0 ▶ unless (Lim::Util::FileWriteContent($file, $zone->{content})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (Lim::Util::FileWriteContent($file, $zone->{"content"})) 0 0 0
918 $self->Error($cb, Lim::Error->new(
919 code => 500,
920 0 message => 'Unable to write content of zone file '.$zone->{file}.' to file '.$file
921 ));
922 0 return;
923 }
924 }
925 else {
926 # Mode on file
927 0 my $tmp = Lim::Util::TempFile;
928 0 ▶ unless (defined $tmp) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tmp) 0 0 0
929 $self->Error($cb, Lim::Error->new(
930 code => 500,
931 message => 'Unable to create temporary file for zone file '.$zone->{file}
932 0 ));
933 0 return;
934 }
935
936 0 ▶ if (exists $zone->{options}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $zone->{"options"}) 0 0 0
937 0 foreach my $option (values %{$zone->{options}}) {
938 0 print $tmp '$', uc($option->{name}), ' ', $option->{value}, "\n";
939 }
940 }
941 0 ▶ if (exists $zone->{rr}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $zone->{"rr"}) 0 0 0
942 0 foreach my $rr (values %{$zone->{rr}}) {
943 print $tmp join("\t",
944 $rr->{name},
945 exists $rr->{ttl} ? $rr->{ttl} : '',
946 exists $rr->{class} ? uc($rr->{class}) : '',
947 uc($rr->{type}),
948 $rr->{rdata}
949 0 ▶ ), "\n";
Branch: 2 branches
BranchTrueFalseTotal
exists $rr->{'ttl'} ? : 0 0 0
exists $rr->{'class'} ? : 0 0 0
950
951 0 ▶ if (exists $rr->{rr}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $rr->{"rr"}) 0 0 0
952 0 foreach my $more_rr (values %{$rr->{rr}}) {
953 print $tmp join("\t",
954 '',
955 exists $more_rr->{ttl} ? $more_rr->{ttl} : '',
956 exists $more_rr->{class} ? uc($more_rr->{class}) : '',
957 uc($more_rr->{type}),
958 $more_rr->{rdata}
959 0 ▶ ), "\n";
Branch: 2 branches
BranchTrueFalseTotal
exists $more_rr->{'ttl'} ? : 0 0 0
exists $more_rr->{'class'} ? : 0 0 0
960 }
961 }
962 }
963 }
964
965 0 $tmp->flush;
966 0 $tmp->close;
967
968 0 ▶ unless (rename($tmp->filename, $file)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (rename $tmp->filename, $file) 0 0 0
969 $self->Error($cb, Lim::Error->new(
970 code => 500,
971 message => 'Unable to rename the temporary file '.$tmp->filename.' to '.$file.' for zone file '.$zone->{file}
972 0 ));
973 0 return;
974 }
975 }
976 }
977 0 $self->Successful($cb);
978 }
979  
980 =item $server->ReadZone(...)
981  
982 Returns a zone file as a content or split into option and rr.
983  
984 =cut
985  
986 0 ▶sub ReadZone {
Subroutine ReadZone: not called CC=27 SCAR=66.3
Pod documented
987 0 my ($self, $cb, $q) = @_;
988 0 my $files = $self->_ScanZoneFile;
989 0 my @zones;
990  
991 0 ▶ foreach my $zone (ref($q->{zone}) eq 'ARRAY' ? @{$q->{zone}} : $q->{zone}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $q->{'zone'} eq 'ARRAY' ? : 0 0 0
992 0 my ($file, $software);
993  
994 0 ▶ if (exists $zone->{software}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $zone->{'software'}) { } 0 0 0
995 0 ▶ unless (exists $ZoneFilePath{$zone->{software}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Lim::Plugin::DNS::Server::ZoneFilePath{$zone->{"software"}}) 0 0 0
996 $self->Error($cb, Lim::Error->new(
997 code => 500,
998 message => 'Unknown software '.$zone->{software}.' specified for zone file '.$zone->{file}
999 0 ));
1000 0 return;
1001 }
1002
1003 0 ▶ if (exists $files->{$zone->{software}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$files{$zone->{"software"}}) 0 0 0
1004 0 foreach (values %{$files->{$zone->{software}}}) {
1005 0 ▶ if ($_->{read} and ($_->{short} eq $zone->{file} or $_->{name} eq $zone->{file})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"read"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}) 0 0 0
Condition0%0/6
$_->{"read"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}
!ll&&!rl&&r
000
$_->{"short"} eq $zone->{"file"} or $_->{"name"} eq $zone->{"file"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$_->{"read"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}
$_->{"read"} $_->{"short"} eq $zone->{"file"} $_->{"name"} eq $zone->{"file"}
Truth table0%0/4
A and B or C
A= $_->{"read"}B= $_->{"short"} eq $zone->{"file"}C= $_->{"name"} eq $zone->{"file"}
ABCresult
0XX0
1000
11X1
1011
1006 0 $file = $_;
1007 0 $software = $zone->{software};
1008 0 last;
1009 }
1010 }
1011 }
1012 }
1013 else {
1014 0 foreach $software (keys %$files) {
1015 0 foreach (values %{$files->{$software}}) {
1016 0 ▶ if ($_->{read} and $_->{name} eq $zone->{file}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"read"} and $_->{"name"} eq $zone->{"file"}) 0 0 0
Condition0%0/3
$_->{"read"} and $_->{"name"} eq $zone->{"file"}
!ll&&!rl&&r
000
MC/DC0%0/2
$_->{"read"} and $_->{"name"} eq $zone->{"file"}
$_->{"read"} $_->{"name"} eq $zone->{"file"}
Truth table0%0/3
A and B
A= $_->{"read"}B= $_->{"name"} eq $zone->{"file"}
ABresult
0X0
100
111
1017 0 $file = $_;
1018 0 last;
1019 }
1020 }
1021 0 ▶ if (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file) 0 0 0
1022 0 last;
1023 }
1024 }
1025 }
1026  
1027 0 ▶ unless (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $file) 0 0 0
1028 0 next;
1029 }
1030
1031 0 ▶ if (exists $zone->{as_content} and $zone->{as_content}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $zone->{"as_content"} and $zone->{"as_content"}) 0 0 0
Condition0%0/3
exists $zone->{"as_content"} and $zone->{"as_content"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $zone->{"as_content"} and $zone->{"as_content"}
exists $zone->{"as_content"} $zone->{"as_content"}
Truth table0%0/3
A and B
A= exists $zone->{"as_content"}B= $zone->{"as_content"}
ABresult
0X0
100
111
1032 0 my $content = Lim::Util::FileReadContent($file->{name});
1033 0 ▶ unless (defined $content) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $content) 0 0 0
1034 $self->Error($cb, Lim::Error->new(
1035 code => 500,
1036 message => 'Unable to read zone file '.$zone->{file}
1037 0 ));
1038 0 return;
1039 }
1040 push(@zones, {
1041 file => $file->{name},
1042 software => $file->{software},
1043 0 content => $content
1044 });
1045 0 next;
1046 }
1047  
1048 0 my $fh;
1049 0 ▶ unless (defined ($fh = IO::File->new($file->{name}))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined($fh = "IO::File"->new($file->{"name"}))) 0 0 0
1050 $self->Error($cb, Lim::Error->new(
1051 code => 500,
1052 message => 'Unable to open zone file '.$zone->{file}
1053 0 ));
1054 0 return;
1055 }
1056
1057 0 my (@options, @rrs);
1058 0 ▶ unless ($self->_ParseZoneFile($fh, \@options, \@rrs)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_ParseZoneFile($fh, \@options, \@rrs)) 0 0 0
1059 0 $fh->close;
1060 $self->Error($cb, Lim::Error->new(
1061 code => 500,
1062 message => 'Unable to parse zone file '.$zone->{file}
1063 0 ));
1064 0 return;
1065 }
1066 0 $fh->close;
1067
1068 push(@zones, {
1069 file => $file->{name},
1070 software => $file->{software},
1071 0 ▶ (scalar @options ? (option => scalar @options == 1 ? $options[0] : \@options) : ()),
Branch: 4 branches
BranchTrueFalseTotal
scalar @options ? : 0 0 0
scalar @options == 1 ? : 0 0 0
scalar @rrs ? : 0 0 0
scalar @rrs == 1 ? : 0 0 0
1072 (scalar @rrs ? (rr => scalar @rrs == 1 ? $rrs[0] : \@rrs) : ())
1073 });
1074 }
1075
1076 0 ▶ if (scalar @zones == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @zones == 1) { } 0 0 0
elsif (scalar @zones) { } 0 0 0
1077 0 $self->Successful($cb, { zone => $zones[0] });
1078 }
1079 elsif (scalar @zones) {
1080 0 $self->Successful($cb, { zone => \@zones });
1081 }
1082 else {
1083 0 $self->Successful($cb);
1084 }
1085 }
1086  
1087 =item $server->UpdateZone(...)
1088  
1089 Update a zone file, this overwrites all zone data.
1090  
1091 =cut
1092  
1093 0 ▶sub UpdateZone {
Subroutine UpdateZone: not called CC=30 SCAR=68.4
Pod documented
1094 0 my ($self, $cb, $q) = @_;
1095 0 my $files = $self->_ScanZoneFile;
1096  
1097 0 ▶ foreach my $zone (ref($q->{zone}) eq 'ARRAY' ? @{$q->{zone}} : $q->{zone}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $q->{'zone'} eq 'ARRAY' ? : 0 0 0
1098 0 my $file;
1099  
1100 0 ▶ if (exists $zone->{software}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $zone->{'software'}) { } 0 0 0
1101 0 ▶ unless (exists $ZoneFilePath{$zone->{software}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Lim::Plugin::DNS::Server::ZoneFilePath{$zone->{"software"}}) 0 0 0
1102 $self->Error($cb, Lim::Error->new(
1103 code => 500,
1104 message => 'Unknown software '.$zone->{software}.' specified for zone file '.$zone->{file}
1105 0 ));
1106 0 return;
1107 }
1108
1109 0 ▶ if (exists $files->{$zone->{software}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$files{$zone->{"software"}}) 0 0 0
1110 0 foreach (values %{$files->{$zone->{software}}}) {
1111 0 ▶ if ($_->{write} and ($_->{short} eq $zone->{file} or $_->{name} eq $zone->{file})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"write"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}) 0 0 0
Condition0%0/6
$_->{"write"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}
!ll&&!rl&&r
000
$_->{"short"} eq $zone->{"file"} or $_->{"name"} eq $zone->{"file"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$_->{"write"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}
$_->{"write"} $_->{"short"} eq $zone->{"file"} $_->{"name"} eq $zone->{"file"}
Truth table0%0/4
A and B or C
A= $_->{"write"}B= $_->{"short"} eq $zone->{"file"}C= $_->{"name"} eq $zone->{"file"}
ABCresult
0XX0
1000
11X1
1011
1112 0 $file = $_;
1113 0 last;
1114 }
1115 }
1116 }
1117 }
1118 else {
1119 0 foreach my $software (keys %$files) {
1120 0 foreach (values %{$files->{$software}}) {
1121 0 ▶ if ($_->{write} and $_->{name} eq $zone->{file}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"write"} and $_->{"name"} eq $zone->{"file"}) 0 0 0
Condition0%0/3
$_->{"write"} and $_->{"name"} eq $zone->{"file"}
!ll&&!rl&&r
000
MC/DC0%0/2
$_->{"write"} and $_->{"name"} eq $zone->{"file"}
$_->{"write"} $_->{"name"} eq $zone->{"file"}
Truth table0%0/3
A and B
A= $_->{"write"}B= $_->{"name"} eq $zone->{"file"}
ABresult
0X0
100
111
1122 0 $file = $_;
1123 0 last;
1124 }
1125 }
1126 0 ▶ if (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file) 0 0 0
1127 0 last;
1128 }
1129 }
1130 }
1131  
1132 0 ▶ unless (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $file) 0 0 0
1133 $self->Error($cb, Lim::Error->new(
1134 code => 500,
1135 message => 'Unable to find zone file '.$zone->{file}
1136 0 ));
1137 0 return;
1138 }
1139
1140 0 ▶ if (exists $zone->{content}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $zone->{'content'}) { } 0 0 0
1141 0 ▶ unless (Lim::Util::FileWriteContent($file->{name}, $zone->{content})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (Lim::Util::FileWriteContent($file->{"name"}, $zone->{"content"})) 0 0 0
1142 $self->Error($cb, Lim::Error->new(
1143 code => 500,
1144 message => 'Unable to write content of zone file '.$zone->{file}
1145 0 ));
1146 0 return;
1147 }
1148 }
1149 else {
1150 0 my $tmp = Lim::Util::TempFileLikeThis($file->{name});
1151 0 ▶ unless (defined $tmp) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tmp) 0 0 0
1152 $self->Error($cb, Lim::Error->new(
1153 code => 500,
1154 message => 'Unable to create temporary file for zone file '.$zone->{file}
1155 0 ));
1156 0 return;
1157 }
1158
1159 0 ▶ if (exists $zone->{options}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $zone->{"options"}) 0 0 0
1160 0 foreach my $option (values %{$zone->{options}}) {
1161 0 print $tmp '$', uc($option->{name}), ' ', $option->{value}, "\n";
1162 }
1163 }
1164 0 ▶ if (exists $zone->{rr}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $zone->{"rr"}) 0 0 0
1165 0 foreach my $rr (values %{$zone->{rr}}) {
1166 print $tmp join("\t",
1167 $rr->{name},
1168 exists $rr->{ttl} ? $rr->{ttl} : '',
1169 exists $rr->{class} ? uc($rr->{class}) : '',
1170 uc($rr->{type}),
1171 $rr->{rdata}
1172 0 ▶ ), "\n";
Branch: 2 branches
BranchTrueFalseTotal
exists $rr->{'ttl'} ? : 0 0 0
exists $rr->{'class'} ? : 0 0 0
1173
1174 0 ▶ if (exists $rr->{rr}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $rr->{"rr"}) 0 0 0
1175 0 foreach my $more_rr (values %{$rr->{rr}}) {
1176 print $tmp join("\t",
1177 '',
1178 exists $more_rr->{ttl} ? $more_rr->{ttl} : '',
1179 exists $more_rr->{class} ? uc($more_rr->{class}) : '',
1180 uc($more_rr->{type}),
1181 $more_rr->{rdata}
1182 0 ▶ ), "\n";
Branch: 2 branches
BranchTrueFalseTotal
exists $more_rr->{'ttl'} ? : 0 0 0
exists $more_rr->{'class'} ? : 0 0 0
1183 }
1184 }
1185 }
1186 }
1187
1188 0 $tmp->flush;
1189 0 $tmp->close;
1190
1191 0 ▶ unless (rename($tmp->filename, $file->{name})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (rename $tmp->filename, $file->{"name"}) 0 0 0
1192 $self->Error($cb, Lim::Error->new(
1193 code => 500,
1194 message => 'Unable to rename the temporary file '.$tmp->filename.' to '.$file->{name}.' for zone file '.$zone->{file}
1195 0 ));
1196 0 return;
1197 }
1198 }
1199 }
1200 0 $self->Successful($cb);
1201 }
1202  
1203 =item $server->DeleteZone(...)
1204  
1205 Delete a zone file.
1206  
1207 =cut
1208  
1209 0 ▶sub DeleteZone {
Subroutine DeleteZone: not called CC=17 SCAR=57.2
Pod documented
1210 0 my ($self, $cb, $q) = @_;
1211 0 my $files = $self->_ScanZoneFile;
1212  
1213 0 ▶ foreach my $zone (ref($q->{zone}) eq 'ARRAY' ? @{$q->{zone}} : $q->{zone}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $q->{'zone'} eq 'ARRAY' ? : 0 0 0
1214 0 my $file;
1215  
1216 0 ▶ if (exists $zone->{software}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $zone->{'software'}) { } 0 0 0
1217 0 ▶ unless (exists $ZoneFilePath{$zone->{software}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Lim::Plugin::DNS::Server::ZoneFilePath{$zone->{"software"}}) 0 0 0
1218 $self->Error($cb, Lim::Error->new(
1219 code => 500,
1220 message => 'Unknown software '.$zone->{software}.' specified for zone file '.$zone->{file}
1221 0 ));
1222 0 return;
1223 }
1224
1225 0 ▶ if (exists $files->{$zone->{software}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$files{$zone->{"software"}}) 0 0 0
1226 0 foreach (values %{$files->{$zone->{software}}}) {
1227 0 ▶ if ($_->{write} and ($_->{short} eq $zone->{file} or $_->{name} eq $zone->{file})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"write"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}) 0 0 0
Condition0%0/6
$_->{"write"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}
!ll&&!rl&&r
000
$_->{"short"} eq $zone->{"file"} or $_->{"name"} eq $zone->{"file"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$_->{"write"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}
$_->{"write"} $_->{"short"} eq $zone->{"file"} $_->{"name"} eq $zone->{"file"}
Truth table0%0/4
A and B or C
A= $_->{"write"}B= $_->{"short"} eq $zone->{"file"}C= $_->{"name"} eq $zone->{"file"}
ABCresult
0XX0
1000
11X1
1011
1228 0 $file = $_;
1229 0 last;
1230 }
1231 }
1232 }
1233 }
1234 else {
1235 0 foreach my $software (keys %$files) {
1236 0 foreach (values %{$files->{$software}}) {
1237 0 ▶ if ($_->{write} and $_->{name} eq $zone->{file}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"write"} and $_->{"name"} eq $zone->{"file"}) 0 0 0
Condition0%0/3
$_->{"write"} and $_->{"name"} eq $zone->{"file"}
!ll&&!rl&&r
000
MC/DC0%0/2
$_->{"write"} and $_->{"name"} eq $zone->{"file"}
$_->{"write"} $_->{"name"} eq $zone->{"file"}
Truth table0%0/3
A and B
A= $_->{"write"}B= $_->{"name"} eq $zone->{"file"}
ABresult
0X0
100
111
1238 0 $file = $_;
1239 0 last;
1240 }
1241 }
1242 0 ▶ if (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file) 0 0 0
1243 0 last;
1244 }
1245 }
1246 }
1247  
1248 0 ▶ unless (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $file) 0 0 0
1249 0 next;
1250 }
1251  
1252 0 ▶ unless (unlink($file->{name})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (unlink $file->{"name"}) 0 0 0
1253 $self->Error($cb, Lim::Error->new(
1254 code => 500,
1255 message => 'Unable to remove file '.$file->{name}.' for zone file '.$zone->{file}
1256 0 ));
1257 0 return;
1258 }
1259 }
1260 0 $self->Successful($cb);
1261 }
1262  
1263 =item $server->CreateZoneOption(...)
1264  
1265 Create a new zone option.
1266  
1267 =cut
1268  
1269 0 ▶sub CreateZoneOption {
Subroutine CreateZoneOption: not called CC=20 SCAR=60.4
Pod documented
1270 0 my ($self, $cb, $q) = @_;
1271 0 my $files = $self->_ScanZoneFile;
1272  
1273 0 ▶ foreach my $zone (ref($q->{zone}) eq 'ARRAY' ? @{$q->{zone}} : $q->{zone}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $q->{'zone'} eq 'ARRAY' ? : 0 0 0
1274 0 my $file;
1275  
1276 0 ▶ if (exists $zone->{software}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $zone->{'software'}) { } 0 0 0
1277 0 ▶ unless (exists $ZoneFilePath{$zone->{software}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Lim::Plugin::DNS::Server::ZoneFilePath{$zone->{"software"}}) 0 0 0
1278 $self->Error($cb, Lim::Error->new(
1279 code => 500,
1280 message => 'Unknown software '.$zone->{software}.' specified for zone file '.$zone->{file}
1281 0 ));
1282 0 return;
1283 }
1284
1285 0 ▶ if (exists $files->{$zone->{software}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$files{$zone->{"software"}}) 0 0 0
1286 0 foreach (values %{$files->{$zone->{software}}}) {
1287 0 ▶ if ($_->{write} and ($_->{short} eq $zone->{file} or $_->{name} eq $zone->{file})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"write"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}) 0 0 0
Condition0%0/6
$_->{"write"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}
!ll&&!rl&&r
000
$_->{"short"} eq $zone->{"file"} or $_->{"name"} eq $zone->{"file"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$_->{"write"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}
$_->{"write"} $_->{"short"} eq $zone->{"file"} $_->{"name"} eq $zone->{"file"}
Truth table0%0/4
A and B or C
A= $_->{"write"}B= $_->{"short"} eq $zone->{"file"}C= $_->{"name"} eq $zone->{"file"}
ABCresult
0XX0
1000
11X1
1011
1288 0 $file = $_;
1289 0 last;
1290 }
1291 }
1292 }
1293 }
1294 else {
1295 0 foreach my $software (keys %$files) {
1296 0 foreach (values %{$files->{$software}}) {
1297 0 ▶ if ($_->{write} and $_->{name} eq $zone->{file}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"write"} and $_->{"name"} eq $zone->{"file"}) 0 0 0
Condition0%0/3
$_->{"write"} and $_->{"name"} eq $zone->{"file"}
!ll&&!rl&&r
000
MC/DC0%0/2
$_->{"write"} and $_->{"name"} eq $zone->{"file"}
$_->{"write"} $_->{"name"} eq $zone->{"file"}
Truth table0%0/3
A and B
A= $_->{"write"}B= $_->{"name"} eq $zone->{"file"}
ABresult
0X0
100
111
1298 0 $file = $_;
1299 0 last;
1300 }
1301 }
1302 0 ▶ if (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file) 0 0 0
1303 0 last;
1304 }
1305 }
1306 }
1307  
1308 0 ▶ unless (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $file) 0 0 0
1309 $self->Error($cb, Lim::Error->new(
1310 code => 500,
1311 message => 'Unable to find zone file '.$zone->{file}
1312 0 ));
1313 0 return;
1314 }
1315
1316 0 my $fh;
1317 0 ▶ unless (defined ($fh = IO::File->new($file->{name}))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined($fh = "IO::File"->new($file->{"name"}))) 0 0 0
1318 $self->Error($cb, Lim::Error->new(
1319 code => 500,
1320 message => 'Unable to open zone file '.$zone->{file}
1321 0 ));
1322 0 return;
1323 }
1324  
1325 0 my (@options, @rrs);
1326 0 ▶ unless ($self->_ParseZoneFile($fh, \@options, \@rrs)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_ParseZoneFile($fh, \@options, \@rrs)) 0 0 0
1327 0 $fh->close;
1328 $self->Error($cb, Lim::Error->new(
1329 code => 500,
1330 message => 'Unable to parse zone file '.$zone->{file}
1331 0 ));
1332 0 return;
1333 }
1334 0 $fh->close;
1335
1336 0 ▶ push(@options, ref($zone->{option}) eq 'ARRAY' ? @{$zone->{option}} : $zone->{option});
Branch: 1 branch
BranchTrueFalseTotal
ref $zone->{'option'} eq 'ARRAY' ? : 0 0 0
1337  
1338 0 eval { $self->_WriteZoneFile($file->{name}, \@rrs, \@options); };
1339 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1340 $self->Error($cb, Lim::Error->new(
1341 code => 500,
1342 0 message => 'Unable to write zone file '.$zone->{file}.': '.$@
1343 ));
1344 0 return;
1345 }
1346 }
1347 0 $self->Successful($cb);
1348 }
1349  
1350 =item $server->ReadZoneOption(...)
1351  
1352 Return zone options specified or all zone options for a zone file.
1353  
1354 =cut
1355  
1356 0 ▶sub ReadZoneOption {
Subroutine ReadZoneOption: not called CC=27 SCAR=66.3
Pod documented
1357 0 my ($self, $cb, $q) = @_;
1358 0 my $files = $self->_ScanZoneFile;
1359 0 my @zones;
1360  
1361 0 ▶ foreach my $zone (ref($q->{zone}) eq 'ARRAY' ? @{$q->{zone}} : $q->{zone}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $q->{'zone'} eq 'ARRAY' ? : 0 0 0
1362 0 my $file;
1363  
1364 0 ▶ if (exists $zone->{software}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $zone->{'software'}) { } 0 0 0
1365 0 ▶ unless (exists $ZoneFilePath{$zone->{software}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Lim::Plugin::DNS::Server::ZoneFilePath{$zone->{"software"}}) 0 0 0
1366 $self->Error($cb, Lim::Error->new(
1367 code => 500,
1368 message => 'Unknown software '.$zone->{software}.' specified for zone file '.$zone->{file}
1369 0 ));
1370 0 return;
1371 }
1372
1373 0 ▶ if (exists $files->{$zone->{software}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$files{$zone->{"software"}}) 0 0 0
1374 0 foreach (values %{$files->{$zone->{software}}}) {
1375 0 ▶ if ($_->{write} and ($_->{short} eq $zone->{file} or $_->{name} eq $zone->{file})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"write"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}) 0 0 0
Condition0%0/6
$_->{"write"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}
!ll&&!rl&&r
000
$_->{"short"} eq $zone->{"file"} or $_->{"name"} eq $zone->{"file"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$_->{"write"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}
$_->{"write"} $_->{"short"} eq $zone->{"file"} $_->{"name"} eq $zone->{"file"}
Truth table0%0/4
A and B or C
A= $_->{"write"}B= $_->{"short"} eq $zone->{"file"}C= $_->{"name"} eq $zone->{"file"}
ABCresult
0XX0
1000
11X1
1011
1376 0 $file = $_;
1377 0 last;
1378 }
1379 }
1380 }
1381 }
1382 else {
1383 0 foreach my $software (keys %$files) {
1384 0 foreach (values %{$files->{$software}}) {
1385 0 ▶ if ($_->{write} and $_->{name} eq $zone->{file}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"write"} and $_->{"name"} eq $zone->{"file"}) 0 0 0
Condition0%0/3
$_->{"write"} and $_->{"name"} eq $zone->{"file"}
!ll&&!rl&&r
000
MC/DC0%0/2
$_->{"write"} and $_->{"name"} eq $zone->{"file"}
$_->{"write"} $_->{"name"} eq $zone->{"file"}
Truth table0%0/3
A and B
A= $_->{"write"}B= $_->{"name"} eq $zone->{"file"}
ABresult
0X0
100
111
1386 0 $file = $_;
1387 0 last;
1388 }
1389 }
1390 0 ▶ if (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file) 0 0 0
1391 0 last;
1392 }
1393 }
1394 }
1395  
1396 0 ▶ unless (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $file) 0 0 0
1397 $self->Error($cb, Lim::Error->new(
1398 code => 500,
1399 message => 'Unable to find zone file '.$zone->{file}
1400 0 ));
1401 0 return;
1402 }
1403
1404 0 my $fh;
1405 0 ▶ unless (defined ($fh = IO::File->new($file->{name}))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined($fh = "IO::File"->new($file->{"name"}))) 0 0 0
1406 $self->Error($cb, Lim::Error->new(
1407 code => 500,
1408 message => 'Unable to open zone file '.$zone->{file}
1409 0 ));
1410 0 return;
1411 }
1412  
1413 0 my @options;
1414 0 ▶ if (exists $zone->{option}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $zone->{'option'}) { } 0 0 0
1415 0 my %option;
1416 0 ▶ unless ($self->_ParseZoneFile($fh, \%option)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_ParseZoneFile($fh, \%option)) 0 0 0
1417 0 $fh->close;
1418 $self->Error($cb, Lim::Error->new(
1419 code => 500,
1420 message => 'Unable to parse zone file '.$zone->{file}
1421 0 ));
1422 0 return;
1423 }
1424
1425 0 ▶ foreach my $option (ref($zone->{option}) eq 'ARRAY' ? @{$zone->{option}} : $zone->{option}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $zone->{'option'} eq 'ARRAY' ? : 0 0 0
1426 0 ▶ if (exists $option{$option->{name}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $option{$option->{"name"}}) 0 0 0
1427 push(@options, {
1428 name => $option->{name},
1429 value => $option{$option->{name}}
1430 0 });
1431 }
1432 }
1433 }
1434 else {
1435 0 ▶ unless ($self->_ParseZoneFile($fh, \@options)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_ParseZoneFile($fh, \@options)) 0 0 0
1436 0 $fh->close;
1437 $self->Error($cb, Lim::Error->new(
1438 code => 500,
1439 message => 'Unable to parse zone file '.$zone->{file}
1440 0 ));
1441 0 return;
1442 }
1443 }
1444 0 $fh->close;
1445
1446 0 ▶ if (scalar @options) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @options) 0 0 0
1447 push(@zones, {
1448 file => $file->{name},
1449 software => $file->{software},
1450 0 ▶ option => scalar @options == 1 ? $options[0] : \@options
Branch: 1 branch
BranchTrueFalseTotal
scalar @options == 1 ? : 0 0 0
1451 })
1452 }
1453 }
1454 0 ▶ if (scalar @zones == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @zones == 1) { } 0 0 0
elsif (scalar @zones) { } 0 0 0
1455 0 $self->Successful($cb, { zone => $zones[0] });
1456 }
1457 elsif (scalar @zones) {
1458 0 $self->Successful($cb, { zone => \@zones });
1459 }
1460 else {
1461 0 $self->Successful($cb);
1462 }
1463 }
1464  
1465 =item $server->UpdateZoneOption(...)
1466  
1467 Update a zone option, this does not overwrite other zone options.
1468  
1469 =cut
1470  
1471 0 ▶sub UpdateZoneOption {
Subroutine UpdateZoneOption: not called CC=22 SCAR=62.3
Pod documented
1472 0 my ($self, $cb, $q) = @_;
1473 0 my $files = $self->_ScanZoneFile;
1474  
1475 0 ▶ foreach my $zone (ref($q->{zone}) eq 'ARRAY' ? @{$q->{zone}} : $q->{zone}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $q->{'zone'} eq 'ARRAY' ? : 0 0 0
1476 0 my $file;
1477  
1478 0 ▶ if (exists $zone->{software}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $zone->{'software'}) { } 0 0 0
1479 0 ▶ unless (exists $ZoneFilePath{$zone->{software}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Lim::Plugin::DNS::Server::ZoneFilePath{$zone->{"software"}}) 0 0 0
1480 $self->Error($cb, Lim::Error->new(
1481 code => 500,
1482 message => 'Unknown software '.$zone->{software}.' specified for zone file '.$zone->{file}
1483 0 ));
1484 0 return;
1485 }
1486
1487 0 ▶ if (exists $files->{$zone->{software}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$files{$zone->{"software"}}) 0 0 0
1488 0 foreach (values %{$files->{$zone->{software}}}) {
1489 0 ▶ if ($_->{write} and ($_->{short} eq $zone->{file} or $_->{name} eq $zone->{file})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"write"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}) 0 0 0
Condition0%0/6
$_->{"write"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}
!ll&&!rl&&r
000
$_->{"short"} eq $zone->{"file"} or $_->{"name"} eq $zone->{"file"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$_->{"write"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}
$_->{"write"} $_->{"short"} eq $zone->{"file"} $_->{"name"} eq $zone->{"file"}
Truth table0%0/4
A and B or C
A= $_->{"write"}B= $_->{"short"} eq $zone->{"file"}C= $_->{"name"} eq $zone->{"file"}
ABCresult
0XX0
1000
11X1
1011
1490 0 $file = $_;
1491 0 last;
1492 }
1493 }
1494 }
1495 }
1496 else {
1497 0 foreach my $software (keys %$files) {
1498 0 foreach (values %{$files->{$software}}) {
1499 0 ▶ if ($_->{write} and $_->{name} eq $zone->{file}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"write"} and $_->{"name"} eq $zone->{"file"}) 0 0 0
Condition0%0/3
$_->{"write"} and $_->{"name"} eq $zone->{"file"}
!ll&&!rl&&r
000
MC/DC0%0/2
$_->{"write"} and $_->{"name"} eq $zone->{"file"}
$_->{"write"} $_->{"name"} eq $zone->{"file"}
Truth table0%0/3
A and B
A= $_->{"write"}B= $_->{"name"} eq $zone->{"file"}
ABresult
0X0
100
111
1500 0 $file = $_;
1501 0 last;
1502 }
1503 }
1504 0 ▶ if (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file) 0 0 0
1505 0 last;
1506 }
1507 }
1508 }
1509  
1510 0 ▶ unless (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $file) 0 0 0
1511 $self->Error($cb, Lim::Error->new(
1512 code => 500,
1513 message => 'Unable to find zone file '.$zone->{file}
1514 0 ));
1515 0 return;
1516 }
1517
1518 0 my $fh;
1519 0 ▶ unless (defined ($fh = IO::File->new($file->{name}))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined($fh = "IO::File"->new($file->{"name"}))) 0 0 0
1520 $self->Error($cb, Lim::Error->new(
1521 code => 500,
1522 message => 'Unable to open zone file '.$zone->{file}
1523 0 ));
1524 0 return;
1525 }
1526  
1527 0 my (%option, @rrs);
1528 0 ▶ unless ($self->_ParseZoneFile($fh, \%option, \@rrs)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_ParseZoneFile($fh, \%option, \@rrs)) 0 0 0
1529 0 $fh->close;
1530 $self->Error($cb, Lim::Error->new(
1531 code => 500,
1532 message => 'Unable to parse zone file '.$zone->{file}
1533 0 ));
1534 0 return;
1535 }
1536 0 $fh->close;
1537
1538 0 ▶ foreach my $option (ref($zone->{option}) eq 'ARRAY' ? @{$zone->{option}} : $zone->{option}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $zone->{'option'} eq 'ARRAY' ? : 0 0 0
1539 0 ▶ unless (exists $option{$option->{name}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $option{$option->{"name"}}) 0 0 0
1540 $self->Error($cb, Lim::Error->new(
1541 code => 500,
1542 message => 'Option '.$option->{name}.' does not exists, can not update it in zone file '.$zone->{file}
1543 0 ));
1544 0 return;
1545 }
1546  
1547 0 $option{$option->{name}} = $option->{value};
1548 }
1549  
1550 0 eval { $self->_WriteZoneFile($file->{name}, \@rrs, \%option); };
1551 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1552 $self->Error($cb, Lim::Error->new(
1553 code => 500,
1554 0 message => 'Unable to write zone file '.$zone->{file}.': '.$@
1555 ));
1556 0 return;
1557 }
1558 }
1559 0 $self->Successful($cb);
1560 }
1561  
1562 =item $server->DeleteZoneOption(...)
1563  
1564 Delete a zone options.
1565  
1566 =cut
1567  
1568 0 ▶sub DeleteZoneOption {
Subroutine DeleteZoneOption: not called CC=22 SCAR=62.3
Pod documented
1569 0 my ($self, $cb, $q) = @_;
1570 0 my $files = $self->_ScanZoneFile;
1571  
1572 0 ▶ foreach my $zone (ref($q->{zone}) eq 'ARRAY' ? @{$q->{zone}} : $q->{zone}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $q->{'zone'} eq 'ARRAY' ? : 0 0 0
1573 0 my $file;
1574  
1575 0 ▶ if (exists $zone->{software}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $zone->{'software'}) { } 0 0 0
1576 0 ▶ unless (exists $ZoneFilePath{$zone->{software}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Lim::Plugin::DNS::Server::ZoneFilePath{$zone->{"software"}}) 0 0 0
1577 $self->Error($cb, Lim::Error->new(
1578 code => 500,
1579 message => 'Unknown software '.$zone->{software}.' specified for zone file '.$zone->{file}
1580 0 ));
1581 0 return;
1582 }
1583
1584 0 ▶ if (exists $files->{$zone->{software}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$files{$zone->{"software"}}) 0 0 0
1585 0 foreach (values %{$files->{$zone->{software}}}) {
1586 0 ▶ if ($_->{write} and ($_->{short} eq $zone->{file} or $_->{name} eq $zone->{file})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"write"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}) 0 0 0
Condition0%0/6
$_->{"write"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}
!ll&&!rl&&r
000
$_->{"short"} eq $zone->{"file"} or $_->{"name"} eq $zone->{"file"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$_->{"write"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}
$_->{"write"} $_->{"short"} eq $zone->{"file"} $_->{"name"} eq $zone->{"file"}
Truth table0%0/4
A and B or C
A= $_->{"write"}B= $_->{"short"} eq $zone->{"file"}C= $_->{"name"} eq $zone->{"file"}
ABCresult
0XX0
1000
11X1
1011
1587 0 $file = $_;
1588 0 last;
1589 }
1590 }
1591 }
1592 }
1593 else {
1594 0 foreach my $software (keys %$files) {
1595 0 foreach (values %{$files->{$software}}) {
1596 0 ▶ if ($_->{write} and $_->{name} eq $zone->{file}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"write"} and $_->{"name"} eq $zone->{"file"}) 0 0 0
Condition0%0/3
$_->{"write"} and $_->{"name"} eq $zone->{"file"}
!ll&&!rl&&r
000
MC/DC0%0/2
$_->{"write"} and $_->{"name"} eq $zone->{"file"}
$_->{"write"} $_->{"name"} eq $zone->{"file"}
Truth table0%0/3
A and B
A= $_->{"write"}B= $_->{"name"} eq $zone->{"file"}
ABresult
0X0
100
111
1597 0 $file = $_;
1598 0 last;
1599 }
1600 }
1601 0 ▶ if (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file) 0 0 0
1602 0 last;
1603 }
1604 }
1605 }
1606  
1607 0 ▶ unless (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $file) 0 0 0
1608 $self->Error($cb, Lim::Error->new(
1609 code => 500,
1610 message => 'Unable to find zone file '.$zone->{file}
1611 0 ));
1612 0 return;
1613 }
1614
1615 0 my $fh;
1616 0 ▶ unless (defined ($fh = IO::File->new($file->{name}))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined($fh = "IO::File"->new($file->{"name"}))) 0 0 0
1617 $self->Error($cb, Lim::Error->new(
1618 code => 500,
1619 message => 'Unable to open zone file '.$zone->{file}
1620 0 ));
1621 0 return;
1622 }
1623  
1624 0 my (%option, @rrs);
1625 0 ▶ unless ($self->_ParseZoneFile($fh, \%option, \@rrs)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_ParseZoneFile($fh, \%option, \@rrs)) 0 0 0
1626 0 $fh->close;
1627 $self->Error($cb, Lim::Error->new(
1628 code => 500,
1629 message => 'Unable to parse zone file '.$zone->{file}
1630 0 ));
1631 0 return;
1632 }
1633 0 $fh->close;
1634
1635 0 ▶ foreach my $option (ref($zone->{option}) eq 'ARRAY' ? @{$zone->{option}} : $zone->{option}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $zone->{'option'} eq 'ARRAY' ? : 0 0 0
1636 0 ▶ if (exists $option{$option->{name}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $option{$option->{"name"}}) 0 0 0
1637 0 delete $option{$option->{name}};
1638 }
1639 }
1640  
1641 0 eval { $self->_WriteZoneFile($file->{name}, \@rrs, \%option); };
1642 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1643 $self->Error($cb, Lim::Error->new(
1644 code => 500,
1645 0 message => 'Unable to write zone file '.$zone->{file}.': '.$@
1646 ));
1647 0 return;
1648 }
1649 }
1650 0 $self->Successful($cb);
1651 }
1652  
1653 =item $server->CreateZoneRr(...)
1654  
1655 Create a new zone resource record.
1656  
1657 =cut
1658  
1659 0 ▶sub CreateZoneRr {
Subroutine CreateZoneRr: not called CC=28 SCAR=67.0
Pod documented
1660 0 my ($self, $cb, $q) = @_;
1661 0 my $files = $self->_ScanZoneFile;
1662  
1663 0 ▶ foreach my $zone (ref($q->{zone}) eq 'ARRAY' ? @{$q->{zone}} : $q->{zone}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $q->{'zone'} eq 'ARRAY' ? : 0 0 0
1664 0 my $file;
1665  
1666 0 ▶ if (exists $zone->{software}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $zone->{'software'}) { } 0 0 0
1667 0 ▶ unless (exists $ZoneFilePath{$zone->{software}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Lim::Plugin::DNS::Server::ZoneFilePath{$zone->{"software"}}) 0 0 0
1668 $self->Error($cb, Lim::Error->new(
1669 code => 500,
1670 message => 'Unknown software '.$zone->{software}.' specified for zone file '.$zone->{file}
1671 0 ));
1672 0 return;
1673 }
1674
1675 0 ▶ if (exists $files->{$zone->{software}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$files{$zone->{"software"}}) 0 0 0
1676 0 foreach (values %{$files->{$zone->{software}}}) {
1677 0 ▶ if ($_->{write} and ($_->{short} eq $zone->{file} or $_->{name} eq $zone->{file})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"write"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}) 0 0 0
Condition0%0/6
$_->{"write"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}
!ll&&!rl&&r
000
$_->{"short"} eq $zone->{"file"} or $_->{"name"} eq $zone->{"file"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$_->{"write"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}
$_->{"write"} $_->{"short"} eq $zone->{"file"} $_->{"name"} eq $zone->{"file"}
Truth table0%0/4
A and B or C
A= $_->{"write"}B= $_->{"short"} eq $zone->{"file"}C= $_->{"name"} eq $zone->{"file"}
ABCresult
0XX0
1000
11X1
1011
1678 0 $file = $_;
1679 0 last;
1680 }
1681 }
1682 }
1683 }
1684 else {
1685 0 foreach my $software (keys %$files) {
1686 0 foreach (values %{$files->{$software}}) {
1687 0 ▶ if ($_->{write} and $_->{name} eq $zone->{file}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"write"} and $_->{"name"} eq $zone->{"file"}) 0 0 0
Condition0%0/3
$_->{"write"} and $_->{"name"} eq $zone->{"file"}
!ll&&!rl&&r
000
MC/DC0%0/2
$_->{"write"} and $_->{"name"} eq $zone->{"file"}
$_->{"write"} $_->{"name"} eq $zone->{"file"}
Truth table0%0/3
A and B
A= $_->{"write"}B= $_->{"name"} eq $zone->{"file"}
ABresult
0X0
100
111
1688 0 $file = $_;
1689 0 last;
1690 }
1691 }
1692 0 ▶ if (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file) 0 0 0
1693 0 last;
1694 }
1695 }
1696 }
1697  
1698 0 ▶ unless (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $file) 0 0 0
1699 $self->Error($cb, Lim::Error->new(
1700 code => 500,
1701 message => 'Unable to find zone file '.$zone->{file}
1702 0 ));
1703 0 return;
1704 }
1705
1706 0 my $fh;
1707 0 ▶ unless (defined ($fh = IO::File->new($file->{name}))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined($fh = "IO::File"->new($file->{"name"}))) 0 0 0
1708 $self->Error($cb, Lim::Error->new(
1709 code => 500,
1710 message => 'Unable to open zone file '.$zone->{file}
1711 0 ));
1712 0 return;
1713 }
1714  
1715 0 my (@options, @rrs);
1716 0 ▶ unless ($self->_ParseZoneFile($fh, \@options, \@rrs)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_ParseZoneFile($fh, \@options, \@rrs)) 0 0 0
1717 0 $fh->close;
1718 $self->Error($cb, Lim::Error->new(
1719 code => 500,
1720 message => 'Unable to parse zone file '.$zone->{file}
1721 0 ));
1722 0 return;
1723 }
1724 0 $fh->close;
1725
1726 0 ▶ foreach my $rr (ref($zone->{rr}) eq 'ARRAY' ? @{$zone->{rr}} : $zone->{rr}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $zone->{'rr'} eq 'ARRAY' ? : 0 0 0
1727 push(@rrs, {
1728 name => $rr->{name},
1729 (exists $rr->{ttl} ? (ttl => $rr->{ttl}) : ()),
1730 (exists $rr->{class} ? (class => $rr->{class}) : ()),
1731 type => $rr->{type},
1732 rdata => $rr->{rdata}
1733 0 ▶ });
Branch: 2 branches
BranchTrueFalseTotal
exists $rr->{'ttl'} ? : 0 0 0
exists $rr->{'class'} ? : 0 0 0
1734
1735 0 ▶ if (exists $rr->{rr}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $rr->{"rr"}) 0 0 0
1736 0 ▶ foreach (ref($rr->{rr}) eq 'ARRAY' ? @{$rr->{rr}} : $rr->{rr}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $rr->{'rr'} eq 'ARRAY' ? : 0 0 0
1737 push(@rrs, {
1738 name => $rr->{name},
1739 (exists $_->{ttl} ? (ttl => $_->{ttl}) : ()),
1740 (exists $_->{class} ? (class => $_->{class}) : ()),
1741 type => $_->{type},
1742 rdata => $_->{rdata}
1743 0 ▶ });
Branch: 2 branches
BranchTrueFalseTotal
exists $_->{'ttl'} ? : 0 0 0
exists $_->{'class'} ? : 0 0 0
1744 }
1745 }
1746 }
1747  
1748 0 eval { $self->_WriteZoneFile($file->{name}, \@rrs, \@options); };
1749 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1750 $self->Error($cb, Lim::Error->new(
1751 code => 500,
1752 0 message => 'Unable to write zone file '.$zone->{file}.': '.$@
1753 ));
1754 0 return;
1755 }
1756 }
1757 0 $self->Successful($cb);
1758 }
1759  
1760 =item $server->ReadZoneRr(...)
1761  
1762 Return zone resource records specified or all zone resource records for a zone
1763 file.
1764  
1765 =cut
1766  
1767 0 ▶sub ReadZoneRr {
Subroutine ReadZoneRr: not called CC=28 SCAR=67.0
Pod documented
1768 0 my ($self, $cb, $q) = @_;
1769 0 my $files = $self->_ScanZoneFile;
1770 0 my @zones;
1771  
1772 0 ▶ foreach my $zone (ref($q->{zone}) eq 'ARRAY' ? @{$q->{zone}} : $q->{zone}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $q->{'zone'} eq 'ARRAY' ? : 0 0 0
1773 0 my $file;
1774  
1775 0 ▶ if (exists $zone->{software}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $zone->{'software'}) { } 0 0 0
1776 0 ▶ unless (exists $ZoneFilePath{$zone->{software}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Lim::Plugin::DNS::Server::ZoneFilePath{$zone->{"software"}}) 0 0 0
1777 $self->Error($cb, Lim::Error->new(
1778 code => 500,
1779 message => 'Unknown software '.$zone->{software}.' specified for zone file '.$zone->{file}
1780 0 ));
1781 0 return;
1782 }
1783
1784 0 ▶ if (exists $files->{$zone->{software}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$files{$zone->{"software"}}) 0 0 0
1785 0 foreach (values %{$files->{$zone->{software}}}) {
1786 0 ▶ if ($_->{write} and ($_->{short} eq $zone->{file} or $_->{name} eq $zone->{file})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"write"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}) 0 0 0
Condition0%0/6
$_->{"write"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}
!ll&&!rl&&r
000
$_->{"short"} eq $zone->{"file"} or $_->{"name"} eq $zone->{"file"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$_->{"write"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}
$_->{"write"} $_->{"short"} eq $zone->{"file"} $_->{"name"} eq $zone->{"file"}
Truth table0%0/4
A and B or C
A= $_->{"write"}B= $_->{"short"} eq $zone->{"file"}C= $_->{"name"} eq $zone->{"file"}
ABCresult
0XX0
1000
11X1
1011
1787 0 $file = $_;
1788 0 last;
1789 }
1790 }
1791 }
1792 }
1793 else {
1794 0 foreach my $software (keys %$files) {
1795 0 foreach (values %{$files->{$software}}) {
1796 0 ▶ if ($_->{write} and $_->{name} eq $zone->{file}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"write"} and $_->{"name"} eq $zone->{"file"}) 0 0 0
Condition0%0/3
$_->{"write"} and $_->{"name"} eq $zone->{"file"}
!ll&&!rl&&r
000
MC/DC0%0/2
$_->{"write"} and $_->{"name"} eq $zone->{"file"}
$_->{"write"} $_->{"name"} eq $zone->{"file"}
Truth table0%0/3
A and B
A= $_->{"write"}B= $_->{"name"} eq $zone->{"file"}
ABresult
0X0
100
111
1797 0 $file = $_;
1798 0 last;
1799 }
1800 }
1801 0 ▶ if (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file) 0 0 0
1802 0 last;
1803 }
1804 }
1805 }
1806  
1807 0 ▶ unless (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $file) 0 0 0
1808 $self->Error($cb, Lim::Error->new(
1809 code => 500,
1810 message => 'Unable to find zone file '.$zone->{file}
1811 0 ));
1812 0 return;
1813 }
1814
1815 0 my $fh;
1816 0 ▶ unless (defined ($fh = IO::File->new($file->{name}))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined($fh = "IO::File"->new($file->{"name"}))) 0 0 0
1817 $self->Error($cb, Lim::Error->new(
1818 code => 500,
1819 message => 'Unable to open zone file '.$zone->{file}
1820 0 ));
1821 0 return;
1822 }
1823  
1824 0 my @rrs;
1825 0 ▶ if (exists $zone->{rr}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $zone->{'rr'}) { } 0 0 0
1826 0 my %rr;
1827 0 ▶ unless ($self->_ParseZoneFile($fh, undef, \%rr)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_ParseZoneFile($fh, undef, \%rr)) 0 0 0
1828 0 $fh->close;
1829 $self->Error($cb, Lim::Error->new(
1830 code => 500,
1831 message => 'Unable to parse zone file '.$zone->{file}
1832 0 ));
1833 0 return;
1834 }
1835
1836 0 ▶ foreach my $rr (ref($zone->{rr}) eq 'ARRAY' ? @{$zone->{rr}} : $zone->{rr}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $zone->{'rr'} eq 'ARRAY' ? : 0 0 0
1837 0 ▶ if (exists $rr{$rr->{name}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $rr{$rr->{"name"}}) 0 0 0
1838 0 foreach (@{$rr{$rr->{name}}}) {
1839 0 $_->{name} = $rr->{name};
1840 0 push(@rrs, $_);
1841 }
1842 }
1843 }
1844 }
1845 else {
1846 0 ▶ unless ($self->_ParseZoneFile($fh, undef, \@rrs)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_ParseZoneFile($fh, undef, \@rrs)) 0 0 0
1847 0 $fh->close;
1848 $self->Error($cb, Lim::Error->new(
1849 code => 500,
1850 message => 'Unable to parse zone file '.$zone->{file}
1851 0 ));
1852 0 return;
1853 }
1854 }
1855 0 $fh->close;
1856
1857 0 ▶ if (scalar @rrs) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @rrs) 0 0 0
1858 push(@zones, {
1859 file => $file->{name},
1860 software => $file->{software},
1861 0 ▶ rr => scalar @rrs == 1 ? $rrs[0] : \@rrs
Branch: 1 branch
BranchTrueFalseTotal
scalar @rrs == 1 ? : 0 0 0
1862 })
1863 }
1864 }
1865 0 ▶ if (scalar @zones == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @zones == 1) { } 0 0 0
elsif (scalar @zones) { } 0 0 0
1866 0 $self->Successful($cb, { zone => $zones[0] });
1867 }
1868 elsif (scalar @zones) {
1869 0 $self->Successful($cb, { zone => \@zones });
1870 }
1871 else {
1872 0 $self->Successful($cb);
1873 }
1874 }
1875  
1876 =item $server->UpdateZoneRr(...)
1877  
1878 Update a zone resource record, this does not remove other zone resource records.
1879  
1880 =cut
1881  
1882 0 ▶sub UpdateZoneRr {
Subroutine UpdateZoneRr: not called CC=29 SCAR=67.7
Pod documented
1883 0 my ($self, $cb, $q) = @_;
1884 0 my $files = $self->_ScanZoneFile;
1885  
1886 0 ▶ foreach my $zone (ref($q->{zone}) eq 'ARRAY' ? @{$q->{zone}} : $q->{zone}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $q->{'zone'} eq 'ARRAY' ? : 0 0 0
1887 0 my $file;
1888  
1889 0 ▶ if (exists $zone->{software}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $zone->{'software'}) { } 0 0 0
1890 0 ▶ unless (exists $ZoneFilePath{$zone->{software}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Lim::Plugin::DNS::Server::ZoneFilePath{$zone->{"software"}}) 0 0 0
1891 $self->Error($cb, Lim::Error->new(
1892 code => 500,
1893 message => 'Unknown software '.$zone->{software}.' specified for zone file '.$zone->{file}
1894 0 ));
1895 0 return;
1896 }
1897
1898 0 ▶ if (exists $files->{$zone->{software}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$files{$zone->{"software"}}) 0 0 0
1899 0 foreach (values %{$files->{$zone->{software}}}) {
1900 0 ▶ if ($_->{write} and ($_->{short} eq $zone->{file} or $_->{name} eq $zone->{file})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"write"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}) 0 0 0
Condition0%0/6
$_->{"write"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}
!ll&&!rl&&r
000
$_->{"short"} eq $zone->{"file"} or $_->{"name"} eq $zone->{"file"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$_->{"write"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}
$_->{"write"} $_->{"short"} eq $zone->{"file"} $_->{"name"} eq $zone->{"file"}
Truth table0%0/4
A and B or C
A= $_->{"write"}B= $_->{"short"} eq $zone->{"file"}C= $_->{"name"} eq $zone->{"file"}
ABCresult
0XX0
1000
11X1
1011
1901 0 $file = $_;
1902 0 last;
1903 }
1904 }
1905 }
1906 }
1907 else {
1908 0 foreach my $software (keys %$files) {
1909 0 foreach (values %{$files->{$software}}) {
1910 0 ▶ if ($_->{write} and $_->{name} eq $zone->{file}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"write"} and $_->{"name"} eq $zone->{"file"}) 0 0 0
Condition0%0/3
$_->{"write"} and $_->{"name"} eq $zone->{"file"}
!ll&&!rl&&r
000
MC/DC0%0/2
$_->{"write"} and $_->{"name"} eq $zone->{"file"}
$_->{"write"} $_->{"name"} eq $zone->{"file"}
Truth table0%0/3
A and B
A= $_->{"write"}B= $_->{"name"} eq $zone->{"file"}
ABresult
0X0
100
111
1911 0 $file = $_;
1912 0 last;
1913 }
1914 }
1915 0 ▶ if (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file) 0 0 0
1916 0 last;
1917 }
1918 }
1919 }
1920  
1921 0 ▶ unless (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $file) 0 0 0
1922 $self->Error($cb, Lim::Error->new(
1923 code => 500,
1924 message => 'Unable to find zone file '.$zone->{file}
1925 0 ));
1926 0 return;
1927 }
1928
1929 0 my $fh;
1930 0 ▶ unless (defined ($fh = IO::File->new($file->{name}))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined($fh = "IO::File"->new($file->{"name"}))) 0 0 0
1931 $self->Error($cb, Lim::Error->new(
1932 code => 500,
1933 message => 'Unable to open zone file '.$zone->{file}
1934 0 ));
1935 0 return;
1936 }
1937  
1938 0 my (@options, %rr);
1939 0 ▶ unless ($self->_ParseZoneFile($fh, \@options, \%rr)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_ParseZoneFile($fh, \@options, \%rr)) 0 0 0
1940 0 $fh->close;
1941 $self->Error($cb, Lim::Error->new(
1942 code => 500,
1943 message => 'Unable to parse zone file '.$zone->{file}
1944 0 ));
1945 0 return;
1946 }
1947 0 $fh->close;
1948
1949 0 ▶ foreach my $rr (ref($zone->{rr}) eq 'ARRAY' ? @{$zone->{rr}} : $zone->{rr}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $zone->{'rr'} eq 'ARRAY' ? : 0 0 0
1950 0 ▶ unless (exists $rr{$rr->{name}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $rr{$rr->{"name"}}) 0 0 0
1951 $self->Error($cb, Lim::Error->new(
1952 code => 500,
1953 message => 'RR '.$rr->{name}.' does not exists, can not update it in zone file '.$zone->{file}
1954 0 ));
1955 0 return;
1956 }
1957  
1958 $rr{$rr->{name}} = [{
1959 (exists $rr->{ttl} ? (ttl => $rr->{ttl}) : ()),
1960 (exists $rr->{class} ? (class => $rr->{class}) : ()),
1961 type => $rr->{type},
1962 rdata => $rr->{rdata}
1963 0 ▶ }];
Branch: 2 branches
BranchTrueFalseTotal
exists $rr->{'ttl'} ? : 0 0 0
exists $rr->{'class'} ? : 0 0 0
1964
1965 0 ▶ if (exists $rr->{rr}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $rr->{"rr"}) 0 0 0
1966 0 ▶ foreach (ref($rr->{rr}) eq 'ARRAY' ? @{$rr->{rr}} : $rr->{rr}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $rr->{'rr'} eq 'ARRAY' ? : 0 0 0
1967 0 ▶ push(@{$rr{$rr->{name}}}, {
Branch: 2 branches
BranchTrueFalseTotal
exists $_->{'ttl'} ? : 0 0 0
exists $_->{'class'} ? : 0 0 0
1968 (exists $_->{ttl} ? (ttl => $_->{ttl}) : ()),
1969 (exists $_->{class} ? (class => $_->{class}) : ()),
1970 type => $_->{type},
1971 rdata => $_->{rdata}
1972 0 });
1973 }
1974 }
1975 }
1976
1977 0 eval { $self->_WriteZoneFile($file->{name}, \%rr, \@options); };
1978 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1979 $self->Error($cb, Lim::Error->new(
1980 code => 500,
1981 0 message => 'Unable to write zone file '.$zone->{file}.': '.$@
1982 ));
1983 0 return;
1984 }
1985 }
1986 0 $self->Successful($cb);
1987 }
1988  
1989 =item $server->DeleteZoneRr(...)
1990  
1991 Delete a zone resource records.
1992  
1993 =cut
1994  
1995 0 ▶sub DeleteZoneRr {
Subroutine DeleteZoneRr: not called CC=22 SCAR=62.3
Pod documented
1996 0 my ($self, $cb, $q) = @_;
1997 0 my $files = $self->_ScanZoneFile;
1998  
1999 0 ▶ foreach my $zone (ref($q->{zone}) eq 'ARRAY' ? @{$q->{zone}} : $q->{zone}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $q->{'zone'} eq 'ARRAY' ? : 0 0 0
2000 0 my $file;
2001  
2002 0 ▶ if (exists $zone->{software}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $zone->{'software'}) { } 0 0 0
2003 0 ▶ unless (exists $ZoneFilePath{$zone->{software}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Lim::Plugin::DNS::Server::ZoneFilePath{$zone->{"software"}}) 0 0 0
2004 $self->Error($cb, Lim::Error->new(
2005 code => 500,
2006 message => 'Unknown software '.$zone->{software}.' specified for zone file '.$zone->{file}
2007 0 ));
2008 0 return;
2009 }
2010
2011 0 ▶ if (exists $files->{$zone->{software}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$files{$zone->{"software"}}) 0 0 0
2012 0 foreach (values %{$files->{$zone->{software}}}) {
2013 0 ▶ if ($_->{write} and ($_->{short} eq $zone->{file} or $_->{name} eq $zone->{file})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"write"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}) 0 0 0
Condition0%0/6
$_->{"write"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}
!ll&&!rl&&r
000
$_->{"short"} eq $zone->{"file"} or $_->{"name"} eq $zone->{"file"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$_->{"write"} and $_->{"short"} eq $zone->{"file"} || $_->{"name"} eq $zone->{"file"}
$_->{"write"} $_->{"short"} eq $zone->{"file"} $_->{"name"} eq $zone->{"file"}
Truth table0%0/4
A and B or C
A= $_->{"write"}B= $_->{"short"} eq $zone->{"file"}C= $_->{"name"} eq $zone->{"file"}
ABCresult
0XX0
1000
11X1
1011
2014 0 $file = $_;
2015 0 last;
2016 }
2017 }
2018 }
2019 }
2020 else {
2021 0 foreach my $software (keys %$files) {
2022 0 foreach (values %{$files->{$software}}) {
2023 0 ▶ if ($_->{write} and $_->{name} eq $zone->{file}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"write"} and $_->{"name"} eq $zone->{"file"}) 0 0 0
Condition0%0/3
$_->{"write"} and $_->{"name"} eq $zone->{"file"}
!ll&&!rl&&r
000
MC/DC0%0/2
$_->{"write"} and $_->{"name"} eq $zone->{"file"}
$_->{"write"} $_->{"name"} eq $zone->{"file"}
Truth table0%0/3
A and B
A= $_->{"write"}B= $_->{"name"} eq $zone->{"file"}
ABresult
0X0
100
111
2024 0 $file = $_;
2025 0 last;
2026 }
2027 }
2028 0 ▶ if (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file) 0 0 0
2029 0 last;
2030 }
2031 }
2032 }
2033  
2034 0 ▶ unless (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $file) 0 0 0
2035 $self->Error($cb, Lim::Error->new(
2036 code => 500,
2037 message => 'Unable to find zone file '.$zone->{file}
2038 0 ));
2039 0 return;
2040 }
2041
2042 0 my $fh;
2043 0 ▶ unless (defined ($fh = IO::File->new($file->{name}))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined($fh = "IO::File"->new($file->{"name"}))) 0 0 0
2044 $self->Error($cb, Lim::Error->new(
2045 code => 500,
2046 message => 'Unable to open zone file '.$zone->{file}
2047 0 ));
2048 0 return;
2049 }
2050  
2051 0 my (@options, %rr);
2052 0 ▶ unless ($self->_ParseZoneFile($fh, \@options, \%rr)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_ParseZoneFile($fh, \@options, \%rr)) 0 0 0
2053 0 $fh->close;
2054 $self->Error($cb, Lim::Error->new(
2055 code => 500,
2056 message => 'Unable to parse zone file '.$zone->{file}
2057 0 ));
2058 0 return;
2059 }
2060 0 $fh->close;
2061
2062 # TODO: Make it so you can delete just a specific rr in a rr set?
2063 0 ▶ foreach my $rr (ref($zone->{rr}) eq 'ARRAY' ? @{$zone->{rr}} : $zone->{rr}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $zone->{'rr'} eq 'ARRAY' ? : 0 0 0
2064 0 ▶ if (exists $rr{$rr->{name}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $rr{$rr->{"name"}}) 0 0 0
2065 0 delete $rr{$rr->{name}};
2066 }
2067 }
2068  
2069 0 eval { $self->_WriteZoneFile($file->{name}, \%rr, \@options); };
2070 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
2071 $self->Error($cb, Lim::Error->new(
2072 code => 500,
2073 0 message => 'Unable to write zone file '.$zone->{file}.': '.$@
2074 ));
2075 0 return;
2076 }
2077 }
2078 0 $self->Successful($cb);
2079 }
2080  
2081 =back
2082  
2083 =head1 AUTHOR
2084  
2085 Jerry Lundström, C<< <lundstrom.jerry at gmail.com> >>
2086  
2087 =head1 BUGS
2088  
2089 Please report any bugs or feature requests to L<https://github.com/jelu/lim-plugin-dns/issues>.
2090  
2091 =head1 SUPPORT
2092  
2093 You can find documentation for this module with the perldoc command.
2094  
2095 perldoc Lim::Plugin::DNS
2096  
2097 You can also look for information at:
2098  
2099 =over 4
2100  
2101 =item * Lim issue tracker (report bugs here)
2102  
2103 L<https://github.com/jelu/lim-plugin-dns/issues>
2104  
2105 =back
2106  
2107 =head1 ACKNOWLEDGEMENTS
2108  
2109 =head1 LICENSE AND COPYRIGHT
2110  
2111 Copyright 2012-2013 Jerry Lundström.
2112  
2113 This program is free software; you can redistribute it and/or modify it
2114 under the terms of either: the GNU General Public License as published
2115 by the Free Software Foundation; or the Artistic License.
2116  
2117 See http://dev.perl.org/licenses/ for more information.
2118  
2119  
2120 =cut
2121  
2122 1 1; # End of Lim::Plugin::DNS::Server
↑ Summary DNS/CLI.pm »