mirror of
https://github.com/moparisthebest/SickRage
synced 2025-01-05 10:58:01 -05:00
Added in better error handling for tornado web server.
Fixed HTTPS issues, web root issues should now be corrected as well.
This commit is contained in:
parent
93e2e93b63
commit
f7502294c5
@ -144,7 +144,6 @@ class HTTPRedirect(Exception):
|
|||||||
def redirect(url, permanent=False, status=None):
|
def redirect(url, permanent=False, status=None):
|
||||||
raise HTTPRedirect(url, permanent, status)
|
raise HTTPRedirect(url, permanent, status)
|
||||||
|
|
||||||
|
|
||||||
@authenticated
|
@authenticated
|
||||||
class MainHandler(RequestHandler):
|
class MainHandler(RequestHandler):
|
||||||
def http_error_401_handler(self):
|
def http_error_401_handler(self):
|
||||||
@ -165,10 +164,27 @@ class MainHandler(RequestHandler):
|
|||||||
if status_code == 401:
|
if status_code == 401:
|
||||||
self.finish(self.http_error_401_handler())
|
self.finish(self.http_error_401_handler())
|
||||||
elif status_code == 404:
|
elif status_code == 404:
|
||||||
redirect('/home/')
|
self.redirect(urlparse.urljoin(sickbeard.WEB_ROOT, '/home/'))
|
||||||
else:
|
elif self.settings.get("debug") and "exc_info" in kwargs:
|
||||||
logger.log(traceback.format_exc(), logger.DEBUG)
|
exc_info = kwargs["exc_info"]
|
||||||
super(MainHandler, self).write_error(status_code, **kwargs)
|
trace_info = ''.join(["%s<br/>" % line for line in traceback.format_exception(*exc_info)])
|
||||||
|
request_info = ''.join(["<strong>%s</strong>: %s<br/>" % (k, self.request.__dict__[k] ) for k in
|
||||||
|
self.request.__dict__.keys()])
|
||||||
|
error = exc_info[1]
|
||||||
|
|
||||||
|
self.set_header('Content-Type', 'text/html')
|
||||||
|
self.finish("""<html>
|
||||||
|
<title>%s</title>
|
||||||
|
<body>
|
||||||
|
<h2>Error</h2>
|
||||||
|
<p>%s</p>
|
||||||
|
<h2>Traceback</h2>
|
||||||
|
<p>%s</p>
|
||||||
|
<h2>Request Info</h2>
|
||||||
|
<p>%s</p>
|
||||||
|
</body>
|
||||||
|
</html>""" % (error, error,
|
||||||
|
trace_info, request_info))
|
||||||
|
|
||||||
def _dispatch(self):
|
def _dispatch(self):
|
||||||
|
|
||||||
@ -212,7 +228,7 @@ class MainHandler(RequestHandler):
|
|||||||
elif not func:
|
elif not func:
|
||||||
func = getattr(klass, 'index', None)
|
func = getattr(klass, 'index', None)
|
||||||
|
|
||||||
if func:
|
if callable(func):
|
||||||
return func(**args)
|
return func(**args)
|
||||||
|
|
||||||
raise HTTPError(404)
|
raise HTTPError(404)
|
||||||
@ -220,14 +236,14 @@ class MainHandler(RequestHandler):
|
|||||||
def get(self, *args, **kwargs):
|
def get(self, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
self.finish(self._dispatch())
|
self.finish(self._dispatch())
|
||||||
except HTTPRedirect, inst:
|
except HTTPRedirect, e:
|
||||||
self.redirect(inst.url, inst.permanent, inst.status)
|
self.redirect(e.url, e.permanent, e.status)
|
||||||
|
|
||||||
def post(self, *args, **kwargs):
|
def post(self, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
self.finish(self._dispatch())
|
self.finish(self._dispatch())
|
||||||
except HTTPRedirect, inst:
|
except HTTPRedirect, e:
|
||||||
self.redirect(inst.url, inst.permanent, inst.status)
|
self.redirect(e.url, e.permanent, e.status)
|
||||||
|
|
||||||
def robots_txt(self, *args, **kwargs):
|
def robots_txt(self, *args, **kwargs):
|
||||||
""" Keep web crawlers out """
|
""" Keep web crawlers out """
|
||||||
|
@ -35,7 +35,7 @@ class MultiStaticFileHandler(StaticFileHandler):
|
|||||||
raise HTTPError(404)
|
raise HTTPError(404)
|
||||||
|
|
||||||
class SRWebServer(threading.Thread):
|
class SRWebServer(threading.Thread):
|
||||||
def __init__(self, options=[], io_loop=None):
|
def __init__(self, options={}, io_loop=None):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
self.daemon = True
|
self.daemon = True
|
||||||
self.alive = True
|
self.alive = True
|
||||||
@ -63,12 +63,12 @@ class SRWebServer(threading.Thread):
|
|||||||
if not create_https_certificates(self.https_cert, self.https_key):
|
if not create_https_certificates(self.https_cert, self.https_key):
|
||||||
logger.log(u"Unable to create CERT/KEY files, disabling HTTPS")
|
logger.log(u"Unable to create CERT/KEY files, disabling HTTPS")
|
||||||
sickbeard.ENABLE_HTTPS = False
|
sickbeard.ENABLE_HTTPS = False
|
||||||
enable_https = False
|
self.enable_https = False
|
||||||
|
|
||||||
if not (os.path.exists(self.https_cert) and os.path.exists(self.https_key)):
|
if not (os.path.exists(self.https_cert) and os.path.exists(self.https_key)):
|
||||||
logger.log(u"Disabled HTTPS because of missing CERT and KEY files", logger.WARNING)
|
logger.log(u"Disabled HTTPS because of missing CERT and KEY files", logger.WARNING)
|
||||||
sickbeard.ENABLE_HTTPS = False
|
sickbeard.ENABLE_HTTPS = False
|
||||||
enable_https = False
|
self.enable_https = False
|
||||||
|
|
||||||
# Load the app
|
# Load the app
|
||||||
self.app = Application([],
|
self.app = Application([],
|
||||||
@ -87,7 +87,7 @@ class SRWebServer(threading.Thread):
|
|||||||
|
|
||||||
# Static Path Handler
|
# Static Path Handler
|
||||||
self.app.add_handlers(".*$", [
|
self.app.add_handlers(".*$", [
|
||||||
(r'%s/(favicon\.ico)' % self.options['web_root'], MultiStaticFileHandler,
|
(r'/(favicon\.ico)', MultiStaticFileHandler,
|
||||||
{'paths': [os.path.join(self.options['data_root'], 'images/ico/favicon.ico')]}),
|
{'paths': [os.path.join(self.options['data_root'], 'images/ico/favicon.ico')]}),
|
||||||
(r'%s/%s/(.*)(/?)' % (self.options['web_root'], 'images'), MultiStaticFileHandler,
|
(r'%s/%s/(.*)(/?)' % (self.options['web_root'], 'images'), MultiStaticFileHandler,
|
||||||
{'paths': [os.path.join(self.options['data_root'], 'images'),
|
{'paths': [os.path.join(self.options['data_root'], 'images'),
|
||||||
|
Loading…
Reference in New Issue
Block a user