Changeset 186 for trunk


Ignore:
Timestamp:
03/03/05 17:14:54 (19 years ago)
Author:
Kris Deugau
Message:

/trunk

First round of changes for "clean" handling of subblock allocations.
Note that the code will likely malfunction in a number of corner
and not-so-corner cases. Fixing those will require rethinking of
the allocation types.

Location:
trunk/cgi-bin
Files:
2 edited

Legend:

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

    r184 r186  
    243243        } else {
    244244          # common stuff for end-use, dialup, dynDSL, pools, etc, etc.
    245           $sth = $dbh->prepare("delete from freeblocks where cidr='$cidr'");
    246           $sth->execute;
    247 
     245
     246          # special case - block is a container/"reserve" block - alloctype begins with 'r'
     247          if ($type =~ /^r.$/) {
     248            $sth = $dbh->prepare("update freeblocks set routed='r' where cidr='$cidr'");
     249            $sth->execute;
     250          } else {
     251            # "normal" case
     252            $sth = $dbh->prepare("delete from freeblocks where cidr='$cidr'");
     253            $sth->execute;
     254          }
    248255          $sth = $dbh->prepare("insert into allocations".
    249256                " (cidr,custid,type,city,description,notes,maskbits,circuitid)".
     
    328335
    329336          # Insert the new freeblocks entries
     337          # Along with some more HairyPerl(TM) in case we're inserting a
     338          # subblock (l.) allocation
    330339          $sth = $dbh->prepare("insert into freeblocks (cidr,maskbits,city,routed)".
    331                 " values (?, ?, (select city from routed where cidr >>= '$cidr'),'y')");
     340                " values (?, ?, (select city from routed where cidr >>= '$cidr'),'".
     341                (($type =~ /^l.$/) ? 'r' : 'y')."')");
    332342          foreach my $block (@newfreeblocks) {
    333343            $sth->execute("$block", $block->masklen);
    334344          }
    335 
     345          # special-case for reserve/"container" blocks
     346          if ($type =~ /^r.$/) {
     347            $sth = $dbh->prepare("insert into freeblocks (cidr,maskbits,city,routed)".
     348                " values ('$cidr',".$cidr->masklen.",'$city','r')");
     349            $sth->execute;
     350          }
    336351          # Insert the allocations entry
    337352          $sth = $dbh->prepare("insert into allocations (cidr,custid,type,city,".
     
    499514      } else { # end alloctype routing case
    500515
    501         $sth = $dbh->prepare("delete from allocations where cidr='$cidr'");
     516        # Delete all allocations within the block being deleted.  This is
     517        # deliberate and correct, and removes the need to special-case
     518        # removal of "container" blocks.
     519        $sth = $dbh->prepare("delete from allocations where cidr <<='$cidr'");
    502520        $sth->execute;
     521
    503522        # Special case - delete pool IPs
    504523        if ($type =~ /^.[pd]$/) {
     
    511530        $sth = $dbh->prepare("select cidr from freeblocks where cidr <<= ".
    512531                "(select cidr from routed where cidr >>= '$cidr') ".
    513                 " and maskbits<=".$cidr->masklen." and routed='y' order by maskbits desc");
     532                " and maskbits<=".$cidr->masklen.
     533                " and routed='".(($type =~ /^l.$/) ? 'r' : 'y').
     534                "' order by maskbits desc");
    514535
    515536      } # end alloctype general case
     
    542563      }
    543564
    544       # Clear old freeblocks entries - if any.  $i==0 if not.
    545       if ($i>0) {
    546         $sth = $dbh->prepare("delete from freeblocks where cidr=?");
    547         foreach my $block (@combinelist) {
    548           $sth->execute("$block");
    549         }
    550       }
     565      # Clear old freeblocks entries - if any.  They should all be within
     566      # the $cidr determined above.
     567      $sth = $dbh->prepare("delete from freeblocks where cidr <<='$cidr'");
     568      $sth->execute;
    551569
    552570      # insert "new" freeblocks entry
     
    557575        $sth = $dbh->prepare("insert into freeblocks (cidr,maskbits,city,routed)".
    558576                " values ('$cidr',".$cidr->masklen.
    559                 ",(select city from routed where cidr >>= '$cidr'),'y')");
     577                ",(select city from routed where cidr >>= '$cidr'),'".
     578                (($type =~ /^l.$/) ? 'r' : 'y')."')");
    560579      }
    561580      $sth->execute;
  • trunk/cgi-bin/main.cgi

    r184 r186  
    331331      $data[2] .= 'i';
    332332    }
    333     my @row = (qq(<a href="/ip/cgi-bin/main.cgi?action=edit&block=$data[0]">$data[0]</a>),
     333    my @row = ( (($data[2] =~ /^l.$/) ? 'Sub ' : '').
     334        qq(<a href="/ip/cgi-bin/main.cgi?action=edit&block=$data[0]">$data[0]</a>),
    334335        $data[1], $disp_alloctypes{$data[2]}, $data[3], $data[4]);
    335336    # Allow listing of pool if desired/required.
     
    598599#    $data[2] =~ s/\s+//g;
    599600
    600     my @row = ("<a href=\"/ip/cgi-bin/main.cgi?action=edit&block=$data[0]\">$data[0]</a>",
     601    my @row = ( (($data[2] =~ /^l.$/) ? 'Sub ' : '').
     602        qq(<a href="/ip/cgi-bin/main.cgi?action=edit&block=$data[0]">$data[0]</a>),
    601603        $data[1], $disp_alloctypes{$data[2]}, $data[3], $data[4]);
    602604    # If the allocation is a pool, allow listing of the IPs in the pool.
     
    634636  # unrouted free blocks, but it's better to let the database do the work if we can.
    635637  $count = 0;
    636   $sth = $ip_dbh->prepare("select cidr from freeblocks where routed='y' and cidr <<= '$master' order by cidr");
     638  $sth = $ip_dbh->prepare("select cidr,routed from freeblocks where cidr <<= '$master'".
     639        " order by cidr");
    637640  $sth->execute();
    638641  while (my @data = $sth->fetchrow_array()) {
    639     # cidr,maskbits,city
     642    # cidr,routed
    640643    my $cidr = new NetAddr::IP $data[0];
    641     my @row = ("<a href=\"/ip/cgi-bin/main.cgi?action=assign&block=$cidr\">$cidr</a>",
     644    my @row = ((($data[1] eq 'r') ? 'Sub ' : '').
     645        "<a href=\"/ip/cgi-bin/main.cgi?action=assign&block=$cidr\">$cidr</a>",
    642646        $cidr->range);
    643647    printRow(\@row, 'color1') if ($count%2 == 0);
     
    869873        if ($webvar{allocfrom} ne '-') {
    870874          $sql = "select cidr from freeblocks where city='$city' and maskbits<=$webvar{maskbits}".
    871                 " and cidr <<= '$webvar{allocfrom}' and routed='y' order by cidr,maskbits desc";
     875                " and cidr <<= '$webvar{allocfrom}' and routed='".
     876                (($webvar{alloctype} =~ /^l.$/) ? 'r' : 'y')."' order by cidr,maskbits desc";
    872877        } else {
    873878          $sql = "select cidr from freeblocks where city='$city' and maskbits<=$webvar{maskbits}".
    874                 " and routed='y' order by cidr,maskbits desc";
     879                " and routed='".(($webvar{alloctype} =~ /^l.$/) ? 'r' : 'y').
     880                "' order by cidr,maskbits desc";
    875881        }
    876882      }
Note: See TracChangeset for help on using the changeset viewer.