Changeset 675 for trunk/cgi-bin


Ignore:
Timestamp:
01/15/15 17:52:26 (10 years ago)
Author:
Kris Deugau
Message:

/trunk

Extend per-IP rDNS through the "confirm add" page and the "edit" page. See #1.

  • Add flag in getBlockRDNS return to indicate if the results are from local caching instead of RPC results. There isn't really a clear way to globally flag "RPC server is up".
  • Add a sub to retrieve per-IP reverse DNS information for a passed CIDR range. Not limited in IPDB.pm, but dnsadmin will refuse to return anything for a block larger than /24 (v4) or /120 (v6) - an 8 bit inverse mask.
  • Use the new sub on editing a small(ish) non-pool block. CSS magic notwithstanding, handling more than 32 IPs in a list like this is awkward.
Location:
trunk/cgi-bin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/IPDB.pm

    r674 r675  
    3232        &getMasterList &getTypeList &getPoolSelect &findAllocateFrom
    3333        &ipParent &subParent &blockParent &getRoutedCity
    34         &allocateBlock &updateBlock &deleteBlock &getBlockData &getBlockRDNS
     34        &allocateBlock &updateBlock &deleteBlock &getBlockData &getBlockRDNS &getRDNSbyIP
    3535        &getNodeList &getNodeName &getNodeInfo
    3636        &mailNotify
     
    4747                &getMasterList &getTypeList &getPoolSelect &findAllocateFrom
    4848                &ipParent &subParent &blockParent &getRoutedCity
    49                 &allocateBlock &updateBlock &deleteBlock &getBlockData &getBlockRDNS
     49                &allocateBlock &updateBlock &deleteBlock &getBlockData &getBlockRDNS &getRDNSbyIP
    5050                &getNodeList &getNodeName &getNodeInfo
    5151                &mailNotify
     
    16801680
    16811681  $args{type} = 'b' if !$args{type};
     1682  my $cached = 1;
    16821683
    16831684  # snag entry from database
     
    17211722    my $remote_rdns = _rpc('getRevPattern', %rpcargs);
    17221723    $rdns = $remote_rdns if $remote_rdns;
     1724    $cached = 0;
    17231725  }
    17241726
    17251727  # hmm.  do we care about where it actually came from?
    1726   return $rdns;
     1728  return $rdns, $cached;
    17271729} # end getBlockRDNS()
     1730
     1731
     1732## IPDB::getRDNSbyIP()
     1733# Get individual reverse entries for the IP or CIDR IP range passed.  Sort of looking the
     1734# opposite direction down the netblock tree compared to getBlockRDNS() above.
     1735sub getRDNSbyIP {
     1736  my $dbh = shift;
     1737  my %args = @_;  # We want to accept a variety of call types
     1738
     1739  # key arguments:  allocation ID, type
     1740  unless ($args{id} || $args{type}) {
     1741    $errstr = 'Missing allocation ID or type';
     1742    return;
     1743  }
     1744
     1745  my @ret = ();
     1746  # special case:  single IP.  Check if it's an allocation or in a pool, then do the RPC call for fresh data.
     1747  if ($args{type} =~ /^.i$/) {
     1748    my ($ip, $localrev) = $dbh->selectrow_array("SELECT ip, rdns FROM poolips WHERE id = ?", undef, ($args{id}) );
     1749    push @ret, { 'r_ip' => $ip, 'iphost' => $localrev };
     1750  } else {
     1751    if ($rpc_url) {
     1752      my %rpcargs = (
     1753        rpcuser => $args{user},
     1754        group => $revgroup,     # not sure how this could sanely be exposed, tbh...
     1755        cidr => $args{range},
     1756        );
     1757
     1758      my $remote_rdns = _rpc('getRevSet', %rpcargs);
     1759      return $remote_rdns;
     1760#      $rdns = $remote_rdns if $remote_rdns;
     1761#      $cached = 0;
     1762    }
     1763  }
     1764  return \@ret;
     1765} # end getRDNSbyIP()
    17281766
    17291767
  • trunk/cgi-bin/main.cgi

    r674 r675  
    313313    my $block = new NetAddr::IP $webvar{block};
    314314
    315     my $rdns = getBlockRDNS($ip_dbh, id => $webvar{parent}, type => $webvar{fbtype}, user => $authuser);
     315    my ($rdns,$cached) = getBlockRDNS($ip_dbh, id => $webvar{parent}, type => $webvar{fbtype}, user => $authuser);
    316316    $page->param(rdns => $rdns) if $rdns;
    317317    $page->param(parent => $webvar{parent});
    318318    $page->param(fbid => $webvar{fbid});
     319    # visual flag that we're working IPDB-local, not off more authoritative data in dnsadmin
     320    $page->param(cached => $cached);
    319321
    320322    $webvar{fbtype} = '' if !$webvar{fbtype};
     
    687689  $blockinfo->{type} =~ s/\s//;
    688690
     691  my $cached;
    689692  # Get rDNS info;  duplicates a bit of getBlockData but also does the RPC call if possible
    690   $blockinfo->{rdns} = getBlockRDNS($ip_dbh, id => $webvar{id}, type => $blockinfo->{type}, user => $authuser);
     693  ($blockinfo->{rdns},$cached) = getBlockRDNS($ip_dbh, id => $webvar{id}, type => $blockinfo->{type}, user => $authuser);
     694  # visual flag that we're working IPDB-local, not off more authoritative data in dnsadmin
     695  $page->param(cached => $cached);
     696
     697  my $cidr = new NetAddr::IP $blockinfo->{block};
     698  # Limit the per-IP rDNS list based on CIDR length;  larger ones just take up too much space.
     699  # Also, don't show on IP pools;  the individual IPs will have a space for rDNS
     700  # Don't show on single IPs;  these use the "pattern" field
     701  if ($IPDBacl{$authuser} =~ /c/
     702      && $cidr->masklen != $cidr->bits
     703      && ($cidr->bits - $cidr->masklen) <= $IPDB::maxrevlist
     704      && $webvar{alloctype} !~ /^.[dpi]/
     705      # do we want to allow v6 at all?
     706      #&& ! $cidr->{isv6}
     707      ) {
     708    $page->param(r_iplist => getRDNSbyIP($ip_dbh, id => $webvar{id}, type => $blockinfo->{type},
     709        range => $blockinfo->{block}, user => $authuser) );
     710  }
    691711
    692712  $page->param(block    => $blockinfo->{block});
Note: See TracChangeset for help on using the changeset viewer.