~azzar1/unity/add-show-desktop-key

413 by mattgiuca
fileservice: Accidentally forgot to add __init__.py. (So last commit was an
1
# IVLE
2
# Copyright (C) 2007-2008 The University of Melbourne
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18
# App: File Service (AJAX server)
19
# Author: Matt Giuca
20
# Date: 9/1/2008
21
22
# This application is a wrapper around the library module fileservice.
23
# It can be configured to either call the library directly (in which case it
24
# behaves just like a regular application), or run it through the trampoline
25
# as a CGI app.
26
27
# It receives file handling instructions as requests. Performs actions on the
28
# student's workspace, and returns directory listings in JSON.
29
30
# See the documentation in lib/fileservice for details.
31
421 by mattgiuca
apps/fileservice: Added code to call interpret on the trampoline version of
32
import os.path
33
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
34
import ivle.conf
35
import ivle.fileservice_lib
36
import ivle.interpret
37
import ivle.util
421 by mattgiuca
apps/fileservice: Added code to call interpret on the trampoline version of
38
39
# handle_with_trampoline controls the way in which fileservice_lib is invoked.
40
# If False, it will simply be called directly by this handler.
41
# If True, the request will get marshalled into a CGI environment and the
1072 by matt.giuca
Renamed scripts to services.
42
# trampoline will invoke services/fileservices within the user's jail
43
# (SetUID'd to them). This script will then wrap the CGI environment in a
44
# replica of the original environment and handle it that way.
421 by mattgiuca
apps/fileservice: Added code to call interpret on the trampoline version of
45
# This is a lot of overhead but it's the only way to properly ensure we are
46
# acting "as" that user and therefore we don't run into permissions problems.
47
# If set to True, it will be a lot more efficient, but there will be
48
# permissions issues unless all user's files are owned by the web server user.
435 by drtomc
setup.py: Fix a couple of jail config glitches.
49
HANDLE_WITH_TRAMPOLINE = True
421 by mattgiuca
apps/fileservice: Added code to call interpret on the trampoline version of
50
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
51
fileservice_path = os.path.join(ivle.conf.share_path, 'services/fileservice')
413 by mattgiuca
fileservice: Accidentally forgot to add __init__.py. (So last commit was an
52
53
def handle(req):
54
    """Handler for the File Services application."""
888 by wagrant
fileservice: Redirect to the user's home directory if no path is
55
    if len(req.path) == 0:
56
        # If no path specified, default to the user's home directory
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
57
        req.throw_redirect(ivle.util.make_path(os.path.join('fileservice',
888 by wagrant
fileservice: Redirect to the user's home directory if no path is
58
                                                       req.user.login)))
421 by mattgiuca
apps/fileservice: Added code to call interpret on the trampoline version of
59
    if not HANDLE_WITH_TRAMPOLINE:
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
60
        ivle.fileservice_lib.handle(req)
421 by mattgiuca
apps/fileservice: Added code to call interpret on the trampoline version of
61
    else:
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
62
        interp_object = ivle.interpret.interpreter_objects["cgi-python"]
63
        user_jail_dir = os.path.join(ivle.conf.jail_base, req.user.login)
64
        ivle.interpret.interpret_file(req, req.user.login, user_jail_dir,
843 by wagrant
Give interpret_file a gentle mode (on by default, to avoid change in
65
            fileservice_path, interp_object, gentle=False)