Пример #1
0
    def testGetUniqIdUniq(self):
        """Test case for nxsession.gen_uniq_id to ensure ID is unique"""

        first = nxsession.gen_uniq_id()

        time.sleep(1)

        second = nxsession.gen_uniq_id()

        self.assertNotEqual(first, second)
Пример #2
0
  def testGetUniqIdUniq(self):
    """Test case for nxsession.gen_uniq_id to ensure ID is unique"""

    first = nxsession.gen_uniq_id()

    time.sleep(1)

    second = nxsession.gen_uniq_id()

    self.assertNotEqual(first, second)
Пример #3
0
    def testConstructorCookieIsUniqId(self):

        old_id = nxsession.gen_uniq_id()

        time.sleep(1)

        # Make sure the id from the generator is now different
        self.assertNotEqual(old_id, nxsession.gen_uniq_id())

        o = nxsession.nxsession('')

        self.failUnless('cookie' in o.params)
        self.assertNotEqual(old_id, o.params['cookie'])
Пример #4
0
  def testConstructorCookieIsUniqId(self):

    old_id = nxsession.gen_uniq_id()

    time.sleep(1)

    # Make sure the id from the generator is now different
    self.assertNotEqual(old_id, nxsession.gen_uniq_id())

    o = nxsession.nxsession('')

    self.failUnless('cookie' in o.params)
    self.assertNotEqual(old_id, o.params['cookie'])
Пример #5
0
    def testConstructorAcceptsCookie(self):
        """Test a cookie paramete is read from vars"""

        cookie = nxsession.gen_uniq_id()

        time.sleep(1)

        # Make sure the id from the generator is now different
        self.assertNotEqual(cookie, nxsession.gen_uniq_id())

        o = nxsession.nxsession('cookie=%s' % cookie)

        self.failUnless('cookie' in o.params)
        self.assertEqual(cookie, o.params['cookie'])
Пример #6
0
  def testConstructorAcceptsCookie(self):
    """Test a cookie paramete is read from vars"""

    cookie = nxsession.gen_uniq_id()

    time.sleep(1)

    # Make sure the id from the generator is now different
    self.assertNotEqual(cookie, nxsession.gen_uniq_id())

    o = nxsession.nxsession('cookie=%s' % cookie)

    self.failUnless('cookie' in o.params)
    self.assertEqual(cookie, o.params['cookie'])
Пример #7
0
        def __init__(self, id, args):
            """node_session constructor

            Args:
              args: The id of the session, followed by all the other
                    parameters the client requested
            """

            self.id = id
            self.args = args
            self.display = self._gen_disp_num()
            self.hostname = socket.getfqdn()
            self.full_id = "%s-%s-%s" % (self.hostname, self.display, self.id)
            self.cookie = nxsession.gen_uniq_id()
            self.dir = os.path.join('/tmp/nx', 'S-%s' % self.full_id)
            # FIXME(diamond): needs error checking, maybe different mode
            os.makedirs(self.dir, 0755)
            self.opts_file_path = os.path.join(self.dir, 'options')
            self.args_file_path = os.path.join(self.dir, 'args')
            self.application = self.args.get('application')
            self.user = pwd.getpwuid(os.getuid())[0]
            self.name = self.args.get('session',
                                      "%s:%s" % (self.hostname, self.display))
            self.keyboard = self.args.get('keyboard', 'pc105/gb')
            self.geometry = self.args.get('geometry', '640x480')
            self.client = self.args.get('client', 'unknown')
            self.link = self.args.get('link', 'isdn')
            self.fullscreen = self.args.get('fullscreen', '0')
            # DEBUG, FIXME(diamond): all of these
            self.type = self.args.get('type', 'unix-default')
            self.options = '-----PSA'  # FIXME(diamond): see note in self.info()
            self.depth = 24
            self.resolution = "640x480"
            # FIXME(diamond): Not ipv6 compatible
            self.proxyip = socket.gethostbyname(self.hostname)
            self.ssl = 1
            # End DEBUG/FIXME(diamond)

            if self.type == 'unix-application':
                assert (self.application)
                self.mode = '-R'  # Run nxagent in rootless mode
            else:
                self.mode = '-D'  # Run nxagent in desktop mode

            # We need to write the type without the 'unix-' prefix for nxagent.
            if self.type.startswith('unix-'):
                self.shorttype = self.type.split('-', 1)[1]
            else:
                self.shorttype = self.type

            self._write_args()
            self._write_opts()
Пример #8
0
    def __init__(self, id, args):
      """node_session constructor

      Args:
        args: The id of the session, followed by all the other
              parameters the client requested
      """

      self.id = id
      self.args = args
      self.display = self._gen_disp_num()
      self.hostname = socket.getfqdn()
      self.full_id = "%s-%s-%s" % (self.hostname, self.display, self.id)
      self.cookie = nxsession.gen_uniq_id()
      self.dir = os.path.join('/tmp/nx', 'S-%s' % self.full_id)
      #FIXME(diamond): needs error checking, maybe different mode
      os.makedirs(self.dir, 0755)
      self.opts_file_path = os.path.join(self.dir, 'options') 
      self.args_file_path = os.path.join(self.dir, 'args') 
      self.application = self.args.get('application')
      self.user = pwd.getpwuid(os.getuid())[0]
      self.name = self.args.get('session', "%s:%s" % (self.hostname, self.display))
      self.keyboard = self.args.get('keyboard', 'pc105/gb')
      self.geometry = self.args.get('geometry', '640x480')
      self.client = self.args.get('client', 'unknown')
      self.link = self.args.get('link', 'isdn')
      self.fullscreen = self.args.get('fullscreen', '0')
      #DEBUG, FIXME(diamond): all of these
      self.type = self.args.get('type', 'unix-default')
      self.options = '-----PSA' #FIXME(diamond): see note in self.info()
      self.depth = 24
      self.resolution = "640x480"
      #FIXME(diamond): Not ipv6 compatible
      self.proxyip = socket.gethostbyname(self.hostname)
      self.ssl = 1
      #End DEBUG/FIXME(diamond)

      if self.type == 'unix-application':
        assert(self.application)
        self.mode = '-R' # Run nxagent in rootless mode
      else:
        self.mode = '-D' # Run nxagent in desktop mode

      # We need to write the type without the 'unix-' prefix for nxagent.
      if self.type.startswith('unix-'):
        self.shorttype = self.type.split('-', 1)[1]
      else:
        self.shorttype = self.type

      self._write_args()
      self._write_opts()
Пример #9
0
    def _nx_startsession_handler(self, command):
        """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.
    '--link="lan"'
    '--backingstore="1"'
    '--encryption="1"'
    '--cache="16M"'
    '--images="64M"'
    '--shmem="1"'
    '--shpix="1"'
    '--strict="0"'
    '--composite="1"'
    '--media="0"'
    '--session="localtest"'
    '--type="unix-gnome"'
    '--geometry="3840x1150"'
    '--client="linux"'
    '--keyboard="pc102/gb"'
    '--screeninfo="3840x1150x24+render"'
    Experiments with this command by directly invoked 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.

    Args:
      command: The NX command and arguments invoked

    Returns:
      None
    """

        # Basic checking of the right status
        if self.status < self.STATUS_LOGGEDIN:
            self.prompt(
                554, 'Error: the command \'%s\' cannot '
                'be called before login' % command[0])
            return
        # Make sure the state is consistent
        assert (hasattr(self, 'username'))
        # Ask for parameters if none have been given
        if len(command) > 1:
            parameters = command[1:]
        else:
            self.prompt(106, 'Parameters: ', override_newline=False)
            response = self.input.readline()
            self.write('')  # Do newline after parameters.
            parameters = response.split()
        # Check the parameters fit with the expected syntax
        for param in parameters:
            key, val = self._parse_param(param)
            # FIXME(diamond): DO something with the params.
        # FIXME(diamond): Start the session.
        if not hasattr(self, 'nxnode_commfd'):
            nxlog.log(nxlog.LOG_ERR, 'Nxserver does not have an nxnode yet.')
            return
        # Send the command to the connected nxnode running
        # FIXME(diamond): Convert the arguments to the form expected by nxnode.
        sess_id = nxsession.gen_uniq_id()
        self.write('startsession %s %s' % (sess_id, " ".join(parameters)),
                   fd=self.nxnode_wfile)

        if self.daemonize():
            # Two threads return here, one connected to the client, one connected to
            # nxnode.
            self.running = False
            return

        start_waiting = time.time()
        wait_time = 30  #FIXME(diamond): make configurable
        while True:
            if time.time() - start_waiting > wait_time:
                nxlog.log(
                    nxlog.LOG_ERR, "Session %s has not appeared in session db "
                    "within %d seconds\n" % (sess_id, wait_time))
                sys.exit(1)
                #FIXME(diamond): raise proper error
            sessions = nxsession.db_find_sessions(id=sess_id)
            if len(sessions) == 1:
                sess = sessions[0]
                nxlog.log(
                    nxlog.LOG_DEBUG,
                    "Session %s has appeared in session db\n" %
                    sess.params['full_id'])
                break
            elif len(sessions) > 1:
                nxlog.log(
                    nxlog.LOG_DEBUG, "Multiple sessions matching %d have been "
                    "found in the session db: %r\n" % sess_id)
                #FIXME(diamond): raise proper error
                break
            else:
                time.sleep(1)

        self.__print_sess_info(sess)

        start_waiting = time.time()
        wait_time = 30  #FIXME(diamond): make configurable
        while True:
            if time.time() - start_waiting > wait_time:
                nxlog.log(
                    nxlog.LOG_ERR,
                    "Session %s has not achieved running status "
                    "within %d seconds\n" % (sess_id, wait_time))
                sys.exit(1)
                #FIXME(diamond): raise proper error
            sess.reload()
            if sess.params['state'] == 'starting':
                break
            elif sess.params['state'] in ['terminating', 'terminated']:
                nxlog.log(
                    nxlog.LOG_ERR, "Session %(full_id)s has status "
                    "'%(state)s', exiting." % sess.params)
                self.prompt(
                    500, "Error: Session %(full_id)s has status '%(state)s'." %
                    sess.params)
                self.prompt(999, "Bye.")
                self.running = False
                return
                #FIXME(diamond): raise proper error
            else:
                time.sleep(1)
        self.prompt(710, 'Session status: %s' % sess.params['state'])
        #FIXME(diamond): use configurable offset
        self.port = int(sess.params['display']) + 4000
Пример #10
0
    def testGetUniqId(self):
        """Test case for nxsession.gen_uniq_id function"""

        self.failUnless(nxsession.gen_uniq_id())
Пример #11
0
  def _nx_startsession_handler(self, command):
    """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.
    '--link="lan"'
    '--backingstore="1"'
    '--encryption="1"'
    '--cache="16M"'
    '--images="64M"'
    '--shmem="1"'
    '--shpix="1"'
    '--strict="0"'
    '--composite="1"'
    '--media="0"'
    '--session="localtest"'
    '--type="unix-gnome"'
    '--geometry="3840x1150"'
    '--client="linux"'
    '--keyboard="pc102/gb"'
    '--screeninfo="3840x1150x24+render"'
    Experiments with this command by directly invoked 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.

    Args:
      command: The NX command and arguments invoked

    Returns:
      None
    """

    # Basic checking of the right status
    if self.status < self.STATUS_LOGGEDIN:
      self.prompt(554, 'Error: the command \'%s\' cannot '
          'be called before login' % command[0])
      return
    # Make sure the state is consistent
    assert(hasattr(self, 'username'))
    # Ask for parameters if none have been given
    if len(command) > 1:
      parameters = command[1:]
    else:
      self.prompt(106, 'Parameters: ', override_newline=False)
      response = self.input.readline()
      self.write('') # Do newline after parameters.
      parameters = response.split()
    # Check the parameters fit with the expected syntax
    for param in parameters:
      key,val = self._parse_param(param)
      # FIXME(diamond): DO something with the params.
    # FIXME(diamond): Start the session.
    if not hasattr(self, 'nxnode_commfd'):
      nxlog.log(nxlog.LOG_ERR, 'Nxserver does not have an nxnode yet.')
      return
    # Send the command to the connected nxnode running
    # FIXME(diamond): Convert the arguments to the form expected by nxnode.
    sess_id = nxsession.gen_uniq_id()
    self.write('startsession %s %s' %
        (sess_id, " ".join(parameters)), fd=self.nxnode_wfile)

    if self.daemonize():
    # Two threads return here, one connected to the client, one connected to
    # nxnode.
      self.running = False
      return

    start_waiting = time.time()
    wait_time = 30 #FIXME(diamond): make configurable
    while True:
      if time.time() - start_waiting > wait_time:
        nxlog.log(nxlog.LOG_ERR, "Session %s has not appeared in session db "
            "within %d seconds\n" % (sess_id, wait_time))
        sys.exit(1)
        #FIXME(diamond): raise proper error
      sessions = nxsession.db_find_sessions(id=sess_id)
      if len(sessions) == 1:
        sess = sessions[0]
        nxlog.log(nxlog.LOG_DEBUG, "Session %s has appeared in session db\n" %
            sess.params['full_id'])
        break
      elif len(sessions) > 1:
        nxlog.log(nxlog.LOG_DEBUG, "Multiple sessions matching %d have been "
            "found in the session db: %r\n" % sess_id)
        #FIXME(diamond): raise proper error
        break
      else:
        time.sleep(1)

    self.__print_sess_info(sess)

    start_waiting = time.time()
    wait_time = 30 #FIXME(diamond): make configurable
    while True:
      if time.time() - start_waiting > wait_time:
        nxlog.log(nxlog.LOG_ERR, "Session %s has not achieved running status "
            "within %d seconds\n" % (sess_id, wait_time))
        sys.exit(1)
        #FIXME(diamond): raise proper error
      sess.reload()
      if sess.params['state'] == 'starting':
        break
      elif sess.params['state'] in ['terminating', 'terminated']:
        nxlog.log(nxlog.LOG_ERR, "Session %(full_id)s has status "
            "'%(state)s', exiting." % sess.params)
        self.prompt(500, "Error: Session %(full_id)s has status '%(state)s'." %
            sess.params)
        self.prompt(999, "Bye.")
        self.running = False
        return
        #FIXME(diamond): raise proper error
      else:
        time.sleep(1)
    self.prompt(710, 'Session status: %s' % sess.params['state'])
    #FIXME(diamond): use configurable offset
    self.port = int(sess.params['display']) + 4000
Пример #12
0
  def testGetUniqId(self):
    """Test case for nxsession.gen_uniq_id function"""

    self.failUnless(nxsession.gen_uniq_id())