Changeset 311 for trunk/DNSDB.pm


Ignore:
Timestamp:
04/19/12 17:21:11 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Move SQL for SOA update to DNSDB.pm (see #1)
Clean up support for reverse zones (see #26)
Move action logging for SOA updates to DNSDB.pm (see #35)

Includes log/info message consistency cleanups, dropping stale
commented code, dropping if(0)'ed code, tweaks to fillsoa() to
retain user changes on errors, updates to getSOA() for consistency,
removal of a stale form input

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r309 r311  
    24942494  my $rev = shift;
    24952495  my $id = shift;
    2496   my %ret;
    24972496
    24982497  # (ab)use distance and weight columns to store SOA data?  can't for default_rev_records...
     
    25012500  my $sql = "SELECT record_id,host,val,ttl from "._rectable($def,$rev).
    25022501        " WHERE "._recparent($def,$rev)." = ? AND type=$reverse_typemap{SOA}";
    2503 
    2504   my $sth = $dbh->prepare($sql);
    2505   $sth->execute($id);
     2502  my $ret = $dbh->selectrow_hashref($sql, undef, ($id) );
     2503  return if !$ret;
    25062504##fixme:  stick a flag somewhere if the record doesn't exist.  by the API, this is an impossible case, but...
    25072505
    2508   my ($recid,$host,$val,$ttl) = $sth->fetchrow_array() or return;
    2509   my ($contact,$prins) = split /:/, $host;
    2510   my ($refresh,$retry,$expire,$minttl) = split /:/, $val;
    2511 
    2512   $ret{recid}   = $recid;
    2513   $ret{ttl}     = $ttl;
    2514 #  $ret{serial} = $serial;      # ca't use distance for serial with default_rev_records
    2515   $ret{prins}   = $prins;
    2516   $ret{contact} = $contact;
    2517   $ret{refresh} = $refresh;
    2518   $ret{retry}   = $retry;
    2519   $ret{expire}  = $expire;
    2520   $ret{minttl}  = $minttl;
    2521 
    2522   return %ret;
     2506  ($ret->{contact},$ret->{prins}) = split /:/, $ret->{host};
     2507  delete $ret->{host};
     2508  ($ret->{refresh},$ret->{retry},$ret->{expire},$ret->{minttl}) = split /:/, $ret->{val};
     2509  delete $ret->{val};
     2510
     2511  return $ret;
    25232512} # end getSOA()
    25242513
     
    25352524  my %soa = @_;
    25362525
    2537   my %oldsoa = getSOA($dbh, $defrec, $revrec, $soa{recid});
     2526  my $oldsoa = getSOA($dbh, $defrec, $revrec, $soa{id});
     2527
     2528  my $msg;
     2529  my %logdata;
     2530  if ($defrec eq 'n') {
     2531    $logdata{domain_id} = $soa{id} if $revrec eq 'n';
     2532    $logdata{rdns_id} = $soa{id} if $revrec eq 'y';
     2533    $logdata{group_id} = parentID($dbh, (id => $soa{id}, revrec => $revrec,
     2534        type => ($revrec eq 'n' ? 'domain' : 'revzone') ) );
     2535  } else {
     2536    $logdata{group_id} = $soa{id};
     2537  }
     2538  my $parname = ($defrec eq 'y' ? groupName($dbh, $soa{id}) :
     2539                ($revrec eq 'n' ? domainName($dbh, $soa{id}) : revName($dbh, $soa{id})) );
    25382540
    25392541  # Allow transactions, and raise an exception on errors so we can catch it later.
     
    25422544  local $dbh->{RaiseError} = 1;
    25432545
    2544   my $msg;
    2545 
    25462546  eval {
    2547 ##fixme: data validation: make sure {recid} is really the SOA for {parent}
    25482547    my $sql = "UPDATE "._rectable($defrec, $revrec)." SET host=?, val=?, ttl=? WHERE record_id=? AND type=6";
    25492548    $dbh->do($sql, undef, ("$soa{contact}:$soa{prins}", "$soa{refresh}:$soa{retry}:$soa{expire}:$soa{minttl}",
    2550         $soa{ttl}, $soa{recid}) );
    2551 
    2552     $msg = "Updated ".($defrec eq 'y' ? 'default ' : '')."SOA for ".
    2553         ($defrec eq 'y' ? groupName($dbh, $soa{recid}) :
    2554                 ($revrec eq 'n' ? domainName($dbh, $soa{recid}) : revName($dbh, $soa{recid}) ) ).
    2555         ": (ns $oldsoa{prins}, contact $oldsoa{contact}, refresh $oldsoa{refresh},".
    2556         " retry $oldsoa{retry}, expire $oldsoa{expire}, minTTL $oldsoa{minttl}, TTL $oldsoa{ttl}) to ".
     2549        $soa{ttl}, $oldsoa->{record_id}) );
     2550    $msg = "Updated ".($defrec eq 'y' ? ($revrec eq 'y' ? 'default reverse ' : 'default ') : '').
     2551        "SOA for $parname: ".
     2552        "(ns $oldsoa->{prins}, contact $oldsoa->{contact}, refresh $oldsoa->{refresh},".
     2553        " retry $oldsoa->{retry}, expire $oldsoa->{expire}, minTTL $oldsoa->{minttl}, TTL $oldsoa->{ttl}) to ".
    25572554        "(ns $soa{prins}, contact $soa{contact}, refresh $soa{refresh},".
    25582555        " retry $soa{retry}, expire $soa{expire}, minTTL $soa{minttl}, TTL $soa{ttl})";
    25592556
    2560 #    _log($dbh, (rdns_id => $rdns_id, user_id => $userinfo{id}, group_id => $group,
    2561 #       username => $userinfo{name}, entry => $msg) );
     2557    $logdata{entry} = $msg;
     2558    _log($dbh, %logdata);
    25622559
    25632560    $dbh->commit;
     
    25662563    $msg = $@;
    25672564    eval { $dbh->rollback; };
    2568     return ('FAIL',$msg);
     2565    $logdata{entry} = "Error updating ".($defrec eq 'y' ? ($revrec eq 'y' ? 'default reverse zone ' : 'default ') : '').
     2566        "SOA record for $parname: $msg";
     2567    if ($config{log_failures}) {
     2568      _log($dbh, %logdata);
     2569      $dbh->commit;
     2570    }
     2571    return ('FAIL', $logdata{entry});
    25692572  } else {
    25702573    return ('OK', $msg);
Note: See TracChangeset for help on using the changeset viewer.