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-2011 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 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 General Public License for more details. 
 14  # 
 15  # You should have received a copy of the GNU 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 gevent 
 28  import os 
 29  import sys 
 30  import types 
 31  import time 
 32  import copy 
 33  import threading 
 34   
 35  # Python X2go modules 
 36  import x2go.forward as forward 
 37  import x2go.utils as utils 
 38  import x2go.log as log 
 39  import base 
 40   
 41  from x2go.defaults import X2GOCLIENT_OS as _X2GOCLIENT_OS 
 42   
43 -class X2goProxyNX3(base.X2goProxyBASE):
44 """\ 45 X2goNX3Proxy is a NX version 3 based X2go proxy connection class. 46 47 It basically fills L{X2goProxyBASE} variables with sensible content. Its 48 methods mostly wrap around the corresponding methods of the parent class. 49 50 """
51 - def __init__(self, *args, **kwargs):
52 """\ 53 For available parameters refer to L{X2goProxyBASE} class documentation. 54 55 """ 56 base.X2goProxyBASE.__init__(self, *args, **kwargs) 57 58 # setting some default environment variables, nxproxy paths etc. 59 if _X2GOCLIENT_OS == "Windows": 60 _nxproxy_paths = [ 61 os.path.join(os.environ["ProgramFiles"], os.path.normpath("PyHoca-GUI/nxproxy/nxproxy.exe")), 62 os.path.join(os.environ["ProgramFiles"], os.path.normpath("x2goclient/nxproxy.exe")), 63 os.path.join(os.environ["ProgramFiles"], os.path.normpath("NX Client for Windows/bin/nxproxy.exe")), 64 ] 65 if os.environ.has_key('NXPROXY_BINARY'): 66 _nxproxy_paths.insert(0, os.environ['NXPROXY_BINARY']) 67 for _nxproxy_cmd in _nxproxy_paths: 68 if os.path.exists(_nxproxy_cmd): 69 break 70 self.PROXY_CMD = _nxproxy_cmd 71 else: 72 self.PROXY_CMD = "/usr/bin/nxproxy" 73 self.PROXY_ENV.update({ 74 "NX_CLIENT": "/bin/true", 75 "NX_ROOT": self.sessions_rootdir 76 }) 77 self.PROXY_MODE = '-S' 78 if _X2GOCLIENT_OS == "Windows": 79 self.PROXY_OPTIONS = [ 80 "nx/nx" , 81 "retry=5", 82 "composite=1", 83 "connect=127.0.0.1", 84 "clipboard=1", 85 "cookie=%s" % self.session_info.cookie, 86 "port=%d" % self.session_info.graphics_port, 87 "errors=%s" % os.path.join(".", "..", "S-%s" % self.session_info.name, self.session_log, ), 88 ] 89 else: 90 self.PROXY_OPTIONS = [ 91 "nx/nx" , 92 "retry=5", 93 "composite=1", 94 "connect=127.0.0.1", 95 "clipboard=1", 96 "cookie=%s" % self.session_info.cookie, 97 "port=%d" % self.session_info.graphics_port, 98 "errors=%s" % os.path.join(self.session_info.local_container, self.session_log, ), 99 ] 100 101 self.PROXY_DISPLAY = self.session_info.display
102
103 - def _update_local_proxy_socket(self, port):
104 for idx, a in enumerate(self.PROXY_OPTIONS): 105 if a.startswith('port='): 106 self.PROXY_OPTIONS[idx] = 'port=%s' % port
107
108 - def _generate_cmdline(self):
109 110 if _X2GOCLIENT_OS == "Windows": 111 _options_filename = os.path.join(self.session_info.local_container, 'options') 112 options = open(_options_filename, 'w') 113 options.write('%s:%s' % (','.join(self.PROXY_OPTIONS), self.PROXY_DISPLAY)) 114 options.close() 115 self.PROXY_OPTIONS= [ 'nx/nx', 'options=%s' % os.path.join("\\", "..", "S-%s" % self.session_info.name, 'options'), ] 116 117 cmd_line = [ self.PROXY_CMD, ] 118 cmd_line.append(self.PROXY_MODE) 119 _proxy_options = "%s:%s" % (",".join(self.PROXY_OPTIONS), self.PROXY_DISPLAY) 120 cmd_line.append(_proxy_options) 121 return cmd_line
122
123 - def process_proxy_options(self):
124 125 if self.proxy_options.has_key('defkeymap') and self.proxy_options['defkeymap']: 126 127 # first: draw in xkb_rules_names from xprop output 128 xkb_rules_names = utils.xkb_rules_names() 129 _proxy_options = { 130 'xkbrules': xkb_rules_names['rules'], 131 'xkbmodel': xkb_rules_names['model'], 132 'xkblayout': xkb_rules_names['layout'], 133 'xkbvariant': xkb_rules_names['variant'], 134 'xkboptions': xkb_rules_names['options'], 135 } 136 137 # merge self.proxy_options into the proxy_options we obtained from xprop 138 _proxy_options.update(self.proxy_options) 139 self.proxy_options = _proxy_options 140 141 del self.proxy_options['defkeymap'] 142 143 # create keyboard file 144 _keyboard = """\ 145 rules=%s 146 model=%s 147 layout=%s 148 variant=%s 149 options=%s""" % ( self.proxy_options['xkbrules'], 150 self.proxy_options['xkbmodel'], 151 self.proxy_options['xkblayout'], 152 self.proxy_options['xkbvariant'], 153 self.proxy_options['xkboptions'], ) 154 155 # remove processed options from self.process_options 156 del self.proxy_options['xkbrules'] 157 del self.proxy_options['xkbmodel'] 158 del self.proxy_options['xkblayout'] 159 del self.proxy_options['xkbvariant'] 160 del self.proxy_options['xkboptions'] 161 162 # write the keyboard file into the remote session directory 163 self.session_instance.control_session._x2go_sftp_write('%s/keyboard' % self.session_info.remote_container, _keyboard) 164 165 # run the base variant of this method (basically for logging of ignored process_options) 166 base.X2goProxyBASE.process_proxy_options(self)
167
168 - def start_proxy(self):
169 self.logger('starting local NX3 proxy...', loglevel=log.loglevel_INFO) 170 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) 171 self.logger('NX3 proxy writes session log to %s.' % os.path.join(self.session_info.local_container, 'session.log'), loglevel=log.loglevel_DEBUG) 172 173 p = base.X2goProxyBASE.start_proxy(self) 174 175 if self.ok(): 176 self.logger('NX3 proxy is up and running.', loglevel=log.loglevel_INFO) 177 else: 178 self.logger('Bringing up NX3 proxy failed.', loglevel=log.loglevel_ERROR) 179 180 return p
181