2 |
2 |
3 use strict; |
3 use strict; |
4 use warnings; |
4 use warnings; |
5 use Pod::Usage; |
5 use Pod::Usage; |
6 use File::Basename; |
6 use File::Basename; |
|
7 use Getopt::Long; |
7 |
8 |
8 my $ME = basename $0; |
9 my $ME = basename $0; |
9 |
10 |
|
11 my $opt_delete = 0; |
10 my $opt_ttl = 3600; |
12 my $opt_ttl = 3600; |
|
13 my $opt_help; |
|
14 my $opt_man; |
|
15 |
11 my $opt_domain; |
16 my $opt_domain; |
12 |
17 |
13 my $opt_resolv = "/etc/resolv.conf"; |
18 my $opt_resolv = "/etc/resolv.conf"; |
14 |
19 |
15 MAIN: { |
20 MAIN: { |
|
21 |
|
22 GetOptions( |
|
23 "d|delete" => \$opt_delete, |
|
24 "ttl=i" => \$opt_ttl, |
|
25 "help" => sub { pod2usage(-verbose => 1, exit => 0) }, |
|
26 "man" => sub { pod2usage(-verbose => 2, exit => 0) }, |
|
27 ) or pod2usage(); |
16 pod2usage() if @ARGV == 0; |
28 pod2usage() if @ARGV == 0; |
|
29 |
|
30 die "HH"; |
|
31 |
|
32 my @out; |
|
33 my $action = $opt_delete ? "delete" : "add"; |
17 |
34 |
18 if (!$opt_domain) { |
35 if (!$opt_domain) { |
19 local @ARGV = ($opt_resolv); |
36 local @ARGV = ($opt_resolv); |
20 $opt_domain = (split " ", (grep /^\s*(?:domain|search)\s+/, <>)[-1])[1]; |
37 $opt_domain = (split " ", (grep /^\s*(?:domain|search)\s+/, <>)[-1])[1]; |
21 |
38 |
26 my ($host, @aliases) = map { /\./ ? $_ : "$_.$opt_domain" } split /:/, shift; |
43 my ($host, @aliases) = map { /\./ ? $_ : "$_.$opt_domain" } split /:/, shift; |
27 my $ip = shift; |
44 my $ip = shift; |
28 |
45 |
29 pod2usage() if !@aliases and not $ip; |
46 pod2usage() if !@aliases and not $ip; |
30 |
47 |
31 print "update add $host $opt_ttl CNAME $_\n" foreach @aliases; |
48 push @out, "update $action $_ $opt_ttl CNAME $host" foreach @aliases; |
32 print "update add $host $opt_ttl A $ip\n" if defined $ip; |
49 push @out, "update $action $host $opt_ttl A $ip" if defined $ip; |
33 print "send\n"; |
50 push @out, "send" if @out; |
34 |
51 |
35 if ($ip) { |
52 if ($ip) { |
36 my $rev_ip = (join ".", reverse split /\./, $ip) . ".in-addr.arpa"; |
53 my $rev_ip = (join ".", reverse split /\./, $ip) . ".in-addr.arpa"; |
37 print "update add $rev_ip $opt_ttl PTR $host\n" |
54 push @out, "update $action $rev_ip $opt_ttl PTR $host", |
38 . "send\n"; |
55 "send"; |
39 } |
56 } |
|
57 |
|
58 print join "\n", @out, ""; |
40 } |
59 } |
41 |
60 |
42 __END__ |
61 __END__ |
43 |
62 |
44 =head1 NAME |
63 =head1 NAME |
45 |
64 |
46 dnstool - interface to nsupdate |
65 dnstool - interface to nsupdate |
47 |
66 |
48 =head1 SYNOPSIS |
67 =head1 SYNOPSIS |
49 |
68 |
50 dns-tool host[:alias:...] ip |
69 dns-tool [-d|--delete] [--ttl=<ttl>] host[:alias:...] ip |
51 dns-tool host:alias:... |
70 dns-tool [-d|--delete] [--ttl=<ttl>] host:alias:... |
52 |
71 |
53 =head1 DESCRIPTION |
72 =head1 DESCRIPTION |
54 |
73 |
|
74 This tool helps you using C<nsupdate>, it doesn't update anything itself, it just |
|
75 produces output suitable for C<nsupdate>. |
|
76 |
|
77 =head2 EXAMPLES |
|
78 |
|
79 dns-tool seb-pc3454:lohn 172.20.2.2 | nsupdate |
|
80 |
55 =head1 OPTIONS |
81 =head1 OPTIONS |
|
82 |
|
83 =over |
|
84 |
|
85 =item B<-d>|B<--delete> |
|
86 |
|
87 Instead of adding, B<delete> the items. (default: off) |
|
88 |
|
89 =item B<--ttl>=I<ttl> |
|
90 |
|
91 Set the TTL (unit: seconds) of the inserted records (default: 3600) |
|
92 |
|
93 =item B<-h>|B<--help> |
|
94 =item B<-m>|B<--man> |
|
95 |
|
96 Help resp. manual page. |
|
97 |
|
98 =back |
|
99 |
|
100 |
|
101 |
|
102 =head1 COPYRIGHT, VERSION and AUTHOR |
|
103 |
|
104 This tool is released under terms of Gnu Public License in its |
|
105 current version. |
|
106 |
|
107 $Id$ |
|
108 $URL$ |
|
109 |
|
110 Heiko Schlittermann <hs@schlittermann.de> |
56 |
111 |
57 =cut |
112 =cut |
58 |
113 |
59 # vim:sts=4 sw=4 aw ai sm: |
114 # vim:sts=4 sw=4 aw ai sm: |
60 |
115 |