Ignore:
Timestamp:
12/11/13 15:45:18 (10 years ago)
Author:
Kris Deugau
Message:

/branches/stable

Merge reverse DNS work and object conversion from /trunk, 4 of mumble

Includes changes through r492 with a few minor conflicts.

Location:
branches/stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/stable

  • branches/stable/tiny-import.pl

    r545 r547  
    2727
    2828use lib '.';
    29 use DNSDB qw(:ALL);
    30 
    31 if (!loadConfig()) {
    32   warn "Using default configuration;  unable to load custom settings: $DNSDB::errstr";
    33 }
     29use DNSDB;
     30
     31my $dnsdb = new DNSDB;
    3432
    3533usage() if !@ARGV;
     
    7775
    7876my $code;
    79 my ($dbh,$msg) = connectDB($config{dbname}, $config{dbuser}, $config{dbpass}, $config{dbhost});
    80 initGlobals($dbh) if $dbh;
     77my $dbh = $dnsdb->{dbh};
    8178
    8279$dbh->{AutoCommit} = 0;
     
    8582my %cnt;
    8683my @deferred;
     84my $converted = 0;
    8785my $errstr = '';
    8886
     
    167165
    168166  # .. but we can at least say how many records weren't imported.
    169   print "$ok OK, ".scalar(@deferred)." deferred records in $flatfile\n";
    170   $#deferred = -1;
    171 
     167  print "$ok OK, ".scalar(@deferred)." deferred, $converted downconverted records in $flatfile\n";
     168  undef @deferred;
     169  $converted = 0;
    172170
    173171  # Sub for various nonstandard types with lots of pure bytes expressed in octal
     
    250248    my $nodefer = shift || 0;
    251249    my $impok = 1;
     250    my $msg;
    252251
    253252    $errstr = $rec;  # this way at least we have some idea what went <splat>
     
    268267      $loc = '' if !$loc;
    269268      $loc = '' if $loc =~ /^:+$/;
    270       my $fparent = DNSDB::_hostparent($dbh, $host);
     269      my $fparent = $dnsdb->_hostparent($host);
    271270      my ($rparent) = $dbh->selectrow_array("SELECT rdns_id FROM revzones WHERE revnet >> ?", undef, ($ip));
    272271      if ($fparent && $rparent) {
    273272        $recsth->execute($fparent, $rparent, $host, 65280, $ip, 0, 0, 0, $ttl, $loc);
    274273      } else {
    275         push @deferred, $rec unless $nodefer;
    276         $impok = 0;
    277         #  print "$tmporig deferred;  can't find both forward and reverse zone parents\n";
     274        if ($importcfg{conv}) {
     275          # downconvert A+PTR if forward zone is not found
     276          $recsth->execute(0, $rparent, $host, 12, $ip, 0, 0, 0, $ttl, $loc);
     277          $converted++;
     278        } else {
     279          push @deferred, $rec unless $nodefer;
     280          $impok = 0;
     281          #  print "$tmporig deferred;  can't find both forward and reverse zone parents\n";
     282        }
    278283      }
    279284
     
    301306
    302307      } else {
    303         my $fparent = DNSDB::_hostparent($dbh, $host);
     308        my $fparent = $dnsdb->_hostparent($host);
    304309        if ($fparent) {
    305310          $recsth->execute($fparent, 0, $host, 5, $targ, 0, 0, 0, $ttl, $loc);
     
    337342        }
    338343      } else {
    339         my $fparent = DNSDB::_hostparent($dbh, $zone);
     344        my $fparent = $dnsdb->_hostparent($zone);
    340345        if ($fparent) {
    341346          $recsth->execute($fparent, 0, $zone, 2, $ns, 0, 0, 0, $ttl, $loc);
     
    389394      $loc = '' if $loc =~ /^:+$/;
    390395
    391       my $domid = DNSDB::_hostparent($dbh, $host);
     396      my $domid = $dnsdb->_hostparent($host);
    392397      if ($domid) {
    393398        $recsth->execute($domid, 0, $host, 1, $ip, 0, 0, 0, $ttl, $loc);
     
    440445
    441446      # allow for subzone MXes, since it's perfectly legitimate to simply stuff it all in a single parent zone
    442       my $domid = DNSDB::_hostparent($dbh, $zone);
     447      my $domid = $dnsdb->_hostparent($zone);
    443448      if ($domid) {
    444449        $recsth->execute($domid, 0, $zone, 15, $host, $dist, 0, 0, $ttl, $loc);
     
    466471        $recsth->execute(0, $rparent, $rdata, 16, "$msg", 0, 0, 0, $ttl, $loc);
    467472      } else {
    468         my $domid = DNSDB::_hostparent($dbh, $fqdn);
     473        my $domid = $dnsdb->_hostparent($fqdn);
    469474        if ($domid) {
    470475          $recsth->execute($domid, 0, $fqdn, 16, $rdata, 0, 0, 0, $ttl, $loc);
     
    581586#  }
    582587
    583         my $domid = DNSDB::_hostparent($dbh, $fqdn);
     588        my $domid = $dnsdb->_hostparent($fqdn);
    584589        if ($domid) {
    585590          $recsth->execute($domid, 0, $fqdn, 33, $target, $prio, $weight, $port, $ttl, $loc) if $domid;
     
    599604        my $val = NetAddr::IP->new(join(':', @v6));
    600605
    601         my $fparent = DNSDB::_hostparent($dbh, $fqdn);
     606        my $fparent = $dnsdb->_hostparent($fqdn);
    602607        if ($fparent) {
    603608          $recsth->execute($fparent, 0, $fqdn, 28, $val->addr, 0, 0, 0, $ttl, $loc);
     
    621626          }
    622627        } else {
    623           my $domid = DNSDB::_hostparent($dbh, $fqdn);
     628          my $domid = $dnsdb->_hostparent($fqdn);
    624629          if ($domid) {
    625630            $recsth->execute($domid, 0, $fqdn, 16, $txtstring, 0, 0, 0, $ttl, $loc);
     
    649654          }
    650655        } else {
    651           my $domid = DNSDB::_hostparent($dbh, $fqdn);
     656          my $domid = $dnsdb->_hostparent($fqdn);
    652657          if ($domid) {
    653658            $recsth->execute($domid, 0, $fqdn, 17, "$email $txtrec", 0, 0, 0, $ttl, $loc);
     
    665670
    666671        # these do not make sense in a reverse zone, since they're logically attached to an A record
    667         my $domid = DNSDB::_hostparent($dbh, $fqdn);
     672        my $domid = $dnsdb->_hostparent($fqdn);
    668673        if ($domid) {
    669674          $recsth->execute($domid, 0, $fqdn, 44, $sshfp, 0, 0, 0, $ttl, $loc);
Note: See TracChangeset for help on using the changeset viewer.