Changeset 290 for trunk


Ignore:
Timestamp:
03/27/12 14:57:39 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Move action logging for delRec() into DNSDB.pm. See #35

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r289 r290  
    26942694  my $id = shift;
    26952695
    2696   my $sth = $dbh->prepare("DELETE FROM "._rectable($defrec,$revrec)." WHERE record_id=?");
    2697   $sth->execute($id);
    2698 
    2699   return ('FAIL',"Couldn't remove record: ".$sth->errstr) if $sth->err;
    2700 
    2701   return ('OK','OK');
     2696  my $oldrec = getRecLine($dbh, $defrec, $revrec, $id);
     2697
     2698  # Allow transactions, and raise an exception on errors so we can catch it later.
     2699  # Use local to make sure these get "reset" properly on exiting this block
     2700  local $dbh->{AutoCommit} = 0;
     2701  local $dbh->{RaiseError} = 1;
     2702
     2703  # Put together the log entry
     2704  my %logdata;
     2705  $logdata{domain_id} = $oldrec->{domain_id};
     2706  $logdata{rdns_id} = $oldrec->{rdns_id};
     2707  $logdata{group_id} = $oldrec->{group_id} if $defrec eq 'y';
     2708  $logdata{group_id} = parentID($dbh,
     2709                (id => $oldrec->{domain_id}, type => ($revrec eq 'n' ? 'domain' : 'revzone'), revrec => $revrec) )
     2710        if $defrec eq 'n';
     2711  $logdata{entry} = "Deleted ".($defrec eq 'y' ? 'default record ' : 'record ').
     2712        "'$oldrec->{host} $typemap{$oldrec->{type}} $oldrec->{val}";
     2713  $logdata{entry} .= " [distance $oldrec->{distance}]" if $typemap{$oldrec->{type}} eq 'MX';
     2714  $logdata{entry} .= " [priority $oldrec->{distance}] [weight $oldrec->{weight}] [port $oldrec->{port}]"
     2715        if $typemap{$oldrec->{type}} eq 'SRV';
     2716  $logdata{entry} .= "', TTL $oldrec->{ttl}\n";
     2717
     2718  eval {
     2719    my $sth = $dbh->do("DELETE FROM "._rectable($defrec,$revrec)." WHERE record_id=?", undef, ($id));
     2720    _log($dbh, %logdata);
     2721    $dbh->commit;
     2722  };
     2723  if ($@) {
     2724    my $msg = $@;
     2725    eval { $dbh->rollback; };
     2726    if ($config{log_failures}) {
     2727      $logdata{entry} = "Error deleting ".($defrec eq 'y' ? 'default record' : 'record').
     2728        " '$oldrec->{host} $typemap{$oldrec->{type}} $oldrec->{val}', TTL $oldrec->{ttl} ($msg)";
     2729      _log($dbh, %logdata);
     2730      $dbh->commit;
     2731    }
     2732    return ('FAIL', $msg);
     2733  }
     2734
     2735  return ('OK',$logdata{entry});
    27022736} # end delRec()
    27032737
  • trunk/dns.cgi

    r289 r290  
    780780    $page->param(recval => $rec->{val});
    781781  } elsif ($webvar{del} eq 'ok') {
    782 # get rec data before we try to delete it
    783     my $rec = getRecLine($dbh, $webvar{defrec}, $webvar{revrec}, $webvar{id});
    784782    my ($code,$msg) = delRec($dbh, $webvar{defrec}, $webvar{revrec}, $webvar{id});
    785783    if ($code eq 'OK') {
    786       if ($webvar{defrec} eq 'y') {
    787         my $recclass = ($webvar{revrec} eq 'n' ? 'default record' : 'default reverse record');
    788 ##fixme:  log distance for MX;  log port/weight/distance for SRV
    789         my $restr = "Deleted $recclass '$rec->{host} $typemap{$rec->{type}} $rec->{val}', TTL $rec->{ttl}";
    790         logaction(0, $session->param("username"), $rec->{parid}, $restr);
    791         changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec},
    792                 revrec => $webvar{revrec}, resultmsg => $restr);
    793       } else {
    794         my $recclass = ($webvar{revrec} eq 'n' ? 'record' : 'reverse record');
    795         my $restr = "Deleted $recclass '$rec->{host} $typemap{$rec->{type}} $rec->{val}', TTL $rec->{ttl}";
    796         logaction($rec->{parid}, $session->param("username"),
    797                 parentID($dbh, (id => $rec->{parid}, type => 'domain', revrec => $webvar{revrec})),
    798                 $restr);
    799         changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec},
    800                 revrec => $webvar{revrec}, resultmsg => $restr);
    801       }
     784      changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec},
     785                revrec => $webvar{revrec}, resultmsg => $msg);
    802786    } else {
    803787## need to find failure mode
    804       if ($config{log_failures}) {
    805         if ($webvar{defrec} eq 'y') {
    806           logaction(0, $session->param("username"), $rec->{parid},
    807                 "Failed deleting default record '$rec->{host} $typemap{$rec->{type}} $rec->{val}',".
    808                 " TTL $rec->{ttl} ($msg)");
    809         } else {
    810           logaction($rec->{parid}, $session->param("username"),
    811                 parentID($dbh, (id => $rec->{parid}, type => 'domain', revrec => $webvar{revrec})),
    812                 "Failed deleting record '$rec->{host} $typemap{$rec->{type}} $rec->{val}', TTL $rec->{ttl} ($msg)");
    813         }
    814       }
    815788      changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec},
    816                 revrec => $webvar{revrec}, errmsg => "Error deleting record: $msg");
     789                revrec => $webvar{revrec}, errmsg => $msg);
    817790    }
    818791  } else {
Note: See TracChangeset for help on using the changeset viewer.