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