|
1 #! /usr/bin/perl |
|
2 #line 2 |
|
3 use 5.010; |
|
4 use strict; |
|
5 use warnings; |
|
6 use if $ENV{DEBUG}//'' eq 'vidns' => 'Smart::Comments'; |
|
7 use File::Temp; |
|
8 use Getopt::Long; |
|
9 use Pod::Usage; |
|
10 |
|
11 use blib; |
|
12 use ViDNS; |
|
13 |
|
14 sub main { |
|
15 my %o = ( |
|
16 key => undef, |
|
17 server => undef, |
|
18 debug => undef, |
|
19 ); |
|
20 |
|
21 GetOptions( |
|
22 'k|key=s' => \$o{key}, |
|
23 's|server=s' => \$o{server}, |
|
24 'd|debug!' => \$o{debug}, |
|
25 ) |
|
26 && @ARGV == 1 |
|
27 or pod2usage(); |
|
28 |
|
29 my @dig = ( |
|
30 dig => 'AXFR', |
|
31 defined $o{key} ? (-k => $o{key}) : (), |
|
32 defined $o{server} ? ("\@$o{server}") : (), |
|
33 $ARGV[0] |
|
34 ); |
|
35 |
|
36 my @zone1 = grep { |
|
37 not $_->{rrset}{rrtype} ~~ |
|
38 [qw(RRSIG NSEC3 NSEC3PARAM NSEC DNSKEY TSIG)] |
|
39 } parse($_ = `@dig`) or die $_; |
|
40 |
|
41 my $tmp = File::Temp->new(); |
|
42 $tmp->print(nice @zone1); |
|
43 $tmp->flush(); |
|
44 system $ENV{EDITOR} // 'vi' => $tmp->filename; |
|
45 $tmp->seek(0, 0); |
|
46 my @zone2 = parse(<$tmp>); |
|
47 my ($add, $del) = delta(\@zone1, \@zone2); |
|
48 |
|
49 my @cmds = ((map { "update add $_" } @$add), |
|
50 (map { "update delete $_" } @$del)); |
|
51 |
|
52 print <<_EOF, join "\n" => @cmds, ''; |
|
53 # The following commands are about to be sent via nsupdate |
|
54 # to the master server: |
|
55 _EOF |
|
56 print '# Please confirm (yes/no): '; |
|
57 return 1 if <STDIN> ne "yes\n"; |
|
58 |
|
59 my @nsupdate = ('nsupdate', defined $o{debug} ? ('-d') : (), defined $o{key} ? (-k => $o{key}) : ()); |
|
60 open(my $nsupdate, '|-') or do { |
|
61 exec @nsupdate; |
|
62 die "Can't exec @nsupdate: $!\n"; |
|
63 }; |
|
64 print $nsupdate join "\n", @cmds, 'send', ''; |
|
65 close($nsupdate); |
|
66 say "nsupdate returned $?"; |
|
67 return 0; |
|
68 } |
|
69 |
|
70 exit main(@ARGV) if not caller; |
|
71 |
|
72 __END__ |
|
73 |
|
74 =head1 NAME |
|
75 |
|
76 vidns -- editor for dynamically maintained zones |
|
77 |
|
78 =head1 SYNOPSIS |
|
79 |
|
80 vidns [-k key] [-s server] [-d] <zone> |
|
81 |
|
82 =head1 DESCRIPTION |
|
83 |
|
84 =head1 PREREQUISITES |
|
85 |
|
86 We need some tools to be installed: |
|
87 |
|
88 =over |
|
89 |
|
90 =item B<dig> |
|
91 |
|
92 The domain information grabber is used for the zone transfer currently. |
|
93 |
|
94 =item B<nsupdate> |
|
95 |
|
96 The nsupdate tool is used to send the updates back to the server. |
|
97 |
|
98 =back |
|
99 |
|
100 =cut |