Changeset 484
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r483 r484 4340 4340 # Import a domain via AXFR 4341 4341 # Takes AXFR host, domain to transfer, group to put the domain in, 4342 # and optionally: 4343 # - active/inactive state flag (defaults to active) 4344 # - overwrite-SOA flag (defaults to off) 4345 # - overwrite-NS flag (defaults to off, doesn't affect subdomain NS records) 4342 # and an optional hash containing: 4343 # status - active/inactive state flag (defaults to active) 4344 # rwsoa - overwrite-SOA flag (defaults to off) 4345 # rwns - overwrite-NS flag (defaults to off, doesn't affect subdomain NS records) 4346 # merge - flag to automerge A or AAAA records with matching PTR records 4346 4347 # Returns a status code (OK, WARN, or FAIL) and message - message should be blank 4347 4348 # if status is OK, but WARN includes conditions that are not fatal but should 4348 4349 # really be reported. 4349 4350 sub importAXFR { 4350 my $dbh = shift; 4351 my $self = shift; 4352 my $dbh = $self->{dbh}; 4351 4353 my $ifrom_in = shift; 4352 4354 my $zone = shift; 4353 4355 my $group = shift; 4354 my $status = shift; 4355 $status = (defined($status) ? $status : 0); # force sane semantics, and allow passing "null" (inactive) status 4356 my $rwsoa = shift || 0; 4357 my $rwns = shift || 0; 4358 my $newttl = shift; 4359 my $merge = shift || 0; # do we attempt to merge A/AAAA and PTR records whenever possible? 4360 # do we overload this with the fixme below? 4356 4357 my %args = @_; 4358 4361 4359 ##fixme: add mode to delete&replace, merge+overwrite, merge new? 4360 4361 $args{status} = (defined($args{status}) ? $args{status} : 0); 4362 $args{status} = 1 if $args{status} eq 'on'; 4362 4363 4363 4364 my $nrecs = 0; … … 4465 4466 if ($rev eq 'n') { 4466 4467 ##fixme: serial 4467 $dbh->do("INSERT INTO domains (domain,group_id,status) VALUES (?,?,?)", undef, ($zone,$group,$status) ); 4468 $dbh->do("INSERT INTO domains (domain,group_id,status) VALUES (?,?,?)", undef, 4469 ($zone, $group, $args{status}) ); 4468 4470 # get domain id so we can do the records 4469 4471 ($zone_id) = $dbh->selectrow_array("SELECT currval('domains_domain_id_seq')"); … … 4473 4475 } else { 4474 4476 ##fixme: serial 4475 $dbh->do("INSERT INTO revzones (revnet,group_id,status) VALUES (?,?,?)", undef, ($cidr,$group,$status) ); 4477 $dbh->do("INSERT INTO revzones (revnet,group_id,status) VALUES (?,?,?)", undef, 4478 ($cidr,$group,$args{status}) ); 4476 4479 # get revzone id so we can do the records 4477 4480 ($zone_id) = $dbh->selectrow_array("SELECT currval('revzones_rdns_id_seq')"); … … 4512 4515 my $type = $rr->type; 4513 4516 my $host = $rr->name; 4514 my $ttl = ($ newttl ? $newttl: $rr->ttl); # allow force-override TTLs4517 my $ttl = ($args{newttl} ? $args{newttl} : $rr->ttl); # allow force-override TTLs 4515 4518 4516 4519 $soaflag = 1 if $type eq 'SOA'; … … 4542 4545 } elsif ($type eq 'NS') { 4543 4546 # hmm. should we warn here if subdomain NS'es are left alone? 4544 next if ($ rwns&& ($rr->name eq $zone));4547 next if ($args{rwns} && ($rr->name eq $zone)); 4545 4548 if ($rev eq 'y') { 4546 4549 # revzones have records more or less reversed from forward zones. … … 4578 4581 } 4579 4582 } elsif ($type eq 'SOA') { 4580 next if $ rwsoa;4583 next if $args{rwsoa}; 4581 4584 $host = $rr->rname.":".$rr->mname; 4582 4585 $val = $rr->refresh.":".$rr->retry.":".$rr->expire.":".$rr->minimum; … … 4626 4629 my $logentry = "[AXFR ".($rev eq 'n' ? $zone : $cidr)."] "; 4627 4630 4628 if ($ merge) {4631 if ($args{merge}) { 4629 4632 if ($rev eq 'n') { 4630 4633 # importing a domain; we have A and AAAA records that could be merged with matching PTR records … … 4672 4675 } 4673 4676 } # $rev eq 'y' 4674 } # if $ merge4677 } # if $args{merge} 4675 4678 4676 4679 # Insert the new record … … 4681 4684 4682 4685 if ($type eq 'SOA') { 4683 # also !$ rwsoa, but if that's set, it should be impossible to get here.4686 # also !$args{rwsoa}, but if that's set, it should be impossible to get here. 4684 4687 my @tmp1 = split /:/, $host; 4685 4688 my @tmp2 = split /:/, $val; … … 4707 4710 4708 4711 # Overwrite SOA record 4709 if ($ rwsoa) {4712 if ($args{rwsoa}) { 4710 4713 $soaflag = 1; 4711 4714 my $sthgetsoa = $dbh->prepare("SELECT host,val,ttl FROM default_records WHERE group_id=? AND type=?"); … … 4720 4723 4721 4724 # Overwrite NS records 4722 if ($ rwns) {4725 if ($args{rwns}) { 4723 4726 $nsflag = 1; 4724 4727 my $sthgetns = $dbh->prepare("SELECT host,val,ttl FROM default_records WHERE group_id=? AND type=?"); -
trunk/dns.cgi
r483 r484 1562 1562 foreach my $domain (@domlist) { 1563 1563 my %row; 1564 my ($code,$msg) = importAXFR($dbh, $webvar{ifrom}, $domain, $webvar{group}, 1565 $webvar{domactive}, $webvar{rwsoa}, $webvar{rwns}, ($webvar{forcettl} ? $webvar{newttl} : 0), 1566 $webvar{mergematching}); 1564 my ($code,$msg) = $dnsdb->importAXFR($webvar{ifrom}, $domain, $webvar{group}, 1565 status => $webvar{domactive}, rwsoa => $webvar{rwsoa}, rwns => $webvar{rwns}, 1566 newttl => ($webvar{forcettl} ? $webvar{newttl} : 0), 1567 merge => $webvar{mergematching}); 1567 1568 $row{domok} = $msg if $code eq 'OK'; 1568 1569 if ($code eq 'WARN') {
Note:
See TracChangeset
for help on using the changeset viewer.