zone-mk
changeset 22 7229d1c95ea8
parent 19 2c3bcb280768
child 25 c02caf4e0eb6
equal deleted inserted replaced
21:6715f8f9d04c 22:7229d1c95ea8
     1 #!/usr/bin/perl -w
     1 #!/usr/bin/perl -w
     2 
     2 
     3 use strict;
     3 use strict;
     4 
       
     5 
     4 
     6 if (@ARGV < 2) {
     5 if (@ARGV < 2) {
     7 	print "usage: zone-mk kundennummer domain ... \n";
     6 	print "usage: zone-mk kundennummer domain ... \n";
     8 	exit 1;
     7 	exit 1;
     9 }
     8 }
    10 
     9 
    11 my $primary = "pu.schlittermann.de";
    10 my %config;
    12 my $secondary= "hh.schlittermann.de";
    11 open (CONFIG, "dnstools.conf");
    13 my $zone_conf_dir= "/etc/bind/zones.d";
    12 while (<CONFIG>) {
    14 my $master_dir = "/etc/bind/master";
    13         chomp;
       
    14         s/#.*//;
       
    15         s/\t//g;
       
    16         s/\s//g;
       
    17 
       
    18         next unless length;
       
    19         my ($cname, $ccont) = split (/\s*=\s*/, $_,2);
       
    20         $config{$cname} = $ccont;
       
    21 }
       
    22 close (CONFIG);
       
    23 
       
    24 
       
    25 my $primary = $config{primary};
       
    26 my $secondary= $config{secondary};
       
    27 my $zone_conf_dir= $config{zone_conf_dir};
       
    28 my $master_dir = $config{master_dir};
    15 my $customer = shift @ARGV;
    29 my $customer = shift @ARGV;
    16 chomp (my $primary_ip = `dig +short $primary`);
    30 chomp (my $primary_ip = `dig +short $primary`);
    17 chomp (my $secondary_ip = `dig +short $secondary`);
    31 chomp (my $secondary_ip = `dig +short $secondary`);
    18 chomp (my $this_host= `hostname -f`);
    32 chomp (my $this_host= `hostname -f`);
    19 chomp (my $this_ip= `hostname -i`);
    33 chomp (my $this_ip= `hostname -i`);
    20 chomp (my $this_domain = `hostname -d`);
    34 chomp (my $this_domain = `hostname -d`);
    21 chomp (my $time = `date +%Y%m%d00`);
    35 chomp (my $time = `date +%Y%m%d00`);
    22 chomp (my $start= `date -I`);
    36 chomp (my $start= `date -I`);
    23 my $hostmaster = "hostmaster.$this_domain";
    37 my $hostmaster = "hostmaster.$this_domain";
    24 
    38 
    25 if (! -e $master_dir) {
    39 unless (-e $master_dir) {
    26 	print "$master_dir nicht vorhanden \n";
    40 	print "$master_dir nicht vorhanden \n";
    27 	exit 1;
    41 	exit 1;
    28 }
    42 }
    29 if (! -e $zone_conf_dir) {
    43 unless (-e $zone_conf_dir) {
    30 	print "$zone_conf_dir nicht vorhanden \n";
    44 	print "$zone_conf_dir nicht vorhanden \n";
    31 	exit 1;
    45 	exit 1;
    32 }
    46 }
    33 
    47 
    34 
    48 
    35 # legt fuer jede domain in @ARGV ein verzeichnis in $master_dir an.
    49 # legt fuer jede domain in @ARGV ein verzeichnis in $master_dir an.
    36 # schreibt aus den angegebenen templates die dateien $zonefile und $config
    50 # schreibt aus den angegebenen templates die dateien $zonefile und $config
    37 # in die entsprechenden verzeichnisse.
    51 # in die entsprechenden verzeichnisse.
    38 
    52 
    39 foreach (@ARGV) {
    53 for (@ARGV) {
    40 
    54 
    41 	chomp (my $domain = `idn --quiet "$_"`);
    55 	chomp (my $domain = `idn --quiet "$_"`);
    42 	my $zonefile = "$master_dir/$domain/$domain";
    56 	my $zonefile = "$master_dir/$domain/$domain";
    43 	my $config = "$zone_conf_dir/$domain";
    57 	my $config = "$zone_conf_dir/$domain";
    44 	my $utf8domain = "$_";
    58 	my $utf8domain = "$_";
    45 
    59 
    46 	if (! -e "$master_dir/$domain") {
    60 	unless ( -e "$master_dir/$domain") {
    47 		`mkdir $master_dir/$domain`;
    61 		`mkdir $master_dir/$domain`;
    48 	}
    62 	}
    49 
    63 
    50 	if (-e $zonefile) {
    64 	if (-e $zonefile) {
    51 		$zonefile =~ s#/.*/##;
    65 		$zonefile =~ s#/.*/##;
    62 
    76 
    63 	open (TEMPZONE, "templates/named.zone");
    77 	open (TEMPZONE, "templates/named.zone");
    64 	my @tempzone = <TEMPZONE>;
    78 	my @tempzone = <TEMPZONE>;
    65 	close (TEMPZONE);
    79 	close (TEMPZONE);
    66 
    80 
    67 	foreach (@tempzone) {
    81 	for (@tempzone) {
    68 		s#<start>#$start#;
    82 		s#<start>#$start#;
    69 		s#<domain>#$domain#;
    83 		s#<domain>#$domain#;
    70 		s#<time>#$time#;
    84 		s#<time>#$time#;
    71 		s#<primary>#$primary#;
    85 		s#<primary>#$primary#;
    72 		s#<secondary>#$secondary#;
    86 		s#<secondary>#$secondary#;
    81 
    95 
    82 	open (TEMPCONF, "templates/named.config");
    96 	open (TEMPCONF, "templates/named.config");
    83 	my @tempconf = <TEMPCONF>;
    97 	my @tempconf = <TEMPCONF>;
    84 	close (TEMPCONF);
    98 	close (TEMPCONF);
    85 
    99 
    86 	foreach (@tempconf) {
   100 	for (@tempconf) {
    87 		s#<domain>#$domain#;
   101 		s#<domain>#$domain#;
    88 		s#<start>#$start#;
   102 		s#<start>#$start#;
    89 		s#<customer>#$customer#;
   103 		s#<customer>#$customer#;
    90 		s#<utf8domain>#$utf8domain#;
   104 		s#<utf8domain>#$utf8domain#;
    91 		s#<file>#$master_dir/$domain/$domain#;
   105 		s#<file>#$master_dir/$domain/$domain#;