Changeset 329


Ignore:
Timestamp:
05/09/12 16:48:23 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Checkpoint, update export process to handle reverse zones. See #26.

  • Split off actual record-printing to its own sub
  • Duplicate domain loop for revzones
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r328 r329  
    39593959##fixme: slurp up further options to specify particular zone(s) to export
    39603960
     3961##fixme: fail if $datafile isn't an open, writable file
     3962
     3963  # easy case - export all evarything
     3964  # not-so-easy case - export item(s) specified
     3965  # todo:  figure out what kind of list we use to export items
     3966
     3967# raw packet in unknown format:  first byte indicates length
     3968# of remaining data, allows up to 255 raw bytes
     3969
     3970  # tracking hash so we don't double-export A+PTR or AAAA+PTR records.
     3971  my %recflags;
     3972
     3973  my $domsth = $dbh->prepare("SELECT domain_id,domain,status FROM domains WHERE status=1");
     3974  my $recsth = $dbh->prepare("SELECT host,type,val,distance,weight,port,ttl ".
     3975        "FROM records WHERE domain_id=?");
     3976  $domsth->execute();
     3977  while (my ($domid,$dom,$domstat) = $domsth->fetchrow_array) {
     3978    $recsth->execute($domid);
     3979    while (my ($host,$type,$val,$dist,$weight,$port,$ttl) = $recsth->fetchrow_array) {
     3980##fixme:  need to store location in the db, and retrieve it here.
     3981# temporarily hardcoded to empty so we can include it further down.
     3982      my $loc = '';
     3983
     3984##fixme:  record validity timestamp. tinydns supports fiddling with timestamps.
     3985# note $ttl must be set to 0 if we want to use tinydns's auto-expiring timestamps.
     3986# timestamps are TAI64
     3987# ~~ 2^62 + time()
     3988      my $stamp = '';
     3989
     3990      _printrec_tiny($datafile,'n',\%recflags,$dom,$host,$type,$val,$dist,$weight,$port,$ttl,$loc,$stamp);
     3991
     3992    } # while ($recsth)
     3993  } # while ($domsth)
     3994
     3995  my $revsth = $dbh->prepare("SELECT rdns_id,revnet,status FROM revzones WHERE status=1");
     3996  $recsth = $dbh->prepare("SELECT host,type,val,distance,weight,port,ttl ".
     3997        "FROM records WHERE rdns_id=?");
     3998  $revsth->execute();
     3999  while (my ($revid,$revzone,$revstat) = $revsth->fetchrow_array) {
     4000    $recsth->execute($revid);
     4001    while (my ($host,$type,$val,$dist,$weight,$port,$ttl) = $recsth->fetchrow_array) {
     4002##fixme:  need to store location in the db, and retrieve it here.
     4003# temporarily hardcoded to empty so we can include it further down.
     4004      my $loc = '';
     4005
     4006##fixme:  record validity timestamp. tinydns supports fiddling with timestamps.
     4007# note $ttl must be set to 0 if we want to use tinydns's auto-expiring timestamps.
     4008# timestamps are TAI64
     4009# ~~ 2^62 + time()
     4010      my $stamp = '';
     4011
     4012      _printrec_tiny($datafile,'y',\%recflags,$revzone,$host,$type,$val,$dist,$weight,$port,$ttl,$loc,$stamp);
     4013
     4014    } # while ($recsth)
     4015  } # while ($domsth)
     4016
     4017} # end __export_tiny()
     4018
     4019
     4020# Utility sub for __export_tiny above
     4021sub _printrec_tiny {
     4022  my ($datafile,$revrec,$recflags,$zone,$host,$type,$val,$dist,$weight,$port,$ttl,$loc,$stamp) = @_;
     4023
    39614024  ## Convert a bare number into an octal-coded pair of octets.
    39624025  # Take optional arg to indicate a decimal or hex input.  Defaults to hex.
     
    39704033  }
    39714034
    3972 ##fixme: fail if $datafile isn't an open, writable file
    3973 
    3974   # easy case - export all evarything
    3975   # not-so-easy case - export item(s) specified
    3976   # todo:  figure out what kind of list we use to export items
    3977 
    3978   my $domsth = $dbh->prepare("SELECT domain_id,domain,status FROM domains WHERE status=1");
    3979   my $recsth = $dbh->prepare("SELECT host,type,val,distance,weight,port,ttl ".
    3980         "FROM records WHERE domain_id=?");
    3981   $domsth->execute();
    3982   while (my ($domid,$dom,$domstat) = $domsth->fetchrow_array) {
    3983     $recsth->execute($domid);
    3984     while (my ($host,$type,$val,$dist,$weight,$port,$ttl) = $recsth->fetchrow_array) {
    3985 ##fixme:  need to store location in the db, and retrieve it here.
    3986 # temporarily hardcoded to empty so we can include it further down.
    3987 my $loc = '';
    3988 
    3989 ##fixme:  record validity timestamp. tinydns supports fiddling with timestamps.
    3990 # note $ttl must be set to 0 if we want to use tinydns's auto-expiring timestamps.
    3991 # timestamps are TAI64
    3992 # ~~ 2^62 + time()
    3993 my $stamp = '';
    3994 
    3995 # raw packet in unknown format:  first byte indicates length
    3996 # of remaining data, allows up to 255 raw bytes
    3997 
    39984035##fixme?  append . to all host/val hostnames
    39994036      if ($typemap{$type} eq 'SOA') {
     
    40054042        my ($email, $primary) = (split /:/, $host)[0,1];
    40064043        my ($refresh, $retry, $expire, $min_ttl) = (split /:/, $val)[0,1,2,3];
    4007         print $datafile "Z$dom:$primary:$email"."::$refresh:$retry:$expire:$min_ttl:$ttl:$stamp:$loc\n";
     4044        print $datafile "Z$zone:$primary:$email"."::$refresh:$retry:$expire:$min_ttl:$ttl:$stamp:$loc\n";
    40084045
    40094046      } elsif ($typemap{$type} eq 'A') {
     
    41184155      } # record type if-else
    41194156
    4120     } # while ($recsth)
    4121   } # while ($domsth)
    4122 } # end __export_tiny()
     4157} # end _printrec_tiny()
    41234158
    41244159
Note: See TracChangeset for help on using the changeset viewer.