-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlist-zones
executable file
·91 lines (74 loc) · 2.2 KB
/
list-zones
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/local/bin/perl -w
#
# $Id$
#
# script to read zone entrys from database
#
use strict;
use HOSTDB;
use Getopt::Std;
use vars qw ($opt_h $opt_d $opt_r $opt_x $opt_X);
getopts ('hdrxX');
my $debug = 0;
my $raw = 0;
my $skip_delegated = 0;
my $skip_non_delegated = 0;
$debug = 1 if (defined ($opt_d));
$raw = 1 if (defined ($opt_r));
$skip_non_delegated = 1 if (defined ($opt_x));
$skip_delegated = 1 if (defined ($opt_X));
if ($opt_h) {
die (<<EOT);
Syntax: $0 [options]
options :
-d debug output
-r raw mode, just zone names (for scripting)
-x skip NON-delegated zones
-X skip delegated zones
EOT
}
die ("$0: -x and -X contradicts each other\n") if ($skip_delegated and $skip_non_delegated);
my $hostdb = HOSTDB::DB->new (inifile => HOSTDB::get_inifile (),
debug => $debug
);
my @searchfor = @ARGV;
push (@searchfor, "*") if ($#searchfor == -1); # search for ALL
my $exit_code = 1;
foreach my $searchzone (sort @searchfor) {
if ($searchzone eq "*") {
print ("search for: ALL ZONES\n") unless ($raw);
} else {
print ("search for: '$searchzone'\n") unless ($raw);
}
printf ("%-25s %-10s %-15s %s\n", "zonename", "serial", "owner", "delegated") unless ($raw);
if ($searchzone eq "*") {
foreach my $zone ($hostdb->findallzones ()) {
next if ($skip_delegated and $zone->delegated () eq 'Y');
next if ($skip_non_delegated and $zone->delegated () eq 'N');
$exit_code = 0;
if ($raw) {
print ($zone->zonename () . "\n");
} else {
printf "%-25s %-10s %-15s %s\n", $zone->zonename (),
$zone->serial (), $zone->owner (), $zone->delegated ();
}
}
} else {
# get list of zone objects. findzonebyname() returns undef if
# $searchzone is not a valid domain name
my @zones = $hostdb->findzonebyname ($searchzone) || ();
foreach my $zone (@zones) {
next if ($skip_delegated and $zone->delegated () eq 'Y');
next if ($skip_non_delegated and $zone->delegated () eq 'N');
$exit_code = 0;
if ($raw) {
print ($zone->zonename () . "\n");
} else {
printf "%-25s %-10s %-15s %s\n", $zone->zonename (), $zone->serial (),
$zone->owner (), $zone->delegated ();
}
}
}
print ("\n") unless ($raw);
}
exit ($exit_code);