Changeset 192 for branches/stable/cgi-bin/IPDB.pm
- Timestamp:
- 03/10/05 14:15:19 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/cgi-bin/IPDB.pm
r185 r192 234 234 eval { 235 235 $msg = "Unable to allocate $cidr as '$disp_alloctypes{$type}'"; 236 if ($type eq 'r r') {236 if ($type eq 'rm') { 237 237 $sth = $dbh->prepare("update freeblocks set routed='y',city='$city'". 238 238 " where cidr='$cidr'"); … … 243 243 } else { 244 244 # common stuff for end-use, dialup, dynDSL, pools, etc, etc. 245 $sth = $dbh->prepare("delete from freeblocks where cidr='$cidr'"); 246 $sth->execute; 247 245 246 # special case - block is a container/"reserve" block 247 if ($type =~ /^(.)c$/) { 248 $sth = $dbh->prepare("update freeblocks set routed='$1' where cidr='$cidr'"); 249 $sth->execute; 250 } else { 251 # "normal" case 252 $sth = $dbh->prepare("delete from freeblocks where cidr='$cidr'"); 253 $sth->execute; 254 } 248 255 $sth = $dbh->prepare("insert into allocations". 249 256 " (cidr,custid,type,city,description,notes,maskbits,circuitid)". … … 305 312 306 313 # now we have to do some magic for routing blocks 307 if ($type eq 'r r') {314 if ($type eq 'rm') { 308 315 309 316 # Insert the new freeblocks entries … … 325 332 $sth->execute; 326 333 327 } else { # done with alloctype == r r334 } else { # done with alloctype == rm 328 335 329 336 # Insert the new freeblocks entries 337 # Along with some more HairyPerl(TM) in case we're inserting a 338 # subblock (.r) allocation 330 339 $sth = $dbh->prepare("insert into freeblocks (cidr,maskbits,city,routed)". 331 " values (?, ?, (select city from routed where cidr >>= '$cidr'),'y')"); 340 " values (?, ?, (select city from routed where cidr >>= '$cidr'),'". 341 (($type =~ /^(.)r$/) ? "$1" : 'y')."')"); 332 342 foreach my $block (@newfreeblocks) { 333 343 $sth->execute("$block", $block->masklen); 334 344 } 335 345 # Special-case for reserve/"container" blocks - generate 346 # the "extra" freeblocks entry for the container 347 if ($type =~ /^(.)c$/) { 348 $sth = $dbh->prepare("insert into freeblocks (cidr,maskbits,city,routed)". 349 " values ('$cidr',".$cidr->masklen.",'$city','$1')"); 350 $sth->execute; 351 } 336 352 # Insert the allocations entry 337 353 $sth = $dbh->prepare("insert into allocations (cidr,custid,type,city,". … … 354 370 } 355 371 356 } # done with netblock alloctype != r r372 } # done with netblock alloctype != rm 357 373 358 374 $dbh->commit; … … 485 501 eval { 486 502 487 if ($type eq 'r r') {503 if ($type eq 'rm') { 488 504 $msg = "Unable to remove routing allocation $cidr"; 489 505 $sth = $dbh->prepare("delete from routed where cidr='$cidr'"); … … 499 515 } else { # end alloctype routing case 500 516 501 $sth = $dbh->prepare("delete from allocations where cidr='$cidr'"); 517 # Delete all allocations within the block being deleted. This is 518 # deliberate and correct, and removes the need to special-case 519 # removal of "container" blocks. 520 $sth = $dbh->prepare("delete from allocations where cidr <<='$cidr'"); 502 521 $sth->execute; 522 503 523 # Special case - delete pool IPs 504 524 if ($type =~ /^.[pd]$/) { … … 511 531 $sth = $dbh->prepare("select cidr from freeblocks where cidr <<= ". 512 532 "(select cidr from routed where cidr >>= '$cidr') ". 513 " and maskbits<=".$cidr->masklen." and routed='y' order by maskbits desc"); 533 " and maskbits<=".$cidr->masklen. 534 " and routed='".(($type =~ /^(.)r$/) ? '$1' : 'y'). 535 "' order by maskbits desc"); 514 536 515 537 } # end alloctype general case … … 562 584 } 563 585 564 # Clear old freeblocks entries - if any. $i==0 if not. 565 if ($i>0) { 566 $sth = $dbh->prepare("delete from freeblocks where cidr=?"); 567 foreach my $block (@combinelist) { 568 $sth->execute("$block"); 569 } 570 } 586 # Clear old freeblocks entries - if any. They should all be within 587 # the $cidr determined above. 588 $sth = $dbh->prepare("delete from freeblocks where cidr <<='$cidr'"); 589 $sth->execute; 571 590 572 591 # insert "new" freeblocks entry 573 if ($type eq 'r r') {592 if ($type eq 'rm') { 574 593 $sth = $dbh->prepare("insert into freeblocks (cidr,maskbits,city)". 575 594 " values ('$cidr',".$cidr->masklen.",'<NULL>')"); … … 577 596 $sth = $dbh->prepare("insert into freeblocks (cidr,maskbits,city,routed)". 578 597 " values ('$cidr',".$cidr->masklen. 579 ",(select city from routed where cidr >>= '$cidr'),'y')"); 598 ",(select city from routed where cidr >>= '$cidr'),'". 599 (($type =~ /^(.)r$/) ? "$1" : 'y')."')"); 580 600 } 581 601 $sth->execute;
Note:
See TracChangeset
for help on using the changeset viewer.