3
# IVLE - Informatics Virtual Learning Environment
4
# Copyright (C) 2007-2008 The University of Melbourne
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
# Script: interpretservice
24
# A CGI script for interpreting files.
34
from common import (cgirequest, studpath)
36
req = cgirequest.CGIRequest()
37
req.install_error_handler()
39
# Work out the parts of the URL
40
url = urlparse.urlparse(req.path)
43
filename = studpath.url_to_jailpaths(urlpath)[2]
45
python = "/usr/bin/python"
48
req.throw_error(req.HTTP_NOT_FOUND, "The path specified is invalid.")
49
elif not os.access(filename, os.R_OK):
50
req.throw_error(req.HTTP_NOT_FOUND,
51
"The specified file (%s) does not exist." % urlpath)
53
if os.path.isdir(filename):
54
# 403 Forbidden error for visiting a directory
55
# (Not giving a directory listing, since this can be seen by
56
# the world at large. Directory contents are private).
57
req.throw_error(req.HTTP_FORBIDDEN,
58
"The path specified is a directory.")
60
# We'll save on a fork and execute in this python process
61
# Let exceptions blow up normally again
62
sys.excepthook = sys.__excepthook__
63
execfile(filename, {})
65
# Non-Python process should probably use something like
66
# subprocess.call([python, filename])