Ignore:
Timestamp:
02/11/26 13:13:59 (2 days ago)
Author:
Kris Deugau
Message:

/branches/stable

Continue merging /trunk commits based on production

Location:
branches/stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/stable

  • branches/stable/tiny-import.pl

    r1032 r1033  
    122122$dnsdb->{logusername} = $dnsdb->{logusername}."/tiny-import.pl";
    123123$dnsdb->{logfullname} = $dnsdb->{logusername} if !$dnsdb->{logfullname};
     124$dnsdb->{logfullname} = $dnsdb->{logfullname}."/tiny-import.pl";
    124125
    125126$dbh->{AutoCommit} = 0;
     
    132133
    133134foreach my $file (@ARGV) {
     135  my %filecount;
     136  my $logentry = "Import records from $file: ";
    134137  eval {
    135     import(file => $file);
    136 #    import(file => $file, nosoa => 1);
     138    import(file => $file, cnt => \%filecount);
     139    if (%filecount) {
     140      foreach (sort keys %filecount) {
     141        $logentry .= "$_ $filecount{$_}, ";
     142        $cnt{$_} += $filecount{$_};
     143      }
     144      $logentry =~ s/[\s,]+$//;
     145      $dnsdb->_log(group_id => $importcfg{group}, entry => $logentry);
     146    }
    137147    $dbh->rollback if $importcfg{trial};
    138148    $dbh->commit unless $importcfg{trial};
     
    146156
    147157# print summary count of record types encountered
    148 foreach (keys %cnt) {
     158foreach (sort keys %cnt) {
    149159  print " $_    $cnt{$_}\n";
    150160}
     
    155165  our %args = @_;
    156166  my $flatfile = $args{file};
     167  my $filecnt = $args{cnt};
    157168  my @fpath = split '/', $flatfile;
    158169  $fpath[$#fpath] = ".$fpath[$#fpath]";
     
    186197    chomp;
    187198    s/\s*$//;
    188     my $recstat = recslurp($_);
     199    my $recstat = recslurp($_, $filecnt);
    189200    $ok++ if $recstat;
    190201    if ($importcfg{rw}) {
     
    322333  sub recslurp {
    323334    my $rec = shift;
     335    my $filecnt = shift;
    324336    my $nodefer = shift || 0;
    325337    my $impok = 1;
     
    329341
    330342    if ($rec =~ /^=/) {
    331       $cnt{APTR}++;
     343      $filecnt->{'A+PTR'}++;
    332344
    333345##fixme:  do checks like this for all types
     
    384396
    385397    } elsif ($rec =~ /^C/) {
    386       $cnt{CNAME}++;
     398      $filecnt->{CNAME}++;
    387399
    388400      my ($host,$targ,$ttl,$stamp,$loc) = split /:/, $rec, 5;
     
    429441
    430442    } elsif ($rec =~ /^\&/) {
    431       $cnt{NS}++;
     443      $filecnt->{NS}++;
    432444
    433445      my ($zone,$ip,$ns,$ttl,$stamp,$loc) = split /:/, $rec, 6;
     
    471483
    472484    } elsif ($rec =~ /^\^/) {
    473       $cnt{PTR}++;
     485      $filecnt->{PTR}++;
    474486
    475487      my ($rip,$host,$ttl,$stamp,$loc) = split /:/, $rec, 5;
     
    521533
    522534    } elsif ($rec =~ /^\+/) {
    523       $cnt{A}++;
     535      $filecnt->{A}++;
    524536
    525537      my ($host,$ip,$ttl,$stamp,$loc) = split /:/, $rec, 5;
     
    558570
    559571    } elsif ($rec =~ /^Z/) {
    560       $cnt{SOA}++;
     572      $filecnt->{SOA}++;
    561573
    562574      my ($zone,$master,$contact,$serial,$refresh,$retry,$expire,$minttl,$ttl,$stamp,$loc) = split /:/, $rec, 11;
     
    569581      $loc = '' if !$loc;
    570582      $loc = '' if $loc =~ /^:+$/;
     583# Default to UNIX epoch for zones with no existing serial value
     584      $serial = scalar(time) if !$serial;
    571585
    572586      my $stampactive = 'n';
     
    588602      if ($zone =~ /\.arpa$/) {
    589603        ($code,$msg) = DNSDB::_zone2cidr($zone);
    590         $dbh->do("INSERT INTO revzones (revnet,group_id,status,default_location) VALUES (?,?,1,?)",
    591                 undef, ($msg, $importcfg{group}, $loc));
     604        $dbh->do("INSERT INTO revzones (revnet,group_id,status,default_location,zserial) VALUES (?,?,1,?,?)",
     605                undef, ($msg, $importcfg{group}, $loc, $serial));
    592606        my ($rdns) = $dbh->selectrow_array("SELECT currval('revzones_rdns_id_seq')");
    593607        my $newttl;
     
    597611                $loc, $stamp, $expires, $stampactive);
    598612      } else {
    599         $dbh->do("INSERT INTO domains (domain,group_id,status,default_location) VALUES (?,?,1,?)",
    600                 undef, ($zone, $importcfg{group}, $loc));
     613        $dbh->do("INSERT INTO domains (domain,group_id,status,default_location,zserial) VALUES (?,?,1,?,?)",
     614                undef, ($zone, $importcfg{group}, $loc, $serial));
    601615        my ($domid) = $dbh->selectrow_array("SELECT currval('domains_domain_id_seq')");
    602616        my $newttl;
     
    608622
    609623    } elsif ($rec =~ /^\@/) {
    610       $cnt{MX}++;
     624      $filecnt->{MX}++;
    611625
    612626      my ($zone,$ip,$host,$dist,$ttl,$stamp,$loc) = split /:/, $rec, 7;
     
    639653
    640654    } elsif ($rec =~ /^'/) {
    641       $cnt{TXT}++;
     655      $filecnt->{TXT}++;
    642656
    643657      my ($fqdn, $rdata, $ttl, $stamp, $loc) = split /:/, $rec, 5;
     
    670684
    671685    } elsif ($rec =~ /^\./) {
    672       $cnt{NSASOA}++;
     686      $filecnt->{NSASOA}++;
    673687
    674688      my ($fqdn, $ip, $ns, $ttl, $stamp, $loc) = split /:/, $rec, 6;
     
    744758
    745759    } elsif ($rec =~ /^\%/) {
    746       $cnt{VIEWS}++;
     760      $filecnt->{VIEWS}++;
    747761
    748762      # unfortunate that we don't have a guaranteed way to get a description on these.  :/
     
    763777
    764778    } elsif ($rec =~ /^:/) {
    765       $cnt{NCUST}++;
     779      $filecnt->{NCUST}++;
    766780# Big section.  Since tinydns can publish anything you can encode properly, but only provides official
    767781# recognition and handling for the core common types, this must deal with the leftovers.
     
    928942
    929943    } else {
    930       $cnt{other}++;
     944      $filecnt->{other}++;
    931945      print " $_\n";
    932946    }
Note: See TracChangeset for help on using the changeset viewer.