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