Changeset 286


Ignore:
Timestamp:
03/23/12 13:25:45 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Convert action logging for "Add reverse zone" to DNSDB-internal. See #35

  • don't pass userdata, either in the upstream caller (dns.cgi) or internally to _log()
  • don't expect userdata to be passed in

Fix up some warning-message-propagation in addRDNS()
Remove domain_id from addDomain() failure logging; if the domain wasn't
added then the log can't usefully refer to it by domain ID.
File off stale ##fixme's on reclist page
Fine-tune handling of message parameters in changepage(); if we're
going to go to the effort of converting newlines to <br> we should
use the result.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r285 r286  
    13271327    my $msg = $@;
    13281328    eval { $dbh->rollback; };
    1329     _log($dbh, (domain_id => $dom_id, group_id => $group, entry => "Failed adding domain $domain ($msg)"))
     1329    _log($dbh, (group_id => $group, entry => "Failed adding domain $domain ($msg)"))
    13301330        if $config{log_failures};
    13311331    $dbh->commit;       # since we enabled transactions earlier
     
    14701470## DNSDB::addRDNS
    14711471# Adds a reverse DNS zone
    1472 # Takes a database handle, CIDR block, numeric group, boolean(ish) state (active/inactive),
    1473 # and user info hash (for logging).
     1472# Takes a database handle, CIDR block, reverse DNS pattern, numeric group,
     1473# and boolean(ish) state (active/inactive)
    14741474# Returns a status code and message
    14751475sub addRDNS {
     
    14811481  my $state = shift;
    14821482
    1483   my %userinfo = @_;    # remaining bits.
    1484 # user ID, username, user full name
    1485 
    14861483  $state = 1 if $state =~ /^active$/;
    14871484  $state = 1 if $state =~ /^on$/;
     
    15131510    ($rdns_id) = $dbh->selectrow_array("SELECT currval('revzones_rdns_id_seq')");
    15141511
    1515     _log($dbh, (rdns_id => $rdns_id, user_id => $userinfo{id}, group_id => $group, username => $userinfo{name},
     1512    _log($dbh, (rdns_id => $rdns_id, group_id => $group,
    15161513        entry => "Added ".($state ? 'active' : 'inactive')." reverse zone $zone"));
    15171514
     
    15761573        my @tmp1 = split /:/, $host;
    15771574        my @tmp2 = split /:/, $val;
    1578         _log($dbh, (rdns_id => $rdns_id, user_id => $userinfo{id}, group_id => $group,
    1579                 username => $userinfo{name}, entry =>
    1580                 "[new $zone] Added SOA record [contact $tmp1[0]] [master $tmp1[1]] ".
     1575        _log($dbh, (rdns_id => $rdns_id, group_id => $group,
     1576                entry => "[new $zone] Added SOA record [contact $tmp1[0]] [master $tmp1[1]] ".
    15811577                "[refresh $tmp2[0]] [retry $tmp2[1]] [expire $tmp2[2]] [minttl $tmp2[3]], TTL $ttl"));
    15821578        $defttl = $tmp2[3];
    15831579      } else {
    15841580        my $logentry = "[new $zone] Added record '$host $typemap{$type}";
    1585         _log($dbh, (rdns_id => $rdns_id, domain_id => $domid, user_id => $userinfo{id}, group_id => $group,
    1586                 username => $userinfo{name}, entry =>
    1587                 $logentry." $val', TTL $ttl"));
     1581        _log($dbh, (rdns_id => $rdns_id, domain_id => $domid, group_id => $group,
     1582                entry => $logentry." $val', TTL $ttl"));
    15881583      }
    15891584    }
     
    16061601
    16071602      $sth_in->execute($domid,$host,$type,$val,$defttl);
     1603      my $logentry = "[new $zone] Added record '$host $typemap{$type}";
     1604      _log($dbh, (rdns_id => $rdns_id, domain_id => $domid, group_id => $group,
     1605        entry => $logentry." $val', TTL $defttl from pattern"));
    16081606    }
    16091607
    16101608    # If there are warnings (presumably about default records skipped for cause) log them
    1611     _log($dbh, (rdns_id => $rdns_id, user_id => $userinfo{id}, group_id => $group,
    1612         username => $userinfo{name}, entry => "Warning(s) adding $zone:$warnstr"))
     1609    _log($dbh, (rdns_id => $rdns_id, group_id => $group, entry => "Warning(s) adding $zone:$warnstr"))
    16131610        if $warnstr;
    16141611
     
    16201617    my $msg = $@;
    16211618    eval { $dbh->rollback; };
     1619    _log($dbh, (group_id => $group, entry => "Failed adding reverse zone $zone ($msg)"))
     1620        if $config{log_failures};
     1621    $dbh->commit;       # since we enabled transactions earlier
    16221622    return ('FAIL',$msg);
    16231623  } else {
    1624     return ('OK',$rdns_id);
     1624    my $retcode = 'OK';
     1625    if ($warnstr) {
     1626      $resultstr = $warnstr;
     1627      $retcode = 'WARN';
     1628    }
     1629    return ($retcode, $rdns_id);
    16251630  }
    16261631
  • trunk/dns.cgi

    r285 r286  
    489489
    490490  my ($code,$msg) = addRDNS($dbh, $webvar{revzone}, $webvar{revpatt}, $webvar{group},
    491         ($webvar{makeactive} eq 'on' ? 1 : 0),
    492         (username => $session->param("username"), id => $session->param("uid")) );
     491        ($webvar{makeactive} eq 'on' ? 1 : 0));
    493492
    494493  if ($code eq 'OK') {
    495     logaction(0, $session->param("username"), $webvar{group}, "Added reverse zone $webvar{revzone}", $msg);
    496494    changepage(page => "reclist", id => $msg, revrec => 'y');
     495  } elsif ($code eq 'WARN') {
     496    changepage(page => "reclist", id => $msg, revrec => 'y', warnmsg => $DNSDB::resultstr);
    497497  } else {
    498     logaction(0, $session->param("username"), $webvar{group}, "Failed adding reverse zone $webvar{revzone} ($msg)");
    499498    $session->param('add_failed', 1);
    500499    changepage(page => "newrevzone", revzone => $webvar{revzone}, revpatt => $webvar{revpatt}, errmsg => $msg);
     
    602601    showzone($webvar{defrec}, $webvar{revrec}, $webvar{id});
    603602    if ($webvar{defrec} eq 'n') {
    604 #      showzone('n',$webvar{id});
    605 ##fixme:  permission for viewing logs?
    606 ##fixme:  determine which slice of the log we view (group, domain, revzone)
    607603      if ($webvar{revrec} eq 'n') {
    608604        $page->param(logdom => 1);
     
    18681864  foreach my $sessme ('resultmsg','warnmsg','errmsg') {
    18691865    if (my $tmp = $params{$sessme}) {
     1866      $tmp =~ s/^\n//;
    18701867      $tmp =~ s|\n|<br />\n|g;
    1871       $session->param($sessme, $params{$sessme});
     1868      $session->param($sessme, $tmp);
    18721869      delete $params{$sessme};
    18731870    }
Note: See TracChangeset for help on using the changeset viewer.