zone-mk
changeset 25 c02caf4e0eb6
parent 22 7229d1c95ea8
child 27 d5337081ed02
equal deleted inserted replaced
24:b1234b9824f0 25:c02caf4e0eb6
     1 #!/usr/bin/perl -w
     1 #!/usr/bin/perl -w
     2 
     2 
     3 use strict;
     3 use strict;
       
     4 use FindBin;
     4 
     5 
     5 if (@ARGV < 2) {
     6 if (@ARGV < 2) {
     6 	print "usage: zone-mk kundennummer domain ... \n";
     7 	print "usage: zone-mk kundennummer domain ... \n";
     7 	exit 1;
     8 	exit 1;
     8 }
     9 }
     9 
    10 
       
    11 # oeffnet Konfigurations- und Templatefiles - relativ oder absolut
       
    12 my @configs = ("$FindBin::Bin/dnstools.conf", "/etc/dnstools.conf");
       
    13 my @templc = ("$FindBin::Bin/templates/named.config","/etc/dnstools/templates/named.config");
       
    14 my @templz = ("$FindBin::Bin/templates/named.zone","/etc/dnstools/templates/named.zone");
    10 my %config;
    15 my %config;
    11 open (CONFIG, "dnstools.conf");
    16 
       
    17 for (grep {-f} @configs) {
       
    18         open(CONFIG, $_) or die "Can't open $_: $!\n";
       
    19 }
       
    20 unless (seek(CONFIG,0 ,0 )) {
       
    21         die "Can't open config (searched: @configs)\n";
       
    22 }
       
    23 
       
    24 for (grep {-f} @templc) {
       
    25 	open(TEMPCONF, $_) or die "Can't open $_: $!\n";
       
    26 }
       
    27 unless (seek(TEMPCONF,0 ,0 )) {
       
    28         die "Can't open config (searched: @templc)\n";
       
    29 }
       
    30 
       
    31 for (grep {-f} @templz) {
       
    32 	open(TEMPZONE, $_) or die "Can't open $_: $!\n";
       
    33 }
       
    34 unless (seek(TEMPZONE,0 ,0 )) {
       
    35         die "Can't open config (searched: @templz)\n";
       
    36 }
       
    37 
    12 while (<CONFIG>) {
    38 while (<CONFIG>) {
    13         chomp;
    39         chomp;
    14         s/#.*//;
    40         s/#.*//;
    15         s/\t//g;
    41         s/\t//g;
    16         s/\s//g;
    42         s/\s//g;
    17 
       
    18         next unless length;
    43         next unless length;
    19         my ($cname, $ccont) = split (/\s*=\s*/, $_,2);
    44         my ($cname, $ccont) = split (/\s*=\s*/, $_,2);
    20         $config{$cname} = $ccont;
    45         $config{$cname} = $ccont;
    21 }
    46 }
    22 close (CONFIG);
    47 close (CONFIG);
    34 chomp (my $this_domain = `hostname -d`);
    59 chomp (my $this_domain = `hostname -d`);
    35 chomp (my $time = `date +%Y%m%d00`);
    60 chomp (my $time = `date +%Y%m%d00`);
    36 chomp (my $start= `date -I`);
    61 chomp (my $start= `date -I`);
    37 my $hostmaster = "hostmaster.$this_domain";
    62 my $hostmaster = "hostmaster.$this_domain";
    38 
    63 
    39 unless (-e $master_dir) {
    64 unless (-d $master_dir and -r $master_dir) {
    40 	print "$master_dir nicht vorhanden \n";
    65         die "$master_dir: $!\n";
    41 	exit 1;
       
    42 }
    66 }
    43 unless (-e $zone_conf_dir) {
    67 
    44 	print "$zone_conf_dir nicht vorhanden \n";
    68 unless (-d $zone_conf_dir and -r $zone_conf_dir) {
    45 	exit 1;
    69 	die "$master_dir: $!\n";
    46 }
    70 }
    47 
    71 
    48 
    72 
    49 # legt fuer jede domain in @ARGV ein verzeichnis in $master_dir an.
    73 # legt fuer jede domain in @ARGV ein verzeichnis in $master_dir an.
    50 # schreibt aus den angegebenen templates die dateien $zonefile und $config
    74 # schreibt aus den angegebenen templates die dateien $zonefile und $config
    51 # in die entsprechenden verzeichnisse.
    75 # in die entsprechenden verzeichnisse.
    52 
       
    53 for (@ARGV) {
    76 for (@ARGV) {
    54 
    77 
    55 	chomp (my $domain = `idn --quiet "$_"`);
    78 	chomp (my $domain = `idn --quiet "$_"`);
    56 	my $zonefile = "$master_dir/$domain/$domain";
    79 	my $zonefile = "$master_dir/$domain/$domain";
    57 	my $config = "$zone_conf_dir/$domain";
    80 	my $config = "$zone_conf_dir/$domain";
    58 	my $utf8domain = "$_";
    81 	my $utf8domain = "$_";
    59 
    82 
    60 	unless ( -e "$master_dir/$domain") {
    83 	unless ( -d "$master_dir/$domain") {
    61 		`mkdir $master_dir/$domain`;
    84 		`mkdir $master_dir/$domain`;
    62 	}
    85 	}
    63 
    86 
    64 	if (-e $zonefile) {
    87 	if (-f $zonefile) {
    65 		$zonefile =~ s#/.*/##;
    88 		$zonefile =~ s#/.*/##;
    66 		print "$zonefile exists. Skipping $domain\n";
    89 		print "$zonefile exists. Skipping $domain\n";
    67 		next;
    90 		next;
    68 	}
    91 	}
    69 	if (-e $config) {
    92 	if (-f $config) {
    70 		$config =~ s#/.*/##;
    93 		$config =~ s#/.*/##;
    71 		print "$config exists. Skipping $domain\n";
    94 		print "$config exists. Skipping $domain\n";
    72 		next;
    95 		next;
    73 	}
    96 	}
    74 
    97 
    75 	print "$domain ($_) for $customer \n";
    98 	print "$domain ($_) for $customer \n";
    76 
    99 
    77 	open (TEMPZONE, "templates/named.zone");
       
    78 	my @tempzone = <TEMPZONE>;
   100 	my @tempzone = <TEMPZONE>;
    79 	close (TEMPZONE);
       
    80 
       
    81 	for (@tempzone) {
   101 	for (@tempzone) {
    82 		s#<start>#$start#;
   102 		s#<start>#$start#;
    83 		s#<domain>#$domain#;
   103 		s#<domain>#$domain#;
    84 		s#<time>#$time#;
   104 		s#<time>#$time#;
    85 		s#<primary>#$primary#;
   105 		s#<primary>#$primary#;
    91 
   111 
    92 	open (ZONEOUT, ">$zonefile");
   112 	open (ZONEOUT, ">$zonefile");
    93 	print ZONEOUT @tempzone;
   113 	print ZONEOUT @tempzone;
    94 	close (ZONEOUT);
   114 	close (ZONEOUT);
    95 
   115 
    96 	open (TEMPCONF, "templates/named.config");
       
    97 	my @tempconf = <TEMPCONF>;
   116 	my @tempconf = <TEMPCONF>;
    98 	close (TEMPCONF);
       
    99 
       
   100 	for (@tempconf) {
   117 	for (@tempconf) {
   101 		s#<domain>#$domain#;
   118 		s#<domain>#$domain#;
   102 		s#<start>#$start#;
   119 		s#<start>#$start#;
   103 		s#<customer>#$customer#;
   120 		s#<customer>#$customer#;
   104 		s#<utf8domain>#$utf8domain#;
   121 		s#<utf8domain>#$utf8domain#;