Changeset 868 for trunk/DNSDB


Ignore:
Timestamp:
09/22/22 17:36:43 (2 years ago)
Author:
Kris Deugau
Message:

/trunk

BIND export, unwinding dev saves, 20 of many many

  • Minor whitespace fiddling for coding style consistency
  • Rejig retrieval of locations/views for a zone
  • Include 'common' metaview in view list
  • Pass location list to printrec_bind(), and iterate over the locations found if the record has no set location
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB/ExportBIND.pm

    r867 r868  
    8484        # fetch a list of views/locations present in the zone.  we need to publish a file for each one.
    8585        # in the event that no locations are present (~~ $viewlist is empty), /%view collapses to nothing in the zone path
    86         my (@loclist) = $dnsdb->{dbh}->selectrow_array("SELECT DISTINCT location FROM records WHERE rdns_id = ?", undef, $revid);
     86#        my (@loclist) = $dnsdb->{dbh}->selectrow_array("SELECT DISTINCT location FROM records WHERE rdns_id = ?", undef, $revid);
     87        my $tmplocs = $dnsdb->{dbh}->selectall_arrayref("SELECT DISTINCT location FROM records WHERE rdns_id = ?", undef, $revid);
     88        my @loclist;
     89        foreach my $tloc (@{$tmplocs}) {
     90          push @loclist, ($tloc->[0] eq '' ? 'common' : $tloc->[0]);
     91        }
     92
    8793        push @loclist, $defloc unless grep /$defloc/, @loclist;
     94        push @loclist, 'common' unless grep /^common$/, @loclist;
    8895        my $zonepath = $dnsdb->{bind_export_reverse_zone_path};
    8996        my %zonefiles;  # to be a hash of file handles.
     
    97104          $zfilepath =~ s,[^\w./-],_,g;
    98105          open $zonefiles{$loc}, ">", $zfilepath;
    99           printf {$zonefiles{$loc}} "; %s in view %s exported %s\n", $arpazone, $loc, scalar(localtime);
    100 print "open zonefile for '$loc', '$zfilepath'\n";
     106          printf {$zonefiles{$loc}} "; %s in view %s exported %s\n", $arpazone, $loc, scalar(localtime)
     107            or die "Error writing SOA [$zone, '$loc']: $!\n";;
    101108        }
    102109
     
    105112        my (@zsoa) = $soasth->fetchrow_array();
    106113##fixme: do we even need @loclist passed in?
    107         printrec_bind(\%zonefiles, $zsoa[7], 'y', \%recflags, $revzone,
     114        printrec_bind(\%zonefiles, \@loclist, $zsoa[7], 'y', \%recflags, $revzone,
    108115          $zsoa[0],$zsoa[1],$zsoa[2],$zsoa[3],$zsoa[4],$zsoa[5],$zsoa[6],$zsoa[8],'');
    109116
     
    139146          }
    140147
    141           printrec_bind($zonefilehandle, $recid, 'y', \%recflags, $revzone,
     148          printrec_bind(\%zonefiles, \@loclist, $recid, 'y', \%recflags, $revzone,
    142149            $host, $type, $val, $dist, $weight, $port, $ttl, $loc, $stamp, $expires, $stampactive);
    143150
     
    222229
    223230#  my ($zonefiles, $recid, $revrec, $loclist, $zone, $host, $type, $val, $distance, $weight, $port, $ttl,
    224   my ($zonefiles, $recid, $revrec, $recflags, $zone, $host, $type, $val, $distance, $weight, $port, $ttl,
     231  my ($zonefiles, $loclist, $recid, $revrec, $recflags, $zone, $host, $type, $val, $distance, $weight, $port, $ttl,
    225232        $loc, $stamp, $expires, $stampactive) = @_;
     233
     234# make sure "global" records get into all the right per-view zone files, without having to do this loop in each record-print location
     235##fixme:  maybe exclude the template types?  those may be more expensive to export
     236## *ponder*  may be more efficient to loop in each record print due to substitution and manipulation from stored data to formal
     237## record for .arpa zones for all records
     238  if ($loc eq '') {
     239    foreach my $subloc (@{$loclist}) {
     240      printrec_bind($zonefiles, $loclist, $recid, $revrec, $recflags, $zone, $host, $type, $val, $distance, $weight, $port, $ttl,
     241        $subloc, $stamp, $expires, $stampactive);
     242    }
     243  }
    226244
    227245  # Just In Case something is lingering in the DB
     
    317335          print {$zonefiles->{$loc}} "$val.".DNSDB::_ZONE($zone, 'ZONE', 'r', '.').'.in-addr.arpa'.
    318336                "       $ttl    IN      PTR     $host\n"
    319                 or die $!;
     337            or die $!;
    320338        } else {
    321339          # not going to care about strange results if $val is not an IP value and is resolveable in DNS
     
    323341          print {$zonefiles->{$loc}} DNSDB::_ZONE($val, 'ZONE', 'r', '.').($val->{isv6} ? '.ip6.arpa' : '.in-addr.arpa').
    324342                "       $ttl    IN      PTR     $host\n"
    325                 or die $!;
     343            or die $!;
    326344
    327345        }
Note: See TracChangeset for help on using the changeset viewer.