Changeset 880 for trunk/DNSDB
- Timestamp:
- 01/19/23 18:09:08 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB/ExportBIND.pm
r878 r880 58 58 while (my ($revid,$revzone,$revstat,$changed,$defloc) = $revsth->fetchrow_array) { 59 59 my $cidr = NetAddr::IP->new($revzone); 60 my $zfile = $cidr->network->addr."-".$cidr->masklen;61 # my $cachefile = "$dnsdb->{exportcache}/$zfile";62 # my $tmpcache = "$dnsdb->{exportcache}/tmp.$zfile.$$";63 my $tmpcache = "tmp.$zfile.$$"; # safety net. don't overwrite a previous known-good file64 60 65 61 ##fixme: convert logical revzone into .arpa name? maybe take a slice of showrev_arpa? … … 85 81 86 82 my $arpazone = DNSDB::_ZONE($cidr, 'ZONE', 'r', '.').($cidr->{isv6} ? '.ip6.arpa' : '.in-addr.arpa'); 83 my $zfile = $cidr->network->addr."-".$cidr->masklen; 84 # my $cachefile = "$dnsdb->{exportcache}/$zfile"; 85 # my $tmpcache = "$dnsdb->{exportcache}/tmp.$zfile.$$"; 86 my $tmpcache = "tmp.$zfile.$$"; # safety net. don't overwrite a previous known-good file 87 87 88 88 ##fixme: need to open separate zone files for aggregated metazones eg /22 or /14 … … 90 90 my $zfilepath = $dnsdb->{bind_export_reverse_zone_path}; 91 91 $zfilepath =~ s/\%view/$loc/; 92 $zfilepath =~ s/\%zone/$ revzone/;92 $zfilepath =~ s/\%zone/$zfile/; 93 93 $zfilepath =~ s/\%arpazone/$arpazone/; 94 94 … … 119 119 my (@zsoa) = $soasth->fetchrow_array(); 120 120 ##fixme: do we even need @loclist passed in? 121 p ublishrec_bind($dnsdb, \%zonefiles, \@loclist, $zsoa[7], 'y', \%recflags, $cidr,121 printrec_bind($dnsdb, \%zonefiles, \@loclist, $zsoa[7], 'y', \%recflags, $cidr, 122 122 $zsoa[0], $zsoa[1], $zsoa[2], $zsoa[3], $zsoa[4], $zsoa[5], $zsoa[6], $loc, ''); 123 123 } # if force_refresh etc … … 158 158 } 159 159 160 p ublishrec_bind($dnsdb, \%zonefiles, \@loclist, $recid, 'y', \%recflags, $revzone,160 printrec_bind($dnsdb, \%zonefiles, \@loclist, $recid, 'y', \%recflags, $revzone, 161 161 $host, $type, $val, $dist, $weight, $port, $ttl, $loc, $stamp, $expires, $stampactive); 162 162 … … 390 390 open BINDCONF, ">", $tmpconf; 391 391 392 foreach my $view (@{$viewlist}, 'common',{ location => 'common', iplist => '' }) {392 foreach my $view (@{$viewlist}, { location => 'common', iplist => '' }) { 393 393 #print Dumper($view); 394 394 print BINDCONF "view $view->{location} {\n"; … … 420 420 421 421 # Print individual records in BIND format 422 sub p ublishrec_bind {422 sub printrec_bind { 423 423 my $dnsdb = shift; 424 424 … … 433 433 if ($loc eq '') { 434 434 foreach my $subloc (@{$loclist}) { 435 p ublishrec_bind($dnsdb, $zonefiles, $loclist, $recid, $revrec, $recflags, $zone, $host, $type, $val,435 printrec_bind($dnsdb, $zonefiles, $loclist, $recid, $revrec, $recflags, $zone, $host, $type, $val, 436 436 $distance, $weight, $port, $ttl, $subloc, $stamp, $expires, $stampactive); 437 437 } … … 466 466 # print *{$zonefiles->{$loc}} "$zone $ttl IN SOA $primary $email ( $serial $refresh $retry $expire $min_ttl )\n" 467 467 # or die "couldn't write $zone SOA: $!"; 468 my $recdata = "$zone. $ttl IN SOA $primary $email ( $serial $refresh $retry $expire $min_ttl )\n"; 469 recprint($zonefiles, $loclist, $loc, $recdata); 468 469 # Prepare the body of the record 470 my $recdata = "$ttl IN SOA $primary $email ( $serial $refresh $retry $expire $min_ttl )\n"; 471 472 # ... and prepend the zone name FQDN 473 if ($revrec eq 'y') { 474 my $zone2 = DNSDB::_ZONE($zone, 'ZONE', 'r', '.').($zone->{isv6} ? '.ip6.arpa' : '.in-addr.arpa'); 475 $recdata = "$zone2. $recdata"; 476 } else { 477 $recdata = "$zone. $recdata"; 478 } 479 480 __recprint($zonefiles, $loclist, $loc, $recdata); 470 481 } # SOA 471 482 … … 475 486 # print {$zonefiles->{$loc}} "$host $ttl IN A $val\n" or die $!; 476 487 my $recdata = "$host. $ttl IN A $val\n"; 477 recprint($zonefiles, $loclist, $loc, $recdata);488 __recprint($zonefiles, $loclist, $loc, $recdata); 478 489 } # A 479 490 … … 487 498 488 499 my $val2 = DNSDB::_ZONE($val, 'ZONE', 'r', '.').($val->{isv6} ? '.ip6.arpa' : '.in-addr.arpa'); 500 $host .= "." if $host !~ /\.$/; 489 501 my $recdata = "$val2. $ttl IN NS $host\n"; 490 recprint($zonefiles, $loclist, $loc, $recdata);502 __recprint($zonefiles, $loclist, $loc, $recdata); 491 503 492 504 } else { 493 505 my $recdata = "$host. $ttl IN NS $val.\n"; 494 recprint($zonefiles, $loclist, $loc, $recdata);506 __recprint($zonefiles, $loclist, $loc, $recdata); 495 507 } 496 508 } # NS … … 500 512 # print {$zonefiles->{$loc}} "$host $ttl IN AAAA $val\n" or die $!; 501 513 my $recdata = "$host. $ttl IN AAAA $val\n"; 502 recprint($zonefiles, $loclist, $loc, $recdata);514 __recprint($zonefiles, $loclist, $loc, $recdata); 503 515 } # AAAA 504 516 … … 508 520 # 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. 509 521 my $recdata = "$host. $ttl IN MX $distance $val.\n"; 510 recprint($zonefiles, $loclist, $loc, $recdata);522 __recprint($zonefiles, $loclist, $loc, $recdata); 511 523 } # MX 512 524 … … 515 527 # print {$zonefiles->{$loc}} "$host $ttl IN TXT \"$val\"\n" or die $!; 516 528 my $recdata = "$host. $ttl IN TXT \"$val\"\n"; 517 recprint($zonefiles, $loclist, $loc, $recdata);529 __recprint($zonefiles, $loclist, $loc, $recdata); 518 530 } # TXT 519 531 … … 522 534 # print {$zonefiles->{$loc}} "$host $ttl IN CNAME $val\n" or die $!; 523 535 my $recdata = "$host. $ttl IN CNAME $val.\n"; 524 recprint($zonefiles, $loclist, $loc, $recdata);536 __recprint($zonefiles, $loclist, $loc, $recdata); 525 537 } # CNAME 526 538 … … 529 541 # print {$zonefiles->{$loc}} "$host $ttl IN SRV $distance $weight $port $val\n" or die $!; 530 542 my $recdata = "$host $ttl IN SRV $distance $weight $port $val.\n"; 531 recprint($zonefiles, $loclist, $loc, $recdata);543 __recprint($zonefiles, $loclist, $loc, $recdata); 532 544 } # SRV 533 545 … … 536 548 # print {$zonefiles->{$loc}} "$host $ttl IN RP $val\n" or die $!; 537 549 my $recdata = "$host. $ttl IN RP $val\n"; 538 recprint($zonefiles, $loclist, $loc, $recdata);550 __recprint($zonefiles, $loclist, $loc, $recdata); 539 551 } # RP 540 552 … … 550 562 # print {$zonefiles->{$loc}} "$val $ttl IN PTR $host\n" or die $!; 551 563 my $recdata = "$val. $ttl IN PTR $host.\n"; 552 recprint($zonefiles, $loclist, $loc, $recdata);564 __recprint($zonefiles, $loclist, $loc, $recdata); 553 565 } else { 554 566 $zone = NetAddr::IP->new($zone); … … 560 572 # or die $!; 561 573 my $recdata = "$val.".DNSDB::_ZONE($zone, 'ZONE', 'r', '.').".in-addr.arpa. $ttl IN PTR $host.\n"; 562 recprint($zonefiles, $loclist, $loc, $recdata);574 __recprint($zonefiles, $loclist, $loc, $recdata); 563 575 } else { 564 576 # not going to care about strange results if $val is not an IP value and is resolveable in DNS … … 569 581 my $recdata = DNSDB::_ZONE($val, 'ZONE', 'r', '.').($val->{isv6} ? '.ip6.arpa' : '.in-addr.arpa'). 570 582 ". $ttl IN PTR $host.\n"; 571 recprint($zonefiles, $loclist, $loc, $recdata);583 __recprint($zonefiles, $loclist, $loc, $recdata); 572 584 } 573 585 } # non-".arpa" $val … … 579 591 # print {$zonefiles->{$loc}} "$host $ttl IN PTR $val\n" or die $!; 580 592 my $recdata = "$host. $ttl IN PTR $val.\n"; 581 recprint($zonefiles, $loclist, $loc, $recdata);593 __recprint($zonefiles, $loclist, $loc, $recdata); 582 594 } 583 595 } # PTR … … 589 601 # $$recflags{$val}++; 590 602 if ($revrec eq 'y') { 591 p ublishrec_bind($dnsdb, $zonefiles, $loclist, $recid, $revrec, $recflags, $zone, $host, 12, $val,603 printrec_bind($dnsdb, $zonefiles, $loclist, $recid, $revrec, $recflags, $zone, $host, 12, $val, 592 604 $distance, $weight, $port, $ttl, $loc, $stamp, $expires, $stampactive); 593 605 # ... but we need to tweak it for this case? so the A record gets published... 594 606 #$$recflags{$val} = 'a+ptr'; 595 607 #print {$zonefiles->{$loc}} "=$host:$val:$ttl:$stamp:$loc\n" or die $!; 596 # p ublishrec_bind($dnsdb, \%zonefiles, $recid, 'y', \@loclist, $revzone,608 # printrec_bind($dnsdb, \%zonefiles, $recid, 'y', \@loclist, $revzone, 597 609 # $host, $type, $val, $dist, $weight, $port, $ttl, $loc, $stamp, $expires, $stampactive); 598 610 # my ($zonefiles, $recid, $revrec, $loclist, $zone, $host, $type, $val, $distance, $weight, $port, $ttl, 599 611 # $loc, $stamp, $expires, $stampactive) = @_; 600 612 } else { 601 p ublishrec_bind($dnsdb, $zonefiles, $loclist, $recid, $revrec, $recflags, $zone, $host, 1, $val,613 printrec_bind($dnsdb, $zonefiles, $loclist, $recid, $revrec, $recflags, $zone, $host, 1, $val, 602 614 $distance, $weight, $port, $ttl, $loc, $stamp, $expires, $stampactive); 603 615 # set a unique flag to skip template expansion for this IP in forward zones … … 617 629 } 618 630 } else { 619 __publish_template_bind($dnsdb, $ sub, $recflags, $host, $zonefiles, $loclist, $ttl, $stamp, $loc, $zone, $revrec);631 __publish_template_bind($dnsdb, $val, $recflags, $host, $zonefiles, $loclist, $ttl, $stamp, $loc, $zone, $revrec); 620 632 } 621 633 } # PTR template … … 631 643 } 632 644 } else { 633 __publish_template_bind($dnsdb, $ sub, $recflags, $host, $zonefiles, $loclist, $ttl, $stamp, $loc, $zone, $revrec);645 __publish_template_bind($dnsdb, $val, $recflags, $host, $zonefiles, $loclist, $ttl, $stamp, $loc, $zone, $revrec); 634 646 } 635 647 } # A+PTR template … … 641 653 } # AAAA+PTR template 642 654 643 } # p ublishrec_bind()655 } # printrec_bind() 644 656 645 657 … … 729 741 } 730 742 # and finally 731 recprint($zonefiles, $loclist, $loc, $recdata);743 __recprint($zonefiles, $loclist, $loc, $recdata); 732 744 } # foreach (@iplist) 733 745 } # __publish_template_bind() … … 736 748 # actual record printing sub 737 749 # loop on the locations here so we don't end up with a huge pot of copypasta 738 sub recprint {750 sub __recprint { 739 751 my ($zonefiles, $loclist, $loc, $recdata) = @_; 740 752 if ($loc eq '') {
Note:
See TracChangeset
for help on using the changeset viewer.