Changeset 717
- Timestamp:
- 04/15/16 12:23:03 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dns-rpc.cgi
r710 r717 580 580 my $zone = new NetAddr::IP $zonelist->[0]->{revnet}; 581 581 if ($zone->contains($cidr)) { 582 # We need to strip the CIDR mask on IPv4 /32 assignments, or we just add a new record all the time. 583 my $filt = ($cidr->{isv6} || $cidr->masklen != 32 ? "$cidr" : $cidr->addr); 584 my $reclist = $dnsdb->getRecList(defrec => 'n', revrec => 'y', 582 # We need to strip the CIDR mask on IPv4 /32 or v6 /128 assignments, or we just add a new record all the time. 583 my $filt = ( $cidr->{isv6} ? ($cidr->masklen != 128 ? "$cidr" : $cidr->addr) : 584 ($cidr->masklen != 32 ? "$cidr" : $cidr->addr) ); 585 my $reclist = $dnsdb->getRecList(rpc => 1, defrec => 'n', revrec => 'y', 585 586 id => $zonelist->[0]->{rdns_id}, filter => $filt); 586 587 ##fixme: Figure some new magic to automerge new incoming A(AAA)+PTR requests … … 598 599 || $rec->{type} == 65282 || $rec->{type} == 65283 || $rec->{type} == 65284; 599 600 next unless $rec->{val} eq $filt; # make sure we really update the record we want to update. 600 my %newrec = (host => $args{name}, val => $args{cidr}, type => $args{type}); 601 # canonicalize the IP values so funny IPv6 short forms don't 602 # cause non-updates by not being literally string-equal 603 $rec->{val} = new NetAddr::IP $rec->{val}; 604 my $tmpcidr = new NetAddr::IP $args{cidr}; 605 my %newrec = (host => $args{name}, val => $tmpcidr, type => $args{type}); 601 606 rpc_updateRec(defrec =>'n', revrec => 'y', id => $rec->{record_id}, 602 607 parent_id => $zonelist->[0]->{rdns_id}, address => "$cidr", %args) … … 620 625 # that spans multiple reverse zones (eg, /23 CIDR -> 2 /24 rzones) 621 626 foreach my $zdata (@$zonelist) { 622 my $reclist = $dnsdb->getRecList( defrec => 'n', revrec => 'y',627 my $reclist = $dnsdb->getRecList(rpc => 1, defrec => 'n', revrec => 'y', 623 628 id => $zdata->{rdns_id}, filter => $zdata->{revnet}); 624 629 if (scalar(@$reclist) == 0) { … … 627 632 address => "$args{cidr}", %args); 628 633 } else { 634 my $updflag = 0; 629 635 foreach my $rec (@$reclist) { 630 636 # only the composite and/or template types; pure PTR or nontemplate composite 631 637 # types are nominally impossible here. 632 638 next unless $rec->{type} == 65282 || $rec->{type} == 65283 || $rec->{type} == 65284; 639 my %newrec = (host => $args{name}, val => $zdata->{revnet}, type => $args{type}); 633 640 rpc_updateRec(defrec => 'n', revrec => 'y', id => $rec->{record_id}, 634 parent_id => $zdata->{rdns_id}, %args); 641 parent_id => $zdata->{rdns_id}, %args) 642 if _checkRecMod($rec, \%newrec); # and only do the update if there really is something to change 643 $updflag = 1; 635 644 last; # only do one record. 636 645 } 637 } 646 # catch the case of "oops, no zone-sized template record and need to add a new one", 647 # because the SOA and NS records will be returned from the getRecList() call above 648 unless ($updflag) { 649 my $type = ($cidr->{isv6} ? 65284 : 65283); 650 rpc_addRec(defrec => 'n', revrec => 'y', parent_id => $zdata->{rdns_id}, type => $type, 651 address => $zdata->{revnet}, %args); 652 } 653 } # scalar(@$reclist) != 0 638 654 } # iterate zones within $cidr 639 655 } # done $cidr-contains-zones … … 658 674 # now we check the parts of the block that didn't get passed to see if they should be deleted 659 675 my $block = new NetAddr::IP $args{cidr}; 660 foreach my $ip (@{$block->splitref(32)}) { 661 my $bare = $ip->addr; 662 next if $args{"host_$bare"}; 663 delByCIDR(delforward => 1, delsubs => 0, cidr => $bare, location => $args{location}, 676 if (!$block->{isv6}) { 677 foreach my $ip (@{$block->splitref(32)}) { 678 my $bare = $ip->addr; 679 next if $args{"host_$bare"}; 680 delByCIDR(delforward => 1, delsubs => 0, cidr => $bare, location => $args{location}, 664 681 rpcuser => $args{rpcuser}, rpcsystem => $args{rpcsystem}); 682 } 665 683 } 666 684 … … 687 705 if ($zone->contains($cidr)) { 688 706 # Find the first record in the reverse zone that matches the CIDR we're splitting... 689 my $reclist = $dnsdb->getRecList( defrec => 'n', revrec => 'y',707 my $reclist = $dnsdb->getRecList(rpc => 1, defrec => 'n', revrec => 'y', 690 708 id => $zonelist->[0]->{rdns_id}, filter => $cidr, sortby => 'val', sortorder => 'DESC'); 691 709 my $oldrec; … … 896 914 $args{delforward} = 0 if !$args{delforward}; 897 915 916 # make sure this is set if not passed 917 $args{location} = '' if !$args{location}; 918 898 919 # much like addOrUpdateRevRec() 899 920 my $zonelist = $dnsdb->getZonesByCIDR(%args); … … 909 930 if ($args{delsubs}) { 910 931 # Delete ALL EVARYTHING!!one11!! in $args{cidr} 911 my $reclist = $dnsdb->getRecList( defrec => 'n', revrec => 'y', id => $zonelist->[0]->{rdns_id});932 my $reclist = $dnsdb->getRecList(rpc => 1, defrec => 'n', revrec => 'y', id => $zonelist->[0]->{rdns_id}); 912 933 foreach my $rec (@$reclist) { 913 934 my $reccidr = new NetAddr::IP $rec->{val}; … … 935 956 # Selectively delete only exact matches on $args{cidr} 936 957 # We need to strip the CIDR mask on IPv4 /32 assignments, or we can't find single-IP records 937 my $filt = ($cidr->{isv6} || $cidr->masklen != 32 ? "$cidr" : $cidr->addr); 938 my $reclist = $dnsdb->getRecList(defrec => 'n', revrec => 'y', 958 my $filt = ( $cidr->{isv6} ? ($cidr->masklen != 128 ? "$cidr" : $cidr->addr) : 959 ($cidr->masklen != 32 ? "$cidr" : $cidr->addr) ); 960 my $reclist = $dnsdb->getRecList(rpc => 1, defrec => 'n', revrec => 'y', location => $args{location}, 939 961 id => $zonelist->[0]->{rdns_id}, filter => $filt, sortby => 'val', sortorder => 'DESC'); 940 962 foreach my $rec (@$reclist) { 941 963 my $reccidr = new NetAddr::IP $rec->{val}; 942 964 next unless $cidr == $reccidr; 943 # restrict to the right location944 next unless ( defined($rec->{locname}) && defined($args{location}) &&945 $rec->{locname} eq $args{location} );946 965 next unless $rec->{type} == 12 || $rec->{type} == 65280 || $rec->{type} == 65281 || 947 966 $rec->{type} == 65282 || $rec->{type} == 65283 ||$rec->{type} == 65284; … … 967 986 # that spans multiple reverse zones (eg, /23 CIDR -> 2 /24 rzones) 968 987 foreach my $zdata (@$zonelist) { 969 my $reclist = $dnsdb->getRecList( defrec => 'n', revrec => 'y', id => $zdata->{rdns_id});988 my $reclist = $dnsdb->getRecList(rpc => 1, defrec => 'n', revrec => 'y', id => $zdata->{rdns_id}); 970 989 if (scalar(@$reclist) == 0) { 971 990 # nothing to do? or do we (re)add a record based on the parent?
Note:
See TracChangeset
for help on using the changeset viewer.