Handle hostnames with upper-case letters
[webmin.git] / bind8 / delete_recs.cgi
1 #!/usr/local/bin/perl
2 # Delete multiple records from a zone file
3
4 require './bind8-lib.pl';
5 &ReadParse();
6 &error_setup($text{'drecs_err'});
7 $zone = &get_zone_name($in{'index'}, $in{'view'});
8 $dom = $zone->{'name'};
9 &can_edit_zone($zone) ||
10         &error($text{'recs_ecannot'});
11 &can_edit_type($in{'type'}, \%access) ||
12         &error($text{'recs_ecannottype'});
13
14 # Find the records
15 @d = split(/\0/, $in{'d'});
16 @d || &error($text{'drecs_enone'});
17
18 # Check if confirmation is needed
19 if (!$in{'confirm'} && $config{'confirm_rec'}) {
20         # Ask first
21         &ui_print_header(undef, $text{'drecs_title'}, "");
22
23         print &ui_confirmation_form("delete_recs.cgi",
24                 &text('drecs_rusure', scalar(@d), $dom),
25                 [ [ 'index', $in{'index'} ],
26                   [ 'view', $in{'view'} ],
27                   [ 'rev', $in{'rev'} ],
28                   map { [ 'd', $_ ] } @d ],
29                 [ [ 'confirm', $text{'drecs_ok'} ] ],
30                 );
31
32         &ui_print_footer("edit_recs.cgi?index=$in{'index'}&view=$in{'view'}&type=$in{'type'}&sort=$in{'sort'}", $text{'recs_return'});
33         }
34 else {
35         # Delete them
36         @recs = &read_zone_file($zone->{'file'}, $dom);
37
38         foreach $d (sort { $b <=> $a } @d) {
39                 ($num, $id) = split(/\//, $d, 2);
40                 $r = &find_record_by_id(\@recs, $id, $num);
41                 next if (!$r);
42                 if ($in{'rev'}) {
43                         # Find the reverse
44                         $fulloldvalue0 = &convert_to_absolute(
45                                                 $r->{'values'}->[0], $dom);
46                         $fulloldname = &convert_to_absolute(
47                                                 $r->{'name'}, $dom);
48                         ($orevconf, $orevfile, $orevrec) = &find_reverse(
49                                         $r->{'values'}->[0], $in{'view'});
50
51                         if ($orevrec && &can_edit_reverse($orevconf) &&
52                             $fulloldname eq $orevrec->{'values'}->[0] &&
53                             ($r->{'type'} eq "A" &&
54                              $r->{'values'}->[0] eq &arpa_to_ip($orevrec->{'name'}) ||
55                              $r->{'type'} eq "AAAA" &&
56                              &expandall_ip6($r->{'values'}->[0]) eq &expandall_ip6(&ip6int_to_net($orevrec->{'name'})))) {
57                                 &lock_file(&make_chroot($orevrec->{'file'}));
58                                 &delete_record($orevrec->{'file'} , $orevrec);
59                                 &lock_file(&make_chroot($orevfile));
60                                 @orrecs = &read_zone_file($orevfile, $orevconf->{'name'});
61                                 if (!$bumpedrev{$orevfile}++) {
62                                         &bump_soa_record($orevfile, \@orrecs);
63                                         }
64                                 &sign_dnssec_zone_if_key($orevconf, \@orrecs);
65                                 }
66                         }
67
68                 # Delete the actual record
69                 &lock_file(&make_chroot($r->{'file'}));
70                 &delete_record($r->{'file'}, $r);
71                 splice(@recs, $d, 1);
72                 }
73         &bump_soa_record($zone->{'file'}, \@recs);
74         &sign_dnssec_zone_if_key($zone, \@recs);
75         &unlock_all_files();
76
77         &webmin_log("delete", "recs", scalar(@d));
78         &redirect("edit_recs.cgi?index=$in{'index'}&view=$in{'view'}&type=$in{'type'}&sort=$in{'sort'}");
79         }
80
81