2
# Copyright (C) 2007-2008 The University of Melbourne
1
# IVLE - Informatics Virtual Learning Environment
2
# Copyright (C) 2007-2009 The University of Melbourne
4
4
# This program is free software; you can redistribute it and/or modify
5
5
# it under the terms of the GNU General Public License as published by
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 a mod_python handler program. The correct way to call it is to have
23
# Apache send all requests to be handled by the module 'dispatch'.
25
# Top-level handler. Handles all requests to all pages in IVLE.
26
# Handles authentication (not authorization).
27
# Then passes the request along to the appropriate ivle app.
18
# Author: Matt Giuca, Will Grant
21
This is a mod_python handler program. The correct way to call it is to have
22
Apache send all requests to be handled by the module 'dispatch'.
24
Top-level handler. Handles all requests to all pages in IVLE.
25
Handles authentication (not authorization).
26
Then passes the request along to the appropriate ivle app.
48
49
from request import Request
49
50
import plugins.console # XXX: Relies on www/ being in the Python path.
52
# XXX List of plugins, which will eventually be read in from conf
53
# Elements are (module, classname) pairs.
55
('ivle.webapp.admin.user', 'Plugin'),
58
def get_routes_mapper():
60
Build a Mapper object for doing URL matching using 'routes', based on the
64
for plugin_path, classname in plugins_HACK:
65
# Load the plugin module from somewhere in the Python path
66
# (Note that plugin_path is a fully-qualified Python module name).
67
plugin = getattr(__import__(plugin_path, fromlist=[classname]),
69
# Establish a URL pattern for each element of plugin.urls
70
for url in plugin.urls:
73
kwargs_dict = url[2] if len(url) >= 3 else {}
74
m.connect(routex, view=view_class, **kwargs_dict)
52
78
"""Handles a request which may be to anywhere in the site except media.
53
79
Intended to be called by mod_python, as a handler.
88
114
if not req.publicmode:
89
115
req.user = login.get_user_details(req)
117
### BEGIN New plugins framework ###
118
# XXX This should be done ONCE per Python process, not per request.
120
# XXX No authentication is done here
121
mapper = get_routes_mapper()
122
matchdict = mapper.match(req.uri)
123
if matchdict is not None:
124
viewcls = matchdict['view']
125
# Get the remaining arguments, less 'view', 'action' and 'controller'
126
# (The latter two seem to be built-in, and we don't want them).
127
kwargs = matchdict.copy()
130
del kwargs['controller']
131
# Instantiate the view, which should be a BaseView class
132
view = viewcls(req, **kwargs)
137
### END New plugins framework ###
91
139
# Check req.app to see if it is valid. 404 if not.
92
140
if req.app is not None and req.app not in ivle.conf.apps.app_url:
93
141
req.throw_error(Request.HTTP_NOT_FOUND,
293
349
logging.error('%s\n%s'%(str(msg), tb))
350
# Error messages are only displayed is the user is NOT a student,
351
# or if there has been a problem logging the error message
352
show_errors = (not publicmode) and ((login and \
353
str(role) != "student") or logfail)
295
354
req.write("""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
296
355
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
297
356
<html xmlns="http://www.w3.org/1999/xhtml">
298
357
<head><title>IVLE Internal Server Error</title></head>
300
359
<h1>IVLE Internal Server Error""")
301
if (codename is not None
302
and httpcode != apache.HTTP_INTERNAL_SERVER_ERROR):
303
req.write(": %s" % cgi.escape(codename))
361
if (codename is not None
362
and httpcode != apache.HTTP_INTERNAL_SERVER_ERROR):
363
req.write(": %s" % cgi.escape(codename))
304
365
req.write("""</h1>
305
366
<p>An error has occured which is the fault of the IVLE developers or
367
administration. The developers have been notified.</p>
309
req.write("<p>%s</p>\n" % cgi.escape(msg))
310
if httpcode is not None:
311
req.write("<p>(HTTP error code %d)</p>\n" % httpcode)
313
<p>Please report this to <a href="mailto:%s">%s</a> (the system
314
administrator). Include the following information:</p>
315
""" % (cgi.escape(admin_email), cgi.escape(admin_email)))
371
req.write("<p>%s</p>\n" % cgi.escape(msg))
372
if httpcode is not None:
373
req.write("<p>(HTTP error code %d)</p>\n" % httpcode)
375
<p>Please report this to <a href="mailto:%s">%s</a> (the system
376
administrator). Include the following information:</p>
377
""" % (cgi.escape(admin_email), cgi.escape(admin_email)))
317
req.write("<pre>\n%s\n</pre>\n"%cgi.escape(tb))
319
req.write("<p>Warning: Could not open Error Log: '%s'</p>\n"
320
%cgi.escape(logfile))
379
req.write("<pre>\n%s\n</pre>\n"%cgi.escape(tb))
381
req.write("<p>Warning: Could not open Error Log: '%s'</p>\n"
382
%cgi.escape(logfile))
321
383
req.write("</body></html>")