Changeset 523 for trunk/cgi-bin/IPDB.pm


Ignore:
Timestamp:
10/19/12 17:32:12 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Move SQL for index/summary page into IPDB.pm. See #34.
Tweak initialization of page templates to set loop_context_vars so
we don't have to manually maintain the row0/row1 entries
Commentstub subs for master and routed list pages.

File:
1 edited

Legend:

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

    r519 r523  
    2525        %disp_alloctypes %list_alloctypes %def_custids @citylist @poplist @masterblocks
    2626        %allocated %free %routed %bigfree %IPDBacl %aclmsg
    27         &initIPDBGlobals &connectDB &finish &checkDBSanity &allocateBlock &addMaster
    28         &deleteBlock &getBlockData
     27        &initIPDBGlobals &connectDB &finish &checkDBSanity
     28        &addMaster
     29        &listSummary &listMaster &listRBlock
     30        &allocateBlock &deleteBlock &getBlockData
    2931        &getNodeList
    3032        &mailNotify
     
    3537                %disp_alloctypes %list_alloctypes %def_custids @citylist @poplist
    3638                @masterblocks %allocated %free %routed %bigfree %IPDBacl %aclmsg
    37                 &initIPDBGlobals &connectDB &finish &checkDBSanity &allocateBlock
    38                 &addMaster &deleteBlock &getBlockData
     39                &initIPDBGlobals &connectDB &finish &checkDBSanity
     40                &addMaster
     41                &listSummary &listMaster &listRBlock
     42                &allocateBlock &deleteBlock &getBlockData
    3943                &getNodeList
    4044                &mailNotify
     
    311315  }
    312316} # end addMaster
     317
     318
     319## IPDB::listSummary()
     320# Get summary list of all master blocks
     321# Returns an arrayref to a list of hashrefs containing the master block, routed count,
     322# allocated count, free count, and largest free block masklength
     323sub listSummary {
     324  my $dbh = shift;
     325
     326  my $mlist = $dbh->selectall_arrayref("SELECT cidr AS master FROM masterblocks ORDER BY cidr", { Slice => {} });
     327
     328  foreach (@{$mlist}) {
     329    my ($rcnt) = $dbh->selectrow_array("SELECT count(*) FROM routed WHERE cidr <<= ?", undef, ($$_{master}));
     330    $$_{routed} = $rcnt;
     331    my ($acnt) = $dbh->selectrow_array("SELECT count(*) FROM allocations WHERE cidr <<= ?", undef, ($$_{master}));
     332    $$_{allocated} = $acnt;
     333    my ($fcnt) = $dbh->selectrow_array("SELECT count(*) FROM freeblocks WHERE cidr <<= ?".
     334        " AND (routed='y' OR routed='n')", undef, ($$_{master}));
     335    $$_{free} = $fcnt;
     336    my ($bigfree) = $dbh->selectrow_array("SELECT maskbits FROM freeblocks WHERE cidr <<= ?".
     337        " AND (routed='y' OR routed='n') ORDER BY maskbits LIMIT 1", undef, ($$_{master}));
     338##fixme:  should find a way to do this without having to HTMLize the <>
     339    $bigfree = "/$bigfree" if $bigfree;
     340    $bigfree = '&lt;NONE&gt;' if !$bigfree;
     341    $$_{bigfree} = $bigfree;
     342  }
     343  return $mlist;
     344} # end listSummary()
     345
     346
     347# &listMaster &listRBlock
    313348
    314349
Note: See TracChangeset for help on using the changeset viewer.