Lots of good advice, but I'm surprised no one mentioned avoiding the shell entirely by using the multi-argument forms of system() or exec() to call traceroute directly.
Put together with the above advice and some sugar, you get something like ...
#!/usr/bin/perl -wT $|++; use strict; use CGI qw( header start_html end_html param p ); print header, start_html( "RavenGate TraceRoute Results" ); if ( param('trace') and param('trace') =~ /^[-.0-9a-zA-Z]+$/ ) { print p( "Hello There- I am writing this from " . "scratch so please be patient. Thanks!" ), "<pre>"; system( "/usr/sbin/traceroute", param('trace') ); print "</pre>"; print p( "Oops, there was a problem running traceroute" ) if $?; } elsif ( param('trace') ) { print p( "Oops,", param('trace'), "contains illegal characters" ); } else { print p( "Oops, you forgot to give me a host to trace to." ); }
As for that one line that "doesn't work", you need to escape the pipe (ie, $value =~ s /\|/ /g;).
In reply to Re: CGI and Traceroute
by Kanji
in thread CGI and Traceroute
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |