Changeset 78 for trunk/cgi-bin
- Timestamp:
- 11/23/04 17:44:12 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/IPDB.pm
r77 r78 22 22 @ISA = qw(Exporter); 23 23 @EXPORT_OK = qw(&initIPDBGlocals &connectDB &finish &checkDBSanity &allocateBlock 24 & initPool &mailNotify);24 &mailNotify); 25 25 26 26 @EXPORT = (); # Export nothing by default. 27 %EXPORT_TAGS = ( ALL => [qw( &initIPDBGlocals &connectDB & checkDBSanity28 &allocateBlock & initPool &mailNotify)]27 %EXPORT_TAGS = ( ALL => [qw( &initIPDBGlocals &connectDB &finish &checkDBSanity 28 &allocateBlock &mailNotify)] 29 29 ); 30 30 … … 136 136 my $alloc_from = new NetAddr::IP $_[2]; 137 137 my $sth; 138 my $msg; # To contain the error message, if any. 138 139 139 140 # Enable transactions and error handling … … 164 165 }; 165 166 if ($@) { 166 # failure 167 $msg = $@; 168 eval { $dbh->rollback; }; 169 return ('FAIL',$msg); 167 170 } else { 168 # success171 return ('OK',"OK"); 169 172 } 170 173 171 174 } else { # end IP-from-pool allocation 172 # Set $cidr here as it may not be a valid IP address elsewhere.173 # my $cidr = new NetAddr::IP $webvar{fullcidr};174 175 175 176 if ($cidr == $alloc_from) { … … 189 190 } else { 190 191 # common stuff for end-use, dialup, dynDSL, pools, etc, etc. 191 ##err How to handle pools?192 ##workhere193 #print "IPDB.pm: $cidr\n";194 192 $sth = $dbh->prepare("delete from freeblocks where cidr='$cidr'"); 195 193 $sth->execute; … … 199 197 $cidr->masklen.",'$circid')"); 200 198 $sth->execute; 201 ## if $type =~ /^[cdsmw]p$/ initpool($dbh,$cidr,$type) 199 200 # And initialize the pool, if necessary 201 if ($type =~ /^.p$/) { 202 my ($pooltype) = ($type =~ /^(.)p$/); 203 # have to insert all pool IPs into poolips table as "unallocated". 204 $sth = $dbh->prepare("insert into poolips values ('$cidr',". 205 " ?, '6750400', '$city', '$pooltype', 'y', '', '', '')"); 206 my @poolip_list = $cidr->hostenum; 207 if ($type eq 'dp') { # (DSLish block - *all* IPs available 208 $sth->execute($cidr->addr); 209 for (my $i=0; $i<=$#poolip_list; $i++) { 210 $sth->execute($poolip_list[$i]->addr); 211 } 212 $cidr--; 213 $sth->execute($cidr->addr); 214 } else { # (real netblock) 215 for (my $i=1; $i<=$#poolip_list; $i++) { 216 $sth->execute($poolip_list[$i]->addr); 217 } 218 } 219 } # end type = pool 202 220 } # routing vs non-routing netblock 203 221 $dbh->commit; 204 }; # end of eval 205 ##err 222 }; # end of eval 206 223 if ($@) { 224 $msg = $@; 207 225 eval { $dbh->rollback; }; 208 return ( 2,$@);226 return ('FAIL',$@); 209 227 } else { 210 ## do we return here or ? 211 return (1,"OK"); 212 # Success 213 } # error handler 228 return ('OK',"OK"); 229 } 214 230 215 231 } else { # cidr != alloc_from … … 268 284 ",'$circid')"); 269 285 $sth->execute; 270 ##err do we initPool here, or force the caller to do it? 271 # Flexibility says we let the caller do it, to allow more options. 286 287 # And initialize the pool, if necessary 288 if ($type =~ /^.p$/) { 289 my ($pooltype) = ($type =~ /^(.)p$/); 290 # have to insert all pool IPs into poolips table as "unallocated". 291 $sth = $dbh->prepare("insert into poolips values ('$cidr',". 292 " ?, '6750400', '$city', '$pooltype', 'y', '', '', '')"); 293 my @poolip_list = $cidr->hostenum; 294 if ($type eq 'dp') { # (DSLish block - *all* IPs available 295 $sth->execute($cidr->addr); 296 for (my $i=0; $i<=$#poolip_list; $i++) { 297 $sth->execute($poolip_list[$i]->addr); 298 } 299 $cidr--; 300 $sth->execute($cidr->addr); 301 } else { # (real netblock) 302 for (my $i=1; $i<=$#poolip_list; $i++) { 303 $sth->execute($poolip_list[$i]->addr); 304 } 305 } 306 } # end type = pool 272 307 } # done with netblock alloctype != rr 273 308 $dbh->commit; 274 309 }; # end eval 275 310 if ($@) { 311 $msg = $@; 276 312 eval { $dbh->rollback; }; 277 return ( 2,$@);313 return ('FAIL',$msg); 278 314 } else { 279 ##err 280 return (1,"OK"); 315 return ('OK',"OK"); 281 316 } 282 317 … … 293 328 # indicating whether the pool should allow allocation of literally every 294 329 # IP, or if it should reserve network/gateway/broadcast IPs 330 # Note that this is NOT done in a transaction, that's why it's a private 331 # function and should ONLY EVER get called from allocateBlock() 295 332 sub initPool { 296 333 my ($dbh,undef,$type,$city,$class) = @_; 297 334 my $pool = new NetAddr::IP $_[1]; 298 335 299 my $pooltype= ($type =~ /^(.)p$/);336 my ($pooltype) = ($type =~ /^(.)p$/); 300 337 my $sth; 301 338 302 # Enable transactions and error handling 303 local $dbh->{AutoCommit} = 0; # These need to be local so we don't 304 local $dbh->{RaiseError} = 1; # step on our toes by accident. 305 306 # Begin SQL transaction block 307 eval { 308 # have to insert all pool IPs into poolips table as "unallocated". 309 $sth = $dbh->prepare("insert into poolips values ('$pool',". 339 # have to insert all pool IPs into poolips table as "unallocated". 340 $sth = $dbh->prepare("insert into poolips values ('$pool',". 310 341 " ?, '6750400', '$city', '$pooltype', 'y', '', '', '')"); 311 my @poolip_list = $pool->hostenum; 312 if ($class) { # (real netblock) 313 for (my $i=1; $i<=$#poolip_list; $i++) { 314 $sth->execute($poolip_list[$i]->addr); 315 } 316 } else { # (DSL-ish block - *all* IPs available 317 $sth->execute($pool->addr); 318 for (my $i=0; $i<=$#poolip_list; $i++) { 319 $sth->execute($poolip_list[$i]->addr); 320 } 321 $pool--; 322 $sth->execute($pool->addr); 342 my @poolip_list = $pool->hostenum; 343 if ($class eq 'all') { # (DSL-ish block - *all* IPs available 344 $sth->execute($pool->addr); 345 for (my $i=0; $i<=$#poolip_list; $i++) { 346 $sth->execute($poolip_list[$i]->addr); 323 347 } 324 $dbh->commit; 325 }; # end eval 326 if ($@) { 327 eval { $dbh->rollback; }; 328 print "$@\n"; 329 return (2,"$@"); 330 } else { 331 ##err 332 return (1,"OK"); 348 $pool--; 349 $sth->execute($pool->addr); 350 } else { # (real netblock) 351 for (my $i=1; $i<=$#poolip_list; $i++) { 352 $sth->execute($poolip_list[$i]->addr); 353 } 333 354 } 334 335 355 } # end initPool() 336 356
Note:
See TracChangeset
for help on using the changeset viewer.