CGI scripts on your homepage

CGI scripts on your homepage

Common Gateway Interface scripts are applications who are - just as HTML-documents - installed on the server. Generally they're used to process the input of forms or clickable maps but they can be engaged in a broad field of purposes, of which the author whishes the user to initiate them by means of the browser: The querying of a database, calculation of a value etc... CGI scripts can be written in for instance Perl, C, C++, the Unix Bourne Shell, the C Shell etc... You yourself can write them or you can copy them from others.

Gateway scripts are usually found on system level. The actual CGI scripts need to be placed in a specific directory by the user. They're processed by the specific servers. Do the following:

The script will be processed by means of a URL of the type:
http://users.UGent.be/~username/cgi-bin/script.cgi
The script has to be named with extension .pl or .cgi. If not, it won't be identified as such. Possible files must be writable/readable for yourself only.

At the use of scripts, you might bump in to this error:

Internal Server Error
Error: Malformed header from script.

First, run your script at the Unix-prompt before addressing it through a WWW-browser. This gives you an idea of the error. You can do this using the command

./scriptname 

General recommendations
s

  1. It is important the scripts contain a Content-type declaration
  2. The ^M which might be created because of not working on a unix platform can simply be removed by cat script | tr -d ^M > betterscript The ^M is created by sequentially typing Ctrl-V and Ctrl-M (on linux)
  3. As to permissions: all user folders- and files
    need to have the own username as user and as group the users group (not: www-data)
    This can be easily checked with ls -alR /users/u/username
    This can be changed with chown username:users /users/u/username -R
    (for the username this needs to be done by a System Administrator)
  4. Can only be writable by the owner = the user
    This can be easily checked with ls -alR /users/u/username
    This can be changed with chmod wo-w /users/u/username -R
  5. Please attach possibly working scripts when you contact the helpdesk.

Running the script form the Unix-prompt doesn't work:

Running the script from the Unix-prompt works but your browser returns an Internal Server Error. Possible causes can be:

Lots of people use CGI scripts (Common Gateway Interface) on their homepage (e.g. counters to register the number of visitors). Again, here a few links to pages which offer more info:

Beware, scripts of Matt's Script Archive contain a few security holes. Use the good alternatives on e.g. http://nms-cgi.sourceforge.net/