Changeset 79 for trunk/cgi-bin
- Timestamp:
- 11/26/04 12:35:43 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/IPDB.pm
r78 r79 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 # To contain the error message, if any. 140 my $msg = "Unknown error allocating $cidr as '$type'"; 139 141 140 142 # Enable transactions and error handling … … 143 145 144 146 if ($type =~ /^[cdsmw]i$/) { 147 $msg = "Unable to assign static IP $cidr to $custid"; 145 148 eval { 146 149 # We'll just have to put up with the oddities caused by SQL (un)sort order … … 162 165 " where ip='$cidr'"); 163 166 $sth->execute; 164 ##err handle the error 167 $dbh->commit; 165 168 }; 166 169 if ($@) { 167 $msg = $@;168 170 eval { $dbh->rollback; }; 169 171 return ('FAIL',$msg); … … 181 183 182 184 eval { 185 $msg = "Unable to allocate $cidr as '$disp_alloctypes{$type}'"; 183 186 if ($type eq 'rr') { 184 187 $sth = $dbh->prepare("update freeblocks set routed='y',city='$city'". … … 200 203 # And initialize the pool, if necessary 201 204 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 205 $msg = "Could not initialize IPs in new $disp_alloctypes{$type} pool $cidr"; 206 initPool($dbh,$cidr,$type,$city,0); 207 } 208 220 209 } # routing vs non-routing netblock 210 221 211 $dbh->commit; 222 212 }; # end of eval … … 250 240 # Begin SQL transaction block 251 241 eval { 242 $msg = "Unable to allocate $cidr as '$disp_alloctypes{$type}'"; 243 252 244 # Delete old freeblocks entry 253 245 $sth = $dbh->prepare("delete from freeblocks where cidr='$alloc_from'"); … … 256 248 # now we have to do some magic for routing blocks 257 249 if ($type eq 'rr') { 250 258 251 # Insert the new freeblocks entries 259 252 # Note that non-routed blocks are assigned to <NULL> … … 262 255 $sth->execute("$block", $block->masklen); 263 256 } 257 264 258 # Insert the entry in the routed table 265 259 $sth = $dbh->prepare("insert into routed values ('$cidr',". … … 279 273 $sth->execute("$block", $block->masklen); 280 274 } 275 281 276 # Insert the allocations entry 282 277 $sth = $dbh->prepare("insert into allocations values ('$cidr',". … … 287 282 # And initialize the pool, if necessary 288 283 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 284 $msg = "Could not initialize IPs in new $disp_alloctypes{$type} $cidr"; 285 initPool($dbh,$cidr,$type,$city,0); 286 } 287 307 288 } # done with netblock alloctype != rr 289 308 290 $dbh->commit; 309 291 }; # end eval 310 292 if ($@) { 311 $msg = $@;312 293 eval { $dbh->rollback; }; 313 294 return ('FAIL',$msg);
Note:
See TracChangeset
for help on using the changeset viewer.