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