Ignore:
Timestamp:
05/14/13 18:10:22 (12 years ago)
Author:
Kris Deugau
Message:

/branches/stable

Merge /trunk r517 (merge /branches/htmlform)
Conflicts all resolved towards /trunk.
Fix a minor syntax error with "while (@data..." -> "while (my @data..."
(may cause merge conflicts later)

Location:
branches/stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/stable

  • branches/stable/cgi-bin/snCalc.cgi

    r507 r593  
    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
    1011use MyIPDB;
    1112
    12 my %webvar = parse_post();
     13# Set up the CGI object...
     14my $q = new CGI::Simple;
     15# ... and get query-string params as well as POST params if necessary
     16$q->parse_query_string;
     17
     18# Convenience;  saves changing all references to %webvar
     19##fixme:  tweak for handling <select multiple='y' size=3> (list with multiple selection)
     20my %webvar = $q->Vars;
     21
    1322my $input;
    1423
    1524print "Content-Type: text/html\n\n";
    1625
    17 open(HTML, "../startsn.html")|| die "Could not open startsn.html :$!";
    18 my $start = join('', <HTML>);
    19 close(HTML);
    20 $start =~ s/\$\$WEBPATH\$\$/$IPDB::webpath/g;
    21 print $start;
     26##fixme:  need better method to find templates.
     27$ENV{HTML_TEMPLATE_ROOT} = $ENV{SCRIPT_FILENAME};
     28$ENV{HTML_TEMPLATE_ROOT} =~ s|cgi-bin/snCalc.cgi||;
     29
     30my $page = HTML::Template->new(filename => "templates/subnet-calc.tmpl");
    2231
    2332# Clean up input so we don't divide by zero or something equally silly
     
    3746my $postnet = new NetAddr::IP "0.0.0.0/$gtinput";
    3847
    39 print qq(<div class="center">
    40 <table align="center" cellspacing="3" cellpadding="3">
    41 <tr>
    42         <td class="heading" align="center">Results for /$ltinput</td>
    43         <td class="heading" align="center">Results for /$input</td>
    44         <td class="heading" align="center">Results for /$gtinput</td>
    45 </tr>
    46 );
     48$page->param(prenet => $ltinput);
     49$page->param(net => $input);
     50$page->param(postnet => $gtinput);
     51$page->param(premask => $prenet->mask);
     52$page->param(mask => $net->mask);
     53$page->param(postmask => $postnet->mask);
     54$page->param(prewildcard => scalar($prenet->wildcard));
     55$page->param(wildcard => scalar($net->wildcard));
     56$page->param(postwildcard => scalar($postnet->wildcard));
    4757
    48 print qq(<tr><td valign="top">\n).
    49         qq(     <div class="mask">).$prenet->mask."</div>\n".
    50         qq(     <div class="wildcard">).$prenet->wildcard."</div>\n".
    51         getranges($ltinput).
    52         qq(</td>\n<td valign="top" bgcolor="#d0e0e0">\n).
    53         qq(     <div class="mask">).$net->mask."</div>\n".
    54         qq(     <div class="wildcard">).$net->wildcard."</div>\n".
    55         getranges($input).
    56         qq(</td>\n<td valign="top">).
    57         qq(     <div class="mask">).$postnet->mask."</div>\n".
    58         qq(     <div class="wildcard">).$postnet->wildcard."</div>\n".
    59         getranges($gtinput);
     58my @prenets;
     59foreach (getranges($ltinput)) {
     60  my %row = (netrange => $_);
     61  push (@prenets, \%row);
     62}
     63$page->param(prenets => \@prenets);
     64my @nets;
     65foreach (getranges($input)) {
     66  my %row = (netrange => $_);
     67  push (@nets, \%row);
     68}
     69$page->param(nets => \@nets);
     70my @postnets;
     71foreach (getranges($gtinput)) {
     72  my %row = (netrange => $_);
     73  push @postnets, \%row;
     74}
     75$page->param(postnets => \@postnets);
    6076
    61 print "</td></tr>\n</table>\n";
    62 
    63 print qq(<input type="button" value="Back" onclick="history.go(-1)" class="heading">
    64 </div>
    65 </body>
    66 </html>
    67 );
     77print $page->output;
    6878       
    6979# Just In Case
     
    8898sub getranges {
    8999  my $masklen = shift;
    90   my $ret = '';
     100  my @ret;
    91101  my $super;
    92102  if ($masklen < 8) {
     
    100110  }
    101111  foreach my $net ($super->split($masklen)) {
    102     $ret .= "\t".xrange($net,$masklen)."<br />\n";
     112    push @ret, xrange($net,$masklen);
    103113  }
    104   return $ret;
     114  return @ret;
    105115} # getranges()
Note: See TracChangeset for help on using the changeset viewer.