--- a/update-serial.pl Tue Dec 21 16:37:27 2010 +0100
+++ b/update-serial.pl Tue Dec 21 16:58:25 2010 +0100
@@ -5,36 +5,106 @@
use warnings;
use FindBin;
use File::Basename;
+use Pod::Usage;
+use Getopt::Long;
-sub uniq {
+sub uniq(@);
+sub read_conf(@);
+sub add_argv;
+sub changed_zone;
+sub sign_end;
+sub sign_zone;
+sub update_serial;
+sub mk_zone_conf;
+sub update_index;
+sub file_entry;
+sub server_reload;
+sub to_begin_ro;
+sub to_end_ro;
+sub begin_ro;
+sub key_to_zonefile;
+sub kill_useless_keys;
+sub end_ro;
+
+my %config;
+
+MAIN: {
+
+ GetOptions(
+ "h|help" => sub { pod2usage(-exit 0, -verbose => 1) },
+ "m|man" => sub {
+ pod2usage(
+ -exit 0,
+ -verbose => 2,
+ -noperldoc => system("perldoc -v &>/dev/null")
+ );
+ },
+ ) or pod2usage;
+
+ %config = read_conf("$FindBin::Bin/dnstools.conf", "/etc/dnstools.conf");
+
+ our @new_serial; # liste fuer neuen serial
+ our @begin_ro_list; # liste mit zonen deren key-rollover beginnt
+ our @end_ro_list; # liste mit zonen deren key-rollover fertig ist
+ our $master_dir = $config{master_dir};
+ our $bind_dir = $config{bind_dir};
+ our $conf_dir = $config{zone_conf_dir};
+ our $sign_alert_time = $config{sign_alert_time};
+ our $indexzone = $config{indexzone};
+ our $key_counter_end = $config{key_counter_end};
+ our $ablauf_zeit = $config{abl_zeit};
+
+ add_argv;
+ changed_zone;
+ sign_end;
+
+ to_begin_ro; # prueft nach beginnenden rollover-verfahren
+ to_end_ro; # prueft nach endenden rollover-verfahren
+
+ if (@begin_ro_list) {
+ begin_ro; # eine rollover-beginn-sequenz
+ }
+
+ if (@end_ro_list) {
+ end_ro; # eine rollover-end-squenz
+ }
+
+ if (@new_serial) {
+ update_index; # index zone aktuallisieren
+ update_serial; # serial aktuallisieren
+ sign_zone; # zone signieren
+ }
+
+ file_entry; # bearbeitet die file-eintraege der konfigurations-datei
+ mk_zone_conf; # konfiguration zusammenfuegen
+ server_reload; # server neu laden
+
+}
+
+sub uniq(@) {
my %all;
@all{@_} = ();
keys %all;
}
-sub read_conf {
-
- # liest die Konfiguration ein
- my @configs = ("$FindBin::Bin/dnstools.conf", "/etc/dnstools.conf");
- our %config;
+sub read_conf(@) {
+ my @configs = @_;
+ my %config;
- for (grep { -f } @configs) {
- open(CONFIG, $_) or die "Can't open $_: $!\n";
- }
- unless (seek(CONFIG, 0, 0)) {
- die "Can't open config (searched: @configs)\n";
- }
- while (<CONFIG>) {
+ my ($config) = grep { -f } @configs
+ or die "No config found (looked at @configs)\n";
+
+ open(my $fh => $config) or die "$config: $!\n";
+
+ while (<$fh>) {
chomp;
s/#.*//;
- s/\t//g;
s/\s//g;
+ my ($k, $v) = split(/\s*=\s*/, $_, 2) or next;
+ $config{$k} = $v;
+ }
- next unless length;
- my ($cname, $ccont) = split(/\s*=\s*/, $_, 2);
- $config{$cname} = $ccont;
- }
- close(CONFIG);
+ return %config;
}
sub add_argv {
@@ -524,45 +594,29 @@
}
}
-MAIN: {
+__END__
- read_conf;
+=head1 NAME
+
+ update-serial - updates the serial numbers and re-signs the zone files
- our %config;
- our @new_serial; # liste fuer neuen serial
- our @begin_ro_list; # liste mit zonen deren key-rollover beginnt
- our @end_ro_list; # liste mit zonen deren key-rollover fertig ist
- our $master_dir = $config{master_dir};
- our $bind_dir = $config{bind_dir};
- our $conf_dir = $config{zone_conf_dir};
- our $sign_alert_time = $config{sign_alert_time};
- our $indexzone = $config{indexzone};
- our $key_counter_end = $config{key_counter_end};
- our $ablauf_zeit = $config{abl_zeit};
+=head1 SYNOPSIS
- add_argv;
- changed_zone;
- sign_end;
+ update-serial [zone...]
+
+=head1 DESCRIPTION
- to_begin_ro; # prueft nach beginnenden rollover-verfahren
- to_end_ro; # prueft nach endenden rollover-verfahren
+B<update-serial> scans the configured directories for modified zone files. On any
+file found it increments the serial number and signs the zone, if approbiate.
- if (@begin_ro_list) {
- begin_ro; # eine rollover-beginn-sequenz
- }
+=head1 OPTIONS
- if (@end_ro_list) {
- end_ro; # eine rollover-end-squenz
- }
+The common options B<-h>|B<--help>|B<-m>|B<--man> are supported.
- if (@new_serial) {
- update_index; # index zone aktuallisieren
- update_serial; # serial aktuallisieren
- sign_zone; # zone signieren
- }
+=head1 AUTHOR
+
+L<andre.suess@pipkin.cc>
- file_entry; # bearbeitet die file-eintraege der konfigurations-datei
- mk_zone_conf; # konfiguration zusammenfuegen
- server_reload; # server neu laden
+=cut
-}
+# vim:sts=4 sw=4 aw ai sm: