3 use v5.10; |
3 use v5.10; |
4 use strict; |
4 use strict; |
5 use warnings; |
5 use warnings; |
6 use FindBin; |
6 use FindBin; |
7 use File::Basename; |
7 use File::Basename; |
8 |
8 use Pod::Usage; |
9 sub uniq { |
9 use Getopt::Long; |
|
10 |
|
11 sub uniq(@); |
|
12 sub read_conf(@); |
|
13 sub add_argv; |
|
14 sub changed_zone; |
|
15 sub sign_end; |
|
16 sub sign_zone; |
|
17 sub update_serial; |
|
18 sub mk_zone_conf; |
|
19 sub update_index; |
|
20 sub file_entry; |
|
21 sub server_reload; |
|
22 sub to_begin_ro; |
|
23 sub to_end_ro; |
|
24 sub begin_ro; |
|
25 sub key_to_zonefile; |
|
26 sub kill_useless_keys; |
|
27 sub end_ro; |
|
28 |
|
29 my %config; |
|
30 |
|
31 MAIN: { |
|
32 |
|
33 GetOptions( |
|
34 "h|help" => sub { pod2usage(-exit 0, -verbose => 1) }, |
|
35 "m|man" => sub { |
|
36 pod2usage( |
|
37 -exit 0, |
|
38 -verbose => 2, |
|
39 -noperldoc => system("perldoc -v &>/dev/null") |
|
40 ); |
|
41 }, |
|
42 ) or pod2usage; |
|
43 |
|
44 %config = read_conf("$FindBin::Bin/dnstools.conf", "/etc/dnstools.conf"); |
|
45 |
|
46 our @new_serial; # liste fuer neuen serial |
|
47 our @begin_ro_list; # liste mit zonen deren key-rollover beginnt |
|
48 our @end_ro_list; # liste mit zonen deren key-rollover fertig ist |
|
49 our $master_dir = $config{master_dir}; |
|
50 our $bind_dir = $config{bind_dir}; |
|
51 our $conf_dir = $config{zone_conf_dir}; |
|
52 our $sign_alert_time = $config{sign_alert_time}; |
|
53 our $indexzone = $config{indexzone}; |
|
54 our $key_counter_end = $config{key_counter_end}; |
|
55 our $ablauf_zeit = $config{abl_zeit}; |
|
56 |
|
57 add_argv; |
|
58 changed_zone; |
|
59 sign_end; |
|
60 |
|
61 to_begin_ro; # prueft nach beginnenden rollover-verfahren |
|
62 to_end_ro; # prueft nach endenden rollover-verfahren |
|
63 |
|
64 if (@begin_ro_list) { |
|
65 begin_ro; # eine rollover-beginn-sequenz |
|
66 } |
|
67 |
|
68 if (@end_ro_list) { |
|
69 end_ro; # eine rollover-end-squenz |
|
70 } |
|
71 |
|
72 if (@new_serial) { |
|
73 update_index; # index zone aktuallisieren |
|
74 update_serial; # serial aktuallisieren |
|
75 sign_zone; # zone signieren |
|
76 } |
|
77 |
|
78 file_entry; # bearbeitet die file-eintraege der konfigurations-datei |
|
79 mk_zone_conf; # konfiguration zusammenfuegen |
|
80 server_reload; # server neu laden |
|
81 |
|
82 } |
|
83 |
|
84 sub uniq(@) { |
10 my %all; |
85 my %all; |
11 @all{@_} = (); |
86 @all{@_} = (); |
12 keys %all; |
87 keys %all; |
13 } |
88 } |
14 |
89 |
15 sub read_conf { |
90 sub read_conf(@) { |
16 |
91 my @configs = @_; |
17 # liest die Konfiguration ein |
92 my %config; |
18 my @configs = ("$FindBin::Bin/dnstools.conf", "/etc/dnstools.conf"); |
93 |
19 our %config; |
94 my ($config) = grep { -f } @configs |
20 |
95 or die "No config found (looked at @configs)\n"; |
21 for (grep { -f } @configs) { |
96 |
22 open(CONFIG, $_) or die "Can't open $_: $!\n"; |
97 open(my $fh => $config) or die "$config: $!\n"; |
23 } |
98 |
24 unless (seek(CONFIG, 0, 0)) { |
99 while (<$fh>) { |
25 die "Can't open config (searched: @configs)\n"; |
|
26 } |
|
27 while (<CONFIG>) { |
|
28 chomp; |
100 chomp; |
29 s/#.*//; |
101 s/#.*//; |
30 s/\t//g; |
|
31 s/\s//g; |
102 s/\s//g; |
32 |
103 my ($k, $v) = split(/\s*=\s*/, $_, 2) or next; |
33 next unless length; |
104 $config{$k} = $v; |
34 my ($cname, $ccont) = split(/\s*=\s*/, $_, 2); |
105 } |
35 $config{$cname} = $ccont; |
106 |
36 } |
107 return %config; |
37 close(CONFIG); |
|
38 } |
108 } |
39 |
109 |
40 sub add_argv { |
110 sub add_argv { |
41 |
111 |
42 # prueft ob zonen aus ARGV verwaltete zonen sind |
112 # prueft ob zonen aus ARGV verwaltete zonen sind |
522 &key_to_zonefile($zone); |
592 &key_to_zonefile($zone); |
523 push @new_serial, $zone; |
593 push @new_serial, $zone; |
524 } |
594 } |
525 } |
595 } |
526 |
596 |
527 MAIN: { |
597 __END__ |
528 |
598 |
529 read_conf; |
599 =head1 NAME |
530 |
600 |
531 our %config; |
601 update-serial - updates the serial numbers and re-signs the zone files |
532 our @new_serial; # liste fuer neuen serial |
602 |
533 our @begin_ro_list; # liste mit zonen deren key-rollover beginnt |
603 =head1 SYNOPSIS |
534 our @end_ro_list; # liste mit zonen deren key-rollover fertig ist |
604 |
535 our $master_dir = $config{master_dir}; |
605 update-serial [zone...] |
536 our $bind_dir = $config{bind_dir}; |
606 |
537 our $conf_dir = $config{zone_conf_dir}; |
607 =head1 DESCRIPTION |
538 our $sign_alert_time = $config{sign_alert_time}; |
608 |
539 our $indexzone = $config{indexzone}; |
609 B<update-serial> scans the configured directories for modified zone files. On any |
540 our $key_counter_end = $config{key_counter_end}; |
610 file found it increments the serial number and signs the zone, if approbiate. |
541 our $ablauf_zeit = $config{abl_zeit}; |
611 |
542 |
612 =head1 OPTIONS |
543 add_argv; |
613 |
544 changed_zone; |
614 The common options B<-h>|B<--help>|B<-m>|B<--man> are supported. |
545 sign_end; |
615 |
546 |
616 =head1 AUTHOR |
547 to_begin_ro; # prueft nach beginnenden rollover-verfahren |
617 |
548 to_end_ro; # prueft nach endenden rollover-verfahren |
618 L<andre.suess@pipkin.cc> |
549 |
619 |
550 if (@begin_ro_list) { |
620 =cut |
551 begin_ro; # eine rollover-beginn-sequenz |
621 |
552 } |
622 # vim:sts=4 sw=4 aw ai sm: |
553 |
|
554 if (@end_ro_list) { |
|
555 end_ro; # eine rollover-end-squenz |
|
556 } |
|
557 |
|
558 if (@new_serial) { |
|
559 update_index; # index zone aktuallisieren |
|
560 update_serial; # serial aktuallisieren |
|
561 sign_zone; # zone signieren |
|
562 } |
|
563 |
|
564 file_entry; # bearbeitet die file-eintraege der konfigurations-datei |
|
565 mk_zone_conf; # konfiguration zusammenfuegen |
|
566 server_reload; # server neu laden |
|
567 |
|
568 } |
|