mirror of
https://github.com/moparisthebest/SickRage
synced 2024-12-12 11:02:21 -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 _request_basic_auth(handler):
|
||||
handler.set_status(401)
|
||||
handler.set_header('WWW-Authenticate', 'Basic realm=Restricted')
|
||||
handler.set_header('WWW-Authenticate', 'Basic realm=SickRage')
|
||||
handler._transforms = []
|
||||
handler.finish()
|
||||
return False
|
||||
@ -107,6 +107,9 @@ def authenticated(handler_class):
|
||||
try:
|
||||
if not (sickbeard.WEB_USERNAME and sickbeard.WEB_PASSWORD):
|
||||
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')
|
||||
|
||||
@ -134,6 +137,7 @@ def authenticated(handler_class):
|
||||
handler_class._execute = wrap_execute(handler_class._execute)
|
||||
return handler_class
|
||||
|
||||
|
||||
@authenticated
|
||||
class IndexHandler(RequestHandler):
|
||||
def __init__(self, application, request, **kwargs):
|
||||
@ -141,12 +145,37 @@ class IndexHandler(RequestHandler):
|
||||
global req_headers
|
||||
|
||||
sickbeard.REMOTE_IP = self.request.remote_ip
|
||||
self.set_header('Cache-Control', "max-age=0,no-cache,no-store")
|
||||
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):
|
||||
|
||||
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]
|
||||
if path.startswith('/api'):
|
||||
@ -186,7 +215,7 @@ class IndexHandler(RequestHandler):
|
||||
return func(**args)
|
||||
|
||||
raise HTTPError(404)
|
||||
|
||||
|
||||
def redirect(self, url, permanent=False, status=None):
|
||||
self._transforms = []
|
||||
super(IndexHandler, self).redirect(sickbeard.WEB_ROOT + url, permanent, status)
|
||||
@ -194,23 +223,14 @@ class IndexHandler(RequestHandler):
|
||||
@asynchronous
|
||||
@gen.engine
|
||||
def get(self, *args, **kwargs):
|
||||
try:
|
||||
response = yield gen.Task(self.getresponse, self._dispatch)
|
||||
self.finish(response)
|
||||
except Exception as e:
|
||||
logger.log(ex(e), logger.ERROR)
|
||||
logger.log(u"Traceback: " + traceback.format_exc(), logger.DEBUG)
|
||||
response = yield gen.Task(self.getresponse, self._dispatch)
|
||||
self.finish(response)
|
||||
|
||||
@asynchronous
|
||||
@gen.engine
|
||||
def post(self, *args, **kwargs):
|
||||
try:
|
||||
response = yield gen.Task(self.getresponse, self._dispatch)
|
||||
self.finish(response)
|
||||
except Exception as e:
|
||||
logger.log(ex(e), logger.ERROR)
|
||||
logger.log(u"Traceback: " + traceback.format_exc(), logger.DEBUG)
|
||||
|
||||
response = yield gen.Task(self.getresponse, self._dispatch)
|
||||
self.finish(response)
|
||||
|
||||
def getresponse(self, func, callback):
|
||||
response = func()
|
||||
@ -446,7 +466,6 @@ class IndexHandler(RequestHandler):
|
||||
|
||||
browser = WebFileBrowser
|
||||
|
||||
|
||||
class PageTemplate(Template):
|
||||
def __init__(self, *args, **KWs):
|
||||
KWs['file'] = os.path.join(sickbeard.PROG_DIR, "gui/" + sickbeard.GUI_NAME + "/interfaces/default/",
|
||||
@ -1464,6 +1483,7 @@ class ConfigGeneral(IndexHandler):
|
||||
else:
|
||||
ui.notifications.message('Configuration Saved', ek.ek(os.path.join, sickbeard.CONFIG_FILE))
|
||||
|
||||
|
||||
class ConfigSearch(IndexHandler):
|
||||
def index(self, *args, **kwargs):
|
||||
|
||||
|
@ -43,41 +43,6 @@ def initWebServer(options={}):
|
||||
assert isinstance(options['port'], int)
|
||||
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
|
||||
enable_https = options['enable_https']
|
||||
https_cert = options['https_cert']
|
||||
@ -116,14 +81,11 @@ def initWebServer(options={}):
|
||||
{'paths': [os.path.join(options['data_root'], 'images/ico/favicon.ico')]}),
|
||||
(r'%s/%s/(.*)(/?)' % (options['web_root'], 'images'), MultiStaticFileHandler,
|
||||
{'paths': [os.path.join(options['data_root'], 'images'),
|
||||
os.path.join(sickbeard.CACHE_DIR, 'images'),
|
||||
os.path.join(sickbeard.CACHE_DIR, 'images', 'thumbnails')]}),
|
||||
os.path.join(sickbeard.CACHE_DIR, 'images')]}),
|
||||
(r'%s/%s/(.*)(/?)' % (options['web_root'], 'css'), MultiStaticFileHandler,
|
||||
{'paths': [os.path.join(options['data_root'], 'css')]}),
|
||||
(r'%s/%s/(.*)(/?)' % (options['web_root'], 'js'), MultiStaticFileHandler,
|
||||
{'paths': [os.path.join(options['data_root'], 'js'),
|
||||
os.path.join(options['data_root'], 'js/lib'),
|
||||
os.path.join(options['data_root'], 'js/fancybox')]})
|
||||
{'paths': [os.path.join(options['data_root'], 'js')]})
|
||||
|
||||
])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user