mirror of
https://github.com/moparisthebest/SickRage
synced 2024-12-13 11:32:20 -05:00
Fix for 401/404 errors now just redirect back to home page.
Fix for static mapping issues.
This commit is contained in:
parent
d01a1eed26
commit
fd88c77d26
@ -99,7 +99,7 @@ def authenticated(handler_class):
|
|||||||
def basicauth(handler, transforms, *args, **kwargs):
|
def basicauth(handler, transforms, *args, **kwargs):
|
||||||
def _request_basic_auth(handler):
|
def _request_basic_auth(handler):
|
||||||
handler.set_status(401)
|
handler.set_status(401)
|
||||||
handler.set_header('WWW-Authenticate', 'Basic realm=Restricted')
|
handler.set_header('WWW-Authenticate', 'Basic realm=SickRage')
|
||||||
handler._transforms = []
|
handler._transforms = []
|
||||||
handler.finish()
|
handler.finish()
|
||||||
return False
|
return False
|
||||||
@ -107,6 +107,9 @@ def authenticated(handler_class):
|
|||||||
try:
|
try:
|
||||||
if not (sickbeard.WEB_USERNAME and sickbeard.WEB_PASSWORD):
|
if not (sickbeard.WEB_USERNAME and sickbeard.WEB_PASSWORD):
|
||||||
return True
|
return True
|
||||||
|
elif handler.request.uri.startswith('/calendar') or (
|
||||||
|
handler.request.uri.startswith('/api') and '/api/builder' not in handler.request.uri):
|
||||||
|
return True
|
||||||
|
|
||||||
auth_hdr = handler.request.headers.get('Authorization')
|
auth_hdr = handler.request.headers.get('Authorization')
|
||||||
|
|
||||||
@ -134,6 +137,7 @@ def authenticated(handler_class):
|
|||||||
handler_class._execute = wrap_execute(handler_class._execute)
|
handler_class._execute = wrap_execute(handler_class._execute)
|
||||||
return handler_class
|
return handler_class
|
||||||
|
|
||||||
|
|
||||||
@authenticated
|
@authenticated
|
||||||
class IndexHandler(RequestHandler):
|
class IndexHandler(RequestHandler):
|
||||||
def __init__(self, application, request, **kwargs):
|
def __init__(self, application, request, **kwargs):
|
||||||
@ -141,12 +145,37 @@ class IndexHandler(RequestHandler):
|
|||||||
global req_headers
|
global req_headers
|
||||||
|
|
||||||
sickbeard.REMOTE_IP = self.request.remote_ip
|
sickbeard.REMOTE_IP = self.request.remote_ip
|
||||||
self.set_header('Cache-Control', "max-age=0,no-cache,no-store")
|
|
||||||
req_headers = self.request.headers
|
req_headers = self.request.headers
|
||||||
|
|
||||||
|
def http_error_401_handler(self):
|
||||||
|
""" Custom handler for 401 error """
|
||||||
|
return r'''<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>%s</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<br/>
|
||||||
|
<font color="#0000FF">Error %s: You need to provide a valid username and password.</font>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
''' % ('Access denied', 401)
|
||||||
|
|
||||||
|
def http_error_404_handler(self):
|
||||||
|
""" Custom handler for 404 error, redirect back to main page """
|
||||||
|
self.redirect('/home/')
|
||||||
|
|
||||||
|
def write_error(self, status_code, **kwargs):
|
||||||
|
if status_code == 404:
|
||||||
|
self.redirect('/home/')
|
||||||
|
elif status_code == 401:
|
||||||
|
self.finish(self.http_error_401_handler())
|
||||||
|
else:
|
||||||
|
super(IndexHandler, self).write_error(status_code, **kwargs)
|
||||||
|
|
||||||
def _dispatch(self):
|
def _dispatch(self):
|
||||||
|
|
||||||
path = self.request.uri.replace(sickbeard.WEB_ROOT,'').split('?')[0]
|
path = self.request.uri.replace(sickbeard.WEB_ROOT, '').split('?')[0]
|
||||||
|
|
||||||
method = path.strip('/').split('/')[-1]
|
method = path.strip('/').split('/')[-1]
|
||||||
if path.startswith('/api'):
|
if path.startswith('/api'):
|
||||||
@ -194,23 +223,14 @@ class IndexHandler(RequestHandler):
|
|||||||
@asynchronous
|
@asynchronous
|
||||||
@gen.engine
|
@gen.engine
|
||||||
def get(self, *args, **kwargs):
|
def get(self, *args, **kwargs):
|
||||||
try:
|
response = yield gen.Task(self.getresponse, self._dispatch)
|
||||||
response = yield gen.Task(self.getresponse, self._dispatch)
|
self.finish(response)
|
||||||
self.finish(response)
|
|
||||||
except Exception as e:
|
|
||||||
logger.log(ex(e), logger.ERROR)
|
|
||||||
logger.log(u"Traceback: " + traceback.format_exc(), logger.DEBUG)
|
|
||||||
|
|
||||||
@asynchronous
|
@asynchronous
|
||||||
@gen.engine
|
@gen.engine
|
||||||
def post(self, *args, **kwargs):
|
def post(self, *args, **kwargs):
|
||||||
try:
|
response = yield gen.Task(self.getresponse, self._dispatch)
|
||||||
response = yield gen.Task(self.getresponse, self._dispatch)
|
self.finish(response)
|
||||||
self.finish(response)
|
|
||||||
except Exception as e:
|
|
||||||
logger.log(ex(e), logger.ERROR)
|
|
||||||
logger.log(u"Traceback: " + traceback.format_exc(), logger.DEBUG)
|
|
||||||
|
|
||||||
|
|
||||||
def getresponse(self, func, callback):
|
def getresponse(self, func, callback):
|
||||||
response = func()
|
response = func()
|
||||||
@ -446,7 +466,6 @@ class IndexHandler(RequestHandler):
|
|||||||
|
|
||||||
browser = WebFileBrowser
|
browser = WebFileBrowser
|
||||||
|
|
||||||
|
|
||||||
class PageTemplate(Template):
|
class PageTemplate(Template):
|
||||||
def __init__(self, *args, **KWs):
|
def __init__(self, *args, **KWs):
|
||||||
KWs['file'] = os.path.join(sickbeard.PROG_DIR, "gui/" + sickbeard.GUI_NAME + "/interfaces/default/",
|
KWs['file'] = os.path.join(sickbeard.PROG_DIR, "gui/" + sickbeard.GUI_NAME + "/interfaces/default/",
|
||||||
@ -1464,6 +1483,7 @@ class ConfigGeneral(IndexHandler):
|
|||||||
else:
|
else:
|
||||||
ui.notifications.message('Configuration Saved', ek.ek(os.path.join, sickbeard.CONFIG_FILE))
|
ui.notifications.message('Configuration Saved', ek.ek(os.path.join, sickbeard.CONFIG_FILE))
|
||||||
|
|
||||||
|
|
||||||
class ConfigSearch(IndexHandler):
|
class ConfigSearch(IndexHandler):
|
||||||
def index(self, *args, **kwargs):
|
def index(self, *args, **kwargs):
|
||||||
|
|
||||||
|
@ -43,41 +43,6 @@ def initWebServer(options={}):
|
|||||||
assert isinstance(options['port'], int)
|
assert isinstance(options['port'], int)
|
||||||
assert 'data_root' in options
|
assert 'data_root' in options
|
||||||
|
|
||||||
def http_error_401_hander(status, message, traceback, version):
|
|
||||||
""" Custom handler for 401 error """
|
|
||||||
if status != "401 Unauthorized":
|
|
||||||
logger.log(u"Tornado caught an error: %s %s" % (status, message), logger.ERROR)
|
|
||||||
logger.log(traceback, logger.DEBUG)
|
|
||||||
return r'''<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>%s</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<br/>
|
|
||||||
<font color="#0000FF">Error %s: You need to provide a valid username and password.</font>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
''' % ('Access denied', status)
|
|
||||||
|
|
||||||
def http_error_404_hander(status, message, traceback, version):
|
|
||||||
""" Custom handler for 404 error, redirect back to main page """
|
|
||||||
return r'''<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>404</title>
|
|
||||||
<script type="text/javascript" charset="utf-8">
|
|
||||||
<!--
|
|
||||||
location.href = "%s/home/"
|
|
||||||
//-->
|
|
||||||
</script>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<br/>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
''' % options['web_root']
|
|
||||||
|
|
||||||
# tornado setup
|
# tornado setup
|
||||||
enable_https = options['enable_https']
|
enable_https = options['enable_https']
|
||||||
https_cert = options['https_cert']
|
https_cert = options['https_cert']
|
||||||
@ -116,14 +81,11 @@ def initWebServer(options={}):
|
|||||||
{'paths': [os.path.join(options['data_root'], 'images/ico/favicon.ico')]}),
|
{'paths': [os.path.join(options['data_root'], 'images/ico/favicon.ico')]}),
|
||||||
(r'%s/%s/(.*)(/?)' % (options['web_root'], 'images'), MultiStaticFileHandler,
|
(r'%s/%s/(.*)(/?)' % (options['web_root'], 'images'), MultiStaticFileHandler,
|
||||||
{'paths': [os.path.join(options['data_root'], 'images'),
|
{'paths': [os.path.join(options['data_root'], 'images'),
|
||||||
os.path.join(sickbeard.CACHE_DIR, 'images'),
|
os.path.join(sickbeard.CACHE_DIR, 'images')]}),
|
||||||
os.path.join(sickbeard.CACHE_DIR, 'images', 'thumbnails')]}),
|
|
||||||
(r'%s/%s/(.*)(/?)' % (options['web_root'], 'css'), MultiStaticFileHandler,
|
(r'%s/%s/(.*)(/?)' % (options['web_root'], 'css'), MultiStaticFileHandler,
|
||||||
{'paths': [os.path.join(options['data_root'], 'css')]}),
|
{'paths': [os.path.join(options['data_root'], 'css')]}),
|
||||||
(r'%s/%s/(.*)(/?)' % (options['web_root'], 'js'), MultiStaticFileHandler,
|
(r'%s/%s/(.*)(/?)' % (options['web_root'], 'js'), MultiStaticFileHandler,
|
||||||
{'paths': [os.path.join(options['data_root'], 'js'),
|
{'paths': [os.path.join(options['data_root'], 'js')]})
|
||||||
os.path.join(options['data_root'], 'js/lib'),
|
|
||||||
os.path.join(options['data_root'], 'js/fancybox')]})
|
|
||||||
|
|
||||||
])
|
])
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user