Changeset 1033 for branches/stable/tiny-import.pl
- Timestamp:
- 02/11/26 13:13:59 (2 days ago)
- Location:
- branches/stable
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
tiny-import.pl (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/stable
-
branches/stable/tiny-import.pl
r1032 r1033 122 122 $dnsdb->{logusername} = $dnsdb->{logusername}."/tiny-import.pl"; 123 123 $dnsdb->{logfullname} = $dnsdb->{logusername} if !$dnsdb->{logfullname}; 124 $dnsdb->{logfullname} = $dnsdb->{logfullname}."/tiny-import.pl"; 124 125 125 126 $dbh->{AutoCommit} = 0; … … 132 133 133 134 foreach my $file (@ARGV) { 135 my %filecount; 136 my $logentry = "Import records from $file: "; 134 137 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 } 137 147 $dbh->rollback if $importcfg{trial}; 138 148 $dbh->commit unless $importcfg{trial}; … … 146 156 147 157 # print summary count of record types encountered 148 foreach ( keys %cnt) {158 foreach (sort keys %cnt) { 149 159 print " $_ $cnt{$_}\n"; 150 160 } … … 155 165 our %args = @_; 156 166 my $flatfile = $args{file}; 167 my $filecnt = $args{cnt}; 157 168 my @fpath = split '/', $flatfile; 158 169 $fpath[$#fpath] = ".$fpath[$#fpath]"; … … 186 197 chomp; 187 198 s/\s*$//; 188 my $recstat = recslurp($_ );199 my $recstat = recslurp($_, $filecnt); 189 200 $ok++ if $recstat; 190 201 if ($importcfg{rw}) { … … 322 333 sub recslurp { 323 334 my $rec = shift; 335 my $filecnt = shift; 324 336 my $nodefer = shift || 0; 325 337 my $impok = 1; … … 329 341 330 342 if ($rec =~ /^=/) { 331 $ cnt{APTR}++;343 $filecnt->{'A+PTR'}++; 332 344 333 345 ##fixme: do checks like this for all types … … 384 396 385 397 } elsif ($rec =~ /^C/) { 386 $ cnt{CNAME}++;398 $filecnt->{CNAME}++; 387 399 388 400 my ($host,$targ,$ttl,$stamp,$loc) = split /:/, $rec, 5; … … 429 441 430 442 } elsif ($rec =~ /^\&/) { 431 $ cnt{NS}++;443 $filecnt->{NS}++; 432 444 433 445 my ($zone,$ip,$ns,$ttl,$stamp,$loc) = split /:/, $rec, 6; … … 471 483 472 484 } elsif ($rec =~ /^\^/) { 473 $ cnt{PTR}++;485 $filecnt->{PTR}++; 474 486 475 487 my ($rip,$host,$ttl,$stamp,$loc) = split /:/, $rec, 5; … … 521 533 522 534 } elsif ($rec =~ /^\+/) { 523 $ cnt{A}++;535 $filecnt->{A}++; 524 536 525 537 my ($host,$ip,$ttl,$stamp,$loc) = split /:/, $rec, 5; … … 558 570 559 571 } elsif ($rec =~ /^Z/) { 560 $ cnt{SOA}++;572 $filecnt->{SOA}++; 561 573 562 574 my ($zone,$master,$contact,$serial,$refresh,$retry,$expire,$minttl,$ttl,$stamp,$loc) = split /:/, $rec, 11; … … 569 581 $loc = '' if !$loc; 570 582 $loc = '' if $loc =~ /^:+$/; 583 # Default to UNIX epoch for zones with no existing serial value 584 $serial = scalar(time) if !$serial; 571 585 572 586 my $stampactive = 'n'; … … 588 602 if ($zone =~ /\.arpa$/) { 589 603 ($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)); 592 606 my ($rdns) = $dbh->selectrow_array("SELECT currval('revzones_rdns_id_seq')"); 593 607 my $newttl; … … 597 611 $loc, $stamp, $expires, $stampactive); 598 612 } 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)); 601 615 my ($domid) = $dbh->selectrow_array("SELECT currval('domains_domain_id_seq')"); 602 616 my $newttl; … … 608 622 609 623 } elsif ($rec =~ /^\@/) { 610 $ cnt{MX}++;624 $filecnt->{MX}++; 611 625 612 626 my ($zone,$ip,$host,$dist,$ttl,$stamp,$loc) = split /:/, $rec, 7; … … 639 653 640 654 } elsif ($rec =~ /^'/) { 641 $ cnt{TXT}++;655 $filecnt->{TXT}++; 642 656 643 657 my ($fqdn, $rdata, $ttl, $stamp, $loc) = split /:/, $rec, 5; … … 670 684 671 685 } elsif ($rec =~ /^\./) { 672 $ cnt{NSASOA}++;686 $filecnt->{NSASOA}++; 673 687 674 688 my ($fqdn, $ip, $ns, $ttl, $stamp, $loc) = split /:/, $rec, 6; … … 744 758 745 759 } elsif ($rec =~ /^\%/) { 746 $ cnt{VIEWS}++;760 $filecnt->{VIEWS}++; 747 761 748 762 # unfortunate that we don't have a guaranteed way to get a description on these. :/ … … 763 777 764 778 } elsif ($rec =~ /^:/) { 765 $ cnt{NCUST}++;779 $filecnt->{NCUST}++; 766 780 # Big section. Since tinydns can publish anything you can encode properly, but only provides official 767 781 # recognition and handling for the core common types, this must deal with the leftovers. … … 928 942 929 943 } else { 930 $ cnt{other}++;944 $filecnt->{other}++; 931 945 print " $_\n"; 932 946 }
Note:
See TracChangeset
for help on using the changeset viewer.
![[ DNS Administrator ]](/fx/dnsadmin-logo.png)