Skip to content

Commit 8820d6d

Browse files
committed
Only feed back traceback to web users if config.WEB_DEBUG is True
1 parent 472a429 commit 8820d6d

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

roundup/cgi/client.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
# $Id: client.py,v 1.239 2008-08-18 05:04:02 richard Exp $
2-
31
"""WWW request handler (also used in the stand-alone server).
42
"""
53
__docformat__ = 'restructuredtext'
64

75
import base64, binascii, cgi, codecs, mimetypes, os
8-
import random, re, rfc822, stat, time, urllib, urlparse
6+
import quopri random, re, rfc822, stat, sys, time, urllib, urlparse
97
import Cookie, socket, errno
108
from Cookie import CookieError, BaseCookie, SimpleCookie
9+
from cStringIO import StringIO
1110

1211
from roundup import roundupdb, date, hyperdb, password
1312
from roundup.cgi import templating, cgitb, TranslationService
@@ -927,7 +926,30 @@ def renderContext(self):
927926
raise Unauthorised, str(message)
928927
except:
929928
# everything else
930-
return cgitb.pt_html(i18n=self.translator)
929+
if self.instance.config.WEB_DEBUG:
930+
return cgitb.pt_html(i18n=self.translator)
931+
exc_info = sys.exc_info()
932+
try:
933+
# If possible, send the HTML page template traceback
934+
# to the administrator.
935+
to = [self.mailer.config.ADMIN_EMAIL]
936+
subject = "Templating Error: %s" % exc_info[1]
937+
content = cgitb.pt_html()
938+
message, writer = self.mailer.get_standard_message(
939+
to, subject)
940+
writer.addheader('Content-Transfer-Encoding', 'quoted-printable')
941+
body = writer.startbody('text/html; charset=utf-8')
942+
content = StringIO(content)
943+
quopri.encode(content, body, 0)
944+
self.mailer.smtp_send(to, message)
945+
# Now report the error to the user.
946+
return self._(error_message)
947+
except:
948+
# Reraise the original exception. The user will
949+
# receive an error message, and the adminstrator will
950+
# receive a traceback, albeit with less information
951+
# than the one we tried to generate above.
952+
raise exc_info[0], exc_info[1], exc_info[2]
931953

932954
# these are the actions that are available
933955
actions = (

0 commit comments

Comments
 (0)