Changeset 913 for trunk


Ignore:
Timestamp:
11/02/17 16:24:13 (7 years ago)
Author:
Kris Deugau
Message:

/trunk

Add IP count and percent-free to the heading and showsubs layout 2 by request

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/IPDB.pm

    r902 r913  
    10031003
    10041004  # 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".
    10061006        " FROM allocations WHERE parent_id = ? ORDER BY cidr");
    10071007  $sth->execute($args{parent});
     
    10181018  my $freesth = $dbh->prepare("SELECT count(*) FROM freeblocks WHERE cidr <<= ? AND master_id = ?");
    10191019  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)");
    10211021
    10221022  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()) {
    10241024    $desc .= " - vrf:$vrf" if $desc && $vrf;
    10251025    $desc = "vrf:$vrf" if !$desc && $vrf;
     
    10331033    my ($free) = $freesth->fetchrow_array();
    10341034    $lfreesth->execute($cidr, $mid);
     1035
     1036    # make sure we capture the first one separately...
    10351037    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;
    10361047    $lfree = "/$lfree" if $lfree;
    10371048    $lfree = '<NONE>' if !$lfree;
     1049
    10381050    my %row = (
    10391051        block => $cidr,
     
    10491061#    $row{subblock} = ($type =~ /^.r$/);         # hmf.  wonder why these won't work in the hash declaration...
    10501062    $row{listpool} = ($type =~ /^.[pd]$/);
     1063    # only set this on suitable types (pools, containers)
     1064    $row{pctfree} = "$num_ipfree IPs, $pctfree" if $type =~ /^.[cpdm]/;
    10511065    push (@blocklist, \%row);
    10521066  }
     
    33213335  } else {
    33223336    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,
    33243338                f.cidr AS reserve, f.id as reserve_id,
    33253339                d.zone >>= a.cidr AS revavail, d.zone << a.cidr AS revpartial, d.location,
     
    33333347        WHERE a.id = ?
    33343348        ), 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    }
    33353362
    33363363    return $binfo;
  • trunk/cgi-bin/MyIPDB.pm

    r902 r913  
    8181# 2 lists all entries in a container in CIDR order
    8282# Both show free blocks in a group at the bottom as previously
    83 # $IPDB::sublistlayout = 1;
     83$IPDB::sublistlayout = 2;
    8484
    8585## UI layout for showing VRFs and master blocks
  • trunk/cgi-bin/main.cgi

    r906 r913  
    430430  # Common elements
    431431  my $pinfo = getBlockData($ip_dbh, $webvar{parent});
     432  $page->param(blockpctfree => sprintf("%0.1f", $pinfo->{nfree}/2**(32-$pinfo->{masklen}) * 100 ) );
    432433
    433434##fixme:  do we add a wrapper to not show the edit link for master blocks?
     
    453454  my $cidr = new NetAddr::IP $poolinfo->{block};
    454455  $page->param(vlan => $poolinfo->{vlan});
     456  $page->param(poolpctfree => sprintf("%0.1f", $poolinfo->{nfree}/2**(32-$poolinfo->{masklen}) * 100 ) );
    455457
    456458  # Tree navigation
  • trunk/templates/listpool.tmpl

    r771 r913  
    33<div class="tbltitle">Listing pool IPs for <TMPL_VAR NAME=block><br>
    44(<TMPL_VAR NAME=disptype> in <TMPL_VAR NAME=city>)<TMPL_IF vlan><br>
    5 VLAN <TMPL_VAR NAME=vlan></TMPL_IF></div>
     5VLAN <TMPL_VAR NAME=vlan></TMPL_IF>
     6<TMPL_VAR NAME=poolpctfree>% free</div>
    67
    78<br>
  • trunk/templates/showsubs.tmpl

    r692 r913  
    11<div class="tbltitle">Subnets in <TMPL_VAR NAME=block>
    2 (<a href="<TMPL_VAR NAME=webpath>/cgi-bin/main.cgi?action=edit&amp;id=<TMPL_VAR NAME=self_id>&amp;basetype=b">Edit</a>)
     2(<a href="<TMPL_VAR NAME=webpath>/cgi-bin/main.cgi?action=edit&amp;id=<TMPL_VAR NAME=self_id>&amp;basetype=b">Edit</a>)<TMPL_IF blockpctfree><br><TMPL_VAR NAME=blockpctfree>% free</TMPL_IF>
    33</div>
    44
  • trunk/templates/showsubs2.tmpl

    r827 r913  
    11<div class="tbltitle">Subnets in <TMPL_VAR NAME=block>
    2 (<a href="<TMPL_VAR NAME=webpath>/cgi-bin/main.cgi?action=edit&amp;id=<TMPL_VAR NAME=self_id>&amp;basetype=b">Edit</a>)
     2(<a href="<TMPL_VAR NAME=webpath>/cgi-bin/main.cgi?action=edit&amp;id=<TMPL_VAR NAME=self_id>&amp;basetype=b">Edit</a>)<TMPL_IF blockpctfree><br><TMPL_VAR NAME=blockpctfree>% free</TMPL_IF>
     3
    34</div>
    45<br>
     
    3031<td><TMPL_VAR NAME=type></td>
    3132<td><a href="<TMPL_VAR NAME=webpath>/cgi-bin/search.cgi?stype=q&amp;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>
    3334</td>
    3435<td><TMPL_VAR NAME=desc></td>
Note: See TracChangeset for help on using the changeset viewer.