Handle hostnames with upper-case letters
[webmin.git] / bind8 / save_controls.cgi
1 #!/usr/local/bin/perl
2 # Save control interface options
3
4 require './bind8-lib.pl';
5 $access{'defaults'} || &error($text{'controls_ecannot'});
6 &error_setup($text{'controls_err'});
7 &ReadParse();
8
9 # Validate and store inputs
10 &lock_file(&make_chroot($config{'named_conf'}));
11 $parent = &get_config_parent();
12 $conf = &get_config();
13 $controls = &find("controls", $conf);
14 if (!$controls) {
15         $controls = { 'name' => 'controls', 'type' => 1 };
16         &save_directive($parent, "controls", [ $controls ]);
17         }
18 $inet = &find("inet", $controls->{'members'});
19 $unix = &find("unix", $controls->{'members'});
20
21 # Save inet control options
22 if ($in{'inet'}) {
23         $inet ||= { 'name' => 'inet', 'type' => 2 };
24         &check_ipaddress($in{'ip'}) || &error($text{'controls_einetip'});
25         $in{'port'} =~ /^\d+$/ && $in{'port'} > 0 && $in{'port'} < 65536 ||
26                 &error($text{'controls_einetport'});
27         $inet->{'values'} = [ $in{'ip'}, "port", $in{'port'} ];
28         @allow = split(/\s+/, $in{'allow'});
29         foreach $a (@allow) {
30                 &check_ipaddress($a) ||
31                         &error(&text('controls_einetallow', $a));
32                 }
33         @allow || &error($text{'controls_einetallows'});
34         $inet->{'members'}->{'allow'} =
35                 [ map { { 'name' => $_ } } @allow ];
36         @keys = split(/\s+/, $in{'keys'});
37         if (@keys) {
38                 $inet->{'members'}->{'keys'} = 
39                         [ map { { 'name' => $_ } } @keys ];
40                 }
41         else {
42                 delete($inet->{'members'}->{'keys'});
43                 }
44         &save_directive($controls, "inet", [ $inet ], 1);
45         }
46 else {
47         &save_directive($controls, "inet", [ ], 1);
48         }
49
50 # Save local control options
51 if ($in{'unix'}) {
52         $unix ||= { 'name' => 'unix', 'type' => 0 };
53         $in{'path'} =~ /^\/\S+$/ || &error($text{'controls_eunixpath'});
54         $in{'perm'} =~ /^[0-7]{3,4}$/ || &error($text{'controls_eunixperm'});
55         $owner = getpwnam($in{'owner'});
56         defined($owner) || &error($text{'controls_eunixowner'});
57         $group = getgrnam($in{'group'});
58         defined($group) || &error($text{'controls_eunixgroup'});
59         $unix->{'values'} = [ $in{'path'}, "perm", $in{'perm'},
60                               "owner", $owner, "group", $group ];
61         &save_directive($controls, "unix", [ $unix ], 1);
62         }
63 else {
64         &save_directive($controls, "unix", [ ], 1);
65         }
66
67 &flush_file_lines();
68 &unlock_file(&make_chroot($config{'named_conf'}));
69 &webmin_log("controls", undef, undef, \%in);
70 &redirect("");
71