Handle hostnames with upper-case letters
[webmin.git] / bind8 / mass_rcreate.cgi
1 #!/usr/local/bin/perl
2 # Add a record to multiple domains
3
4 require './bind8-lib.pl';
5 &ReadParse();
6 $conf = &get_config();
7 &error_setup($text{'rmass_err'});
8
9 # Get the zones
10 foreach $d (split(/\0/, $in{'d'})) {
11         ($idx, $viewidx) = split(/\s+/, $d);
12         $zone = &get_zone_name($idx, $viewidx);
13         $zone || &error($text{'umass_egone'});
14         &can_edit_zone($zone) ||
15                 &error($text{'master_edelete'});
16         push(@zones, $zone);
17         }
18 $access{'ro'} && &error($text{'master_ero'});
19
20 # Validate inputs
21 &valdnsname($in{'name'}) || $in{'name'} eq '@' || &error($text{'rmass_ename'});
22 $in{'name'} =~ /\.$/ && &error($text{'rmass_ename2'});
23 if ($in{'type'} eq 'A') {
24         &check_ipaddress($in{'value'}) ||
25                 &error(&text('edit_eip', $in{'value'}));
26         }
27 elsif ($in{'type'} eq 'AAAA') {
28         &check_ip6address($in{'value'}) ||
29                 &error(&text('edit_eip6', $in{'value'}));
30         }
31 elsif ($in{'type'} eq 'NS') {
32         &valname($in{'value'}) ||
33                 &error(&text('edit_ens', $in{'value'}));
34         }
35 elsif ($in{'type'} eq 'CNAME') {
36         &valname($in{'value'}) || $in{'value'} eq '@' ||
37                 &error(&text('edit_ecname', $in{'value'}));
38         }
39 elsif ($in{'type'} eq 'MX') {
40         $in{'value'} =~ /^(\d+)\s+(\S+)$/ && &valname("$2") ||
41                 &error(&text('emass_emx', $in{'value'}));
42         }
43 elsif ($in{'type'} eq 'TXT') {
44         $in{'value'} = "\"$in{'value'}\"";
45         }
46 elsif ($in{'type'} eq 'PTR') {
47         &valname($in{'value'}) ||
48                 &error(&text('edit_eptr', $in{'value'}));
49         }
50 $in{'ttl_def'} || $in{'ttl'} =~ /^\d+$/ ||
51         &error($text{'rmass_ettl'});
52
53 # Do each one
54 &ui_print_unbuffered_header(undef, $text{'rmass_title'}, "");
55
56 foreach $zi (@zones) {
57         print &text('rmass_doing', "<tt>$zi->{'name'}</tt>"),"<br>\n";
58         if ($zi->{'type'} ne 'master') {
59                 # Skip - not a master zone
60                 print $text{'umass_notmaster'},"<p>\n";
61                 next;
62                 }
63         $fullname = $in{'name'} eq '@' ?
64                         $zi->{'name'}."." :
65                         $in{'name'}.".".$zi->{'name'}.".";
66         @recs = &read_zone_file($zi->{'file'}, $zi->{'name'});
67         if ($in{'type'} eq 'CNAME' || $in{'clash'}) {
68                 # Check if a record with the same name exists
69                 ($clash) = grep { $_->{'name'} eq $fullname &&
70                                   $_->{'type'} eq $in{'type'} } @recs;
71                 if ($clash) {
72                         print &text('rmass_eclash',
73                             "<tt>".join(" ", @{$clash->{'values'}})."</tt>"),
74                             "<p>\n";
75                         next;
76                         }
77                 }
78         # Check if a record with the same name and value exists
79         ($clash) = grep { $_->{'name'} eq $fullname &&
80                           $_->{'type'} eq $in{'type'} &&
81                           join(" ", @{$_->{'values'}}) eq $in{'value'} } @recs;
82         if ($clash) {
83                 print &text('rmass_eclash2',
84                     "<tt>".join(" ", @{$clash->{'values'}})."</tt>"),"<p>\n";
85                 next;
86                 }
87         &create_record($zi->{'file'}, $in{'name'}, $in{'ttl'}, "IN",
88                        $in{'type'}, $in{'value'});
89         &bump_soa_record($zi->{'file'}, \@recs);
90         &sign_dnssec_zone_if_key($zi, \@recs);
91         print $text{'rmass_done'},"<p>\n";
92         }
93
94 &unlock_all_files();
95 &webmin_log("rcreate", "zones", scalar(@zones));
96
97 &ui_print_footer("", $text{'index_return'});
98
99 # valname(name)
100 sub valname
101 {
102 return valdnsname($_[0], 0, $in{'origin'});
103 }
104