Changeset 710
- Timestamp:
- 03/17/16 15:06:32 (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r709 r710 5183 5183 ## DNSDB::getZonesByCIDR() 5184 5184 # Get a list of zone names and IDs that records for a passed CIDR block are within. 5185 # Optionally restrict to a specific location/view 5185 5186 sub getZonesByCIDR { 5186 5187 my $self = shift; … … 5188 5189 my %args = @_; 5189 5190 5190 my $result = $dbh->selectall_arrayref("SELECT rdns_id,revnet FROM revzones WHERE revnet >>= ? OR revnet <<= ?", 5191 { Slice => {} }, ($args{cidr}, $args{cidr}) ); 5191 my $sql = "SELECT rdns_id,revnet,default_location FROM revzones WHERE revnet >>= ? OR revnet <<= ?". 5192 ($args{location} ? " AND default_location = ?" : ''); 5193 my @svals = ($args{cidr}, $args{cidr}); 5194 push @svals, $args{location} if $args{location}; 5195 5196 my $result = $dbh->selectall_arrayref($sql, { Slice => {} }, @svals ); 5192 5197 return $result; 5193 5198 } # end getZonesByCIDR() … … 5351 5356 ##fixme: serial 5352 5357 $dbh->do("INSERT INTO domains (domain,group_id,status) VALUES (?,?,?)", undef, 5353 ($zone, $group, $args{status}) ) ;5358 ($zone, $group, $args{status}) ) or die $dbh->errstr; 5354 5359 # get domain id so we can do the records 5355 5360 ($zone_id) = $dbh->selectrow_array("SELECT currval('domains_domain_id_seq')"); -
trunk/dns-rpc.cgi
r700 r710 137 137 ## 138 138 139 ## 140 ## Internal utility subs 141 ## 142 139 143 # Check RPC ACL 140 144 sub _aclcheck { … … 174 178 } 175 179 176 # set ttl to zone defa ilt minttl if none is specified180 # set ttl to zone default minttl if none is specified 177 181 sub _ttlcheck { 178 182 my $argref = shift; … … 182 186 } 183 187 } 188 189 # Check if the hashrefs passed in refer to identical record data, so we can skip 190 # the actual update if nothing has actually changed. This is mainly useful for 191 # reducing log noise due to chained calls orginating with updateRevSet() since 192 # "many" records could be sent for update but only one or two have actually changed. 193 sub _checkRecMod { 194 my $oldrec = shift; 195 my $newrec = shift; 196 197 # Because we don't know which fields we've even been passed 198 no warnings qw(uninitialized); 199 200 my $modflag = 0; 201 # order by most common change. host should be first, due to rDNS RPC calls 202 for my $field qw(host type val) { 203 return 1 if ( 204 defined($newrec->{$field}) && 205 $oldrec->{$field} ne $newrec->{$field} ); 206 } 207 208 return 0; 209 } # _checRecMod 210 211 212 ## 213 ## Shims for DNSDB core subs 214 ## 184 215 185 216 #sub connectDB { … … 534 565 } # rpc_updateRec 535 566 567 536 568 # Takes a passed CIDR block and DNS pattern; adds a new record or updates the record(s) affected 537 569 sub addOrUpdateRevRec { … … 540 572 _commoncheck(\%args, 'y'); 541 573 my $cidr = new NetAddr::IP $args{cidr}; 542 543 ##fixme: Minor edge case; if we receive calls one after the other to update544 # to the same thing, we bulk out the log with useless notices. Leaving this545 # for future development since this should be rare in practice.546 574 547 575 my $zonelist = $dnsdb->getZonesByCIDR(%args); … … 570 598 || $rec->{type} == 65282 || $rec->{type} == 65283 || $rec->{type} == 65284; 571 599 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}); 572 601 rpc_updateRec(defrec =>'n', revrec => 'y', id => $rec->{record_id}, 573 parent_id => $zonelist->[0]->{rdns_id}, address => "$cidr", %args); 602 parent_id => $zonelist->[0]->{rdns_id}, address => "$cidr", %args) 603 if _checkRecMod($rec, \%newrec); # and only do the update if there really is something to change 574 604 $flag = 1; 575 605 last; # only do one record. … … 623 653 next unless $key =~ m{^host_((?:[\d.]+|[\da-f:]+)(?:/\d+)?)$}; 624 654 my $ip = $1; 625 push @ret, addOrUpdateRevRec(cidr => $ip, name => $args{$key}, %args); 626 } 655 push @ret, addOrUpdateRevRec(%args, cidr => $ip, name => $args{$key}); 656 } 657 658 # now we check the parts of the block that didn't get passed to see if they should be deleted 659 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}, 664 rpcuser => $args{rpcuser}, rpcsystem => $args{rpcsystem}); 665 } 666 627 667 ##fixme: what about errors? what about warnings? 628 668 return \@ret; … … 901 941 my $reccidr = new NetAddr::IP $rec->{val}; 902 942 next unless $cidr == $reccidr; 943 # restrict to the right location 944 next unless ( defined($rec->{locname}) && defined($args{location}) && 945 $rec->{locname} eq $args{location} ); 903 946 next unless $rec->{type} == 12 || $rec->{type} == 65280 || $rec->{type} == 65281 || 904 947 $rec->{type} == 65282 || $rec->{type} == 65283 ||$rec->{type} == 65284;
Note:
See TracChangeset
for help on using the changeset viewer.