|
1 #!/usr/bin/perl |
|
2 |
|
3 use strict; |
|
4 use FindBin; |
|
5 |
|
6 # liest die Konfiguration ein |
|
7 my @configs = ( "$FindBin::Bin/dnstools.conf", "/etc/dnstools.conf" ); |
|
8 my @dnssec_signs |
|
9 = ( "$FindBin::Bin/dnssec-sign", "/usr/bin/dnstools/dnssec-sign" ); |
|
10 my %config; |
|
11 my $dnssec_sign; |
|
12 |
|
13 for ( grep {-f} @configs ) { |
|
14 open( CONFIG, $_ ) or die "Can't open $_: $!\n"; |
|
15 } |
|
16 unless ( seek( CONFIG, 0, 0 ) ) { |
|
17 die "Can't open config (searched: @configs)\n"; |
|
18 } |
|
19 |
|
20 for ( grep {-f} @dnssec_signs ) { |
|
21 if ( -x $_ ) { |
|
22 $dnssec_sign = $_; |
|
23 } |
|
24 else { |
|
25 die "Can't run $_\n"; |
|
26 } |
|
27 } |
|
28 |
|
29 while (<CONFIG>) { |
|
30 chomp; |
|
31 s/#.*//; |
|
32 s/\t//g; |
|
33 s/\s//g; |
|
34 next unless length; |
|
35 my ( $cname, $ccont ) = split( /\s*=\s*/, $_, 2 ); |
|
36 $config{$cname} = $ccont; |
|
37 } |
|
38 close(CONFIG); |
|
39 |
|
40 my $bind_dir = $config{bind_dir}; |
|
41 my $conf_dir = $config{zone_conf_dir}; |
|
42 my $master_dir = $config{master_dir}; |
|
43 |
|
44 unless ( -d $master_dir and -r $master_dir ) { |
|
45 die "$master_dir: $!\n"; |
|
46 } |
|
47 |
|
48 unless ( -d $bind_dir and -r $bind_dir ) { |
|
49 die "$bind_dir: $!\n"; |
|
50 } |
|
51 |
|
52 # dnssec - new sign |
|
53 system "$dnssec_sign"; |
|
54 die "$dnssec_sign not found ($!)" if $? == -1; |
|
55 exit 1 if $?; |
|
56 |
|
57 |
|
58 # prueft jede domain, die ein verzeichnis in $master_dir hat, ob es eine |
|
59 # datei $zone_file.signed gibt und ob diese datei in $config_file eingetragen |
|
60 # ist. |
|
61 # passt die eintraege in $config_file falls noetig an. |
|
62 while (<$master_dir/*>) { |
|
63 s#($master_dir/)(.*)#$2#; |
|
64 my $zone = $_; |
|
65 |
|
66 my $zone_file = "$master_dir/$zone/$zone"; |
|
67 my $conf_file = "$conf_dir/$zone"; |
|
68 my @c_content; |
|
69 |
|
70 unless ( -f "$conf_file" ) { |
|
71 die "$conf_file: $! \n"; |
|
72 } |
|
73 |
|
74 if ( -f "$zone_file.signed" ) { |
|
75 |
|
76 open( FILE, "<$conf_file" ) or die "$conf_file: $!\n"; |
|
77 @c_content = <FILE>; |
|
78 close(FILE); |
|
79 |
|
80 for (@c_content) { |
|
81 if (m{(.*)($zone_file)(";)}) { |
|
82 print "$2 ==> $2.signed\n"; |
|
83 $_ = "$1$2.signed$3\n"; |
|
84 } |
|
85 |
|
86 open( FILE, ">$conf_file" ) or die "$conf_file: $!\n"; |
|
87 print FILE @c_content; |
|
88 close(FILE); |
|
89 |
|
90 } |
|
91 } |
|
92 else { |
|
93 |
|
94 open( FILE, "<$conf_file" ) or die "$conf_file: $!\n"; |
|
95 @c_content = <FILE>; |
|
96 close(FILE); |
|
97 |
|
98 for (@c_content) { |
|
99 if (m{(.*)($zone_file)\.signed(.*)}) { |
|
100 print "$2.signed ==> $2\n"; |
|
101 $_ = "$1$2$3\n"; |
|
102 } |
|
103 } |
|
104 |
|
105 open( FILE, ">$conf_file" ) or die "$conf_file: $!\n"; |
|
106 print FILE @c_content; |
|
107 close(FILE); |
|
108 } |
|
109 } |
|
110 |
|
111 # erzeugt eine named.conf-datei aus den entsprechenden vorlagen. |
|
112 open( TO, ">$bind_dir/named.conf.zones" ) |
|
113 or die "$bind_dir/named.conf.zones: $!\n"; |
|
114 while (<$conf_dir/*>) { |
|
115 open( FROM, "$_" ) or die "$_: $! \n"; |
|
116 print TO <FROM>; |
|
117 close(FROM); |
|
118 } |
|
119 close(TO); |
|
120 |
|
121 |
|
122 system "named-checkconf"; |
|
123 system "named-checkconf -z"; |
|
124 system "rndc reload"; |