Changeset 913 for trunk/cgi-bin
- Timestamp:
- 11/02/17 16:24:13 (7 years ago)
- Location:
- trunk/cgi-bin
- Files:
-
- 3 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
Note:
See TracChangeset
for help on using the changeset viewer.