Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: System commands using CGI

by dsheroh (Prior)
on Dec 03, 2012 at 10:10 UTC ( #1006840=note: print w/replies, xml ) Need Help??

in reply to System commands using CGI

Aside from
use strict; use warnings;
the next major point for debugging problems in web-related code is to check your web server's error log to find the error message generated when things went wrong.

In this particular case, I expect that you'll find an "access denied" error indicating that the user the web server runs as (probably "nobody", "apache", "httpd", or "www-data", depending on your OS and distribution) doesn't have permission to create or append to /var/www/cgi-bin/new.txt. The reason it works when you run it from the command line is that you have permission to create and write to that file, but the web server doesn't, so it fails when run by the web server.

If my guess as to the cause is correct, then the solution is to first create that file from the command line, then give the web server user permission to write to it. Do not give the web server user write permission to the entire /var/www/cgi-bin/ directory, as that would open up huge security holes allowing anyone who compromised one of your cgi-bin scripts to then create their own new scripts (or replace existing ones) on your machine.

Or, better, tell us what you're actually trying to achieve and we can probably find a way to do it that doesn't require allowing the web server process to write directly to files in potentially-sensitive locations.

Replies are listed 'Best First'.
Re^2: System commands using CGI
by nikhilB (Initiate) on Dec 03, 2012 at 10:55 UTC
    Thanks all for the response. I am trying to run a the perl script from the browser. The perl script is supposed to run some system level commands and print on the webpage. I figured out that the changes needed in the httpd.conf file and I was able to run some simple commands like ls and who from the browser. However I am unable to run the commands which require the root access for example useradd. Any idea what I need to do to execute the commands which require the root access ? Thanks, Nikhil.

      As Anonymous Monk pointed out, this is a bad idea. In fact, that is precisely why you can't do it: web servers are specifically set up to prevent that sort of thing.

      What do you want to do, anyway?

      When's the last time you used duct tape on a duct? --Larry Wall

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1006840]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2018-05-27 20:32 GMT
Find Nodes?
    Voting Booth?