Changeset 303


Ignore:
Timestamp:
04/13/12 18:14:26 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Checkpoint - still finding rough edges in AXFR import
[ log -> ticket fixup: see #26 ]

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r302 r303  
    32943294  return ('FAIL', ($rev eq 'n' ? 'Domain' : 'Reverse zone')." already exists") if $zone_id;
    32953295
     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?
     3314print "$rechost\n";
     3315      # canonicalize with NetAddr::IP
     3316      $rechost = NetAddr::IP->new($rechost)->addr unless $rechost =~ /\*$/;
     3317    }
     3318    return ($recdata,$rechost)
     3319  }
     3320
     3321
    32963322  # Allow transactions, and raise an exception on errors so we can catch it later.
    32973323  # Use local to make sure these get "reset" properly on exiting this block
     
    33183344      $rdns_id = $zone_id;
    33193345      _log($dbh, (group_id => $group, rdns_id => $rdns_id,
    3320                 entry => "[Added ".($status ? 'active' : 'inactive')." reverse zone $zone via AXFR]") );
     3346                entry => "[Added ".($status ? 'active' : 'inactive')." reverse zone $cidr via AXFR]") );
    33213347    }
    33223348
     
    33403366      my $weight = 0;
    33413367      my $port = 0;
     3368      my $logfrag = '';
    33423369
    33433370      my $type = $rr->type;
     
    33803407          $val = "$tmpmsg";
    33813408          $host = $rr->nsdname;
     3409          $logfrag = "Added record '$val $type $host', TTL $ttl";
    33823410        } else {
    33833411          $val = $rr->nsdname;
     
    33863414      } elsif ($type eq 'CNAME') {
    33873415        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";
    34133421        } else {
    34143422          $val = $rr->cname;
     
    34203428        $soaflag = 1;
    34213429      } 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";
    34393432        # hmm.  PTR records should not be in forward zones.
    34403433      } elsif ($type eq 'MX') {
     
    34443437##fixme:  Net::DNS docs say this should be deprecated for rdatastr() or char_str_list(),
    34453438## 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        }
    34473450      } elsif ($type eq 'SPF') {
    34483451##fixme: and the same caveat here, since it is apparently a clone of ::TXT
     
    34653468      }
    34663469
    3467       my $logentry = "[AXFR $zone] ";
     3470      my $logentry = "[AXFR ".($rev eq 'n' ? $zone : $cidr)."] ";
    34683471
    34693472$merge = 1;
     
    35273530        $logentry .= "Added SOA record [contact $tmp1[0]] [master $tmp1[1]] ".
    35283531                "[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;
    35293535      } else {
    35303536        $logentry .= "Added record '$host $type";
Note: See TracChangeset for help on using the changeset viewer.