Changeset 545 for trunk


Ignore:
Timestamp:
11/07/12 17:20:58 (12 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.

Location:
trunk/cgi-bin
Files:
2 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);
  • trunk/cgi-bin/admin.cgi

    r544 r545  
    203203    $page->param(locerr => "Invalid customer location!  Go back and select customer's location.");
    204204    goto ERRJUMP;
    205   } else {
    206     if ($webvar{alloctype} =~ /^.i$/) {
    207       $sth = $ip_dbh->prepare("update poolips set available='n', custid='$webvar{custid}', ".
    208         "city='$webvar{city}', description='$webvar{desc}', notes='$webvar{notes}' ".
    209         "where ip='$webvar{cidr}'");
    210       $sth->execute;
    211       if ($sth->err) {
    212         $page->param(errmsg => $sth->errstr);
    213         syslog "err", "($authuser) Allocation of '$webvar{cidr}' to '$webvar{custid}' as ".
    214                 "'$webvar{alloctype}' failed: '".$sth->errstr."'";
    215       } else {
    216         syslog "notice", "$authuser allocated '$webvar{cidr}' to '$webvar{custid}' as ".
    217                 "'$webvar{alloctype}'";
    218         mailNotify($ip_dbh, "a$webvar{alloctype}", "ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
    219           "$disp_alloctypes{$webvar{alloctype}} $webvar{cidr} allocated to customer $webvar{custid}\n".
    220           "Description: $webvar{desc}\n\nAllocated by: $authuser\n");
    221       }
    222     } else {
    223       my ($retcode,$msg) = allocateBlock($ip_dbh, $webvar{cidr}, $webvar{alloc_from},
     205  }
     206
     207  my ($retcode,$msg) = allocateBlock($ip_dbh, $webvar{cidr}, $webvar{alloc_from},
    224208        $webvar{custid}, $webvar{alloctype}, $webvar{city}, $webvar{desc}, $webvar{notes},
    225209        $webvar{circid});
    226       if ($retcode eq 'OK') {
    227         syslog "notice", "$authuser allocated '$webvar{cidr}' to '$webvar{custid}' as ".
    228                 "'$webvar{alloctype}'";
    229       } else {
    230         $page->param(errmsg => $msg);
    231         syslog "err", "($authuser) Allocation of '$webvar{cidr}' to '$webvar{custid}' as ".
    232                 "'$webvar{alloctype}' failed: '$msg'";
    233       }
    234     } # static IP vs netblock
    235 
    236   } # done city check
     210  if ($retcode eq 'OK') {
     211    syslog "notice", "$authuser allocated '$webvar{cidr}' to '$webvar{custid}' as ".
     212        "'$webvar{alloctype}'";
     213    if ($webvar{alloctype} =~ /^.i$/) {
     214      mailNotify($ip_dbh, "a$webvar{alloctype}", "ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
     215        "$disp_alloctypes{$webvar{alloctype}} $webvar{cidr} allocated to customer $webvar{custid}\n".
     216        "Description: $webvar{desc}\n\nAllocated by: $authuser\n");
     217    }
     218  } else {
     219    $page->param(errmsg => $msg);
     220    syslog "err", "($authuser) Allocation of '$webvar{cidr}' to '$webvar{custid}' as ".
     221        "'$webvar{alloctype}' failed: '$msg'";
     222  }
    237223
    238224} elsif ($webvar{action} eq 'alloctweak') {
Note: See TracChangeset for help on using the changeset viewer.