Changeset 274
- Timestamp:
- 03/14/12 18:01:42 (13 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r273 r274 39 39 &changeGroup 40 40 &loadConfig &connectDB &finish 41 &addDomain &del Domain&domainName &revName &domainID &addRDNS41 &addDomain &delZone &domainName &revName &domainID &addRDNS 42 42 &getZoneCount &getZoneList 43 43 &addGroup &delGroup &getChildren &groupName … … 61 61 &changeGroup 62 62 &loadConfig &connectDB &finish 63 &addDomain &del Domain&domainName &revName &domainID &addRDNS63 &addDomain &delZone &domainName &revName &domainID &addRDNS 64 64 &getZoneCount &getZoneList 65 65 &addGroup &delGroup &getChildren &groupName … … 1266 1266 1267 1267 1268 ## DNSDB::delDomain() 1269 # Delete a domain. 1268 ## DNSDB::delZone() 1269 # Delete a forward or reverse zone. 1270 # Takes a database handle, zone ID, and forward/reverse flag. 1270 1271 # for now, just delete the records, then the domain. 1271 1272 # later we may want to archive it in some way instead (status code 2, for example?) 1272 sub delDomain { 1273 my $dbh = shift; 1274 my $domid = shift; 1273 sub delZone { 1274 my $dbh = shift; 1275 my $zoneid = shift; 1276 my $revrec = shift; 1275 1277 1276 1278 # Allow transactions, and raise an exception on errors so we can catch it later. … … 1283 1285 # Wrap all the SQL in a transaction 1284 1286 eval { 1285 my $sth = $dbh->prepare("delete from records where domain_id=?"); 1286 $failmsg = "Failure removing domain records"; 1287 $sth->execute($domid); 1288 $sth = $dbh->prepare("delete from domains where domain_id=?"); 1289 $failmsg = "Failure removing domain"; 1290 $sth->execute($domid); 1287 # Disentangle custom record types before removing the 1288 # ones that are only in the zone to be deleted 1289 if ($revrec eq 'n') { 1290 my $sth = $dbh->prepare("UPDATE records SET type=?,domain_id=0 WHERE domain_id=? AND type=?"); 1291 $failmsg = "Failure converting multizone types to single-zone"; 1292 $sth->execute($reverse_typemap{PTR}, $zoneid, 65280); 1293 $sth->execute($reverse_typemap{PTR}, $zoneid, 65281); 1294 $sth->execute(65282, $zoneid, 65283); 1295 $sth->execute(65282, $zoneid, 65284); 1296 $failmsg = "Failure removing domain records"; 1297 $dbh->do("DELETE FROM records WHERE domain_id=?", undef, ($zoneid)); 1298 $failmsg = "Failure removing domain"; 1299 $dbh->do("DELETE FROM domains WHERE domain_id=?", undef, ($zoneid)); 1300 } else { 1301 my $sth = $dbh->prepare("UPDATE records SET type=?,rdns_id=0 WHERE rdns_id=? AND type=?"); 1302 $failmsg = "Failure converting multizone types to single-zone"; 1303 $sth->execute($reverse_typemap{A}, $zoneid, 65280); 1304 $sth->execute($reverse_typemap{AAAA}, $zoneid, 65281); 1305 # We don't have an "A template" or "AAAA template" type, although it might be useful for symmetry. 1306 # $sth->execute(65285?, $zoneid, 65283); 1307 # $sth->execute(65285?, $zoneid, 65284); 1308 $failmsg = "Failure removing reverse records"; 1309 $dbh->do("DELETE FROM records WHERE rdns_id=?", undef, ($zoneid)); 1310 $failmsg = "Failure removing reverse zone"; 1311 $dbh->do("DELETE FROM revzones WHERE rdns_id=?", undef, ($zoneid)); 1312 } 1291 1313 1292 1314 # once we get here, we should have suceeded. … … 1302 1324 } 1303 1325 1304 } # end del Domain()1326 } # end delZone() 1305 1327 1306 1328 -
trunk/dns.cgi
r272 r274 416 416 my $pargroup = parentID($dbh, (id => $webvar{id}, type => 'domain', revrec => $webvar{revrec})); 417 417 my $dom = domainName($dbh, $webvar{id}); 418 my ($code,$msg) = del Domain($dbh, $webvar{id});418 my ($code,$msg) = delZone($dbh, $webvar{id}, $webvar{revrec}); 419 419 if ($code eq 'OK') { 420 420 logaction($webvar{id}, $session->param("username"), $pargroup, "Deleted domain $dom"); … … 434 434 435 435 $webvar{revrec} = 'y'; 436 437 if ($session->param('resultmsg')) { 438 $page->param(resultmsg => $session->param('resultmsg')); 439 $session->clear('resultmsg'); 440 } 441 if ($session->param('errmsg')) { 442 $page->param(errmsg => $session->param('errmsg')); 443 $session->clear('errmsg'); 444 } 445 436 446 $page->param(curpage => $webvar{page}); 437 447 listzones(); … … 480 490 } 481 491 482 #} elsif ($webvar{page} eq 'delrevzone') { 492 } elsif ($webvar{page} eq 'delrevzone') { 493 494 changepage(page => "revzones", errmsg => "You are not permitted to delete reverse zones") 495 unless ($permissions{admin} || $permissions{domain_delete}); 496 497 # security check - does the user have permission to access this entity? 498 if (!check_scope(id => $webvar{id}, type => 'revzone')) { 499 changepage(page => "revzones", errmsg => "You do not have permission to delete the requested reverse zone"); 500 } 501 502 $page->param(id => $webvar{id}); 503 504 # first pass = confirm y/n (sorta) 505 if (!defined($webvar{del})) { 506 507 $page->param(del_getconf => 1); 508 $page->param(revzone => revName($dbh,$webvar{id})); 509 510 } elsif ($webvar{del} eq 'ok') { 511 my $pargroup = parentID($dbh, (id => $webvar{id}, type => 'revzone', revrec => $webvar{revrec})); 512 my $zone = revName($dbh, $webvar{id}); 513 my ($code,$msg) = delZone($dbh, $webvar{id}, 'y'); 514 if ($code eq 'OK') { 515 ##fixme: logaction needs to take "domid OR revid" and some way to know which it is 516 logaction($webvar{id}, $session->param("username"), $pargroup, "Deleted reverse zone $zone"); 517 changepage(page => "revzones", resultmsg => "Deleted reverse zone $zone"); 518 } else { 519 logaction($webvar{id}, $session->param("username"), $pargroup, "Failed to delete domain $zone ($msg)") 520 if $config{log_failures}; 521 #push @debugbits, "got back $code, $msg\n"; 522 changepage(page => "revzones", errmsg => "Error deleting reverse zone $zone: $msg"); 523 } 524 525 } else { 526 # cancelled. whee! 527 changepage(page => "revzones"); 528 } 483 529 484 530 } elsif ($webvar{page} eq 'reclist') { … … 1205 1251 my $pargroup = parentID($dbh, (id => $webvar{$_}, type => 'domain', revrec => $webvar{revrec})); 1206 1252 my $dom = domainName($dbh, $webvar{$_}); 1207 my ($code, $msg) = del Domain($dbh, $webvar{$_});1253 my ($code, $msg) = delZone($dbh, $webvar{$_}, 'n'); 1208 1254 if ($code eq 'OK') { 1209 1255 logaction($webvar{$_}, $session->param("username"), $pargroup, "Deleted domain $dom");
Note:
See TracChangeset
for help on using the changeset viewer.