Changeset 329
- Timestamp:
- 05/09/12 16:48:23 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r328 r329 3959 3959 ##fixme: slurp up further options to specify particular zone(s) to export 3960 3960 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 4021 sub _printrec_tiny { 4022 my ($datafile,$revrec,$recflags,$zone,$host,$type,$val,$dist,$weight,$port,$ttl,$loc,$stamp) = @_; 4023 3961 4024 ## Convert a bare number into an octal-coded pair of octets. 3962 4025 # Take optional arg to indicate a decimal or hex input. Defaults to hex. … … 3970 4033 } 3971 4034 3972 ##fixme: fail if $datafile isn't an open, writable file3973 3974 # easy case - export all evarything3975 # not-so-easy case - export item(s) specified3976 # todo: figure out what kind of list we use to export items3977 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 TAI643992 # ~~ 2^62 + time()3993 my $stamp = '';3994 3995 # raw packet in unknown format: first byte indicates length3996 # of remaining data, allows up to 255 raw bytes3997 3998 4035 ##fixme? append . to all host/val hostnames 3999 4036 if ($typemap{$type} eq 'SOA') { … … 4005 4042 my ($email, $primary) = (split /:/, $host)[0,1]; 4006 4043 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"; 4008 4045 4009 4046 } elsif ($typemap{$type} eq 'A') { … … 4118 4155 } # record type if-else 4119 4156 4120 } # while ($recsth) 4121 } # while ($domsth) 4122 } # end __export_tiny() 4157 } # end _printrec_tiny() 4123 4158 4124 4159
Note:
See TracChangeset
for help on using the changeset viewer.