Changeset 453 for trunk/dns-rpc.cgi
- Timestamp:
- 01/15/13 18:15:32 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dns-rpc.cgi
r452 r453 63 63 'dnsdb.addRec' => \&addRec, 64 64 'dnsdb.updateRec' => \&updateRec, 65 'dnsdb.addOrUpdateRevRec' => \&addOrUpdateRevRec, 65 66 'dnsdb.delRec' => \&delRec, 66 67 #sub getLogCount {} … … 111 112 unless DNSDB::initRPC($dbh, (username => $argref->{rpcuser}, rpcsys => $argref->{rpcsystem}, 112 113 fullname => ($argref->{fullname} ? $argref->{fullname} : $argref->{rpcuser}) ) ); 114 } 115 } 116 117 # set location to the zone's default location if none is specified 118 sub _loccheck { 119 my $argref = shift; 120 if (!$argref->{location} && $argref->{defrec} eq 'n') { 121 $argref->{location} = DNSDB::getZoneLocation($dbh, $argref->{revrec}, $argref->{parent_id}); 122 } 123 } 124 125 # set ttl to zone defailt minttl if none is specified 126 sub _ttlcheck { 127 my $argref = shift; 128 if (!$argref->{ttl}) { 129 my $tmp = DNSDB::getSOA($dbh, $argref->{defrec}, $argref->{revrec}, $argref->{parent_id}); 130 $argref->{ttl} = $tmp->{minttl}; 113 131 } 114 132 } … … 370 388 _commoncheck(\%args, 'y'); 371 389 372 # add records in the zone's default location if none is specified 373 if (!$args{location} && $args{defrec} eq 'n') { 374 $args{location} = DNSDB::getZoneLocation($dbh, $args{revrec}, $args{parent_id}); 375 } 376 377 # callers may often not care about TTLs 378 if (!$args{ttl}) { 379 my $tmp = DNSDB::getSOA($dbh, $args{defrec}, $args{revrec}, $args{parent_id}); 380 $args{ttl} = $tmp->{minttl}; 381 } 390 _loccheck(\%args); 391 _ttlcheck(\%args); 382 392 383 393 my @recargs = ($dbh, $args{defrec}, $args{revrec}, $args{parent_id}, … … 419 429 } 420 430 431 # Takes a passed CIDR block and DNS pattern; adds a new record or updates the record(s) affected 432 sub addOrUpdateRevRec { 433 my %args = @_; 434 435 _commoncheck(\%args, 'y'); 436 $args{cidr} = new NetAddr::IP $args{cidr}; 437 438 my $zonelist = DNSDB::getZonesByCIDR($dbh, %args); 439 if (scalar(@$zonelist) == 0) { 440 # enhh.... WTF? 441 } elsif (scalar(@$zonelist) == 1) { 442 # check if the single zone returned is bigger than the CIDR. if so, we can just add a record 443 my $zone = new NetAddr::IP $zonelist->[0]->{revnet}; 444 if ($zone->contains($args{cidr})) { 445 my $reclist = DNSDB::getDomRecs($dbh, defrec => 'n', revrec => 'y', 446 id => $zonelist->[0]->{rdns_id}, filter => "$args{cidr}"); 447 if (scalar(@$reclist) == 0) { 448 # Aren't Magic Numbers Fun? See pseudotype list in dnsadmin. 449 my $type = ($args{cidr}->{isv6} ? 65282 : ($args{cidr}->masklen == 32 ? 65280 : 65283) ); 450 addRec(defrec =>'n', revrec => 'y', parent_id => $zonelist->[0]->{rdns_id}, type => $type, 451 address => "$args{cidr}", %args); 452 } else { 453 foreach my $rec (@$reclist) { 454 next unless $rec->{type} == 65282 || $rec->{type} == 65283 || $rec->{type} == 65284; 455 updateRec(defrec =>'n', revrec => 'y', id => $rec->{record_id}, 456 parent_id => $zonelist->[0]->{rdns_id}, %args); 457 last; # only do one record. 458 } 459 } 460 } else { 461 # ebbeh? CIDR is only partly represented in DNS. This needs manual intervention. 462 } # done single-zone-contains-$cidr 463 } else { 464 # Overlapping reverse zones shouldn't be possible, so if we're here we've got a CIDR 465 # that spans multiple reverse zones (eg, /23 CIDR -> 2 /24 rzones) 466 foreach my $zdata (@$zonelist) { 467 my $reclist = DNSDB::getDomRecs($dbh, defrec => 'n', revrec => 'y', 468 id => $zdata->{rdns_id}, filter => $zdata->{revnet}); 469 if (scalar(@$reclist) == 0) { 470 my $type = ($args{cidr}->{isv6} ? 65282 : ($args{cidr}->masklen == 32 ? 65280 : 65283) ); 471 addRec(defrec =>'n', revrec => 'y', parent_id => $zdata->{rdns_id}, type => $type, 472 address => "$args{cidr}", %args); 473 } else { 474 foreach my $rec (@$reclist) { 475 next unless $rec->{type} == 65282 || $rec->{type} == 65283 || $rec->{type} == 65284; 476 updateRec(defrec =>'n', revrec => 'y', id => $rec->{record_id}, 477 parent_id => $zdata->{rdns_id}, %args); 478 last; # only do one record. 479 } 480 } 481 } # iterate zones within $cidr 482 } # done $cidr-contains-zones 483 } 484 421 485 sub delRec { 422 486 my %args = @_;
Note:
See TracChangeset
for help on using the changeset viewer.