Changeset 523
- Timestamp:
- 10/19/12 17:32:12 (12 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/IPDB.pm
r519 r523 25 25 %disp_alloctypes %list_alloctypes %def_custids @citylist @poplist @masterblocks 26 26 %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 29 31 &getNodeList 30 32 &mailNotify … … 35 37 %disp_alloctypes %list_alloctypes %def_custids @citylist @poplist 36 38 @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 39 43 &getNodeList 40 44 &mailNotify … … 311 315 } 312 316 } # 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 323 sub 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 = '<NONE>' if !$bigfree; 341 $$_{bigfree} = $bigfree; 342 } 343 return $mlist; 344 } # end listSummary() 345 346 347 # &listMaster &listRBlock 313 348 314 349 -
trunk/cgi-bin/main.cgi
r519 r523 90 90 my $page; 91 91 if (-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); 93 93 } else { 94 94 $page = HTML::Template->new(filename => "dunno.tmpl"); … … 218 218 # Initial display: Show master blocks with total allocated subnets, total free subnets 219 219 sub 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 '') ? ("<NONE>") : ("/".$bigfree{"$master"}) ) 270 ); 271 push (@masterlist, \%row); 272 } 273 $page->param(masterlist => \@masterlist); 220 my $masterlist = listSummary($ip_dbh); 221 $page->param(masterlist => $masterlist); 274 222 275 223 $page->param(addmaster => ($IPDBacl{$authuser} =~ /a/) ); 276 277 224 } # showSummary 278 225 -
trunk/templates/index.tmpl
r517 r523 10 10 </tr> 11 11 <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>"> 13 13 <td><a href="<TMPL_VAR NAME=webpath>/cgi-bin/main.cgi?action=showmaster&block=<TMPL_VAR NAME=master>"><TMPL_VAR NAME=master></a></td> 14 14 <td><TMPL_VAR NAME=routed></td>
Note:
See TracChangeset
for help on using the changeset viewer.