- Timestamp:
- 02/25/15 18:09:13 (10 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/IPDB.pm
r702 r705 32 32 &getMasterList &getTypeList &getPoolSelect &findAllocateFrom 33 33 &ipParent &subParent &blockParent &getBreadCrumbs &getRoutedCity 34 &allocateBlock &updateBlock &splitBlock &deleteBlock &getBlockData &getBlockRDNS &getRDNSbyIP 34 &allocateBlock &updateBlock &splitBlock &shrinkBlock &deleteBlock &getBlockData 35 &getBlockRDNS &getRDNSbyIP 35 36 &getNodeList &getNodeName &getNodeInfo 36 37 &mailNotify … … 47 48 &getMasterList &getTypeList &getPoolSelect &findAllocateFrom 48 49 &ipParent &subParent &blockParent &getBreadCrumbs &getRoutedCity 49 &allocateBlock &updateBlock &splitBlock &deleteBlock &getBlockData &getBlockRDNS &getRDNSbyIP 50 &allocateBlock &updateBlock &splitBlock &shrinkBlock &deleteBlock &getBlockData 51 &getBlockRDNS &getRDNSbyIP 50 52 &getNodeList &getNodeName &getNodeInfo 51 53 &mailNotify … … 1571 1573 1572 1574 1575 ## IPDB::shrinkBlock() 1576 # Shrink an allocation to the passed CIDR block 1577 # Takes an allocation ID and a new CIDR 1578 # Returns an arrayref to a list of hashrefs with the ID and CIDR of the freed block(s) 1579 # Refuses to shrink "real netblock" pool types below /30 1580 sub shrinkBlock { 1581 my $dbh = shift; 1582 my $id = shift; 1583 1584 # just take the new CIDR spec; this way we can shrink eg .16/28 to .20/30 without extra contortions 1585 my $newblock = new NetAddr::IP shift; 1586 1587 if (!$newblock) { 1588 $errstr = "Can't shrink something that's not a netblock"; 1589 return; 1590 } 1591 1592 my $binfo = getBlockData($dbh, $id); 1593 my $pinfo = getBlockData($dbh, $binfo->{parent_id}); 1594 1595 if ($binfo->{type} =~ /.d/ && $newblock->masklen > ($newblock->bits+2) ) { 1596 $errstr = "Can't shrink a non-PPP pool smaller than ".($newblock->{isv6} ? '/124' : '/30'); 1597 return; 1598 } 1599 1600 my $oldblock = new NetAddr::IP $binfo->{block}; 1601 1602 # Don't try to shrink the block outside of itself, Bad Things (probably) Happen. 1603 if (!$oldblock->contains($newblock)) { 1604 $errstr = "Can't shrink an allocation outside of itself"; 1605 return; 1606 } 1607 1608 local $dbh->{AutoCommit} = 0; 1609 local $dbh->{RaiseError} = 1; 1610 1611 my $fbsth = $dbh->prepare("INSERT INTO freeblocks (cidr,city,routed,vrf,parent_id,master_id) VALUES (?,?,?,?,?,?)"); 1612 my $idsth = $dbh->prepare("SELECT currval('freeblocks_id_seq')"); 1613 my $poolsth = $dbh->prepare("DELETE FROM poolips WHERE parent_id = ? AND ip << ?"); 1614 my $netsth = $dbh->prepare("DELETE FROM poolips WHERE parent_id = ? AND ip = ?"); 1615 1616 my @ret; 1617 eval { 1618 $dbh->do("UPDATE allocations SET cidr = ? WHERE id = ?", undef, $newblock, $id); 1619 1620 # find the netblock(s) that are now free 1621 my @workingblocks = $oldblock->split($newblock->masklen); 1622 my @wb2; 1623 foreach my $newsub (@workingblocks) { 1624 next if $newsub == $newblock; 1625 push @wb2, $newsub; 1626 } 1627 @wb2 = Compact(@wb2); 1628 1629 # set new freeblocks, and clean up any IP pool entries if needed. 1630 foreach my $newfree (@wb2) { 1631 # add as freeblock 1632 $fbsth->execute($newfree, $pinfo->{city}, (split //, $pinfo->{type})[1], $pinfo->{vrf}, 1633 $binfo->{parent_id}, $binfo->{master_id}); 1634 $idsth->execute; 1635 my ($nid) = $idsth->fetchrow_array(); 1636 # add to return list 1637 push @ret, {fbid => $nid, newfree => "$newfree", fbparent => $binfo->{parent_id} }; 1638 # clean up pool IPs if necessary 1639 if ($binfo->{type} =~ /.[dp]/) { 1640 $poolsth->execute($id, $newfree); 1641 } 1642 } 1643 1644 # additional cleanup on net/gw/bcast IPs in pool 1645 if ($binfo->{type} =~ /.d/) { 1646 $netsth->execute($id, $newblock->addr); 1647 $newblock++; 1648 $netsth->execute($id, $newblock->addr); 1649 $newblock--; 1650 $newblock--; 1651 $netsth->execute($id, $newblock->addr); 1652 } 1653 1654 $dbh->commit; 1655 }; 1656 if ($@) { 1657 $errstr = "Error splitting $binfo->{block}: $@"; 1658 $dbh->rollback; 1659 return; 1660 } 1661 1662 return \@ret; 1663 } # end shrinkBlock() 1664 1665 1573 1666 ## IPDB::deleteBlock() 1574 1667 # Removes an allocation from the database, including deleting IPs -
trunk/cgi-bin/main.cgi
r702 r705 875 875 $utilbar->param(breadcrumb => \@rcrumbs); 876 876 877 # Show link to IP list for pools 878 $page->param(ispool => 1) if $blockinfo->{type} =~ /^.[dp]$/; 879 877 880 # Clean up extra whitespace on alloc type. Mainly a legacy-data cleanup. 878 881 $blockinfo->{type} =~ s/\s//; … … 1092 1095 my $blockinfo = getBlockData($ip_dbh, $webvar{block}); 1093 1096 1097 # Tree navigation 1098 my $crumbs = getBreadCrumbs($ip_dbh, $blockinfo->{parent_id}); 1099 my @rcrumbs = reverse (@$crumbs); 1100 $utilbar->param(breadcrumb => \@rcrumbs); 1101 1094 1102 if ($blockinfo->{type} =~ /^.i$/) { 1095 1103 $page->param(err => "Can't split a single IP allocation"); … … 1110 1118 if ($blockinfo->{type} =~ /^.d$/) { 1111 1119 # Non-PPP pools 1120 $page->param(ispool => 1); 1112 1121 if ($oldmask+2 >= $block->bits) { 1113 1122 $page->param(err => "Can't split a standard netblock pool any further"); … … 1117 1126 $page->param(sp4mask => $oldmask+2) if $oldmask+2 <= $block->bits-2; 1118 1127 } elsif ($blockinfo->{type} =~ /.p/) { 1128 $page->param(ispool => 1); 1119 1129 # Allow splitting PPP pools down to v4 /31 1120 1130 $page->param(sp4mask => $oldmask+2) if $oldmask+2 <= $block->bits-1; … … 1144 1154 my $blockinfo = getBlockData($ip_dbh, $webvar{block}); 1145 1155 1156 # Tree navigation 1157 my $crumbs = getBreadCrumbs($ip_dbh, $blockinfo->{parent_id}); 1158 my @rcrumbs = reverse (@$crumbs); 1159 $utilbar->param(breadcrumb => \@rcrumbs); 1160 1146 1161 if ($blockinfo->{type} =~ /^.i$/) { 1147 1162 $page->param(err => "Can't split a single IP allocation"); … … 1151 1166 if ($webvar{subact} eq 'split') { 1152 1167 $page->param(issplit => 1); 1153 my $binfo = getBlockData($ip_dbh, $webvar{block}); 1154 $page->param(cidr => $binfo->{block}); 1155 my $block = new NetAddr::IP $binfo->{block}; 1168 my $block = new NetAddr::IP $blockinfo->{block}; 1156 1169 my $newblocks = splitBlock($ip_dbh, $webvar{block}, 'b', $webvar{split}); 1157 1170 if ($newblocks) { 1158 1171 $page->param(newblocks => $newblocks); 1159 # and the backlink to the parent container1160 my $pinfo = getBlockData($ip_dbh, $binfo->{parent_id});1161 $page->param(backid => $binfo->{parent_id});1162 $page->param(backblock => $pinfo->{block});1163 1172 } else { 1164 1173 $page->param(err => $IPDB::errstr); 1165 1174 } 1166 1175 1176 } elsif ($webvar{subact} eq 'shrink') { 1177 $page->param(nid => $webvar{block}); 1178 $page->param(newblock => $webvar{shrink}); 1179 my $newfree = shrinkBlock($ip_dbh, $webvar{block}, $webvar{shrink}); 1180 if ($newfree) { 1181 $page->param(newfb => $newfree); 1182 } else { 1183 $page->param(err => $IPDB::errstr); 1184 } 1185 1167 1186 } else { 1168 # Shrink 1169 } 1187 # Your llama is on fire. 1188 $page->param(err => "Missing form field that shouldn't be missing."); 1189 return; 1190 } 1191 1192 # common bits 1193 $page->param(cidr => $blockinfo->{block}); 1194 # and the backlink to the parent container 1195 my $pinfo = getBlockData($ip_dbh, $blockinfo->{parent_id}); 1196 $page->param(backid => $blockinfo->{parent_id}); 1197 $page->param(backblock => $pinfo->{block}); 1170 1198 } # doSplit() 1171 1199 -
trunk/templates/dosplit.tmpl
r702 r705 7 7 8 8 <table class="indent altrows" cellspacing="1" cellpadding="1"> 9 <tr class="heading"><td >Allocation resized:</td></tr>9 <tr class="heading"><td colspan="2">Allocation resized:</td></tr> 10 10 11 11 <tr> … … 18 18 <td>New netblocks:</td> 19 19 <td> 20 <TMPL_LOOP NAME=newblocks><a href="<TMPL_VAR NAME=webpath>/cgi-bin/main.cgi?action=edit&id=<TMPL_VAR 21 NAME=nid>&basetype=b"><TMPL_VAR NAME=nblock><TMPL_UNLESS __last__><br></TMPL_UNLESS> 20 <TMPL_LOOP NAME=newblocks><a href="<TMPL_VAR NAME=webpath>/cgi-bin/main.cgi?action=edit&id=<TMPL_VAR NAME=nid>&basetype=b"><TMPL_VAR NAME=nblock><TMPL_UNLESS __last__><br></TMPL_UNLESS> 22 21 </TMPL_LOOP> 23 22 </td> … … 25 24 <TMPL_ELSE> 26 25 <tr> 27 <td>New netblock:</td> 28 <td><a href="<TMPL_VAR NAME=webpath>/cgi-bin/main.cgi?action=edit&id=<TMPL_VAR NAME=nid>&basetype=b"><TMPL_VAR NAME=newblock></a></td> 26 <td>Shrunk netblock:</td> 27 <td><a href="<TMPL_VAR NAME=webpath>/cgi-bin/main.cgi?action=edit&id=<TMPL_VAR NAME=nid>&basetype=b"><TMPL_VAR 28 NAME=newblock></a></td> 29 29 </tr> 30 30 <tr> 31 31 <td>New free block:</td> 32 <td><a href="<TMPL_VAR NAME=webpath>/cgi-bin/main.cgi?action=assign&block=<TMPL_VAR NAME=newfree>&fbid=<TMPL_VAR NAME=fbid>&parent=<TMPL_VAR NAME=fbparent>"><TMPL_VAR NAME=newfree></a></td> 32 <td><TMPL_LOOP name=newfb><a href="<TMPL_VAR NAME=webpath>/cgi-bin/main.cgi?action=assign&block=<TMPL_VAR 33 NAME=newfree>&fbid=<TMPL_VAR NAME=fbid>&parent=<TMPL_VAR NAME=fbparent>"><TMPL_VAR 34 NAME=newfree></a><TMPL_UNLESS __last__><br></TMPL_UNLESS></TMPL_LOOP> 35 </td> 33 36 </tr> 34 37 </TMPL_IF> -
trunk/templates/edit.tmpl
r702 r705 15 15 16 16 <table class="altrows" cellspacing="1"> 17 <tr class="heading"><td>Edit the information below</td></tr> 17 <tr class="heading"> 18 <td colspan="2">Edit the information below 19 <TMPL_IF ispool> 20 <div style="float:right;"><a href="<TMPL_VAR NAME=webpath>/cgi-bin/main.cgi?action=listpool&pool=<TMPL_VAR NAME=id>">List IPs</a></div></TMPL_IF> 21 </td></tr> 18 22 19 23 <tr> -
trunk/templates/split.tmpl
r702 r705 13 13 14 14 <table class="regular altrows" cellspacing="1" cellpadding="1"> 15 <tr class="heading"><td>Split/shrink allocation</td></tr> 15 <tr class="heading"> 16 <td colspan="2">Split/shrink allocation 17 <TMPL_IF ispool> 18 <div style="float:right;"><a href="<TMPL_VAR NAME=webpath>/cgi-bin/main.cgi?action=listpool&pool=<TMPL_VAR 19 NAME=block>">List IPs</a></div> 20 </TMPL_IF></td> 21 </tr> 16 22 <tr> 17 23 <td>Current netblock:</td> … … 34 40 </tr> 35 41 42 <TMPL_IF ispool> 43 <tr> 44 <td colspan="2" class="warning">Warning: Proceeding may remove pool IP entries</td> 45 </tr> 46 </TMPL_IF> 47 36 48 <tr> 37 49 <td class="center" colspan="2"><input type="submit" value=" Split/Shrink "></td>
Note:
See TracChangeset
for help on using the changeset viewer.