Changeset 274 for trunk


Ignore:
Timestamp:
03/14/12 18:01:42 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Flesh out most reverse zone deletion. See #26.

  • Convert delDomain() to delZone()
  • Add checks to coerce the shared-zone record types down to standard types on removal of the second parent, either way around. (IE, A+PTR will be converted to PTR if the parent domain is removed, or A if the parent revzone is removed)

Make sure to show result or error messages on the reverse zone
list page

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r273 r274  
    3939        &changeGroup
    4040        &loadConfig &connectDB &finish
    41         &addDomain &delDomain &domainName &revName &domainID &addRDNS
     41        &addDomain &delZone &domainName &revName &domainID &addRDNS
    4242        &getZoneCount &getZoneList
    4343        &addGroup &delGroup &getChildren &groupName
     
    6161                &changeGroup
    6262                &loadConfig &connectDB &finish
    63                 &addDomain &delDomain &domainName &revName &domainID &addRDNS
     63                &addDomain &delZone &domainName &revName &domainID &addRDNS
    6464                &getZoneCount &getZoneList
    6565                &addGroup &delGroup &getChildren &groupName
     
    12661266
    12671267
    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.
    12701271# for now, just delete the records, then the domain.
    12711272# 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;
     1273sub delZone {
     1274  my $dbh = shift;
     1275  my $zoneid = shift;
     1276  my $revrec = shift;
    12751277
    12761278  # Allow transactions, and raise an exception on errors so we can catch it later.
     
    12831285  # Wrap all the SQL in a transaction
    12841286  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    }
    12911313
    12921314    # once we get here, we should have suceeded.
     
    13021324  }
    13031325
    1304 } # end delDomain()
     1326} # end delZone()
    13051327
    13061328
  • trunk/dns.cgi

    r272 r274  
    416416    my $pargroup = parentID($dbh, (id => $webvar{id}, type => 'domain', revrec => $webvar{revrec}));
    417417    my $dom = domainName($dbh, $webvar{id});
    418     my ($code,$msg) = delDomain($dbh, $webvar{id});
     418    my ($code,$msg) = delZone($dbh, $webvar{id}, $webvar{revrec});
    419419    if ($code eq 'OK') {
    420420      logaction($webvar{id}, $session->param("username"), $pargroup, "Deleted domain $dom");
     
    434434
    435435  $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
    436446  $page->param(curpage => $webvar{page});
    437447  listzones();
     
    480490  }
    481491
    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  }
    483529
    484530} elsif ($webvar{page} eq 'reclist') {
     
    12051251      my $pargroup = parentID($dbh, (id => $webvar{$_}, type => 'domain', revrec => $webvar{revrec}));
    12061252      my $dom = domainName($dbh, $webvar{$_});
    1207       my ($code, $msg) = delDomain($dbh, $webvar{$_});
     1253      my ($code, $msg) = delZone($dbh, $webvar{$_}, 'n');
    12081254      if ($code eq 'OK') {
    12091255        logaction($webvar{$_}, $session->param("username"), $pargroup, "Deleted domain $dom");
Note: See TracChangeset for help on using the changeset viewer.