Changeset 673 for trunk


Ignore:
Timestamp:
01/15/15 15:27:56 (10 years ago)
Author:
Kris Deugau
Message:

/trunk

Add getRevSet() to retrieve a whole set of per-IP reverse names, and

expose via RPC

Fix module name in comment header for getRevPattern()

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r669 r673  
    46774677
    46784678
    4679 ## IPDB::getRevPattern()
     4679## DNSDB::getRevPattern()
    46804680# Get the narrowest template pattern applicable to a passed CIDR address (may be a netblock or an IP)
    46814681sub getRevPattern {
     
    46954695  return $revpatt;
    46964696} # end getRevPattern()
     4697
     4698
     4699## DNSDB::getRevSet()
     4700# Return the unique per-IP reverse hostnames, if any, for the passed
     4701# CIDR address (may be a netblock or an IP)
     4702sub getRevSet {
     4703  my $self = shift;
     4704  my $dbh = $self->{dbh};
     4705  my $cidr = shift;
     4706  my $group = shift || 1;       # just in case
     4707
     4708  # for speed!  Casting and comparing even ~7K records takes ~2.5s, so narrow it down to one revzone first.
     4709  my ($revid) = $dbh->selectrow_array("SELECT rdns_id FROM revzones WHERE revnet >>= ?",
     4710        undef, ($cidr) );
     4711
     4712  $cidr = new NetAddr::IP $cidr;
     4713  if ($cidr->num > 256) {       # should also catch v6!
     4714    # Even reverse entries for a v4 /24 of IPs is a bit much.  I don't expect
     4715    # there to be a sane reason to retrive more than a /27 at once, really.
     4716    # v6 is going to be hairy no matter how you slice it.
     4717    $errstr = "Reverse hostname detail range too large";
     4718    return;
     4719  }
     4720
     4721  my $sth = $dbh->prepare("SELECT val, host FROM records ".
     4722        "WHERE (type in (12,65280,65281,65282,65283,65284)) AND rdns_id = ? AND inetlazy(val) = ?");
     4723
     4724  my @ret;
     4725  foreach my $ip (@{$cidr->splitref()}) {
     4726    $sth->execute($revid, $ip);
     4727    my @data = $sth->fetchrow_array();
     4728    my %row;
     4729    if (@data) {
     4730      $row{r_ip} = $data[0];
     4731      $row{iphost} = $data[1];
     4732    } else {
     4733      $row{r_ip} = $ip->addr;
     4734      $row{iphost} = '';
     4735    }
     4736    push @ret, \%row;
     4737  }
     4738
     4739  return \@ret;
     4740} # end getRevSet()
    46974741
    46984742
  • trunk/dns-rpc.cgi

    r672 r673  
    9292#sub getLogEntries {}
    9393        'dnsdb.getRevPattern'   => \&getRevPattern,
     94        'dnsdb.getRevSet'       => \&getRevSet,
    9495        'dnsdb.getTypelist'     => \&getTypelist,
    9596        'dnsdb.getTypemap'      => \&getTypemap,
     
    729730}
    730731
     732sub getRevSet {
     733  my %args = @_;
     734
     735  _commoncheck(\%args, 'y');
     736
     737  return $dnsdb->getRevSet($args{cidr}, $args{group});
     738}
     739
    731740sub getTypelist {
    732741  my %args = @_;
Note: See TracChangeset for help on using the changeset viewer.