Ignore:
Timestamp:
10/18/12 16:53:10 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Finally merge conversion to HTML::Template from /branches/htmlform

  • Node "hack" showed conflict due to having been added to all branches in parallel
  • editDisplay.html was apparently changed enough that the merged delete caused an irrelevant conflict

Closes #3.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/cgi-bin/snCalc.cgi

    r371 r517  
    44use warnings;   
    55use CGI::Carp qw(fatalsToBrowser);
     6use CGI::Simple;
     7use HTML::Template;
    68use NetAddr::IP;
    7 use CommonWeb qw(:ALL);;
    89
    910#file snCalc.cgi        little subnet calculator app
    1011
    11 my %webvar = parse_post();
     12# Set up the CGI object...
     13my $q = new CGI::Simple;
     14# ... and get query-string params as well as POST params if necessary
     15$q->parse_query_string;
     16
     17# Convenience;  saves changing all references to %webvar
     18##fixme:  tweak for handling <select multiple='y' size=3> (list with multiple selection)
     19my %webvar = $q->Vars;
     20
    1221my $input;
    1322
    1423print "Content-Type: text/html\n\n";
    1524
    16 open(HTML, "../startsn.html")|| die "Could not open startsn.html :$!";
    17 my $start = join('', <HTML>);
    18 close(HTML);
    19 print $start;
     25##fixme:  need better method to find templates.
     26$ENV{HTML_TEMPLATE_ROOT} = $ENV{SCRIPT_FILENAME};
     27$ENV{HTML_TEMPLATE_ROOT} =~ s|cgi-bin/snCalc.cgi||;
     28
     29my $page = HTML::Template->new(filename => "templates/subnet-calc.tmpl");
    2030
    2131# Clean up input so we don't divide by zero or something equally silly
     
    3545my $postnet = new NetAddr::IP "0.0.0.0/$gtinput";
    3646
    37 print qq(<div class="center">
    38 <table align="center" cellspacing="3" cellpadding="3">
    39 <tr>
    40         <td class="heading" align="center">Results for /$ltinput</td>
    41         <td class="heading" align="center">Results for /$input</td>
    42         <td class="heading" align="center">Results for /$gtinput</td>
    43 </tr>
    44 );
     47$page->param(prenet => $ltinput);
     48$page->param(net => $input);
     49$page->param(postnet => $gtinput);
     50$page->param(premask => $prenet->mask);
     51$page->param(mask => $net->mask);
     52$page->param(postmask => $postnet->mask);
     53$page->param(prewildcard => scalar($prenet->wildcard));
     54$page->param(wildcard => scalar($net->wildcard));
     55$page->param(postwildcard => scalar($postnet->wildcard));
    4556
    46 print qq(<tr><td valign="top">\n).
    47         qq(     <div class="mask">).$prenet->mask."</div>\n".
    48         qq(     <div class="wildcard">).$prenet->wildcard."</div>\n".
    49         getranges($ltinput).
    50         qq(</td>\n<td valign="top" bgcolor="#d0e0e0">\n).
    51         qq(     <div class="mask">).$net->mask."</div>\n".
    52         qq(     <div class="wildcard">).$net->wildcard."</div>\n".
    53         getranges($input).
    54         qq(</td>\n<td valign="top">).
    55         qq(     <div class="mask">).$postnet->mask."</div>\n".
    56         qq(     <div class="wildcard">).$postnet->wildcard."</div>\n".
    57         getranges($gtinput);
     57my @prenets;
     58foreach (getranges($ltinput)) {
     59  my %row = (netrange => $_);
     60  push (@prenets, \%row);
     61}
     62$page->param(prenets => \@prenets);
     63my @nets;
     64foreach (getranges($input)) {
     65  my %row = (netrange => $_);
     66  push (@nets, \%row);
     67}
     68$page->param(nets => \@nets);
     69my @postnets;
     70foreach (getranges($gtinput)) {
     71  my %row = (netrange => $_);
     72  push @postnets, \%row;
     73}
     74$page->param(postnets => \@postnets);
    5875
    59 print "</td></tr>\n</table>\n";
    60 
    61 print qq(<input type="button" value="Back" onclick="history.go(-1)" class="heading">
    62 </div>
    63 </body>
    64 </html>
    65 );
     76print $page->output;
    6677       
    6778# Just In Case
     
    8697sub getranges {
    8798  my $masklen = shift;
    88   my $ret = '';
     99  my @ret;
    89100  my $super;
    90101  if ($masklen < 8) {
     
    98109  }
    99110  foreach my $net ($super->split($masklen)) {
    100     $ret .= "\t".xrange($net,$masklen)."<br />\n";
     111    push @ret, xrange($net,$masklen);
    101112  }
    102   return $ret;
     113  return @ret;
    103114} # getranges()
Note: See TracChangeset for help on using the changeset viewer.