- Timestamp:
- 09/29/22 13:59:33 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB/ExportBIND.pm
r872 r873 40 40 my $soasth = $dnsdb->{dbh}->prepare("SELECT host,type,val,distance,weight,port,ttl,record_id,location ". 41 41 "FROM records WHERE rdns_id=? AND type=6"); 42 # record order matters for reverse zones because we need to override larger templates with smaller ones. 42 43 my $recsth = $dnsdb->{dbh}->prepare("SELECT host,type,val,distance,weight,port,ttl,record_id,location,extract(epoch from stamp),expires,stampactive ". 43 44 "FROM records WHERE rdns_id=? AND NOT type=6 ". … … 202 203 $soasth = $dnsdb->{dbh}->prepare("SELECT host,type,val,distance,weight,port,ttl,record_id,location ". 203 204 "FROM records WHERE domain_id=? AND type=6"); 205 # record order doesn't strictly matter, but ordering by conventional zone 206 # file order doesn't really have a lever without tweaking the table structure. 207 # ordering by nominal parent-child label hierarchy (as actually found live 208 # in some AXFRed zone files) would be even hairier. 209 # ordering by record_id has the advantage of consistent order export to export 204 210 $recsth = $dnsdb->{dbh}->prepare("SELECT host,type,val,distance,weight,port,ttl,record_id,location,extract(epoch from stamp),expires,stampactive ". 205 "FROM records WHERE domain_id=? AND NOT type=6 ");211 "FROM records WHERE domain_id=? AND NOT type=6 ORDER BY record_id"); 206 212 # "FROM records WHERE domain_id=? AND type < 65280"); # Just exclude all types relating to rDNS 207 213 … … 280 286 # $zsoa[0],$zsoa[1],$zsoa[2],$zsoa[3],$zsoa[4],$zsoa[5],$zsoa[6],$zsoa[8],''); 281 287 288 } # if force_refresh etc 289 282 290 # tag the zonefile for publication in the view 283 291 push @{$viewzones{$loc}}, $arpazone; … … 287 295 while (my ($host,$type,$val,$dist,$weight,$port,$ttl,$recid,$loc,$stamp,$expires,$stampactive) = $recsth->fetchrow_array) { 288 296 next if $recflags{$recid}; 289 290 # Check for out-of-zone data291 $host = $dom if $host eq '@';292 if ($host !~ /$dom$/i) {293 warn "Not exporting out-of-zone record $host $type $val, $ttl (zone $dom)\n";294 next;295 }296 297 297 298 # Spaces are evil. … … 303 304 $val =~ s/\s+$//; 304 305 } 306 307 # Check for out-of-zone data 308 $host = $dom if $host eq '@'; 309 if ($host !~ /$dom$/i) { 310 warn "Not exporting out-of-zone record $host $type $val, $ttl (zone $dom)\n"; 311 next; 312 } 313 305 314 $recflags{$recid} = 1; 306 315 … … 429 438 # print *{$zonefiles->{$loc}} "$zone $ttl IN SOA $primary $email ( $serial $refresh $retry $expire $min_ttl )\n" 430 439 # or die "couldn't write $zone SOA: $!"; 431 my $recdata = "$zone $ttl IN SOA $primary $email ( $serial $refresh $retry $expire $min_ttl )\n";440 my $recdata = "$zone. $ttl IN SOA $primary $email ( $serial $refresh $retry $expire $min_ttl )\n"; 432 441 recprint($zonefiles, $loclist, $loc, $recdata); 433 442 } # SOA 434 443 435 444 elsif ($typemap{$type} eq 'A') { 436 #($host,$val) = __revswap($host,$val) if $revrec eq 'y';445 ($host,$val) = __revswap($host,$val) if $revrec eq 'y'; 437 446 # print $datafile "+$host:$val:$ttl:$stamp:$loc\n" or die $!; 438 447 # print {$zonefiles->{$loc}} "$host $ttl IN A $val\n" or die $!; 439 my $recdata = "$host $ttl IN A $val\n";448 my $recdata = "$host. $ttl IN A $val\n"; 440 449 recprint($zonefiles, $loclist, $loc, $recdata); 441 450 } # A … … 449 458 # } 450 459 451 # print {$zonefiles->{$loc}} "$zone $ttl IN NS $host\n"; 452 # print "$zone $ttl IN NS $host\n" or die $!; 453 my $recdata = "$zone $ttl IN NS $host\n"; 460 my $val2 = DNSDB::_ZONE($val, 'ZONE', 'r', '.').($val->{isv6} ? '.ip6.arpa' : '.in-addr.arpa'); 461 my $recdata = "$val2. $ttl IN NS $host\n"; 454 462 recprint($zonefiles, $loclist, $loc, $recdata); 455 463 456 464 } else { 457 # print $datafile "\&$host"."::$val:$ttl:$stamp:$loc\n" or die $!; 465 my $recdata = "$host. $ttl IN NS $val.\n" 466 recprint($zonefiles, $loclist, $loc, $recdata); 458 467 } 459 468 } # NS … … 462 471 # ($host,$val) = __revswap($host,$val) if $revrec eq 'y'; 463 472 # print {$zonefiles->{$loc}} "$host $ttl IN AAAA $val\n" or die $!; 464 my $recdata = "$host $ttl IN AAAA $val\n";473 my $recdata = "$host. $ttl IN AAAA $val\n"; 465 474 recprint($zonefiles, $loclist, $loc, $recdata); 466 475 } # AAAA 476 477 elsif ($typemap{$type} eq 'MX') { 478 # ($host,$val) = __revswap($host,$val) if $revrec eq 'y'; 479 # print {$zonefiles->{$loc}} "$host $ttl IN MX $distance $val\n" or die $!; 480 # should arguably swap host and val first, but MX records really don't make any sense in reverse zones, so any silliness that results from finding one doesn't much matter. 481 my $recdata = "$host. $ttl IN MX $distance $val.\n"; 482 recprint($zonefiles, $loclist, $loc, $recdata); 483 } # MX 467 484 468 485 elsif ($typemap{$type} eq 'TXT') { 469 486 # ($host,$val) = __revswap($host,$val) if $revrec eq 'y'; 470 487 # print {$zonefiles->{$loc}} "$host $ttl IN TXT \"$val\"\n" or die $!; 471 my $recdata = "$host $ttl IN TXT \"$val\"\n";488 my $recdata = "$host. $ttl IN TXT \"$val\"\n"; 472 489 recprint($zonefiles, $loclist, $loc, $recdata); 473 490 } # TXT … … 476 493 # ($host,$val) = __revswap($host,$val) if $revrec eq 'y'; 477 494 # print {$zonefiles->{$loc}} "$host $ttl IN CNAME $val\n" or die $!; 478 my $recdata = "$host $ttl IN CNAME $val\n";495 my $recdata = "$host. $ttl IN CNAME $val.\n"; 479 496 recprint($zonefiles, $loclist, $loc, $recdata); 480 497 } # CNAME … … 494 511 } # RP 495 512 496 497 513 elsif ($typemap{$type} eq 'PTR') { 498 514 $$recflags{$val}++; … … 502 518 # someone put in the formal .arpa name. humor them. 503 519 # print {$zonefiles->{$loc}} "$val $ttl IN PTR $host\n" or die $!; 504 my $recdata = "$val $ttl IN PTR $host\n";520 my $recdata = "$val. $ttl IN PTR $host.\n"; 505 521 recprint($zonefiles, $loclist, $loc, $recdata); 506 522 } else { … … 512 528 # " $ttl IN PTR $host\n" 513 529 # or die $!; 514 my $recdata = "$val.".DNSDB::_ZONE($zone, 'ZONE', 'r', '.').".in-addr.arpa $ttl IN PTR $host\n";530 my $recdata = "$val.".DNSDB::_ZONE($zone, 'ZONE', 'r', '.').".in-addr.arpa. $ttl IN PTR $host.\n"; 515 531 recprint($zonefiles, $loclist, $loc, $recdata); 516 532 } else { … … 521 537 # or die $!; 522 538 my $recdata = DNSDB::_ZONE($val, 'ZONE', 'r', '.').($val->{isv6} ? '.ip6.arpa' : '.in-addr.arpa'). 523 " $ttl IN PTR $host\n";539 ". $ttl IN PTR $host.\n"; 524 540 recprint($zonefiles, $loclist, $loc, $recdata); 525 541 } … … 606 622 607 623 # do this conversion once, not (number-of-ips-in-subnet) times 608 my $arpabase = DNSDB::_ZONE($zone, 'ZONE.in-addr.arpa ', 'r', '.');624 my $arpabase = DNSDB::_ZONE($zone, 'ZONE.in-addr.arpa.', 'r', '.'); 609 625 610 626 my $iplist = $sub->splitref(32); … … 643 659 # print $fh "$rec $ttl IN A $ip\n" or die $!; 644 660 # } 645 $recdata = "$lastoct.$arpabase $ttl IN PTR $rec\n"; 661 if ($dnsdb->{bind_export_fqdn}) { 662 $recdata = "$lastoct.$arpabase $ttl IN PTR $rec.\n"; 663 } else { 664 $recdata = "$lastoct $ttl IN PTR $rec.\n"; 665 } 666 646 667 } else { 647 668 # A record, not merged 648 669 # print $fh "=$rec:$ip:$ttl:$stamp:$loc\n" or die $!; 649 670 # print $fh "$rec $ttl IN A $ip\n" or die $!; 650 $recdata = "$rec $ttl IN A $ip\n"; 671 $rec =~ s/\.$zone$// unless $dnsdb->{bind_export_fqdn}; 672 $recdata = "$rec. $ttl IN A $ip\n"; 651 673 } 652 674 # and finally
Note:
See TracChangeset
for help on using the changeset viewer.