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