42
42
from ivle import util
44
44
from ivle.dispatch.request import Request
45
45
import ivle.webapp.security
46
46
from ivle.webapp.base.plugins import ViewPlugin, PublicViewPlugin
47
from ivle.webapp.base.xhtml import XHTMLView, XHTMLErrorView
48
from ivle.webapp.errors import HTTPError, Unauthorized, NotFound
50
config = ivle.config.Config()
52
def generate_router(view_plugins, attr):
47
from ivle.webapp.errors import HTTPError, Unauthorized
49
def generate_route_mapper(view_plugins, attr):
54
51
Build a Mapper object for doing URL matching using 'routes', based on the
55
52
given plugin registry.
84
81
if user and user.valid:
84
conf = ivle.config.Config()
88
req.mapper = generate_router(config.plugin_index[PublicViewPlugin],
88
req.mapper = generate_route_mapper(conf.plugin_index[PublicViewPlugin],
91
req.mapper = generate_router(config.plugin_index[ViewPlugin], 'urls')
91
req.mapper = generate_route_mapper(conf.plugin_index[ViewPlugin],
93
94
matchdict = req.mapper.match(req.uri)
94
95
if matchdict is not None:
129
except mod_python.apache.SERVER_RETURN:
130
# A mod_python-specific Apache error.
131
# XXX: We need to raise these because req.throw_error() uses them.
132
# Remove this after Google Code issue 117 is fixed.
134
130
except Exception, e:
135
131
# A non-HTTPError appeared. We have an unknown exception. Panic.
136
132
handle_unknown_exception(req, *sys.exc_info())
154
148
the IVLE request is created.
156
150
req.content_type = "text/html"
157
logfile = os.path.join(config['paths']['logs'], 'ivle_error.log')
151
logfile = os.path.join(ivle.conf.log_path, 'ivle_error.log')
160
# XXX: This remains here for ivle.interpret's IVLEErrors. Once we rewrite
161
# fileservice, req.status should always be 500 (ISE) here.
163
154
httpcode = exc_value.httpcode
164
155
req.status = httpcode
165
156
except AttributeError:
167
158
req.status = mod_python.apache.HTTP_INTERNAL_SERVER_ERROR
170
160
publicmode = req.publicmode
171
161
except AttributeError:
194
188
# misbehaves (which is currently very easy, if things aren't set up
196
190
# Write the traceback.
198
# We need to special-case IVLEJailError, as we can get another
191
# If this is a non-4xx IVLEError, get the message and httpcode and
192
# make the error message a bit nicer (but still include the
194
# We also need to special-case IVLEJailError, as we can get another
199
195
# almost-exception out of it.
197
codename, msg = None, None
200
199
if exc_type is util.IVLEJailError:
200
msg = exc_value.type_str + ": " + exc_value.message
201
201
tb = 'Exception information extracted from IVLEJailError:\n'
202
202
tb += urllib.unquote(exc_value.info)
205
codename, msg = req.get_http_codename(httpcode)
206
except AttributeError:
204
209
tb = ''.join(traceback.format_exception(exc_type, exc_value,
207
logging.error('\n' + tb)
212
logging.error('%s\n%s'%(str(msg), tb))
209
214
# Error messages are only displayed is the user is NOT a student,
210
215
# or if there has been a problem logging the error message
211
show_errors = (not publicmode) and ((login and req.user.admin) or logfail)
216
show_errors = (not publicmode) and ((login and \
217
str(role) != "student") or logfail)
212
218
req.write("""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
213
219
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
214
220
<html xmlns="http://www.w3.org/1999/xhtml">
215
221
<head><title>IVLE Internal Server Error</title></head>
217
<h1>IVLE Internal Server Error</h1>
223
<h1>IVLE Internal Server Error""")
225
if codename is not None and \
226
httpcode != mod_python.apache.HTTP_INTERNAL_SERVER_ERROR:
227
req.write(": %s" % cgi.escape(codename))
218
230
<p>An error has occured which is the fault of the IVLE developers or
222
req.write("Please report this issue to the server administrators, "
223
"along with the following information.")
225
req.write("Details have been logged for further examination.")
231
administrators. Details have been logged for further examination.</p>
235
req.write("<p>%s</p>\n" % cgi.escape(msg))
236
if httpcode is not None:
237
req.write("<p>(HTTP error code %d)</p>\n" % httpcode)
229
238
req.write("<h2>Debugging information</h2>")
230
240
req.write("<pre>\n%s\n</pre>\n"%cgi.escape(tb))
242
req.write("<p>Warning: Could not open error log.</p>\n"
243
%cgi.escape(logfile))
231
244
req.write("</body></html>")