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