Changeset 636


Ignore:
Timestamp:
10/09/14 18:05:07 (10 years ago)
Author:
Kris Deugau
Message:

/trunk

Commit 9/mumble for work done intermittently over the past ~year.
See #5, comment 25:

  • Update getBlockData(); used several places (likely including previous commits in this series)
File:
1 edited

Legend:

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

    r634 r636  
    15261526# private/restricted data, for a CIDR block or pool IP
    15271527# Also returns SWIP status flag for CIDR blocks or pool netblock for IPs
    1528 # Takes the block/IP to look up, routing depth, and VRF identifier
     1528# Takes the block ID or IP to look up and an optional flag to indicate a pool IP lookup
     1529# instead of a netblock.
    15291530# Returns a hashref to the block data
    15301531sub getBlockData {
    15311532  my $dbh = shift;
    1532   my $block = shift;
    1533   my $rdepth = shift;
    1534   my $vrf = shift || '';
    1535 
    1536   my $cidr = new NetAddr::IP $block;
    1537 
    1538   # better way to find IP allocations vs /32 "netblocks"
    1539   my $btype = $dbh->selectrow_array("SELECT type FROM searchme WHERE cidr=?", undef, ($block) );
    1540 
    1541   if (defined($rdepth) && $rdepth == 0) {
    1542     # Only master blocks exist at rdepth 0
    1543     my $binfo = $dbh->selectrow_hashref("SELECT cidr AS block, 'mm' AS type, 0 AS parent, cidr,".
    1544         " ctime, mtime, rwhois, vrf".
    1545         " FROM masterblocks WHERE cidr = ?", undef, ($block) );
    1546 #       " FROM masterblocks WHERE cidr = ? AND vrf = ?", undef, ($block, $vrf) );
    1547     return $binfo;
    1548   } elsif ($btype =~ /^.i$/) {
     1533  my $id = shift;
     1534  my $type = shift || 'b';      # default to netblock for lazy callers
     1535
     1536  # netblocks are in the allocations table;  pool IPs are in the poolips table.
     1537  # If we try to look up a CIDR in an integer field we should just get back nothing.
     1538  my ($btype) = $dbh->selectrow_array("SELECT type FROM allocations WHERE id=?", undef, ($id) );
     1539
     1540  if ($type eq 'i') {
    15491541    my $binfo = $dbh->selectrow_hashref("SELECT ip AS block, custid, type, city, circuitid, description,".
    1550         " notes, modifystamp AS lastmod, privdata, vrf, pool, rdepth, rdns".
    1551         " FROM poolips WHERE ip = ?", undef, ($block) );
    1552 #       " FROM poolips WHERE ip = ? AND vrf = ?", undef, ($block, $vrf) );
     1542        " notes, modifystamp AS lastmod, privdata, vrf, rdns, parent_id, master_id".
     1543        " FROM poolips WHERE id = ?", undef, ($id) );
    15531544    return $binfo;
    15541545  } else {
    1555     my $binfo = $dbh->selectrow_hashref("SELECT cidr AS block, parent, custid, type, city, circuitid, ".
    1556         "description, notes, modifystamp AS lastmod, privdata, vrf, swip, rdepth, rdns".
    1557         " FROM allocations WHERE cidr = ? AND rdepth = ?", undef, ($block, $rdepth) );
    1558 #       " FROM allocations WHERE cidr = ? AND rdepth = ? AND vrf = ?", undef, ($block, $rdepth, $vrf) );
     1546    my $binfo = $dbh->selectrow_hashref("SELECT cidr AS block, custid, type, city, circuitid, ".
     1547        "description, notes, modifystamp AS lastmod, privdata, vrf, swip, rdns, parent_id, master_id".
     1548        " FROM allocations WHERE id = ?", undef, ($id) );
    15591549    return $binfo;
    15601550  }
Note: See TracChangeset for help on using the changeset viewer.