Changeset 523 for trunk/cgi-bin/main.cgi


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/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
Note: See TracChangeset for help on using the changeset viewer.