Forum OpenACS Development: Using Perl CGI

Collapse
Posted by Pietro Zuco on
Hi to all!

I'm trying to use a CGI program in Perl.

I configured the AOLServer as:

ns_section "ns/server/${server}/modules/nscgi"

ns_param Map "GET /cgi /usr/local/cgi"
ns_param Map "POST /cgi /usr/local/cgi"
ns_param Interps CGIinterps
ns_param .pl "/usr/bin/perl"
ns_section "ns/interps/CGIinterps"
ns_param .pl "/usr/bin/perl"

I tried to call the script from an HTML file as:
/cgi/foo.cgi

The error message is "File Not Found"

I tried to change the path in almost any combination but, nothing...

I need to use the CGI program for a HTML code from a SCORM course that is designed in that way.

Thank you in advance.

Pietro.

Collapse
2: Re: Using Perl CGI (response to 1)
Posted by Dave Bauer on
You map statements have to have the trailing slash on the URL like this

ns_param Map "GET /cgi/ /usr/local/cgi"
ns_param Map "POST /cgi/ /usr/local/cgi"

Make sure you are loading nscgi in

ns_section "ns/server/${servername}/modules"
ns_param nscgi ${bindir}/nscgi${ext}

as well.

Collapse
3: Re: Re: Using Perl CGI (response to 2)
Posted by Kika B on
I am also trying to solve what looks like the same as Pietro's problem. Trying to add a Perl script to the system:
- nscgi enabled as you mention
ns_param nscgi ${bindir}/nscgi${ext}
- GET and POST pointing to the script's location
- Perl extension mapped correctly

Still I get "Not Found". I wonder whether I need to map a different method (beyond GET and POST) when the CGI script is called directly through the URL and is not a result of a form, or specify the location through a different parameter?

Thanks,

Kika

Collapse
4: Re: Using Perl CGI (response to 1)
Posted by Dave Bauer on
Check this http://jongriffin.com/static/consultant/nscgi?

Important point that might apply "You must make sure that your cgi directories are group readable."

Notice that if there are subdirectories under the top cgi directory you map, each subdirectory must also be mapped. Jon's mapping of the cgi URL is wrong, you must have the trailing slash.

Collapse
5: Re: Using Perl CGI (response to 4)
Posted by Kika B on
Thanks Dave for the quick reply.

I did read Jon's page before. My permissions are 755 which should be good.

www.tcl.tk/man/aolserver3.0/con-ch3.htm#120876 mentions "A trailing slash on the URL is not allowed" - is this wrong too? They mention that a trailing slash on the directory is optional.

Can you confirm that setting GET and POST methods should be enough for accessing this CGI explicitely through the URL rather than a form, as Pietro (and I) are trying to do?

Thanks again,

Kika

Collapse
6: Re: Using Perl CGI (response to 5)
Posted by Kika B on
Dave -

I was trying modifying the config script in many ways, including trailing slashes on either URL or disk path, but the results are the same. It seems like the CGI mapping is ignored altogether and the directory under www is searched instead, so if I put a Perl script there it is found, but returned as a text file rathen then a CGI.

I would suspect the nscgi module is not loaded correctly. Where can I verify that?

I have in the script the following lines:

# CGI interface -- nscgi
#
ns_section "ns/server/${servername}/module/nscgi"
ns_param map "GET /cgi /usr/local/cgi/" ;# CGI script file dir (GET).
ns_param map "POST /cgi /usr/local/cgi/" ;# CGI script file dir (POST).
ns_param map "GET /calendar /web/mydir/www/calendar/" ;# CGI script file dir (GET).
ns_param map "POST /calendar /web/mydir/www/calendar/" ;# CGI script file dir (POST).
ns_param Interps CGIinterps

ns_section ns/interps/CGIInterps
ns_param .pl /usr/bin/perl

ns_section "ns/server/${servername}/modules"
ns_param nssock ${bindir}/nssock${ext}
ns_param nslog ${bindir}/nslog${ext}
ns_param nssha1 ${bindir}/nssha1${ext}
ns_param nscache ${bindir}/nscache${ext}
ns_param nscgi ${bindir}/nscgi${ext}

Any more insight here?

Thanks again,

Kika

Collapse
7: Re: Using Perl CGI (response to 1)
Posted by Dave Bauer on
Check the error log on startup

You must make sure that your cgi directories are group readable. You can easily check this by looking in your error log when the server starts. You should see something like:

[-main-] Notice: modload: loading '/home/nsadmin/bin/nscgi.so' [-main-] Notice: nscgi: GET /cgi-bin -> /home/mydir/cgi [-main-] Notice: nscgi: POST /cgi-bin -> /home/mydir/cgi [-main-] Notice: nscgi: GET /cgi-bin/cvsweb -> /home/mydir/cgi/cvsweb [-main-] Notice: nscgi: POST /cgi-bin/cvsweb -> /home/mydir/cgi/cvsweb [-main-] Notice: nscgi: GET /cgi-bin/cvsweb/icons -> /home/mydir/cgi/cvsweb/icons [-main-] Notice: nscgi: POST /cgi-bin/cvsweb/icons -> /home/mydir/cgi/cvsweb/icons

Collapse
8: Re: Re: Using Perl CGI (response to 7)
Posted by Kika B on
Hi Dave,

Sorry but I come back to this problem every Wednesday...

My directories are seemingly group readable (actually they are readable to all). Which log file (name and directory) are you referring to?

Thanks again, Kika

Collapse
9: Re: Using Perl CGI (response to 1)
Posted by Roger Williams on
Hello:

I have been trying to help out on Kika's system.

I know that the directories are group-readable, since I can see the log messages:

GET /cgi/ -> /usr/local/cgi

etc.

I have tried it with and without the trailing slash.

But all it ever seems to do is (no output).

I tried to turn on debug (referenced here: http://www.tcl.tk/man/aolserver3.0/con-ch3.htm#120876), but I could not see any debug output.

Can anyone point me anywhere else?

TIA.

Regards..

Collapse
10: Re: Using Perl CGI (response to 1)
Posted by Torben Brosten on
Collapse
11: Re: Using Perl CGI (response to 1)
Posted by Torben Brosten on
Oops. Posted too early.

In addition to group readable, you might want to try making the directory public readable and executable, for example:

service1# ls -dl sql-ledger
drwxrwxr-x 12 service1 web 1024 Aug 27 13:29 cgi
service1#

hth

Collapse
12: Re: Using Perl CGI (response to 1)
Posted by Dave Bauer on
Again. Check the server error log during startup to see if nscgi is loading. If not, first make sure nscgi is loading then try to figure out if the mappings are correct.

Somethign like this should show up in the error log. Default error log is located at /var/lib/aolserver/yourservice/log/error.log

Check the error log on startup

You must make sure that your cgi directories are group readable. You can easily check this by looking in your error log when the server starts. You should see something like:

[-main-] Notice: modload: loading '/home/nsadmin/bin/nscgi.so'
[-main-] Notice: nscgi: GET /cgi-bin -> /home/mydir/cgi
[-main-] Notice: nscgi: POST /cgi-bin -> /home/mydir/cgi
[-main-] Notice: nscgi: GET /cgi-bin/cvsweb -> /home/mydir/cgi/cvsweb
[-main-] Notice: nscgi: POST /cgi-bin/cvsweb -> /home/mydir/cgi/cvsweb
[-main-] Notice: nscgi: GET /cgi-bin/cvsweb/icons -> /home/mydir/cgi/cvsweb/icons
[-main-] Notice: nscgi: POST /cgi-bin/cvsweb/icons -> /home/mydir/cgi/cvsweb/icons

Collapse
13: Re: Using Perl CGI (response to 1)
Posted by Torben Brosten on
Given my comment about trying with public read permissions etc. above, I have re-tested permissions locally.

chmod -R 550 cgi

seems to be the minimum required permissions to read and execute. I'm running sql-ledger (a cgi program which writes within the directory), so locally the minimum required is:

chmod -R 770 cgi

I had left the permissions really loose from when I was trying to get nscgi to execute scripts instead of displaying them!

Public read/write is not necessary. Thanks Dave for suggesting (via irc) that I test them again.