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
18
# App: File Service (AJAX server)
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
27
# It receives file handling instructions as requests. Performs actions on the
28
# student's workspace, and returns directory listings in JSON.
30
# See the documentation in lib/fileservice for details.
18
# Author: Matt Giuca, Will Grant
20
'''Service for accessing a jail's filesystem.
22
This application is a wrapper around the library module fileservice, running
23
it through trampoline.
25
It receives file handling instructions as requests, performs actions on the
26
student's workspace, and returns directory listings in JSON.
28
See the documentation in ivle.fileservice_lib for details.
35
import ivle.fileservice_lib
36
34
import ivle.interpret
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
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.
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.
49
HANDLE_WITH_TRAMPOLINE = True
36
from ivle.webapp.base.views import BaseView
37
from ivle.webapp.base.plugins import ViewPlugin
51
39
fileservice_path = os.path.join(ivle.conf.share_path, 'services/fileservice')
54
"""Handler for the File Services application."""
55
if len(req.path) == 0:
56
# If no path specified, default to the user's home directory
57
req.throw_redirect(ivle.util.make_path(os.path.join('fileservice',
59
if not HANDLE_WITH_TRAMPOLINE:
60
ivle.fileservice_lib.handle(req)
41
# XXX: Writes to req directly. This is a direct port of the legacy version.
42
# This needs to be rewritten soon.
44
class FileserviceView(BaseView):
45
def __init__(self, req, path):
46
# XXX: Still depends on req.path internally.
49
def authorize(self, req):
50
return req.user is not None
52
def render(self, req):
53
"""Handler for the File Services application."""
54
if len(self.path) == 0:
55
# If no path specified, default to the user's home directory
56
req.throw_redirect(ivle.util.make_path(os.path.join('fileservice',
62
59
interp_object = ivle.interpret.interpreter_objects["cgi-python"]
63
60
user_jail_dir = os.path.join(ivle.conf.jail_base, req.user.login)
64
61
ivle.interpret.interpret_file(req, req.user, user_jail_dir,
65
62
fileservice_path, interp_object, gentle=False)
64
class Plugin(ViewPlugin):
66
('fileservice/*path', FileserviceView),
67
('fileservice', FileserviceView, {'path': ''}),