Changeset 536


Ignore:
Timestamp:
10/31/12 17:56:03 (11 years ago)
Author:
Kris Deugau
Message:

/trunk

Clean up and move SQL for post-update backlink to IPDB.pm. See #34.
Also rename getParent() to subParent() to fit in with ipParent() and
blockParent().

Fix a couple "Use of uninitialized..." log-noise bugs. See #31.

Move some HTML-entity-escaping into the template, and shuffle lines
munging the notes and restricted data on post-update value display
so we can properly munge in <br> for \n. Doesn't seem to be a way
to plug that into HTML::Template. :( See #3.

Location:
trunk
Files:
3 edited

Legend:

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

    r535 r536  
    2929        &listSummary &listMaster &listRBlock &listFree &listPool
    3030        &getTypeList &getPoolSelect &findAllocateFrom
    31         &getParent &getRoutedCity
     31        &ipParent &subParent &blockParent &getRoutedCity
    3232        &allocateBlock &updateBlock &deleteBlock &getBlockData
    3333        &getNodeList &getNodeName &getNodeInfo
     
    4343                &listSummary &listMaster &listRBlock &listFree &listPool
    4444                &getTypeList &getPoolSelect &findAllocateFrom
    45                 &getParent &getRoutedCity
     45                &ipParent &subParent &blockParent &getRoutedCity
    4646                &allocateBlock &updateBlock &deleteBlock &getBlockData
    4747                &getNodeList &getNodeName &getNodeInfo
     
    576576
    577577
    578 ## IPDB::getParent()
    579 # Get a block's parent's details
    580 # Takes a database handle and CIDR block
    581 # Returns a hashref to the parent routed or container block, if any
    582 sub getParent {
     578## IPDB::ipParent()
     579# Get an IP's parent pool's details
     580# Takes a database handle and IP
     581# Returns a hashref to the parent pool block, if any
     582sub ipParent {
    583583  my $dbh = shift;
    584584  my $block = shift;
     
    587587        " WHERE cidr >>= ?", undef, ($block) );
    588588  return $pinfo;
    589 } # end getParent()
     589} # end ipParent()
     590
     591
     592## IPDB::subParent()
     593# Get a block's parent's details
     594# Takes a database handle and CIDR block
     595# Returns a hashref to the parent container block, if any
     596sub subParent {
     597  my $dbh = shift;
     598  my $block = shift;
     599
     600  my $pinfo = $dbh->selectrow_hashref("SELECT cidr,custid,type,city,description FROM allocations".
     601        " WHERE cidr >>= ?", undef, ($block) );
     602  return $pinfo;
     603} # end subParent()
     604
     605
     606## IPDB::blockParent()
     607# Get a block's parent's details
     608# Takes a database handle and CIDR block
     609# Returns a hashref to the parent container block, if any
     610sub blockParent {
     611  my $dbh = shift;
     612  my $block = shift;
     613
     614  my $pinfo = $dbh->selectrow_hashref("SELECT cidr,city FROM routed".
     615        " WHERE cidr >>= ?", undef, ($block) );
     616  return $pinfo;
     617} # end blockParent()
    590618
    591619
  • trunk/cgi-bin/main.cgi

    r534 r536  
    328328      # Snag the type of the container block from the database.
    329329## hmm.  need a flag for parent class/type, sort of?
    330       my $pblock = getParent($ip_dbh, $webvar{block});
     330      my $pblock = subParent($ip_dbh, $webvar{block});
    331331      my $ptype = $pblock->{type};
    332332      $ptype =~ s/c$/r/;
     
    616616##fixme:  hook to force-set POP or city on certain alloctypes
    617617# if ($webvar{alloctype =~ /foo,bar,bz/ { $webvar{pop} = 'blah'; }
    618     if ($webvar{pop} =~ /^-$/) {
     618    if ($webvar{pop} && $webvar{pop} =~ /^-$/) {
    619619      $flag = 'to route the block from/through';
    620620    }
     
    722722  return if !validateInput;
    723723
     724  $webvar{swip} = 'n' if !$webvar{swip};
     725
    724726  my %updargs = (
    725727        custid          => $webvar{custid},
     
    730732        block           => $webvar{block},
    731733        type            => $webvar{alloctype},
     734        swip            => $webvar{swip},
    732735        );
    733736
     
    760763
    761764  # Link back to browse-routed or list-pool page on "Update complete" page.
    762   my $cblock;   # to contain the CIDR of the container block we're retrieving.
    763   my $sql;
     765  my $cblock;
    764766  if (my $pooltype = ($webvar{alloctype} =~ /^(.)i$/) ) {
    765767    $page->param(backpool => 1);
    766     $sql = "select pool from poolips where ip='$webvar{block}'";
     768    $cblock = ipParent($ip_dbh, $webvar{block});
    767769  } else {
    768     $sql = "select cidr from routed where cidr >>= '$webvar{block}'";
    769   }
    770   # I define there to be no errors on this operation...  so we don't need to check for them.
    771   $sth = $ip_dbh->prepare($sql);
    772   $sth->execute;
    773   $sth->bind_columns(\$cblock);
    774   $sth->fetch();
    775   $sth->finish;
    776   $page->param(backblock => $cblock);
     770    $cblock = blockParent($ip_dbh, $webvar{block});
     771  }
     772  $page->param(backblock => $cblock->{cidr});
     773
     774  # Do some HTML fiddling here instead of using ESCAPE=HTML in the template,
     775  # because otherwise we can't convert \n to <br>.  *sigh*
     776  $webvar{notes} = $q->escapeHTML($webvar{notes});      # escape first...
     777  $webvar{notes} =~ s/\n/<br>\n/;                       # ... then convert newlines
     778  $webvar{privdata} = ($webvar{privdata} ? $q->escapeHTML($webvar{privdata}) : "&nbsp;");
     779  $webvar{privdata} =~ s/\n/<br>\n/;
    777780
    778781  $page->param(cidr => $webvar{block});
     
    781784  $page->param(custid => $webvar{custid});
    782785  $page->param(swip => $webvar{swip} eq 'on' ? 'Yes' : 'No');
    783   $page->param(circid => $q->escapeHTML($webvar{circid}));
    784   $page->param(desc => $q->escapeHTML($webvar{desc}));
    785   $page->param(notes => $q->escapeHTML($webvar{notes}));
    786   $webvar{privdata} = ($webvar{privdata} ? $q->escapeHTML($webvar{privdata}) : "&nbsp;");
     786  $page->param(circid => $webvar{circid});
     787  $page->param(desc => $webvar{desc});
     788  $page->param(notes => $webvar{notes});
    787789  $page->param(privdata => $webvar{privdata})
    788790        if $IPDBacl{$authuser} =~ /s/;
  • trunk/templates/update.tmpl

    r517 r536  
    4141<tr class="row0">
    4242<td>Circuit ID:</td>
    43 <td><TMPL_VAR NAME=circid></td>
     43<td><TMPL_VAR ESCAPE=HTML NAME=circid></td>
    4444</tr>
    4545
    4646<tr class="row1">
    4747<td valign="top">Description/Name:</td>
    48 <td><TMPL_VAR NAME=desc></td>
     48<td><TMPL_VAR ESCAPE=HTML NAME=desc></td>
    4949</tr>
    5050
Note: See TracChangeset for help on using the changeset viewer.