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
|
|
7
|
use Net::DNS::Create qw(internal full_host local_host email interval); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
5
|
1
|
|
|
1
|
|
24
|
use feature ':5.10'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
129
|
|
6
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
32
|
|
7
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
46
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
1010
|
use POSIX qw(strftime); |
|
1
|
|
|
|
|
8376
|
|
|
1
|
|
|
|
|
17
|
|
10
|
1
|
|
|
1
|
|
2802
|
use File::Slurp qw(write_file); |
|
1
|
|
|
|
|
5173
|
|
|
1
|
|
|
|
|
1331
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our %config = (conf_prefix=>'', default_ttl=>'1h', dest_dir=>'.'); |
13
|
|
|
|
|
|
|
sub import { |
14
|
1
|
|
|
1
|
|
4
|
my $package = shift; |
15
|
1
|
|
|
|
|
5
|
my %c = @_; |
16
|
1
|
|
|
|
|
48
|
$config{$_} = $c{$_} for keys %c; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub quote_txt(@) { |
20
|
7
|
|
|
7
|
0
|
11
|
local $_ = $_[0]; |
21
|
7
|
|
|
|
|
17
|
s/[^[:print:]]/sprintf("\\%03o",ord($&))/ge; |
|
3
|
|
|
|
|
11
|
|
22
|
7
|
|
|
|
|
18
|
s/["]/\\"/g; |
23
|
7
|
|
|
|
|
32
|
"\"$_\"" |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub txt(@) { |
27
|
6
|
100
|
|
6
|
0
|
244
|
return quote_txt(@_) if scalar @_ == 1; |
28
|
1
|
|
|
|
|
4
|
'('.join("\n" . " " x 41, map { quote_txt($_) } @_).')'; |
|
2
|
|
|
|
|
5
|
|
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
our @zone; |
32
|
|
|
|
|
|
|
sub domain { |
33
|
1
|
|
|
1
|
0
|
3
|
my ($package, $domain, $entries) = @_; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $conf = '$TTL '.interval($config{default_ttl})."\n". |
36
|
1
|
|
|
|
|
7
|
join '', map { ; |
37
|
27
|
|
|
|
|
339
|
my $rr = lc $_->type; |
38
|
27
|
50
|
|
|
|
345
|
my $ttl = $_->ttl != interval($config{default_ttl}) ? $_->ttl : ""; |
39
|
27
|
|
|
|
|
148
|
my $prefix = sprintf "%-30s %7s in %-5s", local_host($_->name, $domain), $ttl, $rr; |
40
|
|
|
|
|
|
|
|
41
|
27
|
50
|
33
|
|
|
301
|
$rr eq 'mx' ? "$prefix ".$_->preference." ".local_host($_->exchange, $domain)."\n" : |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
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
|
|
|
|
|
8
|
my $conf_name = "$config{dest_dir}/$config{conf_prefix}$domain.zone"; |
61
|
1
|
|
|
|
|
5
|
$conf_name =~ s/\.\././g; |
62
|
1
|
|
|
|
|
5
|
push @zone, { conf => $conf_name, domain => $domain }; |
63
|
1
|
|
|
|
|
8
|
write_file($conf_name, $conf); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub master { |
67
|
1
|
|
|
1
|
0
|
4
|
my ($package, $filename, $prefix, @extra) = @_; |
68
|
1
|
|
50
|
|
|
9
|
$prefix //= ''; |
69
|
1
|
|
|
|
|
4
|
my $master_file_name = "$config{dest_dir}/$config{conf_prefix}$filename"; |
70
|
1
|
|
|
|
|
7
|
write_file($master_file_name, |
71
|
|
|
|
|
|
|
@extra, |
72
|
1
|
|
|
|
|
4
|
map { <
|
73
|
|
|
|
|
|
|
zone "$_->{domain}" { |
74
|
|
|
|
|
|
|
type master; |
75
|
|
|
|
|
|
|
file "$prefix$_->{conf}"; |
76
|
|
|
|
|
|
|
}; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
EOZ |
79
|
|
|
|
|
|
|
} @zone); |
80
|
1
|
|
|
|
|
5354
|
system("named-checkconf", "-z", $master_file_name); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub domain_list($@) { |
84
|
0
|
|
|
0
|
0
|
|
print "$config{conf_prefix}$_[0].zone\n"; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub master_list($$) { |
88
|
0
|
|
|
0
|
0
|
|
print "$config{conf_prefix}$_[0]\n" |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
92
|
|
|
|
|
|
|
__END__ |