blib/lib/DNS/TinyDNS/dnsserver.pm

filter: Statementstmt 11.1% 17 / 153 Branchbran 0.0% 0 / 106 Conditioncond 0.0% 0 / 89 MC/DCmcdc 0.0% 0 / 50 Subroutinesub 23.5% 4 / 17 Podpod 100% 8 / 8 totaltotal 6.8% 29 / 423 CC 86 SCAR 60.4
CC
86
Cov
5%
del
930.0
add
462.0
list
210.0
CRAP 420.0
↑ Summary blib/lib/DNS/TinyDNS/dnscache.pm »
1 # by Anarion
2 # anarion@7a69ezine.org
3 package DNS::TinyDNS::dnsserver;
4  
5 1 our @ISA = qw(DNS::TinyDNS);
6 1 our $VERSION = '0.22';
7  
8 =head1 NAME
9  
10 DNS::TinyDNS::dnsserver - Perl extension for manipulating dnsserver from djbdns
11  
12 =head1 SYNOPSIS
13  
14 use DNS::TinyDNS;
15  
16 # First create the object
17 my $dnsserver = DNS::TinyDNS->new(type => 'dnsserver',
18 dir => '/service/tinydns');
19  
20 # Get zones
21 @zones = $dnsserver->list_zones;
22  
23 # Get one zone
24 $zone = $dnsserver->get_zone($zones[0]);
25  
26 # Add entry
27 $dnsserver->add(zone => $zones[0],
28 type => 'ns',
29 host => 'anarion.7a69ezine.org',
30 ttl => 84500,
31 );
32  
33 # Modify ip where tinydns listens
34 $dnsserver->set_env( IP => '10.0.0.1' );
35 $dnsserver->restart;
36  
37  
38 =head1 DESCRIPTION
39  
40 This module will allow you to manipulate djbdns dnsserver files.
41  
42 =head1 FUNCTIONS
43  
44 =over 4
45  
46 =head2 get_env/set_env
47  
48 =back
49  
50 You can set/get the this vars:
51  
52 IP
53 ROOT
54  
55 For further information about every var, consult djbdns server documentation at
56 C<http://cr.yp.to/>
57  
58 =over 4
59  
60 =head2 list_zones
61  
62 =back
63  
64 This method returns a list of all the diferent zones configured
65  
66 my @zones = $dnsserver->list_zones;
67  
68 =over 4
69  
70 =head2 get_zone
71  
72 =back
73  
74 This method returns a list of hashes with all records of one zone.
75 The keys of the hash deppends on the type of the record
76  
77 my @zone_e = $dnsserver->get_zone('catalunya.cat');
78  
79 The hash have the following keys:
80  
81 type => String showing the type of the record
82 ('ns','host','mx','alias','reverse')
83 ttl => ttl of the record
84 ip => ip of the host
85 host => host is only set with ns or mx records
86 priority => is only set with mx records
87  
88 =over 4
89  
90 =head2 list
91  
92 =back
93  
94 This method return an array of hashes with all records of one type.
95 Posible types are: mx, ns, host, alias, reverse or all
96  
97 my @mxs = $dnsserver->list(type => 'mx' ,
98 zone => '7a69ezine.org');
99  
100 =over 4
101  
102 =head2 add
103  
104 =back
105  
106 This method adds a mx record
107  
108 $dnsserver->add(zone => '7a69ezine.org',
109 type => 'mx',
110 ip => '10.0.0.1',
111 host => 'rivendel.7a69ezine.org',
112 pref => 10,
113 ttl => 84500,
114 );
115  
116  
117 This method adds a ns record
118  
119 $dnsserver->add(zone => '7a69ezine.org',
120 type => 'ns',
121 ip => '10.0.0.1',
122 host => 'rivendel.7a69ezine.org',
123 ttl => 84500,
124 );
125  
126  
127 This method adds a host record
128  
129 $dnsserver->add(zone => '7a69ezine.org',
130 type => 'host',
131 ip => '10.0.0.1',
132 host => 'rivendel',
133 ttl => 84500,
134 );
135  
136 This method adds a alias record
137  
138 $dnsserver->add(zone => '7a69ezine.org',
139 type => 'alias',
140 cname=> 'www.7a69ezine.org',
141 host => 'rivendel',
142 ttl => 84500,
143 );
144  
145 This method add a reverse dns record
146  
147 $dnsserver->add(zone => '7a69ezine.org',
148 type => 'reverse',
149 host => 'anarion',
150 ip => '10.0.0.13',
151 );
152  
153  
154 =over 4
155  
156 =head2 del
157  
158 =back
159  
160 This method delete a mx record
161  
162 $dnsserver->del(zone => '7a69ezine.org',
163 type => 'mx',
164 ip => '10.0.0.1',
165 host => 'rivendel.7a69ezine.org',
166 pref => 10,
167 );
168  
169  
170 This method delete a ns record
171  
172 $dnsserver->del(zone => '7a69ezine.org',
173 type => 'ns',
174 ip => '10.0.0.1',
175 host => 'rivendel.7a69ezine.org',
176 );
177  
178  
179 This method delete a host record
180  
181 $dnsserver->del(zone => '7a69ezine.org',
182 type => 'host',
183 host => 'rivendel',
184 ip => '10.0.0.1',
185 );
186  
187 This method delete a alias record
188  
189 $dnsserver->del(zone => '7a69ezine.org',
190 type => 'alias',
191 host => 'rivendel',
192 cname=> 'www.7a69ezine.org',
193 );
194  
195 This method delete a reverse dns record
196  
197 $dnsserver->del(type => 'reverse',
198 ip => '10.0.0.13',
199 );
200  
201 =head1 NOTE
202  
203 If you want to change from named to bind you can use to methods:
204  
205 =over 4
206  
207 Allow bind to transfer the zones from localhost:
208  
209 perl -lne 'system "tcpclient 127.0.0.1 53 axfr-get $1 zona-$1 zona-$1.tmp" if /zone[^"]+"([^"]+)"/' /home/named/etc/named.conf
210  
211 Use L<DNS::ZoneParse> and DNS::TinyDNS::dnsserver.
212  
213 =back
214  
215 =head1 AUTHOR
216  
217 Anarion: anarion@7a69ezine.org
218  
219 This library is free software; you can redistribute it and/or modify
220 it under the same terms as Perl itself.
221  
222 =head1 SEE ALSO
223  
224 L<DNS::TinyDNS::dnscache>.
225 L<DNS::TinyDNS>.
226  
227 =cut
228  
229 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
230 1 ▶use Fcntl qw(:DEFAULT :flock);
Subroutine BEGIN: called CC=1 SCAR=0.0
231 1 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
232  
233 1 my %types = ( 'ns' => '[.&]',
234 'host' => '[=+]',
235 'alias' => 'C',
236 'mx' => '@',
237 'reverse'=> '\^',
238 'all' => '[C.&=+@^]');
239  
240 1 my %parse = ( 'ns' => \&_parse_ns,
241 'host' => \&_parse_host,
242 'alias' => \&_parse_alias,
243 'mx' => \&_parse_mx,
244 'reverse'=> \&_parse_reverse,
245 'all' => \&_parse_all );
246  
247  
248 sub new
249 1 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod documented
250 1 my ($clase,$dir)=@_;
251 1 my $self = { dir => $dir,
252 t_env => { IP => '' ,
253 ROOT => '' },
254 svc => '/usr/local/bin/svc'
255 };
256 1 return bless $self,$clase;
257 }
258  
259 sub start
260 0 ▶{
Subroutine start: not called CC=3 SCAR=24.8
Pod documented
261 0 my $self = shift;
262 0 my $c_dir = getcwd;
263 0 ▶ chdir($self->{dir} . '/root')
Branch: 1 branch
BranchTrueFalseTotal
chdir $self->{"dir"} . '/root' or carp(qq[Error cant chdir to $self->{"dir"}]) 0 0 0
264 or carp "Error cant chdir to $self->{dir}";
265 0 ▶ system "/usr/bin/make"
Branch: 1 branch
BranchTrueFalseTotal
system "/usr/bin/make" and carp("Error cant make database") 0 0 0
266 and carp "Error cant make database";
267  
268 0 chdir($c_dir);
269 0 $self->SUPER::start();
270 }
271  
272 sub restart
273 0 ▶{
Subroutine restart: not called CC=3 SCAR=24.8
Pod documented
274 0 my $self = shift;
275 0 my $c_dir = getcwd;
276 0 ▶ chdir($self->{dir} . '/root')
Branch: 1 branch
BranchTrueFalseTotal
chdir $self->{"dir"} . '/root' or carp(qq[Error cant chdir to $self->{"dir"}]) 0 0 0
277 or carp "Error cant chdir to $self->{dir}";
278 0 ▶ system "/usr/bin/make"
Branch: 1 branch
BranchTrueFalseTotal
system "/usr/bin/make" and carp("Error cant make database") 0 0 0
279 and carp "Error cant make database";
280  
281 0 chdir($c_dir);
282 0 $self->SUPER::restart();
283 }
284  
285 sub list
286 0 ▶{
Subroutine list: not called CC=14 SCAR=53.5
Pod documented
287 0 my ($self,%options) = @_;
288 0 my $file = $self->{dir} . "/root/data";
289 0 my (@zone);
290 0 local *FILE;
291  
292 0 ▶ unless($self->{dir} and -f $file)
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"dir"} and -f $file) 0 0 0
Condition0%0/3
$self->{"dir"} and -f $file
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"dir"} and -f $file
$self->{"dir"} -f $file
Truth table0%0/3
A and B
A= $self->{"dir"}B= -f $file
ABresult
0X0
100
111
293 {
294 0 carp "ERROR: dnsserver directory not set";
295 0 return 0;
296 }
297  
298 0 ▶ unless($options{type} and exists $types{$options{type}})
Branch: 1 branch
BranchTrueFalseTotal
unless ($options{"type"} and exists $types{$options{"type"}}) 0 0 0
Condition0%0/3
$options{"type"} and exists $types{$options{"type"}}
!ll&&!rl&&r
000
MC/DC0%0/2
$options{"type"} and exists $types{$options{"type"}}
$options{"type"} exists $types{$options{"type"}}
Truth table0%0/3
A and B
A= $options{"type"}B= exists $types{$options{"type"}}
ABresult
0X0
100
111
299 {
300 0 carp "ERROR: this type doesnt exists.";
301 0 return 0;
302 }
303  
304 0 ▶ open(FILE,$file)
Branch: 1 branch
BranchTrueFalseTotal
open FILE, $file or carp("ERROR: Cant read from $file") 0 0 0
305 or carp "ERROR: Cant read from $file";
306 0 ▶ flock(FILE,LOCK_EX)
Branch: 1 branch
BranchTrueFalseTotal
flock FILE, 2 or carp("Cant lock $file") 0 0 0
307 or carp "Cant lock $file";
308 0 ▶ seek(FILE,0,0)
Branch: 1 branch
BranchTrueFalseTotal
seek FILE, 0, 0 or carp("ERROR: Cant seek $file") 0 0 0
309 or carp "ERROR: Cant seek $file";
310 0 ▶ while(my $entrada=<FILE>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $entrada = readline FILE)) 0 0 0
311 {
312 0 chomp($entrada);
313 0 ▶ if($entrada =~ /^$types{ $options{type} }/)
Branch: 1 branch
BranchTrueFalseTotal
if ($entrada =~ /^$types{$options{"type"}}/) 0 0 0
314 {
315 next if ! $options{zone} or
316 0 ▶ $entrada !~ /^.([\w\-]+\.)*\Q$options{zone}\E:/ and
Branch: 1 branch
BranchTrueFalseTotal
unless $options{"zone"} and $entrada =~ /^.([\w\-]+\.)*\Q$options{"zone"}\E:/ || $entrada =~ /^.[\w.]+\.in-addr.arpa:\Q$options{"zone"}\E:/ 0 0 0
Condition0%0/6
$options{"zone"} and $entrada =~ /^.([\w\-]+\.)*\Q$options{"zone"}\E:/ || $entrada =~ /^.[\w.]+\.in-addr.arpa:\Q$options{"zone"}\E:/
!ll&&!rl&&r
000
$entrada =~ /^.([\w\-]+\.)*\Q$options{"zone"}\E:/ or $entrada =~ /^.[\w.]+\.in-addr.arpa:\Q$options{"zone"}\E:/
l!l&&r!l&&!r
000
MC/DC0%0/3
$options{"zone"} and $entrada =~ /^.([\w\-]+\.)*\Q$options{"zone"}\E:/ || $entrada =~ /^.[\w.]+\.in-addr.arpa:\Q$options{"zone"}\E:/
$options{"zone"} $entrada =~ /^.([\w\-]+\.)*\Q$options{"zone"}\E:/ $entrada =~ /^.[\w.]+\.in-addr.arpa:\Q$options{"zone"}\E:/
Truth table0%0/4
A and B or C
A= $options{"zone"}B= $entrada =~ /^.([\w\-]+\.)*\Q$options{"zone"}\E:/C= $entrada =~ /^.[\w.]+\.in-addr.arpa:\Q$options{"zone"}\E:/
ABCresult
0XX0
1000
11X1
1011
317 $entrada !~ /^.[\w.]+\.in-addr.arpa:\Q$options{zone}\E:/;
318 0 push(@zone,$parse{ $options{type} }->($entrada));
319 }
320 }
321 0 ▶ close FILE
Branch: 1 branch
BranchTrueFalseTotal
close FILE or carp("Error: Cant Close File") 0 0 0
322 or carp "Error: Cant Close File";
323 0 return @zone;
324 }
325  
326 sub list_zones
327 0 ▶{
Subroutine list_zones: not called CC=10 SCAR=47.0
Pod documented
328 0 my $self = shift;
329 0 my $file=$self->{dir} . "/root/data";
330 0 my %zones;
331 0 local *FILE;
332  
333 0 ▶ unless($self->{dir} and -f $file)
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"dir"} and -f $file) 0 0 0
Condition0%0/3
$self->{"dir"} and -f $file
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"dir"} and -f $file
$self->{"dir"} -f $file
Truth table0%0/3
A and B
A= $self->{"dir"}B= -f $file
ABresult
0X0
100
111
334 {
335 0 carp "ERROR: dnsserver directory not set";
336 0 return 0;
337 }
338  
339 0 ▶ open(FILE,$file)
Branch: 1 branch
BranchTrueFalseTotal
open FILE, $file or carp("ERROR: Cant read from $file") 0 0 0
340 or carp "ERROR: Cant read from $file";
341 0 ▶ flock(FILE,LOCK_EX)
Branch: 1 branch
BranchTrueFalseTotal
flock FILE, 2 or carp("Cant lock $file") 0 0 0
342 or carp "Cant lock $file";
343 0 ▶ seek(FILE,0,0)
Branch: 1 branch
BranchTrueFalseTotal
seek FILE, 0, 0 or carp("ERROR: Cant seek $file") 0 0 0
344 or carp "ERROR: Cant seek $file";
345 0 ▶ while(my $entrada=<FILE>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $entrada = readline FILE)) 0 0 0
346 {
347 0 ▶ $zones{$1}++ if $entrada=~/^.(?:\d{1,3}\.)([-\w.]+\.arpa):/ or
Branch: 1 branch
BranchTrueFalseTotal
if $entrada =~ /^.(?:\d{1,3}\.)([-\w.]+\.arpa):/ or $entrada =~ /^.(?:[\w\-]+\.)*([\w\-]+\.\w{2,4}):/ 0 0 0
Condition0%0/3
$entrada =~ /^.(?:\d{1,3}\.)([-\w.]+\.arpa):/ or $entrada =~ /^.(?:[\w\-]+\.)*([\w\-]+\.\w{2,4}):/
l!l&&r!l&&!r
000
MC/DC0%0/2
$entrada =~ /^.(?:\d{1,3}\.)([-\w.]+\.arpa):/ or $entrada =~ /^.(?:[\w\-]+\.)*([\w\-]+\.\w{2,4}):/
$entrada =~ /^.(?:\d{1,3}\.)([-\w.]+\.arpa):/ $entrada =~ /^.(?:[\w\-]+\.)*([\w\-]+\.\w{2,4}):/
Truth table0%0/3
A or B
A= $entrada =~ /^.(?:\d{1,3}\.)([-\w.]+\.arpa):/B= $entrada =~ /^.(?:[\w\-]+\.)*([\w\-]+\.\w{2,4}):/
ABresult
1X1
011
000
348 $entrada=~/^.(?:[\w\-]+\.)*([\w\-]+\.\w{2,4}):/
349 }
350 0 ▶ close FILE
Branch: 1 branch
BranchTrueFalseTotal
close FILE or carp("Error: Cant Close File") 0 0 0
351 or carp "Error: Cant Close File";
352 0 return keys %zones;
353 }
354  
355 sub get_zone
356 0 ▶{
Subroutine get_zone: not called CC=10 SCAR=47.0
Pod documented
357 0 my ($self,$zone) = @_;
358 0 my $file = $self->{dir} . "/root/data";
359 0 my @zone;
360 0 local *FILE;
361  
362 0 ▶ unless($self->{dir} and -f $file)
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"dir"} and -f $file) 0 0 0
Condition0%0/3
$self->{"dir"} and -f $file
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"dir"} and -f $file
$self->{"dir"} -f $file
Truth table0%0/3
A and B
A= $self->{"dir"}B= -f $file
ABresult
0X0
100
111
363 {
364 0 carp "ERROR: dnsserver directory not set";
365 0 return 0;
366 }
367  
368 0 ▶ open(FILE,$file)
Branch: 1 branch
BranchTrueFalseTotal
open FILE, $file or carp("ERROR: Cant read from $file") 0 0 0
369 or carp "ERROR: Cant read from $file";
370 0 ▶ flock(FILE,LOCK_EX)
Branch: 1 branch
BranchTrueFalseTotal
flock FILE, 2 or carp("Cant lock $file") 0 0 0
371 or carp "Cant lock $file";
372 0 ▶ seek(FILE,0,0)
Branch: 1 branch
BranchTrueFalseTotal
seek FILE, 0, 0 or carp("ERROR: Cant seek $file") 0 0 0
373 or carp "ERROR: Cant seek $file";
374 0 ▶ while(my $entrada=<FILE>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $entrada = readline FILE)) 0 0 0
375 {
376 0 chomp($entrada);
377 0 ▶ if ($entrada=~/^$types{all}(?:[\w\.\-]*\.)*\Q$zone\E:/ or
Branch: 1 branch
BranchTrueFalseTotal
if ($entrada =~ /^$types{"all"}(?:[\w\.\-]*\.)*\Q$zone\E:/ or $entrada =~ /^\^(?:\d{1,3}\.){4}in-addr.arpa:(?:[\w\-]+\.)*\Q$zone\E/) 0 0 0
Condition0%0/3
$entrada =~ /^$types{"all"}(?:[\w\.\-]*\.)*\Q$zone\E:/ or $entrada =~ /^\^(?:\d{1,3}\.){4}in-addr.arpa:(?:[\w\-]+\.)*\Q$zone\E/
l!l&&r!l&&!r
000
MC/DC0%0/2
$entrada =~ /^$types{"all"}(?:[\w\.\-]*\.)*\Q$zone\E:/ or $entrada =~ /^\^(?:\d{1,3}\.){4}in-addr.arpa:(?:[\w\-]+\.)*\Q$zone\E/
$entrada =~ /^$types{"all"}(?:[\w\.\-]*\.)*\Q$zone\E:/ $entrada =~ /^\^(?:\d{1,3}\.){4}in-addr.arpa:(?:[\w\-]+\.)*\Q$zone\E/
Truth table0%0/3
A or B
A= $entrada =~ /^$types{"all"}(?:[\w\.\-]*\.)*\Q$zone\E:/B= $entrada =~ /^\^(?:\d{1,3}\.){4}in-addr.arpa:(?:[\w\-]+\.)*\Q$zone\E/
ABresult
1X1
011
000
378 $entrada=~/^\^(?:\d{1,3}\.){4}in-addr.arpa:(?:[\w\-]+\.)*\Q$zone\E/)
379 {
380 0 push(@zone,_parse_all->($entrada));
381 }
382 }
383 0 ▶ close FILE
Branch: 1 branch
BranchTrueFalseTotal
close FILE or carp("Error: Cant Close File") 0 0 0
384 or carp "Error: Cant Close File";
385 0 return @zone;
386 }
387  
388 sub add
389 0 ▶{
Subroutine add: not called CC=21 SCAR=61.4
Pod documented
390 0 my ($self,%options) = @_;
391 0 my $file = $self->{dir} . "/root/data";
392 0 my $string;
393 0 local *FILE;
394  
395 0 ▶ unless($self->{dir} and -f $file)
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"dir"} and -f $file) 0 0 0
Condition0%0/3
$self->{"dir"} and -f $file
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"dir"} and -f $file
$self->{"dir"} -f $file
Truth table0%0/3
A and B
A= $self->{"dir"}B= -f $file
ABresult
0X0
100
111
396 {
397 0 carp "ERROR: dnsserver directory not set";
398 0 return 0;
399 }
400  
401 0 ▶ unless(exists $types{ $options{type} })
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $types{$options{"type"}}) 0 0 0
402 {
403 0 carp "ERROR: this type doesnt exists.";
404 0 return 0;
405 }
406  
407 0 ▶ open(FILE,">>$file")
Branch: 1 branch
BranchTrueFalseTotal
open FILE, ">>$file" or carp("ERROR: Cant read from $file") 0 0 0
408 or carp "ERROR: Cant read from $file";
409 0 ▶ flock(FILE,LOCK_EX)
Branch: 1 branch
BranchTrueFalseTotal
flock FILE, 2 or carp("Cant lock $file") 0 0 0
410 or carp "Cant lock $file";
411 0 ▶ seek(FILE,0,2)
Branch: 1 branch
BranchTrueFalseTotal
seek FILE, 0, 2 or carp("ERROR: Cant seek $file") 0 0 0
412 or carp "ERROR: Cant seek $file";
413 0 ▶ $options{ttl} ||= 86400;
Condition0%0/2
$options{"ttl"} ||= 86400
l!l
00
MC/DC0%0/1
$options{"ttl"} ||= 86400
$options{"ttl"}
Truth table0%0/2
A
A= $options{"ttl"}
Aresult
11
00
414 0 for($options{type})
415 {
416 $string =
417 0 ▶ /ns/ && do { '.' . join":",@options{qw/zone ip host ttl/} } ||
Condition0%0/3
/mx/ and do { '@' . join(":", @options{"zone", "ip", "host", "pref", "ttl"}) }
!ll&&!rl&&r
000
MC/DC0%0/2
/mx/ and do { '@' . join(":", @options{"zone", "ip", "host", "pref", "ttl"}) }
/mx/ do { '@' . join(":", @options{"zone", "ip", "host", "pref", "ttl"}) }
Truth table0%0/3
A and B
A= /mx/B= do { '@' . join(":", @options{"zone", "ip", "host", "pref", "ttl"}) }
ABresult
0X0
100
111
418 0 ▶ /mx/ && do { '@' . join ":",@options{qw/zone ip host pref ttl/} } ||
Condition0%0/3
/host/ and do { qq[+$options{"host"}.] . join(":", @options{"zone", "ip", "ttl"}) }
!ll&&!rl&&r
000
MC/DC0%0/2
/host/ and do { qq[+$options{"host"}.] . join(":", @options{"zone", "ip", "ttl"}) }
/host/ do { qq[+$options{"host"}.] . join(":", @options{"zone", "ip", "ttl"}) }
Truth table0%0/3
A and B
A= /host/B= do { qq[+$options{"host"}.] . join(":", @options{"zone", "ip", "ttl"}) }
ABresult
0X0
100
111
419 0 ▶ /host/ && do { "+$options{host}." . join ":", @options{qw/zone ip ttl/} } ||
Condition0%0/3
/alias/ and do { qq[C$options{"host"}.] . join(":", @options{"zone", "cname", "ttl"}) }
!ll&&!rl&&r
000
MC/DC0%0/2
/alias/ and do { qq[C$options{"host"}.] . join(":", @options{"zone", "cname", "ttl"}) }
/alias/ do { qq[C$options{"host"}.] . join(":", @options{"zone", "cname", "ttl"}) }
Truth table0%0/3
A and B
A= /alias/B= do { qq[C$options{"host"}.] . join(":", @options{"zone", "cname", "ttl"}) }
ABresult
0X0
100
111
420 0 ▶ /alias/ && do { "C$options{host}." . join ":", @options{qw/zone cname ttl/} } ||
Condition0%0/3
/reverse/ and do { sprintf "^%d.%d.%d.%d.in-addr.arpa:%s.%s:%d", ($options{"ip"} =~ /\d+/g)[3, 2, 1, 0], @options{"host", "zone", "ttl"} }
!ll&&!rl&&r
000
MC/DC0%0/2
/reverse/ and do { sprintf "^%d.%d.%d.%d.in-addr.arpa:%s.%s:%d", ($options{"ip"} =~ /\d+/g)[3, 2, 1, 0], @options{"host", "zone", "ttl"} }
/reverse/ do { sprintf "^%d.%d.%d.%d.in-addr.arpa:%s.%s:%d", ($options{"ip"} =~ /\d+/g)[3, 2, 1, 0], @options{"host", "zone", "ttl"} }
Truth table0%0/3
A and B
A= /reverse/B= do { sprintf "^%d.%d.%d.%d.in-addr.arpa:%s.%s:%d", ($options{"ip"} =~ /\d+/g)[3, 2, 1, 0], @options{"host", "zone", "ttl"} }
ABresult
0X0
100
111
421 0 ▶ /reverse/&&do { sprintf("^%d.%d.%d.%d.in-addr.arpa:%s.%s:%d",($options{ip} =~
Branch: 1 branch
BranchTrueFalseTotal
$string = /ns/ && do { '.' . join(":", @options{"zone", "ip", "host", "ttl"}) } || /mx/ && do { '@' . join(":", @options{"zone", "ip", "host", "pref", "ttl"}) } || /host/ && do { qq[+$options{"host"}.] . join(":", @options{"zone", "ip", "ttl"}) } || /alias/ && do { qq[C$options{"host"}.] . join(":", @options{"zone", "cname", "ttl"}) } || /reverse/ && do { sprintf "^%d.%d.%d.%d.in-addr.arpa:%s.%s:%d", ($options{"ip"} =~ /\d+/g)[3, 2, 1, 0], @options{"host", "zone", "ttl"} } or carp("What type is ($_) ?") 0 0 0
Condition0%0/15
/ns/ && do { '.' . join(':', @options{'zone', 'ip', 'host', 'ttl'}) } || /mx/ && do { '@' . join(':', @options{'zone', 'ip', 'host', 'pref', 'ttl'}) } || /host/ && do { "+$options{'host'}." . join(':', @options{'zone', 'ip', 'ttl'}) } || /alias/ && do { "C$options{'host'}." . join(':', @options{'zone', 'cname', 'ttl'}) } || /reverse/ && do { sprintf '^%d.%d.%d.%d.in-addr.arpa:%s.%s:%d', ($options{'ip'} =~ /\d+/g)[3, 2, 1, 0], @options{'host', 'zone', 'ttl'} }
l!l&&r!l&&!r
000
/ns/ and do { '.' . join(":", @options{"zone", "ip", "host", "ttl"}) } or /mx/ and do { '@' . join(":", @options{"zone", "ip", "host", "pref", "ttl"}) } or /host/ and do { qq[+$options{"host"}.] . join(":", @options{"zone", "ip", "ttl"}) } or /alias/ and do { qq[C$options{"host"}.] . join(":", @options{"zone", "cname", "ttl"}) }
l!l&&r!l&&!r
000
/ns/ and do { '.' . join(":", @options{"zone", "ip", "host", "ttl"}) } or /mx/ and do { '@' . join(":", @options{"zone", "ip", "host", "pref", "ttl"}) } or /host/ and do { qq[+$options{"host"}.] . join(":", @options{"zone", "ip", "ttl"}) }
l!l&&r!l&&!r
000
/ns/ and do { '.' . join(":", @options{"zone", "ip", "host", "ttl"}) } or /mx/ and do { '@' . join(":", @options{"zone", "ip", "host", "pref", "ttl"}) }
l!l&&r!l&&!r
000
/ns/ and do { '.' . join(":", @options{"zone", "ip", "host", "ttl"}) }
!ll&&!rl&&r
000
MC/DC0%0/6
/ns/ && do { '.' . join(':', @options{'zone', 'ip', 'host', 'ttl'}) } || /mx/ && do { '@' . join(':', @options{'zone', 'ip', 'host', 'pref', 'ttl'}) } || /host/ && do { "+$options{'host'}." . join(':', @options{'zone', 'ip', 'ttl'}) } || /alias/ && do { "C$options{'host'}." . join(':', @options{'zone', 'cname', 'ttl'}) } || /reverse/ && do { sprintf '^%d.%d.%d.%d.in-addr.arpa:%s.%s:%d', ($options{'ip'} =~ /\d+/g)[3, 2, 1, 0], @options{'host', 'zone', 'ttl'} }
/ns/ do { '.' . join(":", @options{"zone", "ip", "host", "ttl"}) } /mx/ and do { '@' . join(":", @options{"zone", "ip", "host", "pref", "ttl"}) } /host/ and do { qq[+$options{"host"}.] . join(":", @options{"zone", "ip", "ttl"}) } /alias/ and do { qq[C$options{"host"}.] . join(":", @options{"zone", "cname", "ttl"}) } /reverse/ && do { sprintf '^%d.%d.%d.%d.in-addr.arpa:%s.%s:%d', ($options{'ip'} =~ /\d+/g)[3, 2, 1, 0], @options{'host', 'zone', 'ttl'} }
Truth table0%0/11
A and B or C or D or E || F
A= /ns/B= do { '.' . join(":", @options{"zone", "ip", "host", "ttl"}) }C= /mx/ and do { '@' . join(":", @options{"zone", "ip", "host", "pref", "ttl"}) }D= /host/ and do { qq[+$options{"host"}.] . join(":", @options{"zone", "ip", "ttl"}) }E= /alias/ and do { qq[C$options{"host"}.] . join(":", @options{"zone", "cname", "ttl"}) }F= /reverse/ && do { sprintf '^%d.%d.%d.%d.in-addr.arpa:%s.%s:%d', ($options{'ip'} =~ /\d+/g)[3, 2, 1, 0], @options{'host', 'zone', 'ttl'} }
ABCDEFresult
11XXXX1
0X1XXX1
101XXX1
0X01XX1
1001XX1
0X001X1
10001X1
0X00011
1000011
0X00000
1000000
422 0 /\d+/g)[3,2,1,0],@options{'host','zone','ttl'}) } or
423 carp "What type is ($_) ?";
424 }
425 0 ▶ return 0 unless $string;
Branch: 1 branch
BranchTrueFalseTotal
unless $string 0 0 0
426 0 syswrite(FILE,"$string\n");
427 0 ▶ close(FILE)
Branch: 1 branch
BranchTrueFalseTotal
close FILE or carp("Error: Cant close file") 0 0 0
428 or carp "Error: Cant close file";
429 }
430  
431 sub del
432 0 ▶{
Subroutine del: not called CC=30 SCAR=68.4
Pod documented
433 0 my ($self,%options) = @_;
434 0 my $file = $self->{dir} . "/root/data";
435 0 local (*FILE,*FILENEW);
436  
437 0 ▶ unless($self->{dir} and -f $file)
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"dir"} and -f $file) 0 0 0
Condition0%0/3
$self->{"dir"} and -f $file
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"dir"} and -f $file
$self->{"dir"} -f $file
Truth table0%0/3
A and B
A= $self->{"dir"}B= -f $file
ABresult
0X0
100
111
438 {
439 0 carp "ERROR: dnscache directory not set";
440 0 return 0;
441 }
442  
443 0 ▶ unless(exists $types{ $options{type} } and $options{zone})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $types{$options{"type"}} and $options{"zone"}) 0 0 0
Condition0%0/3
exists $types{$options{"type"}} and $options{"zone"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $types{$options{"type"}} and $options{"zone"}
exists $types{$options{"type"}} $options{"zone"}
Truth table0%0/3
A and B
A= exists $types{$options{"type"}}B= $options{"zone"}
ABresult
0X0
100
111
444 {
445 0 carp "ERROR: not enougth arguments.";
446 0 return 0;
447 }
448  
449 0 ▶ open(FILENEW,">$file.new")
Branch: 1 branch
BranchTrueFalseTotal
open FILENEW, ">$file.new" or carp("ERROR: Cant write to $file.new") 0 0 0
450 or carp "ERROR: Cant write to $file.new";
451 0 ▶ flock(FILENEW,LOCK_EX)
Branch: 1 branch
BranchTrueFalseTotal
flock FILENEW, 2 or carp("Cant lock $file.new") 0 0 0
452 or carp "Cant lock $file.new";
453  
454 0 ▶ open(FILE,"<$file")
Branch: 1 branch
BranchTrueFalseTotal
open FILE, "<$file" or carp("ERROR: Cant read from $file.new") 0 0 0
455 or carp "ERROR: Cant read from $file.new";
456 0 ▶ flock(FILE,LOCK_EX)
Branch: 1 branch
BranchTrueFalseTotal
flock FILE, 2 or carp("Cant lock $file") 0 0 0
457 or carp "Cant lock $file";
458  
459 0 ▶ seek(FILE,0,0)
Branch: 1 branch
BranchTrueFalseTotal
seek FILE, 0, 0 or carp("ERROR: Cant seek $file") 0 0 0
460 or carp "ERROR: Cant seek $file";
461 0 ▶ seek(FILENEW,0,0)
Branch: 1 branch
BranchTrueFalseTotal
seek FILENEW, 0, 0 or carp("ERROR: Cant seek $file.new") 0 0 0
462 or carp "ERROR: Cant seek $file.new";
463  
464 0 my $entry;
465 0 for($options{type})
466 {
467 0 ▶ $entry = /host/ && do { "^[=+]\Q$options{host}.$options{zone}\E" .
Condition0%0/3
/alias/ and do { qq[^C\Q$options{"host"}.$options{"zone"}\E] . quotemeta(':' . $options{"cname"}) }
!ll&&!rl&&r
000
MC/DC0%0/2
/alias/ and do { qq[^C\Q$options{"host"}.$options{"zone"}\E] . quotemeta(':' . $options{"cname"}) }
/alias/ do { qq[^C\Q$options{"host"}.$options{"zone"}\E] . quotemeta(':' . $options{"cname"}) }
Truth table0%0/3
A and B
A= /alias/B= do { qq[^C\Q$options{"host"}.$options{"zone"}\E] . quotemeta(':' . $options{"cname"}) }
ABresult
0X0
100
111
468 "\Q:$options{ip}$options{cname}\E" } ||
469 0 ▶ /alias/ && do { "^C\Q$options{host}.$options{zone}\E" .
Condition0%0/3
/mx/ and do { qq[^\@\Q$options{"zone"}:$options{"ip"}\E] . qq[:\Q$options{"host"}:$options{"pref"}\E] }
!ll&&!rl&&r
000
MC/DC0%0/2
/mx/ and do { qq[^\@\Q$options{"zone"}:$options{"ip"}\E] . qq[:\Q$options{"host"}:$options{"pref"}\E] }
/mx/ do { qq[^\@\Q$options{"zone"}:$options{"ip"}\E] . qq[:\Q$options{"host"}:$options{"pref"}\E] }
Truth table0%0/3
A and B
A= /mx/B= do { qq[^\@\Q$options{"zone"}:$options{"ip"}\E] . qq[:\Q$options{"host"}:$options{"pref"}\E] }
ABresult
0X0
100
111
470 "\Q:$options{cname}\E" } ||
471 0 ▶ /mx/ && do { "^\@\Q$options{zone}:$options{ip}\E" .
Condition0%0/3
/ns/ and do { qq[^[.&]\Q$options{"zone"}:$options{"ip"}\E] . qq[:\Q$options{"host"}\E:] }
!ll&&!rl&&r
000
MC/DC0%0/2
/ns/ and do { qq[^[.&]\Q$options{"zone"}:$options{"ip"}\E] . qq[:\Q$options{"host"}\E:] }
/ns/ do { qq[^[.&]\Q$options{"zone"}:$options{"ip"}\E] . qq[:\Q$options{"host"}\E:] }
Truth table0%0/3
A and B
A= /ns/B= do { qq[^[.&]\Q$options{"zone"}:$options{"ip"}\E] . qq[:\Q$options{"host"}\E:] }
ABresult
0X0
100
111
472 ":\Q$options{host}:$options{pref}\E" } ||
473 0 ▶ /ns/ && do { "^[.&]\Q$options{zone}:$options{ip}\E" .
Condition0%0/3
/reverse/ and do { sprintf "^\\^%d.%d.%d.%d.in-addr.arpa:", ($options{"ip"} =~ /\d+/g)[3, 2, 1, 0] }
!ll&&!rl&&r
000
MC/DC0%0/2
/reverse/ and do { sprintf "^\\^%d.%d.%d.%d.in-addr.arpa:", ($options{"ip"} =~ /\d+/g)[3, 2, 1, 0] }
/reverse/ do { sprintf "^\\^%d.%d.%d.%d.in-addr.arpa:", ($options{"ip"} =~ /\d+/g)[3, 2, 1, 0] }
Truth table0%0/3
A and B
A= /reverse/B= do { sprintf "^\\^%d.%d.%d.%d.in-addr.arpa:", ($options{"ip"} =~ /\d+/g)[3, 2, 1, 0] }
ABresult
0X0
100
111
474 ":\Q$options{host}\E:" } ||
475 0 ▶ /reverse/&&do { sprintf("^\\^%d.%d.%d.%d.in-addr.arpa:",
Branch: 1 branch
BranchTrueFalseTotal
$entry = /host/ && do { qq[^[=+]\Q$options{"host"}.$options{"zone"}\E] . quotemeta(':' . $options{"ip"} . $options{"cname"}) } || /alias/ && do { qq[^C\Q$options{"host"}.$options{"zone"}\E] . quotemeta(':' . $options{"cname"}) } || /mx/ && do { qq[^\@\Q$options{"zone"}:$options{"ip"}\E] . qq[:\Q$options{"host"}:$options{"pref"}\E] } || /ns/ && do { qq[^[.&]\Q$options{"zone"}:$options{"ip"}\E] . qq[:\Q$options{"host"}\E:] } || /reverse/ && do { sprintf "^\\^%d.%d.%d.%d.in-addr.arpa:", ($options{"ip"} =~ /\d+/g)[3, 2, 1, 0] } or warn "Unknown option ($_)" 0 0 0
Condition0%0/15
/host/ && do { "^[=+]\Q$options{'host'}.$options{'zone'}\E" . quotemeta(':' . $options{'ip'} . $options{'cname'}) } || /alias/ && do { "^C\Q$options{'host'}.$options{'zone'}\E" . quotemeta(':' . $options{'cname'}) } || /mx/ && do { "^\@\Q$options{'zone'}:$options{'ip'}\E" . ":\Q$options{'host'}:$options{'pref'}\E" } || /ns/ && do { "^[.&]\Q$options{'zone'}:$options{'ip'}\E" . ":\Q$options{'host'}\E:" } || /reverse/ && do { sprintf '^\\^%d.%d.%d.%d.in-addr.arpa:', ($options{'ip'} =~ /\d+/g)[3, 2, 1, 0] }
l!l&&r!l&&!r
000
/host/ and do { qq[^[=+]\Q$options{"host"}.$options{"zone"}\E] . quotemeta(':' . $options{"ip"} . $options{"cname"}) } or /alias/ and do { qq[^C\Q$options{"host"}.$options{"zone"}\E] . quotemeta(':' . $options{"cname"}) } or /mx/ and do { qq[^\@\Q$options{"zone"}:$options{"ip"}\E] . qq[:\Q$options{"host"}:$options{"pref"}\E] } or /ns/ and do { qq[^[.&]\Q$options{"zone"}:$options{"ip"}\E] . qq[:\Q$options{"host"}\E:] }
l!l&&r!l&&!r
000
/host/ and do { qq[^[=+]\Q$options{"host"}.$options{"zone"}\E] . quotemeta(':' . $options{"ip"} . $options{"cname"}) } or /alias/ and do { qq[^C\Q$options{"host"}.$options{"zone"}\E] . quotemeta(':' . $options{"cname"}) } or /mx/ and do { qq[^\@\Q$options{"zone"}:$options{"ip"}\E] . qq[:\Q$options{"host"}:$options{"pref"}\E] }
l!l&&r!l&&!r
000
/host/ and do { qq[^[=+]\Q$options{"host"}.$options{"zone"}\E] . quotemeta(':' . $options{"ip"} . $options{"cname"}) } or /alias/ and do { qq[^C\Q$options{"host"}.$options{"zone"}\E] . quotemeta(':' . $options{"cname"}) }
l!l&&r!l&&!r
000
/host/ and do { qq[^[=+]\Q$options{"host"}.$options{"zone"}\E] . quotemeta(':' . $options{"ip"} . $options{"cname"}) }
!ll&&!rl&&r
000
MC/DC0%0/6
/host/ && do { "^[=+]\Q$options{'host'}.$options{'zone'}\E" . quotemeta(':' . $options{'ip'} . $options{'cname'}) } || /alias/ && do { "^C\Q$options{'host'}.$options{'zone'}\E" . quotemeta(':' . $options{'cname'}) } || /mx/ && do { "^\@\Q$options{'zone'}:$options{'ip'}\E" . ":\Q$options{'host'}:$options{'pref'}\E" } || /ns/ && do { "^[.&]\Q$options{'zone'}:$options{'ip'}\E" . ":\Q$options{'host'}\E:" } || /reverse/ && do { sprintf '^\\^%d.%d.%d.%d.in-addr.arpa:', ($options{'ip'} =~ /\d+/g)[3, 2, 1, 0] }
/host/ do { qq[^[=+]\Q$options{"host"}.$options{"zone"}\E] . quotemeta(':' . $options{"ip"} . $options{"cname"}) } /alias/ and do { qq[^C\Q$options{"host"}.$options{"zone"}\E] . quotemeta(':' . $options{"cname"}) } /mx/ and do { qq[^\@\Q$options{"zone"}:$options{"ip"}\E] . qq[:\Q$options{"host"}:$options{"pref"}\E] } /ns/ and do { qq[^[.&]\Q$options{"zone"}:$options{"ip"}\E] . qq[:\Q$options{"host"}\E:] } /reverse/ && do { sprintf '^\\^%d.%d.%d.%d.in-addr.arpa:', ($options{'ip'} =~ /\d+/g)[3, 2, 1, 0] }
Truth table0%0/11
A and B or C or D or E || F
A= /host/B= do { qq[^[=+]\Q$options{"host"}.$options{"zone"}\E] . quotemeta(':' . $options{"ip"} . $options{"cname"}) }C= /alias/ and do { qq[^C\Q$options{"host"}.$options{"zone"}\E] . quotemeta(':' . $options{"cname"}) }D= /mx/ and do { qq[^\@\Q$options{"zone"}:$options{"ip"}\E] . qq[:\Q$options{"host"}:$options{"pref"}\E] }E= /ns/ and do { qq[^[.&]\Q$options{"zone"}:$options{"ip"}\E] . qq[:\Q$options{"host"}\E:] }F= /reverse/ && do { sprintf '^\\^%d.%d.%d.%d.in-addr.arpa:', ($options{'ip'} =~ /\d+/g)[3, 2, 1, 0] }
ABCDEFresult
11XXXX1
0X1XXX1
101XXX1
0X01XX1
1001XX1
0X001X1
10001X1
0X00011
1000011
0X00000
1000000
476 0 ($options{ip} =~/\d+/g)[3,2,1,0]) } or
477 warn "Unknown option ($_)";
478 }
479 0 ▶ return 0 unless $entry;
Branch: 1 branch
BranchTrueFalseTotal
unless $entry 0 0 0
480 0 $entry = qr/$entry/;
481  
482 0 ▶ while(my $entrada=<FILE>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $entrada = readline FILE)) 0 0 0
483 {
484 0 ▶ next if $entrada=~/$entry/;
Branch: 1 branch
BranchTrueFalseTotal
if $entrada =~ /$entry/ 0 0 0
485 0 ▶ syswrite(FILENEW,$entrada)
Branch: 1 branch
BranchTrueFalseTotal
syswrite FILENEW, $entrada or carp("Cant write to file") 0 0 0
486 or carp "Cant write to file";
487 }
488  
489 0 ▶ close(FILENEW)
Branch: 1 branch
BranchTrueFalseTotal
close FILENEW or carp("ERROR: Cant close $file.new") 0 0 0
490 or carp "ERROR: Cant close $file.new";
491 0 ▶ close(FILE)
Branch: 1 branch
BranchTrueFalseTotal
close FILE or carp("ERROR: Cant close $file") 0 0 0
492 or carp "ERROR: Cant close $file";
493 0 ▶ unlink($file)
Branch: 1 branch
BranchTrueFalseTotal
unlink $file or carp("ERROR: Cant unlink $file") 0 0 0
494 or carp "ERROR: Cant unlink $file";
495 0 ▶ rename("$file.new",$file)
Branch: 1 branch
BranchTrueFalseTotal
rename "$file.new", $file or carp("ERROR: Cant rename $file.new to $file") 0 0 0
496 or carp "ERROR: Cant rename $file.new to $file";
497 0 return $trobat;
498 }
499  
500 ### PRIVATE SUBS
501 sub _parse_ns
502 0 ▶{
Subroutine _parse_ns: not called CC=1 SCAR=6.9
503 0 my @data=split/:/,substr($_[0],1);
504 0 return { zone => $data[0],
505 ip => $data[1],
506 type => 'ns',
507 host => $data[2],
508 ttl => $data[3] };
509 }
510  
511 sub _parse_mx
512 0 ▶{
Subroutine _parse_mx: not called CC=1 SCAR=6.9
513 0 my @data=split/:/,substr($_[0],1);
514 0 return { zone => $data[0],
515 ip => $data[1],
516 type => 'mx',
517 host => $data[2],
518 ttl => $data[4],
519 pref => $data[3] };
520 }
521  
522 sub _parse_host
523 0 ▶{
Subroutine _parse_host: not called CC=1 SCAR=6.9
524 0 my @data=split/:/,substr($_[0],1);
525 0 my ($host,$zone) = split/\./,$data[0],2;
526 0 return { zone => $zone,
527 host => $host,
528 type => 'host',
529 ip => $data[1],
530 ttl => $data[2] };
531 }
532  
533 sub _parse_alias
534 0 ▶{
Subroutine _parse_alias: not called CC=1 SCAR=6.9
535 0 my @data=split/:/,substr($_[0],1);
536 0 my ($host,$zone) = split/\./,$data[0],2;
537 0 return { zone => $zone,
538 host => $host,
539 type => 'alias',
540 cname=> $data[1],
541 ttl => $data[2] };
542 }
543  
544 sub _parse_reverse
545 0 ▶{
Subroutine _parse_reverse: not called CC=1 SCAR=6.9
546 0 my @data=split/:/,substr($_[0],1);
547 0 my $ip = join ".", ($data[0]=~/\d+/g)[3,2,1,0];
548 0 my ($host,$zone) = split/\./,$data[1],2;
549 0 return { zone => $zone,
550 ip => $ip,
551 type => 'reverse',
552 host => $host,
553 ttl => $data[2] };
554 }
555  
556 sub _parse_all
557 0 ▶{
Subroutine _parse_all: not called CC=2 SCAR=17.9
558 0 my $tipus=substr($_[0],0,1);
559 0 my %types = ( '.' => \&_parse_ns,
560 '&' => \&_parse_ns,
561 '=' => \&_parse_host,
562 '+' => \&_parse_host,
563 'C' => \&_parse_alias,
564 '^' => \&_parse_reverse,
565 '@' => \&_parse_mx );
566 0 ▶ return exists $types{$tipus} ? $types{$tipus}->($_[0]) : 0
Branch: 1 branch
BranchTrueFalseTotal
exists $types{$tipus} ? : 0 0 0
567 }
568  
569 1 1;
↑ Summary blib/lib/DNS/TinyDNS/dnscache.pm »