def startWebServer(self): log.info("Generating CherryPy configuration") # cherrypy.config.update(gamez.CONFIG_PATH) # Set Webinterface Path css_path = os.path.join(app_path, 'html', 'css') images_path = os.path.join(app_path, 'html', 'img') js_path = os.path.join(app_path, 'html', 'js') bootstrap_path = os.path.join(app_path, 'html', 'bootstrap') images = xdm.IMAGEPATH # Default config : there is no auth. def sha512(passwd): return hashlib.sha512(hashlib.sha512(passwd).hexdigest()).hexdigest() useAuth = False userPassDict = {} # get auth dictionnary from system plugins that contains credentials systemPlugins = common.PM.getSystem() for sysPlugin in systemPlugins: username = sysPlugin.c.getConfig('login_user') password = sysPlugin.hc.getConfig('login_password') if username and password: # if there is credentials in the plugin useAuth = True userPassDict[username.value] = password.value #checkpassword = cherrypy.lib.auth_basic.checkpassword_dict(userPassDict) conf = {'/': {'tools.basic_auth.on': useAuth, 'tools.basic_auth.realm': 'XDM', 'tools.basic_auth.users': userPassDict, 'tools.basic_auth.encrypt': sha512, 'tools.encode.encoding': 'utf-8'}, '/api': {'tools.auth_basic.on': False}, '/css': {'tools.staticdir.on': True, 'tools.staticdir.dir': css_path}, '/js': {'tools.staticdir.on': True, 'tools.staticdir.dir': js_path}, '/bootstrap': {'tools.staticdir.on': True, 'tools.staticdir.dir': bootstrap_path}, '/images': {'tools.staticdir.on': True, 'tools.staticdir.dir': images}, '/img': {'tools.staticdir.on': True, 'tools.staticdir.dir': images_path}, '/favicon.ico': {'tools.staticfile.on': True, 'tools.staticfile.filename': os.path.join(images_path, 'favicon.ico')} } common.PUBLIC_PATHS = list(conf.keys()) if common.SYSTEM.c.webRoot: # if this is always set even when False then https does not work options_dict = {'global': {'tools.proxy.on': True}} else: options_dict = {} sslCert_path = common.SYSTEM.c.https_cert_filepath sslKey_path = common.SYSTEM.c.https_key_filepath if common.SYSTEM.c.https: # If either the HTTPS certificate or key do not exist, make some self-signed ones. if not (sslCert_path and os.path.exists(sslCert_path)) or not (sslKey_path and os.path.exists(sslKey_path)): if not helper.create_https_certificates(sslCert_path, sslKey_path): log.error(u"Unable to create cert/key files, disabling HTTPS") common.SYSTEM.c.https = False if not (os.path.exists(sslCert_path) and os.path.exists(sslKey_path)): log.error(u"Disabled HTTPS because of missing CERT and KEY files") common.SYSTEM.c.https = False if common.SYSTEM.c.https: options_dict['server.ssl_certificate'] = sslCert_path options_dict['server.ssl_private_key'] = sslKey_path # Workoround for OSX. It seems have problem wit the autoreload engine if sys.platform.startswith('darwin') or sys.platform.startswith('win'): options_dict['engine.autoreload.on'] = False cherrypy.config.update(options_dict) cherrypy.config["tools.encode.on"] = True cherrypy.config["tools.encode.encoding"] = "utf-8" cherrypy.tools.stateBlock = cherrypy._cptools.HandlerTool(xdm.web.stateCheck) if common.SYSTEM.c.https: log.info("Starting the XDM https web server") else: log.info("Starting the XDM http web server") app_root = '/' if common.SYSTEM.c.webRoot: app_root = common.SYSTEM.c.webRoot common.CHERRYPY_APP = cherrypy.tree.mount(WebRoot(app_path), app_root, config=conf) helper.updateCherrypyPluginDirs() cherrypy.server.socket_host = common.SYSTEM.c.socket_host cherrypy.log.screen = False cherrypy.server.start() log.info("XDM web server running") cherrypy.server.wait() # from couchpotato host = common.SYSTEM.c.socket_host https = common.SYSTEM.c.https try: if not (common.STARTOPTIONS.nolaunch or common.SYSTEM.c.dont_open_browser): log.info("launch Browser %s:%s" % (host, self.port)) launchBrowser(host, self.port, https) except: pass
def startWebServer(self): log.info("Generating CherryPy configuration") # cherrypy.config.update(gamez.CONFIG_PATH) # Set Webinterface Path css_path = os.path.join(app_path, 'html', 'css') images_path = os.path.join(app_path, 'html', 'img') js_path = os.path.join(app_path, 'html', 'js') bootstrap_path = os.path.join(app_path, 'html', 'bootstrap') images = xdm.IMAGEPATH username = common.SYSTEM.c.login_user password = common.SYSTEM.c.login_password useAuth = False if username and password: useAuth = True userPassDict = {username: password} checkpassword = cherrypy.lib.auth_basic.checkpassword_dict( userPassDict) conf = { '/': { 'tools.auth_basic.on': useAuth, 'tools.auth_basic.realm': 'XDM', 'tools.auth_basic.checkpassword': checkpassword, 'tools.encode.encoding': 'utf-8' }, '/api': { 'tools.auth_basic.on': False }, '/css': { 'tools.staticdir.on': True, 'tools.staticdir.dir': css_path }, '/js': { 'tools.staticdir.on': True, 'tools.staticdir.dir': js_path }, '/bootstrap': { 'tools.staticdir.on': True, 'tools.staticdir.dir': bootstrap_path }, '/images': { 'tools.staticdir.on': True, 'tools.staticdir.dir': images }, '/img': { 'tools.staticdir.on': True, 'tools.staticdir.dir': images_path }, '/favicon.ico': { 'tools.staticfile.on': True, 'tools.staticfile.filename': os.path.join(images_path, 'favicon.ico') } } common.PUBLIC_PATHS = list(conf.keys()) if common.SYSTEM.c.webRoot: # if this is always set even when False then https does not work options_dict = {'global': {'tools.proxy.on': True}} else: options_dict = {} sslCert_path = common.SYSTEM.c.https_cert_filepath sslKey_path = common.SYSTEM.c.https_key_filepath if common.SYSTEM.c.https: # If either the HTTPS certificate or key do not exist, make some self-signed ones. if not (sslCert_path and os.path.exists(sslCert_path)) or not ( sslKey_path and os.path.exists(sslKey_path)): if not helper.create_https_certificates( sslCert_path, sslKey_path): log.error( u"Unable to create cert/key files, disabling HTTPS") common.SYSTEM.c.https = False if not (os.path.exists(sslCert_path) and os.path.exists(sslKey_path)): log.error( u"Disabled HTTPS because of missing CERT and KEY files") common.SYSTEM.c.https = False if common.SYSTEM.c.https: options_dict['server.ssl_certificate'] = sslCert_path options_dict['server.ssl_private_key'] = sslKey_path # Workoround for OSX. It seems have problem wit the autoreload engine if sys.platform.startswith('darwin') or sys.platform.startswith('win'): options_dict['engine.autoreload.on'] = False cherrypy.config.update(options_dict) cherrypy.config["tools.encode.on"] = True cherrypy.config["tools.encode.encoding"] = "utf-8" cherrypy.tools.stateBlock = cherrypy._cptools.HandlerTool( xdm.web.stateCheck) if common.SYSTEM.c.https: log.info("Starting the XDM https web server") else: log.info("Starting the XDM http web server") app_root = '/' if common.SYSTEM.c.webRoot: app_root = common.SYSTEM.c.webRoot common.CHERRYPY_APP = cherrypy.tree.mount(WebRoot(app_path), app_root, config=conf) helper.updateCherrypyPluginDirs() cherrypy.server.socket_host = common.SYSTEM.c.socket_host cherrypy.log.screen = False cherrypy.server.start() log.info("XDM web server running") cherrypy.server.wait() # from couchpotato host = common.SYSTEM.c.socket_host https = common.SYSTEM.c.https try: if not (common.STARTOPTIONS.nolaunch or common.SYSTEM.c.dont_open_browser): log.info("launch Browser %s:%s" % (host, self.port)) launchBrowser(host, self.port, https) except: pass
def startWebServer(self): log.info("Generating CherryPy configuration") #cherrypy.config.update(gamez.CONFIG_PATH) # Set Webinterface Path css_path = os.path.join(app_path, 'html', 'css') images_path = os.path.join(app_path, 'html', 'img') js_path = os.path.join(app_path, 'html', 'js') bootstrap_path = os.path.join(app_path, 'html', 'bootstrap') images = xdm.IMAGEPATH username = common.SYSTEM.c.login_user password = common.SYSTEM.c.login_password useAuth = False if username and password: useAuth = True userPassDict = {username: password} checkpassword = cherrypy.lib.auth_basic.checkpassword_dict(userPassDict) conf = {'/': {'tools.auth_basic.on': useAuth, 'tools.auth_basic.realm': 'Gamez', 'tools.auth_basic.checkpassword': checkpassword}, '/api': {'tools.auth_basic.on': False}, '/css': {'tools.staticdir.on': True, 'tools.staticdir.dir': css_path}, '/js': {'tools.staticdir.on': True, 'tools.staticdir.dir': js_path}, '/bootstrap': {'tools.staticdir.on': True, 'tools.staticdir.dir': bootstrap_path}, '/images': {'tools.staticdir.on': True, 'tools.staticdir.dir': images}, '/img': {'tools.staticdir.on': True, 'tools.staticdir.dir': images_path}, '/favicon.ico': {'tools.staticfile.on': True, 'tools.staticfile.filename': os.path.join(images_path, 'favicon.ico')} } conf.update(self.pluginResPaths) if common.SYSTEM.c.webRoot: # if this is always set even when False then https does not work options_dict = {'global': {'tools.proxy.on': True}} else: options_dict = {} sslCert_path = common.SYSTEM.c.https_cert_filepath sslKey_path = common.SYSTEM.c.https_key_filepath if common.SYSTEM.c.https: # If either the HTTPS certificate or key do not exist, make some self-signed ones. if not (sslCert_path and os.path.exists(sslCert_path)) or not (sslKey_path and os.path.exists(sslKey_path)): if not helper.create_https_certificates(sslCert_path, sslKey_path): log.error(u"Unable to create cert/key files, disabling HTTPS") common.SYSTEM.c.https = False if not (os.path.exists(sslCert_path) and os.path.exists(sslKey_path)): log.error(u"Disabled HTTPS because of missing CERT and KEY files") common.SYSTEM.c.https = False if common.SYSTEM.c.https: options_dict['server.ssl_certificate'] = sslCert_path options_dict['server.ssl_private_key'] = sslKey_path # Workoround for OSX. It seems have problem wit the autoreload engine if sys.platform.startswith('darwin') or sys.platform.startswith('win'): options_dict['engine.autoreload.on'] = False cherrypy.config.update(options_dict) if common.SYSTEM.c.https: log.info("Starting the XDM https web server") else: log.info("Starting the XDM http web server") cherrypy.tree.mount(WebRoot(app_path), config=conf) cherrypy.server.socket_host = common.SYSTEM.c.socket_host cherrypy.log.screen = False cherrypy.server.start() log.info("XDM web server running") common.SM.setNewMessage("Up and running.") common.SM.setNewMessage("Done!") cherrypy.server.wait() # from couchpotato host = common.SYSTEM.c.socket_host https = common.SYSTEM.c.https try: if not (common.STARTOPTIONS.nolaunch or common.SYSTEM.c.dont_open_browser): print "------------------- launch Browser ( " + str(host) + ":" + str(self.port) + ") -------------------" launchBrowser(host, self.port, https) except: pass
def startWebServer(self): log.info("Generating CherryPy configuration") #cherrypy.config.update(gamez.CONFIG_PATH) # Set Webinterface Path css_path = os.path.join(app_path, 'html', 'css') images_path = os.path.join(app_path, 'html', 'img') js_path = os.path.join(app_path, 'html', 'js') bootstrap_path = os.path.join(app_path, 'html', 'bootstrap') images = xdm.IMAGEPATH username = common.SYSTEM.c.login_user password = common.SYSTEM.c.login_password useAuth = False if username and password: useAuth = True userPassDict = {username: password} checkpassword = cherrypy.lib.auth_basic.checkpassword_dict( userPassDict) conf = { '/': { 'tools.auth_basic.on': useAuth, 'tools.auth_basic.realm': 'Gamez', 'tools.auth_basic.checkpassword': checkpassword }, '/api': { 'tools.auth_basic.on': False }, '/css': { 'tools.staticdir.on': True, 'tools.staticdir.dir': css_path }, '/js': { 'tools.staticdir.on': True, 'tools.staticdir.dir': js_path }, '/bootstrap': { 'tools.staticdir.on': True, 'tools.staticdir.dir': bootstrap_path }, '/images': { 'tools.staticdir.on': True, 'tools.staticdir.dir': images }, '/img': { 'tools.staticdir.on': True, 'tools.staticdir.dir': images_path }, '/favicon.ico': { 'tools.staticfile.on': True, 'tools.staticfile.filename': os.path.join(images_path, 'favicon.ico') } } conf.update(self.pluginResPaths) options_dict = { 'global': { 'tools.proxy.on': bool(common.SYSTEM.c.webRoot) } } #TODO HTTPS support look at sb cp sab and others sslCert_path = common.SYSTEM.c.https_cert_filepath sslKey_path = common.SYSTEM.c.https_key_filepath if common.SYSTEM.c.https: # If either the HTTPS certificate or key do not exist, make some self-signed ones. if not (sslCert_path and os.path.exists(sslCert_path)) or not ( sslKey_path and os.path.exists(sslKey_path)): if not helper.create_https_certificates( sslCert_path, sslKey_path): log.error( u"Unable to create cert/key files, disabling HTTPS") common.SYSTEM.c.https = False if not (os.path.exists(sslCert_path) and os.path.exists(sslKey_path)): log.error( u"Disabled HTTPS because of missing CERT and KEY files") common.SYSTEM.c.https = False if common.SYSTEM.c.https: options_dict['server.ssl_certificate'] = sslCert_path options_dict['server.ssl_private_key'] = sslKey_path cherrypy.config.update(options_dict) # Workoround for OSX. It seems have problem wit the autoreload engine if sys.platform.startswith('darwin') or sys.platform.startswith('win'): cherrypy.config.update({'engine.autoreload.on': False}) log.info("Starting the XDM web server") cherrypy.tree.mount(WebRoot(app_path), config=conf) cherrypy.server.socket_host = common.SYSTEM.c.socket_host cherrypy.log.screen = False cherrypy.server.start() log.info("XDM web server running") common.SM.setNewMessage("Up and running.") common.SM.setNewMessage("Done!") cherrypy.server.wait() # from couchpotato host = common.SYSTEM.c.socket_host https = common.SYSTEM.c.https try: if not (common.STARTOPTIONS.nolaunch or common.SYSTEM.c.dont_open_browser): print "------------------- launch Browser ( " + str( host) + ":" + str(self.port) + ") -------------------" launchBrowser(host, self.port, https) except: pass