Changeset 452


Ignore:
Timestamp:
01/11/13 12:21:13 (11 years ago)
Author:
Kris Deugau
Message:

/trunk

Continue tweaking RPC for actual usage. See #43.

  • Add and expose getRevPattern() to retrieve the narrowest template pattern applicable to a passed CIDR (netblock or IP)
  • Add and expose getZonesByCIDR() to retrieve a list of revzones and zone IDs for records within a passed CIDR block. Note the block may be larger than the zones, so we may return more than one revzone.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r451 r452  
    5252        &addRec &updateRec &delRec
    5353        &getLogCount &getLogEntries
     54        &getRevPattern
    5455        &getTypelist
    5556        &parentID
    5657        &isParent
    57         &zoneStatus &importAXFR
     58        &zoneStatus &getZonesByCIDR &importAXFR
    5859        &export
    5960        &mailNotify
     
    7980                &addRec &updateRec &delRec
    8081                &getLogCount &getLogEntries
     82                &getRevPattern
    8183                &getTypelist
    8284                &parentID
    8385                &isParent
    84                 &zoneStatus &importAXFR
     86                &zoneStatus &getZonesByCIDR &importAXFR
    8587                &export
    8688                &mailNotify
     
    39263928
    39273929
     3930## IPDB::getRevPattern()
     3931# Get the narrowest template pattern applicable to a passed CIDR address (may be a netblock or an IP)
     3932sub getRevPattern {
     3933  my $dbh = shift;
     3934  my $cidr = shift;
     3935  my $group = shift || 1;       # just in case
     3936
     3937  my ($revpatt) = $dbh->selectrow_array("SELECT r.host FROM records r JOIN revzones z ON r.rdns_id=z.rdns_id ".
     3938        "WHERE r.type=65282 OR r.type=65283 AND z.group_id=? AND CAST (r.val AS inet) >>= ? ".
     3939        "ORDER BY CAST (r.val AS inet) DESC LIMIT 1", undef, ($group, $cidr) );
     3940  return $revpatt;
     3941} # end getRevPattern()
     3942
     3943
    39283944## DNSDB::getTypelist()
    39293945# Get a list of record types for various UI dropdowns
     
    41534169  return $status;
    41544170} # end zoneStatus()
     4171
     4172
     4173## DNSDB::getZonesByCIDR()
     4174# Get a list of zone names and IDs that records for a passed CIDR block are within.
     4175sub getZonesByCIDR {
     4176  my $dbh = shift;
     4177  my %args = @_;
     4178
     4179  my $result = $dbh->selectall_arrayref("SELECT rdns_id,revnet FROM revzones WHERE revnet >>= ? OR revnet <<= ?",
     4180        { Slice => {} }, ($args{cidr}, $args{cidr}) );
     4181  return $result;
     4182} # end getZonesByCIDR()
    41554183
    41564184
  • trunk/dns-rpc.cgi

    r447 r452  
    6464        'dnsdb.updateRec'       => \&updateRec,
    6565        'dnsdb.delRec'          => \&delRec,
     66#sub getLogCount {}
     67#sub getLogEntries {}
     68        'dnsdb.getRevPattern'   => \&getRevPattern,
    6669        'dnsdb.zoneStatus'      => \&zoneStatus,
     70        'dnsdb.getZonesByCIDR'  => \&getZonesByCIDR,
    6771
    6872        'dnsdb.getMethods'      => \&get_method_list
     
    371375  }
    372376
     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  }
     382
    373383  my @recargs = ($dbh, $args{defrec}, $args{revrec}, $args{parent_id},
    374384        \$args{name}, \$args{type}, \$args{address}, $args{ttl}, $args{location});
     
    392402  _commoncheck(\%args, 'y');
    393403
     404  # get old line, so we can update only the bits that the caller passed to change
     405  # note we subbed address for val since it's a little more caller-friendly
     406  my $oldrec = DNSDB::getRecLine($dbh, $args{defrec}, $args{revrec}, $args{id});
     407  foreach my $field (qw(name type address ttl location distance weight port)) {
     408    $args{$field} = $oldrec->{$field} if !$args{$field} && defined($oldrec->{$field});
     409  }
     410
    394411  # note dist, weight, port are not required on all types;  will be ignored if not needed.
    395412  # parent_id is the "primary" zone we're updating;  necessary for forward/reverse voodoo
     
    415432#sub getLogCount {}
    416433#sub getLogEntries {}
     434
     435sub getRevPattern {
     436  my %args = @_;
     437
     438  _commoncheck(\%args, 'y');
     439
     440  return DNSDB::getRevPattern($dbh, $args{cidr}, $args{group});
     441}
     442
    417443#sub getTypelist {}
    418444#sub parentID {}
     
    428454
    429455  my $status = DNSDB::zoneStatus(@arglist);
     456}
     457
     458# Get a list of hashes referencing the reverse zone(s) for a passed CIDR block
     459sub getZonesByCIDR {
     460  my %args = @_;
     461
     462  _commoncheck(\%args, 'y');
     463
     464  return DNSDB::getZonesByCIDR($dbh, %args);
    430465}
    431466
Note: See TracChangeset for help on using the changeset viewer.