Changeset 781 for trunk/DNSDB.pm


Ignore:
Timestamp:
Aug 13, 2019, 5:46:19 PM (12 months ago)
Author:
Kris Deugau
Message:

/trunk

Move serial number tweaking into a sub for better maintainability. See #24.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r780 r781  
    494494#  } elsif ($self->{log_channel} eq 'syslog') {
    495495#  }
    496 } # end _log
     496} # end _log()
     497
     498## DNSDB::_updateserial()
     499# Update the serial number on a forward and/or reverse zone, and flag it as changed
     500# Takes a logdata hash
     501sub _updateserial {
     502  my $self = shift;
     503  my $dbh = $self->{dbh};
     504
     505  my %args = @_;
     506
     507##fixme:  add alternate serial schemes here
     508
     509  if ($args{rdns_id}) {
     510    $dbh->do("UPDATE revzones SET changed = 'y',zserial = ? WHERE rdns_id = ?", undef, (scalar(time), $args{rdns_id}) );
     511  }
     512  if ($args{domain_id}) {
     513    $dbh->do("UPDATE domains SET changed = 'y',zserial = ? WHERE domain_id = ?", undef, (scalar(time), $args{domain_id}) );
     514  }
     515} # end _updateserial()
    497516
    498517
     
    42544273        " retry $soa{retry}, expire $soa{expire}, minTTL $soa{minttl}, TTL $soa{ttl})";
    42554274    }
    4256     if ($revrec eq 'y') {
    4257       $dbh->do("UPDATE revzones SET changed = 'y',zserial = ? WHERE rdns_id = ?", undef, (scalar(time), $soa{id}) );
    4258     } else {
    4259       $dbh->do("UPDATE domains SET changed = 'y',zserial = ? WHERE domain_id = ?", undef, (scalar(time), $soa{id}) );
    4260     }
     4275    _updateserial(%logdata);
    42614276    $logdata{entry} = $msg;
    42624277    $self->_log(%logdata);
     
    46074622    $dbh->do("INSERT INTO "._rectable($defrec, $revrec)." ($fields) VALUES ($vallen)",
    46084623        undef, @vallist);
    4609     if ($revrec eq 'y') {
    4610       $dbh->do("UPDATE revzones SET changed = 'y',zserial = ? WHERE rdns_id = ?", undef, (scalar(time), $domid) );
    4611     } else {
    4612       $dbh->do("UPDATE domains SET changed = 'y',zserial = ? WHERE domain_id = ?", undef, (scalar(time), $domid) );
    4613     }
     4624    _updateserial(%logdata);
    46144625    $self->_log(%logdata);
    46154626    $dbh->commit;
     
    48124823  eval {
    48134824    $dbh->do("UPDATE "._rectable($defrec,$revrec)." SET $fields WHERE record_id=?", undef, (@vallist, $id) );
    4814     if ($revrec eq 'y') {
    4815       $dbh->do("UPDATE revzones SET changed = 'y',zserial = ? WHERE rdns_id = ?", undef, (scalar(time), $domid) );
    4816     } else {
    4817       $dbh->do("UPDATE domains SET changed = 'y',zserial = ? WHERE domain_id = ?", undef, (scalar(time), $domid) );
    4818     }
     4825    _updateserial(%logdata);
    48194826    $self->_log(%logdata);
    48204827    $dbh->commit;
     
    48824889  eval {
    48834890    $dbh->do("UPDATE records SET $delpar = ?, type = ? WHERE record_id = ?", undef, @sqlargs);
    4884     # both forward and reverse zones affected, more or less by definition
    4885     $dbh->do("UPDATE revzones SET changed = 'y',zserial = ? WHERE rdns_id = ?", undef, (scalar(time), $rec->{rdns_id}) );
    4886     $dbh->do("UPDATE domains SET changed = 'y',zserial = ? WHERE domain_id = ?", undef, (scalar(time), $rec->{domain_id}) );
     4891    # we have no %logdata in this sub
     4892    _updateserial(domain_id => $rec->{domain_id}, rdns_id => $rec->{rdns_id});
    48874893    $self->_log(domain_id => $rec->{domain_id}, rdns_id => $rec->{rdns_id},
    48884894        group_id => $self->parentID(id => $rec->{rdns_id}, type => 'revzone', revrec => 'y'),
     
    49504956      $logdata{entry} = "Error deleting ".($defrec eq 'y' ? 'default record' : 'record').
    49514957        " '$oldrec->{host} $typemap{$oldrec->{type}} $oldrec->{val}', TTL $oldrec->{ttl} ($msg)";
     4958      _updateserial(%logdata);
    49524959      $self->_log(%logdata);
    49534960      $dbh->commit;
     
    55205527#  status - active/inactive state flag (defaults to active)
    55215528#  rwsoa - overwrite-SOA flag (defaults to off)
     5529#  keepserial - keep the upstream serial number even if we overwrite the rest of the SOA
    55225530#  rwns - overwrite-NS flag (defaults to off, doesn't affect subdomain NS records)
    55235531#  merge - flag to automerge A or AAAA records with matching PTR records
Note: See TracChangeset for help on using the changeset viewer.