Changeset 354


Ignore:
Timestamp:
06/29/12 12:49:20 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Checkpoint on tiny-import.pl

  • normalize some whitespace now that the code seems to be working
  • remove some stale working comments
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tiny-import.pl

    r353 r354  
    123123    if ($rec =~ /^=/) {
    124124      $cnt{APTR}++;
    125 if ($rec !~ /^=(?:\*|\\052)?[a-z0-9\._-]+:[\d\.]+:\d*/i) {
    126   print "bad A+PTR $rec\n";
    127   return;
    128 #=sud-rr-iGi0-1_sud-gw1-iGi4-2.vianet.ca::10.10.10.13:900::in
    129 }
     125
     126##fixme:  do checks like this for all types
     127      if ($rec !~ /^=(?:\*|\\052)?[a-z0-9\._-]+:[\d\.]+:\d*/i) {
     128        print "bad A+PTR $rec\n";
     129        return;
     130      }
    130131      my ($host,$ip,$ttl,$stamp,$loc) = split /:/, $rec, 5;
    131132      $host =~ s/^=//;
     
    146147    } elsif ($rec =~ /^C/) {
    147148      $cnt{CNAME}++;
     149
    148150      my ($host,$targ,$ttl,$stamp,$loc) = split /:/, $rec, 5;
    149151      $host =~ s/^C//;
     
    176178    } elsif ($rec =~ /^\&/) {
    177179      $cnt{NS}++;
     180
    178181    } elsif ($rec =~ /^\^/) {
    179182      $cnt{PTR}++;
     183
    180184    } elsif ($rec =~ /^\+/) {
    181185      $cnt{A}++;
     186
    182187    } elsif ($rec =~ /^Z/) {
    183188      $cnt{SOA}++;
    184 #Z128.91.209.in-addr.arpa:ns1.vianet.ca.:dnsadmin.vianet.ca.::1209600:1209600:900:900:900:
     189
    185190      my ($zone,$master,$contact,$serial,$refresh,$retry,$expire,$minttl,$ttl,$stamp,$loc) = split /:/, $rec, 11;
    186191      $zone =~ s/^Z//;
     
    202207        $recsth->execute($domid, 0, "$contact:$master", 6, "$refresh:$retry:$expire:$minttl", 0, 0, 0, $ttl);
    203208      }
    204       return;  # since we don't use the "standard" record-add call at the bottom
     209
    205210    } elsif ($rec =~ /^\@/) {
    206211      $cnt{MX}++;
     212
    207213    } elsif ($rec =~ /^'/) {
    208214      $cnt{TXT}++;
     
    225231    } elsif ($rec =~ /^\./) {
    226232      $cnt{NSASOA}++;
     233
    227234      my ($fqdn, $ip, $ns, $ttl, $stamp, $loc) = split /:/, $rec, 6;
    228235      $fqdn =~ s/^\.//;
     
    254261# Even the auto-nameserver-fqdn comes out...  ugly.
    255262
    256 ##work
    257263      } else {
    258264        my ($domid) = $dbh->selectrow_array("SELECT domain_id FROM domains WHERE lower(domain) = lower(?)",
     
    271277    } elsif ($rec =~ /^\%/) {
    272278      $cnt{VIEWS}++;
     279
    273280    } elsif ($rec =~ /^:/) {
    274281      $cnt{NCUST}++;
     
    276283# recognition and handling for the core common types, this must deal with the leftovers.
    277284# :fqdn:type:rdata:ttl:time:loc
    278 #:mx2.sys.vianet.ca:44:\001\001\215\272\152\152\123\142\120\071\320\106\160\364\107\372\153\116\036\111\247\135:900::sys
    279 #:_sipfederationtls._tcp.ncstechnology.com:33:\000\144\000\001\023\305\006sipfed\006online\004lync\003com\000:3600::
    280 
    281 my (undef, $fqdn, $type, $rdata, $ttl, $time, $loc) = split /:/, $rec;
    282 
    283 if ($type == 33) {
    284   # SRV
    285   my ($prio, $weight, $port, $target) = (0,0,0,0);
    286 
    287   my @tmp = _byteparse(\$rdata, 2);
    288   $prio = $tmp[0] * 256 + $tmp[1];
    289   @tmp = _byteparse(\$rdata, 2);
    290   $weight = $tmp[0] * 256 + $tmp[1];
    291   @tmp = _byteparse(\$rdata, 2);
    292   $port = $tmp[0] * 256 + $tmp[1];
    293 
    294   $rdata =~ s/\\\d{3}/./g;
    295   ($target) = ($rdata =~ /^\.(.+)\.$/);
     285
     286      my (undef, $fqdn, $type, $rdata, $ttl, $stamp, $loc) = split /:/, $rec, 7;
     287      $ttl = 0 if !$ttl;
     288      $stamp = '' if !$stamp;
     289      $loc = '' if !$loc;
     290      $loc = '' if $loc =~ /^:+$/;
     291
     292      if ($type == 33) {
     293        # SRV
     294        my ($prio, $weight, $port, $target) = (0,0,0,0);
     295
     296        my @tmp = _byteparse(\$rdata, 2);
     297        $prio = $tmp[0] * 256 + $tmp[1];
     298        @tmp = _byteparse(\$rdata, 2);
     299        $weight = $tmp[0] * 256 + $tmp[1];
     300        @tmp = _byteparse(\$rdata, 2);
     301        $port = $tmp[0] * 256 + $tmp[1];
     302
     303        $rdata =~ s/\\\d{3}/./g;
     304        ($target) = ($rdata =~ /^\.(.+)\.$/);
    296305# hmm.  the above *should* work, but What If(TM) we have ASCII-range bytes
    297306# representing the target's fqdn part length(s)?  axfr-get doesn't seem to,
     
    306315#  }
    307316
    308   my $domid = DNSDB::_hostparent($dbh, $fqdn);
    309   if ($domid) {
    310     $recsth->execute($domid, 0, $fqdn, $type, $target, $prio, $weight, $port, $ttl) if $domid;
    311   } else {
    312     push @deferred, $rec unless $nodefer;
    313   }
    314 
    315 } elsif ($type == 28) {
    316   # AAAA
    317 
    318   my @v6;
    319 
    320   for (my $i=0; $i < 8; $i++) {
    321     my @tmp = _byteparse(\$rdata, 2);
    322     push @v6, sprintf("%0.4x", $tmp[0] * 256 + $tmp[1]);
    323   }
    324   my $val = NetAddr::IP->new(join(':', @v6));
    325 
    326   my $domid = DNSDB::_hostparent($dbh, $fqdn);
    327   if ($domid) {
    328     $recsth->execute($domid, 0, $fqdn, $type, $val->addr, 0, 0, 0, $ttl) if $domid;
    329   } else {
    330     push @deferred, $rec unless $nodefer;
    331   }
    332 
    333 } else {
    334   # ... uhhh, dunno
    335 }
     317        my $domid = DNSDB::_hostparent($dbh, $fqdn);
     318        if ($domid) {
     319          $recsth->execute($domid, 0, $fqdn, 33, $target, $prio, $weight, $port, $ttl) if $domid;
     320        } else {
     321          push @deferred, $rec unless $nodefer;
     322        }
     323
     324      } elsif ($type == 28) {
     325        # AAAA
     326        my @v6;
     327
     328        for (my $i=0; $i < 8; $i++) {
     329          my @tmp = _byteparse(\$rdata, 2);
     330          push @v6, sprintf("%0.4x", $tmp[0] * 256 + $tmp[1]);
     331        }
     332        my $val = NetAddr::IP->new(join(':', @v6));
     333
     334        my ($rdns) = $dbh->selectrow_array("SELECT rdns_id FROM revzones WHERE revnet >> ?", undef, ("$val"));
     335        if ($rdns) {
     336          $recsth->execute(0, $rdns, $fqdn, 28, $val->addr, 0, 0, 0, $ttl);
     337        } else {
     338          push @deferred, $rec unless $nodefer;
     339        }
     340
     341      } else {
     342        # ... uhhh, dunno
     343      }
    336344
    337345    } else {
    338346      $cnt{other}++;
    339   print " $_\n";
     347      print " $_\n";
    340348    }
    341349  }
Note: See TracChangeset for help on using the changeset viewer.