Handle hostnames with upper-case letters
[webmin.git] / bind8 / save_acls.cgi
1 #!/usr/local/bin/perl
2 # save_acls.cgi
3 # Update all the acl directives
4
5 require './bind8-lib.pl';
6 $access{'defaults'} || &error($text{'acls_ecannot'});
7 &error_setup($text{'acls_err'});
8 &ReadParse();
9
10 # Convert inputs into ACL structures
11 %depmap = ( );
12 &lock_file(&make_chroot($config{'named_conf'}));
13 $conf = &get_config();
14 for($i=0; defined($name = $in{"name_$i"}); $i++) {
15         next if (!$name);
16         $name =~ /^\S+$/ && $name !~ /;/ || &error(&text('acls_ename', $name));
17         $in{"values_$i"} =~ s/\r//g;
18         @vals = split(/\n+/, $in{"values_$i"});
19         foreach $v (@vals) {
20                 if ($v =~ /^[0-9\.]+\s+\S/ && $v !~ /;/) {
21                         &error(&text('acls_eline', $name));
22                         }
23                 }
24         push(@acls, { 'name' => 'acl',
25                       'values' => [ $name ],
26                       'type' => 1,
27                       'members' => [ map { my ($n, @w)=split(/\s+/, $_);
28                                            { 'name' => $n,
29                                              'values' => \@w } } @vals ] });
30
31         # Record this ACL as a dependency of some ACL it refers to
32         foreach (@vals) {
33                 my ($n, @w)=split(/\s+/, $_);
34                 if ($n !~ /^[0-9\.]+$/) {
35                         push(@{$depmap{$n}}, $name);
36                         }
37                 }
38         }
39
40 # Sort the list so that depended-on ACLs come first
41 @acls = sort { my $an = $a->{'values'}->[0];
42                my $bn = $b->{'values'}->[0];
43                &indexof($an, @{$depmap{$bn}}) >= 0 ? 1 :
44                &indexof($bn, @{$depmap{$an}}) >= 0 ? -1 : 0 } @acls;
45
46 &save_directive(&get_config_parent(), 'acl', \@acls, 0, 0, 1);
47 &flush_file_lines();
48 &unlock_file(&make_chroot($config{'named_conf'}));
49 &webmin_log("acls", undef, undef, \%in);
50 &redirect("");
51