cool has asked for the wisdom of the Perl Monks concerning the following question:

If one does not want to use '/var/www/cgi-bin' or '/../../html'dir to keep cgiscripts and html file and want to use 'home' dir instead of root (As my scripting is generating jpg files, for which i am facing problems in creating it in root's place). What are all changes one needs to do in '/etc/httpd/conf/http.conf' file to keep all my cgi scripts and html file in home dir with name cgi-bin and html respectively. And also while dealing with the security issues what precautions one can take with file permissions.
My programe generates data first after taking inputs from the user and from generated data it plots the graph in each iteration of code. This graph is jpg file and I am overwriting it each time while reading and sending to output html file each time. While in root area, I was not able to create images and other problems also persisted. Can you suggest something.
Eagerly waiting for your help... Enjoy posting

2006-04-11 Retitled by g0n, as per Monastery guidelines
Original title: 'Regarding CGI script location'

Replies are listed 'Best First'.
Re: (OT) Regarding CGI script location
by bowei_99 (Friar) on Apr 10, 2006 at 23:54 UTC
    Hm, it's not clear to me what exactly you're trying to do, and you don't provide too much specific, so there's only so much I can help with.

    Two things I might suggest:

    • Since your first question is not a perl question, but rather an apache (webserver) question, I'd suggest looking on google. I did a search for 'apache cgi howto', and came up with this. (the short answer is you need to set a ScriptAlias in httpd.conf; see the link for more info).
    • Check out the perlmonks Web Programming tutorial.

    -- Burvil

Re: (OT) Regarding CGI script location
by idle (Friar) on Apr 11, 2006 at 06:28 UTC
    There is a special directory /tmp - thats writeable by anyone. When apache itself need to create some files it uses /tmp, because its running as user nobody and can't write neither in root directories nor any home dir.
    And your scripts should act that way.
      thanx for giving me the clue, will try again and revert back to you for help :) good day!
Re: (OT) Regarding CGI script location
by jhourcle (Prior) on Apr 11, 2006 at 15:36 UTC

    Your question had two parts -- neither of which is particularly a Perl question, but the second one at least a programming question. (For the first part, you'll want to take a look at your webserver's documentation. For dealing with security, you might want to take a look at suExec for apache, or cgiwrap for any other server.

    Now -- for graphing -- I don't know exactly what you're trying to do, but overwriting the same file over and over again based on the input from the user just seems to be asking for trouble. If you have users A & B asking for the same page, but with different input, at almost the same time, it's possible that one of them will be given the wrong image. You also have to make sure to send the necessary cache-control headers in case the user tries revisiting the page with new parameters.

    Instead, I see two main options:

    1. Give each image a unique name. The problem is, you need a routine to periodically go through and clean up the older images, so you don't fill your disk.
    2. Generate the images as they are requested. Images don't need to be static files ... they can be generated from CGIs as well. So, as you take the parameters from the user, you can then pass the relevent ones onto the image generating CGI, either through the QUERY_STRING, or PATH_INFO:

      <img src='/cgi-bin/script?param=value;param2=value2' alt='whatever' height='x' width='y'>
    3. The whole page will take a little longer to load, as you don't start generating the image 'till the image is requested, rather than the page being requested, but I find it to be easier to maintain, as you don't need to worry about temp directories. If you're worried about other people making use of the image generating routine, you can add some sort of checksum to the parameters passed in, so it's less likely that someone will bypass the first page.

    Note -- I've made a possibly incorrect assumption that the images vary with the parameters passed in and some sort of internal state, and that each image generated is most likely to be unique, or at the very least repeat so infrequently as to be not worthwhile to cache. If this isn't the case, you'll need to provide more details about what you're trying to do.