Changeset 557


Ignore:
Timestamp:
12/19/12 12:00:11 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Work in progress, see #5:
Update getBlockData() to handle new table logic and fields

File:
1 edited

Legend:

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

    r556 r557  
    12071207
    12081208## IPDB::getBlockData()
    1209 # Get CIDR or IP, custid, type, city, circuit ID, description, notes, modification time, private/restricted
    1210 # data, for a CIDR block or pool IP
    1211 # Also returns SWIP status flag for CIDR blocks
    1212 # Takes the block/IP to look up
    1213 # Returns an arrayref to a list of hashrefs
     1209# Get CIDR or IP, custid, type, city, circuit ID, description, notes, modification time,
     1210# private/restricted data, for a CIDR block or pool IP
     1211# Also returns SWIP status flag for CIDR blocks or pool netblock for IPs
     1212# Takes the block/IP to look up, routing depth, and VRF identifier
     1213# Returns a hashref to the block data
    12141214sub getBlockData {
    12151215  my $dbh = shift;
    12161216  my $block = shift;
     1217  my $rdepth = shift;
     1218  my $vrf = shift || '';
    12171219
    12181220  my $cidr = new NetAddr::IP $block;
    12191221
    1220   my $keycol = 'cidr';
    1221   my $blocktable = 'allocations';
    1222   my $poolip = 0;
    1223 
    1224   # Pool IP and IPv6 check all in one!  Still needs to be tightened
    1225   # up a little for the as-yet-unhandled case of IPv6 IP pools
    1226   if ($cidr->bits == 32 && $cidr->masklen == 32) {
    1227     $poolip = 1;
    1228     $keycol = 'ip';
    1229     $blocktable = 'poolips';
    1230   }
    1231   my $binfo = $dbh->selectrow_hashref("SELECT $keycol AS block, custid, type, city, circuitid, description,".
    1232         " notes, modifystamp AS lastmod, privdata".($poolip ? '' : ', swip')." FROM $blocktable".
    1233         " WHERE $keycol = ?", undef, ($block) );
    1234   return $binfo;
     1222  # better way to find IP allocations vs /32 "netblocks"
     1223  my $btype = $dbh->selectrow_array("SELECT type FROM searchme WHERE cidr=?", undef, ($block) );
     1224
     1225  if (defined($rdepth) && $rdepth == 0) {
     1226    # Only master blocks exist at rdepth 0
     1227    my $binfo = $dbh->selectrow_hashref("SELECT cidr AS block, 'mm' AS type, 0 AS parent, cidr,".
     1228        " ctime, mtime, rwhois, vrf".
     1229        " FROM masterblocks WHERE cidr = ? AND vrf = ?", undef, ($block, $vrf) );
     1230    return $binfo;
     1231  } elsif ($btype =~ /^.i$/) {
     1232    my $binfo = $dbh->selectrow_hashref("SELECT ip AS block, custid, type, city, circuitid, description,".
     1233        " notes, modifystamp AS lastmod, privdata, vrf, pool, rdepth".
     1234        " FROM poolips WHERE ip = ? AND vrf = ?", undef, ($block, $vrf) );
     1235    return $binfo;
     1236  } else {
     1237    my $binfo = $dbh->selectrow_hashref("SELECT cidr AS block, parent, custid, type, city, circuitid, ".
     1238        "description, notes, modifystamp AS lastmod, privdata, vrf, swip, rdepth".
     1239        " FROM allocations WHERE cidr = ? AND rdepth = ?", undef, ($block, $rdepth) );
     1240#       " FROM allocations WHERE cidr = ? AND rdepth = ? AND vrf = ?", undef, ($block, $rdepth, $vrf) );
     1241    return $binfo;
     1242  }
    12351243} # end getBlockData()
    12361244
Note: See TracChangeset for help on using the changeset viewer.