1 # This file is part of Indico.
2 # Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).
4 # Indico is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3 of the
7 # License, or (at your option) any later version.
9 # Indico is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Indico; if not, see <http://www.gnu.org/licenses/>.
17 """Some pages for dealing with generic application errors
22 from xml
.sax
.saxutils
import quoteattr
24 from flask
import session
, request
26 import MaKaC
.webinterface
.urlHandlers
as urlHandlers
27 from MaKaC
.webinterface
.pages
.base
import WPDecorated
28 from MaKaC
.webinterface
.wcomponents
import WTemplated
29 from MaKaC
.webinterface
.pages
.main
import WPMainBase
30 from MaKaC
.i18n
import _
31 from indico
.core
.config
import Config
32 from indico
.util
.i18n
import i18nformat
33 from indico
.web
.util
import get_request_info
36 class WGenericError( WTemplated
):
38 def __init__( self
, rh
, showDetails
=False ):
40 self
._showDetails
= showDetails
44 vars = WTemplated
.getVars( self
)
45 ex
= sys
.exc_info()[1]
46 vars["msg"] = self
.htmlText( str( ex
) )
48 ty
, ex
, tb
= sys
.exc_info()
49 tracebackList
= traceback
.format_list( traceback
.extract_tb( tb
) )
50 rh
= self
._rh
.__class
__
51 url
= request
.url
.encode('utf-8')
53 for (k
,v
) in self
._rh
.getRequestParams().items():
54 if k
.strip() != "password":
55 params
.append("""%s = %s""" % (self
.htmlText(k
), self
.htmlText(v
)))
57 for k
, v
in request
.headers
.iteritems():
58 headers
.append("""%s: %s""" % (self
.htmlText(k
), self
.htmlText(v
)))
59 userHTML
= """-- none --"""
60 vars["userEmail"] = ""
61 av
= self
._rh
.getAW().getUser()
63 userHTML
= self
.htmlText( "%s <%s>"%( av
.getFullName(), av
.getEmail() ) )
64 vars["userEmail"] = quoteattr( av
.getEmail() )
65 vars["reportURL"] = quoteattr( str( urlHandlers
.UHErrorReporting
.getURL() ) )
67 show_details
= Config
.getInstance().getDebug()
70 show_details
= session
.user
and session
.user
.is_admin
72 # We are handling some error so we cannot know if accessing the session user works
73 # If it fails we simply don't show details...
77 <table class="errorDetailsBox">
79 <td>ERROR DETAILS</td>
85 <td nowrap align="right"><b>Exception type:</b></td>
89 <td nowrap align="right" valign="top"><b>Exception message:</b></td>
92 """%( self
.htmlText( str(ty
) ), self
.htmlText( str(ex
) ))
94 if hasattr(ex
, 'problematic_templates') and hasattr(ex
, 'template_tracebacks'):
95 for i
in range(len(ex
.problematic_templates
)):
98 <td nowrap align="right" valign="top"><b>Traceback for<br>%s.tpl:</b></td>
101 """%(ex
.problematic_templates
[i
], "<br>".join(ex
.template_tracebacks
[i
]))
105 <td valign="top" nowrap align="right"><b>Traceback:</b></td>
106 <td><pre>%s</pre></td>
109 <td nowrap align="right"><b>Request handler:</b></td>
113 <td nowrap align="right"><b>URL:</b></td>
117 <td nowrap align="right" valign="top"><b>Params:</b></td>
121 <td valign="top" nowrap align="right"><b>HTTP headers:</b></td>
122 <td><pre>%s</pre></td>
125 <td nowrap align="right"><b>Logged user:</b></td>
129 """%("\n".join( tracebackList
), rh
.__name
__, url
, "<br>".join(params
), \
130 "\n".join( headers
), userHTML
)
131 vars["errorDetails"] = details
132 vars["reportMsg"] = quoteattr(json
.dumps({'request_info': get_request_info(),
133 'traceback': traceback
.format_exc()}))
136 class WUnexpectedError( WGenericError
):
140 class WPGenericError( WPDecorated
):
142 def __init__( self
, rh
):
143 WPDecorated
.__init
__( self
, rh
)
146 def _getBody( self
, params
):
147 wc
= WGenericError( self
._rh
, params
.get("showDetails", False) )
150 class WPUnexpectedError( WPDecorated
):
152 def __init__( self
, rh
):
153 WPDecorated
. __init__( self
, rh
)
156 def _getBody( self
, params
):
157 wc
= WUnexpectedError( self
._rh
)
160 class WAccessError( WTemplated
):
162 def __init__( self
, rh
):
166 vars = WTemplated
.getVars( self
)
167 vars["area"]= i18nformat(""" _("Authorisation") - """)
168 vars["msg"] = _("The access to this page has been restricted by its owner and you are not authorised to view it")
169 if isinstance(self
._rh
._target
, list):
170 #only objects with Access Controler (e.g. we do not want to check this for RB reservertion target): Conferences, Contribs...
171 contactInfo
= [item
.getAccessController().getAnyContactInfo() for item
in self
._rh
._target
if hasattr(item
, 'getAccessController') ]
172 vars["contactInfo"] = ";".join(contactInfo
)
173 elif self
._rh
._target
is not None and hasattr(self
._rh
._target
, 'getAccessController'): #only objects with Access Controler (e.g. we do not want to check this for RB reservertion target): Conferences, Contribs...
174 vars["contactInfo"] = self
._rh
._target
.getAccessController().getAnyContactInfo()
176 vars["contactInfo"] = ""
179 class WAccessKeyError( WTemplated
):
181 def __init__( self
, rh
, msg
="" ):
186 from MaKaC
.conference
import Conference
,Material
, Resource
187 vars = WTemplated
.getVars( self
)
188 if isinstance(self
._rh
._target
,Conference
):
189 vars["type"] = "event"
190 vars["url"] = quoteattr( str( urlHandlers
.UHConfEnterAccessKey
.getURL(self
._rh
._target
) ) )
192 vars["type"] = "presentation"
193 vars["url"] = quoteattr( str( urlHandlers
.UHConfEnterAccessKey
.getURL(self
._rh
._target
.getConference()) ) )
194 vars["msg"] = self
._msg
198 class WPAccessError( WPDecorated
):
200 def __init__( self
, rh
):
201 WPDecorated
.__init
__( self
, rh
)
203 def _getBody( self
, params
):
204 wc
= WAccessError( self
._rh
)
208 class WPKeyAccessError( WPDecorated
):
210 def __init__( self
, rh
):
211 WPDecorated
.__init
__( self
, rh
)
213 def _getBody( self
, params
):
214 tgt
= self
._rh
._target
216 keys
= session
.get("accessKeys", {})
217 if tgt
.getUniqueId() in keys
:
218 msg
= i18nformat("""<font color=red> _("Bad access key")!</font>""")
221 wc
= WAccessKeyError( self
._rh
, msg
)
225 class WPLaTeXError(WPDecorated
):
227 def __init__(self
, rh
, error
):
228 WPDecorated
.__init
__(self
, rh
)
231 def _getBody( self
, params
):
232 wc
= WTemplated('LaTeXError')
233 conf
= self
._error
.params
['conf']
235 'report_id': self
._error
.report_id
,
236 'is_manager': conf
.canModify(self
._getAW
()),
237 'log': open(self
._error
.log_file
, 'r').read(),
238 'source_code': open(self
._error
.source_file
, 'r').read()
242 class WTimingError( WTemplated
):
244 def __init__( self
, rh
, msg
="" ):
249 vars = WTemplated
.getVars( self
)
250 vars["msg"] = self
._msg
251 vars["urlbase"] = Config
.getInstance().getBaseURL()
254 class WParentTimingError( WTimingError
):
257 class WEntryTimingError( WTimingError
):
260 class WPTimingError( WPDecorated
):
262 def __init__( self
, rh
, msg
="" ):
264 WPDecorated
. __init__( self
, rh
)
266 def _getBody( self
, params
):
267 wc
= WTimingError( self
._rh
, self
._msg
)
270 class WPParentTimingError( WPTimingError
):
272 def _getBody( self
, params
):
273 wc
= WParentTimingError( self
._rh
, self
._msg
)
276 class WPEntryTimingError( WPTimingError
):
278 def _getBody( self
, params
):
279 wc
= WEntryTimingError( self
._rh
, self
._msg
)
282 class WModificationError( WTemplated
):
284 def __init__( self
, rh
):
288 vars = WTemplated
.getVars( self
)
292 class WModificationKeyError( WTemplated
):
294 def __init__( self
, rh
, msg
="" ):
299 vars = WTemplated
.getVars( self
)
300 vars["msg"] = self
._msg
302 if hasattr(self
._rh
, "_redirectURL"):
303 redirectURL
= self
._rh
._redirectURL
304 vars["redirectURL"] = quoteattr(redirectURL
)
305 vars["url"] = quoteattr( str( urlHandlers
.UHConfEnterModifKey
.getURL(self
._rh
._target
) ) )
309 class WPModificationError( WPDecorated
):
311 def __init__( self
, rh
):
312 WPDecorated
.__init
__( self
, rh
)
314 def _getBody( self
, params
):
315 if hasattr(self
._rh
._target
, "getModifKey") and \
316 self
._rh
._target
.getModifKey() != "":
317 keys
= session
.get("modifKeys", {})
318 if keys
.get(self
._rh
._target
.getId()):
319 msg
= i18nformat("""<font color=red> _("Wrong modification key!")</font>""")
322 wc
= WModificationKeyError( self
._rh
, msg
)
324 wc
= WModificationError( self
._rh
)
328 class WReportError( WTemplated
):
330 def __init__( self
, dstMail
, msg
):
331 WTemplated
.__init
__(self
)
332 self
._dstMail
= dstMail
336 vars = WTemplated
.getVars( self
)
337 vars["postURL"] = quoteattr( str( urlHandlers
.UHErrorReporting
.getURL() ) )
338 vars["dstEmail"] = quoteattr( self
._dstMail
)
339 vars["reportMsg"] = quoteattr( self
._msg
)
343 class WPReportError( WPDecorated
):
345 def __init__( self
, rh
):
346 WPDecorated
.__init
__(self
, rh
)#, True)
348 def _getHTMLHeader(self
):
351 def _getHeader(self
):
354 def _getBody( self
, params
):
355 wc
= WReportError( params
["userEmail"], params
["msg"] )
356 return wc
.getHTML( params
)
358 def _getFooter( self
):
361 class WNoReportError( WTemplated
):
363 def __init__( self
, msg
):
367 vars = WTemplated
.getVars( self
)
368 vars["msg"] = self
._msg
372 class WPNoReportError( WPDecorated
):
374 def __init__( self
, rh
, msg
):
376 WPDecorated
. __init__( self
, rh
)
378 def _getHeader(self
):
381 def _getBody( self
, params
):
382 wc
= WNoReportError( self
._msg
)
383 return wc
.getHTML( params
)
385 class WReportErrorSummary( WTemplated
):
389 class WPReportErrorSummary( WPDecorated
):
391 def __init__( self
, rh
):
392 WPDecorated
. __init__( self
, rh
)
394 def _getHTMLHeader( self
):
397 def _getHeader( self
):
400 def _getBody( self
, params
):
401 wc
= WReportErrorSummary()
404 def _getFooter( self
):
407 class WFormValuesError( WTemplated
):
409 def __init__( self
, rh
, msg
="" ):
414 vars = WTemplated
.getVars( self
)
415 vars["msg"] = self
._msg
418 class WPFormValuesError( WPDecorated
):
420 def __init__( self
, rh
, msg
="" ):
422 WPDecorated
. __init__( self
, rh
)
424 def _getBody( self
, params
):
425 wc
= WFormValuesError( self
._rh
, self
._msg
)
429 class WPRestrictedHTML( WPDecorated
):
431 def __init__( self
, rh
, msg
="" ):
433 WPDecorated
. __init__( self
, rh
)
435 def _getBody( self
, params
):
436 wc
= WRestrictedHTML( self
._rh
, self
._msg
)
439 class WRestrictedHTML( WGenericError
):
441 def __init__( self
, rh
, msg
="" ):
446 vars = WGenericError
.getVars( self
)
447 vars["msg"] = self
._msg
450 class WPError404( WPMainBase
):
452 def __init__( self
, rh
, goBack
="" ):
453 WPMainBase
. __init__( self
, rh
)
454 self
._goBack
= goBack
456 def _getBody( self
, params
):
457 wc
= WError404( self
._rh
, self
._goBack
)
460 class WError404( WTemplated
):
462 def __init__( self
, rh
, goBack
="" ):
464 self
._goBack
= goBack
467 vars = WTemplated
.getVars( self
)
468 vars["goBack"] = self
._goBack