[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.3

upload file and run bash application on file

Asked by awesomefennis in CGI Scripting, Perl Programming Language, Apache Web Server

Tags: Perl CGI apache web server on Ubuntu

Hello,

I have an apache web server (on Ubuntu) that is running perl, and i would like to do the following. I would like an upload file functionality on the site, which once a user has uploaded a file to the webserver, an bash shell application is launched once the file is uploaded and the bash shell responses are displayed in the browser.

So I have the upload functionality upload.cgi, at the end of which I have put a command:
`progname -f /var/www/$filename -t /path to other folder/`;

Is it ok to run the bash command simply using ` `, or do i need to use the system() command?
I am assuming this will run progname in the background using the newly uploaded $filename, as if i had typed it in as bash shell .

I would like to display the responses of the bash shell in the browser.

Is this possible? How would it be done?

I have included the full code of upload.cgi below.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
#!/usr/bin/perl -w
 
use strict;
use CGI;
use CGI::Carp qw ( fatalsToBrowser );
use File::Basename;
 
$CGI::POST_MAX = 1024 * 5000;
my $safe_filename_characters = "a-zA-Z0-9_.-";
my $upload_dir = "/var/www/";
 
my $query = new CGI;
my $filename = $query->param("photo");
 
if ( !$filename )
{
 print $query->header ( );
 print "There was a problem uploading your photo (try a smaller file).";
 exit;
}
 
my ( $name, $path, $extension ) = fileparse ( $filename, '\..*' );
$filename = $name . $extension;
$filename =~ tr/ /_/;
$filename =~ s/[^$safe_filename_characters]//g;
 
if ( $filename =~ /^([$safe_filename_characters]+)$/ )
{
 $filename = $1;
}
else
{
 die "Filename contains invalid characters";
}
 
my $upload_filehandle = $query->upload("photo");
 
open ( UPLOADFILE, ">$upload_dir/$filename" ) or die "$!";
binmode UPLOADFILE;
 
while ( <$upload_filehandle> )
{
 print UPLOADFILE;
}
 
close UPLOADFILE;
 
 
`progname -f /var/www/$filename -t /path to other folder/`;
 
 
print $query->header ( );
print <<END_HTML;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <title>Thanks!</title>
   <style type="text/css">
     img {border: none;}
   </style>
 </head>
 <body>
   <p>Thanks for uploading your file!</p>
 </body>
</html>
END_HTML
 
Related Solutions
Keywords: upload file and run bash application on …
 
Loading Advertisement...
 
[+][-]10/25/09 08:14 AM, ID: 25656859Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: CGI Scripting, Perl Programming Language, Apache Web Server
Tags: Perl CGI apache web server on Ubuntu
Sign Up Now!
Solution Provided By: David_Botham
Participating Experts: 1
Solution Grade: A
 
[+][-]10/25/09 08:18 AM, ID: 25656878Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89 - Hierarchy / EE_QW_3_20080625