Changeset 934 for branches/secondaryzones/DNSDB.pm
- Timestamp:
- 08/28/25 15:55:24 (9 days ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/secondaryzones/DNSDB.pm
r932 r934 3077 3077 ## DNSDB::delZone() 3078 3078 # Delete a forward or reverse zone. 3079 # Takes a database handle, zone ID, and forward/reverseflag.3079 # Takes a database handle, zone ID, forward/reverse flag, and optional secondary flag. 3080 3080 # for now, just delete the records, then the domain. 3081 3081 # later we may want to archive it in some way instead (status code 2, for example?) … … 3083 3083 my $self = shift; 3084 3084 my $dbh = $self->{dbh}; 3085 3085 3086 my $zoneid = shift; 3086 3087 my $revrec = shift; 3088 my $secondary = shift || 'n'; 3087 3089 3088 3090 # Allow transactions, and raise an exception on errors so we can catch it later. … … 3092 3094 3093 3095 return ('FAIL', 'Need a zone identifier to look up') if !$zoneid; 3096 return ('FAIL', 'Reverse zone flag missing') if !$revrec; 3094 3097 3095 3098 my $msg = ''; 3096 3099 my $failmsg = ''; 3097 my $zone = ($revrec eq 'n' ? $self->domainName($zoneid) : $self->revName($zoneid)); 3098 my $zonestatus = $self->zoneStatus(zoneid => $zoneid, revrec => $revrec); 3099 3100 return ('FAIL', ($revrec eq 'n' ? 'Domain' : 'Reverse zone')." ID $zoneid doesn't exist") if !$zone; 3100 my $zone = ($secondary eq 'n' ? ($revrec eq 'n' ? $self->domainName($zoneid) : $self->revName($zoneid)) : $self->secondaryName($zoneid)); 3101 my $zonestatus = $self->zoneStatus(zoneid => $zoneid, revrec => $revrec, secondary => $secondary); 3102 3103 return ('FAIL', ($secondary eq 'n' ? ($revrec eq 'n' ? 'Domain' : 'Reverse zone') : 'Secondary zone')." ID $zoneid doesn't exist") 3104 if !$zone; 3101 3105 3102 3106 # Set this up here since we may use if if $self->{log_failures} is enabled 3103 3107 my %loghash; 3104 $loghash{domain_id} = $zoneid if $revrec eq 'n'; 3105 $loghash{rdns_id} = $zoneid if $revrec eq 'y'; 3108 if ($secondary eq 'n') { 3109 $loghash{domain_id} = $zoneid if $revrec eq 'n'; 3110 $loghash{rdns_id} = $zoneid if $revrec eq 'y'; 3111 } else { 3112 $loghash{secondary_id} = $zoneid; 3113 } 3114 3106 3115 $loghash{group_id} = $self->parentID( 3107 id => $zoneid, type => ($ revrec eq 'n' ? 'domain' : 'revzone'), revrec => $revrec);3116 id => $zoneid, type => ($secondary eq 'n' ? ($revrec eq 'n' ? 'domain' : 'revzone') : 'secondaryzone'), revrec => $revrec); 3108 3117 3109 3118 # Wrap all the SQL in a transaction … … 3111 3120 # Disentangle custom record types before removing the 3112 3121 # ones that are only in the zone to be deleted 3113 if ($revrec eq 'n') { 3114 my $sth = $dbh->prepare("UPDATE records SET type=?,domain_id=0 WHERE domain_id=? AND type=?"); 3115 $failmsg = "Failure converting multizone types to single-zone"; 3116 $sth->execute($reverse_typemap{PTR}, $zoneid, 65280); 3117 $sth->execute($reverse_typemap{PTR}, $zoneid, 65281); 3118 $sth->execute(65282, $zoneid, 65283); 3119 $sth->execute(65282, $zoneid, 65284); 3120 $failmsg = "Failure removing domain records"; 3121 $dbh->do("DELETE FROM records WHERE domain_id=?", undef, ($zoneid)); 3122 $failmsg = "Failure removing domain"; 3123 $dbh->do("DELETE FROM domains WHERE domain_id=?", undef, ($zoneid)); 3122 if ($secondary eq 'n') { 3123 if ($revrec eq 'n') { 3124 my $sth = $dbh->prepare("UPDATE records SET type=?,domain_id=0 WHERE domain_id=? AND type=?"); 3125 $failmsg = "Failure converting multizone types to single-zone"; 3126 $sth->execute($reverse_typemap{PTR}, $zoneid, 65280); 3127 $sth->execute($reverse_typemap{PTR}, $zoneid, 65281); 3128 $sth->execute(65282, $zoneid, 65283); 3129 $sth->execute(65282, $zoneid, 65284); 3130 $failmsg = "Failure removing domain records"; 3131 $dbh->do("DELETE FROM records WHERE domain_id=?", undef, ($zoneid)); 3132 $failmsg = "Failure removing domain"; 3133 $dbh->do("DELETE FROM domains WHERE domain_id=?", undef, ($zoneid)); 3134 } else { 3135 my $sth = $dbh->prepare("UPDATE records SET type=?,rdns_id=0 WHERE rdns_id=? AND type=?"); 3136 $failmsg = "Failure converting multizone types to single-zone"; 3137 $sth->execute($reverse_typemap{A}, $zoneid, 65280); 3138 $sth->execute($reverse_typemap{AAAA}, $zoneid, 65281); 3139 # We don't have an "A template" or "AAAA template" type, although it might be useful for symmetry. 3140 # $sth->execute(65286?, $zoneid, 65283); 3141 # $sth->execute(65286?, $zoneid, 65284); 3142 $failmsg = "Failure removing reverse records"; 3143 $dbh->do("DELETE FROM records WHERE rdns_id=?", undef, ($zoneid)); 3144 $failmsg = "Failure removing reverse zone"; 3145 $dbh->do("DELETE FROM revzones WHERE rdns_id=?", undef, ($zoneid)); 3146 } 3124 3147 } else { 3125 my $sth = $dbh->prepare("UPDATE records SET type=?,rdns_id=0 WHERE rdns_id=? AND type=?"); 3126 $failmsg = "Failure converting multizone types to single-zone"; 3127 $sth->execute($reverse_typemap{A}, $zoneid, 65280); 3128 $sth->execute($reverse_typemap{AAAA}, $zoneid, 65281); 3129 # We don't have an "A template" or "AAAA template" type, although it might be useful for symmetry. 3130 # $sth->execute(65286?, $zoneid, 65283); 3131 # $sth->execute(65286?, $zoneid, 65284); 3132 $failmsg = "Failure removing reverse records"; 3133 $dbh->do("DELETE FROM records WHERE rdns_id=?", undef, ($zoneid)); 3134 $failmsg = "Failure removing reverse zone"; 3135 $dbh->do("DELETE FROM revzones WHERE rdns_id=?", undef, ($zoneid)); 3136 } 3137 3138 $msg = "Deleted ".($zonestatus ? '' : 'inactive ').($revrec eq 'n' ? 'domain' : 'reverse zone')." $zone"; 3148 $failmsg = "Failure removing secondary zone"; 3149 $dbh->do("DELETE FROM secondary_zones WHERE secondary_id=?", undef, $zoneid); 3150 } 3151 3152 $msg = "Deleted ".($zonestatus ? '' : 'inactive '). 3153 ($secondary eq 'n' ? ($revrec eq 'n' ? 'domain' : 'reverse zone') : 'secondary zone')." $zone"; 3139 3154 $loghash{entry} = $msg; 3140 3155 $self->_log(%loghash);
Note:
See TracChangeset
for help on using the changeset viewer.