Changeset 277 for trunk/DNSDB.pm


Ignore:
Timestamp:
03/15/12 18:04:02 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Checkpoint: Clean up SOA editing and extend for reverse zones.
Mostly complete; still need to finish shuffling arguments to
get logging moved into DNSDB.pm
See #26

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r276 r277  
    4343        &addGroup &delGroup &getChildren &groupName
    4444        &addUser &updateUser &delUser &userFullName &userStatus &getUserData
    45         &getSOA &getRecLine &getDomRecs &getRecCount
     45        &getSOA &updateSOA &getRecLine &getDomRecs &getRecCount
    4646        &addRec &updateRec &delRec
    4747        &getTypelist
     
    6565                &addGroup &delGroup &getChildren &groupName
    6666                &addUser &updateUser &delUser &userFullName &userStatus &getUserData
    67                 &getSOA &getRecLine &getDomRecs &getRecCount
     67                &getSOA &updateSOA &getRecLine &getDomRecs &getRecCount
    6868                &addRec &updateRec &delRec
    6969                &getTypelist
     
    21822182# Update the specified SOA record
    21832183# Takes a database handle, default/live flag, forward/reverse flag, and SOA data hash
     2184# Returns a two-element list with a result code and message
    21842185sub updateSOA {
    21852186  my $dbh = shift;
     
    21892190  my %soa = @_;
    21902191
     2192  my %oldsoa = getSOA($dbh, $defrec, $revrec, $soa{recid});
     2193
     2194  # Allow transactions, and raise an exception on errors so we can catch it later.
     2195  # Use local to make sure these get "reset" properly on exiting this block
     2196  local $dbh->{AutoCommit} = 0;
     2197  local $dbh->{RaiseError} = 1;
     2198
     2199  my $msg;
     2200
     2201  eval {
    21912202##fixme: data validation: make sure {recid} is really the SOA for {parent}
    2192   my $sql = "UPDATE "._rectable($defrec, $revrec)." SET host=?, val=?, ttl=? WHERE record_id=? AND type=6";
    2193   $dbh->do($sql, undef, ("$soa{contact}:$soa{prins}", "$soa{refresh}:$soa{retry}:$soa{expire}:$soa{minttl}",
    2194         $soa{ttl}, $soa{recid}));
    2195 
     2203    my $sql = "UPDATE "._rectable($defrec, $revrec)." SET host=?, val=?, ttl=? WHERE record_id=? AND type=6";
     2204    $dbh->do($sql, undef, ("$soa{contact}:$soa{prins}", "$soa{refresh}:$soa{retry}:$soa{expire}:$soa{minttl}",
     2205        $soa{ttl}, $soa{recid}) );
     2206
     2207    $msg = "Updated ".($defrec eq 'y' ? 'default ' : '')."SOA for ".
     2208        ($defrec eq 'y' ? groupName($dbh, $soa{recid}) :
     2209                ($revrec eq 'n' ? domainName($dbh, $soa{recid}) : revName($dbh, $soa{recid}) ) ).
     2210        ": (ns $oldsoa{prins}, contact $oldsoa{contact}, refresh $oldsoa{refresh},".
     2211        " retry $oldsoa{retry}, expire $oldsoa{expire}, minTTL $oldsoa{minttl}, TTL $oldsoa{ttl}) to ".
     2212        "(ns $soa{prins}, contact $soa{contact}, refresh $soa{refresh},".
     2213        " retry $soa{retry}, expire $soa{expire}, minTTL $soa{minttl}, TTL $soa{ttl})";
     2214
     2215#    _log($dbh, (rdns_id => $rdns_id, user_id => $userinfo{id}, group_id => $group,
     2216#       username => $userinfo{name}, entry => $msg) );
     2217
     2218    $dbh->commit;
     2219  };
     2220  if ($@) {
     2221    $msg = $@;
     2222    eval { $dbh->rollback; };
     2223    return ('FAIL',$msg);
     2224  } else {
     2225    return ('OK', $msg);
     2226  }
    21962227} # end updateSOA()
    21972228
Note: See TracChangeset for help on using the changeset viewer.