| 1 | # Copyright (c) 2009-2014 David Caldwell, All Rights Reserved. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package Net::DNS::Create::Bind; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Net::DNS::Create qw(internal full_host local_host email interval); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use feature ':5.10'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use POSIX qw(strftime); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use File::Slurp qw(write_file); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | our %config = (conf_prefix=>'', default_ttl=>'1h', dest_dir=>'.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | sub import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | my $package = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | my %c = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | $config{$_} = $c{$_} for keys %c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | sub quote_txt(@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 7 | ▶ | local $_ = $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
quote_txt: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 7 | s/[^[:print:]]/sprintf("\\%03o",ord($&))/ge; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 7 | s/["]/\\"/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 7 | "\"$_\"" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | sub txt(@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 6 | ▶ | return quote_txt(@_) if scalar @_ == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
txt: called CC=2 SCAR=6.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | '('.join("\n" . " " x 41, map { quote_txt($_) } @_).')'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | our @zone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | sub domain { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | my ($package, $domain, $entries) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
domain: called CC=11 SCAR=24.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | my $conf = '$TTL '.interval($config{default_ttl})."\n". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | join '', map { ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 27 | my $rr = lc $_->type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 27 | ▶ | my $ttl = $_->ttl != interval($config{default_ttl}) ? $_->ttl : ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 27 | my $prefix = sprintf "%-30s %7s in %-5s", local_host($_->name, $domain), $ttl, $rr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 27 | ▶ | $rr eq 'mx' ? "$prefix ".$_->preference." ".local_host($_->exchange, $domain)."\n" : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 8 branches
Condition33%1/3
$_->serial || strftime('%g%m%d%H%M', localtime)
MC/DC0%0/2
$_->serial || strftime('%g%m%d%H%M', localtime)
$_->serial
strftime('%g%m%d%H%M', localtime)
Truth table33%1/3
A || B
A= $_->serialB= strftime('%g%m%d%H%M', localtime)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | $rr eq 'ns' ? "$prefix ".local_host($_->nsdname, $domain)."\n" : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | $rr eq 'txt' ? "$prefix ".txt($_->char_str_list)."\n" : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | $rr eq 'srv' ? "$prefix ".join(' ', $_->priority, $_->weight, $_->port, local_host($_->target, $domain))."\n" : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | $rr eq 'rp' ? "$prefix ".local_host(email($_->mbox), $domain)." ".local_host($_->txtdname, $domain)."\n" : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | $rr eq 'soa' ? "$prefix ".join(' ', local_host($_->mname, $domain), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | local_host(email($_->rname), $domain), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | '(', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | $_->serial || strftime('%g%m%d%H%M', localtime), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | $_->refresh, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | $_->retry, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | $_->expire, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | $_->minimum, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | ')')."\n" : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | $rr eq 'a' ? "$prefix ".$_->address."\n" : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | $rr eq 'cname' ? "$prefix ".local_host($_->cname, $domain)."\n" : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | die __PACKAGE__." doesn't handle $rr record types"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } @$entries; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 1 | my $conf_name = "$config{dest_dir}/$config{conf_prefix}$domain.zone"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | $conf_name =~ s/\.\././g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | push @zone, { conf => $conf_name, domain => $domain }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | write_file($conf_name, $conf); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | sub master { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | ▶ | my ($package, $filename, $prefix, @extra) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
master: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | ▶ | $prefix //= ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$prefix //= ""
MC/DC0%0/1
$prefix //= ""
$prefix
Truth table50%1/2
A
A= $prefix
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | my $master_file_name = "$config{dest_dir}/$config{conf_prefix}$filename"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | write_file($master_file_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | @extra, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | map { <<EOZ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | zone "$_->{domain}" { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | type master; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | file "$prefix$_->{conf}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | EOZ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | } @zone); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | system("named-checkconf", "-z", $master_file_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | sub domain_list($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | print "$config{conf_prefix}$_[0].zone\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
domain_list: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | sub master_list($$) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | print "$config{conf_prefix}$_[0]\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
master_list: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||