sbin/update-serial
changeset 131 d8fa60488868
parent 128 ce219be2c383
child 136 43e9d618af43
equal deleted inserted replaced
130:5578cb7933c1 131:d8fa60488868
       
     1 #!/usr/bin/perl -w
       
     2 
       
     3 #    Copyright (C) 2011 Matthias Förste
       
     4 #    Copyright (C) 2010, 2011 Heiko Schlittermann
       
     5 #    Copyright (C) 2010 Andre Süß
       
     6 #
       
     7 #    This program is free software: you can redistribute it and/or modify
       
     8 #    it under the terms of the GNU General Public License as published by
       
     9 #    the Free Software Foundation, either version 3 of the License, or
       
    10 #    (at your option) any later version.
       
    11 #
       
    12 #    This program is distributed in the hope that it will be useful,
       
    13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    15 #    GNU General Public License for more details.
       
    16 #
       
    17 #    You should have received a copy of the GNU General Public License
       
    18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
       
    19 #
       
    20 #    Matthias Förste <foerste@schlittermann.de>
       
    21 
       
    22 =encoding utf8
       
    23 =cut
       
    24 
       
    25 use v5.10;
       
    26 use strict;
       
    27 use warnings;
       
    28 
       
    29 use Pod::Usage;
       
    30 use Getopt::Long;
       
    31 use File::Temp;
       
    32 use IO::File;
       
    33 use POSIX qw(strftime);
       
    34 use if $ENV{DEBUG} => "Smart::Comments";
       
    35 use DNStools::Config qw(get_config);
       
    36 use DNStools::UpdateSerial;
       
    37 
       
    38 my %opt;
       
    39 
       
    40 MAIN: {
       
    41 
       
    42     GetOptions(
       
    43         "sign-alert-time=i" => \$opt{sign_alert_time},
       
    44         "key-counter-end=i" => \$opt{key_counter_end},
       
    45         "h|help"            => sub { pod2usage(-exit => 0, -verbose => 1) },
       
    46         "m|man"             => sub {
       
    47             pod2usage(
       
    48                 -exit => 0,
       
    49                 -verbose   => 2,
       
    50                 # "system('perldoc -V &>/dev/null')" appears shorter, but may not
       
    51                 # do what you expect ( it still returns 0 on debian squeeze with
       
    52                 # dash as system shell even if cannot find the command in $PATH)
       
    53                 -noperldoc => system('perldoc -V >/dev/null 2>&1')
       
    54             );
       
    55         }
       
    56     ) or pod2usage;
       
    57 
       
    58     # merge the config and the defined options from commandline
       
    59     my @configs = ( "dnstools.conf", "$ENV{HOME}/.dnstools.conf",
       
    60         "/etc/dnstools.conf");
       
    61     unshift @configs, $ENV{DNSTOOLS_CONF} if defined $ENV{DNSTOOLS_CONF};
       
    62     %config = get_config @configs, \%opt;
       
    63 
       
    64     my @candidates = @ARGV ? zones(@ARGV) : changed_zones;
       
    65     push @candidates, update_index($config{indexzone});
       
    66     push @candidates, signature_expired($config{sign_alert_time});
       
    67 
       
    68     my @need_rollover = need_rollover;
       
    69     my @done_rollover = done_rollover;
       
    70 
       
    71     push @candidates, begin_rollover(@need_rollover);
       
    72     push @candidates, end_rollover(@done_rollover);
       
    73 
       
    74     foreach my $zone (uniq(@candidates)) {
       
    75 #        say "XXX: candidate $zone";
       
    76         update_serial($zone);
       
    77         sign($zone) if dnssec_enabled($zone, "$config{master_dir}/$config{indexzone}/$config{indexzone}");
       
    78 #        say "XXX: $zone should be signed" if dnssec_enabled($zone, "$config{master_dir}/$config{indexzone}/$config{indexzone}");
       
    79     }
       
    80 
       
    81     file_entry;
       
    82     mk_zone_conf($config{bind_dir}, $config{zone_conf_dir});
       
    83     server_reload;
       
    84 
       
    85 }
       
    86 
       
    87 __END__
       
    88 
       
    89 =pod
       
    90 
       
    91 =head1 NAME
       
    92  
       
    93  update-serial - updates the serial numbers and re-signs the zone files
       
    94 
       
    95 =head1 SYNOPSIS
       
    96 
       
    97  update-serial [options] [zone...]
       
    98 
       
    99 =head1 DESCRIPTION
       
   100 
       
   101 B<update-serial> scans the configured directories for modified zone files. On any
       
   102 file found it increments the serial number and signs the zone, if approbiate.
       
   103 
       
   104 =head1 OPTIONS
       
   105 
       
   106 =over
       
   107 
       
   108 =item B<--sign-alert-time> I<days>
       
   109 
       
   110 TODO
       
   111 
       
   112 =item B<--key-counter-end> I<integer>
       
   113 
       
   114 Maximum number if key usages.
       
   115 
       
   116 =back
       
   117 
       
   118 The common options B<-h>|B<--help>|B<-m>|B<--man> are supported.
       
   119 
       
   120 =head1 AUTHORS
       
   121 
       
   122 Matthias Förste L<<foerste@schlittermann.de>>, Heiko Schlittermann L<<hs@schlittermann.de>>, Andre Süss L<<andre.suess@pipkin.cc>>
       
   123 
       
   124 =cut
       
   125 
       
   126 # vim:sts=4 sw=4 aw ai sm: