Changeset 854 for trunk/DNSDB


Ignore:
Timestamp:
09/15/22 16:03:14 (2 years ago)
Author:
Kris Deugau
Message:

/trunk

BIND export, unwinding dev saves, 6 of many many

  • Start fleshing out actual record output blocks with SOA, largely copy-pasted from _printrec_tiny() in DNSDB.pm
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB/ExportBIND.pm

    r853 r854  
    9191        }
    9292
    93 
    9493        # need to fetch this separately since the rest of the records all (should) have real IPs in val
    9594        $soasth->execute($revid);
    9695        my (@zsoa) = $soasth->fetchrow_array();
    97         $self->_printrec_tiny($zonefilehandle, $zsoa[7], 'y',\%recflags,$revzone,
     96        printrec_bind($zonefilehandle, $zsoa[7], 'y',\%recflags,$revzone,
    9897          $zsoa[0],$zsoa[1],$zsoa[2],$zsoa[3],$zsoa[4],$zsoa[5],$zsoa[6],$zsoa[8],'');
    9998
     
    129128          }
    130129
    131           $self->_printrec_tiny($zonefilehandle, $recid, 'y', \%recflags, $revzone,
     130          printrec_bind($zonefilehandle, $recid, 'y', \%recflags, $revzone,
    132131            $host, $type, $val, $dist, $weight, $port, $ttl, $loc, $stamp, $expires, $stampactive);
    133132
     
    170169
    171170
    172 
    173     $soasth->execute($revid);
    174     my (@zsoa) = $soasth->fetchrow_array();
    175171
    176172  } # revsth->fetch
     
    205201} # export()
    206202
     203
     204# Print individual records in BIND format
     205sub printrec_bind {
     206  my ($zonefiles, $recid, $revrec, $loclist, $zone, $host, $type, $val, $distance, $weight, $port, $ttl,
     207        $recloc, $stamp, $expires, $stampactive) = @_;
     208
     209  # Just In Case something is lingering in the DB
     210  $recloc = '' if !$loc;
     211
     212  ## And now to the records!
     213
     214  if ($typemap{$type} eq 'SOA') {
     215    # host contains pri-ns:responsible
     216    # val is abused to contain refresh:retry:expire:minttl
     217    # let's be explicit about abusing $host and $val
     218    my ($email, $primary) = (split /:/, $host)[0,1];
     219    my ($refresh, $retry, $expire, $min_ttl) = (split /:/, $val)[0,1,2,3];
     220    my $serial = 0;  # fail less horribly than leaving it empty?
     221    if ($revrec eq 'y') {
     222##fixme:  have to publish SOA records for each v4 /24 in sub-/16, and each /16 in sub-/8
     223# what about v6?
     224# -> only need SOA for local chunks offset from reverse delegation boundaries, so v6 is fine
     225# anyone who says they need sub-nibble v6 delegations, at this time, needs their head examined.
     226##fixme?:  alternate SOA serial schemes?
     227      ($serial) = $self->{dbh}->selectrow_array("SELECT zserial FROM revzones WHERE revnet=?", undef, $zone);
     228      $zone = NetAddr::IP->new($zone);
     229      # handle split-n-multiply SOA for off-octet (8 < mask < 16) or (16 < mask < 24) v4 zones
     230      if (!$zone->{isv6} && ($zone->masklen < 24) && ($zone->masklen % 8 != 0)) {
     231        foreach my $szone ($zone->split($zone->masklen + (8 - $zone->masklen % 8))) {
     232          $szone = _ZONE($szone, 'ZONE.in-addr.arpa', 'r', '.');
     233          print $datafile "Z$szone:$primary:$email:$serial:$refresh:$retry:$expire:$min_ttl:$ttl:$stamp:$loc\n"
     234            or die $!;
     235        }
     236        return; # skips "default" bits just below
     237      }
     238      $zone = _ZONE($zone, 'ZONE', 'r', '.').($zone->{isv6} ? '.ip6.arpa' : '.in-addr.arpa');
     239    } else {
     240      # just snarfing the right SOA serial for the zone type
     241##fixme?:  alternate SOA serial schemes?
     242      ($serial) = $self->{dbh}->selectrow_array("SELECT zserial FROM domains WHERE domain=?", undef, $zone);
     243    } # revrec <> 'y'
     244    # suppress a "uninitialized value" warning.  should be impossible but...
     245    # abuse hours as the last digit pair of the serial for simplicity
     246    $serial = strftime("%Y%m%d%H", localtime()) if !$serial;
     247    print $zonefiles{$recloc} "Z$zone:$primary:$email:$serial:$refresh:$retry:$expire:$min_ttl:$ttl:$stamp:$loc\n"
     248      or die $!;
     249  } # SOA
     250
     251} # printrec_bind()
     252
     253
    2072541;
Note: See TracChangeset for help on using the changeset viewer.