- Timestamp:
- 12/31/13 15:36:27 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tiny-import.pl
r543 r575 39 39 conv => 0, 40 40 trial => 0, 41 legacy => 0, 41 legacy => 0, 42 group => 1, 42 43 ); 44 my $gnum = ''; 43 45 # Handle some command-line arguments 44 46 while ($ARGV[0] =~ /^-/) { 45 47 my $arg = shift @ARGV; 46 usage() if $arg !~ /^- [rclt]+$/;48 usage() if $arg !~ /^-(?:[rclt]+|g\d*)$/; 47 49 # -r rewrite imported files to comment imported records 48 50 # -c coerce/downconvert A+PTR = records to PTR 49 51 # -l swallow A+PTR as-is 50 52 # -t trial mode; don't commit to DB or actually rewrite flatfile (disables -r) 53 # -g import to specified group (name or ID) instead of group 1 51 54 $arg =~ s/^-//; 52 my @tmp = split //, $arg; 53 foreach (@tmp) { 54 $importcfg{rw} = 1 if $_ eq 'r'; 55 $importcfg{conv} = 1 if $_ eq 'c'; 56 $importcfg{legacy} = 1 if $_ eq 'l'; 57 $importcfg{trial} = 1 if $_ eq 't'; 58 } 55 # for Reasons (none clear), $arg is undefined yet defined, but only when number characters are involved. Ebbeh? 56 no warnings qw(uninitialized); 57 if ($arg =~ /^g/) { 58 if ($arg eq 'g') { 59 $importcfg{group} = shift @ARGV; 60 } else { 61 $arg =~ s/^g//; 62 $importcfg{group} = $arg; 63 } 64 } else { 65 my @tmp = split //, $arg; 66 foreach (@tmp) { 67 $importcfg{rw} = 1 if $_ eq 'r'; 68 $importcfg{conv} = 1 if $_ eq 'c'; 69 $importcfg{legacy} = 1 if $_ eq 'l'; 70 $importcfg{trial} = 1 if $_ eq 't'; 71 } 72 } 73 use warnings qw(uninitialized); 59 74 } 60 75 $importcfg{rw} = 0 if $importcfg{trial}; 61 76 77 # allow group names 78 if ($importcfg{group} =~ /^\d+$/) { 79 $importcfg{groupname} = $dnsdb->groupName($importcfg{group}); 80 } else { 81 $importcfg{groupname} = $importcfg{group}; 82 $importcfg{group} = $dnsdb->groupID($importcfg{groupname}); 83 } 84 85 die usage() if $importcfg{group} !~ /^\d+$/; 86 62 87 sub usage { 63 die q(usage: tiny-import.pl [-r ] [-c] datafile1 datafile2 ... datafileN ...88 die q(usage: tiny-import.pl [-rclt] [-gnn] [-g name] datafile1 datafile2 ... datafileN ... 64 89 -r Rewrite all specified data files with a warning header indicating the 65 90 records are now managed by web, and commenting out all imported records. … … 72 97 -l (for "legacy") Force import of A+PTR records as-is. Mutually exclusive 73 98 with -c. -l takes precedence as -c is lossy. 99 -gnnn or -g nnn or -g name 100 Import new zones into this group (group name or ID accepted) instead of 101 the root/default group 1 74 102 -t Trial run mode; spits out records that would be left unimported. 75 103 Disables -r if set. … … 514 542 if ($zone =~ /\.arpa$/) { 515 543 ($code,$msg) = DNSDB::_zone2cidr($zone); 516 $dbh->do("INSERT INTO revzones (revnet,group_id,status,default_location) VALUES (?, 1,1,?)",517 undef, ($msg, $ loc));544 $dbh->do("INSERT INTO revzones (revnet,group_id,status,default_location) VALUES (?,?,1,?)", 545 undef, ($msg, $importcfg{group}, $loc)); 518 546 my ($rdns) = $dbh->selectrow_array("SELECT currval('revzones_rdns_id_seq')"); 519 547 my $newttl; … … 523 551 $loc, $stamp, $expires, $stampactive); 524 552 } else { 525 $dbh->do("INSERT INTO domains (domain,group_id,status,default_location) VALUES (?, 1,1,?)",526 undef, ($zone, $ loc));553 $dbh->do("INSERT INTO domains (domain,group_id,status,default_location) VALUES (?,?,1,?)", 554 undef, ($zone, $importcfg{group}, $loc)); 527 555 my ($domid) = $dbh->selectrow_array("SELECT currval('domains_domain_id_seq')"); 528 556 my $newttl;
Note:
See TracChangeset
for help on using the changeset viewer.