Changeset 523


Ignore:
Timestamp:
10/19/12 17:32:12 (11 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.

Location:
trunk
Files:
3 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
  • trunk/cgi-bin/main.cgi

    r519 r523  
    9090my $page;
    9191if (-e "$ENV{HTML_TEMPLATE_ROOT}/$webvar{action}.tmpl") {
    92   $page = HTML::Template->new(filename => "$webvar{action}.tmpl");
     92  $page = HTML::Template->new(filename => "$webvar{action}.tmpl", loop_context_vars => 1);
    9393} else {
    9494  $page = HTML::Template->new(filename => "dunno.tmpl");
     
    218218# Initial display:  Show master blocks with total allocated subnets, total free subnets
    219219sub showSummary {
    220   my %allocated;
    221   my %free;
    222   my %routed;
    223   my %bigfree;
    224 
    225   # Count the allocations.
    226   $sth = $ip_dbh->prepare("select count(*) from allocations where cidr <<= ?");
    227   foreach my $master (@masterblocks) {
    228     $sth->execute("$master");
    229     $sth->bind_columns(\$allocated{"$master"});
    230     $sth->fetch();
    231   }
    232 
    233   # Count routed blocks
    234   $sth = $ip_dbh->prepare("select count(*) from routed where cidr <<= ?");
    235   foreach my $master (@masterblocks) {
    236     $sth->execute("$master");
    237     $sth->bind_columns(\$routed{"$master"});
    238     $sth->fetch();
    239   }
    240 
    241   # Count the free blocks.
    242   $sth = $ip_dbh->prepare("select count(*) from freeblocks where cidr <<= ? and ".
    243         "(routed='y' or routed='n')");
    244   foreach my $master (@masterblocks) {
    245     $sth->execute("$master");
    246     $sth->bind_columns(\$free{"$master"});
    247     $sth->fetch();
    248   }
    249 
    250   # Find the largest free block in each master
    251   $sth = $ip_dbh->prepare("select maskbits from freeblocks where cidr <<= ? and ".
    252         "(routed='y' or routed='n') order by maskbits limit 1");
    253   foreach my $master (@masterblocks) {
    254     $sth->execute("$master");
    255     $sth->bind_columns(\$bigfree{"$master"});
    256     $sth->fetch();
    257   }
    258 
    259   # Assemble the data to stuff into the template.
    260   my @masterlist;
    261   my $rowclass=0;
    262   foreach my $master (@masterblocks) {
    263     my %row = (
    264         rowclass => $rowclass++ % 2,
    265         master => "$master",
    266         routed => $routed{"$master"},
    267         allocated => $allocated{"$master"},
    268         free => $free{"$master"},
    269         bigfree => ( ($bigfree{"$master"} eq '') ? ("&lt;NONE&gt;") : ("/".$bigfree{"$master"}) )
    270         );
    271     push (@masterlist, \%row);
    272   }
    273   $page->param(masterlist => \@masterlist);
     220  my $masterlist = listSummary($ip_dbh);
     221  $page->param(masterlist => $masterlist);
    274222
    275223  $page->param(addmaster => ($IPDBacl{$authuser} =~ /a/) );
    276 
    277224} # showSummary
    278225
  • trunk/templates/index.tmpl

    r517 r523  
    1010</tr>
    1111<TMPL_LOOP NAME=masterlist>
    12 <tr class="row<TMPL_VAR name=rowclass>">
     12<tr class="row<TMPL_IF __odd__>0<TMPL_ELSE>1</TMPL_IF>">
    1313<td><a href="<TMPL_VAR NAME=webpath>/cgi-bin/main.cgi?action=showmaster&amp;block=<TMPL_VAR NAME=master>"><TMPL_VAR NAME=master></a></td>
    1414<td><TMPL_VAR NAME=routed></td>
Note: See TracChangeset for help on using the changeset viewer.