Changeset 634


Ignore:
Timestamp:
10/09/14 12:37:39 (10 years ago)
Author:
Kris Deugau
Message:

/trunk

Commit 8/mumble for work done intermittently over the past ~year.
See #5, comment 25:

  • Netblock update
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/IPDB.pm

    r633 r634  
    11661166  return ('FAIL', 'Missing block to update') if !$args{block};
    11671167
     1168  # Spaces don't show up well in lots of places.  Make sure they don't get into the DB.
     1169  $args{custid} =~ s/^\s+//;
     1170  $args{custid} =~ s/\s+$//;
     1171
    11681172  # do it all in a transaction
    11691173  local $dbh->{AutoCommit} = 0;
     
    11791183  }
    11801184
     1185  my $binfo;
    11811186  my $updtable = 'allocations';
    1182   my $keyfield = 'cidr';
     1187  my $keyfield = 'id';
    11831188  if ($args{type} =~ /^(.)i$/) {
    11841189    $updtable = 'poolips';
    1185     $keyfield = 'ip';
     1190    $binfo = getBlockData($dbh, $args{block}, 'i');
    11861191  } else {
    11871192## fixme:  there's got to be a better way...
     1193    $binfo = getBlockData($dbh, $args{block});
    11881194    if ($args{swip}) {
    11891195      if ($args{swip} eq 'on' || $args{swip} eq '1' || $args{swip} eq 'y') {
     
    12031209  return ('FAIL', 'No fields to update') if !@fieldlist;
    12041210
    1205 #  push @vallist, $args{block}, $args{rdepth}, $args{vrf};
    1206   push @vallist, $args{block}, $args{rdepth};
     1211  push @vallist, $args{block};
    12071212  my $sql = "UPDATE $updtable SET ";
    12081213  $sql .= join " = ?, ", @fieldlist;
    1209 #  $sql .= " = ? WHERE $keyfield = ? AND rdepth = ? AND vrf = ?";
    1210   $sql .= " = ? WHERE $keyfield = ? AND rdepth = ? ";
     1214  $sql .= " = ? WHERE $keyfield = ?";
    12111215
    12121216  eval {
     
    12161220    if ($args{node}) {
    12171221      # done with delete/insert so we don't have to worry about funkyness updating a node ref that isn't there
    1218       $dbh->do("DELETE FROM noderef WHERE block = ?", undef, ($args{block}) );
    1219       $dbh->do("INSERT INTO noderef (block,node_id) VALUES (?,?)", undef, ($args{block}, $args{node}) );
     1222      $dbh->do("DELETE FROM noderef WHERE block = ?", undef, ($binfo->{block}) );
     1223      $dbh->do("INSERT INTO noderef (block,node_id) VALUES (?,?)", undef, ($binfo->{block}, $args{node}) )
     1224        if $args{node} ne '--';
    12201225    }
    12211226
     
    12281233  }
    12291234
    1230   _rpc('addOrUpdateRevRec', cidr => $args{block}, name => $args{rdns}, rpcuser => $args{user});
     1235  $binfo->{block} =~ s|/32$||;
     1236  _rpc('addOrUpdateRevRec', cidr => $binfo->{block}, name => $args{rdns}, rpcuser => $args{user});
    12311237  return ('OK','OK');
    12321238} # end updateBlock()
  • trunk/cgi-bin/main.cgi

    r633 r634  
    651651
    652652  # snag block info from db
    653   my $blockinfo = getBlockData($ip_dbh, $webvar{block}, $webvar{rdepth});
     653  my $blockinfo = getBlockData($ip_dbh, $webvar{id}, $webvar{basetype});
     654  $page->param(id => $webvar{id});
     655  $page->param(basetype => $webvar{basetype});
    654656
    655657  # Clean up extra whitespace on alloc type.  Mainly a legacy-data cleanup.
     
    657659
    658660  # Get rDNS info;  duplicates a bit of getBlockData but also does the RPC call if possible
    659   $blockinfo->{rdns} = getBlockRDNS($ip_dbh, $webvar{block}, $webvar{rdepth}, user => $authuser);
    660 
    661   $page->param(block => $webvar{block});
     661  $blockinfo->{rdns} = getBlockRDNS($ip_dbh, id => $webvar{id}, type => $blockinfo->{type}, user => $authuser);
     662
     663  $page->param(block    => $blockinfo->{block});
    662664  $page->param(rdns     => $blockinfo->{rdns});
    663   $page->param(rdepth   => $blockinfo->{rdepth});
    664665
    665666  $page->param(custid   => $blockinfo->{custid});
     
    689690
    690691## node hack
    691   my ($nodeid,$nodename) = getNodeInfo($ip_dbh, $webvar{block});
    692   $page->param(havenodeid => $nodeid);
    693 
    694   if ($blockinfo->{type} eq 'fr' || $blockinfo->{type} eq 'bi') {
    695     $page->param(typesupportsnodes => 1);
    696     $page->param(nodename => $nodename);
     692  my ($nodeid,$nodename) = getNodeInfo($ip_dbh, $blockinfo->{block});
     693#  $page->param(havenodeid => $nodeid);
     694  $page->param(nodename => $nodename);
    697695
    698696##fixme:  this whole hack needs cleanup and generalization for all alloctypes
    699697##fixme:  arguably a bug that presence of a nodeid implies it can be changed..
    700 #  but except for manual database changes, only the two types fr and bi can
    701 #  (currently) have a nodeid set in the first place.
    702     if ($IPDBacl{$authuser} =~ /c/) {
    703       my $nlist = getNodeList($ip_dbh);
     698  if ($IPDBacl{$authuser} =~ /c/) {
     699    my $nlist = getNodeList($ip_dbh);
     700    if ($nodeid) {
    704701      foreach (@{$nlist}) {
    705         $$_{selme} = ($$_{node_id} == $nodeid);
     702        $$_{selme} = ($$_{node_id} == $nodeid);
    706703      }
    707       $page->param(nodelist => $nlist);
    708     }
     704    }
     705    $page->param(nodelist => $nlist);
    709706  }
    710707## end node hack
     
    750747        type            => $webvar{alloctype},
    751748        swip            => $webvar{swip},
    752         rdepth          => $webvar{rdepth},
    753749        rdns            => $webvar{rdns},
    754750        user            => $authuser,
     
    783779
    784780  # Link back to browse-routed or list-pool page on "Update complete" page.
    785   my $cblock = getBlockData($ip_dbh, $webvar{block}, $webvar{rdepth});
    786   if (my $pooltype = ($webvar{alloctype} =~ /^(.)i$/) ) {
    787     $page->param(backpool => 1);
    788     $page->param(backblock => $cblock->{pool});
    789   } else {
    790     $page->param(backblock => $cblock->{parent});
    791   }
    792   $page->param(backdepth => ($webvar{rdepth}));
     781  my $binfo = getBlockData($ip_dbh, $webvar{block}, $webvar{basetype});
     782  my $pblock = getBlockData($ip_dbh, $binfo->{parent_id});
     783  $page->param(backid => $binfo->{parent_id});
     784  $page->param(backblock => $pblock->{block});
     785  $page->param(backpool => ($webvar{basetype} eq 'i'));
    793786
    794787  # Do some HTML fiddling here instead of using ESCAPE=HTML in the template,
     
    799792  $webvar{privdata} =~ s/\n/<br>\n/;
    800793
    801   $page->param(cidr => $webvar{block});
     794  $page->param(cidr => $binfo->{block});
    802795  $page->param(rdns => $webvar{rdns});
    803796  $page->param(city => $webvar{city});
  • trunk/templates/edit.tmpl

    r586 r634  
    1111<fieldset><legend class="noshow">&nbsp;</legend>
    1212<input type="hidden" name="action" value="update">
    13 <input type="hidden" name="block" value="<TMPL_VAR NAME=block>">
    14 <input type="hidden" name="rdepth" value="<TMPL_VAR NAME=rdepth>">
     13<input type="hidden" name="block" value="<TMPL_VAR NAME=id>">
    1514</TMPL_IF>
    1615
     
    6160
    6261<tr class="row0">
    63 <td class=heading>Demarc/tower:</td>
     62<td class=heading>Layer-2/demarc node:</td>
    6463<td class=regular>
    65 <TMPL_IF typesupportsnodes>
    6664<TMPL_IF maychange>
    67 <select name="node"><TMPL_UNLESS havenodeid>
    68         <option selected="selected">--</option></TMPL_UNLESS>
     65<select name="node">
     66        <option selected="selected">--</option>
    6967<TMPL_LOOP NAME=nodelist>
    7068        <option value="<TMPL_VAR NAME=node_id>"<TMPL_IF selme> selected</TMPL_IF>><TMPL_VAR NAME=node_name></option></TMPL_LOOP>
    7169</select>
     70&nbsp;<a href="javascript:popNotes('<TMPL_VAR NAME=webpath>/cgi-bin/newnode.cgi')">Add new demarc node</a>
    7271<TMPL_ELSE>
    7372<TMPL_IF nodename><TMPL_VAR NAME=nodename><TMPL_ELSE>N/A</TMPL_IF>
    74 </TMPL_IF>
    75 <TMPL_ELSE>
    76 N/A
    7773</TMPL_IF>
    7874</td>
     
    158154<tr class="row<TMPL_IF nocling>0<TMPL_ELSE>1</TMPL_IF>">
    159155<td colspan="2" class="center">
     156<input type="hidden" name="basetype" value="<TMPL_VAR NAME=basetype>">
    160157<input type="submit" value=" Update this block " class="regular">
    161158</td>
     
    175172<div class="row<TMPL_IF nocling><TMPL_IF maychange>1<TMPL_ELSE>0</TMPL_IF><TMPL_ELSE><TMPL_IF maychange>0<TMPL_ELSE>1</TMPL_IF></TMPL_IF>">
    176173<input type="hidden" name="action" value="delete">
    177 <input type="hidden" name="block" value="<TMPL_VAR NAME=block>">
    178 <input type="hidden" name="rdepth" value="<TMPL_VAR NAME=rdepth>">
     174<input type="hidden" name="block" value="<TMPL_VAR NAME=id>">
     175<input type="hidden" name="basetype" value="<TMPL_VAR NAME=basetype>">
    179176<input type=submit value=" Delete this block ">
    180177</div>
  • trunk/templates/update.tmpl

    r588 r634  
    1010
    1111<tr class="row0">
    12 <td>IP block:</td>
     12<td>IP<TMPL_UNLESS backpool> block</TMPL_UNLESS>:</td>
    1313<td><TMPL_VAR NAME=cidr></td>
    1414</tr>
     
    3232
    3333<tr class="row0">
    34 <td>Demarc/tower:</td>
     34<td>Layer-2/demarc node:</td>
    3535<td><TMPL_IF nodename><TMPL_VAR NAME=nodename><TMPL_ELSE>N/A</TMPL_IF></td>
    3636</tr>
     
    7272<br>
    7373<div class="backlink">
    74 <a href="<TMPL_VAR NAME=webpath>/cgi-bin/main.cgi?action=<TMPL_IF backpool>listpool&amp;pool=<TMPL_ELSE>showsubs&amp;block=</TMPL_IF><TMPL_VAR NAME=backblock>&amp;rdepth=<TMPL_VAR NAME=backdepth>">Back to <TMPL_VAR NAME=backblock></a>
     74<a href="<TMPL_VAR NAME=webpath>/cgi-bin/main.cgi?action=<TMPL_IF backpool>listpool&amp;pool=<TMPL_ELSE>showsubs&amp;parent=</TMPL_IF><TMPL_VAR NAME=backid>">Back to <TMPL_VAR NAME=backblock></a>
    7575</div>
    7676</TMPL_IF>
Note: See TracChangeset for help on using the changeset viewer.