-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnsupdate-delete.pl
executable file
·75 lines (54 loc) · 1.37 KB
/
nsupdate-delete.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/perl
use warnings;
use strict;
use autodie;
# usage:
# ./nsupdate-delete.pl /tmp/nsupdate.delete | nsupdate -v -d && /usr/sbin/rndc sync -clean
use lib './lib';
use BIND::Config qw( check_config @zones zone_local_ip );
use Data::Dump qw(dump);
my $debug = $ENV{DEBUG} || 0;
$|=1; # if $debug;
check_config( "/etc/bind/named.conf" );
my $dynamic_regex = '(' . join('|', keys %{ $BIND::Config::allow_update } ) . ')\.';
my $update;
while(<>) {
chomp;
my $name = $_;
warn "# $name\n";
if ( $name =~ m/$dynamic_regex/ ) {
push @{ $update->{$1} }, $name;
} else {
die "not dynamic ip $name";
}
}
warn "# update = ",dump($update) if $debug;
foreach my $zone ( sort keys %$update ) {
if ( $ENV{FILE} ) {
open(STDOUT, '>', "/tmp/nsupdate.zone.$zone");
warn "# created /tmp/nsupdate.zone.$zone\n";
}
if ( my $ip = zone_local_ip( $zone ) ) {
print "server $ip\n";
print "local $ip\n";
}
print "zone $zone\n";
my ( $key_name, $secret ) = BIND::Config::zone_key_name_secret( $zone );
# key [hmac:] {keyname} {secret}
print "key $key_name $secret\n";
print "send\n";
my $count = 0;
foreach my $name ( @{ $update->{$zone} } ) {
if ( $zone =~ m/\.arpa$/ ) {
print "delete $name PTR\n";
print "send\n";
$count++;
} else {
print "delete $name A\n";
print "send\n";
print "delete $name TXT\n";
print "send\n";
$count++;
}
}
}