Package x2go :: Package backends :: Package proxy :: Module _nx3
[frames] | no frames]

Source Code for Module x2go.backends.proxy._nx3

  1  # -*- coding: utf-8 -*- 
  2   
  3  # Copyright (C) 2010-2014 by Mike Gabriel <mike.gabriel@das-netzwerkteam.de> 
  4  # 
  5  # Python X2Go is free software; you can redistribute it and/or modify 
  6  # it under the terms of the GNU Affero General Public License as published by 
  7  # the Free Software Foundation; either version 3 of the License, or 
  8  # (at your option) any later version. 
  9  # 
 10  # Python X2Go is distributed in the hope that it will be useful, 
 11  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 13  # GNU Affero General Public License for more details. 
 14  # 
 15  # You should have received a copy of the GNU Affero General Public License 
 16  # along with this program; if not, write to the 
 17  # Free Software Foundation, Inc., 
 18  # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 
 19   
 20  """\ 
 21  X2GoProxy classes - proxying your connection through NX3 and others. 
 22   
 23  """ 
 24  __NAME__ = 'x2goproxynx3-pylib' 
 25   
 26  # modules 
 27  import os 
 28   
 29  # Python X2Go modules 
 30  import x2go.log as log 
 31  import base 
 32   
 33  from x2go.defaults import X2GOCLIENT_OS as _X2GOCLIENT_OS 
 34   
35 -class X2GoProxyNX3(base.X2GoProxyBASE):
36 """\ 37 X2GoNX3Proxy is a NX version 3 based X2Go proxy connection class. 38 39 It basically fills L{X2GoProxyBASE} variables with sensible content. Its 40 methods mostly wrap around the corresponding methods of the parent class. 41 42 """
43 - def __init__(self, *args, **kwargs):
44 """\ 45 For available parameters refer to L{X2GoProxyBASE} class documentation. 46 47 """ 48 base.X2GoProxyBASE.__init__(self, *args, **kwargs) 49 50 # setting some default environment variables, nxproxy paths etc. 51 if _X2GOCLIENT_OS == "Windows": 52 _nxproxy_paths = [ 53 os.path.join(os.environ["ProgramFiles"], os.path.normpath("PyHoca-GUI/nxproxy/nxproxy.exe")), 54 os.path.join(os.environ["ProgramFiles"], os.path.normpath("x2goclient/nxproxy.exe")), 55 os.path.join(os.environ["ProgramFiles"], os.path.normpath("NX Client for Windows/bin/nxproxy.exe")), 56 os.path.normpath("../pyhoca-contrib/mswin/nxproxy-mswin/nxproxy-3.5.0.12/nxproxy.exe"), 57 ] 58 if os.environ.has_key('NXPROXY_BINARY'): 59 _nxproxy_paths.insert(0, os.environ['NXPROXY_BINARY']) 60 for _nxproxy_cmd in _nxproxy_paths: 61 if os.path.exists(_nxproxy_cmd): 62 break 63 self.PROXY_CMD = _nxproxy_cmd 64 else: 65 self.PROXY_CMD = "/usr/bin/nxproxy" 66 self.PROXY_ENV.update({ 67 "NX_CLIENT": "/bin/true", 68 "NX_ROOT": self.sessions_rootdir 69 }) 70 self.PROXY_MODE = '-S' 71 if _X2GOCLIENT_OS == "Windows": 72 self.PROXY_OPTIONS = [ 73 "nx/nx" , 74 "retry=5", 75 "composite=1", 76 "connect=127.0.0.1", 77 "clipboard=1", 78 "cookie=%s" % self.session_info.cookie, 79 "port=%s" % self.session_info.graphics_port, 80 "errors=%s" % os.path.join(".", "..", "S-%s" % self.session_info.name, self.session_log, ), 81 ] 82 else: 83 self.PROXY_OPTIONS = [ 84 "nx/nx" , 85 "retry=5", 86 "composite=1", 87 "connect=127.0.0.1", 88 "clipboard=1", 89 "cookie=%s" % self.session_info.cookie, 90 "port=%s" % self.session_info.graphics_port, 91 "errors=%s" % os.path.join(self.session_info.local_container, self.session_log, ), 92 ] 93 94 self.PROXY_DISPLAY = self.session_info.display
95
96 - def _update_local_proxy_socket(self, port):
97 """\ 98 Update the local proxy socket on port changes due to already-bound-to local TCP/IP port sockets. 99 100 @param port: new local TCP/IP socket port 101 @type port: C{int} 102 103 """ 104 105 for idx, a in enumerate(self.PROXY_OPTIONS): 106 if a.startswith('port='): 107 self.PROXY_OPTIONS[idx] = 'port=%s' % port
108
109 - def _generate_cmdline(self):
110 """\ 111 Generate the NX proxy command line for execution. 112 113 """ 114 if _X2GOCLIENT_OS == "Windows": 115 _options_filename = os.path.join(self.session_info.local_container, 'options') 116 options = open(_options_filename, 'w') 117 options.write('%s:%s' % (','.join(self.PROXY_OPTIONS), self.PROXY_DISPLAY)) 118 options.close() 119 self.PROXY_OPTIONS= [ 'nx/nx', 'options=%s' % os.path.join("\\", "..", "S-%s" % self.session_info.name, 'options'), ] 120 121 cmd_line = [ self.PROXY_CMD, ] 122 cmd_line.append(self.PROXY_MODE) 123 _proxy_options = "%s:%s" % (",".join(self.PROXY_OPTIONS), self.PROXY_DISPLAY) 124 cmd_line.append(_proxy_options) 125 return cmd_line
126
127 - def start_proxy(self):
128 """\ 129 Start the thread runner and wait for the proxy to come up. 130 131 @return: a subprocess instance that knows about the externally started proxy command. 132 @rtype: C{obj} 133 134 """ 135 self.logger('starting local NX3 proxy...', loglevel=log.loglevel_INFO) 136 self.logger('NX3 Proxy mode is server, cookie=%s, host=127.0.0.1, port=%s.' % (self.session_info.cookie, self.session_info.graphics_port,), loglevel=log.loglevel_DEBUG) 137 self.logger('NX3 proxy writes session log to %s.' % os.path.join(self.session_info.local_container, 'session.log'), loglevel=log.loglevel_DEBUG) 138 139 p, p_ok = base.X2GoProxyBASE.start_proxy(self) 140 141 if self.ok(): 142 self.logger('NX3 proxy is up and running.', loglevel=log.loglevel_INFO) 143 else: 144 self.logger('Bringing up NX3 proxy failed.', loglevel=log.loglevel_ERROR) 145 146 return p, self.ok()
147