Changeset 187


Ignore:
Timestamp:
03/04/05 18:12:54 (20 years ago)
Author:
Kris Deugau
Message:

/trunk

Another herd of changes to alloctypes. This cleaned up the
corner-case messes left by the introduction of subblocks in
/trunk r186, and fixed some other problems related to alloctype
handling. Note that the code changes REQUIRE changes to the
alloctypes table data!!

Location:
trunk
Files:
4 edited

Legend:

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

    r186 r187  
    234234      eval {
    235235        $msg = "Unable to allocate $cidr as '$disp_alloctypes{$type}'";
    236         if ($type eq 'rr') {
     236        if ($type eq 'rm') {
    237237          $sth = $dbh->prepare("update freeblocks set routed='y',city='$city'".
    238238            " where cidr='$cidr'");
     
    244244          # common stuff for end-use, dialup, dynDSL, pools, etc, etc.
    245245
    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'");
     246          # special case - block is a container/"reserve" block
     247          if ($type =~ /^(.)c$/) {
     248            $sth = $dbh->prepare("update freeblocks set routed='$1' where cidr='$cidr'");
    249249            $sth->execute;
    250250          } else {
     
    312312
    313313        # now we have to do some magic for routing blocks
    314         if ($type eq 'rr') {
     314        if ($type eq 'rm') {
    315315
    316316          # Insert the new freeblocks entries
     
    336336          # Insert the new freeblocks entries
    337337          # Along with some more HairyPerl(TM) in case we're inserting a
    338           # subblock (l.) allocation
     338          # subblock (.r) allocation
    339339          $sth = $dbh->prepare("insert into freeblocks (cidr,maskbits,city,routed)".
    340340                " values (?, ?, (select city from routed where cidr >>= '$cidr'),'".
    341                 (($type =~ /^l.$/) ? 'r' : 'y')."')");
     341                (($type =~ /^(.)r$/) ? '$1' : 'y')."')");
    342342          foreach my $block (@newfreeblocks) {
    343343            $sth->execute("$block", $block->masklen);
    344344          }
    345           # special-case for reserve/"container" blocks
    346           if ($type =~ /^r.$/) {
     345          # Special-case for reserve/"container" blocks - generate
     346          # the "extra" freeblocks entry for the container
     347          if ($type =~ /^(.)c$/) {
    347348            $sth = $dbh->prepare("insert into freeblocks (cidr,maskbits,city,routed)".
    348                 " values ('$cidr',".$cidr->masklen.",'$city','r')");
     349                " values ('$cidr',".$cidr->masklen.",'$city','$1')");
    349350            $sth->execute;
    350351          }
     
    500501    eval {
    501502
    502       if ($type eq 'rr') {
     503      if ($type eq 'rm') {
    503504        $msg = "Unable to remove routing allocation $cidr";
    504505        $sth = $dbh->prepare("delete from routed where cidr='$cidr'");
     
    531532                "(select cidr from routed where cidr >>= '$cidr') ".
    532533                " and maskbits<=".$cidr->masklen.
    533                 " and routed='".(($type =~ /^l.$/) ? 'r' : 'y').
     534                " and routed='".(($type =~ /^(.)r$/) ? '$1' : 'y').
    534535                "' order by maskbits desc");
    535536
     
    569570
    570571      # insert "new" freeblocks entry
    571       if ($type eq 'rr') {
     572      if ($type eq 'rm') {
    572573        $sth = $dbh->prepare("insert into freeblocks (cidr,maskbits,city)".
    573574                " values ('$cidr',".$cidr->masklen.",'<NULL>')");
     
    576577                " values ('$cidr',".$cidr->masklen.
    577578                ",(select city from routed where cidr >>= '$cidr'),'".
    578                 (($type =~ /^l.$/) ? 'r' : 'y')."')");
     579                (($type =~ /^(.)r$/) ? '$1' : 'y')."')");
    579580      }
    580581      $sth->execute;
  • trunk/cgi-bin/ipdb.psql

    r182 r187  
    125125mp      Static Pool - Dialup    Static dialup pool      43      DIAL-BUS
    126126wp      Static Pool - Wireless  Static wireless pool    44      WL-BUS
    127 dc      Dynamic cable block     Dynamic cable block     103     CBL-RES
    128 dy      Dynamic DSL block       Dynamic DSL block       102     DSL-RES
    129 dn      Dialup netblock Dialup netblock 101     DIAL-RES
    130 dw      Dynamic WiFi block      Dynamic WiFi block      104     WL-RES
     127ce      Dynamic cable block     Dynamic cable block     103     CBL-RES
     128de      Dynamic DSL block       Dynamic DSL block       102     DSL-RES
     129me      Dialup netblock Dialup netblock 101     DIAL-RES
     130we      Dynamic WiFi block      Dynamic WiFi block      104     WL-RES
    131131mm      Master block    Master block    999     6750400
    132 rr      Routing Routed netblock 500     6750400
     132rm      Routing Routed netblock 500     6750400
    133133in      Internal netblock       Internal netblock       990     6750400
    134 ee      End-use netblock        End-use netblock        100     6750400
     134en      End-use netblock        End-use netblock        100     6750400
    135135sd      Static Pool - Servers   Server pool     40      6750400
    136136cn      Customer netblock       Customer netblock       0       
     
    140140wi      Static IP - Wireless    Static wireless IP      24     
    141141si      Static IP - Server pool Server pool IP  20      6750400
     142wc      Reserve for WAN blocks  WAN IP blocks   200     6750400
     143wr      Internal WAN block      Internal WAN block      201     6750400
     144pc      Reserve for dynamic-route DSL netblocks Dynamic-route netblocks 202     6750400
     145pr      Dynamic-route DSL netblock      Dynamic-route DSL       203     
    142146\.
  • trunk/cgi-bin/main.cgi

    r186 r187  
    324324
    325325  while (my @data = $sth->fetchrow_array) {
    326     # cidr,custid,type,city,description,notes
    327     # Fix up types from pools (which are single-char)
    328     # Fixing the database would be...  painful.  :(
    329 ##fixme LEGACY CODE
    330     if ($data[2] =~ /^[cdsmw]$/) {
    331       $data[2] .= 'i';
    332     }
    333     my @row = ( (($data[2] =~ /^l.$/) ? 'Sub ' : '').
     326    # cidr,custid,type,city,description
     327    # Prefix subblocks with "Sub "
     328    my @row = ( (($data[2] =~ /^.r$/) ? 'Sub ' : '').
    334329        qq(<a href="/ip/cgi-bin/main.cgi?action=edit&block=$data[0]">$data[0]</a>),
    335330        $data[1], $disp_alloctypes{$data[2]}, $data[3], $data[4]);
     
    599594#    $data[2] =~ s/\s+//g;
    600595
    601     my @row = ( (($data[2] =~ /^l.$/) ? 'Sub ' : '').
     596    # Prefix subblocks with "Sub "
     597    my @row = ( (($data[2] =~ /^.r$/) ? 'Sub ' : '').
    602598        qq(<a href="/ip/cgi-bin/main.cgi?action=edit&block=$data[0]">$data[0]</a>),
    603599        $data[1], $disp_alloctypes{$data[2]}, $data[3], $data[4]);
     
    623619        qq(<input type=hidden name=action value="delete">\n).
    624620        qq(<input type=hidden name=block value="$master">\n).
    625         qq(<input type=hidden name=alloctype value="rr">\n).
     621        qq(<input type=hidden name=alloctype value="rm">\n).
    626622        qq(<input type=submit value=" Remove this block ">\n).
    627623        qq(</form>\n);
     
    642638    # cidr,routed
    643639    my $cidr = new NetAddr::IP $data[0];
    644     my @row = ((($data[1] eq 'r') ? 'Sub ' : '').
    645         "<a href=\"/ip/cgi-bin/main.cgi?action=assign&block=$cidr\">$cidr</a>",
     640    # Include some HairyPerl(TM) to prefix subblocks with "Sub "
     641    my @row = ((($data[1] ne 'y' && $data[1] ne 'n') ? 'Sub ' : '').
     642        qq(<a href="/ip/cgi-bin/main.cgi?action=assign&block=$cidr&fbtype=$data[1]">$cidr</a>),
    646643        $cidr->range);
    647644    printRow(\@row, 'color1') if ($count%2 == 0);
     
    733730    $html =~ s|\$\$MASKBITS\$\$|$block->masklen|;
    734731    my $typelist = '';
    735     $sth = $ip_dbh->prepare("select type,listname from alloctypes where listorder < 500 and type not like '_i' order by listorder");
    736     $sth->execute;
    737     my @data = $sth->fetchrow_array;
    738     $typelist .= "<option value='$data[0]' selected>$data[1]</option>\n";
    739     while (my @data = $sth->fetchrow_array) {
    740       $typelist .= "<option value='$data[0]'>$data[1]</option>\n";
     732
     733    # This is a little dangerous, as it's *theoretically* possible to
     734    # get fbtype='n' (aka a non-routed freeblock).  However, should
     735    # someone manage to get there, they get what they deserve.
     736    if ($webvar{fbtype} ne 'y') {
     737      # Snag the type of the block from the database.  We have no
     738      # convenient way to pass this in from the calling location.  :/
     739      $sth = $ip_dbh->prepare("select type from allocations where cidr >>='$block'");
     740      $sth->execute;
     741      my @data = $sth->fetchrow_array;
     742      $data[0] =~ s/c$/r/;      # Munge the type into the correct form
     743      $typelist = "$disp_alloctypes{$data[0]}<input type=hidden name=alloctype value=$data[0]>\n";
     744    } else {
     745      $typelist .= qq(<select name="alloctype">\n);
     746      $sth = $ip_dbh->prepare("select type,listname from alloctypes where listorder < 500 ".
     747        "and type not like '_i' order by listorder");
     748      $sth->execute;
     749      my @data = $sth->fetchrow_array;
     750      $typelist .= "<option value='$data[0]' selected>$data[1]</option>\n";
     751      while (my @data = $sth->fetchrow_array) {
     752        $typelist .= "<option value='$data[0]'>$data[1]</option>\n";
     753      }
     754      $typelist .= "</select>\n";
    741755    }
    742756    $html =~ s|\$\$TYPELIST\$\$|$typelist|g;
     
    842856      my $city;
    843857      my $failmsg;
    844       if ($webvar{alloctype} eq 'rr') {
     858      if ($webvar{alloctype} eq 'rm') {
    845859        if ($webvar{allocfrom} ne '-') {
    846860          $sql = "select * from freeblocks where maskbits<=$webvar{maskbits} and routed='n'".
     
    856870##fixme
    857871# This section needs serious Pondering.
    858         if ($webvar{alloctype} =~ /^.[pd]$/) {
     872        # Pools of all types get assigned to the POP they're "routed from"
     873        # This includes WAN blocks and other netblock "containers"
     874        if ($webvar{alloctype} =~ /^.[pdc]$/) {
    859875          if (($webvar{city} !~ /^(Sudbury|North Bay)$/) && ($webvar{alloctype} eq 'dp')) {
    860876            printError("You must chose Sudbury or North Bay for DSL pools.");
     
    874890          $sql = "select cidr from freeblocks where city='$city' and maskbits<=$webvar{maskbits}".
    875891                " and cidr <<= '$webvar{allocfrom}' and routed='".
    876                 (($webvar{alloctype} =~ /^l.$/) ? 'r' : 'y')."' order by cidr,maskbits desc";
     892                (($webvar{alloctype} =~ /^(.)r$/) ? '$1' : 'y')."' order by cidr,maskbits desc";
    877893        } else {
    878894          $sql = "select cidr from freeblocks where city='$city' and maskbits<=$webvar{maskbits}".
    879                 " and routed='".(($webvar{alloctype} =~ /^l.$/) ? 'r' : 'y').
     895                " and routed='".(($webvar{alloctype} =~ /^(.)r$/) ? '$1' : 'y').
    880896                "' order by cidr,maskbits desc";
    881897        }
     
    10121028  # Check POP location
    10131029  my $flag;
    1014   if ($webvar{alloctype} eq 'rr') {
     1030  if ($webvar{alloctype} eq 'rm') {
    10151031    $flag = 'for a routed netblock';
    10161032    foreach (@poplist) {
     
    10841100# this has now been Requested, so here goes.
    10851101
    1086   if ($data[2] =~ /^d[nyc]|cn|ee|in$/) {
     1102##fixme The check here should be built from the database
     1103  if ($data[2] =~ /^.[ne]$/) {
    10871104    # Block that can be changed
    10881105    my $blockoptions = "<select name=alloctype><option".
    1089         (($data[2] eq 'dn') ? ' selected' : '') ." value='dn'>Dialup netblock</option>\n<option".
    1090         (($data[2] eq 'dy') ? ' selected' : '') ." value='dy'>Dynamic DSL netblock</option>\n<option".
    1091         (($data[2] eq 'dc') ? ' selected' : '') ." value='dc'>Dynamic cable netblock</option>\n<option".
     1106        (($data[2] eq 'me') ? ' selected' : '') ." value='me'>Dialup netblock</option>\n<option".
     1107        (($data[2] eq 'de') ? ' selected' : '') ." value='de'>Dynamic DSL netblock</option>\n<option".  (($data[2] eq 'dc') ? ' selected' : '') ." value='dc'>Dynamic cable netblock</option>\n<option".
     1108        (($data[2] eq 'ce') ? ' selected' : '') ." value='ce'>Dynamic cable netblock</option>\n<option".        (($data[2] eq 'dc') ? ' selected' : '') ." value='dc'>Dynamic cable netblock</option>\n<option".
     1109        (($data[2] eq 'we') ? ' selected' : '') ." value='we'>Dynamic wireless netblock</option>\n<option".     (($data[2] eq 'dc') ? ' selected' : '') ." value='dc'>Dynamic cable netblock</option>\n<option".
    10921110        (($data[2] eq 'cn') ? ' selected' : '') ." value='cn'>Customer netblock</option>\n<option".
    1093         (($data[2] eq 'ee') ? ' selected' : '') ." value='ee'>End-use netblock</option>\n<option".
     1111        (($data[2] eq 'en') ? ' selected' : '') ." value='en'>End-use netblock</option>\n<option".
    10941112        (($data[2] eq 'in') ? ' selected' : '') ." value='in'>Internal netblock</option>\n".
    10951113        "</select>\n";
     
    11901208  my ($cidr, $custid, $type, $city, $circid, $desc, $notes, $alloctype);
    11911209
    1192   if ($webvar{alloctype} eq 'rr') {
     1210  if ($webvar{alloctype} eq 'rm') {
    11931211    $sth = $ip_dbh->prepare("select cidr,city from routed where cidr='$webvar{block}'");
    11941212    $sth->execute();
  • trunk/fb-assign.html

    r110 r187  
    1313<tr class="color1">
    1414<td>Allocation type:</td><td>
    15 <select name="alloctype">
    1615$$TYPELIST$$
    17 </select>
    1816<input type="button" value=" ? " onclick="helpAllocTypes()" class="regular">
    1917</td>
Note: See TracChangeset for help on using the changeset viewer.