Changeset 544


Ignore:
Timestamp:
11/05/12 16:53:38 (11 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.

Location:
trunk
Files:
4 edited

Legend:

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

    r541 r544  
    549549  ##fixme:  chain cities to align roughly with a full layer-2 node graph
    550550  $city = $pop if $type !~ /^.[pc]$/;
    551   if ($type ne 'rm') {
     551  if ($type ne 'rm' && $city) {
    552552    $sql .= " AND city = ?";
    553553    push @vallist, $city;
     554  }
     555  # Allow specifying an arbitrary full block, instead of a master
     556  if ($optargs{gimme}) {
     557    $sql .= " AND cidr >>= ?";
     558    push @vallist, $optargs{gimme};
    554559  }
    555560  # if a specific master was requested, allow the requestor to self->shoot(foot)
  • 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;
  • trunk/ipdb.css

    r517 r544  
    109109}
    110110
     111.warnmsg {
     112        border: solid 2px #FFFF00;
     113        color: #333300;
     114        background-color: #e0e0e0;
     115        text-align: center;
     116        padding: 5px;
     117        width: 70%;
     118}
     119
     120
    111121hr.w60 {
    112122        width: 60%;
  • trunk/templates/admin/alloc.tmpl

    r517 r544  
    22<TMPL_VAR NAME=errmsg>
    33<TMPL_ELSE>
     4<TMPL_IF warnmsg><div class="warnmsg"><TMPL_VAR NAME=warnmsg></div></TMPL_IF>
    45<form method="POST" action="admin.cgi">
    56<fieldset><legend class="noshow">&nbsp;</legend>
Note: See TracChangeset for help on using the changeset viewer.