1 #! /bin/bash |
1 #!/usr/bin/perl -w |
2 |
2 |
3 while getopts "d" opt; do |
3 use strict; |
4 case $opt in |
|
5 d) opt_debug=1;; |
|
6 ?) exit 1;; |
|
7 esac |
|
8 done |
|
9 |
|
10 if test $# -lt 2; then |
|
11 echo "usage: $0 kundennummer domain..." >&2 |
|
12 exit |
|
13 fi |
|
14 |
|
15 customer="$1"; shift |
|
16 start=$(date -I) |
|
17 |
|
18 # config |
|
19 source dnstools.conf |
|
20 |
|
21 primary=$PRIMARY |
|
22 primary_ip=${PRIMARY_IP:-$(dig +short $primary)} |
|
23 |
|
24 secondary=$SECONDARY |
|
25 secondary_ip=${SECONDARY_IP:-$(dig +short $secondary)} |
|
26 |
|
27 this_host=${THIS_HOST:-$(hostname -f)} |
|
28 this_ip=${THIS_IP:-$(hostname -i)} |
|
29 this_domain=${THIS_DOMAIN:-$(hostname -d)} |
|
30 primary=${PRIMARY:-$this_host} |
|
31 |
|
32 hostmaster=${HOSTMASTER:-"hostmaster.$this_domain"} |
|
33 |
|
34 zone_conf_dir=${ZONE_CONF_DIR:-/etc/bind/zones.d} |
|
35 master_dir=${MASTER_DIR:-/etc/bind/master} |
|
36 |
|
37 if [ ! -d $master_dir ] |
|
38 then |
|
39 echo $master_dir nicht gefunden |
|
40 exit 1 |
|
41 fi |
|
42 |
|
43 if [ ! -d $zone_conf_dir ] |
|
44 then |
|
45 echo $zone_conf_dir nicht gefunden |
|
46 exit 1 |
|
47 fi |
|
48 |
|
49 # debug option |
|
50 if test $opt_debug; then |
|
51 cat <<xxx |
|
52 this host: $this_host [$this_ip] |
|
53 this domain: $this_domain |
|
54 primary: $primary |
|
55 secondary: $secondary [$secondary_ip] |
|
56 hostmaster: $hostmaster |
|
57 zone config directory: $zone_conf_dir |
|
58 xxx |
|
59 exit |
|
60 fi |
|
61 |
|
62 for utf8domain in "$@"; do |
|
63 domain=$(idn --quiet "$utf8domain") |
|
64 |
|
65 test -d $master_dir/$domain || mkdir $master_dir/$domain |
|
66 |
|
67 zonefile=$master_dir/$domain/$domain |
|
68 config=$zone_conf_dir/$domain |
|
69 |
|
70 echo "$domain ($utf8domain)" |
|
71 |
|
72 test -f $zonefile && { echo "$zonefile exists. Skipping $domain" >&2; continue; } |
|
73 test -f $config && { echo "$config exists. Skipping $domain" >&2; continue; } |
|
74 |
|
75 tpage \ |
|
76 --define start="$start" \ |
|
77 --define domain="$domain" \ |
|
78 --define time="$(date +%Y%m%d00)" \ |
|
79 --define primary="$primary" \ |
|
80 --define secondary="$secondary" \ |
|
81 --define hostmaster="$hostmaster" \ |
|
82 --define customer="$customer" \ |
|
83 --define utf8domain="$utf8domain" \ |
|
84 templates/named.zone \ |
|
85 >$zonefile |
|
86 |
|
87 tpage \ |
|
88 --define domain="$domain" \ |
|
89 --define start="$start" \ |
|
90 --define customer="$customer" \ |
|
91 --define utf8domain="$utf8domain" \ |
|
92 --define file="$master_dir/$domain/$domain" \ |
|
93 --define primary_ip="$primary_ip" \ |
|
94 --define secondary_ip="$secondary_ip" \ |
|
95 templates/named.config \ |
|
96 >$config |
|
97 |
|
98 done |
|
99 |
4 |
100 |
5 |
|
6 if (@ARGV < 2) { |
|
7 print "usage: zone-mk kundennummer domain ... \n"; |
|
8 exit 1; |
|
9 } |
|
10 |
|
11 my $primary = "pu.schlittermann.de"; |
|
12 my $secondary= "hh.schlittermann.de"; |
|
13 my $zone_conf_dir= "/etc/bind/zones.d"; |
|
14 my $master_dir = "/etc/bind/master"; |
|
15 my $customer = shift @ARGV; |
|
16 chomp (my $primary_ip = `dig +short $primary`); |
|
17 chomp (my $secondary_ip = `dig +short $secondary`); |
|
18 chomp (my $this_host= `hostname -f`); |
|
19 chomp (my $this_ip= `hostname -i`); |
|
20 chomp (my $this_domain = `hostname -d`); |
|
21 chomp (my $time = `date +%Y%m%d00`); |
|
22 chomp (my $start= `date -I`); |
|
23 my $hostmaster = "hostmaster.$this_domain"; |
|
24 |
|
25 if (! -e $master_dir) { |
|
26 print "$master_dir nicht vorhanden \n"; |
|
27 exit 1; |
|
28 } |
|
29 if (! -e $zone_conf_dir) { |
|
30 print "$zone_conf_dir nicht vorhanden \n"; |
|
31 exit 1; |
|
32 } |
|
33 |
|
34 |
|
35 # legt fuer jede domain in @ARGV ein verzeichnis in $master_dir an. |
|
36 # schreibt aus den angegeben templates die dateien $zonefile und $config |
|
37 # in die entsprechenden verzeichnisse. |
|
38 |
|
39 foreach (@ARGV) { |
|
40 |
|
41 chomp (my $domain = `idn --quiet "$_"`); |
|
42 my $zonefile = "$master_dir/$domain/$domain"; |
|
43 my $config = "$zone_conf_dir/$domain"; |
|
44 my $utf8domain = "$_"; |
|
45 |
|
46 if (! -e "$master_dir/$domain") { |
|
47 `mkdir $master_dir/$domain`; |
|
48 } |
|
49 |
|
50 if (-e $zonefile) { |
|
51 $zonefile =~ s#/.*/##; |
|
52 print "$zonefile exists. Skipping $domain\n"; |
|
53 next; |
|
54 } |
|
55 if (-e $config) { |
|
56 $config =~ s#/.*/##; |
|
57 print "$config exists. Skipping $domain\n"; |
|
58 next; |
|
59 } |
|
60 |
|
61 print "$domain ($_) for $customer \n"; |
|
62 |
|
63 open (TEMPZONE, "templates/named.zone"); |
|
64 my @tempzone = <TEMPZONE>; |
|
65 close (TEMPZONE); |
|
66 |
|
67 foreach (@tempzone) { |
|
68 s#<start>#$start#; |
|
69 s#<domain>#$domain#; |
|
70 s#<time>#$time#; |
|
71 s#<primary>#$primary#; |
|
72 s#<secondary>#$secondary#; |
|
73 s#<hostmaster>#$hostmaster#; |
|
74 s#<customer>#$customer#; |
|
75 s#<utf8domain>#$utf8domain#; |
|
76 } |
|
77 |
|
78 open (ZONEOUT, ">$zonefile"); |
|
79 print ZONEOUT @tempzone; |
|
80 close (ZONEOUT); |
|
81 |
|
82 open (TEMPCONF, "templates/named.config"); |
|
83 my @tempconf = <TEMPCONF>; |
|
84 close (TEMPCONF); |
|
85 |
|
86 foreach (@tempconf) { |
|
87 s#<domain>#$domain#; |
|
88 s#<start>#$start#; |
|
89 s#<customer>#$customer#; |
|
90 s#<utf8domain>#$utf8domain#; |
|
91 s#<file>#$master_dir/$domain/$domain#; |
|
92 s#<primary_ip>#$primary_ip#; |
|
93 s#<secondary_ip>#$secondary_ip#; |
|
94 } |
|
95 |
|
96 open (CONFOUT, ">$config" ); |
|
97 print CONFOUT @tempconf; |
|
98 close (CONFOUT); |
|
99 } |