[lug] Apache CGI: ExecCGI for Just One File?

Jack Rosenthal jack at rosenth.al
Sun Apr 21 13:51:38 MDT 2019


I vaguely recall doing something like this a while ago as a hack. There
may be a better way, but IIRC this worked for what I needed:

Make a file in your cgi-bin like default-index-handler.cgi... for
example I wrote mine in bash:

    #!/bin/bash

    # FIXME: handle security cases
    # (what happens if .. in REQUEST_URI)?
    INDEX_SCRIPT="${DOCUMENT_ROOT}/${REQUEST_URI}/index.cgi"

    # does an index.cgi exist and executable?
    if [[ -x "${INDEX_SCRIPT}" ]]; then
        exec "${INDEX_SCRIPT}"
    else
        echo "Content-Type: text/html"
        echo
        echo "<H1>No index file exists</H1>"
    fi

Then you'll need to set DirectoryIndex to have your custom handler at
the end:

    DirectoryIndex index.html index.htm ... /cgi-bin/default-index-handler.cgi

And maybe it'll just work. I think this approach is really hacky, and
you'll need to fix the FIXME above, but this is a rough outline of an
approach.

You may think this is a little bit out of style, so if there's a better
way to do this, please someone else chime in. Then again, CGI scripting
went out of style a few years ago too... =)

Jack

-- 
Jack M. Rosenthal
http://jack.rosenth.al

You can rent this space for only $5/week.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20190421/1353e9e9/attachment.sig>


More information about the LUG mailing list