3 # Delete a master or slave zone
5 require './dns-lib.pl';
8 $zconf = $conf->[$in{'index'}];
9 %access = &get_module_acl();
10 &can_edit_zone(\%access, $zconf->{'values'}->[0]) ||
11 &error("You are not allowed to delete this zone");
13 $rev = $zconf->{'values'}->[0] =~ /in-addr.arpa/i;
14 if (!$in{'confirm'}) {
15 # Ask the user if he is sure ..
16 &header("Delete Zone", "");
19 print "<center><p>Are you sure you want to delete the zone <tt>",
20 &arpa_to_ip($zconf->{'values'}->[0]),"</tt> ? All records ",
21 "and the zone file will be deleted.<p>\n";
22 print "<form action=delete_zone.cgi>\n";
23 print "<input type=hidden name=index value=$in{'index'}>\n";
24 print "<input type=submit name=confirm value='$text{'delete'}'><br>\n";
25 print $rev ? "Delete forward records in other zones ?\n" :
26 "Delete reverse records in other zones ?\n";
27 print "<input type=radio name=rev value=1 checked> $text{'yes'}\n";
28 print "<input type=radio name=rev value=0> $text{'no'}\n";
29 print "</form></center>\n";
31 &footer("", "record types");
35 if (!$rev && $in{'rev'} && $zconf->{'name'} eq 'primary') {
36 # find and delete reverse records
37 &lock_file($zconf->{'values'}->[1]);
38 @recs = &read_zone_file($zconf->{'values'}->[1],
39 $zconf->{'values'}->[0]);
41 next if ($r->{'type'} ne "A");
42 ($orevconf, $orevfile, $orevrec) =
43 &find_reverse($r->{'values'}->[0]);
44 if ($orevrec && &can_edit_reverse($orevconf) &&
45 $r->{'name'} eq $orevrec->{'values'}->[0] &&
46 $r->{'values'}->[0] eq &arpa_to_ip($orevrec->{'name'})) {
47 &lock_file($orevrec->{'file'});
48 &delete_record($orevrec->{'file'} , $orevrec);
49 &lock_file($orevfile);
50 @orrecs = &read_zone_file(
51 $orevfile, $orevconf->{'values'}->[0]);
52 &bump_soa_record($orevfile, \@orrecs);
56 elsif ($rev && $in{'rev'} && $zconf->{'name'} eq 'primary') {
57 # find and delete forward records
58 &lock_file($zconf->{'values'}->[1]);
59 @recs = &read_zone_file($zconf->{'values'}->[1],
60 $zconf->{'values'}->[0]);
62 next if ($r->{'type'} ne "PTR");
63 ($ofwdconf, $ofwdfile, $ofwdrec) =
64 &find_forward($r->{'values'}->[0]);
65 if ($ofwdrec && &can_edit_zone($ofwdconf->{'values'}->[0]) &&
66 &arpa_to_ip($r->{'name'}) eq $ofwdrec->{'values'}->[0] &&
67 $r->{'values'}->[0] eq $ofwdrec->{'name'}) {
68 &lock_file($ofwdrec->{'file'});
69 &delete_record($ofwdrec->{'file'} , $ofwdrec);
70 &lock_file($ofwdfile);
71 @ofrecs = &read_zone_file($ofwdfile,
72 $ofwdconf->{'value'});
73 &bump_soa_record($ofwdfile, \@ofrecs);
78 &lock_file($zconf->{'file'});
80 if ($zconf->{'name'} eq "primary") {
81 &lock_file(&absolute_path($zconf->{'values'}->[1]));
82 unlink(&absolute_path($zconf->{'values'}->[1]));
85 &webmin_log("delete", $zconf->{'name'} eq "primary" ? "master" : "slave",
86 $zconf->{'values'}->[0], \%in);
88 # remove from acl files
89 &read_acl(undef, \%wusers);
90 foreach $u (keys %wusers) {
91 %uaccess = &get_module_acl($u);
92 if ($uaccess{'zones'} ne '*') {
94 join(' ', grep { $_ ne $zconf->{'values'}->[0] }
95 split(/\s+/, $uaccess{'zones'}));
96 &save_module_acl(\%uaccess, $u);
101 # can_edit_reverse(&zone)
104 return $access{'reverse'} || &can_edit_zone(\%access, $_[0]->{'values'}->[0]);