# Runs a command under -T captures output ############################################################################## sub run_cmd_safely{ my ($cmd) = @_; my ($DEBUG) = 0; #$DEBUG = 1 if ($cmd =~ /nexsat/i); if ($DEBUG == 1){ use CGI; my $query = new CGI; print $query->header; } print "

Initially command = $cmd\n" if ($DEBUG == 1); # Need to untaint and run in a restricted environment { $cmd =~ /([\~\*\w\_\-\%\+\/\.\,\!\s\"\'\|\\\>\<\&]+)/; $cmd = $1; } print "

After untaint cmd = $cmd\n" if ($DEBUG == 1); my ($ORIG_PATH) = $ENV{'PATH'}; $ENV{'PATH'} = "/bin:/usr/bin:/usr/local/bin"; my (@RESULTS); # Remove any trailing | $cmd =~ s/\|\s*$//; print "

Really Running $cmd\n

" if ($DEBUG == 1); open(CMD,"$cmd 2>&1 |") || return ($!); print "Successfully opened $cmd\n" if ($DEBUG == 1); while(){ chomp($_); next if ($_ =~ /sh /); next if ($_ =~ /grep /); print "
Pushing $_\n" if ($DEBUG == 1); push (@RESULTS,$_) if ($_ =~ /\w+/); } close (CMD); $ENV{'PATH'} = $ORIG_PATH; return (\@RESULTS); } ############################################################