def __init__(self, options={}, io_loop=None): threading.Thread.__init__(self) self.daemon = True self.alive = True self.name = "TORNADO" self.io_loop = io_loop or IOLoop.current() self.options = options self.options.setdefault('port', 8081) self.options.setdefault('host', '0.0.0.0') self.options.setdefault('log_dir', None) self.options.setdefault('username', '') self.options.setdefault('password', '') self.options.setdefault('web_root', '/') assert isinstance(self.options['port'], int) assert 'data_root' in self.options # video root if sickbeard.ROOT_DIRS: root_dirs = sickbeard.ROOT_DIRS.split('|') self.video_root = root_dirs[int(root_dirs[0]) + 1] else: self.video_root = None # web root if self.options['web_root']: sickbeard.WEB_ROOT = self.options['web_root'] = ('/' + self.options['web_root'].lstrip('/').strip('/')) # api root if not sickbeard.API_KEY: sickbeard.API_KEY = generateApiKey() self.options['api_root'] = r'%s/api/%s' % (sickbeard.WEB_ROOT, sickbeard.API_KEY) # tornado setup self.enable_https = self.options['enable_https'] self.https_cert = self.options['https_cert'] self.https_key = self.options['https_key'] if self.enable_https: # If either the HTTPS certificate or key do not exist, make some self-signed ones. if not (self.https_cert and os.path.exists(self.https_cert)) or not ( self.https_key and os.path.exists(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") sickbeard.ENABLE_HTTPS = False self.enable_https = False 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) sickbeard.ENABLE_HTTPS = False self.enable_https = False # Load the app self.app = Application([], debug=True, autoreload=False, gzip=True, xheaders=sickbeard.HANDLE_REVERSE_PROXY, cookie_secret='61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=', login_url='%s/login/' % self.options['web_root'], ) # Main Handlers self.app.add_handlers('.*$', [ # webapi handler (r'%s(/?.*)' % self.options['api_root'], ApiHandler), # webapi key retrieval (r'%s/getkey(/?.*)' % self.options['web_root'], KeyHandler), # webapi builder redirect (r'%s/api/builder' % self.options['web_root'], RedirectHandler, {"url": self.options['web_root'] + '/apibuilder/'}), # webui login/logout handlers (r'%s/login(/?)' % self.options['web_root'], LoginHandler), (r'%s/logout(/?)' % self.options['web_root'], LogoutHandler), # webui handlers ] + route.get_routes(self.options['web_root'])) # Static File Handlers self.app.add_handlers(".*$", [ # favicon (r'%s/(favicon\.ico)' % self.options['web_root'], StaticFileHandler, {"path": os.path.join(self.options['data_root'], 'images/ico/favicon.ico')}), # images (r'%s/images/(.*)' % self.options['web_root'], StaticFileHandler, {"path": os.path.join(self.options['data_root'], 'images')}), # cached images (r'%s/cache/images/(.*)' % self.options['web_root'], StaticFileHandler, {"path": os.path.join(sickbeard.CACHE_DIR, 'images')}), # css (r'%s/css/(.*)' % self.options['web_root'], StaticFileHandler, {"path": os.path.join(self.options['data_root'], 'css')}), # javascript (r'%s/js/(.*)' % self.options['web_root'], StaticFileHandler, {"path": os.path.join(self.options['data_root'], 'js')}), # videos ] + [(r'%s/videos/(.*)' % self.options['web_root'], StaticFileHandler, {"path": self.video_root})])
def __init__(self, options=None, io_loop=None): threading.Thread.__init__(self) self.daemon = True self.alive = True self.name = "TORNADO" self.io_loop = io_loop or IOLoop.current() self.options = options or {} self.options.setdefault("port", 8081) self.options.setdefault("host", "0.0.0.0") self.options.setdefault("log_dir", None) self.options.setdefault("username", "") self.options.setdefault("password", "") self.options.setdefault("web_root", "/") assert isinstance(self.options["port"], int) assert "data_root" in self.options self.server = None # video root if sickbeard.ROOT_DIRS: root_dirs = sickbeard.ROOT_DIRS.split("|") self.video_root = root_dirs[int(root_dirs[0]) + 1] else: self.video_root = None # web root if self.options["web_root"]: sickbeard.WEB_ROOT = self.options["web_root"] = "/" + self.options["web_root"].lstrip("/").strip("/") # api root if not sickbeard.API_KEY: sickbeard.API_KEY = generateApiKey() self.options["api_root"] = r"{0}/api/{1}".format(sickbeard.WEB_ROOT, sickbeard.API_KEY) # tornado setup self.enable_https = self.options["enable_https"] self.https_cert = self.options["https_cert"] self.https_key = self.options["https_key"] if self.enable_https: # If either the HTTPS certificate or key do not exist, make some self-signed ones. if not (self.https_cert and ek(os.path.exists, self.https_cert)) or not ( self.https_key and ek(os.path.exists, 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") sickbeard.ENABLE_HTTPS = False self.enable_https = False if not (ek(os.path.exists, self.https_cert) and ek(os.path.exists, self.https_key)): logger.log(u"Disabled HTTPS because of missing CERT and KEY files", logger.WARNING) sickbeard.ENABLE_HTTPS = False self.enable_https = False # Load the app self.app = Application( [], debug=True, autoreload=False, gzip=sickbeard.WEB_USE_GZIP, xheaders=sickbeard.HANDLE_REVERSE_PROXY, cookie_secret=sickbeard.WEB_COOKIE_SECRET, login_url="{0}/login/".format(self.options["web_root"]), ) # Main Handlers self.app.add_handlers( ".*$", [ # webapi handler (r"{0}(/?.*)".format(self.options["api_root"]), ApiHandler), # webapi key retrieval (r"{0}/getkey(/?.*)".format(self.options["web_root"]), KeyHandler), # webapi builder redirect ( r"{0}/api/builder".format(self.options["web_root"]), RedirectHandler, {"url": self.options["web_root"] + "/apibuilder/"}, ), # webui login/logout handlers (r"{0}/login(/?)".format(self.options["web_root"]), LoginHandler), (r"{0}/logout(/?)".format(self.options["web_root"]), LogoutHandler), # Web calendar handler (Needed because option Unprotected calendar) (r"{0}/calendar".format(self.options["web_root"]), CalendarHandler), # webui handlers ] + route.get_routes(self.options["web_root"]), ) # Static File Handlers self.app.add_handlers( ".*$", [ # favicon ( r"{0}/(favicon\.ico)".format(self.options["web_root"]), StaticFileHandler, {"path": ek(os.path.join, self.options["data_root"], "images/ico/favicon.ico")}, ), # images ( r"{0}/images/(.*)".format(self.options["web_root"]), StaticFileHandler, {"path": ek(os.path.join, self.options["data_root"], "images")}, ), # cached images ( r"{0}/cache/images/(.*)".format(self.options["web_root"]), StaticFileHandler, {"path": ek(os.path.join, sickbeard.CACHE_DIR, "images")}, ), # css ( r"{0}/css/(.*)".format(self.options["web_root"]), StaticFileHandler, {"path": ek(os.path.join, self.options["data_root"], "css")}, ), # javascript ( r"{0}/js/(.*)".format(self.options["web_root"]), StaticFileHandler, {"path": ek(os.path.join, self.options["data_root"], "js")}, ), # fonts ( r"{0}/fonts/(.*)".format(self.options["web_root"]), StaticFileHandler, {"path": ek(os.path.join, self.options["data_root"], "fonts")}, ), # videos (r"{0}/videos/(.*)".format(self.options["web_root"]), StaticFileHandler, {"path": self.video_root}), ], )
def __init__(self, options=None, io_loop=None): threading.Thread.__init__(self) self.daemon = True self.alive = True self.name = "TORNADO" self.io_loop = io_loop or IOLoop.current() self.options = options or {} self.options.setdefault('port', 8081) self.options.setdefault('host', '0.0.0.0') self.options.setdefault('log_dir', None) self.options.setdefault('username', '') self.options.setdefault('password', '') self.options.setdefault('web_root', '/') assert isinstance(self.options['port'], int) assert 'data_root' in self.options self.server = None # video root if sickbeard.ROOT_DIRS: root_dirs = sickbeard.ROOT_DIRS.split('|') self.video_root = root_dirs[int(root_dirs[0]) + 1] else: self.video_root = None # web root if self.options['web_root']: sickbeard.WEB_ROOT = self.options['web_root'] = ( '/' + self.options['web_root'].lstrip('/').strip('/')) # api root if not sickbeard.API_KEY: sickbeard.API_KEY = generateApiKey() self.options['api_root'] = r'{0}/api/{1}'.format( sickbeard.WEB_ROOT, sickbeard.API_KEY) # tornado setup self.enable_https = self.options['enable_https'] self.https_cert = self.options['https_cert'] self.https_key = self.options['https_key'] if self.enable_https: # If either the HTTPS certificate or key do not exist, make some self-signed ones. if not (self.https_cert and ek(os.path.exists, self.https_cert)) or not ( self.https_key and ek(os.path.exists, self.https_key)): if not create_https_certificates(self.https_cert, self.https_key): logger.log( "Unable to create CERT/KEY files, disabling HTTPS") sickbeard.ENABLE_HTTPS = False self.enable_https = False if not (ek(os.path.exists, self.https_cert) and ek(os.path.exists, self.https_key)): logger.log( "Disabled HTTPS because of missing CERT and KEY files", logger.WARNING) sickbeard.ENABLE_HTTPS = False self.enable_https = False # Load the app self.app = Application( [], debug=True, autoreload=False, gzip=sickbeard.WEB_USE_GZIP, cookie_secret=sickbeard.WEB_COOKIE_SECRET, login_url='{0}/login/'.format(self.options['web_root']), ) # Main Handlers self.app.add_handlers( '.*$', [ # webapi handler (r'{0}(/?.*)'.format(self.options['api_root']), ApiHandler), # webapi key retrieval (r'{0}/getkey(/?.*)'.format( self.options['web_root']), KeyHandler), # webapi builder redirect (r'{0}/api/builder'.format( self.options['web_root']), RedirectHandler, { "url": self.options['web_root'] + '/apibuilder/' }), # webui login/logout handlers (r'{0}/login(/?)'.format( self.options['web_root']), LoginHandler), (r'{0}/logout(/?)'.format( self.options['web_root']), LogoutHandler), # Web calendar handler (Needed because option Unprotected calendar) (r'{0}/calendar'.format( self.options['web_root']), CalendarHandler), # webui handlers ] + route.get_routes(self.options['web_root'])) # Static File Handlers self.app.add_handlers( ".*$", [ # favicon (r'{0}/(favicon\.ico)'.format( self.options['web_root']), StaticFileHandler, { "path": ek(os.path.join, self.options['data_root'], 'images/ico/favicon.ico') }), # images (r'{0}/images/(.*)'.format( self.options['web_root']), StaticFileHandler, { "path": ek(os.path.join, self.options['data_root'], 'images') }), # locale (r'{0}/locale/messages\.json'.format( self.options['web_root']), LocaleFileHandler, { "path": ek(os.path.join, sickbeard.LOCALE_DIR, '{lang_code}/LC_MESSAGES') }), # cached images (r'{0}/cache/images/(.*)'.format( self.options['web_root']), StaticFileHandler, { "path": ek(os.path.join, sickbeard.CACHE_DIR, 'images') }), # css (r'{0}/css/(.*)'.format(self.options['web_root']), StaticFileHandler, { "path": ek(os.path.join, self.options['data_root'], 'css') }), # javascript (r'{0}/js/(.*)'.format(self.options['web_root']), StaticFileHandler, { "path": ek(os.path.join, self.options['data_root'], 'js') }), # fonts (r'{0}/fonts/(.*)'.format( self.options['web_root']), StaticFileHandler, { "path": ek(os.path.join, self.options['data_root'], 'fonts') }), # videos (r'{0}/videos/(.*)'.format( self.options['web_root']), StaticFileHandler, { "path": self.video_root }) ])
def __init__(self, options={}, io_loop=None): threading.Thread.__init__(self) self.daemon = True self.alive = True self.name = "TORNADO" self.io_loop = io_loop or IOLoop.current() self.options = options self.options.setdefault('port', 8081) self.options.setdefault('host', '0.0.0.0') self.options.setdefault('log_dir', None) self.options.setdefault('username', '') self.options.setdefault('password', '') self.options.setdefault('web_root', '/') assert isinstance(self.options['port'], int) assert 'data_root' in self.options # video root if sickbeard.ROOT_DIRS: root_dirs = sickbeard.ROOT_DIRS.split('|') self.video_root = root_dirs[int(root_dirs[0]) + 1] else: self.video_root = None # web root if self.options['web_root']: sickbeard.WEB_ROOT = self.options['web_root'] = ('/' + self.options['web_root'].lstrip('/').strip('/')) # api root if not sickbeard.API_KEY: sickbeard.API_KEY = generateApiKey() self.options['api_root'] = r'%s/api/%s' % (sickbeard.WEB_ROOT, sickbeard.API_KEY) # tornado setup self.enable_https = self.options['enable_https'] self.https_cert = self.options['https_cert'] self.https_key = self.options['https_key'] if self.enable_https: # If either the HTTPS certificate or key do not exist, make some self-signed ones. if not (self.https_cert and os.path.exists(self.https_cert)) or not ( self.https_key and os.path.exists(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") sickbeard.ENABLE_HTTPS = False self.enable_https = False 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) sickbeard.ENABLE_HTTPS = False self.enable_https = False # Load the app self.app = Application([], debug=True, autoreload=False, gzip=True, xheaders=sickbeard.HANDLE_REVERSE_PROXY, cookie_secret='61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=', login_url='/login/', ) # Main Handlers self.app.add_handlers('.*$', [ # webapi handler (r'%s(/?.*)' % self.options['api_root'], ApiHandler), # webapi key retrieval (r'%s/getkey(/?.*)' % self.options['web_root'], KeyHandler), # webapi builder redirect (r'%s/api/builder' % self.options['web_root'], RedirectHandler, {"url": self.options['web_root'] + '/apibuilder/'}), # webui login/logout handlers (r'%s/login(/?.*)' % self.options['web_root'], LoginHandler), (r'%s/logout(/?.*)' % self.options['web_root'], LogoutHandler), # webui redirect (r'/', RedirectHandler, {"url": self.options['web_root'] + '/home/'}), # webui handlers ] + route.get_routes(self.options['web_root'])) # Static File Handlers self.app.add_handlers(".*$", [ # favicon (r'%s/(favicon\.ico)' % self.options['web_root'], StaticFileHandler, {"path": os.path.join(self.options['data_root'], 'images/ico/favicon.ico')}), # images (r'%s/images/(.*)' % self.options['web_root'], StaticFileHandler, {"path": os.path.join(self.options['data_root'], 'images')}), # cached images (r'%s/cache/images/(.*)' % self.options['web_root'], StaticFileHandler, {"path": os.path.join(sickbeard.CACHE_DIR, 'images')}), # css (r'%s/css/(.*)' % self.options['web_root'], StaticFileHandler, {"path": os.path.join(self.options['data_root'], 'css')}), # javascript (r'%s/js/(.*)' % self.options['web_root'], StaticFileHandler, {"path": os.path.join(self.options['data_root'], 'js')}), # videos ] + [(r'%s/videos/(.*)' % self.options['web_root'], StaticFileHandler, {"path": self.video_root})])
def __init__(self, options=None, io_loop=None): threading.Thread.__init__(self) self.daemon = True self.alive = True self.name = "TORNADO" self.io_loop = io_loop or IOLoop.current() self.options = options or {} self.options.setdefault('port', 8081) self.options.setdefault('host', '0.0.0.0') self.options.setdefault('log_dir', None) self.options.setdefault('username', '') self.options.setdefault('password', '') self.options.setdefault('web_root', '/') assert isinstance(self.options['port'], int) assert 'data_root' in self.options self.server = None # video root if sickbeard.ROOT_DIRS: root_dirs = sickbeard.ROOT_DIRS.split('|') self.video_root = root_dirs[int(root_dirs[0]) + 1] else: self.video_root = None # web root if self.options['web_root']: sickbeard.WEB_ROOT = self.options['web_root'] = ('/' + self.options['web_root'].lstrip('/').strip('/')) # api root if not sickbeard.API_KEY: sickbeard.API_KEY = generateApiKey() self.options['api_root'] = r'{0}/api/{1}'.format(sickbeard.WEB_ROOT, sickbeard.API_KEY) # tornado setup self.enable_https = self.options['enable_https'] self.https_cert = self.options['https_cert'] self.https_key = self.options['https_key'] if self.enable_https: # If either the HTTPS certificate or key do not exist, make some self-signed ones. if not (self.https_cert and ek(os.path.exists, self.https_cert)) or not ( self.https_key and ek(os.path.exists, 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") sickbeard.ENABLE_HTTPS = False self.enable_https = False if not (ek(os.path.exists, self.https_cert) and ek(os.path.exists, self.https_key)): logger.log(u"Disabled HTTPS because of missing CERT and KEY files", logger.WARNING) sickbeard.ENABLE_HTTPS = False self.enable_https = False # Load the app self.app = Application( [], debug=True, autoreload=False, gzip=sickbeard.WEB_USE_GZIP, cookie_secret=sickbeard.WEB_COOKIE_SECRET, login_url='{0}/login/'.format(self.options['web_root']), ) # Main Handlers self.app.add_handlers('.*$', [ # webapi handler (r'{0}(/?.*)'.format(self.options['api_root']), ApiHandler), # webapi key retrieval (r'{0}/getkey(/?.*)'.format(self.options['web_root']), KeyHandler), # webapi builder redirect (r'{0}/api/builder'.format(self.options['web_root']), RedirectHandler, {"url": self.options['web_root'] + '/apibuilder/'}), # webui login/logout handlers (r'{0}/login(/?)'.format(self.options['web_root']), LoginHandler), (r'{0}/logout(/?)'.format(self.options['web_root']), LogoutHandler), # Web calendar handler (Needed because option Unprotected calendar) (r'{0}/calendar'.format(self.options['web_root']), CalendarHandler), # webui handlers ] + route.get_routes(self.options['web_root'])) # Static File Handlers self.app.add_handlers(".*$", [ # favicon (r'{0}/(favicon\.ico)'.format(self.options['web_root']), StaticFileHandler, {"path": ek(os.path.join, self.options['data_root'], 'images/ico/favicon.ico')}), # images (r'{0}/images/(.*)'.format(self.options['web_root']), StaticFileHandler, {"path": ek(os.path.join, self.options['data_root'], 'images')}), # cached images (r'{0}/cache/images/(.*)'.format(self.options['web_root']), StaticFileHandler, {"path": ek(os.path.join, sickbeard.CACHE_DIR, 'images')}), # css (r'{0}/css/(.*)'.format(self.options['web_root']), StaticFileHandler, {"path": ek(os.path.join, self.options['data_root'], 'css')}), # javascript (r'{0}/js/(.*)'.format(self.options['web_root']), StaticFileHandler, {"path": ek(os.path.join, self.options['data_root'], 'js')}), # fonts (r'{0}/fonts/(.*)'.format(self.options['web_root']), StaticFileHandler, {"path": ek(os.path.join, self.options['data_root'], 'fonts')}), # videos (r'{0}/videos/(.*)'.format(self.options['web_root']), StaticFileHandler, {"path": self.video_root}) ])
def __init__(self, options={}, io_loop=None): threading.Thread.__init__(self) self.name = "TORNADO" self.alive = True self.io_loop = io_loop or IOLoop.current() self.options = options self.options.setdefault('port', 8081) self.options.setdefault('host', '0.0.0.0') self.options.setdefault('log_dir', None) self.options.setdefault('username', '') self.options.setdefault('password', '') self.options.setdefault('web_root', '/') assert isinstance(self.options[b'port'], int) assert 'gui_root' in self.options # video root if sickbeard.ROOT_DIRS: root_dirs = sickbeard.ROOT_DIRS.split('|') self.video_root = root_dirs[int(root_dirs[0]) + 1] else: self.video_root = None # web root if self.options[b'web_root']: sickbeard.WEB_ROOT = self.options[b'web_root'] = ('/' + self.options[b'web_root'].lstrip('/').strip('/')) # api root if not sickbeard.API_KEY: sickbeard.API_KEY = generateApiKey() self.options[b'api_root'] = r'%s/api/%s' % (sickbeard.WEB_ROOT, sickbeard.API_KEY) # tornado setup self.enable_https = self.options[b'enable_https'] self.https_cert = self.options[b'https_cert'] self.https_key = self.options[b'https_key'] if self.enable_https: # If either the HTTPS certificate or key do not exist, make some self-signed ones. if not (self.https_cert and ek(os.path.exists, self.https_cert)) or not ( self.https_key and ek(os.path.exists, self.https_key)): if not create_https_certificates(self.https_cert, self.https_key): logging.info("Unable to create CERT/KEY files, disabling HTTPS") sickbeard.ENABLE_HTTPS = False self.enable_https = False if not (os.path.exists(self.https_cert) and ek(os.path.exists, self.https_key)): logging.warning("Disabled HTTPS because of missing CERT and KEY files") sickbeard.ENABLE_HTTPS = False self.enable_https = False # Load the app self.app = Application([], debug=sickbeard.DEBUG, autoreload=False, gzip=sickbeard.WEB_USE_GZIP, xheaders=sickbeard.HANDLE_REVERSE_PROXY, cookie_secret=sickbeard.WEB_COOKIE_SECRET, login_url='%s/login/' % self.options[b'web_root'], ) # Main Handlers self.app.add_handlers('.*$', [ # webapi handler (r'%s(/?.*)' % self.options[b'api_root'], ApiHandler), # webapi key retrieval (r'%s/getkey(/?.*)' % self.options[b'web_root'], KeyHandler), # webapi builder redirect (r'%s/api/builder' % self.options[b'web_root'], RedirectHandler, {"url": self.options[b'web_root'] + '/apibuilder/'}), # webui login/logout handlers (r'%s/login(/?)' % self.options[b'web_root'], LoginHandler), (r'%s/logout(/?)' % self.options[b'web_root'], LogoutHandler), # webui handlers ] + route.get_routes(self.options[b'web_root'])) # Web calendar handler (Needed because option Unprotected calendar) self.app.add_handlers('.*$', [ (r'%s/calendar' % self.options[b'web_root'], CalendarHandler), ]) # Static File Handlers self.app.add_handlers(".*$", [ # favicon (r'%s/(favicon\.ico)' % self.options[b'web_root'], StaticFileHandler, {"path": ek(os.path.join, self.options[b'gui_root'], 'images/ico/favicon.ico')}), # images (r'%s.*?/images/(.*)' % self.options[b'web_root'], StaticImageHandler, {"path": ek(os.path.join, self.options[b'gui_root'], 'images')}), # css (r'%s/css/(.*)' % self.options[b'web_root'], StaticFileHandler, {"path": ek(os.path.join, self.options[b'gui_root'], 'css')}), # javascript (r'%s/js/(.*)' % self.options[b'web_root'], StaticFileHandler, {"path": ek(os.path.join, self.options[b'gui_root'], 'js')}), # videos ] + [(r'%s/videos/(.*)' % self.options[b'web_root'], StaticFileHandler, {"path": self.video_root})])
def __init__(self, options=None, io_loop=None): threading.Thread.__init__(self) self.daemon = True self.alive = True self.name = 'TORNADO' self.io_loop = io_loop or IOLoop.current() self.options = options or {} self.options.setdefault('port', 8081) self.options.setdefault('host', '0.0.0.0') self.options.setdefault('log_dir', None) self.options.setdefault('username', '') self.options.setdefault('password', '') self.options.setdefault('web_root', '/') assert isinstance(self.options['port'], int) assert 'data_root' in self.options self.server = None # video root if app.ROOT_DIRS: root_dirs = app.ROOT_DIRS.split('|') self.video_root = root_dirs[int(root_dirs[0]) + 1] else: self.video_root = None # web root if self.options['web_root']: app.WEB_ROOT = self.options['web_root'] = ('/' + self.options['web_root'].lstrip('/').strip('/')) # api root if not app.API_KEY: app.API_KEY = generateApiKey() self.options['api_root'] = r'{root}/api/(?:v1/)?{key}'.format(root=app.WEB_ROOT, key=app.API_KEY) self.options['api_v2_root'] = r'{root}/api/v2'.format(root=app.WEB_ROOT) # tornado setup self.enable_https = self.options['enable_https'] self.https_cert = self.options['https_cert'] self.https_key = self.options['https_key'] if self.enable_https: # If either the HTTPS certificate or key do not exist, make some self-signed ones. if not (self.https_cert and os.path.exists(self.https_cert)) or not ( self.https_key and os.path.exists(self.https_key)): if not create_https_certificates(self.https_cert, self.https_key): logger.log('Unable to create CERT/KEY files, disabling HTTPS') app.ENABLE_HTTPS = False self.enable_https = False if not (os.path.exists(self.https_cert) and os.path.exists(self.https_key)): logger.log('Disabled HTTPS because of missing CERT and KEY files', logger.WARNING) app.ENABLE_HTTPS = False self.enable_https = False # Load the app self.app = Application( [], debug=True, autoreload=False, gzip=app.WEB_USE_GZIP, xheaders=app.HANDLE_REVERSE_PROXY, cookie_secret=app.WEB_COOKIE_SECRET, login_url=r'{root}/login/'.format(root=self.options['web_root']), ) # API v1 handlers self.app.add_handlers('.*$', [ # Main handler (r'{base}(/?.*)'.format(base=self.options['api_root']), ApiHandler), # Key retrieval (r'{base}/getkey(/?.*)'.format(base=self.options['web_root']), KeyHandler), # Builder redirect (r'{base}/api/builder'.format(base=self.options['web_root']), RedirectHandler, {'url': '{base}/apibuilder/'.format(base=self.options['web_root'])}), # Webui login/logout handlers (r'{base}/login(/?)'.format(base=self.options['web_root']), LoginHandler), (r'{base}/logout(/?)'.format(base=self.options['web_root']), LogoutHandler), # Web calendar handler (Needed because option Unprotected calendar) (r'{base}/calendar'.format(base=self.options['web_root']), CalendarHandler), # webui handlers ] + route.get_routes(self.options['web_root'])) # API v2 handlers self.app.add_handlers('.*$', [ # Shows handler (r'{base}/show/?([0-9]*)/?'.format(base=self.options['api_v2_root']), ShowHandler), (r'{base}/info/?([A-Za-z0-9_-]*)/?'.format(base=self.options['api_v2_root']), InfoHandler), (r'{base}/log/?(?P<log_level>[0-9]*)/?'.format(base=self.options['api_v2_root']), LogHandler) ]) # Static File Handlers self.app.add_handlers('.*$', [ # favicon (r'{base}/(favicon\.ico)'.format(base=self.options['web_root']), StaticFileHandler, {'path': os.path.join(self.options['data_root'], 'images/ico/favicon.ico')}), # images (r'{base}/images/(.*)'.format(base=self.options['web_root']), StaticFileHandler, {'path': os.path.join(self.options['data_root'], 'images')}), # cached images (r'{base}/cache/images/(.*)'.format(base=self.options['web_root']), StaticFileHandler, {'path': os.path.join(app.CACHE_DIR, 'images')}), # css (r'{base}/css/(.*)'.format(base=self.options['web_root']), StaticFileHandler, {'path': os.path.join(self.options['data_root'], 'css')}), # javascript (r'{base}/js/(.*)'.format(base=self.options['web_root']), StaticFileHandler, {'path': os.path.join(self.options['data_root'], 'js')}), # fonts (r'{base}/fonts/(.*)'.format(base=self.options['web_root']), StaticFileHandler, {'path': os.path.join(self.options['data_root'], 'fonts')}), # videos (r'{base}/videos/(.*)'.format(base=self.options['web_root']), StaticFileHandler, {'path': self.video_root}) ])
def __init__(self, options={}, io_loop=None): threading.Thread.__init__(self) self.name = "TORNADO" self.alive = True self.io_loop = io_loop or IOLoop.current() self.options = options self.options.setdefault('port', 8081) self.options.setdefault('host', '0.0.0.0') self.options.setdefault('log_dir', None) self.options.setdefault('username', '') self.options.setdefault('password', '') self.options.setdefault('web_root', '/') assert isinstance(self.options[b'port'], int) assert 'gui_root' in self.options # video root if sickbeard.ROOT_DIRS: root_dirs = sickbeard.ROOT_DIRS.split('|') self.video_root = root_dirs[int(root_dirs[0]) + 1] else: self.video_root = None # web root if self.options[b'web_root']: sickbeard.WEB_ROOT = self.options[b'web_root'] = ( '/' + self.options[b'web_root'].lstrip('/').strip('/')) # api root if not sickbeard.API_KEY: sickbeard.API_KEY = generateApiKey() self.options[b'api_root'] = r'%s/api/%s' % (sickbeard.WEB_ROOT, sickbeard.API_KEY) # tornado setup self.enable_https = self.options[b'enable_https'] self.https_cert = self.options[b'https_cert'] self.https_key = self.options[b'https_key'] if self.enable_https: # If either the HTTPS certificate or key do not exist, make some self-signed ones. if not (self.https_cert and ek(os.path.exists, self.https_cert)) or not ( self.https_key and ek(os.path.exists, self.https_key)): if not create_https_certificates(self.https_cert, self.https_key): logging.info( "Unable to create CERT/KEY files, disabling HTTPS") sickbeard.ENABLE_HTTPS = False self.enable_https = False if not (os.path.exists(self.https_cert) and ek(os.path.exists, self.https_key)): logging.warning( "Disabled HTTPS because of missing CERT and KEY files") sickbeard.ENABLE_HTTPS = False self.enable_https = False # Load the app self.app = Application( [], debug=sickbeard.DEBUG, autoreload=False, gzip=sickbeard.WEB_USE_GZIP, xheaders=sickbeard.HANDLE_REVERSE_PROXY, cookie_secret=sickbeard.WEB_COOKIE_SECRET, login_url='%s/login/' % self.options[b'web_root'], ) # Main Handlers self.app.add_handlers( '.*$', [ # webapi handler (r'%s(/?.*)' % self.options[b'api_root'], ApiHandler), # webapi key retrieval (r'%s/getkey(/?.*)' % self.options[b'web_root'], KeyHandler), # webapi builder redirect (r'%s/api/builder' % self.options[b'web_root'], RedirectHandler, { "url": self.options[b'web_root'] + '/apibuilder/' }), # webui login/logout handlers (r'%s/login(/?)' % self.options[b'web_root'], LoginHandler), (r'%s/logout(/?)' % self.options[b'web_root'], LogoutHandler), # webui handlers ] + route.get_routes(self.options[b'web_root'])) # Web calendar handler (Needed because option Unprotected calendar) self.app.add_handlers('.*$', [ (r'%s/calendar' % self.options[b'web_root'], CalendarHandler), ]) # Static File Handlers self.app.add_handlers( ".*$", [ # favicon (r'%s/(favicon\.ico)' % self.options[b'web_root'], StaticFileHandler, { "path": ek(os.path.join, self.options[b'gui_root'], 'images/ico/favicon.ico') }), # images (r'%s.*?/images/(.*)' % self.options[b'web_root'], StaticImageHandler, { "path": ek(os.path.join, self.options[b'gui_root'], 'images') }), # css (r'%s/css/(.*)' % self.options[b'web_root'], StaticFileHandler, { "path": ek(os.path.join, self.options[b'gui_root'], 'css') }), # javascript (r'%s/js/(.*)' % self.options[b'web_root'], StaticFileHandler, { "path": ek(os.path.join, self.options[b'gui_root'], 'js') }), # videos ] + [(r'%s/videos/(.*)' % self.options[b'web_root'], StaticFileHandler, { "path": self.video_root })])