Changeset 533 for trunk/cgi-bin/main.cgi


Ignore:
Timestamp:
10/31/12 15:47:53 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Clean up and move SQL for finding a free block to allocate from
into IPDB.pm. See #34.
Also fix a minor "Use of uninitialized value...".

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/main.cgi

    r532 r533  
    405405  } else { # end show pool options
    406406
    407 ##fixme: uninitialized
    408     if ($webvar{fbassign} eq 'y') {
     407    if ($webvar{fbassign} && $webvar{fbassign} eq 'y') {
    409408      $cidr = new NetAddr::IP $webvar{block};
    410409      $webvar{maskbits} = $cidr->masklen;
     
    415414        return;
    416415      }
    417       my $sql;
    418       my $city;
    419       my $failmsg;
    420       my $extracond = '';
    421       if ($webvar{allocfrom} eq '-') {
    422 ##fixme: uninitialized
    423         $extracond = ($webvar{allowpriv} eq 'on' ? '' :
    424                 " and not (cidr <<= '192.168.0.0/16'".
    425                         " or cidr <<= '10.0.0.0/8'".
    426                         " or cidr <<= '172.16.0.0/12')");
    427       }
    428       my $sortorder;
     416
     417##fixme ick, ew, bleh.  gotta handle the failure message generation better.  push it into findAllocateFrom()?
     418      my $failmsg = "No suitable free block found.<br>\n";
    429419      if ($webvar{alloctype} eq 'rm') {
    430         if ($webvar{allocfrom} ne '-') {
    431           $sql = "select * from freeblocks where maskbits<=$webvar{maskbits} and routed='n'".
    432                 " and cidr <<= '$webvar{allocfrom}'";
    433           $sortorder = "maskbits desc";
    434         } else {
    435           $sql = "select * from freeblocks where maskbits<=$webvar{maskbits} and routed='n'";
    436           $sortorder = "maskbits desc";
    437         }
    438         $failmsg = "No suitable free block found.<br>\nWe do not have a free".
    439           " routeable block of that size.<br>\nYou will have to either route".
    440           " a set of smaller netblocks or a single smaller netblock.";
     420        $failmsg .= "We do not have a free routeable block of that size.<br>\n".
     421                "You will have to either route a set of smaller netblocks or a single smaller netblock.";
    441422      } else {
    442 ##fixme
    443 # This section needs serious Pondering.
    444         # Pools of most types get assigned to the POP they're "routed from"
    445         # This includes WAN blocks and other netblock "containers"
    446         # This does NOT include cable pools.
    447423        if ($webvar{alloctype} =~ /^.[pc]$/) {
    448           $city = $webvar{city};
    449           $failmsg = "No suitable free block found.<br>\nYou will have to route another".
    450             " superblock from one of the<br>\nmaster blocks or chose a smaller".
    451             " block size for the pool.";
     424          $failmsg .= "You will have to route another superblock from one of the<br>\n".
     425                "master blocks or chose a smaller block size for the pool.";
    452426        } else {
    453427          if (!$webvar{pop}) {
     
    455429            return;
    456430          }
    457           $city = $webvar{pop};
    458           $failmsg = "No suitable free block found.<br>\nYou will have to route another".
    459             " superblock to $webvar{pop}<br>\nfrom one of the master blocks or".
    460             " chose a smaller blocksize.";
    461         }
    462         if (defined $webvar{allocfrom} && $webvar{allocfrom} ne '-') {
    463           $sql = "select cidr from freeblocks where city='$city' and maskbits<=$webvar{maskbits}".
    464                 " and cidr <<= '$webvar{allocfrom}' and routed='".
    465                 (($webvar{alloctype} =~ /^(.)r$/) ? "$1" : 'y')."'";
    466           $sortorder = "maskbits desc,cidr";
    467         } else {
    468           $sql = "select cidr from freeblocks where city='$city' and maskbits<=$webvar{maskbits}".
    469                 " and routed='".(($webvar{alloctype} =~ /^(.)r$/) ? "$1" : 'y')."'";
    470           $sortorder = "maskbits desc,cidr";
     431          $failmsg .= "You will have to route another superblock to $webvar{pop}<br>\n".
     432                "from one of the master blocks or chose a smaller blocksize.";
    471433        }
    472434      }
    473       $sql = $sql.$extracond." order by ".$sortorder;
    474       $sth = $ip_dbh->prepare($sql);
    475       $sth->execute;
    476       my @data = $sth->fetchrow_array();
    477       if ($data[0] eq "") {
     435
     436      $cidr = findAllocateFrom($ip_dbh, $webvar{maskbits}, $webvar{alloctype}, $webvar{city}, $webvar{pop},
     437        (master => $webvar{allocfrom}, allowpriv => $webvar{allowpriv}) );
     438      if (!$cidr) {
    478439        $page->param(err => $failmsg);
    479440        return;
    480441      }
    481       $cidr = new NetAddr::IP $data[0];
     442      $cidr = new NetAddr::IP $cidr;
    482443    } # check for freeblocks assignment or IPDB-controlled assignment
    483444
Note: See TracChangeset for help on using the changeset viewer.