1 #!/usr/bin/perl |
1 #!/usr/bin/perl |
2 |
2 |
|
3 use v5.10; |
3 use warnings; |
4 use warnings; |
4 use strict; |
5 use strict; |
5 use File::Path; |
6 use File::Path qw(remove_tree); |
6 use DNStools::Config qw(get_config); |
7 use DNStools::Config qw(get_config); |
|
8 use Net::LibIDN qw(:all); |
|
9 use Pod::Usage; |
|
10 use Getopt::Long; |
7 |
11 |
8 # liest die Konfiguration ein |
12 my $CHARSET = "UTF-8"; |
9 my %config = get_config(); |
|
10 |
13 |
11 my $master_dir = $config{"master_dir"}; |
14 my %cf = get_config(); |
12 my $conf_dir = $config{"zone_conf_dir"}; |
|
13 |
15 |
14 for (@ARGV) { |
16 my $opt_interactive = 0; |
15 chomp(my $zone = `idn --quiet "$_"`); |
|
16 |
17 |
17 if (-d "$master_dir/$zone") { |
18 MAIN: { |
18 rmtree "$master_dir/$zone/" |
|
19 and print "zone-dir for $zone removed\n"; |
|
20 } |
|
21 else { |
|
22 print "$master_dir/$zone: $!\n"; |
|
23 } |
|
24 |
19 |
25 if (-e "$conf_dir/$zone") { |
20 GetOptions( |
26 unlink "$conf_dir/$zone" |
21 "i|interactive!" => \$opt_interactive, |
27 and print "configuration-file for $zone removed\n"; |
22 "h|help" => sub { pod2usage(-exit => 0, -verbose => 1) }, |
28 } |
23 "m|man" => sub { |
29 else { |
24 pod2usage( |
30 print "$conf_dir/$zone: $!\n"; |
25 -exit => 0, |
|
26 -verbose => 2, |
|
27 -noperldoc => system("perldoc -V &>/dev/null") |
|
28 ); |
|
29 }, |
|
30 ) |
|
31 and @ARGV |
|
32 or pod2usage; |
|
33 |
|
34 for my $utf8zone (@ARGV) { |
|
35 my $zone = idn_to_ascii($utf8zone, $CHARSET); |
|
36 |
|
37 if (not(-d "$cf{master_dir}/$zone" or -f "$cf{zone_conf_dir}/$zone")) { |
|
38 say "$utf8zone ($zone): nothing found"; |
|
39 next; |
|
40 } |
|
41 |
|
42 if ($opt_interactive) { |
|
43 print "Remove $utf8zone ($zone)? [y/n]: "; |
|
44 chomp($_ = <STDIN>); |
|
45 next if not /^y(?:es)?$/i; |
|
46 } |
|
47 |
|
48 remove_tree("$cf{master_dir}/$zone", "$cf{zone_conf_dir}/$zone", |
|
49 { verbose => 1 }); |
|
50 |
31 } |
51 } |
32 } |
52 } |
|
53 |
|
54 __END__ |
|
55 |
|
56 =head1 NAME |
|
57 |
|
58 zone-rm - remove a zone |
|
59 |
|
60 =head1 SYNOPSIS |
|
61 |
|
62 zone-rm [-i|--interactive] zone... |
|
63 |
|
64 zone-rm [-h|--help] |
|
65 zone-rm [-m|--man] |
|
66 |
|
67 =head1 DESCRIPTION |
|
68 |
|
69 This removes the specified zone(s) from the configured directories. |
|
70 |
|
71 =head1 OPTIONS |
|
72 |
|
73 The standard B<-h>, B<--help>, B<-m>, and B<--man> options are |
|
74 understood. |
|
75 |
|
76 =over |
|
77 |
|
78 =item B<-i>|B<--interactive> |
|
79 |
|
80 Ask for confirmation. (default: off) |
|
81 |
|
82 =cut |