Changeset 849


Ignore:
Timestamp:
09/01/22 13:17:46 (20 months ago)
Author:
Kris Deugau
Message:

/trunk

BIND export, unwinding dev saves, 2 of many many

  • Start stubbing out reverse zone loop
  • Add a templatable variable for BIND export pathnames
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB/ExportBIND.pm

    r848 r849  
    3030  my $dbh = $self->{dbh};
    3131
     32  # to be a hash of views/locations, containing lists of zones
     33  my %viewzones;
     34
    3235  # allow for future exports of subgroups of records
    33   my $viewlist = $dnsdb->getLocList(curgroup => 1);
     36  my $viewlist = $self->getLocList(curgroup => 1);
    3437
    35   # Write the view list to a configuration fragment
     38  # Fetch active zone list
     39  my $revsth = $self->{dbh}->prepare("SELECT rdns_id,revnet,status,changed,default_location FROM revzones WHERE status=1 ".
     40        "ORDER BY masklen(revnet) DESC, rdns_id");
     41  # Unflag changed zones, so we can maybe cache the export and not redo everything every time
     42  my $zonesth = $self->{dbh}->prepare("UPDATE revzones SET changed='n' WHERE rdns_id=?");
     43  $revsth->execute();
     44  while (my ($revid,$revzone,$revstat,$changed,$defloc) = $revsth->fetchrow_array) {
     45    # fetch a list of views/locations present in the zone.  we need to publish a file for each one.
     46    # in the event that no locations are present (~~ $viewlist is empty), /%view collapses to nothing in the zone path
     47    my (@loclist) = $self->{dbh}->selectrow_array("SELECT DISTINCT location FROM records WHERE rdns_id = ?", undef, $revid);
     48    push @loclist, $defloc;
     49    my $zonepath = $self->{bind_export_zone_path};
     50    my %zonefiles;  # to be a list of file handles.
     51##fixme:  convert logical revzone into .arpa name
     52    foreach my $loc (@loclist) {
     53      local $zonepath =~ s/\%view/$loc/;
     54print "open $zonefiles{$loc}, $zonepath\n";
     55    }
     56
     57  } # revsth->fetch
     58
     59
     60  # Write the view configuration last, because otherwise we have to be horribly inefficient
     61  # at figuring out which zones are visible/present in which views
    3662  if ($viewlist) {
    3763    foreach my $view (@{$viewlist}) {
     
    4773         print "  match-clients { ".join("; ", split(/[\s,]+/, $view->{iplist}))."; };\n";
    4874      } else {
    49 #         print BINDCONF "  match-clients { any; };\n"
    50          print "  match-clients { any; };\n"
     75#         print BINDCONF "  match-clients { any; };\n";
     76         print "  match-clients { any; };\n";
     77      }
     78      foreach my $zone (@{$viewzones{$view->{location}}}) {
     79##fixme:  notify settings, maybe per-zone?
     80        print qq(  zone "$zone" IN {\n\ttype master;\n\tnotify no;\n\tfile "db.$zone";\n  };\n);
    5181      }
    5282      print "};\n\n";
  • trunk/dnsdb.conf

    r798 r849  
    2727#  the DB or read from the existing cache file.
    2828#force_refresh = 1
     29
     30## BIND export options
     31#bind_export_zone_path = /var/named/zones/%view/db.%zone
    2932
    3033## DNS data template options
Note: See TracChangeset for help on using the changeset viewer.