Ignore:
Timestamp:
08/21/25 16:57:47 (15 hours ago)
Author:
Kris Deugau
Message:

/branches/secondaryzones

Fill out autoaxfr branch of tinydns secondary zone export. See #86.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/secondaryzones/DNSDB.pm

    r927 r928  
    69046904  } # while ($domsth)
    69056905
     6906  my $sec_sth = $dbh->prepare("SELECT secondary_id FROM secondary_zones WHERE zone = ? AND status = 1");
     6907
     6908  # update secondary zones as needed
     6909  if ($self->{tiny_secondary_method} eq 'autoaxfr') {
     6910    # secondary zone AXFR managed by Matt Armstrong's autoaxfr (http://www.lickey.com/autoaxfr/)
     6911
     6912    my $secondary_path = $self->{autoaxfr_root}.'/slaves/';
     6913##fixme:  arguably should be configurable, since this is not part of autoaxfr
     6914    my $secondary_removed = $self->{autoaxfr_root}.'/slaves.removed/';
     6915    # remove secondaries no longer in DB
     6916    opendir AUTOROOT, $secondary_path;
     6917    my %activesecondaries;
     6918    while (my $zone = readdir AUTOROOT) {
     6919      next if $zone eq '.' || $zone eq '..';
     6920
     6921      $sec_sth->execute($zone);
     6922      my ($zid) = $sec_sth->fetchrow_array;
     6923      if (!$zid) {
     6924        # zone removed/disabled
     6925        rename $secondary_path.$zone, $secondary_removed.$zone;
     6926      } else {
     6927        open PRIMARY, "<$secondary_path/$zone";
     6928        my @primary;
     6929        foreach (<PRIMARY>) {
     6930          chomp;
     6931          push @primary, $_;
     6932        }
     6933        $activesecondaries{$zone} = join ',', sort @primary;
     6934      } # remove/refresh existing entries
     6935    } # readdir AUTOROOT
     6936
     6937    # Now we iterate the active zones in dnsadmin to update existing ones or add new ones
     6938    $sec_sth = $dbh->prepare("SELECT zone,primaryserver FROM secondary_zones WHERE status = 1") or print $dbh->errstr;
     6939    $sec_sth->execute or print $dbh->errstr;
     6940    while (my ($zone, $primary) = $sec_sth->fetchrow_array) {
     6941      my @plist = split ',', $primary;
     6942      # need deterministic comparison
     6943      my $pcompare = join ',', sort @plist;
     6944      next if $activesecondaries{$zone} && $activesecondaries{$zone} eq $pcompare;
     6945      # primary list is either different or zone is new/recently-(re-)enabled
     6946      open PRIMARY, ">$secondary_path/$zone";
     6947      foreach my $p (@plist) {
     6948        print PRIMARY "$p\n";
     6949      }
     6950      close PRIMARY;
     6951    }
     6952
     6953  } elsif ($self->{tiny_secondary_method} eq 'dnsadmin') {
     6954    # secondary zone AXFR managed by dnsadmin
     6955
     6956  } else {
     6957    # Your llama is on fire
     6958  }
     6959
    69066960  return 1;
    69076961} # end __export_tiny()
Note: See TracChangeset for help on using the changeset viewer.