Changeset 311 for trunk/DNSDB.pm
- Timestamp:
- 04/19/12 17:21:11 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r309 r311 2494 2494 my $rev = shift; 2495 2495 my $id = shift; 2496 my %ret;2497 2496 2498 2497 # (ab)use distance and weight columns to store SOA data? can't for default_rev_records... … … 2501 2500 my $sql = "SELECT record_id,host,val,ttl from "._rectable($def,$rev). 2502 2501 " 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; 2506 2504 ##fixme: stick a flag somewhere if the record doesn't exist. by the API, this is an impossible case, but... 2507 2505 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; 2523 2512 } # end getSOA() 2524 2513 … … 2535 2524 my %soa = @_; 2536 2525 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})) ); 2538 2540 2539 2541 # Allow transactions, and raise an exception on errors so we can catch it later. … … 2542 2544 local $dbh->{RaiseError} = 1; 2543 2545 2544 my $msg;2545 2546 2546 eval { 2547 ##fixme: data validation: make sure {recid} is really the SOA for {parent}2548 2547 my $sql = "UPDATE "._rectable($defrec, $revrec)." SET host=?, val=?, ttl=? WHERE record_id=? AND type=6"; 2549 2548 $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 ". 2557 2554 "(ns $soa{prins}, contact $soa{contact}, refresh $soa{refresh},". 2558 2555 " retry $soa{retry}, expire $soa{expire}, minTTL $soa{minttl}, TTL $soa{ttl})"; 2559 2556 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); 2562 2559 2563 2560 $dbh->commit; … … 2566 2563 $msg = $@; 2567 2564 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}); 2569 2572 } else { 2570 2573 return ('OK', $msg);
Note:
See TracChangeset
for help on using the changeset viewer.