Changeset 545 for trunk/cgi-bin/IPDB.pm


Ignore:
Timestamp:
11/07/12 17:20:58 (11 years ago)
Author:
Kris Deugau
Message:

/trunk

Tweak allocateBlock() to usefully handle passing an IP as an
override on the automatic IP-chooser.
Convert allocation of a pool IP in admin.cgi to use updated
allocateBlock(). See #34.

File:
1 edited

Legend:

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

    r544 r545  
    671671#       and available='y' order by ip limit 1);
    672672
    673       $sth = $dbh->prepare("select ip from poolips where pool='$alloc_from'".
    674         " and available='y' order by ip");
    675       $sth->execute;
    676 
    677       my @data = $sth->fetchrow_array;
    678       $cidr = $data[0];  # $cidr is already declared when we get here!
    679 
    680       $sth = $dbh->prepare("update poolips set custid=?,city=?,".
    681         "available='n',description=?,notes=?,circuitid=?,privdata=?".
    682         " where ip=?");
    683       $sth->execute($custid, $city, $desc, $notes, $circid, $privdata, "$cidr");
     673      if ($cidr) {
     674        my ($isavail) = $dbh->selectrow_array("SELECT available FROM poolips WHERE ip=?", undef, ($cidr) );
     675        if ($isavail eq 'n') {
     676          die "IP already allocated.  Deallocate and reallocate, or update the entry\n";
     677        }
     678        if (!$isavail) {
     679          die "IP is not in an IP pool.\n";
     680        }
     681      } else {
     682        ($cidr) = $dbh->selectrow_array("SELECT ip FROM poolips WHERE pool=? AND available='y' ORDER BY ip",
     683                undef, ($alloc_from) );
     684      }
     685      $dbh->do("UPDATE poolips SET custid=?,city=?,available='n',description=?,notes=?,circuitid=?,privdata=? ".
     686        "WHERE ip=?", undef, ($custid, $city, $desc, $notes, $circid, $privdata, $cidr) );
     687
    684688# node hack
    685689      if ($nodeid && $nodeid ne '') {
     
    688692      }
    689693# end node hack
     694
    690695      $dbh->commit;
    691696    };
    692697    if ($@) {
    693       $msg .= ": '".$sth->errstr."'";
     698      $msg .= ": $@";
    694699      eval { $dbh->rollback; };
    695700      return ('FAIL',$msg);
Note: See TracChangeset for help on using the changeset viewer.