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