Changeset 149
- Timestamp:
- 02/03/05 14:23:34 (20 years ago)
- Location:
- branches/sql-cleanup/cgi-bin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/sql-cleanup/cgi-bin/IPDB.pm
r148 r149 251 251 252 252 # And initialize the pool, if necessary 253 # PPPoE pools (currently dialup, DSL, and WiFi) get all IPs made available 254 # "DHCP" or "real-subnet" pools have the net, gw, and bcast IPs removed. 253 255 if ($type =~ /^.p$/) { 254 $msg = "Could not initialize IPs in new $disp_alloctypes{$type} pool $cidr"; 255 initPool($dbh,$cidr,$type,$city,($type eq 'dp' ? "all" : "normal")); 256 $msg = "Could not initialize IPs in new $disp_alloctypes{$type} $cidr"; 257 my ($code,$rmsg) = initPool($dbh,$cidr,$type,$city,"all"); 258 die $rmsg if $code eq 'FAIL'; 259 } elsif ($type =~ /^.d$/) { 260 $msg = "Could not initialize IPs in new $disp_alloctypes{$type} $cidr"; 261 my ($code,$rmsg) = initPool($dbh,$cidr,$type,$city,"normal"); 262 die $rmsg if $code eq 'FAIL'; 256 263 } 257 264 … … 261 268 }; # end of eval 262 269 if ($@) { 263 $msg =$@;270 $msg .= ": ".$@; 264 271 eval { $dbh->rollback; }; 265 return ('FAIL',$ @);272 return ('FAIL',$msg); 266 273 } else { 267 274 return ('OK',"OK"); … … 367 374 my $pool = new NetAddr::IP $_[1]; 368 375 369 my ($pooltype) = ($type =~ /^(.)p$/); 376 ##fixme Need to just replace 2nd char of type with i rather than capturing 1st char of type 377 $type =~ s/[pd]$/i/; 370 378 my $sth; 371 372 # have to insert all pool IPs into poolips table as "unallocated". 373 $sth = $dbh->prepare("insert into poolips (pool,ip,custid,city,ptype)". 374 " values ('$pool', ?, '6750400', '$city', '$pooltype')"); 375 my @poolip_list = $pool->hostenum; 376 if ($class eq 'all') { # (DSL-ish block - *all* IPs available 377 $sth->execute($pool->addr); 378 for (my $i=0; $i<=$#poolip_list; $i++) { 379 $sth->execute($poolip_list[$i]->addr); 380 } 381 $pool--; 382 $sth->execute($pool->addr); 383 } else { # (real netblock) 384 for (my $i=1; $i<=$#poolip_list; $i++) { 385 $sth->execute($poolip_list[$i]->addr); 386 } 379 my $msg; 380 381 # Trap errors so we can pass them back to the caller. Even if the 382 # caller is only ever supposed to be local, and therefore already 383 # trapping errors. >:( 384 local $dbh->{AutoCommit} = 0; # These need to be local so we don't 385 local $dbh->{RaiseError} = 1; # step on our toes by accident. 386 387 eval { 388 # have to insert all pool IPs into poolips table as "unallocated". 389 $sth = $dbh->prepare("insert into poolips (pool,ip,custid,city,type)". 390 " values ('$pool', ?, '6750400', '$city', '$type')"); 391 my @poolip_list = $pool->hostenum; 392 if ($class eq 'all') { # (DSL-ish block - *all* IPs available 393 $sth->execute($pool->addr); 394 for (my $i=0; $i<=$#poolip_list; $i++) { 395 $sth->execute($poolip_list[$i]->addr); 396 } 397 $pool--; 398 $sth->execute($pool->addr); 399 } else { # (real netblock) 400 for (my $i=1; $i<=$#poolip_list; $i++) { 401 $sth->execute($poolip_list[$i]->addr); 402 } 403 } 404 }; 405 if ($@) { 406 $msg = "'".$sth->errstr."'"; 407 eval { $dbh->rollback; }; 408 return ('FAIL',$msg); 409 } else { 410 return ('OK',"OK"); 387 411 } 388 412 } # end initPool() … … 412 436 413 437 eval { 414 $msg = "Unable to deallocate $ type$cidr";438 $msg = "Unable to deallocate $disp_alloctypes{$type} $cidr"; 415 439 $sth = $dbh->prepare("update poolips set custid='6750400',available='y',". 416 440 "city=(select city from allocations where cidr >>= '$cidr'),". … … 469 493 $sth->execute; 470 494 # Special case - delete pool IPs 471 if ($type =~ /^. p$/) {495 if ($type =~ /^.[pd]$/) { 472 496 # We have to delete the IPs from the pool listing. 473 497 $sth = $dbh->prepare("delete from poolips where pool='$cidr'"); -
branches/sql-cleanup/cgi-bin/main.cgi
r142 r149 354 354 $data[1], $disp_alloctypes{$data[2]}, $data[3], $data[4]); 355 355 # Allow listing of pool if desired/required. 356 if ($data[2] =~ /^ [cdsmw]p$/) {356 if ($data[2] =~ /^.[pd]$/) { 357 357 $row[0] .= ' <a href="/ip/cgi-bin/main.cgi?action=listpool'. 358 358 "&pool=$data[0]\">List IPs</a>"; … … 620 620 $data[3], $disp_alloctypes{$data[2]}, $data[1], $data[4]); 621 621 # If the allocation is a pool, allow listing of the IPs in the pool. 622 if ($data[2] =~ /^ [cdsmw]p$/) {622 if ($data[2] =~ /^.[pd]$/) { 623 623 $row[0] .= ' <a href="/ip/cgi-bin/main.cgi?action=listpool'. 624 624 "&pool=$data[0]\">List IPs</a>"; … … 675 675 my $cidr = new NetAddr::IP $webvar{pool}; 676 676 677 my ($pooltype,$poolcity); 678 677 679 # Snag pool info for heading 678 $sth = $ip_dbh->prepare("select *from allocations where cidr='$cidr'");680 $sth = $ip_dbh->prepare("select type,city from allocations where cidr='$cidr'"); 679 681 $sth->execute; 680 my @data = $sth->fetchrow_array;681 my $type = $data[2]; # We'll need this later.682 $sth->bind_columns(\$pooltype, \$poolcity); 683 $sth->fetch() || carp $sth->errstr; 682 684 683 685 print qq(<center><div class="heading">Listing pool IPs for $cidr<br>\n). 684 qq(($disp_alloctypes{$type} in $data[3])</div></center><br>\n); 685 print qq(<div class="indent"><b>Reserved IPs:</b><br>\n); 686 print qq(<div class="indent"><table><tr class=color1><td>Network IP:</td><td>). 686 qq(($disp_alloctypes{$pooltype} in $poolcity)</div></center><br>\n); 687 # Only display net/gw/bcast if it's a "real" netblock and not a PPP(oE) lunacy 688 if ($pooltype =~ /^.d$/) { 689 print qq(<div class="indent"><b>Reserved IPs:</b><br>\n); 690 print qq(<div class="indent"><table><tr class=color1><td>Network IP:</td><td>). 687 691 $cidr->addr."</td></tr>\n"; 688 $cidr++;689 print "<tr class=color2><td>Gateway:</td><td>".$cidr->addr."</td></tr>\n";690 $cidr--; $cidr--;691 print "<tr class=color1><td>Broadcast:</td><td>".$cidr->addr."</td></tr>\n".692 $cidr++; 693 print "<tr class=color2><td>Gateway:</td><td>".$cidr->addr."</td></tr>\n"; 694 $cidr--; $cidr--; 695 print "<tr class=color1><td>Broadcast:</td><td>".$cidr->addr."</td></tr>\n". 692 696 "<tr><td>Netmask:</td><td>".$cidr->mask."</td></tr>\n". 693 697 "</table></div></div>\n"; 698 } 694 699 695 700 # probably have to add an "edit IP allocation" link here somewhere. … … 973 978 "'$webvar{alloctype}' by $authuser failed: '$msg'"; 974 979 printError("Allocation of $webvar{fullcidr} as $disp_alloctypes{$webvar{alloctype}}". 975 " failed: 980 " failed:<br>\n$msg\n"); 976 981 } 977 982
Note:
See TracChangeset
for help on using the changeset viewer.