Changeset 353
- Timestamp:
- 06/27/12 17:20:54 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tiny-import.pl
r348 r353 38 38 my %cnt; 39 39 my @deferred; 40 my $errstr = ''; 40 41 41 42 foreach my $file (@ARGV) { … … 48 49 if ($@) { 49 50 print "bleh: $@\n"; 50 die "die harder \n";51 die "die harder: $errstr\n"; 51 52 } 52 53 } … … 65 66 our $recsth = $dbh->prepare("INSERT INTO records (domain_id,rdns_id,host,type,val,distance,weight,port,ttl) ". 66 67 " VALUES (?,?,?,?,?,?,?,?,?)"); 68 69 my %deleg; 67 70 68 71 while (<FLAT>) { … … 79 82 } 80 83 84 print scalar(@deferred)." deferred records in $flatfile\n"; 85 81 86 # Sub for various nonstandard types with lots of pure bytes expressed in octal 82 # Takes a tinydns rdata string and count, returns a lis of $count bytes as well87 # Takes a tinydns rdata string and count, returns a list of $count bytes as well 83 88 # as trimming those logical bytes off the front of the rdata string. 84 89 sub _byteparse { … … 103 108 } 104 109 110 # Convert octal-coded bytes back to something resembling normal characters, general case 111 sub _deoctal { 112 my $targ = shift; 113 while ($$targ =~ /\\(\d{3})/) { 114 my $sub = chr(oct($1)); 115 $$targ =~ s/\\$1/$sub/g; 116 } 117 } 118 105 119 sub recslurp { 106 120 my $rec = shift; … … 114 128 #=sud-rr-iGi0-1_sud-gw1-iGi4-2.vianet.ca::10.10.10.13:900::in 115 129 } 116 my ($host,$ip,$ttl,$ time,$loc) = split /:/, $rec;130 my ($host,$ip,$ttl,$stamp,$loc) = split /:/, $rec, 5; 117 131 $host =~ s/^=//; 118 132 $host =~ s/\.$//; 119 $time = '' if !$time; 120 $loc = '' if !$loc; 121 print "bleh, bad A+PTR! $rec\n" if $loc =~ /:/; 133 $ttl = 0 if !$ttl; 134 $stamp = '' if !$stamp; 135 $loc = '' if !$loc; 136 $loc = '' if $loc =~ /^:+$/; 122 137 my $fparent = DNSDB::_hostparent($dbh, $host); 123 138 my ($rparent) = $dbh->selectrow_array("SELECT rdns_id FROM revzones WHERE revnet >> ?", undef, ($ip)); 124 139 if ($fparent && $rparent) { 125 $dbh->do("INSERT INTO records (domain_id,rdns_id,host,type,val,ttl) VALUES (?,?,?,?,?,?)", undef, 126 ($fparent, $rparent, $host, 65280, $ip, $ttl)); 140 $recsth->execute($fparent, $rparent, $host, 65280, $ip, 0, 0, 0, $ttl); 127 141 } else { 128 142 push @deferred, $rec unless $nodefer; … … 132 146 } elsif ($rec =~ /^C/) { 133 147 $cnt{CNAME}++; 134 my ($host,$targ,$ttl,$ time,$loc) = split /:/, $rec;148 my ($host,$targ,$ttl,$stamp,$loc) = split /:/, $rec, 5; 135 149 $host =~ s/^C//; 136 150 $host =~ s/\.$//; 137 $time = '' if !$time; 138 $loc = '' if !$loc; 139 my $fparent = DNSDB::_hostparent($dbh, $host); 140 if ($fparent) { 141 142 } else { 143 push @deferred, $rec unless $nodefer; 144 # print "$tmporig deferred; can't find parent zone\n"; 151 $ttl = 0 if !$ttl; 152 $stamp = '' if !$stamp; 153 $loc = '' if !$loc; 154 $loc = '' if $loc =~ /^:+$/; 155 if ($host =~ /\.arpa$/) { 156 ($code,$msg) = DNSDB::_zone2cidr($host); 157 my ($rparent) = $dbh->selectrow_array("SELECT rdns_id FROM revzones WHERE revnet >> ?", undef, ($msg)); 158 $recsth->execute(0, $rparent, $targ, 5, $msg->addr, 0, 0, 0, $ttl); 159 160 ##fixme: automagically convert manually maintained sub-/24 delegations 161 # my ($subip, $zone) = split /\./, $targ, 2; 162 # ($code, $msg) = DNSDB::_zone2cidr($zone); 163 # push @{$deleg{"$msg"}{iplist}}, $subip; 164 #print "$msg $subip\n"; 165 166 } else { 167 my $fparent = DNSDB::_hostparent($dbh, $host); 168 if ($fparent) { 169 $recsth->execute($fparent, 0, $host, 5, $targ, 0, 0, 0, $ttl); 170 } else { 171 push @deferred, $rec unless $nodefer; 172 # print "$tmporig deferred; can't find parent zone\n"; 173 } 145 174 } 146 175 … … 154 183 $cnt{SOA}++; 155 184 #Z128.91.209.in-addr.arpa:ns1.vianet.ca.:dnsadmin.vianet.ca.::1209600:1209600:900:900:900: 156 my ($zone,$master,$contact,$serial,$refresh,$retry,$expire,$minttl,$ttl,$ time,$loc) = split /:/, $rec;185 my ($zone,$master,$contact,$serial,$refresh,$retry,$expire,$minttl,$ttl,$stamp,$loc) = split /:/, $rec, 11; 157 186 $zone =~ s/^Z//; 158 187 $zone =~ s/\.$//; 159 188 $master =~ s/\.$//; 160 189 $contact =~ s/\.$//; 161 $time = '' if !$time; 162 $loc = '' if !$loc; 190 $ttl = 0 if !$ttl; 191 $stamp = '' if !$stamp; 192 $loc = '' if !$loc; 193 $loc = '' if $loc =~ /^:+$/; 163 194 if ($zone =~ /\.arpa$/) { 164 195 ($code,$msg) = DNSDB::_zone2cidr($zone); 165 196 $dbh->do("INSERT INTO revzones (revnet,group_id,status) VALUES (?,1,1)", undef, ($msg)); 166 197 my ($rdns) = $dbh->selectrow_array("SELECT currval('revzones_rdns_id_seq')"); 167 $dbh->do("INSERT INTO records (rdns_id,host,type,val,ttl) VALUES (?,?,6,?,?)", undef, 168 ($rdns, "$contact:$master", "$refresh:$retry:$expire:$minttl", $ttl)); 198 $recsth->execute(0, $rdns, "$contact:$master", 6, "$refresh:$retry:$expire:$minttl", 0, 0, 0, $ttl); 169 199 } else { 170 200 $dbh->do("INSERT INTO domains (domain,group_id,status) VALUES (?,1,1)", undef, ($zone)); 171 201 my ($domid) = $dbh->selectrow_array("SELECT currval('domains_domain_id_seq')"); 172 $dbh->do("INSERT INTO records (rdns_id,host,type,val,ttl) VALUES (?,?,6,?,?)", undef, 173 ($domid, "$contact:$master", "$refresh:$retry:$expire:$minttl", $ttl)); 174 } 175 202 $recsth->execute($domid, 0, "$contact:$master", 6, "$refresh:$retry:$expire:$minttl", 0, 0, 0, $ttl); 203 } 204 return; # since we don't use the "standard" record-add call at the bottom 176 205 } elsif ($rec =~ /^\@/) { 177 206 $cnt{MX}++; … … 179 208 $cnt{TXT}++; 180 209 181 sub _deoctal { 182 my $targ = shift; 183 while ($$targ =~ /\\(\d{3})/) { 184 my $sub = chr(oct($1)); 185 $$targ =~ s/\\$1/$sub/g; 186 } 187 } 188 189 my ($fqdn, $rdata, $ttl, $time, $loc) = split /:/, $rec; 210 my ($fqdn, $rdata, $ttl, $stamp, $loc) = split /:/, $rec, 5; 190 211 $fqdn =~ s/^'//; 191 212 _deoctal(\$rdata); 192 193 print "$fqdn TXT '$rdata'\n" if $fqdn =~ /^\*/; 213 $ttl = 0 if !$ttl; 214 $stamp = '' if !$stamp; 215 $loc = '' if !$loc; 216 $loc = '' if $loc =~ /^:+$/; 217 194 218 my $domid = DNSDB::_hostparent($dbh, $fqdn); 195 219 if ($domid) { … … 201 225 } elsif ($rec =~ /^\./) { 202 226 $cnt{NSASOA}++; 227 my ($fqdn, $ip, $ns, $ttl, $stamp, $loc) = split /:/, $rec, 6; 228 $fqdn =~ s/^\.//; 229 $fqdn =~ s/\.$//; 230 $ns =~ s/\.$//; 231 $ns = "$ns.ns.$fqdn" if $ns !~ /\./; 232 $ttl = 0 if !$ttl; 233 $stamp = '' if !$stamp; 234 $loc = '' if !$loc; 235 $loc = '' if $loc =~ /^:+$/; 236 237 if ($fqdn =~ /\.arpa$/) { 238 ($code,$msg) = DNSDB::_zone2cidr($fqdn); 239 my ($rdns) = $dbh->selectrow_array("SELECT rdns_id FROM revzones WHERE revnet = ?", undef, ($msg)); 240 if (!$rdns) { 241 $errstr = "adding revzone $msg"; 242 $dbh->do("INSERT INTO revzones (revnet,group_id,status) VALUES (?,1,1)", undef, ($msg)); 243 ($rdns) = $dbh->selectrow_array("SELECT currval('revzones_rdns_id_seq')"); 244 # this would probably make a lot more sense to do hostmaster.$config{admindomain} 245 $recsth->execute(0, $rdns, "hostmaster.$fqdn:$ns", 6, "16384:2048:1048576:2560", 0, 0, 0, "2560"); 246 } 247 $recsth->execute(0, $rdns, $ns, 2, "$msg", 0, 0, 0, $ttl); 248 ##fixme: (?) implement full conversion of tinydns . records? 249 # -> problem: A record for NS must be added to the appropriate *forward* zone, not the reverse 250 #$recsth->execute(0, $rdns, $ns, 1, $ip, 0, 0, 0, $ttl) 251 # ... auto-A-record simply does not make sense in reverse zones. Functionally 252 # I think it would work, sort of, but it's a nasty mess and anyone hosting reverse 253 # zones has names for their nameservers already. 254 # Even the auto-nameserver-fqdn comes out... ugly. 255 256 ##work 257 } else { 258 my ($domid) = $dbh->selectrow_array("SELECT domain_id FROM domains WHERE lower(domain) = lower(?)", 259 undef, ($fqdn)); 260 if (!$domid) { 261 $errstr = "adding domain $fqdn"; 262 $dbh->do("INSERT INTO domains (domain,group_id,status) VALUES (?,1,1)", undef, ($fqdn)); 263 ($domid) = $dbh->selectrow_array("SELECT currval('domains_domain_id_seq')"); 264 $recsth->execute($domid, 0, "hostmaster.$fqdn:$ns", 6, "16384:2048:1048576:2560", 0, 0, 0, "2560"); 265 } 266 $recsth->execute($domid, 0, $fqdn, 2, $ns, 0, 0, 0, $ttl); 267 $recsth->execute($domid, 0, $ns, 1, $ip, 0, 0, 0, $ttl) if $ip; 268 } 269 270 271 } elsif ($rec =~ /^\%/) { 272 $cnt{VIEWS}++; 203 273 } elsif ($rec =~ /^:/) { 204 274 $cnt{NCUST}++;
Note:
See TracChangeset
for help on using the changeset viewer.