Changeset 895 for trunk/cgi-bin
- Timestamp:
- 11/18/16 14:00:54 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/allocate.pl
r517 r895 45 45 # Hokay, now we can start to handle the allocation. 46 46 47 my ($cidr, $type, $custid, $city, $desc, $alloc_from); 47 my ($cidr, $type, $vrf, $custid, $city, $desc) = @ARGV; 48 my ($fbid, $fbparent); 48 49 # Check ARGV. We need some information to determine what to allocate. 49 if (! $ARGV[1]) {50 if (!defined($vrf)) { 50 51 # Usage message 51 print "Usage: allocate.pl [IP/subnet] [Type] [CustID] [City] [\"Description\"]\n". 52 print "Usage: allocate.pl <IP/subnet> <Type> <VRF> [CustID] [City] [\"Description\"]\n". 53 " IP/subnet, Type, and VRF are required\n". 52 54 " Further information can be entered via the web interface\n"; 53 55 exit; 54 56 } else { 55 $cidr = new NetAddr::IP "$ARGV[0]"; 56 $sth = $ip_dbh->prepare("select cidr from freeblocks where cidr >>='$cidr'"); 57 $sth->execute; 58 my @data = $sth->fetchrow_array; 59 # User deserves errors if user can't be bothered to find the free block first. 60 die "Can't allocate from outside a free block!!\n" 61 if !$data[0]; 62 $alloc_from = new NetAddr::IP $data[0]; 63 $sth->finish; 64 $type = $ARGV[1]; 65 if (!$ARGV[4]) { 57 58 $cidr = new NetAddr::IP $cidr; 59 ($fbid,$fbparent) = $ip_dbh->selectrow_array( 60 "SELECT id,parent_id FROM freeblocks WHERE cidr >>= ? AND vrf = ?", undef, "$cidr", $vrf) 61 or die "Couldn't find a free block to match '$cidr' in $vrf\n"; 62 if (!$desc) { 66 63 # Default desc 67 64 $desc = "DEFAULT: $disp_alloctypes{$type}"; 68 } else {69 $desc = $ARGV[4];70 65 } 71 if (!$ARGV[3]) { 72 # Default city 73 $sth = $ip_dbh->prepare("select city from routed where cidr >>='$cidr'"); 74 $sth->execute; 75 my @data = $sth->fetchrow_array; 76 $city = $data[0]; 77 $sth->finish; 78 } else { 79 $city = $ARGV[3]; 66 if (!$city) { 67 # Default city taken from parent allocation 68 ($city) = $ip_dbh->selectrow_array("SELECT city FROM allocations WHERE id = ?", undef, $fbparent); 80 69 } 81 if (!$ ARGV[2]) {82 # Default custid - make it REAL obvious.83 $custid = "FIXME";84 } else {85 $custid = $ARGV[2];70 if (!$custid) { 71 # See if the type has a default custID.... 72 $custid = $ip_dbh->selectrow_array("SELECT def_custid FROM alloctypes WHERE type = ?", undef, $type); 73 # ... and if not, make it REAL obvious this needs to be fixed. 74 $custid = "FIXME" if !$custid; 86 75 } 87 76 } … … 89 78 print "Allocating $cidr as $type to $custid in $city: '$desc'\n"; 90 79 91 my ($code,$msg) = allocateBlock($ip_dbh, $cidr, $alloc_from, $custid, $type, $city, 92 $desc, '', ''); 80 my %insert_args = ( 81 cidr => "$cidr", 82 fbid => $fbid, 83 parent => $fbparent, 84 custid => $custid, 85 type => $type, 86 city => $city, 87 desc => $desc, 88 vrf => $vrf, 89 user => $authuser, 90 ); 91 92 my ($code,$msg) = allocateBlock($ip_dbh, %insert_args); 93 93 94 94 if ($code eq 'OK') {
Note:
See TracChangeset
for help on using the changeset viewer.