Ignore:
Timestamp:
11/05/12 16:53:38 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Extend findAllocateFrom() to allow passing a target block to allocate
to restrict the freeblock selection
Remove local SQL for confirmation page for "assign this block" in
admin.cgi in favour of existing data and subs. See #34.
For admin.cgi "assign this block", if the requested IP type does not
match the pool, the type will be adjusted and a warning pushed out.
Add space on "assign this block" template for a warning.

File:
1 edited

Legend:

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

    r543 r544  
    121121  }
    122122
    123   $sth = $ip_dbh->prepare("select def_custid from alloctypes where type='$webvar{alloctype}'");
    124   $sth->execute;
    125   my @data = $sth->fetchrow_array;
    126   my $custid = $data[0];
     123  my $custid = $def_custids{$webvar{alloctype}};
    127124  if ($custid eq '') {
    128125    if ($webvar{custid} !~ /^(?:\d{10}|\d{7}|STAFF)(?:-\d\d?)?$/) {
     
    146143  }
    147144
    148   my @data;
     145  my $maskbits = $cidr->masklen;
     146  my $fbtmp = findAllocateFrom($ip_dbh, $maskbits, $webvar{alloctype}, '','',
     147        (gimme => "$cidr", allowpriv => 1));
     148
    149149  if ($webvar{alloctype} eq 'rm') {
    150     $sth = $ip_dbh->prepare("select cidr from freeblocks where cidr >>='$cidr' and routed='n'");
    151     $sth->execute;
    152     @data = $sth->fetchrow_array;
    153 # User deserves errors if user can't be bothered to find the free block first.
    154     if (!$data[0]) {
     150    if (!$fbtmp) {
    155151      $page->param(errmsg => "Can't allocate from outside a free block!!");
    156152      goto ERRJUMP;
    157153    }
    158154  } elsif ($webvar{alloctype} =~ /^(.)i$/) {
    159     $sth = $ip_dbh->prepare("select cidr from allocations where cidr >>='$cidr' and (type like '_d' or type like '_p')");
    160     $sth->execute;
    161     @data = $sth->fetchrow_array;
    162 # User deserves errors if user can't be bothered to find the pool and a free IP first.
    163     if (!$data[0]) {
     155    my $iptype = $1;
     156    my $ptmp = ipParent($ip_dbh, "$cidr");
     157    if ($ptmp->{type} =~ /^(.)[dp]$/) {
     158      my $newiptype = "$1i";
     159      $fbtmp = $ptmp->{cidr};
     160      if ($ptmp->{type} !~ /^$iptype./) {
     161        $page->param(warnmsg => "Warning:  Allocating IP as '".$disp_alloctypes{$newiptype}."' instead of '".
     162                $disp_alloctypes{$webvar{alloctype}}."' to match pool $fbtmp\n");
     163        $webvar{alloctype} = $newiptype;
     164      }
     165    }
     166    if (!$fbtmp) {
    164167      $page->param(errmsg => "Can't allocate static IP from outside a pool!!");
    165168      goto ERRJUMP;
    166169    }
    167170  } else {
    168     $sth = $ip_dbh->prepare("select cidr from freeblocks where cidr >>='$cidr' and not (routed='n')");
    169     $sth->execute;
    170     @data = $sth->fetchrow_array;
    171 # User deserves errors if user can't be bothered to find the free block first.
    172     if (!$data[0]) {
     171    if (!$fbtmp) {
    173172      $page->param(errmsg => "Can't allocate from outside a routed block!!");
    174173      goto ERRJUMP;
     
    176175  }
    177176
    178   my $alloc_from = new NetAddr::IP $data[0];
    179   $sth->finish;
     177  my $alloc_from = new NetAddr::IP $fbtmp;
    180178
    181179  my @cities;
Note: See TracChangeset for help on using the changeset viewer.