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-2015 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 x2go.backends.proxy.base as base 
 32   
 33  from x2go.defaults import X2GOCLIENT_OS as _X2GOCLIENT_OS 
 34   
35 -class X2GoProxy(base.X2GoProxy):
36 """\ 37 This L{X2GoProxy} class is a NX version 3 based X2Go proxy connection class. 38 39 It basically fills L{x2go.backends.proxy.base.X2GoProxy} 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{x2go.backends.proxy.base.X2GoProxy} class documentation. 46 47 """ 48 base.X2GoProxy.__init__(self, *args, **kwargs) 49 self.subsystem = 'NX Proxy' 50 51 # setting some default environment variables, nxproxy paths etc. 52 if _X2GOCLIENT_OS == "Windows": 53 _nxproxy_paths = [ 54 os.path.join(os.environ["ProgramFiles"], os.path.normpath("PyHoca-GUI/nxproxy/nxproxy.exe")), 55 os.path.join(os.environ["ProgramFiles"], os.path.normpath("x2goclient/nxproxy.exe")), 56 os.path.join(os.environ["ProgramFiles"], os.path.normpath("NX Client for Windows/bin/nxproxy.exe")), 57 os.path.normpath("../pyhoca-contrib/mswin/nxproxy-mswin/nxproxy-3.5.0.27_cygwin-2015-10-18/nxproxy.exe"), 58 ] 59 if os.environ.has_key('NXPROXY_BINARY'): 60 _nxproxy_paths.insert(0, os.environ['NXPROXY_BINARY']) 61 for _nxproxy_cmd in _nxproxy_paths: 62 if os.path.exists(_nxproxy_cmd): 63 break 64 self.PROXY_CMD = _nxproxy_cmd 65 else: 66 self.PROXY_CMD = "/usr/bin/nxproxy" 67 self.PROXY_ENV.update({ 68 "NX_CLIENT": "/bin/true", 69 "NX_ROOT": self.sessions_rootdir 70 }) 71 self.PROXY_MODE = '-S' 72 if _X2GOCLIENT_OS == "Windows": 73 self.PROXY_OPTIONS = [ 74 "nx/nx" , 75 "retry=5", 76 "composite=1", 77 "connect=127.0.0.1", 78 "clipboard=1", 79 "cookie=%s" % self.session_info.cookie, 80 "port=%s" % self.session_info.graphics_port, 81 "errors=%s" % os.path.join(".", "..", "S-%s" % self.session_info.name, self.session_errors, ), 82 ] 83 else: 84 self.PROXY_OPTIONS = [ 85 "nx/nx" , 86 "retry=5", 87 "composite=1", 88 "connect=127.0.0.1", 89 "clipboard=1", 90 "cookie=%s" % self.session_info.cookie, 91 "port=%s" % self.session_info.graphics_port, 92 "errors=%s" % os.path.join(self.session_info.local_container, self.session_errors, ), 93 ] 94 95 self.PROXY_DISPLAY = self.session_info.display
96
97 - def _update_local_proxy_socket(self, port):
98 """\ 99 Update the local proxy socket on port changes due to already-bound-to local TCP/IP port sockets. 100 101 @param port: new local TCP/IP socket port 102 @type port: C{int} 103 104 """ 105 106 for idx, a in enumerate(self.PROXY_OPTIONS): 107 if a.startswith('port='): 108 self.PROXY_OPTIONS[idx] = 'port=%s' % port
109
110 - def _generate_cmdline(self):
111 """\ 112 Generate the NX proxy command line for execution. 113 114 """ 115 if _X2GOCLIENT_OS == "Windows": 116 _options_filename = os.path.join(self.session_info.local_container, 'options') 117 options = open(_options_filename, 'w') 118 options.write('%s:%s' % (','.join(self.PROXY_OPTIONS), self.PROXY_DISPLAY)) 119 options.close() 120 self.PROXY_OPTIONS= [ 'nx/nx', 'options=%s' % os.path.join("\\", "..", "S-%s" % self.session_info.name, 'options'), ] 121 122 cmd_line = [ self.PROXY_CMD, ] 123 cmd_line.append(self.PROXY_MODE) 124 _proxy_options = "%s:%s" % (",".join(self.PROXY_OPTIONS), self.PROXY_DISPLAY) 125 cmd_line.append(_proxy_options) 126 return cmd_line
127
128 - def process_proxy_options(self):
130
131 - def start_proxy(self):
132 """\ 133 Start the thread runner and wait for the proxy to come up. 134 135 @return: a subprocess instance that knows about the externally started proxy command. 136 @rtype: C{obj} 137 138 """ 139 self.logger('starting local NX3 proxy...', loglevel=log.loglevel_INFO) 140 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) 141 self.logger('NX3 proxy writes session log to %s.' % os.path.join(self.session_info.local_container, 'session.log'), loglevel=log.loglevel_DEBUG) 142 143 p, p_ok = base.X2GoProxy.start_proxy(self) 144 145 if self.ok(): 146 self.logger('NX3 proxy is up and running.', loglevel=log.loglevel_INFO) 147 else: 148 self.logger('Bringing up NX3 proxy failed.', loglevel=log.loglevel_ERROR) 149 150 return p, self.ok()
151