def _configure_server(restarting=False): global websocket_plugin # Configure server error log cherrypy.config.update({'log.error_file': 'cherrypy.error.log'}) # Configure server url cherrypy.config.update({'server.socket_host': utils.s2n(autosubliminal.WEBSERVERIP), 'server.socket_port': int(autosubliminal.WEBSERVERPORT) }) # Disable engine plugins (no need for autoreload plugin) cherrypy.config.update({'engine.autoreload.on': False}) # Configure authentication in if a username and password is set by the user if autosubliminal.USERNAME and autosubliminal.PASSWORD: users = {utils.s2n(autosubliminal.USERNAME): utils.s2n(autosubliminal.PASSWORD)} cherrypy.config.update({'tools.auth_digest.on': True, 'tools.auth_digest.realm': 'Auto-Subliminal website', 'tools.auth_digest.get_ha1': auth_digest.get_ha1_dict_plain(users), 'tools.auth_digest.key': 'yek.tsegid_htua.lanimilbuS-otuA' # Can be any random string }) if not restarting: # Enable websocket plugin websocket_plugin = WebSocketPlugin(cherrypy.engine) websocket_plugin.subscribe() cherrypy.tools.websocket = WebSocketTool() else: # When restarting we need to create a new websocket manager thread (you cannot start the same thread twice!) websocket_plugin.manager = WebSocketManager() # When restarting we need to clear the httpserver to force the creation of a new one (needed for ip/port change) cherrypy.server.httpserver = None
def _configure_server(restarting=False): global websocket_plugin # Configure server error log cherrypy.config.update({'log.error_file': 'cherrypy.error.log'}) # Configure server url cherrypy.config.update({ 'server.socket_host': s2n(autosubliminal.WEBSERVERIP), 'server.socket_port': int(autosubliminal.WEBSERVERPORT) }) # Disable engine plugins (no need for autoreload plugin) cherrypy.config.update({'engine.autoreload.on': False}) # Read and store cherrypy server version (if not set, it returns CherryPy/Unknown because it's not installed) server_header = 'CherryPy/%s' % get_library_version('cherrypy') cherrypy.config.update({'response.headers.server': server_header}) # Configure authentication in if a username and password is set by the user if autosubliminal.USERNAME and autosubliminal.PASSWORD: users = {s2n(autosubliminal.USERNAME): s2n(autosubliminal.PASSWORD)} cherrypy.config.update({ 'tools.auth_digest.on': True, 'tools.auth_digest.realm': 'Auto-Subliminal website', 'tools.auth_digest.get_ha1': auth_digest.get_ha1_dict_plain(users), 'tools.auth_digest.key': 'yek.tsegid_htua.lanimilbuS-otuA' # Can be any random string }) # Configure our custom json_out_handler (Uncomment if it should be used for any @cherrypy.tools.json_out()) # cherrypy.config.update({'tools.json_out.handler': json_out_handler}) if not restarting: # Enable websocket plugin websocket_plugin = WebSocketPlugin(cherrypy.engine) websocket_plugin.subscribe() cherrypy.tools.websocket = WebSocketTool() else: # When restarting we need to create a new websocket manager thread (you cannot start the same thread twice!) websocket_plugin.manager = WebSocketManager() # When restarting we need to clear the httpserver to force the creation of a new one (needed for ip/port change) cherrypy.server.httpserver = None
def start_cherrypy_debug_server(htdocs_path, http_host, http_port, mpd_host, mpd_port=6600, mpd_password=None): # set cherrypy configuration. cherrypy.config.update({'server.socket_port': http_port}) cherrypy.config.update({'server.socket_host': http_host}) if (not os.path.isdir(htdocs_path)): print("=" * 80 + """ The ympd htdocs dir is not available: perhaps the git submodule is missing? """ + "=" * 80) sys.exit(1) # Add the websocket requirements. a = WebSocketPlugin(cherrypy.engine) a.manager = WebSocketManager() a.subscribe() cherrypy.tools.websocket = WebSocketTool() web_root = Root() # get a function to instantiate the websocket with the correct settings. ympd_websocket = ympdWebSocket_wrap(mpd_host, mpd_port, mpd_password) # Run a no-websocket alternative at http://hostname:port/nows/ nowebsocket = ympdNoWebSocket_wrap(mpd_host, mpd_port, mpd_password) web_root.nows = nowebsocket(htdocs_path) # this implementation uses POST requests communicate. # Takes a little bit longer for the UI to update, but it should get through # firewalls and proxies where the websocket cannot. cherrypy.quickstart(web_root, '/', config={ '/ws': {'tools.websocket.on': True, 'tools.websocket.handler_cls': ympd_websocket}, '/': {'tools.staticdir.on': True, 'tools.staticdir.dir': os.path.join(htdocs_path), "tools.staticdir.index": "index.html"}, } )
def _configure_server(restarting=False): global websocket_plugin # Configure server error log cherrypy.config.update({'log.error_file': 'cherrypy.error.log'}) # Configure server url cherrypy.config.update({'server.socket_host': s2n(autosubliminal.WEBSERVERIP), 'server.socket_port': int(autosubliminal.WEBSERVERPORT) }) # Disable engine plugins (no need for autoreload plugin) cherrypy.config.update({'engine.autoreload.on': False}) # Read and store cherrypy server version (if not set, it returns CherryPy/Unknown because it's not installed) server_header = 'CherryPy/%s' % get_library_version('cherrypy') cherrypy.config.update({'response.headers.server': server_header}) # Configure authentication in if a username and password is set by the user if autosubliminal.USERNAME and autosubliminal.PASSWORD: users = {s2n(autosubliminal.USERNAME): s2n(autosubliminal.PASSWORD)} cherrypy.config.update({'tools.auth_digest.on': True, 'tools.auth_digest.realm': 'Auto-Subliminal website', 'tools.auth_digest.get_ha1': auth_digest.get_ha1_dict_plain(users), 'tools.auth_digest.key': 'yek.tsegid_htua.lanimilbuS-otuA' # Can be any random string }) # Configure our custom json_out_handler (Uncomment if it should be used for any @cherrypy.tools.json_out()) # cherrypy.config.update({'tools.json_out.handler': json_out_handler}) if not restarting: # Enable websocket plugin websocket_plugin = WebSocketPlugin(cherrypy.engine) websocket_plugin.subscribe() cherrypy.tools.websocket = WebSocketTool() else: # When restarting we need to create a new websocket manager thread (you cannot start the same thread twice!) websocket_plugin.manager = WebSocketManager() # When restarting we need to clear the httpserver to force the creation of a new one (needed for ip/port change) cherrypy.server.httpserver = None
formatter = logging.Formatter('%(name)s - %(asctime)s - %(levelname)s' ' - %(message)s') ch.setFormatter(formatter) interface_logger.addHandler(ch) # create the preset folder if it does not exist: preset_dir = os.path.abspath(args.presetdir) if (not os.path.isdir(preset_dir)): print("Preset folder {} did not exist, creating.".format(preset_dir)) os.makedirs(preset_dir) # Add the websocket requirements. cherrypy.tools.websocket = WebSocketTool() a = WebSocketPlugin(cherrypy.engine) a.manager = WebSocketManager() a.subscribe() stack_interface = interface.StackInterface() stack_interface.daemon = True stack_interface.start() server_tree = FocusStackRoot(stack_interface, preset_dir=preset_dir) # create a broadcast function which relays messages received over the # serial port to the websockets via the websocketmanager. def broadcaster(): m = stack_interface.get_message() if m: payload = dict(m) payload["msg_type"] = message.msg_type_name[payload["msg_type"]] msg = ["serial", payload]