Changeset 821


Ignore:
Timestamp:
12/04/20 13:26:33 (4 years ago)
Author:
Kris Deugau
Message:

/trunk

Fourtheenth sampled iteration of bind-import

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bind-import

    r820 r821  
    3131
    3232my $dnsdb = new DNSDB;
    33 my $doimport = 1;
     33my $dryrun = 0;
    3434
    3535#print Dumper(\%reverse_typemap);
     
    5959        "skip=s" => \@skipdefs,
    6060        "skipfile=s" => \$skipfile,
    61         "test|dry-run" => sub { $doimport = 0; },
     61        "test|dry-run" => \$dryrun,
    6262);
    6363
     
    7272                A file containing patterns to skip.  Patterns from the file and
    7373                any --skip arguments are merged.
     74        --dry-run
     75                Do everything except finalize the import
    7476        zonename
    7577                The name of the zone to import.  Required.
     
    131133##fixme:  this is wrong, BIND zone files are generally complete and we're adding.  merging records is an entire fridge full of worms.
    132134##fixme:  for import, should arguably check for zone *non*existence
     135
    133136  if ($zname =~ /\.arpa\.?$/ || $zname =~ m,^[\d./]+$,) {
    134137    $rev = 'y';
     
    137140    if ($zid) {
    138141      die "zone $origzone already present, not merging records\n";
    139       $zname = new NetAddr::IP $zname;
    140       $zname = DNSDB::_ZONE($zname, 'ZONE', 'r', '.').($zname->{isv6} ? '.ip6.arpa' : '.in-addr.arpa');
     142#print "dbg: skip add domain\n";
     143#      $zname = new NetAddr::IP $zname;
     144#      $zname = DNSDB::_ZONE($zname, 'ZONE', 'r', '.').($zname->{isv6} ? '.ip6.arpa' : '.in-addr.arpa');
    141145    }
    142146    ($zid) = $dnsdb->{dbh}->selectrow_array("INSERT INTO revzones (revnet,group_id,status,default_location,zserial) VALUES (?,?,?,?,?) RETURNING rnds_id",
     
    144148
    145149  } else {
    146 print "dbg: forward zone\n";
    147150    $zid = $dnsdb->domainID($zname,':ANY:');
    148151    if ($zid) {
    149 #      die "zone $origzone already present, not merging records\n";
    150 print "dbg: skip add domain\n";
    151     } else {
    152       ($zid) = $dnsdb->{dbh}->selectrow_array("INSERT INTO domains (domain,group_id,status,default_location,zserial) VALUES (?,?,?,?,?) RETURNING domain_id",
     152      die "zone $origzone already present, not merging records\n";
     153#print "dbg: skip add domain\n";
     154    }
     155    ($zid) = $dnsdb->{dbh}->selectrow_array("INSERT INTO domains (domain,group_id,status,default_location,zserial) VALUES (?,?,?,?,?) RETURNING domain_id",
    153156        undef, ($zname, $group, $status, $location, $serial));
    154     }
    155157
    156158  }
     
    557559    }
    558560
    559 no warnings qw(uninitialized);
    560 #print "parsed: '$curlabel' '$class' '$ttl' '$type'->'$itype' '$rdata'\n";
    561 #print;
    562 #;imap   IN      900     CNAME   deepnet.cx.
    563 ##fixme:  not sure how to handle the case where someone leaves off the class.
    564     if ($doimport) {
     561##fixme:  need to dig out a subtransaction widget or extract a core of addRec() that doesn't dbh->commit(), so --dry-run works
     562#    unless ($dryrun) {
    565563      my ($code, $msg);
    566564      if ($rev eq 'n') {
     
    572570      }
    573571      print "$code: $msg\n" if $code ne 'OK';
    574     }
     572#    }
    575573#  $i++;
    576574  }
    577575
     576  if ($dryrun) {
     577    $dnsdb->{dbh}->rollback;
     578  } else {
     579    $dnsdb->{dbh}->commit;
     580  }
    578581};
    579582if ($@) {
Note: See TracChangeset for help on using the changeset viewer.