Changeset 550 for branches


Ignore:
Timestamp:
11/12/12 17:31:34 (11 years ago)
Author:
Kris Deugau
Message:

/branches/stable

Commit semihack allocate-from-browsed-freeblock changes to stable branch

Location:
branches/stable/cgi-bin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/cgi-bin/IPDB.pm

    r549 r550  
    345345#       and available='y' order by ip limit 1);
    346346
    347       $sth = $dbh->prepare("select ip from poolips where pool='$alloc_from'".
    348         " and available='y' order by ip");
    349       $sth->execute;
    350 
    351       my @data = $sth->fetchrow_array;
    352       $cidr = $data[0];  # $cidr is already declared when we get here!
     347# If no specific IP was requested, pick the next available one from the pool.
     348      if (!$cidr) {
     349        $sth = $dbh->prepare("select ip from poolips where pool='$alloc_from'".
     350          " and available='y' order by ip");
     351        $sth->execute;
     352
     353        my @data = $sth->fetchrow_array;
     354        $cidr = $data[0];  # $cidr is already declared when we get here!
     355      }
    353356
    354357      $sth = $dbh->prepare("update poolips set custid='$custid',".
  • branches/stable/cgi-bin/main.cgi

    r549 r550  
    389389  while (my @data = $sth->fetchrow_array()) {
    390390    my $cidr = new NetAddr::IP $data[0];
    391     my @row = ("$cidr", $cidr->range);
     391    my @row = (
     392        ($IPDBacl{$authuser} =~ /a/ ?
     393                qq(<a href="$IPDB::webpath/cgi-bin/main.cgi?action=assign&block=$cidr&fbtype=n">$cidr</a>)
     394                : $cidr),
     395        $cidr->range);
    392396    printRow(\@row, 'color1' ) if($count%2==0);
    393397    printRow(\@row, 'color2' ) if($count%2!=0);
     
    544548    #   -> if $data[2] (aka poolips.available) == 'n' then we print the unassign link
    545549    #      else we print a blank space
    546     my @row = ( qq(<a href="$IPDB::webpath/cgi-bin/main.cgi?action=edit&block=$data[0]">$data[0]</a>),
     550    my @row;
     551    if ($data[2] eq 'y' && $IPDBacl{$authuser} =~ /a/) {
     552      push @row, qq(<a href="$IPDB::webpath/cgi-bin/main.cgi?action=assign&block=$data[0]&fbtype=i">$data[0]</a>);
     553    } else {
     554      push @row, qq(<a href="$IPDB::webpath/cgi-bin/main.cgi?action=edit&block=$data[0]">$data[0]</a>);
     555    }
     556    push @row, (
    547557        $data[1],$data[2],$data[3],
    548558        ( (($data[2] eq 'n') && ($IPDBacl{$authuser} =~ /d/)) ?
     
    578588    close HTML;
    579589    my $block = new NetAddr::IP $webvar{block};
    580     $html =~ s|\$\$BLOCK\$\$|$block|g;
    581     $html =~ s|\$\$MASKBITS\$\$|$block->masklen|;
     590
    582591    my $typelist = '';
    583592
     
    592601    # get fbtype='n' (aka a non-routed freeblock).  However, should
    593602    # someone manage to get there, they get what they deserve.
    594     if ($webvar{fbtype} ne 'y') {
    595       # Snag the type of the block from the database.  We have no
    596       # convenient way to pass this in from the calling location.  :/
    597       $sth = $ip_dbh->prepare("select type from allocations where cidr >>='$block'");
    598       $sth->execute;
    599       my @data = $sth->fetchrow_array;
    600       $data[0] =~ s/c$/r/;      # Munge the type into the correct form
    601       $typelist = "$list_alloctypes{$data[0]}<input type=hidden name=alloctype value=$data[0]>\n";
    602     } else {
     603#    if ($webvar{fbtype} ne 'y') {
     604#      # Snag the type of the block from the database.  We have no
     605#      # convenient way to pass this in from the calling location.  :/
     606#      $sth = $ip_dbh->prepare("select type from allocations where cidr >>='$block'");
     607#      $sth->execute;
     608#      my @data = $sth->fetchrow_array;
     609#      $data[0] =~ s/c$/r/;     # Munge the type into the correct form
     610#      $typelist = "$list_alloctypes{$data[0]}<input type=hidden name=alloctype value=$data[0]>\n";
     611#    } else {
     612if ($webvar{fbtype} eq 'n') {
     613  $typelist = "Routed netblock<input type=hidden name=alloctype value=rm>\n";
     614  $html =~ s|\$\$ALLOCBLOCK\$\$|<input name=block size=25 value="$block">|;
     615  $html =~ s|\$\$BLOCK\$\$|$block|g;
     616} elsif ($webvar{fbtype} eq 'i') {
     617  my ($iptype,$pool) = $ip_dbh->selectrow_array("SELECT type,pool FROM poolips WHERE ip = ?", undef, ($block));
     618  $typelist = "$list_alloctypes{$iptype}<input type=hidden name=alloctype value=$iptype>\n";
     619  $html =~ s|\$\$ALLOCBLOCK\$\$|$block<input type=hidden name=block size=25 value="$block">|;
     620  $html =~ s|\$\$BLOCK\$\$|$pool|g;
     621} else {
     622  $html =~ s|\$\$ALLOCBLOCK\$\$|<input name=block size=25 value="$block">|;
     623  $html =~ s|\$\$BLOCK\$\$|$block|g;
    603624      $typelist .= qq(<select name="alloctype">\n);
    604625      $sth = $ip_dbh->prepare("select type,listname from alloctypes where listorder < 500 ".
    605         "and type not like '_i' and type not like '_r' order by listorder");
     626        "and type not like '_i' order by listorder");
    606627      $sth->execute;
    607628      my @data = $sth->fetchrow_array;
    608629      $typelist .= "<option value='$data[0]' selected>$data[1]</option>\n";
    609       while (my @data = $sth->fetchrow_array) {
     630      while (@data = $sth->fetchrow_array) {
    610631        $typelist .= "<option value='$data[0]'>$data[1]</option>\n";
    611632      }
     
    700721#  + Different flavours of netblock
    701722
    702   if ($webvar{alloctype} =~ /^.i$/) {
     723  if ($webvar{alloctype} =~ /^.i$/ && $webvar{fbassign} ne 'y') {
    703724    my ($base,undef) = split //, $webvar{alloctype};    # split into individual chars
    704725
     
    722743
    723744    if ($webvar{fbassign} eq 'y') {
     745      $alloc_from = new NetAddr::IP $webvar{allocfrom};
     746## possibly messy behaviour:  force the _from and block to be the network addr?
     747      $alloc_from = qq($alloc_from<input type=hidden name=alloc_from value="$alloc_from">);
    724748      $cidr = new NetAddr::IP $webvar{block};
    725749      $webvar{maskbits} = $cidr->masklen;
     
    790814      }
    791815      $cidr = new NetAddr::IP $data[0];
     816
     817# this chunk now specific to "guided" allocation;  freeblock-select can now slice-n-dice on its own.
     818      $alloc_from = qq($cidr<input type=hidden name=alloc_from value="$cidr">);
     819      # If the block to be allocated is smaller than the one we found,
     820      # figure out the "real" block to be allocated.
     821      if ($cidr->masklen() ne $webvar{maskbits}) {
     822        my $maskbits = $cidr->masklen();
     823        my @subblocks;
     824        while ($maskbits++ < $webvar{maskbits}) {
     825          @subblocks = $cidr->split($maskbits);
     826        }
     827        $cidr = $subblocks[0];
     828      }
    792829    } # check for freeblocks assignment or IPDB-controlled assignment
    793830
    794     $alloc_from = qq($cidr<input type=hidden name=alloc_from value="$cidr">);
    795 
    796     # If the block to be allocated is smaller than the one we found,
    797     # figure out the "real" block to be allocated.
    798     if ($cidr->masklen() ne $webvar{maskbits}) {
    799       my $maskbits = $cidr->masklen();
    800       my @subblocks;
    801       while ($maskbits++ < $webvar{maskbits}) {
    802         @subblocks = $cidr->split($maskbits);
    803       }
    804       $cidr = $subblocks[0];
    805     }
     831
    806832  } # if ($webvar{alloctype} =~ /^.i$/)
    807833
Note: See TracChangeset for help on using the changeset viewer.