--- a/zone-mk Mon Aug 02 13:45:47 2010 +0200
+++ b/zone-mk Wed Aug 04 11:27:21 2010 +0200
@@ -1,20 +1,45 @@
#!/usr/bin/perl -w
use strict;
+use FindBin;
if (@ARGV < 2) {
print "usage: zone-mk kundennummer domain ... \n";
exit 1;
}
+# oeffnet Konfigurations- und Templatefiles - relativ oder absolut
+my @configs = ("$FindBin::Bin/dnstools.conf", "/etc/dnstools.conf");
+my @templc = ("$FindBin::Bin/templates/named.config","/etc/dnstools/templates/named.config");
+my @templz = ("$FindBin::Bin/templates/named.zone","/etc/dnstools/templates/named.zone");
my %config;
-open (CONFIG, "dnstools.conf");
+
+for (grep {-f} @configs) {
+ open(CONFIG, $_) or die "Can't open $_: $!\n";
+}
+unless (seek(CONFIG,0 ,0 )) {
+ die "Can't open config (searched: @configs)\n";
+}
+
+for (grep {-f} @templc) {
+ open(TEMPCONF, $_) or die "Can't open $_: $!\n";
+}
+unless (seek(TEMPCONF,0 ,0 )) {
+ die "Can't open config (searched: @templc)\n";
+}
+
+for (grep {-f} @templz) {
+ open(TEMPZONE, $_) or die "Can't open $_: $!\n";
+}
+unless (seek(TEMPZONE,0 ,0 )) {
+ die "Can't open config (searched: @templz)\n";
+}
+
while (<CONFIG>) {
chomp;
s/#.*//;
s/\t//g;
s/\s//g;
-
next unless length;
my ($cname, $ccont) = split (/\s*=\s*/, $_,2);
$config{$cname} = $ccont;
@@ -36,20 +61,18 @@
chomp (my $start= `date -I`);
my $hostmaster = "hostmaster.$this_domain";
-unless (-e $master_dir) {
- print "$master_dir nicht vorhanden \n";
- exit 1;
+unless (-d $master_dir and -r $master_dir) {
+ die "$master_dir: $!\n";
}
-unless (-e $zone_conf_dir) {
- print "$zone_conf_dir nicht vorhanden \n";
- exit 1;
+
+unless (-d $zone_conf_dir and -r $zone_conf_dir) {
+ die "$master_dir: $!\n";
}
# legt fuer jede domain in @ARGV ein verzeichnis in $master_dir an.
# schreibt aus den angegebenen templates die dateien $zonefile und $config
# in die entsprechenden verzeichnisse.
-
for (@ARGV) {
chomp (my $domain = `idn --quiet "$_"`);
@@ -57,16 +80,16 @@
my $config = "$zone_conf_dir/$domain";
my $utf8domain = "$_";
- unless ( -e "$master_dir/$domain") {
+ unless ( -d "$master_dir/$domain") {
`mkdir $master_dir/$domain`;
}
- if (-e $zonefile) {
+ if (-f $zonefile) {
$zonefile =~ s#/.*/##;
print "$zonefile exists. Skipping $domain\n";
next;
}
- if (-e $config) {
+ if (-f $config) {
$config =~ s#/.*/##;
print "$config exists. Skipping $domain\n";
next;
@@ -74,10 +97,7 @@
print "$domain ($_) for $customer \n";
- open (TEMPZONE, "templates/named.zone");
my @tempzone = <TEMPZONE>;
- close (TEMPZONE);
-
for (@tempzone) {
s#<start>#$start#;
s#<domain>#$domain#;
@@ -93,10 +113,7 @@
print ZONEOUT @tempzone;
close (ZONEOUT);
- open (TEMPCONF, "templates/named.config");
my @tempconf = <TEMPCONF>;
- close (TEMPCONF);
-
for (@tempconf) {
s#<domain>#$domain#;
s#<start>#$start#;