Changeset 593 for branches/stable/cgi-bin/snCalc.cgi
- Timestamp:
- 05/14/13 18:10:22 (12 years ago)
- Location:
- branches/stable
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable
- Property svn:mergeinfo changed
/branches/htmlform (added) merged: 446-451,456-461,463-484,487-505,511-514,516 /trunk merged: 517
- Property svn:mergeinfo changed
-
branches/stable/cgi-bin/snCalc.cgi
r507 r593 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 use MyIPDB; 11 12 12 my %webvar = parse_post(); 13 # Set up the CGI object... 14 my $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) 20 my %webvar = $q->Vars; 21 13 22 my $input; 14 23 15 24 print "Content-Type: text/html\n\n"; 16 25 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 30 my $page = HTML::Template->new(filename => "templates/subnet-calc.tmpl"); 22 31 23 32 # Clean up input so we don't divide by zero or something equally silly … … 37 46 my $postnet = new NetAddr::IP "0.0.0.0/$gtinput"; 38 47 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)); 47 57 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); 58 my @prenets; 59 foreach (getranges($ltinput)) { 60 my %row = (netrange => $_); 61 push (@prenets, \%row); 62 } 63 $page->param(prenets => \@prenets); 64 my @nets; 65 foreach (getranges($input)) { 66 my %row = (netrange => $_); 67 push (@nets, \%row); 68 } 69 $page->param(nets => \@nets); 70 my @postnets; 71 foreach (getranges($gtinput)) { 72 my %row = (netrange => $_); 73 push @postnets, \%row; 74 } 75 $page->param(postnets => \@postnets); 60 76 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 ); 77 print $page->output; 68 78 69 79 # Just In Case … … 88 98 sub getranges { 89 99 my $masklen = shift; 90 my $ret = '';100 my @ret; 91 101 my $super; 92 102 if ($masklen < 8) { … … 100 110 } 101 111 foreach my $net ($super->split($masklen)) { 102 $ret .= "\t".xrange($net,$masklen)."<br />\n";112 push @ret, xrange($net,$masklen); 103 113 } 104 return $ret;114 return @ret; 105 115 } # getranges()
Note:
See TracChangeset
for help on using the changeset viewer.