Changeset 695
- Timestamp:
- 02/13/15 12:26:44 (10 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/IPDB.pm
r694 r695 1232 1232 # have to insert all pool IPs into poolips table as "unallocated". 1233 1233 $sth = $dbh->prepare("INSERT INTO poolips (ip,custid,city,type,parent_id) VALUES (?,?,?,?,?)"); 1234 1235 # in case of pool extension by some means, we need to see what IPs were already inserted 1236 my $tmp1 = $dbh->selectall_arrayref("SELECT ip FROM poolips WHERE parent_id = ?", undef, $parent); 1237 my %foundips; 1238 foreach (@{$tmp1}) { 1239 $foundips{$_->[0]} = 1; 1240 } 1241 1242 # enumerate the hosts in the IP range - everything except the first (net) and last (bcast) IP 1234 1243 my @poolip_list = $pool->hostenum; 1244 1245 # always check/add IPs from gw+1 through bcast-1: 1246 # (but the set won't be in oooorderrrrr! <pout>) 1247 for (my $i=1; $i<=$#poolip_list; $i++) { 1248 $sth->execute($poolip_list[$i]->addr, $pcustid, $city, $type, $parent) unless $foundips{$poolip_list[$i]}; 1249 } 1250 1251 # now do the special case - DSL/PPP blocks can use the "net", "gw", and "bcast" IPs. 1252 # we exclude .0 and .255 anyway, since while they'll mostly work, they *will* behave badly here and there. 1235 1253 if ($class eq 'all') { # (DSL-ish block - *all* IPs available 1236 1254 if ($pool->addr !~ /\.0$/) { # .0 causes weirdness. 1237 $sth->execute($pool->addr, $pcustid, $city, $type, $parent); 1238 } 1239 for (my $i=0; $i<=$#poolip_list; $i++) { 1240 $sth->execute($poolip_list[$i]->addr, $pcustid, $city, $type, $parent); 1241 } 1255 $sth->execute($pool->addr, $pcustid, $city, $type, $parent) unless $foundips{$pool->addr}; 1256 } 1257 $sth->execute($poolip_list[0]->addr, $pcustid, $city, $type, $parent) unless $poolip_list[0]; 1242 1258 $pool--; 1243 1259 if ($pool->addr !~ /\.255$/) { # .255 can cause weirdness. 1244 $sth->execute($pool->addr, $pcustid, $city, $type, $parent); 1245 } 1246 } else { # (real netblock) 1247 for (my $i=1; $i<=$#poolip_list; $i++) { 1248 $sth->execute($poolip_list[$i]->addr, $pcustid, $city, $type, $parent); 1260 $sth->execute($pool->addr, $pcustid, $city, $type, $parent) unless $foundips{$pool->addr}; 1249 1261 } 1250 1262 } … … 1315 1327 return ('FAIL', 'No fields to update') if !@fieldlist; 1316 1328 1317 push @vallist, $args{block};1318 1329 my $sql = "UPDATE $updtable SET "; 1319 1330 $sql .= join " = ?, ", @fieldlist; 1320 $sql .= " = ? WHERE $keyfield = ?";1321 1331 1322 1332 eval { 1333 # check for block merge first... 1334 if ($args{fbmerge}) { 1335 my $cidr = NetAddr::IP->new($binfo->{block}); 1336 my $newblock = NetAddr::IP->new($cidr->addr, $cidr->masklen - 1)->network; 1337 # safety net? make sure mergeable block passed in is really one or both of 1338 # a) reserved for expansion of the block and 1339 # b) confirmed CIDR-combinable 1340 # "safety? SELECT foo FROM freeblocks WHERE cidr << ? AND masklen(cidr) = ?, $newblock, ".$cidr->masklen."\n"; 1341 $dbh->do("DELETE FROM freeblocks WHERE id=?", undef, $args{fbmerge}); 1342 # ... so we can append the change in the stored CIDR field to extend the allocation. 1343 $sql .= " = ?, cidr"; 1344 push @vallist, $newblock; 1345 # if we have an IP pool, call initPool to fill in any missing entries in the pool 1346 if ($binfo->{type} =~ /^.p$/) { 1347 my ($code,$rmsg) = initPool($dbh, "$newblock", $binfo->{type}, $binfo->{city}, 'all', $args{block}); 1348 die $rmsg if $code eq 'FAIL'; 1349 } elsif ($binfo->{type} =~ /^.d$/) { 1350 my ($code,$rmsg) = initPool($dbh, "$newblock", $binfo->{type}, $binfo->{city}, 'normal', $args{block}); 1351 die $rmsg if $code eq 'FAIL'; 1352 } 1353 } 1354 1355 # append another SQL fragment 1356 push @vallist, $args{block}; 1357 $sql .= " = ? WHERE $keyfield = ?"; 1358 1323 1359 # do the update 1324 1360 $dbh->do($sql, undef, @vallist); -
trunk/cgi-bin/main.cgi
r692 r695 904 904 $page->param(vlan => $blockinfo->{vlan}); 905 905 906 # Reserved-for-expansion 907 $page->param(reserve => $blockinfo->{reserve}); 908 $page->param(reserve_id => $blockinfo->{reserve_id}); 909 my $newblock = NetAddr::IP->new($cidr->addr, $cidr->masklen - 1)->network; 910 $page->param(newblock => $newblock); 911 906 912 # not happy with the upside-down logic, but... 907 913 $page->param(swipable => $blockinfo->{type} !~ /.i/); … … 961 967 } 962 968 969 # Merge with reserved freeblock 970 $updargs{fbmerge} = $webvar{expandme} if $webvar{expandme}; 971 963 972 my ($code,$msg) = updateBlock($ip_dbh, %updargs, iprev => \%iprev); 964 973 -
trunk/templates/edit.tmpl
r691 r695 21 21 <td class="regular"><TMPL_VAR NAME=block></td> 22 22 </tr> 23 24 <TMPL_IF reserve> 25 <tr> 26 <td class="heading">Expand allocation:</td> 27 <td> 28 <input type="checkbox" name="expandme" value="<TMPL_VAR NAME=reserve_id>">Add <TMPL_VAR NAME=reserve> to make <TMPL_VAR NAME=newblock> 29 <input type="hidden" name="newblock" value="<TMPL_VAR NAME=newblock>"> 30 </td> 31 </tr> 32 </TMPL_IF> 23 33 24 34 <tr>
Note:
See TracChangeset
for help on using the changeset viewer.