~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
34
import conf
413 by mattgiuca
fileservice: Accidentally forgot to add __init__.py. (So last commit was an
35
import fileservice_lib
421 by mattgiuca
apps/fileservice: Added code to call interpret on the trampoline version of
36
import common
37
import common.interpret
888 by wagrant
fileservice: Redirect to the user's home directory if no path is
38
import common.util
421 by mattgiuca
apps/fileservice: Added code to call interpret on the trampoline version of
39
40
# handle_with_trampoline controls the way in which fileservice_lib is invoked.
41
# If False, it will simply be called directly by this handler.
42
# If True, the request will get marshalled into a CGI environment and the
1072 by matt.giuca
Renamed scripts to services.
43
# trampoline will invoke services/fileservices within the user's jail
44
# (SetUID'd to them). This script will then wrap the CGI environment in a
45
# 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
46
# This is a lot of overhead but it's the only way to properly ensure we are
47
# acting "as" that user and therefore we don't run into permissions problems.
48
# If set to True, it will be a lot more efficient, but there will be
49
# 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.
50
HANDLE_WITH_TRAMPOLINE = True
421 by mattgiuca
apps/fileservice: Added code to call interpret on the trampoline version of
51
1072 by matt.giuca
Renamed scripts to services.
52
fileservice_path = "/opt/ivle/services/fileservice"   # Within jail
413 by mattgiuca
fileservice: Accidentally forgot to add __init__.py. (So last commit was an
53
54
def handle(req):
55
    """Handler for the File Services application."""
888 by wagrant
fileservice: Redirect to the user's home directory if no path is
56
    if len(req.path) == 0:
57
        # If no path specified, default to the user's home directory
58
        req.throw_redirect(common.util.make_path(os.path.join('fileservice',
59
                                                       req.user.login)))
421 by mattgiuca
apps/fileservice: Added code to call interpret on the trampoline version of
60
    if not HANDLE_WITH_TRAMPOLINE:
61
        fileservice_lib.handle(req)
62
    else:
63
        interp_object = common.interpret.interpreter_objects["cgi-python"]
506 by mattgiuca
dispatch.__init__, dispatch.request, cgirequest:
64
        user_jail_dir = os.path.join(conf.jail_base, req.user.login)
65
        common.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
66
            fileservice_path, interp_object, gentle=False)