Handle hostnames with upper-case letters
[webmin.git] / bind8 / resign.pl
1 #!/usr/local/bin/perl
2 # Called from cron to re-sign all zones that are too old
3
4 $no_acl_check++;
5 require './bind8-lib.pl';
6
7 if ($ARGV[0] eq "--debug") {
8         $debug = 1;
9         }
10 if (!$config{'dnssec_period'}) {
11         print STDERR "Maximum age not set\n" if ($debug);
12         exit(0);
13         }
14
15 @zones = &list_zone_names();
16 $errcount = 0;
17 foreach $z (@zones) {
18         # Get the key
19         next if ($z->{'type'} ne 'master');
20         print STDERR "Considering zone $z->{'name'}\n" if ($debug);
21         @keys = &get_dnssec_key($z);
22         print STDERR "  Key count ",scalar(@keys),"\n" if ($debug);
23         next if (@keys != 2);
24         ($zonekey) = grep { !$_->{'ksk'} } @keys;
25         next if (!$zonekey);
26         print STDERR "  Zone key in ",$zonekey->{'privatefile'},"\n"
27                 if ($debug);
28
29         # Check if old enough
30         @st = stat($zonekey->{'privatefile'});
31         if (!@st) {
32                 print STDERR "  Private key file $zonekey->{'privatefile'} ",
33                              "missing\n" if ($debug);
34                 next;
35                 }
36         $old = (time() - $st[9]) / (24*60*60);
37         print STDERR "  Age in days $old\n" if ($debug);
38         if ($old > $config{'dnssec_period'}) {
39                 # Too old .. signing
40                 $err = &resign_dnssec_key($z);
41                 if ($err) {
42                         print STDERR "  Re-signing failed : $err\n";
43                         $errcount++;
44                         }
45                 elsif ($debug) {
46                         print STDERR "  Re-signed OK\n";
47                         }
48                 }
49         }
50 exit($errcount);
51