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.
33
from common import (cgirequest, studpath)
35
import conf.mimetypes, conf.app, conf.app.server
37
serveservice_path = "/opt/ivle/scripts/serveservice"
39
req = cgirequest.CGIRequest()
40
req.install_error_handler()
42
# Work out the parts of the URL
43
url = urlparse.urlparse(req.path)
46
username, _, filename = studpath.url_to_jailpaths(urlpath)
48
python = "/usr/bin/python"
50
# Everything should be done from the home directory
51
os.chdir(os.path.join('/home', username))
53
(type, _) = mimetypes.guess_type(filename)
55
type = conf.mimetypes.default_mimetype
58
req.throw_error(req.HTTP_NOT_FOUND, "The path specified is invalid.")
59
elif not os.access(filename, os.R_OK):
60
req.throw_error(req.HTTP_NOT_FOUND,
61
"The specified file (%s) does not exist." % urlpath)
62
elif os.path.isdir(filename):
63
# 403 Forbidden error for visiting a directory
64
# (Not giving a directory listing, since this can be seen by
65
# the world at large. Directory contents are private).
66
req.throw_error(req.HTTP_FORBIDDEN,
67
"The path specified is a directory.")
68
elif type in conf.app.server.interpreters:
69
# We'll save on a fork and execute in this python process
70
# Let exceptions blow up normally again
71
sys.excepthook = sys.__excepthook__
72
execfile(filename, {})
73
# Non-Python process should probably use something like
74
# subprocess.call([python, filename])
76
# Otherwise, use the blacklist/whitelist to see if this file should be
77
# served or disallowed
78
if (conf.app.server.blacklist_served_filetypes and \
79
type in conf.app.server.served_filetypes_blacklist) or \
80
(conf.app.server.served_filetypes_whitelist and \
81
type not in conf.app.server.served_filetypes_whitelist):
82
req.throw_error(req.HTTP_FORBIDDEN,
83
"Files of this type are not allowed to be served.")
85
execfile(serveservice_path)