Changeset 913
- Timestamp:
- 11/02/17 16:24:13 (7 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/IPDB.pm
r902 r913 1003 1003 1004 1004 # Snag the allocations for this block 1005 my $sth = $dbh->prepare("SELECT cidr,city,type,custid,swip,description,vrf,id,master_id".1005 my $sth = $dbh->prepare("SELECT masklen(cidr),cidr,city,type,custid,swip,description,vrf,id,master_id". 1006 1006 " FROM allocations WHERE parent_id = ? ORDER BY cidr"); 1007 1007 $sth->execute($args{parent}); … … 1018 1018 my $freesth = $dbh->prepare("SELECT count(*) FROM freeblocks WHERE cidr <<= ? AND master_id = ?"); 1019 1019 my $lfreesth = $dbh->prepare("SELECT masklen(cidr) AS maskbits FROM freeblocks WHERE cidr <<= ?". 1020 " AND master_id = ? ORDER BY masklen(cidr) LIMIT 1");1020 " AND master_id = ? ORDER BY masklen(cidr)"); 1021 1021 1022 1022 my @blocklist; 1023 while (my ($ cidr,$city,$type,$custid,$swip,$desc,$vrf,$id,$mid) = $sth->fetchrow_array()) {1023 while (my ($blockmask,$cidr,$city,$type,$custid,$swip,$desc,$vrf,$id,$mid) = $sth->fetchrow_array()) { 1024 1024 $desc .= " - vrf:$vrf" if $desc && $vrf; 1025 1025 $desc = "vrf:$vrf" if !$desc && $vrf; … … 1033 1033 my ($free) = $freesth->fetchrow_array(); 1034 1034 $lfreesth->execute($cidr, $mid); 1035 1036 # make sure we capture the first one separately... 1035 1037 my ($lfree) = $lfreesth->fetchrow_array(); 1038 my $num_ipfree = ($lfree ? 2**(32-$lfree) : 0); 1039 # ... so this can proceed without accidentally whacking it 1040 while (my ($freemask) = $lfreesth->fetchrow_array) { 1041 $num_ipfree += 2**(32-$freemask); 1042 } 1043 if ($type =~ /^.[dp]$/) { 1044 ($num_ipfree) = $dbh->selectrow_array("SELECT count(*) FROM poolips WHERE parent_id = ? AND available = 'y'", undef, $id); 1045 } 1046 my $pctfree = sprintf "%0.1f", $num_ipfree / 2**(32-$blockmask) * 100; 1036 1047 $lfree = "/$lfree" if $lfree; 1037 1048 $lfree = '<NONE>' if !$lfree; 1049 1038 1050 my %row = ( 1039 1051 block => $cidr, … … 1049 1061 # $row{subblock} = ($type =~ /^.r$/); # hmf. wonder why these won't work in the hash declaration... 1050 1062 $row{listpool} = ($type =~ /^.[pd]$/); 1063 # only set this on suitable types (pools, containers) 1064 $row{pctfree} = "$num_ipfree IPs, $pctfree" if $type =~ /^.[cpdm]/; 1051 1065 push (@blocklist, \%row); 1052 1066 } … … 3321 3335 } else { 3322 3336 my $binfo = $dbh->selectrow_hashref(qq( 3323 SELECT a.id, a.cidr AS block, a.city, a.vrf, a.parent_id, a.master_id, a.swip, $commonfields,3337 SELECT a.id, masklen(a.cidr), a.cidr AS block, a.city, a.vrf, a.parent_id, a.master_id, a.swip, $commonfields, 3324 3338 f.cidr AS reserve, f.id as reserve_id, 3325 3339 d.zone >>= a.cidr AS revavail, d.zone << a.cidr AS revpartial, d.location, … … 3333 3347 WHERE a.id = ? 3334 3348 ), undef, ($id) ); 3349 3350 if ($binfo->{type} =~ /^.[dp]$/) { 3351 ($binfo->{nfree}) = $dbh->selectrow_array("SELECT count(*) FROM poolips WHERE parent_id = ? AND available = 'y'", undef, $id); 3352 } else { 3353 # assemble free IP count 3354 my $tmp = $dbh->prepare("SELECT 2^(32-masklen(cidr)) AS fc FROM freeblocks WHERE parent_id = ?"); 3355 $tmp->execute($id); 3356 my $nfree = 0; 3357 while (my ($fc) = $tmp->fetchrow_array) { 3358 $nfree += $fc; 3359 } 3360 $binfo->{nfree} = $nfree; 3361 } 3335 3362 3336 3363 return $binfo; -
trunk/cgi-bin/MyIPDB.pm
r902 r913 81 81 # 2 lists all entries in a container in CIDR order 82 82 # Both show free blocks in a group at the bottom as previously 83 # $IPDB::sublistlayout = 1;83 $IPDB::sublistlayout = 2; 84 84 85 85 ## UI layout for showing VRFs and master blocks -
trunk/cgi-bin/main.cgi
r906 r913 430 430 # Common elements 431 431 my $pinfo = getBlockData($ip_dbh, $webvar{parent}); 432 $page->param(blockpctfree => sprintf("%0.1f", $pinfo->{nfree}/2**(32-$pinfo->{masklen}) * 100 ) ); 432 433 433 434 ##fixme: do we add a wrapper to not show the edit link for master blocks? … … 453 454 my $cidr = new NetAddr::IP $poolinfo->{block}; 454 455 $page->param(vlan => $poolinfo->{vlan}); 456 $page->param(poolpctfree => sprintf("%0.1f", $poolinfo->{nfree}/2**(32-$poolinfo->{masklen}) * 100 ) ); 455 457 456 458 # Tree navigation -
trunk/templates/listpool.tmpl
r771 r913 3 3 <div class="tbltitle">Listing pool IPs for <TMPL_VAR NAME=block><br> 4 4 (<TMPL_VAR NAME=disptype> in <TMPL_VAR NAME=city>)<TMPL_IF vlan><br> 5 VLAN <TMPL_VAR NAME=vlan></TMPL_IF></div> 5 VLAN <TMPL_VAR NAME=vlan></TMPL_IF> 6 <TMPL_VAR NAME=poolpctfree>% free</div> 6 7 7 8 <br> -
trunk/templates/showsubs.tmpl
r692 r913 1 1 <div class="tbltitle">Subnets in <TMPL_VAR NAME=block> 2 (<a href="<TMPL_VAR NAME=webpath>/cgi-bin/main.cgi?action=edit&id=<TMPL_VAR NAME=self_id>&basetype=b">Edit</a>) 2 (<a href="<TMPL_VAR NAME=webpath>/cgi-bin/main.cgi?action=edit&id=<TMPL_VAR NAME=self_id>&basetype=b">Edit</a>)<TMPL_IF blockpctfree><br><TMPL_VAR NAME=blockpctfree>% free</TMPL_IF> 3 3 </div> 4 4 -
trunk/templates/showsubs2.tmpl
r827 r913 1 1 <div class="tbltitle">Subnets in <TMPL_VAR NAME=block> 2 (<a href="<TMPL_VAR NAME=webpath>/cgi-bin/main.cgi?action=edit&id=<TMPL_VAR NAME=self_id>&basetype=b">Edit</a>) 2 (<a href="<TMPL_VAR NAME=webpath>/cgi-bin/main.cgi?action=edit&id=<TMPL_VAR NAME=self_id>&basetype=b">Edit</a>)<TMPL_IF blockpctfree><br><TMPL_VAR NAME=blockpctfree>% free</TMPL_IF> 3 3 4 </div> 4 5 <br> … … 30 31 <td><TMPL_VAR NAME=type></td> 31 32 <td><a href="<TMPL_VAR NAME=webpath>/cgi-bin/search.cgi?stype=q&input=<TMPL_VAR NAME=custid>"><TMPL_VAR NAME=custid></a></td> 32 <td><TMPL_IF hassubs><TMPL_VAR NAME=subfree> free<TMPL_IF subfree>, largest <TMPL_VAR ESCAPE=HTML NAME=lfree></TMPL_IF></TMPL_IF> 33 <td><TMPL_IF hassubs><TMPL_VAR NAME=subfree> free<TMPL_IF subfree>, largest <TMPL_VAR ESCAPE=HTML NAME=lfree></TMPL_IF></TMPL_IF><TMPL_IF pctfree><TMPL_IF hassubs>, </TMPL_IF><TMPL_VAR NAME=pctfree>%</TMPL_IF> 33 34 </td> 34 35 <td><TMPL_VAR NAME=desc></td>
Note:
See TracChangeset
for help on using the changeset viewer.