Changeset 561 for trunk/cgi-bin


Ignore:
Timestamp:
12/19/12 16:09:04 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Work in progress, see #5:
Replace listMaster() and listRBlock() with listSubs() due to
the merge of routing and other container types.

File:
1 edited

Legend:

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

    r560 r561  
    2727        &initIPDBGlobals &connectDB &finish &checkDBSanity
    2828        &addMaster &touchMaster
    29         &listSummary &listMaster &listRBlock &listFree &listPool
     29        &listSummary &listSubs &listFree &listPool
    3030        &getMasterList &getTypeList &getPoolSelect &findAllocateFrom
    3131        &ipParent &subParent &blockParent &getRoutedCity
     
    4141                &initIPDBGlobals &connectDB &finish &checkDBSanity
    4242                &addMaster &touchMaster
    43                 &listSummary &listMaster &listRBlock &listFree &listPool
     43                &listSummary &listSubs &listFree &listPool
    4444                &getMasterList &getTypeList &getPoolSelect &findAllocateFrom
    4545                &ipParent &subParent &blockParent &getRoutedCity
     
    359359  return $mlist;
    360360} # end listSummary()
     361
     362
     363## IPDB::listSubs()
     364# Get list of subnets within a specified CIDR block, on a specified VRF.
     365# Returns an arrayref to a list of hashrefs containing the CIDR block, customer location or
     366# city it's routed to, block type, SWIP status, and description
     367sub listSubs {
     368  my $dbh = shift;
     369  my %args = @_;
     370
     371  # Just In Case
     372  $args{vrf} = '' if !$args{vrf};
     373  $args{rdepth} = 1 if !$args{rdepth};
     374
     375  # Snag the allocations for this block
     376  my $sth = $dbh->prepare("SELECT cidr,city,type,custid,swip,description".
     377        " FROM allocations WHERE parent = ? AND rdepth = ? ORDER BY cidr");
     378  $sth->execute($args{block},$args{rdepth});
     379
     380  # hack hack hack
     381  # set up to flag swip=y records if they don't actually have supporting data in the customers table
     382  my $custsth = $dbh->prepare("SELECT count(*) FROM customers WHERE custid = ?");
     383
     384  my @blocklist;
     385  while (my ($cidr,$city,$type,$custid,$swip,$desc) = $sth->fetchrow_array()) {
     386    $custsth->execute($custid);
     387    my ($ncust) = $custsth->fetchrow_array();
     388    my %row = (
     389        block => $cidr,
     390        city => $city,
     391        type => $disp_alloctypes{$type},
     392        custid => $custid,
     393        swip => ($swip eq 'y' ? 'Yes' : 'No'),
     394        partswip => ($swip eq 'y' && $ncust == 0 ? 1 : 0),
     395        desc => $desc,
     396        hassubs => ($type eq 'rm' || $type =~ /.c/ ? 1 : 0),
     397        );
     398#    $row{subblock} = ($type =~ /^.r$/);         # hmf.  wonder why these won't work in the hash declaration...
     399    $row{listpool} = ($type =~ /^.[pd]$/);
     400    push (@blocklist, \%row);
     401  }
     402  return \@blocklist;
     403} # end listSubs()
    361404
    362405
Note: See TracChangeset for help on using the changeset viewer.