Changeset 303
- Timestamp:
- 04/13/12 18:14:26 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r302 r303 3294 3294 return ('FAIL', ($rev eq 'n' ? 'Domain' : 'Reverse zone')." already exists") if $zone_id; 3295 3295 3296 # little local utility sub to swap $val and $host for revzone records. 3297 sub _revswap { 3298 my $rechost = shift; 3299 my $recdata = shift; 3300 3301 if ($rechost =~ /\.in-addr\.arpa\.?$/) { 3302 $rechost =~ s/\.in-addr\.arpa\.?$//; 3303 $rechost = join '.', reverse split /\./, $rechost; 3304 } else { 3305 $rechost =~ s/\.ip6\.arpa\.?$//; 3306 my @nibs = reverse split /\./, $rechost; 3307 $rechost = ''; 3308 my $nc; 3309 foreach (@nibs) { 3310 $rechost.= $_; 3311 $rechost .= ":" if ++$nc % 4 == 0 && $nc < 32; 3312 } 3313 $rechost .= ":" if $nc < 32 && $rechost !~ /\*$/; # close netblock records? 3314 print "$rechost\n"; 3315 # canonicalize with NetAddr::IP 3316 $rechost = NetAddr::IP->new($rechost)->addr unless $rechost =~ /\*$/; 3317 } 3318 return ($recdata,$rechost) 3319 } 3320 3321 3296 3322 # Allow transactions, and raise an exception on errors so we can catch it later. 3297 3323 # Use local to make sure these get "reset" properly on exiting this block … … 3318 3344 $rdns_id = $zone_id; 3319 3345 _log($dbh, (group_id => $group, rdns_id => $rdns_id, 3320 entry => "[Added ".($status ? 'active' : 'inactive')." reverse zone $ zonevia AXFR]") );3346 entry => "[Added ".($status ? 'active' : 'inactive')." reverse zone $cidr via AXFR]") ); 3321 3347 } 3322 3348 … … 3340 3366 my $weight = 0; 3341 3367 my $port = 0; 3368 my $logfrag = ''; 3342 3369 3343 3370 my $type = $rr->type; … … 3380 3407 $val = "$tmpmsg"; 3381 3408 $host = $rr->nsdname; 3409 $logfrag = "Added record '$val $type $host', TTL $ttl"; 3382 3410 } else { 3383 3411 $val = $rr->nsdname; … … 3386 3414 } elsif ($type eq 'CNAME') { 3387 3415 if ($rev eq 'y') { 3388 3389 # hmm. do we even want to bother with storing these at this level? Sub-octet delegation 3390 # by CNAME is essentially a record-publication hack, and we want to just represent the 3391 # "true" logical intentions as far down the stack as we can from the UI. 3392 3393 # really wanna spin this bit off to somewhere common, since it's likely we'll need it 3394 # for more than CNAME and PTR... 3395 $val = $host; 3396 $host = $rr->cname; 3397 if ($val =~ /\.in-addr\.arpa\.?$/) { 3398 $val =~ s/\.in-addr\.arpa\.?$//; 3399 $val = join '.', reverse split /\./, $val; 3400 } else { 3401 $val =~ s/\.ip6\.arpa\.?$//; 3402 my @nibs = reverse split /\./, $val; 3403 $val = ''; 3404 my $nc; 3405 foreach (@nibs) { 3406 $val .= $_; 3407 $val .= ":" if ++$nc % 4 == 0 && $nc < 32; 3408 } 3409 # canonicalize with NetAddr::IP 3410 $val = NetAddr::IP->new($val)->addr unless $val =~ /\*$/; 3411 } 3412 3416 # hmm. do we even want to bother with storing these at this level? Sub-octet delegation 3417 # by CNAME is essentially a record-publication hack, and we want to just represent the 3418 # "true" logical intentions as far down the stack as we can from the UI. 3419 ($host,$val) = _revswap($host,$rr->cname); 3420 $logfrag = "Added record '$val $type $host', TTL $ttl"; 3413 3421 } else { 3414 3422 $val = $rr->cname; … … 3420 3428 $soaflag = 1; 3421 3429 } elsif ($type eq 'PTR') { 3422 $val = $host; 3423 $host = $rr->ptrdname; 3424 if ($val =~ /\.in-addr\.arpa\.?$/) { 3425 $val =~ s/\.in-addr\.arpa\.?$//; 3426 $val = join '.', reverse split /\./, $val; 3427 } else { 3428 $val =~ s/\.ip6\.arpa\.?$//; 3429 my @nibs = reverse split /\./, $val; 3430 $val = ''; 3431 my $nc; 3432 foreach (@nibs) { 3433 $val .= $_; 3434 $val .= ":" if ++$nc % 4 == 0 && $nc < 32; 3435 } 3436 # canonicalize with NetAddr::IP 3437 $val = NetAddr::IP->new($val)->addr unless $val =~ /\*$/; 3438 } 3430 ($host,$val) = _revswap($host,$rr->ptrdname); 3431 $logfrag = "Added record '$val $type $host', TTL $ttl"; 3439 3432 # hmm. PTR records should not be in forward zones. 3440 3433 } elsif ($type eq 'MX') { … … 3444 3437 ##fixme: Net::DNS docs say this should be deprecated for rdatastr() or char_str_list(), 3445 3438 ## but don't really seem enthusiastic about it. 3446 $val = $rr->txtdata; 3439 #print "should use rdatastr:\n\t".$rr->rdatastr."\n or char_str_list:\n\t".join(' ',$rr->char_str_list())."\n"; 3440 # rdatastr returns a BIND-targetted logical string, including opening and closing quotes 3441 # char_str_list returns a list of the individual string fragments in the record 3442 # txtdata returns the more useful all-in-one form. 3443 # NB: this may turn out to be more troublesome if we ever have need of >512-byte TXT records. 3444 if ($rev eq 'y') { 3445 ($host,$val) = _revswap($host,$rr->txtdata); 3446 $logfrag = "Added record '$val $type $host', TTL $ttl"; 3447 } else { 3448 $val = $rr->txtdata; 3449 } 3447 3450 } elsif ($type eq 'SPF') { 3448 3451 ##fixme: and the same caveat here, since it is apparently a clone of ::TXT … … 3465 3468 } 3466 3469 3467 my $logentry = "[AXFR $zone] ";3470 my $logentry = "[AXFR ".($rev eq 'n' ? $zone : $cidr)."] "; 3468 3471 3469 3472 $merge = 1; … … 3527 3530 $logentry .= "Added SOA record [contact $tmp1[0]] [master $tmp1[1]] ". 3528 3531 "[refresh $tmp2[0]] [retry $tmp2[1]] [expire $tmp2[2]] [minttl $tmp2[3]], TTL $ttl"; 3532 } elsif ($logfrag) { 3533 # special case for log entries we need to meddle with a little. 3534 $logentry .= $logfrag; 3529 3535 } else { 3530 3536 $logentry .= "Added record '$host $type";
Note:
See TracChangeset
for help on using the changeset viewer.