Changeset 517 for trunk/cgi-bin/snCalc.cgi
- Timestamp:
- 10/18/12 16:53:10 (12 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to
/branches/htmlform merged eligible
-
Property svn:mergeinfo
set to
-
trunk/cgi-bin/snCalc.cgi
r371 r517 4 4 use warnings; 5 5 use CGI::Carp qw(fatalsToBrowser); 6 use CGI::Simple; 7 use HTML::Template; 6 8 use NetAddr::IP; 7 use CommonWeb qw(:ALL);;8 9 9 10 #file snCalc.cgi little subnet calculator app 10 11 11 my %webvar = parse_post(); 12 # Set up the CGI object... 13 my $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) 19 my %webvar = $q->Vars; 20 12 21 my $input; 13 22 14 23 print "Content-Type: text/html\n\n"; 15 24 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 29 my $page = HTML::Template->new(filename => "templates/subnet-calc.tmpl"); 20 30 21 31 # Clean up input so we don't divide by zero or something equally silly … … 35 45 my $postnet = new NetAddr::IP "0.0.0.0/$gtinput"; 36 46 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)); 45 56 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); 57 my @prenets; 58 foreach (getranges($ltinput)) { 59 my %row = (netrange => $_); 60 push (@prenets, \%row); 61 } 62 $page->param(prenets => \@prenets); 63 my @nets; 64 foreach (getranges($input)) { 65 my %row = (netrange => $_); 66 push (@nets, \%row); 67 } 68 $page->param(nets => \@nets); 69 my @postnets; 70 foreach (getranges($gtinput)) { 71 my %row = (netrange => $_); 72 push @postnets, \%row; 73 } 74 $page->param(postnets => \@postnets); 58 75 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 ); 76 print $page->output; 66 77 67 78 # Just In Case … … 86 97 sub getranges { 87 98 my $masklen = shift; 88 my $ret = '';99 my @ret; 89 100 my $super; 90 101 if ($masklen < 8) { … … 98 109 } 99 110 foreach my $net ($super->split($masklen)) { 100 $ret .= "\t".xrange($net,$masklen)."<br />\n";111 push @ret, xrange($net,$masklen); 101 112 } 102 return $ret;113 return @ret; 103 114 } # getranges()
Note:
See TracChangeset
for help on using the changeset viewer.