Handle hostnames with upper-case letters
[webmin.git] / dnsadmin / create_slave.cgi
1 #!/usr/local/bin/perl
2 # create_slave.cgi
3 # Create a new slave zone
4
5 require './dns-lib.pl';
6 &ReadParse();
7 $whatfailed = "Failed to create slave zone";
8 %access = &get_module_acl();
9 $access{'slave'} || &error("You are not allowed to create slave zones");
10
11 # validate inputs
12 if ($in{'rev'}) {
13         $in{'zone'} =~ /^[\d\.]+$/ ||
14                 &error("'$in{'zone'}' is not a valid network");
15         $in{'zone'} = &ip_to_arpa($in{'zone'});
16         }
17 else {
18         $in{'zone'} =~ /^[A-z0-9\-\.]+$/ ||
19                 &error("'$in{'zone'}' is not a valid domain name");
20         }
21 $in{'zone'} =~ s/\.$//g;
22 @masters = split(/\s+/, $in{'masters'});
23 foreach $m (@masters) {
24         &check_ipaddress($m) ||
25                 &error("'$m' is not a valid master server address");
26         }
27 if (!@masters) {
28         &error("You must enter at least one master server");
29         }
30 $base = $access{'dir'} eq '/' ? &base_directory($conf) : $access{'dir'};
31 if ($in{'file_def'} == 0) {
32         $in{'file'} =~ /^\S+$/ ||
33                 &error("'$in{'file'}' is not a valid filename");
34         if ($in{'file'} !~ /^\//) {
35                 $file = $base."/".$in{'file'};
36                 }
37         else { $file = $in{'file'}; }
38         &allowed_zone_file(\%access, $file) ||
39                 &error("'$file' is not an allowable zone file");
40         if (!-r $file) {
41                 &lock_file($file);
42                 open(ZONE, "> $file") ||
43                         &error("Failed to create '$file' : $?");
44                 close(ZONE);
45                 &unlock_file($file);
46                 }
47         }
48 elsif ($in{'file_def'} == 2) {
49         if ($in{'rev'}) {
50                 $file = $base."/".&arpa_to_ip($in{'zone'}).".rev";
51                 }
52         else {
53                 $file = $base."/".$in{'zone'}.".hosts";
54                 }
55         }
56
57
58 @vals = ($in{'zone'}, @masters);
59 if ($file) { push(@vals, $file); }
60 &lock_file($config{'named_boot_file'});
61 &create_zone({ 'name' => 'secondary', 'values' => \@vals });
62 &unlock_file($config{'named_boot_file'});
63 &webmin_log("create", "slave", $in{'zone'}, \%in);
64
65 # Add the new zone to the access list
66 if ($access{'zones'} ne '*') {
67         $access{'zones'} .= " ".$in{'zone'};
68         &save_module_acl(\%access);
69         }
70 &redirect("");
71