Changeset 869
- Timestamp:
- 09/28/22 15:29:29 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB/ExportBIND.pm
r868 r869 111 111 $soasth->execute($revid); 112 112 my (@zsoa) = $soasth->fetchrow_array(); 113 113 114 ##fixme: do we even need @loclist passed in? 114 p rintrec_bind(\%zonefiles, \@loclist, $zsoa[7], 'y', \%recflags, $revzone,115 $zsoa[0], $zsoa[1],$zsoa[2],$zsoa[3],$zsoa[4],$zsoa[5],$zsoa[6],$zsoa[8],'');115 publishrec_bind(\%zonefiles, \@loclist, $zsoa[7], 'y', \%recflags, $revzone, 116 $zsoa[0], $zsoa[1], $zsoa[2], $zsoa[3], $zsoa[4], $zsoa[5], $zsoa[6], $loc, ''); 116 117 117 118 $recsth->execute($revid); … … 146 147 } 147 148 148 p rintrec_bind(\%zonefiles, \@loclist, $recid, 'y', \%recflags, $revzone,149 publishrec_bind(\%zonefiles, \@loclist, $recid, 'y', \%recflags, $revzone, 149 150 $host, $type, $val, $dist, $weight, $port, $ttl, $loc, $stamp, $expires, $stampactive); 150 151 … … 225 226 226 227 # Print individual records in BIND format 227 sub p rintrec_bind {228 sub publishrec_bind { 228 229 my $dnsdb = shift; 229 230 … … 238 239 if ($loc eq '') { 239 240 foreach my $subloc (@{$loclist}) { 240 p rintrec_bind($zonefiles, $loclist, $recid, $revrec, $recflags, $zone, $host, $type, $val, $distance, $weight, $port, $ttl,241 publishrec_bind($zonefiles, $loclist, $recid, $revrec, $recflags, $zone, $host, $type, $val, $distance, $weight, $port, $ttl, 241 242 $subloc, $stamp, $expires, $stampactive); 242 243 } … … 269 270 # print *{$zonefiles->{$loc}} "Z$zone:$primary:$email:$serial:$refresh:$retry:$expire:$min_ttl:$ttl:$stamp:$loc\n" 270 271 # or die $!; 271 print *{$zonefiles->{$loc}} "$zone $ttl IN SOA $primary $email ( $serial $refresh $retry $expire $min_ttl )\n" 272 or die "couldn't write $zone SOA: $!"; 272 # print *{$zonefiles->{$loc}} "$zone $ttl IN SOA $primary $email ( $serial $refresh $retry $expire $min_ttl )\n" 273 # or die "couldn't write $zone SOA: $!"; 274 my $recdata = "$zone $ttl IN SOA $primary $email ( $serial $refresh $retry $expire $min_ttl )\n"; 275 recprint($zonefiles, $loclist, $loc, $recdata); 273 276 } # SOA 274 277 … … 276 279 # ($host,$val) = __revswap($host,$val) if $revrec eq 'y'; 277 280 # print $datafile "+$host:$val:$ttl:$stamp:$loc\n" or die $!; 278 print {$zonefiles->{$loc}} "$host $ttl IN A $val\n" or die $!; 281 # print {$zonefiles->{$loc}} "$host $ttl IN A $val\n" or die $!; 282 my $recdata = "$host $ttl IN A $val\n"; 283 recprint($zonefiles, $loclist, $loc, $recdata); 279 284 } # A 280 285 … … 288 293 289 294 # print {$zonefiles->{$loc}} "$zone $ttl IN NS $host\n"; 290 print "$zone $ttl IN NS $host\n" or die $!; 295 # print "$zone $ttl IN NS $host\n" or die $!; 296 my $recdata = "$zone $ttl IN NS $host\n"; 297 recprint($zonefiles, $loclist, $loc, $recdata); 291 298 292 299 } else { … … 297 304 elsif ($typemap{$type} eq 'AAAA') { 298 305 # ($host,$val) = __revswap($host,$val) if $revrec eq 'y'; 299 print {$zonefiles->{$loc}} "$host $ttl IN AAAA $val\n" or die $!; 306 # print {$zonefiles->{$loc}} "$host $ttl IN AAAA $val\n" or die $!; 307 my $recdata = "$host $ttl IN AAAA $val\n"; 308 recprint($zonefiles, $loclist, $loc, $recdata); 300 309 } # AAAA 301 310 302 311 elsif ($typemap{$type} eq 'TXT') { 303 312 # ($host,$val) = __revswap($host,$val) if $revrec eq 'y'; 304 print {$zonefiles->{$loc}} "$host $ttl IN TXT \"$val\"\n" or die $!; 313 # print {$zonefiles->{$loc}} "$host $ttl IN TXT \"$val\"\n" or die $!; 314 my $recdata = "$host $ttl IN TXT \"$val\"\n"; 315 recprint($zonefiles, $loclist, $loc, $recdata); 305 316 } # TXT 306 317 307 318 elsif ($typemap{$type} eq 'CNAME') { 308 319 # ($host,$val) = __revswap($host,$val) if $revrec eq 'y'; 309 print {$zonefiles->{$loc}} "$host $ttl IN CNAME $val\n" or die $!; 320 # print {$zonefiles->{$loc}} "$host $ttl IN CNAME $val\n" or die $!; 321 my $recdata = "$host $ttl IN CNAME $val\n"; 322 recprint($zonefiles, $loclist, $loc, $recdata); 310 323 } # CNAME 311 324 312 325 elsif ($typemap{$type} eq 'SRV') { 313 326 # ($host,$val) = __revswap($host,$val) if $revrec eq 'y'; 314 print {$zonefiles->{$loc}} "$host $ttl IN SRV $distance $weight $port $val\n" or die $!; 327 # print {$zonefiles->{$loc}} "$host $ttl IN SRV $distance $weight $port $val\n" or die $!; 328 my $recdata = "$host $ttl IN SRV $distance $weight $port $val\n"; 329 recprint($zonefiles, $loclist, $loc, $recdata); 315 330 } # SRV 316 331 317 332 elsif ($typemap{$type} eq 'RP') { 318 333 # ($host,$val) = __revswap($host,$val) if $revrec eq 'y'; 319 print {$zonefiles->{$loc}} "$host $ttl IN RP $val\n" or die $!; 334 # print {$zonefiles->{$loc}} "$host $ttl IN RP $val\n" or die $!; 335 my $recdata = "$host $ttl IN RP $val\n"; 336 recprint($zonefiles, $loclist, $loc, $recdata); 320 337 } # RP 321 338 … … 327 344 if ($val =~ /\.arpa$/) { 328 345 # someone put in the formal .arpa name. humor them. 329 print {$zonefiles->{$loc}} "$val $ttl IN PTR $host\n" or die $!; 346 # print {$zonefiles->{$loc}} "$val $ttl IN PTR $host\n" or die $!; 347 my $recdata = "$val $ttl IN PTR $host\n"; 348 recprint($zonefiles, $loclist, $loc, $recdata); 330 349 } else { 331 350 $zone = NetAddr::IP->new($zone); … … 333 352 # sub-octet v4 zone 334 353 ($val) = ($val =~ /\.(\d+)$/); 335 print {$zonefiles->{$loc}} "$val.".DNSDB::_ZONE($zone, 'ZONE', 'r', '.').'.in-addr.arpa'. 336 " $ttl IN PTR $host\n" 337 or die $!; 354 # print {$zonefiles->{$loc}} "$val.".DNSDB::_ZONE($zone, 'ZONE', 'r', '.').'.in-addr.arpa'. 355 # " $ttl IN PTR $host\n" 356 # or die $!; 357 my $recdata = "$val.".DNSDB::_ZONE($zone, 'ZONE', 'r', '.').".in-addr.arpa $ttl IN PTR $host\n"; 358 recprint($zonefiles, $loclist, $loc, $recdata); 338 359 } else { 339 360 # not going to care about strange results if $val is not an IP value and is resolveable in DNS 340 361 $val = NetAddr::IP->new($val); 341 print {$zonefiles->{$loc}} DNSDB::_ZONE($val, 'ZONE', 'r', '.').($val->{isv6} ? '.ip6.arpa' : '.in-addr.arpa'). 342 " $ttl IN PTR $host\n" 343 or die $!; 344 362 # print {$zonefiles->{$loc}} DNSDB::_ZONE($val, 'ZONE', 'r', '.').($val->{isv6} ? '.ip6.arpa' : '.in-addr.arpa'). 363 # " $ttl IN PTR $host\n" 364 # or die $!; 365 my $recdata = DNSDB::_ZONE($val, 'ZONE', 'r', '.').($val->{isv6} ? '.ip6.arpa' : '.in-addr.arpa'). 366 " $ttl IN PTR $host\n"; 367 recprint($zonefiles, $loclist, $loc, $recdata); 345 368 } 346 369 } # non-".arpa" $val … … 350 373 # in reverse zones... OTOH we can't validate them any which way, so we cross our 351 374 # fingers and close our eyes and make it Someone Else's Problem. 352 print {$zonefiles->{$loc}} "^$host:$val:$ttl:$stamp:$loc\n" or die $!; 375 # print {$zonefiles->{$loc}} "$host $ttl IN PTR $val\n" or die $!; 376 my $recdata = "$host $ttl IN PTR $val\n"; 377 recprint($zonefiles, $loclist, $loc, $recdata); 353 378 } 354 379 } # PTR … … 359 384 $$recflags{$val}++; 360 385 if ($revrec eq 'y') { 361 p rintrec_bind($zonefiles, $recid, $revrec, $recflags, $zone, $host, 12, $val, $distance, $weight, $port, $ttl,386 publishrec_bind($zonefiles, $loclist, $recid, $revrec, $recflags, $zone, $host, 12, $val, $distance, $weight, $port, $ttl, 362 387 $loc, $stamp, $expires, $stampactive); 363 388 #print {$zonefiles->{$loc}} "=$host:$val:$ttl:$stamp:$loc\n" or die $!; 364 # p rintrec_bind(\%zonefiles, $recid, 'y', \@loclist, $revzone,389 # publishrec_bind(\%zonefiles, $recid, 'y', \@loclist, $revzone, 365 390 # $host, $type, $val, $dist, $weight, $port, $ttl, $loc, $stamp, $expires, $stampactive); 366 391 # my ($zonefiles, $recid, $revrec, $loclist, $zone, $host, $type, $val, $distance, $weight, $port, $ttl, 367 392 # $loc, $stamp, $expires, $stampactive) = @_; 368 393 } else { 369 p rintrec_bind($zonefiles, $recid, $revrec, $recflags, $zone, $host, 1, $val, $distance, $weight, $port, $ttl,394 publishrec_bind($zonefiles, $loclist, $recid, $revrec, $recflags, $zone, $host, 1, $val, $distance, $weight, $port, $ttl, 370 395 $loc, $stamp, $expires, $stampactive); 371 396 } … … 380 405 if ($val->masklen <= 16) { 381 406 foreach my $sub ($val->split(16)) { 382 __publish_template_bind($sub, $recflags, $host, $zonefiles ->{$loc}, $ttl, $stamp, $loc, $zone, 1);407 __publish_template_bind($sub, $recflags, $host, $zonefiles, $loclist, $ttl, $stamp, $loc, $zone, $revrec); 383 408 } 384 409 } else { 385 __publish_template_bind($ val, $recflags, $host, $zonefiles->{$loc}, $ttl, $stamp, $loc, $zone, 1);410 __publish_template_bind($sub, $recflags, $host, $zonefiles, $loclist, $ttl, $stamp, $loc, $zone, $revrec); 386 411 } 387 412 } # PTR template … … 394 419 if ($val->masklen < 16) { 395 420 foreach my $sub ($val->split(16)) { 396 __publish_template_bind($sub, $recflags, $host, $zonefiles ->{$loc}, $ttl, $stamp, $loc, $zone, 'y');421 __publish_template_bind($sub, $recflags, $host, $zonefiles, $loclist, $ttl, $stamp, $loc, $zone, $revrec); 397 422 } 398 423 } else { 399 __publish_template_bind($ val, $recflags, $host, $zonefiles->{$loc}, $ttl, $stamp, $loc, $zone, 'y');424 __publish_template_bind($sub, $recflags, $host, $zonefiles, $loclist, $ttl, $stamp, $loc, $zone, $revrec); 400 425 } 401 426 } # A+PTR template … … 407 432 } # AAAA+PTR template 408 433 409 } # p rintrec_bind()434 } # publishrec_bind() 410 435 411 436 … … 414 439 my $recflags = shift; 415 440 my $hpat = shift; 416 my $fh = shift; 441 my $zonefiles = shift; 442 my $loclist = shift; 417 443 my $ttl = shift; 418 444 my $stamp = shift; … … 449 475 ##fixme: trim merged record type voodoo. "if ($ptrflag) {} else {}" ? 450 476 # if ($ptrflag || $zone->masklen > 24) { 451 if ($revrec eq 'y' || $zone->masklen > 24) { 477 my $recdata; 478 if ($revrec eq 'y') { 479 # || $zone->masklen > 24) { 452 480 # print $fh "^$lastoct.$arpabase:$rec:$ttl:$stamp:$loc\n" or die $!; 453 481 ##fixme: use $ORIGIN instead? make the FQDN output switchable-optional? 454 print $fh "$lastoct.$arpabase $ttl IN PTR $rec\n" or die $!; 455 # if (!$ptrflag) { 456 if ($revrec ne 'y') { 482 # print $fh "$lastoct.$arpabase $ttl IN PTR $rec\n" or die $!; 483 # if ($revrec ne 'y') { 457 484 # print a separate A record. Arguably we could use an = record here instead. 458 485 # print $fh "+$rec:$ip:$ttl:$stamp:$loc\n" or die $!; 459 print $fh "$rec $ttl IN A $ip\n" or die $!; 460 } 486 # print $fh "$rec $ttl IN A $ip\n" or die $!; 487 # } 488 $recdata = "$lastoct.$arpabase $ttl IN PTR $rec\n"; 461 489 } else { 462 490 # A record, not merged 463 491 # print $fh "=$rec:$ip:$ttl:$stamp:$loc\n" or die $!; 464 print $fh "$rec $ttl IN A $ip\n" or die $!; 465 } 492 # print $fh "$rec $ttl IN A $ip\n" or die $!; 493 $recdata = "$rec $ttl IN A $ip\n"; 494 } 495 # and finally 496 recprint($zonefiles, $loclist, $loc, $recdata); 497 } # foreach (@iplist) 498 } # __publish_template_bind() 499 500 501 # actual record printing sub 502 # loop on the locations here so we don't end up with a huge pot of copypasta 503 sub recprint { 504 my ($zonefiles, $loclist, $loc, $recdata) = @_; 505 if ($loc eq '') { 506 # "common" record visible in all locations 507 foreach my $rloc (@{$loclist}) { 508 print {$zonefiles->{$rloc}} $recdata or die $!; 509 } 510 } else { 511 # record with specific location tagged 512 print {$zonefiles->{$loc}} $recdata or die $!; 466 513 } 467 } # __publish_template_bind()514 } 468 515 469 516 1;
Note:
See TracChangeset
for help on using the changeset viewer.