Changeset 702 for trunk/cgi-bin/main.cgi
- Timestamp:
- 02/23/15 18:16:11 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/main.cgi
r697 r702 171 171 elsif($webvar{action} eq 'update') { 172 172 update(); 173 } 174 elsif($webvar{action} eq 'split') { 175 prepSplit(); 176 } 177 elsif($webvar{action} eq 'dosplit') { 178 doSplit(); 173 179 } 174 180 elsif($webvar{action} eq 'delete') { … … 965 971 $page->param(maydel => $IPDBacl{$authuser} =~ /d/); 966 972 973 # Need to find internal knobs to twist to actually vary these. (Ab)use "change" flag for now 974 $page->param(maymerge => ($IPDBacl{$authuser} =~ /c/ && $blockinfo->{type} !~ /^.i$/)); 975 if ($IPDBacl{$authuser} =~ /c/ && $blockinfo->{type} !~ /^.i$/) { 976 if ($blockinfo->{type} =~ /^.p$/) { 977 # PPP pools 978 $page->param(maysplit => 1) if $cidr->masklen+1 < $cidr->bits; 979 } elsif ($blockinfo->{type} =~ /.d/) { 980 # Non-PPP pools 981 $page->param(maysplit => 1) if $cidr->masklen+2 < $cidr->bits; 982 } else { 983 # Standard netblocks. Arguably allowing splitting these down to single IPs 984 # doesn't make much sense, but forcing users to apply allocation types 985 # "properly" is worse than herding cats. 986 $page->param(maysplit => 1) if $cidr->masklen < $cidr->bits; 987 } 988 } 989 967 990 } # edit() 968 991 … … 1061 1084 1062 1085 1086 sub prepSplit { 1087 if ($IPDBacl{$authuser} !~ /c/) { 1088 $aclerr = 'splitblock'; 1089 return; 1090 } 1091 1092 my $blockinfo = getBlockData($ip_dbh, $webvar{block}); 1093 1094 if ($blockinfo->{type} =~ /^.i$/) { 1095 $page->param(err => "Can't split a single IP allocation"); 1096 return; 1097 } 1098 1099 # Info about current allocation 1100 $page->param(oldblock => $blockinfo->{block}); 1101 $page->param(block => $webvar{block}); 1102 1103 # Note that there are probably different rules that should be followed to restrict splitting IPv6 blocks; 1104 # strictly speaking it will be exceptionally rare to see smaller than a /64 assigned to a customer, since that 1105 # breaks auto-addressing schemes. 1106 1107 # Generate possible splits 1108 my $block = new NetAddr::IP $blockinfo->{block}; 1109 my $oldmask = $block->masklen; 1110 if ($blockinfo->{type} =~ /^.d$/) { 1111 # Non-PPP pools 1112 if ($oldmask+2 >= $block->bits) { 1113 $page->param(err => "Can't split a standard netblock pool any further"); 1114 return; 1115 } 1116 # Allow splitting down to v4 /30 (which results in one usable IP; dubiously useful) 1117 $page->param(sp4mask => $oldmask+2) if $oldmask+2 <= $block->bits-2; 1118 } elsif ($blockinfo->{type} =~ /.p/) { 1119 # Allow splitting PPP pools down to v4 /31 1120 $page->param(sp4mask => $oldmask+2) if $oldmask+2 <= $block->bits-1; 1121 } else { 1122 # Allow splitting all other non-pool netblocks down to single IPs, which... 1123 # arguably should be *aggregated* in a pool. Except where they shouldn't. 1124 $page->param(sp4mask => $oldmask+2) if $oldmask+2 <= $block->bits; 1125 } 1126 # set the split-in-half mask 1127 $page->param(sp2mask => $oldmask+1); 1128 1129 # Generate possible shrink targets 1130 my @keepers = $block->split($block->masklen+1); 1131 $page->param(newblockA => $keepers[0]); 1132 $page->param(newblockB => $keepers[1]); 1133 } # prepSplit() 1134 1135 1136 sub doSplit { 1137 if ($IPDBacl{$authuser} !~ /c/) { 1138 $aclerr = 'splitblock'; 1139 return; 1140 } 1141 1142 ##fixme: need consistent way to identify "this thing that is this thing" with only the ID 1143 # also applies to other locations 1144 my $blockinfo = getBlockData($ip_dbh, $webvar{block}); 1145 1146 if ($blockinfo->{type} =~ /^.i$/) { 1147 $page->param(err => "Can't split a single IP allocation"); 1148 return; 1149 } 1150 1151 if ($webvar{subact} eq 'split') { 1152 $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}; 1156 my $newblocks = splitBlock($ip_dbh, $webvar{block}, 'b', $webvar{split}); 1157 if ($newblocks) { 1158 $page->param(newblocks => $newblocks); 1159 # and the backlink to the parent container 1160 my $pinfo = getBlockData($ip_dbh, $binfo->{parent_id}); 1161 $page->param(backid => $binfo->{parent_id}); 1162 $page->param(backblock => $pinfo->{block}); 1163 } else { 1164 $page->param(err => $IPDB::errstr); 1165 } 1166 1167 } else { 1168 # Shrink 1169 } 1170 } # doSplit() 1171 1172 1063 1173 # Delete an allocation. 1064 1174 sub remove {
Note:
See TracChangeset
for help on using the changeset viewer.