- Timestamp:
- 06/08/12 18:11:20 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r337 r339 4023 4023 my $domsth = $dbh->prepare("SELECT domain_id,domain,status FROM domains WHERE status=1"); 4024 4024 my $recsth = $dbh->prepare("SELECT host,type,val,distance,weight,port,ttl,record_id ". 4025 "FROM records WHERE domain_id=? ");4025 "FROM records WHERE domain_id=? AND NOT type=65283"); 4026 4026 $domsth->execute(); 4027 4027 while (my ($domid,$dom,$domstat) = $domsth->fetchrow_array) { … … 4089 4089 my @o = ($tmp =~ /^(..)(..)$/); # split into octets 4090 4090 return sprintf "\\%0.3o\\%0.3o", hex($o[0]), hex($o[1]);; 4091 } 4092 4093 ## WARNING: This works to export even the whole Internet's worth of IP space... 4094 ## if you have the disk/RAM to handle the dataset, and you call this sub based on /16-sized chunks 4095 ## A /16 took ~3 seconds with a handful of separate records; adding a /8 pushed export time out to ~13m:40s 4096 ## 0/0 is estimated to take ~54 hours and ~256G of disk 4097 ## RAM usage depends on how many non-template entries you have in the set. 4098 ## This should probably be done on record addition rather than export; large blocks may need to be done in a 4099 ## forked process 4100 sub __publish_subnet { 4101 my $sub = shift; 4102 my $recflags = shift; 4103 my $hpat = shift; 4104 my $fh = shift; 4105 my $ttl = shift; 4106 my $stamp = shift; 4107 my $loc = shift; 4108 my $ptronly = shift || 0; 4109 4110 my $iplist = $sub->splitref(32); 4111 foreach (@$iplist) { 4112 my $ip = $_->addr; 4113 # make as if we split the non-octet-aligned block into octet-aligned blocks as with SOA 4114 next if $ip =~ /\.(0|255)$/; 4115 next if $$recflags{$ip}; 4116 $$recflags{$ip}++; 4117 my $rec = $hpat; # start fresh with the template for each IP 4118 _template4_expand(\$rec, $ip); 4119 print $fh ($ptronly ? "^"._ZONE($_, 'ZONE.in-addr.arpa', 'r', '.').":$rec" : "=$rec:$ip"). 4120 ":$ttl:$stamp:$loc\n"; 4121 } 4091 4122 } 4092 4123 … … 4250 4281 } elsif ($type == 65282) { # PTR template 4251 4282 4252 ##work4253 4283 # only useful for v4 with standard DNS software, since this expands all 4254 4284 # IPs in $zone (or possibly $val?) with autogenerated records … … 4256 4286 return if $val->{isv6}; 4257 4287 4258 my $iplist = $val->hostenumref; 4259 foreach (@$iplist) { 4260 my $ip = $_->addr; 4261 # make as if we split the non-octet-aligned block into octet-aligned blocks as with SOA 4262 next if $ip =~ /\.(0|255)$/; 4263 next if $$recflags{$ip}; 4264 $$recflags{$ip}++; 4265 my $rec = $host; # start fresh with the template for each IP 4266 _template4_expand(\$rec, $ip); 4267 print $datafile "^"._ZONE($_, 'ZONE.in-addr.arpa', 'r', '.').":$rec:$ttl:$stamp:$loc\n"; 4288 if ($val->masklen <= 16) { 4289 foreach my $sub ($val->split(16)) { 4290 __publish_subnet($sub, $recflags, $host, $datafile, $ttl, $stamp, $loc, 1); 4291 } 4292 } else { 4293 __publish_subnet($val, $recflags, $host, $datafile, $ttl, $stamp, $loc, 1); 4268 4294 } 4269 4295 … … 4273 4299 # Just In Case. An A+PTR should be impossible to add to a v6 revzone via API. 4274 4300 return if $val->{isv6}; 4275 my $iplist = $val->hostenumref; 4276 foreach (@$iplist) { 4277 my $ip = $_->addr; 4278 # make as if we split the non-octet-aligned block into octet-aligned blocks as with SOA 4279 next if $ip =~ /\.(0|255)$/; 4280 next if $$recflags{$ip}; 4281 $$recflags{$ip}++; 4282 my $rec = $host; # start fresh with the template for each IP 4283 _template4_expand(\$rec, $ip); 4284 print $datafile "=$rec:$ip:$ttl:$stamp:$loc\n"; 4301 4302 if ($val->masklen <= 16) { 4303 foreach my $sub ($val->split(16)) { 4304 __publish_subnet($sub, $recflags, $host, $datafile, $ttl, $stamp, $loc, 0); 4305 } 4306 } else { 4307 __publish_subnet($val, $recflags, $host, $datafile, $ttl, $stamp, $loc, 0); 4285 4308 } 4286 4309
Note:
See TracChangeset
for help on using the changeset viewer.