def _RestoreSession(self, args): """Handle the restoresession NX command. "restoresession" requests an existing session be resumed. It requires parameters be specified. The following parameters have been seen, from which at least the session id must be specified: - C{--backingstore="1"} - C{--cache="16M"} - C{--client="linux"} - C{--composite="1"} - C{--encryption="1"} - C{--geometry="3840x1150"} - C{--id="A28EBF5AAC354E9EEAFEEB867980C543"} - C{--images="64M"} - C{--keyboard="pc102/gb"} - C{--link="lan"} - C{--media="0"} - C{--rootless="1"} - C{--screeninfo="3840x1150x24+render"} - C{--session="localtest"} - C{--shmem="1"} - C{--shpix="1"} - C{--strict="0"} - C{--type="unix-gnome"} - C{--virtualdesktop="0"} @type args: string @param args: Parameters """ ctx = self._ctx server = self._server mgr = ctx.session_mgr # Parse parameters params = self._GetParameters(args) parsed_params = dict(protocol.ParseParameters(params)) # Parameters will be checked in nxnode try: sessid = parsed_params["id"] except KeyError: raise protocol.NxProtocolError(500, ("Restore session requested, " "but no session specified")) logging.info("Restoring session %r", sessid) # Try to find session sess = mgr.LoadSessionForUser(sessid, ctx.username) if sess is None: raise protocol.NxProtocolError(500, "Failed to load session") sessid = sess.id logging.info("Found session %r in session database", sessid) # Connect to daemon and tell it to restore our session nodeclient = self._GetNodeClient(sessid, False) try: logging.debug("Sending restoresession command") nodeclient.RestoreSession(parsed_params) finally: nodeclient.Close() # Already running sessions take a bit longer to restart self._ConnectToSession(sessid, _SESSION_RESTORE_TIMEOUT)
def _AttachSession(self, args): """Handle the attachsession NX command. "attachsession" seems to request a new shadow session be started. It requires parameters be specified. The following parameters have been seen: - C{--backingstore="1"} - C{--cache="16M"} - C{--client="linux"} - C{--composite="1"} - C{--encryption="1"} - C{--geometry="3840x1150"} - C{--images="64M"} - C{--keyboard="pc102/gb"} - C{--link="lan"} - C{--media="0"} - C{--screeninfo="3840x1150x24+render"} - C{--session="localtest"} - C{--shmem="1"} - C{--shpix="1"} - C{--strict="0"} - C{--type="shadow"} @type args: string @param args: Parameters """ ctx = self._ctx server = self._server mgr = self._ctx.session_mgr # Parse parameters params = self._GetParameters(args) parsed_params = dict(protocol.ParseParameters(params)) # Parameters will be checked in nxnode try: shadowid = parsed_params["id"] except KeyError: raise protocol.NxProtocolError(500, ("Shadow session requested, " "but no session specified")) logging.info("Preparing to shadow session %r", shadowid) # Connect to daemon and ask for shadow cookie shadownodeclient = self._GetNodeClient(shadowid, False) try: logging.debug("Requesting shadow cookie from session %r", shadowid) shadowcookie = shadownodeclient.GetShadowCookie(None) finally: shadownodeclient.Close() logging.debug("Got shadow cookie %r", shadowcookie) sessid = mgr.CreateSessionID() logging.info("Starting new session %r", sessid) # Start nxnode daemon node.StartNodeDaemon(ctx.username, sessid) # Connect to daemon and tell it to shadow our session nodeclient = self._GetNodeClient(sessid, True) try: logging.debug("Sending attachsession command") nodeclient.AttachSession(parsed_params, shadowcookie) finally: nodeclient.Close() # Wait for session self._ConnectToSession(sessid, _SESSION_START_TIMEOUT)
def _ListSession(self, args): """Handle the listsession NX command. "listsession" requests a table of session information for the current user. It requires parameters be specified. The following parameters have been seen: - C{--geometry="1920x1200x24+render"}: This seems to specify the desired geometry. - C{--status="suspended,running"}: This seems to specify the desired type. - C{--type="unix-gnome"}: This seems to constrain the list to sessions in the given states. - C{--user="******"}: This seems to be ignored. No matter what is specified, the user given at login is used. @type args: string @param args: Parameters """ ctx = self._ctx server = self._server mgr = ctx.session_mgr # Parse parameters parsed_params = dict( protocol.ParseParameters(self._GetParameters(args))) # TODO: Accepted parameters # Ignore --user, as per commercial implementation # TODO: Check sessions from all users if type=shadow? This is problematic # due to file system access permissions. find_users = [self._ctx.username] find_types = None want_shadow = False # Ignoring --user, as per commercial implementation if "type" in parsed_params: types = parsed_params["type"].split(",") # If the type is shadow do the settings to get running sessions if types[0] == constants.SESS_TYPE_SHADOW: want_shadow = True else: find_types = types if want_shadow: find_states = constants.SESS_STATE_RUNNING elif "status" in parsed_params: find_states = parsed_params["status"].split(",") else: find_states = None sessions = self._ListSessionInner(find_types, find_states) server.Write(127, "Session list of user '%s':" % ctx.username) for line in utils.FormatTable(sessions, LISTSESSION_COLUMNS): server.WriteLine(line) server.WriteLine("") server.Write( 148, ("Server capacity: not reached for user: %s" % ctx.username))
def _StartSession(self, args): """Handle the startsession NX command. "startsession" seems to request a new session be started. It requires parameters be specified. The following parameters have been seen: - C{--backingstore="1"} - C{--cache="16M"} - C{--client="linux"} - C{--composite="1"} - C{--encryption="1"} - C{--fullscreen="0"} - C{--geometry="3840x1150"} - C{--images="64M"} - C{--keyboard="pc102/gb"} - C{--link="lan"} - C{--media="0"} - C{--rootless="0"} - C{--screeninfo="3840x1150x24+render"} - C{--session="localtest"} - C{--shmem="1"} - C{--shpix="1"} - C{--strict="0"} - C{--type="unix-gnome"} - C{--virtualdesktop="1"} Experiments with this command by directly invoking nxserver have not worked, as it refuses to create a session saying the unencrypted sessions are not supported. This is independent of whether the --encryption option has been set, so probably is related to the fact the nxserver has not been launched by sshd. @type args: string @param args: Parameters """ ctx = self._ctx mgr = ctx.session_mgr server = self._server # Parse parameters params = self._GetParameters(args) parsed_params = dict(protocol.ParseParameters(params)) # Parameters will be checked in nxnode sessid = mgr.CreateSessionID() logging.info("Starting new session %r", sessid) # Start nxnode daemon node.StartNodeDaemon(ctx.username, sessid) # Connect to daemon and tell it to start our session nodeclient = self._GetNodeClient(sessid, True) try: logging.debug("Sending startsession command") nodeclient.StartSession(parsed_params) finally: nodeclient.Close() # Wait for session self._ConnectToSession(sessid, _SESSION_START_TIMEOUT)
def _DoTest(self, params, expected): result = protocol.ParseParameters(params, _logging=self._fake_logging) self.failUnlessEqual(result, expected)