2008-04-28 17:57:05 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
|
2008-04-28 18:28:25 +02:00
|
|
|
use Getopt::Long;
|
|
|
|
use Net::DNS::Resolver;
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
2008-04-28 17:57:05 +02:00
|
|
|
|
|
|
|
for my $f (@ARGV) {
|
2008-04-28 18:28:25 +02:00
|
|
|
my $maxserial = 0;
|
|
|
|
if (my $zone = $file2zone{$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: $!";
|
2008-04-28 17:57:05 +02:00
|
|
|
while (<$in>) {
|
|
|
|
if (/(.*\bSOA\b.*?)(\d+)( \d+ \d+ \d+ \d+)/) {
|
|
|
|
my $serial = $2;
|
2008-04-28 18:28:25 +02:00
|
|
|
$maxserial = $serial if ($serial > $maxserial);
|
|
|
|
$maxserial++;
|
|
|
|
print $out "$1$maxserial$3\n";
|
2008-04-28 17:57:05 +02:00
|
|
|
} else {
|
|
|
|
print $out $_;
|
|
|
|
}
|
|
|
|
}
|
2008-04-28 18:28:25 +02:00
|
|
|
close($out) or die "cannot close $f.new: $!";
|
|
|
|
# rename "$f.new", $f || die "cannot rename $f.new to $f: $!";
|
2008-04-28 17:57:05 +02:00
|
|
|
}
|