Changeset 575


Ignore:
Timestamp:
12/21/12 17:43:19 (11 years ago)
Author:
Kris Deugau
Message:

/trunk

Work in progress, see #5:
Update "add new allocation" templates and calling code for new
table logic and fields.
Also update listpool page to pass around rdepth as necessary

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/main.cgi

    r571 r575  
    286286  $page->param(rowa => 'row'.($webvar{block} eq '' ? 1 : 0));
    287287  $page->param(rowb => 'row'.($webvar{block} eq '' ? 0 : 1));
    288   $page->param(block => $webvar{block});        # fb-assign flag, if block is set, we're in fb-assign
    289   $page->param(iscontained => ($webvar{fbtype} && $webvar{fbtype} ne 'y'));
    290 
    291   # New special case- block to assign is specified
     288  $page->param(allocfrom => $webvar{block});    # fb-assign flag, if block is set, we're in fb-assign
     289
    292290  if ($webvar{block} ne '') {
     291
     292    # Common case, according to reported usage.  Block to assign is specified.
    293293    my $block = new NetAddr::IP $webvar{block};
    294 
    295     # Handle contained freeblock allocation.
    296     # This is a little dangerous, as it's *theoretically* possible to
    297     # get fbtype='n' (aka a non-routed freeblock).  However, should
    298     # someone manage to get there, they get what they deserve.
    299     if ($webvar{fbtype} ne 'y') {
    300       # Snag the type of the container block from the database.
    301 ## hmm.  need a flag for parent class/type, sort of?
    302       my $pblock = subParent($ip_dbh, $webvar{block});
    303       my $ptype = $pblock->{type};
    304       $ptype =~ s/c$/r/;
    305       $page->param(fbdisptype => $list_alloctypes{$ptype});
    306       $page->param(type => $ptype);
     294    $page->param(rdepth => $webvar{rdepth});
     295
     296    $webvar{fbtype} = '' if !$webvar{fbtype};
     297    if ($webvar{fbtype} eq 'i') {
     298      my $ipinfo = getBlockData($ip_dbh, $block);
     299      $page->param(
     300        fbip => 1,
     301        block => $block,
     302        fbdisptype => $list_alloctypes{$ipinfo->{type}},
     303        type => $ipinfo->{type},
     304        allocfrom => $ipinfo->{pool},
     305        );
    307306    } else {
    308307      # get "primary" alloctypes, since these are all that can correctly be assigned if we're in this branch
    309       my $tlist = getTypeList($ip_dbh, 'p');
     308      my $tlist = getTypeList($ip_dbh, 'n');
    310309      $tlist->[0]->{sel} = 1;
    311       $page->param(typelist => $tlist);
    312     }
     310      $page->param(typelist => $tlist, block => $block);
     311    }
     312
    313313  } else {
     314
     315    # Uncommon case, according to reported usage.  Block to assign needs to be found based on criteria.
    314316    my $mlist = getMasterList($ip_dbh, 'c');
    315317    $page->param(masterlist => $mlist);
     
    364366#  + Different flavours of netblock
    365367
    366   if ($webvar{alloctype} =~ /^.i$/) {
     368  if ($webvar{alloctype} =~ /^.i$/ && $webvar{fbassign} ne 'y') {
    367369    my $plist = getPoolSelect($ip_dbh, $webvar{alloctype}, $webvar{pop});
    368370    $page->param(staticip => 1);
     
    375377    if ($webvar{fbassign} && $webvar{fbassign} eq 'y') {
    376378      $cidr = new NetAddr::IP $webvar{block};
     379      $alloc_from = new NetAddr::IP $webvar{allocfrom};
    377380      $webvar{maskbits} = $cidr->masklen;
    378381    } else { # done with direct freeblocks assignment
     
    402405      }
    403406
    404       $cidr = findAllocateFrom($ip_dbh, $webvar{maskbits}, $webvar{alloctype}, $webvar{city}, $webvar{pop},
    405         (master => $webvar{allocfrom}, allowpriv => $webvar{allowpriv}) );
     407## fixme:  add rdepth?
     408      ($cidr,$webvar{rdepth}) = findAllocateFrom($ip_dbh, $webvar{maskbits}, $webvar{alloctype}, $webvar{city},
     409        $webvar{pop}, (master => $webvar{allocfrom}, allowpriv => $webvar{allowpriv}) );
    406410      if (!$cidr) {
    407411        $page->param(err => $failmsg);
     
    409413      }
    410414      $cidr = new NetAddr::IP $cidr;
     415
     416# this chunk now specific to "guided" allocation;  freeblock-select can now slice-n-dice on its own.     
     417      $alloc_from = "$cidr";
     418      # If the block to be allocated is smaller than the one we found,
     419      # figure out the "real" block to be allocated.
     420      if ($cidr->masklen() ne $webvar{maskbits}) {
     421        my $maskbits = $cidr->masklen();
     422        my @subblocks;
     423        while ($maskbits++ < $webvar{maskbits}) {
     424          @subblocks = $cidr->split($maskbits);
     425        }
     426        $cidr = $subblocks[0];
     427      }
    411428    } # check for freeblocks assignment or IPDB-controlled assignment
    412429
    413     $alloc_from = "$cidr";
    414 
    415     # If the block to be allocated is smaller than the one we found,
    416     # figure out the "real" block to be allocated.
    417     if ($cidr->masklen() ne $webvar{maskbits}) {
    418       my $maskbits = $cidr->masklen();
    419       my @subblocks;
    420       while ($maskbits++ < $webvar{maskbits}) {
    421         @subblocks = $cidr->split($maskbits);
    422       }
    423       $cidr = $subblocks[0];
    424     }
    425430  } # if ($webvar{alloctype} =~ /^.i$/)
    426431
     
    437442  $page->param(typefull => $q->escapeHTML($disp_alloctypes{$webvar{alloctype}}));
    438443  $page->param(alloc_from => $alloc_from);
     444  $page->param(rdepth => $webvar{rdepth});
    439445  $page->param(cidr => $cidr);
    440446  $page->param(city => $q->escapeHTML($webvar{city}));
     
    477483    $webvar{privdata} = '';
    478484  }
     485
     486  # split up some linked data for static IPs via guided allocation.  needed for breadcrumbs lite.
     487  ($webvar{alloc_from},$webvar{rdepth}) = split /,/, $webvar{alloc_from};
     488
    479489  # $code is "success" vs "failure", $msg contains OK for a
    480490  # successful netblock allocation, the IP allocated for static
    481491  # IP, or the error message if an error occurred.
    482492
    483   my ($code,$msg) = allocateBlock($ip_dbh, $webvar{fullcidr}, $webvar{alloc_from},
    484         $webvar{custid}, $webvar{alloctype}, $webvar{city}, $webvar{desc}, $webvar{notes},
    485         $webvar{circid}, $webvar{privdata}, $webvar{node});
     493  my ($code,$msg) = allocateBlock($ip_dbh, cidr => $webvar{fullcidr}, alloc_from => $webvar{alloc_from},
     494        rdepth => $webvar{rdepth}, custid => $webvar{custid}, type => $webvar{alloctype}, city => $webvar{city},
     495        desc => $webvar{desc}, notes => $webvar{notes}, circid => $webvar{circid},
     496        privdata => $webvar{privdata}, nodeid => $webvar{node});
    486497
    487498  if ($code eq 'OK') {
     
    490501      $page->param(staticip => $msg);
    491502      $page->param(custid => $webvar{custid});
     503      $page->param(parent => $webvar{alloc_from}, rdepth => $webvar{rdepth}-1);
    492504      $page->param(billinguser => $webvar{billinguser});
    493505      mailNotify($ip_dbh, "a$webvar{alloctype}", "ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
     
    499511      $page->param(alloctype => $disp_alloctypes{$webvar{alloctype}});
    500512      $page->param(custid => $webvar{custid});
     513      # breadcrumbs lite!  provide at least a link to the parent of the block we just allocated.
     514      my $binfo = getBlockData($ip_dbh, $webvar{fullcidr}, $webvar{rdepth});
     515      $page->param(parent => $binfo->{parent}, rdepth => $binfo->{rdepth});
    501516      if ($webvar{alloctype} eq 'pr' && $webvar{billinguser}) {
    502517        $page->param(billinguser => $webvar{billinguser});
  • trunk/templates/assign.tmpl

    r530 r575  
    11<div class="indent">
    2 <TMPL_IF block>
    3 <div class="tblsubtitle">
    4 Assign free <TMPL_IF iscontained><TMPL_VAR NAME=fbdisptype></TMPL_IF> block <TMPL_VAR NAME=block>
    5 </div>
    6 <TMPL_ELSE>
    7 <div class="tblsubtitle">Assign IPs</div>
    8 </TMPL_IF>
     2<div class="tblsubtitle">Assign IP<TMPL_UNLESS fbip>s</TMPL_UNLESS></div>
    93<br>
    104
     
    126<fieldset><legend class="noshow">&nbsp;</legend>
    137
    14 <TMPL_IF block>
    15 <input type="hidden" name="block" value="<TMPL_VAR NAME=block>">
     8<table class="regular" cellspacing="1" cellpadding="1">
     9
     10<TMPL_IF allocfrom>
     11<tr class="row0">
     12<TMPL_IF fbip>
     13<td>IP pool:</td>
     14<TMPL_ELSE>
     15<td>Free block selected:</td>
     16</TMPL_IF>
     17<td><TMPL_VAR NAME=allocfrom><input type="hidden" name="allocfrom" value="<TMPL_VAR NAME=allocfrom>">
     18<input type="hidden" name="rdepth" value="<TMPL_VAR NAME=rdepth>">
     19</td>
     20</tr>
     21<tr class="row1">
     22<TMPL_IF fbip>
     23<td>IP:</td>
     24<td>
     25<TMPL_VAR NAME=block><input type="hidden" name="block" value="<TMPL_VAR NAME=block>">
    1626<input type="hidden" name="fbassign" value="y">
     27</td>
     28<TMPL_ELSE>
     29<td>Allocation:</td>
     30<td>
     31<input name="block" value="<TMPL_VAR NAME=block>">
     32<input type="hidden" name="fbassign" value="y">
     33</td>
    1734</TMPL_IF>
    18 
    19 <table class="regular" cellspacing="1" cellpadding="1">
     35</tr>
     36</TMPL_IF>
    2037
    2138<tr class="row0">
     
    3451<td>Allocation type:</td>
    3552<td>
    36 <TMPL_IF iscontained>
     53<TMPL_IF fbip>
    3754<TMPL_VAR NAME=fbdisptype><input type="hidden" name="alloctype" value="<TMPL_VAR NAME=type>">
    3855<TMPL_ELSE>
     
    4663</tr>
    4764
    48 <TMPL_UNLESS block>
     65<TMPL_UNLESS allocfrom>
    4966<tr class="row0">
    5067<td>Subnet CIDR mask length:</td>
     
    6683        <option value="<TMPL_VAR NAME=node_id>"><TMPL_VAR NAME=node_name></option></TMPL_LOOP>
    6784</select>
    68 &nbsp;<a href="javascript:popNotes('<TMPL_VAR NAME=webpath>/cgi-bin/newnode.cgi')">Add new location</a>
     85&nbsp;<a href="javascript:popNotes('<TMPL_VAR NAME=webpath>/cgi-bin/newnode.cgi')">Add new demarc/tower</a>
    6986</td>
    7087</tr>
    7188
    72 <TMPL_UNLESS block>
     89<TMPL_UNLESS allocfrom>
    7390<tr class="<TMPL_VAR NAME=rowa>">
    7491<td>Route from/through:</td>
  • trunk/templates/confirm.tmpl

    r517 r575  
    2323<td>
    2424<select name="alloc_from">
    25 <TMPL_LOOP name=poollist>       <option value="<TMPL_VAR NAME=poolblock>"><TMPL_VAR NAME=poolblock> [<TMPL_VAR NAME=poolfree>] free IP(s) in <TMPL_VAR NAME=poolcit></option>
     25<TMPL_LOOP name=poollist>       <option value="<TMPL_VAR NAME=poolblock>,<TMPL_VAR NAME=poolrdepth>"><TMPL_VAR NAME=poolblock> [<TMPL_VAR NAME=poolfree>] free IP(s) in <TMPL_VAR NAME=poolcit></option>
    2626</TMPL_LOOP></select>
    2727</td>
     
    7777<td class="center" colspan="2">
    7878<TMPL_UNLESS poollist><input type="hidden" name="alloc_from" value="<TMPL_VAR NAME=alloc_from>"></TMPL_UNLESS>
     79<input type="hidden" name="rdepth" value="<TMPL_VAR NAME=rdepth>">
    7980<input type="hidden" name="fullcidr" value="<TMPL_VAR NAME=cidr>">
    8081<input type="hidden" name="city" value="<TMPL_VAR NAME=city>">
  • trunk/templates/insert.tmpl

    r517 r575  
    1 <TMPL_IF webpath></TMPL_IF>
    21<TMPL_IF err>
    32<div class="err">
     
    1312</TMPL_IF>
    1413</div>
     14<div class="center">IPs in <a href="<TMPL_VAR NAME=webpath>/cgi-bin/main.cgi?action=listpool&amp;pool=<TMPL_VAR NAME=parent>&amp;rdepth=<TMPL_VAR NAME=rdepth>"><TMPL_VAR NAME=parent></a></div>
    1515<TMPL_ELSE>
    1616<div class="center">
     
    2020</TMPL_IF>
    2121</div>
     22<div class="center">Allocations in <a href="<TMPL_VAR NAME=webpath>/cgi-bin/main.cgi?action=showsubs&amp;block=<TMPL_VAR NAME=parent>&amp;rdepth=<TMPL_VAR NAME=rdepth>"><TMPL_VAR NAME=parent></a></div>
    2223</TMPL_IF>
    2324</TMPL_IF>
  • trunk/templates/listpool.tmpl

    r570 r575  
    4040<td><TMPL_VAR NAME=desc></td>
    4141<TMPL_IF maydel><td><TMPL_IF delme>
    42 <a href="<TMPL_VAR NAME=webpath>/cgi-bin/main.cgi?action=delete&amp;block=<TMPL_VAR NAME=ip>&amp;alloctype=<TMPL_VAR NAME=type>">Unassign this IP</a>
     42<a href="<TMPL_VAR NAME=webpath>/cgi-bin/main.cgi?action=delete&amp;block=<TMPL_VAR NAME=ip>&amp;rdepth=<TMPL_VAR NAME=ipdepth>&amp;alloctype=<TMPL_VAR NAME=type>">Unassign this IP</a>
    4343</TMPL_IF></td></TMPL_IF>
    4444</tr>
Note: See TracChangeset for help on using the changeset viewer.