Changeset 288


Ignore:
Timestamp:
03/26/12 18:06:09 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Move action logging for updateRec() into DNSDB.pm.
Fix lurking bug in update that reset distance/weight/port to 0
Rearrange log/resultstring entry in addRec() for more consistent
order of fields, also to match ordering in updateRec()

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r287 r288  
    25152515                (id => $id, type => ($revrec eq 'n' ? 'domain' : 'revzone'), revrec => $revrec) )
    25162516        if $defrec eq 'n';
    2517   $logdata{entry} = "Added ".($defrec eq 'y' ? 'default record' : 'record')." '$$host $typemap{$$rectype}";
     2517  $logdata{entry} = "Added ".($defrec eq 'y' ? 'default record' : 'record')." '$$host $typemap{$$rectype} $$val";
    25182518  $logdata{entry} .= " [distance $dist]" if $typemap{$$rectype} eq 'MX';
    25192519  $logdata{entry} .= " [priority $dist] [weight $weight] [port $port]"
    25202520        if $typemap{$$rectype} eq 'SRV';
    2521   $logdata{entry} .= " $$val', TTL $ttl";
     2521  $logdata{entry} .= "', TTL $ttl";
    25222522
    25232523  # Allow transactions, and raise an exception on errors so we can catch it later.
     
    25842584
    25852585  # only MX and SRV will use these
    2586   my $dist = 0;
    2587   my $weight = 0;
    2588   my $port = 0;
     2586  my $dist = shift || 0;
     2587  my $weight = shift || 0;
     2588  my $port = shift || 0;
    25892589
    25902590  my $fields;
     
    26312631  $fields .= "=?";
    26322632
     2633  # Put together the success log entry.  Horrible kludge from addRec() copied as-is since
     2634  # we don't know whether the passed arguments or retrieved values for domain_id and rdns_id
     2635  # will be maintained (due to "not-in-zone" validation changes)
     2636  my %logdata;
     2637  my @ftmp = split /,/, $fields;
     2638  for (my $i=0; $i <= $#vallist; $i++) {
     2639    $logdata{domain_id} = $vallist[$i] if $ftmp[$i] eq 'domain_id';
     2640    $logdata{rdns_id} = $vallist[$i] if $ftmp[$i] eq 'rdns_id';
     2641  }
     2642  $logdata{group_id} = $parid if $defrec eq 'y';
     2643  $logdata{group_id} = parentID($dbh,
     2644                (id => $parid, type => ($revrec eq 'n' ? 'domain' : 'revzone'), revrec => $revrec) )
     2645        if $defrec eq 'n';
     2646  $logdata{entry} = "Updated ".($defrec eq 'y' ? 'default record' : 'record')." from\n".
     2647        "'$oldrec->{host} $typemap{$oldrec->{type}} $oldrec->{val}";
     2648  $logdata{entry} .= " [distance $oldrec->{distance}]" if $typemap{$oldrec->{type}} eq 'MX';
     2649  $logdata{entry} .= " [priority $oldrec->{distance}] [weight $oldrec->{weight}] [port $oldrec->{port}]"
     2650        if $typemap{$oldrec->{type}} eq 'SRV';
     2651  $logdata{entry} .= "', TTL $oldrec->{ttl}\nto\n'$$host $typemap{$$rectype} $$val";
     2652  $logdata{entry} .= " [distance $dist]" if $typemap{$$rectype} eq 'MX';
     2653  $logdata{entry} .= " [priority $dist] [weight $weight] [port $port]" if $typemap{$$rectype} eq 'SRV';
     2654  $logdata{entry} .= "', TTL $ttl";
     2655
    26332656  local $dbh->{AutoCommit} = 0;
    26342657  local $dbh->{RaiseError} = 1;
     
    26362659  eval {
    26372660    $dbh->do("UPDATE "._rectable($defrec,$revrec)." SET $fields WHERE record_id=?", undef, (@vallist, $id) );
     2661    _log($dbh, %logdata);
    26382662    $dbh->commit;
    26392663  };
    26402664  if ($@) {
    26412665    my $msg = $@;
    2642     $dbh->rollback;
     2666    eval { $dbh->rollback; };
    26432667    return ('FAIL', $msg);
    26442668  }
    26452669
     2670  $resultstr = $logdata{entry};
    26462671  return ($retcode, $retmsg);
    26472672} # end updateRec()
  • trunk/dns.cgi

    r287 r288  
    738738
    739739    if ($code eq 'OK' || $code eq 'WARN') {
    740       my $restr;
    741       if ($webvar{defrec} eq 'y') {
    742         $restr = "Updated default record from '$oldrec->{host} $typemap{$oldrec->{type}} $oldrec->{val}', TTL $oldrec->{ttl}\n".
    743                 "to '$webvar{name} $typemap{$webvar{type}} $webvar{address}', TTL $webvar{ttl}";
    744         logaction(0, $session->param("username"), $webvar{parentid}, $restr);
    745       } else {
    746         $restr = "Updated record from '$oldrec->{host} $typemap{$oldrec->{type}} $oldrec->{val}', TTL $oldrec->{ttl}\n".
    747                 "to '$webvar{name} $typemap{$webvar{type}} $webvar{address}', TTL $webvar{ttl}";
    748         logaction($webvar{parentid}, $session->param("username"),
    749                 parentID($dbh, (id => $webvar{id}, type => 'record', defrec => $webvar{defrec},
    750                         revrec => $webvar{revrec}, partype => 'group')),
    751                 $restr);
    752       }
    753       changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec},
    754         revrec => $webvar{revrec}, resultmsg => $restr, warnmsg => ($code ne 'OK' ? $msg : ''));
     740      my %pageparams = (page => "reclist", id => $webvar{parentid},
     741        defrec => $webvar{defrec}, revrec => $webvar{revrec});
     742      $pageparams{warnmsg} = $msg."<br><br>\n".$DNSDB::resultstr if $code eq 'WARN';
     743      $pageparams{resultmsg} = $DNSDB::resultstr if $code eq 'OK';
     744      changepage(%pageparams);
    755745    } else {
    756746      $page->param(failed       => 1);
Note: See TracChangeset for help on using the changeset viewer.