1
0
mirror of https://github.com/moparisthebest/SickRage synced 2024-12-13 03:22:22 -05:00

Merge remote-tracking branch 'origin/dev'

This commit is contained in:
echel0n 2014-06-17 12:54:06 -07:00
commit 829105059b
2 changed files with 22 additions and 52 deletions

View File

@ -18,6 +18,7 @@
from __future__ import with_statement from __future__ import with_statement
import base64 import base64
import functools
import inspect import inspect
import os.path import os.path
@ -80,11 +81,11 @@ from lib import adba
from Cheetah.Template import Template from Cheetah.Template import Template
from tornado import gen, autoreload from tornado import gen, autoreload
from tornado.web import RequestHandler, HTTPError, asynchronous, authenticated from tornado.web import RequestHandler, HTTPError, asynchronous
from tornado.ioloop import IOLoop from tornado.ioloop import IOLoop
# def _handle_reverse_proxy(): # def _handle_reverse_proxy():
# if sickbeard.HANDLE_REVERSE_PROXY: # if sickbeard.HANDLE_REVERSE_PROXY:
# cherrypy.lib.cptools.proxy() # cherrypy.lib.cptools.proxy()
@ -92,12 +93,14 @@ from tornado.ioloop import IOLoop
req_headers = None req_headers = None
def basicauth(handler_class):
def authenticated(handler_class):
def wrap_execute(handler_execute): def wrap_execute(handler_execute):
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=Restricted')
handler._transforms = []
handler.finish() handler.finish()
return False return False
@ -112,16 +115,9 @@ def basicauth(handler_class):
auth_decoded = base64.decodestring(auth_hdr[6:]) auth_decoded = base64.decodestring(auth_hdr[6:])
username, password = auth_decoded.split(':', 2) username, password = auth_decoded.split(':', 2)
if username == sickbeard.WEB_USERNAME and password == sickbeard.WEB_PASSWORD: if username != sickbeard.WEB_USERNAME or password != sickbeard.WEB_PASSWORD:
#logger.log('authenticated user successfully', logger.DEBUG)
if not handler.get_secure_cookie("user"):
handler.set_secure_cookie("user", str(time.time()))
else:
if handler.get_secure_cookie("user"):
handler.clear_cookie("user")
return _request_basic_auth(handler) return _request_basic_auth(handler)
except Exception, e: except Exception, e:
handler.clear_cookie("user")
return _request_basic_auth(handler) return _request_basic_auth(handler)
return True return True
@ -135,12 +131,12 @@ def basicauth(handler_class):
handler_class._execute = wrap_execute(handler_class._execute) handler_class._execute = wrap_execute(handler_class._execute)
return handler_class return handler_class
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 @authenticated
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)
@ -161,7 +157,7 @@ class IndexHandler(RedirectHandler):
args[arg] = value[0] args[arg] = value[0]
return args return args
def _dispatch(self, callback): def _dispatch(self):
args = None args = None
path = self.request.uri.split('?')[0] path = self.request.uri.split('?')[0]
@ -170,7 +166,7 @@ class IndexHandler(RedirectHandler):
if path.startswith('/api'): if path.startswith('/api'):
apikey = path.strip('/').split('/')[-1] apikey = path.strip('/').split('/')[-1]
method = path.strip('/').split('/')[0] method = path.strip('/').split('/')[0]
self.request.arguments.update({'apikey':[apikey]}) self.request.arguments.update({'apikey': [apikey]})
def pred(c): def pred(c):
return inspect.isclass(c) and c.__module__ == pred.__module__ return inspect.isclass(c) and c.__module__ == pred.__module__
@ -200,35 +196,29 @@ class IndexHandler(RedirectHandler):
if func: if func:
if args: if args:
callback(func(**args)) return func(**args)
else: else:
callback(func()) return func()
callback(HTTPError(404)) raise HTTPError(404)
def get_current_user(self):
return self.get_secure_cookie("user")
@authenticated
@asynchronous @asynchronous
@gen.engine
def get(self, *args, **kwargs): def get(self, *args, **kwargs):
try: try:
result = yield gen.Task(self._dispatch) resp = self._dispatch()
self.finish(result) if resp:
self.finish(resp)
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)
self.finish(ex(e))
@asynchronous
def post(self, *args, **kwargs): def post(self, *args, **kwargs):
try: try:
result = yield gen.Task(self._dispatch) self.finish(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)
self.finish(ex(e))
def robots_txt(self, *args, **kwargs): def robots_txt(self, *args, **kwargs):
""" Keep web crawlers out """ """ Keep web crawlers out """
@ -460,10 +450,6 @@ class IndexHandler(RedirectHandler):
browser = WebFileBrowser browser = WebFileBrowser
class LoginHandler(IndexHandler):
def get(self):
self.redirect(self.get_argument("next", u"/"))
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/",
@ -552,6 +538,7 @@ def _getEpisode(show, season=None, episode=None, absolute=None):
return epObj return epObj
def ManageMenu(): def ManageMenu():
manageMenu = [ manageMenu = [
{'title': 'Backlog Overview', 'path': 'manage/backlogOverview/'}, {'title': 'Backlog Overview', 'path': 'manage/backlogOverview/'},
@ -626,6 +613,7 @@ class ManageSearches(IndexHandler):
self.redirect("/manage/manageSearches/") self.redirect("/manage/manageSearches/")
class Manage(IndexHandler): class Manage(IndexHandler):
def index(self, *args, **kwargs): def index(self, *args, **kwargs):
t = PageTemplate(file="manage.tmpl") t = PageTemplate(file="manage.tmpl")
@ -1479,8 +1467,6 @@ 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))
self.redirect("/config/general/")
class ConfigSearch(IndexHandler): class ConfigSearch(IndexHandler):
def index(self, *args, **kwargs): def index(self, *args, **kwargs):
@ -1564,8 +1550,6 @@ class ConfigSearch(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))
self.redirect("/config/search/")
class ConfigPostProcessing(IndexHandler): class ConfigPostProcessing(IndexHandler):
def index(self, *args, **kwargs): def index(self, *args, **kwargs):
@ -1669,8 +1653,6 @@ class ConfigPostProcessing(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))
self.redirect("/config/postProcessing/")
def testNaming(self, pattern=None, multi=None, abd=False, sports=False, anime_type=None): def testNaming(self, pattern=None, multi=None, abd=False, sports=False, anime_type=None):
@ -2109,8 +2091,6 @@ class ConfigProviders(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))
self.redirect("/config/providers/")
class ConfigNotifications(IndexHandler): class ConfigNotifications(IndexHandler):
def index(self, *args, **kwargs): def index(self, *args, **kwargs):
@ -2312,8 +2292,6 @@ class ConfigNotifications(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))
self.redirect("/config/notifications/")
class ConfigSubtitles(IndexHandler): class ConfigSubtitles(IndexHandler):
def index(self, *args, **kwargs): def index(self, *args, **kwargs):
@ -2371,8 +2349,6 @@ class ConfigSubtitles(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))
self.redirect("/config/subtitles/")
class ConfigAnime(IndexHandler): class ConfigAnime(IndexHandler):
def index(self, *args, **kwargs): def index(self, *args, **kwargs):
@ -2418,8 +2394,6 @@ class ConfigAnime(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))
self.redirect("/config/anime/")
class Config(IndexHandler): class Config(IndexHandler):
def index(self, *args, **kwargs): def index(self, *args, **kwargs):
@ -4222,7 +4196,6 @@ class UI(IndexHandler):
return "ok" return "ok"
def get_messages(self, *args, **kwargs): def get_messages(self, *args, **kwargs):
messages = {} messages = {}
cur_notification_num = 1 cur_notification_num = 1

View File

@ -4,7 +4,6 @@ import sickbeard
import webserve import webserve
import webapi import webapi
import tornado.options
from sickbeard import logger from sickbeard import logger
from sickbeard.helpers import create_https_certificates from sickbeard.helpers import create_https_certificates
from tornado.web import Application, StaticFileHandler, RedirectHandler, HTTPError from tornado.web import Application, StaticFileHandler, RedirectHandler, HTTPError
@ -103,14 +102,12 @@ def initWebServer(options={}):
debug=sickbeard.DEBUG, debug=sickbeard.DEBUG,
gzip=True, gzip=True,
xheaders=True, xheaders=True,
cookie_secret='61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=', cookie_secret='61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo='
login_url='/login'
) )
# Index Handler # Index Handler
app.add_handlers(".*$", [ app.add_handlers(".*$", [
(r"/", RedirectHandler, {'url': '/home/'}), (r"/", RedirectHandler, {'url': '/home/'}),
(r'/login', webserve.LoginHandler),
(r'/api/(.*)(/?)', webapi.Api), (r'/api/(.*)(/?)', webapi.Api),
(r'%s(.*)(/?)' % options['web_root'], webserve.IndexHandler) (r'%s(.*)(/?)' % options['web_root'], webserve.IndexHandler)
]) ])