34
33
from common import (cgirequest, studpath)
35
import conf.mimetypes, conf.app, conf.app.server
37
serveservice_path = "/opt/ivle/scripts/serveservice"
36
39
req = cgirequest.CGIRequest()
37
40
req.install_error_handler()
47
50
# Everything should be done from the home directory
48
51
os.chdir(os.path.join('/home', username))
53
(type, _) = mimetypes.guess_type(filename)
55
type = conf.mimetypes.default_mimetype
50
57
if filename is None:
51
58
req.throw_error(req.HTTP_NOT_FOUND, "The path specified is invalid.")
52
59
elif not os.access(filename, os.R_OK):
53
60
req.throw_error(req.HTTP_NOT_FOUND,
54
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])
56
if os.path.isdir(filename):
57
# 403 Forbidden error for visiting a directory
58
# (Not giving a directory listing, since this can be seen by
59
# the world at large. Directory contents are private).
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):
60
82
req.throw_error(req.HTTP_FORBIDDEN,
61
"The path specified is a directory.")
63
# We'll save on a fork and execute in this python process
64
# Let exceptions blow up normally again
65
sys.excepthook = sys.__excepthook__
66
execfile(filename, {})
68
# Non-Python process should probably use something like
69
# subprocess.call([python, filename])
83
"Files of this type are not allowed to be served.")
85
execfile(serveservice_path)