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


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!!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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();
Note: See TracChangeset for help on using the changeset viewer.