An Intro to
Programming
with Python

Fall 2006
course
navigation

nov 29

cgi scripts

$ ssh mahoney@cs.marlboro.edu passwd: **** $ cd html/cgi/python $ ls -al drwxr-sr-x 2 mahoney mahoney 4096 2006-11-28 18:28 . drwxr-sr-x 5 mahoney mahoney 4096 2006-11-28 18:25 .. -rwxr-xr-x 1 mahoney mahoney 138 2006-11-28 18:28 test.cgi
I'm running cgi scripts as 'setuid', which means in your directory they run as your user, not apache. However, apache is finicky about permissions when things are set up this way. In particular, the directory and file must not be writeable by others.
Explain how this works on unix systems, chmod, and all that.
On cs,
* must be in your html/cgi/ directory (or below) * must end in .cgi * must be executable (chmod +x filename) * must have ok directory and file permissions (see above) * can only be accessed on campus (security); ask if you need more
When things go wrong:
$ tail /var/www/cs/logs/suexec_log # or $ tail /var/www/cs/logs/error_log
Remember that you can see the source with file.cgi_html on cs.

debugging

import cgitb; cgitb.enable()
This shows errors in the browser window. Turn this off (by commenting it out) once everything is working.

examples

images on the fly

Mention URL encoding
Discuss common HTML tags if time allows.
http://cs.marlboro.edu/ courses/ fall2006/python/ notes/ nov_29
last modified Tuesday November 28 2006 7:29 pm EST