mirror of
https://github.com/SickGear/SickGear.git
synced 2025-03-15 09:07:43 +00:00
Fix for NoneType is not iterable issue
This commit is contained in:
parent
18a1681a61
commit
cc86dda802
2 changed files with 37 additions and 30 deletions
|
@ -101,11 +101,11 @@ def foldersAtPath(path, includeParent=False):
|
||||||
|
|
||||||
|
|
||||||
class WebFileBrowser(RequestHandler):
|
class WebFileBrowser(RequestHandler):
|
||||||
def index(self, path=''):
|
def index(self, path='', *args, **kwargs):
|
||||||
self.set_header("Content-Type", "application/json")
|
self.set_header("Content-Type", "application/json")
|
||||||
return self.finish(json.dumps(foldersAtPath(path, True)))
|
return json.dumps(foldersAtPath(path, True))
|
||||||
|
|
||||||
def complete(self, term):
|
def complete(self, term):
|
||||||
self.set_header("Content-Type", "application/json")
|
self.set_header("Content-Type", "application/json")
|
||||||
paths = [entry['path'] for entry in foldersAtPath(os.path.dirname(term)) if 'path' in entry]
|
paths = [entry['path'] for entry in foldersAtPath(os.path.dirname(term)) if 'path' in entry]
|
||||||
return self.finish(json.dumps(paths))
|
return json.dumps(paths)
|
||||||
|
|
|
@ -92,35 +92,41 @@ from tornado.ioloop import IOLoop
|
||||||
|
|
||||||
req_headers = None
|
req_headers = None
|
||||||
|
|
||||||
def require_basic_auth(handler_class):
|
def basicauth(handler_class):
|
||||||
def wrap_execute(handler_execute):
|
def wrap_execute(handler_execute):
|
||||||
def require_basic_auth(handler, kwargs):
|
def basicauth(handler, transforms, *args, **kwargs):
|
||||||
def get_auth():
|
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=Restricted')
|
||||||
handler._transforms = []
|
|
||||||
handler.finish()
|
handler.finish()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if not sickbeard.WEB_USERNAME and not sickbeard.WEB_PASSWORD:
|
try:
|
||||||
if not handler.get_secure_cookie("user"):
|
auth_hdr = handler.request.headers.get('Authorization')
|
||||||
handler.set_secure_cookie("user", str(time.time()))
|
|
||||||
return True
|
|
||||||
|
|
||||||
auth_header = handler.request.headers.get('Authorization')
|
if auth_hdr == None:
|
||||||
if auth_header and auth_header.startswith('Basic '):
|
return _request_basic_auth(handler)
|
||||||
auth_decoded = base64.decodestring(auth_header[6:])
|
if not auth_hdr.startswith('Basic '):
|
||||||
basicauth_user, basicauth_pass = auth_decoded.split(':', 2)
|
return _request_basic_auth(handler)
|
||||||
if basicauth_user == sickbeard.WEB_USERNAME and basicauth_pass == sickbeard.WEB_PASSWORD:
|
|
||||||
|
auth_decoded = base64.decodestring(auth_hdr[6:])
|
||||||
|
username, password = auth_decoded.split(':', 2)
|
||||||
|
|
||||||
|
if username == sickbeard.WEB_USERNAME and password == sickbeard.WEB_PASSWORD:
|
||||||
|
#logger.log('authenticated user successfully', logger.DEBUG)
|
||||||
if not handler.get_secure_cookie("user"):
|
if not handler.get_secure_cookie("user"):
|
||||||
handler.set_secure_cookie("user", str(time.time()))
|
handler.set_secure_cookie("user", str(time.time()))
|
||||||
return True
|
else:
|
||||||
|
if handler.get_secure_cookie("user"):
|
||||||
handler.clear_cookie("user")
|
handler.clear_cookie("user")
|
||||||
get_auth()
|
return _request_basic_auth(handler)
|
||||||
|
except Exception, e:
|
||||||
|
handler.clear_cookie("user")
|
||||||
|
return _request_basic_auth(handler)
|
||||||
|
return True
|
||||||
|
|
||||||
def _execute(self, transforms, *args, **kwargs):
|
def _execute(self, transforms, *args, **kwargs):
|
||||||
if not require_basic_auth(self, kwargs):
|
if not basicauth(self, transforms, *args, **kwargs):
|
||||||
return False
|
return False
|
||||||
return handler_execute(self, transforms, *args, **kwargs)
|
return handler_execute(self, transforms, *args, **kwargs)
|
||||||
|
|
||||||
|
@ -129,12 +135,12 @@ def require_basic_auth(handler_class):
|
||||||
handler_class._execute = wrap_execute(handler_class._execute)
|
handler_class._execute = wrap_execute(handler_class._execute)
|
||||||
return handler_class
|
return handler_class
|
||||||
|
|
||||||
@require_basic_auth
|
|
||||||
class RedirectHandler(RequestHandler):
|
class RedirectHandler(RequestHandler):
|
||||||
|
|
||||||
def get(self, path, **kwargs):
|
def get(self, path, **kwargs):
|
||||||
self.redirect(path, permanent=True)
|
self.redirect(path, permanent=True)
|
||||||
|
|
||||||
|
@basicauth
|
||||||
class IndexHandler(RedirectHandler):
|
class IndexHandler(RedirectHandler):
|
||||||
def __init__(self, application, request, **kwargs):
|
def __init__(self, application, request, **kwargs):
|
||||||
super(IndexHandler, self).__init__(application, request, **kwargs)
|
super(IndexHandler, self).__init__(application, request, **kwargs)
|
||||||
|
@ -155,7 +161,7 @@ class IndexHandler(RedirectHandler):
|
||||||
args[arg] = value[0]
|
args[arg] = value[0]
|
||||||
return args
|
return args
|
||||||
|
|
||||||
def _dispatch(self):
|
def _dispatch(self, callback):
|
||||||
|
|
||||||
args = None
|
args = None
|
||||||
path = self.request.uri.split('?')[0]
|
path = self.request.uri.split('?')[0]
|
||||||
|
@ -194,21 +200,22 @@ class IndexHandler(RedirectHandler):
|
||||||
|
|
||||||
if func:
|
if func:
|
||||||
if args:
|
if args:
|
||||||
return func(**args)
|
callback(func(**args))
|
||||||
else:
|
else:
|
||||||
return func()
|
callback(func())
|
||||||
|
|
||||||
if self.request.uri != ('/'):
|
callback(HTTPError(404))
|
||||||
raise HTTPError(404)
|
|
||||||
|
|
||||||
def get_current_user(self):
|
def get_current_user(self):
|
||||||
return self.get_secure_cookie("user")
|
return self.get_secure_cookie("user")
|
||||||
|
|
||||||
@authenticated
|
@authenticated
|
||||||
@asynchronous
|
@asynchronous
|
||||||
|
@gen.engine
|
||||||
def get(self, *args, **kwargs):
|
def get(self, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
self.finish(self._dispatch())
|
result = yield gen.Task(self._dispatch)
|
||||||
|
self.finish(result)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.log(ex(e), logger.ERROR)
|
logger.log(ex(e), logger.ERROR)
|
||||||
logger.log(u"Traceback: " + traceback.format_exc(), logger.DEBUG)
|
logger.log(u"Traceback: " + traceback.format_exc(), logger.DEBUG)
|
||||||
|
@ -216,8 +223,8 @@ class IndexHandler(RedirectHandler):
|
||||||
|
|
||||||
def post(self, *args, **kwargs):
|
def post(self, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
resp = self._dispatch()
|
result = yield gen.Task(self._dispatch)
|
||||||
self.finish(resp)
|
self.finish(result)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.log(ex(e), logger.ERROR)
|
logger.log(ex(e), logger.ERROR)
|
||||||
logger.log(u"Traceback: " + traceback.format_exc(), logger.DEBUG)
|
logger.log(u"Traceback: " + traceback.format_exc(), logger.DEBUG)
|
||||||
|
|
Loading…
Reference in a new issue