1 #! /usr/bin/perl |
|
2 |
|
3 use v5.10; |
|
4 use strict; |
|
5 use warnings; |
|
6 use Pod::Usage; |
|
7 use File::Basename; |
|
8 use FindBin; |
|
9 use Time::Local; |
|
10 use Getopt::Long; |
|
11 |
|
12 my %config; |
|
13 my $opt_expiry = undef; |
|
14 |
|
15 MAIN: { |
|
16 my %info; # will hold the information we collected |
|
17 |
|
18 GetOptions( |
|
19 "e|expiry" => \$opt_expiry, |
|
20 "h|help" => sub { pod2usage(-exit => 0, -verbose => 1) }, |
|
21 "m|man" => sub { |
|
22 pod2usage( |
|
23 -exit => 0, |
|
24 -verbose => 2, |
|
25 -noperldoc => system("perldoc -V &>/dev/null") |
|
26 ); |
|
27 }, |
|
28 ) or pod2usage; |
|
29 |
|
30 { # find and read/parse the config (could use some common config parser) |
|
31 my @configs = ("$FindBin::Bin/dnstools.conf", "/etc/dnstools.conf"); |
|
32 ($_) = grep { -f } @configs; |
|
33 open(my $config, $_) or die "Can't open $_: $!\n"; |
|
34 |
|
35 while (<$config>) { |
|
36 chomp; |
|
37 s/#.*//; |
|
38 s/\s//g; |
|
39 my ($k, $v) = split(/\s*=\s*/, $_, 2) or next; |
|
40 $config{$k} = $v; |
|
41 } |
|
42 } |
|
43 |
|
44 die "$config{master_dir}: $!\n" if not -d $config{master_dir}; |
|
45 |
|
46 foreach my $dir (grep { -d } glob "$config{master_dir}/*") { |
|
47 |
|
48 my $zone = basename($dir); |
|
49 $info{$zone} = { status => "OK" }; |
|
50 |
|
51 if (not -f "$dir/.index.zsk") { |
|
52 $info{$zone}{zsk} = 0; |
|
53 $info{$zone}{ksk} = 0; |
|
54 $info{$zone}{kc} = 0; |
|
55 $info{$zone}{end} = "-"; |
|
56 $info{$zone}{expiry} = undef; |
|
57 next; |
|
58 } |
|
59 |
|
60 # prueft wie viele zsks genutzt werden |
|
61 { |
|
62 open(my ($fh), $_ = "<$dir/.index.zsk") |
|
63 or die "Can't open $_: $!\n"; |
|
64 () = <$fh>; |
|
65 $info{$zone}{zsk} = $. |
|
66 } |
|
67 |
|
68 # prueft wie viele ksks genutzt werden |
|
69 { |
|
70 open(my ($fh), $_ = "<$dir/.index.ksk") |
|
71 or die "Can't open $_: $!\n"; |
|
72 () = <$fh>; |
|
73 $info{$zone}{ksk} = $. |
|
74 } |
|
75 |
|
76 # prueft wie oft die schluessel zum signieren genutzt wurden |
|
77 { |
|
78 open(my ($fh), $_ = "<$dir/.keycounter") |
|
79 or die "Can't open $_: $!\n"; |
|
80 chomp($info{$zone}{kc} = <$fh>); |
|
81 } |
|
82 |
|
83 # prueft das ablaufdatum |
|
84 if (!-f "$dir/$zone.signed") { |
|
85 $info{$zone}{end} = "-"; |
|
86 next; |
|
87 } |
|
88 |
|
89 open(my ($fh), $_ = "<$dir/$zone.signed") or die "Can't open $_: $!\n"; |
|
90 while (<$fh>) { |
|
91 next if not /RSIG.*SOA.*\s |
|
92 (?<year>\d\d\d\d) |
|
93 (?<mon>\d\d) |
|
94 (?<day>\d\d) |
|
95 (?<hour>\d\d) |
|
96 (?<min>\d\d)\d+\s\(/ix; |
|
97 $info{$zone}{end} = "$+{day}.$+{mon}.$+{year} $+{hour}:$+{min}"; |
|
98 $info{$zone}{expiry} = |
|
99 timelocal(0, $+{min}, $+{hour}, $+{day}, $+{mon} - 1, $+{year}); |
|
100 } |
|
101 } |
|
102 |
|
103 { # output |
|
104 |
|
105 my $sort_by = |
|
106 $opt_expiry |
|
107 ? sub { ($info{$a}{expiry} // 2**64) <=> ($info{$b}{expiry} // 2**64) } |
|
108 : sub { $a cmp $b }; |
|
109 |
|
110 my $format_h = "%-35s %-8s %1s/%1s %3s %7s\n"; |
|
111 my $format_l = "%-35s %-8s %1d/%1d %5d %19s\n"; |
|
112 |
|
113 printf $format_h => qw(Domain Status ZSK KSK Used Sig-end); |
|
114 |
|
115 foreach my $zone (sort $sort_by keys %info) { |
|
116 printf $format_l => $zone, |
|
117 @{ $info{$zone} }{qw(status zsk ksk kc end)}; |
|
118 } |
|
119 } |
|
120 } |
|
121 |
|
122 __END__ |
|
123 |
|
124 =head1 NAME |
|
125 |
|
126 zone-ls -- lists all zones |
|
127 |
|
128 =head1 SYNOPSIS |
|
129 |
|
130 zone-ls [-e|--expiry] |
|
131 |
|
132 =head1 DESCRIPTION |
|
133 |
|
134 This B<zone-ls> lists all zones under control of our dnstools suite. The output is ordered by domain name. |
|
135 |
|
136 =head1 OPTIONS |
|
137 |
|
138 =over |
|
139 |
|
140 =item B<-e>|B<--expiry> |
|
141 |
|
142 Order the output by expiry date. The sooner the key expires, the more top the |
|
143 domain is listed. |
|
144 |
|
145 =back |
|
146 |
|
147 Additionally the common B<-h>|B<--help>|B<-m>|B<--man> options, which should be |
|
148 self explanatory. |
|
149 |
|
150 =head1 AUTHORS |
|
151 |
|
152 L<andre.suess@pipkin.cc> |
|
153 |
|
154 =cut |
|
155 |
|
156 # vim:ts=4 sw=4 ai si aw: |
|