Changeset 707
- Timestamp:
- 02/27/15 18:17:24 (10 years ago)
- Location:
- trunk/cgi-bin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/IPDB.pm
r705 r707 1462 1462 sub splitBlock { 1463 1463 my $dbh = shift; 1464 my $id = shift; 1465 my $basetype = shift; 1466 my $newmask = shift; 1464 my %args = @_; 1465 # my $id = shift; 1466 # my $basetype = shift; 1467 # my $newmask = shift; 1467 1468 1468 1469 ##fixme: set errstr on errors so caller can suitably clue-by-four the user 1469 return if $ basetypene 'b'; # only netblocks allowed!1470 1471 my $binfo = getBlockData($dbh, $ id);1470 return if $args{basetype} ne 'b'; # only netblocks allowed! 1471 1472 my $binfo = getBlockData($dbh, $args{id}); 1472 1473 return if !$binfo; 1473 1474 1474 return if $ newmask!~ /^\d+$/;1475 return if $args{newmask} !~ /^\d+$/; 1475 1476 1476 1477 my @ret; … … 1481 1482 # failure modes: 1482 1483 # difference between $oldmask and $newmask is negative or 0 1483 if ($ newmask- $oldmask <= 0) {1484 $errstr = "Can't split a /$oldmask allocation into /$ newmaskpieces";1484 if ($args{newmask} - $oldmask <= 0) { 1485 $errstr = "Can't split a /$oldmask allocation into /$args{newmask} pieces"; 1485 1486 return; 1486 1487 } … … 1490 1491 # $oldmask > n, for arbitrary n? At least check limits of data type. 1491 1492 if ($block->{isv6}) { 1492 if ($ newmask- $oldmask > 128) {1493 $errstr = "Impossible IPv6 mask length /$ newmaskrequested";1493 if ($args{newmask} - $oldmask > 128) { 1494 $errstr = "Impossible IPv6 mask length /$args{newmask} requested"; 1494 1495 return; 1495 1496 } 1496 1497 } else { 1497 if ($ newmask- $oldmask > 32) {1498 $errstr = "Impossible IPv4 mask length /$ newmaskrequested";1498 if ($args{newmask} - $oldmask > 32) { 1499 $errstr = "Impossible IPv4 mask length /$args{newmask} requested"; 1499 1500 return; 1500 1501 } 1501 1502 } 1502 1503 1503 my @newblocks = $block->split($ newmask);1504 my @newblocks = $block->split($args{newmask}); 1504 1505 1505 1506 local $dbh->{AutoCommit} = 0; … … 1517 1518 } 1518 1519 # note the first block in the split for return 1519 push @ret, {nid => $ id, nblock => "$newblocks[0]"};1520 push @ret, {nid => $args{id}, nblock => "$newblocks[0]"}; 1520 1521 1521 1522 # prepare … … 1527 1528 1528 1529 # set up update of existing block 1529 $dbh->do("UPDATE allocations SET cidr = ? WHERE id = ?", undef, ("$newblocks[0]", $ id) );1530 $dbh->do("UPDATE allocations SET cidr = ? WHERE id = ?", undef, ("$newblocks[0]", $args{id}) ); 1530 1531 1531 1532 # axe the net, gw, and bcast IPs as necessary when splitting a "normal" pool 1532 1533 if ($binfo->{type} =~ /.d/) { 1533 1534 $newblocks[0]--; 1534 $nbsth->execute($ id, $newblocks[0]->addr);1535 $nbsth->execute($args{id}, $newblocks[0]->addr); 1535 1536 } 1536 1537 … … 1547 1548 if ($binfo->{type} =~ /.d/) { 1548 1549 # net 1549 $nbsth->execute($ id, $newblocks[$i]->addr);1550 $nbsth->execute($args{id}, $newblocks[$i]->addr); 1550 1551 $newblocks[$i]++; 1551 1552 # gw 1552 $nbsth->execute($ id, $newblocks[$i]->addr);1553 $nbsth->execute($args{id}, $newblocks[$i]->addr); 1553 1554 $newblocks[$i]--; 1554 1555 $newblocks[$i]--; 1555 1556 # bcast 1556 $nbsth->execute($ id, $newblocks[$i]->addr);1557 $nbsth->execute($args{id}, $newblocks[$i]->addr); 1557 1558 $newblocks[$i]++; 1558 1559 } 1559 1560 # ... and update the existing IPs with the new parent_id 1560 $poolchildsth->execute($nid, $newblocks[$i], $ id);1561 $poolchildsth->execute($nid, $newblocks[$i], $args{id}); 1561 1562 } 1562 1563 … … 1568 1569 return; 1569 1570 } 1571 ##fixme: RPC return code? 1572 # particularly useful in this case as there may be arbitrary combinations of pass, warn, fail 1573 # results from each of the update and add(s), which could get the user to prod dnsadmin to see what exploded 1574 my $foo = _rpc('splitTemplate', cidr => $binfo->{block}, newmask => $args{newmask}, rpcuser => $args{user}); 1570 1575 1571 1576 return \@ret; -
trunk/cgi-bin/main.cgi
r706 r707 1172 1172 $page->param(issplit => 1); 1173 1173 my $block = new NetAddr::IP $blockinfo->{block}; 1174 my $newblocks = splitBlock($ip_dbh, $webvar{block}, 'b', $webvar{split}); 1174 my $newblocks = splitBlock($ip_dbh, id => $webvar{block}, basetype => 'b', newmask => $webvar{split}, 1175 user => $authuser); 1175 1176 if ($newblocks) { 1176 1177 $page->param(newblocks => $newblocks);
Note:
See TracChangeset
for help on using the changeset viewer.