Handle hostnames with upper-case letters
[webmin.git] / bind8 / save_trusted.cgi
1 #!/usr/local/bin/perl
2 # Save DNSSEC verification options
3
4 require './bind8-lib.pl';
5 $access{'defaults'} || &error($text{'trusted_ecannot'});
6 &error_setup($text{'trusted_err'});
7 &ReadParse();
8
9 &lock_file(&make_chroot($config{'named_conf'}));
10 $parent = &get_config_parent();
11 $conf = $parent->{'members'};
12 $options = &find("options", $conf);
13
14 # DNSSEC enabled
15 &save_choice("dnssec-enable", $options, 1);
16 if (&supports_dnssec_client() == 2) {
17         &save_choice("dnssec-validation", $options, 1);
18         }
19
20 # Save DLV zones
21 @dlvs = ( );
22 for($i=0; defined($in{"anchor_$i"}); $i++) {
23         if (!$in{"anchor_${i}_def"}) {
24                 $in{"anchor_$i"} =~ /^[a-z0-9\.\-\_]+$/ ||
25                         &error(&text('trusted_eanchor', $i+1));
26                 $in{"anchor_$i"} .= "." if ($in{"anchor_$i"} !~ /\.$/);
27                 if ($in{"dlv_${i}_def"}) {
28                         $dlv = ".";
29                         }
30                 else {
31                         $in{"dlv_$i"} =~ /^[a-z0-9\.\-\_]+$/ ||
32                                 &error(&text('trusted_edlv', $i+1));
33                         $dlv = $in{"dlv_$i"};
34                         $dlv .= "." if ($dlv !~ /\.$/);
35                         }
36                 push(@dlvs, { 'name' => 'dnssec-lookaside',
37                               'values' => [ $dlv, "trust-anchor",
38                                             $in{"anchor_$i"} ] });
39                 }
40         }
41 &save_directive($options, "dnssec-lookaside", \@dlvs, 1);
42
43 # Save trusted keys
44 @keys = ( );
45 $trusted = &find("trusted-keys", $conf);
46 if (!$trusted) {
47         # Need to create block
48         $trusted = { 'name' => 'trusted-keys',
49                      'type' => 1,
50                      'members' => [ ] };
51         &save_directive($parent, "trusted-keys", [ $trusted ]);
52         }
53 for($i=0; defined($in{"zone_$i"}); $i++) {
54         next if ($in{"zone_${i}_def"});
55         $in{"zone_$i"} =~ /^[a-z0-9\.\-\_]+$/ ||
56                 &error(&text('trusted_ezone', $i+1));
57         $in{"zone_$i"} .= "." if ($in{"zone_$i"} !~ /\.$/);
58         $in{"flags_$i"} =~ /^\d+$/ ||
59                 &error(&text('trusted_eflags', $i+1));
60         $in{"proto_$i"} =~ /^\d+$/ ||
61                 &error(&text('trusted_eproto', $i+1));
62         $in{"alg_$i"} =~ /^\d+$/ ||
63                 &error(&text('trusted_ealg', $i+1));
64         $in{"key_$i"} =~ s/\s//g;
65         $in{"key_$i"} || &error(&text('trusted_ekey', $i+1));
66         push(@keys, { 'name' => $in{"zone_$i"},
67                       'values' => [ $in{"flags_$i"}, $in{"proto_$i"},
68                                     $in{"alg_$i"}, '"'.$in{"key_$i"}.'"' ],
69                     });
70         }
71 @oldkeys = @{$trusted->{'members'}};
72 &save_directive($trusted, \@oldkeys, \@keys, 1);
73
74 &flush_file_lines();
75 &unlock_file(&make_chroot($config{'named_conf'}));
76 &webmin_log("trusted");
77 &redirect("");
78