Changeset 499


Ignore:
Timestamp:
09/23/11 13:00:51 (12 years ago)
Author:
Kris Deugau
Message:

/branches/htmlform

Convert subnet calculator to HTML::Template, clean up output
to validate and rely more on CSS
See #3.

Location:
branches/htmlform
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • branches/htmlform/cgi-bin/snCalc.cgi

    r447 r499  
    55use CGI::Carp qw(fatalsToBrowser);
    66use CGI::Simple;
     7use HTML::Template;
    78use NetAddr::IP;
    89use CommonWeb qw(:ALL);;
     
    2324print "Content-Type: text/html\n\n";
    2425
    25 open(HTML, "../startsn.html")|| die "Could not open startsn.html :$!";
    26 my $start = join('', <HTML>);
    27 close(HTML);
    28 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");
    2931
    3032# Clean up input so we don't divide by zero or something equally silly
     
    4446my $postnet = new NetAddr::IP "0.0.0.0/$gtinput";
    4547
    46 print qq(<div class="center">
    47 <table align="center" cellspacing="3" cellpadding="3">
    48 <tr>
    49         <td class="heading" align="center">Results for /$ltinput</td>
    50         <td class="heading" align="center">Results for /$input</td>
    51         <td class="heading" align="center">Results for /$gtinput</td>
    52 </tr>
    53 );
     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));
    5457
    55 print qq(<tr><td valign="top">\n).
    56         qq(     <div class="mask">).$prenet->mask."</div>\n".
    57         qq(     <div class="wildcard">).$prenet->wildcard."</div>\n".
    58         getranges($ltinput).
    59         qq(</td>\n<td valign="top" bgcolor="#d0e0e0">\n).
    60         qq(     <div class="mask">).$net->mask."</div>\n".
    61         qq(     <div class="wildcard">).$net->wildcard."</div>\n".
    62         getranges($input).
    63         qq(</td>\n<td valign="top">).
    64         qq(     <div class="mask">).$postnet->mask."</div>\n".
    65         qq(     <div class="wildcard">).$postnet->wildcard."</div>\n".
    66         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);
    6776
    68 print "</td></tr>\n</table>\n";
    69 
    70 print qq(<input type="button" value="Back" onclick="history.go(-1)" class="heading">
    71 </div>
    72 </body>
    73 </html>
    74 );
     77print $page->output;
    7578       
    7679# Just In Case
     
    9598sub getranges {
    9699  my $masklen = shift;
    97   my $ret = '';
     100  my @ret;
    98101  my $super;
    99102  if ($masklen < 8) {
     
    107110  }
    108111  foreach my $net ($super->split($masklen)) {
    109     $ret .= "\t".xrange($net,$masklen)."<br />\n";
     112    push @ret, xrange($net,$masklen);
    110113  }
    111   return $ret;
     114  return @ret;
    112115} # getranges()
  • branches/htmlform/ipdb.css

    r469 r499  
    169169}
    170170
     171.ljust {
     172        text-align: left;
     173}
     174.topalign {
     175        vertical-align: top;
     176}
     177
    171178.small {
    172179        font-size: 60%;
     
    198205        background: #ffff00;
    199206}
     207
     208.altbg {
     209        background: #d0e0e0;
     210}
Note: See TracChangeset for help on using the changeset viewer.