Check authoritative name servers for serial numbers, too.
This commit is contained in:
parent
7d35c95bc5
commit
4ebc2b2a57
|
@ -2,22 +2,69 @@
|
||||||
use warnings;
|
use warnings;
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
# Idea for improvement:
|
use Getopt::Long;
|
||||||
# take maximum of serial from file and from all authoritative nameservers,
|
use Net::DNS::Resolver;
|
||||||
# then increment by one.
|
|
||||||
|
my $cfg;
|
||||||
|
GetOptions('config:s' => \$cfg);
|
||||||
|
|
||||||
|
my %file2zone;
|
||||||
|
my $res;
|
||||||
|
|
||||||
|
if ($cfg) {
|
||||||
|
# XXX - this is very simplistic
|
||||||
|
open(my $fh, '<', $cfg) or die "cannot open $cfg: $!";
|
||||||
|
my $currentzone;
|
||||||
|
while (<$fh>) {
|
||||||
|
if (/zone "(.*?)"/) {
|
||||||
|
$currentzone = $1;
|
||||||
|
} elsif (m{file ".*/(.*)"}) {
|
||||||
|
$file2zone{$1} = $currentzone;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$res = Net::DNS::Resolver->new();
|
||||||
|
}
|
||||||
|
|
||||||
for my $f (@ARGV) {
|
for my $f (@ARGV) {
|
||||||
rename $f, "$f.old" || die "cannot rename $f to $f.old: $!";
|
my $maxserial = 0;
|
||||||
open (my $in, '<', "$f.old") or die "cannot open $f.old: $!";
|
if (my $zone = $file2zone{$f}) {
|
||||||
open (my $out, '>', "$f") or die "cannot open $f: $!";
|
my $reply = $res->send($zone, 'NS');
|
||||||
|
my @nsnames;
|
||||||
|
for my $ans ($reply->answer) {
|
||||||
|
push @nsnames, $ans->nsdname;
|
||||||
|
}
|
||||||
|
my @nsips;
|
||||||
|
for (@nsnames) {
|
||||||
|
my $reply = $res->send($_, 'A');
|
||||||
|
for my $ans ($reply->answer) {
|
||||||
|
push @nsips, $ans->address if $ans->type eq 'A';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (@nsips) {
|
||||||
|
$res->nameservers($_);
|
||||||
|
my $reply = $res->send($zone, 'SOA');
|
||||||
|
for my $ans ($reply->answer) {
|
||||||
|
if ($ans->type eq 'SOA') {
|
||||||
|
# XXX assume no wraparound
|
||||||
|
if ($ans->serial > $maxserial) {
|
||||||
|
$maxserial = $ans->serial;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
open (my $in, '<', "$f") or die "cannot open $f: $!";
|
||||||
|
open (my $out, '>', "$f.new") or die "cannot open $f.new: $!";
|
||||||
while (<$in>) {
|
while (<$in>) {
|
||||||
if (/(.*\bSOA\b.*?)(\d+)( \d+ \d+ \d+ \d+)/) {
|
if (/(.*\bSOA\b.*?)(\d+)( \d+ \d+ \d+ \d+)/) {
|
||||||
my $serial = $2;
|
my $serial = $2;
|
||||||
$serial++;
|
$maxserial = $serial if ($serial > $maxserial);
|
||||||
print $out "$1$serial$3\n";
|
$maxserial++;
|
||||||
|
print $out "$1$maxserial$3\n";
|
||||||
} else {
|
} else {
|
||||||
print $out $_;
|
print $out $_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
close($out) or die "cannot close $out";
|
close($out) or die "cannot close $f.new: $!";
|
||||||
|
# rename "$f.new", $f || die "cannot rename $f.new to $f: $!";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue