15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
# This is an IVLE application.
23
# A sample / testing application for IVLE.
22
# Serves content to the user (acting as a web server for students files).
23
# For most file types we just serve the static file, but
24
# for python files, we evaluate the python script inside
25
# our safe execution environment.
25
27
from common import util
31
"""Handler for the Server application which serves pages.
32
For most file types we just serve the static file, but
33
for python files, we evaluate the python script inside
34
our safe execution environment."""
34
"""Handler for the Server application which serves pages."""
36
36
if req.path.endswith('.py'):
37
37
raise Exception, "executing python not done yet!"
39
39
# We're expecting paths are all of the form <usr>/...
40
parts = req.path.split('/')
40
parts = req.path.split(os.sep)
41
41
if len(parts) == 0:
42
42
raise Exception, "empty path!"
46
46
# The corresponding file on the filesystem
47
path = conf.root_dir + '/jails/' + user + '/home/' + req.path
47
path = os.path.join(conf.student_dir, usr, 'home', req.path)
50
50
(type, encoding) = mimetypes.guess_type(path)
53
53
type = 'text/plain'
55
55
# Set request attributes
56
56
req.content_type = type
57
if encoding is not None:
58
58
req.content_encoding = encoding
60
60
req.write_html_head_foot = False