--- a/bin/dnsvi Wed Jan 21 23:12:53 2015 +0100
+++ b/bin/dnsvi Tue Jan 27 20:03:08 2015 +0100
@@ -14,19 +14,20 @@
use DNS::Vi;
sub slurp {
- local $/ = undef;
+ local $/ = undef;
local @ARGV = @_;
<>;
}
sub main {
my %o = (
- local => undef,
- key => undef,
+ local => undef,
+ key => (grep { -f } glob "$ENV{HOME}/.dnsvi/default/K*key")[0]
+ // (undef, local => 1),
server => undef,
debug => undef,
editor => $ENV{EDITOR} // 'vi',
- skip => [qw/RRSIG NSEC3 NSEC3PARAM NSEC DNSKEY TSIG/],
+ skip => [qw/RRSIG NSEC3 NSEC3PARAM NSEC DNSKEY TSIG/],
);
GetOptions(
@@ -52,23 +53,24 @@
$zone
);
- my @zone1 = parse($_ = `@dig`, { -skip => $o{skip} } )
+ my @zone1 = parse($_ = `@dig`, { -skip => $o{skip} })
or die "Empty zone\n";
my $fh2;
my @zone2 = do {
- if (my $file = shift @ARGV) {
- parse(slurp($file), { -skip => $o{skip} });
- }
- else {
- edit(@zone1, { -skip => $o{skip}, -editor => $o{editor}, -backup => \$fh2 });
- }
+ if (my $file = shift @ARGV) {
+ parse(slurp($file), { -skip => $o{skip} });
+ }
+ else {
+ edit(@zone1,
+ { -skip => $o{skip}, -editor => $o{editor}, -backup => \$fh2 });
+ }
};
### @zone2
my %delta = delta(\@zone1, \@zone2);
if (!%delta) {
- say 'nothing changed';
- return 0;
+ say 'nothing changed';
+ return 0;
}
say 'The following changes need your confirmation.';
@@ -76,16 +78,21 @@
print 'confirm (yes|NO): ';
return 1 if <STDIN> !~ /^y/i;
- update(\@zone1, @delta{qw/add del/}, {
- -server => $o{server},
- -local => $o{local},
- -debug => $o{debug},
- -key => $o{key}})
- or do {
- copy($fh2->filename, ",dnsvi-$$")
- and say "Saved as ',dnsvi-$$'"
- if $fh2;
- };
+ update(
+ \@zone1,
+ @delta{qw/add del/},
+ {
+ -server => $o{server},
+ -local => $o{local},
+ -debug => $o{debug},
+ -key => $o{key}
+ }
+ )
+ or do {
+ copy($fh2->filename, ",dnsvi-$$")
+ and say "Saved as ',dnsvi-$$'"
+ if $fh2;
+ };
return 0;
}
@@ -115,7 +122,8 @@
=item B<-l>|B<--local>
Local mode, when running on the server where the updates need to go to.
-But still zone transfers need to be enabled! (default: off)
+But still zone transfers need to be enabled! (default: on, if not
+default key file is found, otherwise off)
=item B<-s>|B<--server> B<server-name>
@@ -125,7 +133,7 @@
=item B<-k>|B<--key> B<key-file>
The name of the key file we need for TSIG (the AXFR will use it,
-as well as the update).
+as well as the update). (default: F<~/.dnsvi/default/K*key)
To create such a key you may use