Package x2go :: Module defaults

[frames] | no frames]

# Source Code for Module x2go.defaults

      1  # -*- coding: utf-8 -*-
      2
      3  # Copyright (C) 2010-2013 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  Default variables and values for Python X2Go.
     22
     23  """
     24  __NAME__ = 'x2godefaults-pylib'
     25
     26  import os
     27  import paramiko
     28  import platform
     29
     30  ##
     31  ## Common X2Go defaults
     32  ##
     33
     34  X2GOCLIENT_OS = platform.system()
     35
     36  if X2GOCLIENT_OS != 'Windows':
     37      import Xlib.display
     38      import Xlib.error
     39
     40      # handle missing X displays on package build
     41      try:
     42          X_DISPLAY = Xlib.display.Display()
     43      except Xlib.error.DisplayNameError:
     44          X_DISPLAY = None
     45      except Xlib.error.DisplayConnectionError:
     46          X_DISPLAY = None
     47
     48  LOCAL_HOME = os.path.normpath(os.path.expanduser('~'))
     49  X2GO_SESSIONS_ROOTDIR = '.x2go'
     50  X2GO_CLIENT_ROOTDIR = '.x2goclient'
     51  X2GO_SSH_ROOTDIR = os.path.join('.x2go','.ssh')
     52
     53  # setting OS dependent variables
     54  if X2GOCLIENT_OS == "Windows":
     55      # on Windows we will use the current directory as ,,ROOTDIR'' which
     56      # will normally be the application directory
     57      ROOT_DIR = os.path.abspath(os.path.curdir)
     58      ETC_DIR = os.path.join(ROOT_DIR, 'etc')
     59      import win32api
     60      CURRENT_LOCAL_USER = win32api.GetUserName()
     61      X2GO_SSH_ROOTDIR = '.ssh'
     62      SUPPORTED_SOUND = True
     63      SUPPORTED_PRINTING = True
     64      SUPPORTED_FOLDERSHARING = True
     65      SUPPORTED_MIMEBOX = True
     66
     67  elif X2GOCLIENT_OS == "Linux":
     68      ROOT_DIR = '/'
     69      ETC_DIR = os.path.join(ROOT_DIR, 'etc', 'x2goclient')
     70      import getpass
     71      CURRENT_LOCAL_USER = getpass.getuser()
     72      X2GO_SSH_ROOTDIR = '.ssh'
     73      SUPPORTED_SOUND = True
     74      SUPPORTED_PRINTING = True
     75      SUPPORTED_FOLDERSHARING = True
     76      SUPPORTED_MIMEBOX = True
     77
     78  elif X2GOCLIENT_OS == "Mac":
     79      ROOT_DIR = '/'
     80      ETC_DIR = os.path.join(ROOT_DIR, 'etc', 'x2goclient')
     81      import getpass
     82      CURRENT_LOCAL_USER = getpass.getuser()
     83      X2GO_SSH_ROOTDIR = '.ssh'
     84      SUPPORTED_SOUND = True
     85      SUPPORTED_PRINTING = True
     86      SUPPORTED_FOLDERSHARING = True
     87      SUPPORTED_MIMEBOX = True
     88
     89  else:
     90      import exceptions
     91 -    class OSNotSupportedException(exceptions.StandardError): pass
     92      raise OSNotSupportedException('Platform %s is not supported' % platform.system())
     93
     94  ##
     95  ## control and terminal session backend as well as session info and proxy backend defaults
     96  ##
     97
     98  BACKENDS_CONTROLSESSION = {
     99      'STDOUT': 'X2GoControlSessionSTDOUT',
    100  }
    101  BACKENDS_TERMINALSESSION = {
    102      'STDOUT': 'X2GoTerminalSessionSTDOUT',
    103  }
    104  BACKENDS_SERVERSESSIONINFO = {
    105      'STDOUT': 'X2GoServerSessionInfoSTDOUT',
    106  }
    107  BACKENDS_SERVERSESSIONLIST = {
    108      'STDOUT': 'X2GoServerSessionListSTDOUT',
    109  }
    110  BACKENDS_PROXY = {
    111      'NX3': 'X2GoProxyNX3',
    112  }
    113
    114  BACKEND_CONTROLSESSION_DEFAULT =  'X2GoControlSessionSTDOUT'
    115  BACKEND_TERMINALSESSION_DEFAULT = 'X2GoTerminalSessionSTDOUT'
    116  BACKEND_SERVERSESSIONINFO_DEFAULT = 'X2GoServerSessionInfoSTDOUT'
    117  BACKEND_SERVERSESSIONLIST_DEFAULT = 'X2GoServerSessionListSTDOUT'
    118  BACKEND_PROXY_DEFAULT = 'X2GoProxyNX3'
    119
    120  ##
    121  ## profile backend defaults
    122  ##
    123
    124  BACKENDS_SESSIONPROFILES = {
    125      'FILE': 'X2GoSessionProfilesFILE',
    126      'GCONF': 'X2GoSessionProfilesGCONF',
    127      'HTTPSBROKER': 'X2GoSessionProfilesHTTPSBROKER',
    128      'WINREG': 'X2GoSessionProfilesWINREG',
    129  }
    130  """Python X2Go backends for storing session profiles."""
    131  BACKENDS_CLIENTSETTINGS = {
    132      'FILE': 'X2GoClientSettingsFILE',
    133      'GCONF': 'X2GoClientSettingsGCONF',
    134      'HTTPSBROKER': 'X2GoClientSettingsHTTPSBROKER',
    135      'WINREG': 'X2GoClientSettingsWINREG',
    136  }
    137  """Python X2Go backends for storing client settings."""
    138  BACKENDS_CLIENTPRINTING = {
    139      'FILE': 'X2GoClientPrintingFILE',
    140      'GCONF': 'X2GoClientPrintingGCONF',
    141      'HTTPSBROKER': 'X2GoClientPrintingHTTPSBROKER',
    142      'WINREG': 'X2GoClientPrintingWINREG',
    143  }
    144  """Python X2Go backends for storing print settings."""
    145
    146  BACKEND_SESSIONPROFILES_DEFAULT = 'X2GoSessionProfilesFILE'
    147  BACKEND_CLIENTSETTINGS_DEFAULT = 'X2GoClientSettingsFILE'
    148  BACKEND_CLIENTPRINTING_DEFAULT = 'X2GoClientPrintingFILE'
    149
    150  ##
    151  ## X2Go Printing
    152  ##
    153
    154  X2GO_SETTINGS_FILENAME = 'settings'
    155  X2GO_SETTINGS_CONFIGFILES = [
    156      os.path.normpath(os.path.join(LOCAL_HOME, X2GO_CLIENT_ROOTDIR, 'settings')),
    157      os.path.normpath(os.path.join(ETC_DIR,X2GO_SETTINGS_FILENAME)),
    158  ]
    159  X2GO_PRINTING_FILENAME = 'printing'
    160  X2GO_PRINTING_CONFIGFILES = [
    161      os.path.normpath(os.path.join(LOCAL_HOME, X2GO_CLIENT_ROOTDIR, 'printing')),
    162      os.path.normpath(os.path.join(ETC_DIR,X2GO_PRINTING_FILENAME)),
    163  ]
    164  X2GO_SESSIONPROFILES_FILENAME = 'sessions'
    165  X2GO_SESSIONPROFILES_CONFIGFILES = [
    166      os.path.normpath(os.path.join(LOCAL_HOME, X2GO_CLIENT_ROOTDIR, 'sessions')),
    167      os.path.normpath(os.path.join(ETC_DIR,X2GO_SESSIONPROFILES_FILENAME)),
    168  ]
    169  X2GO_XCONFIG_FILENAME = 'xconfig'
    170  X2GO_XCONFIG_CONFIGFILES = [
    171      os.path.normpath(os.path.join(LOCAL_HOME, X2GO_CLIENT_ROOTDIR, 'xconfig')),
    172      os.path.normpath(os.path.join(ETC_DIR,X2GO_XCONFIG_FILENAME)),
    173  ]
    174
    175  X2GO_CLIENTSETTINGS_DEFAULTS = {
    176      'LDAP': {
    177          'useldap': False,
    178          'port': 389,
    179          'server': 'localhost',
    180          'port1': 0,
    181          'port2': 0,
    182      },
    183      'General': {
    184          # clientport is not needed for Python X2Go
    185          'clientport': 22,
    186          'autoresume': True,
    187      },
    188      'Authorization': {
    189          'newprofile': True,
    190          'suspend': True,
    191          'editprofile': True,
    192          'resume': True
    193      },
    194      'trayicon': {
    195          'enabled': True,
    196          'mintotray': True,
    197          'noclose': True,
    198          'mincon': True,
    199          'maxdiscon': True,
    200      },
    201  }
    202  X2GO_CLIENTPRINTING_DEFAULTS = {
    203      'General': {
    204          # showdialog will result in a print action that allows opening a print dialog box
    205          'showdialog': False,
    206          # if true, open a PDF viewer (or save as PDF file). If false, print via CUPS or print command
    207          'pdfview': True,
    208      },
    209      'print': {
    210          # If false, print via CUPS. If true, run "command" to process the print job
    211          'startcmd': False,
    212          # print command for non-CUPS printing
    213          'command': 'lpr',
    214          # ignored in Python X2Go
    215          'stdin': False,
    216          # ignored in Python X2Go
    217          'ps': False,
    218      },
    219      'save': {
    220          # a path relative to the user's home directory
    221          'folder': 'PDF',
    222      },
    223      'view': {
    224          # If General->pdfview is true:
    225          #   if open is true, the PDF viewer command is executed
    226          #   if open is false, the incoming print job is saved in ~/PDF folder
    227          'open': True,
    228          # command to execute as PDF viewer
    229          'command': 'xpdf',
    230      },
    231      'CUPS': {
    232          # default print queue for CUPS, if print queue does not exist, the default
    233          # CUPS queue is detected
    234          'defaultprinter': 'PDF',
    235      },
    236  }
    237  if X2GOCLIENT_OS == 'Windows':
    238      X2GO_CLIENTPRINTING_DEFAULTS['print'].update({'gsprint': os.path.join(os.environ['ProgramFiles'], 'GhostGum', 'gsview', 'gsprint.exe'), })
    239
    240
    241  if X2GOCLIENT_OS == 'Windows':
    242      X2GO_CLIENTXCONFIG_DEFAULTS = {
    243          'XServers': {
    244              'known_xservers': ['VcXsrv_development', 'VcXsrv_shipped', 'VcXsrv', 'Xming', 'Cygwin-X', ],
    245          },
    246          'Cygwin-X': {
    247              'display': 'localhost:40',
    248              'last_display': 'localhost:40',
    249              'process_name': 'XWin.exe',
    250              'test_installed': os.path.join(os.environ['SystemDrive'], '\\', 'cygwin', 'bin', 'XWin.exe'),
    251              'run_command': os.path.join(os.environ['SystemDrive'], '\\', 'cygwin', 'bin', 'XWin.exe'),
    252              'parameters': [':40', '-clipboard', '-multiwindow', '-notrayicon', '-nowinkill', '-nounixkill', '-swcursor', ],
    253          },
    254          'VcXsrv': {
    255              'display': 'localhost:40',
    256              'last_display': 'localhost:40',
    257              'process_name': 'vcxsrv.exe',
    258              'test_installed': os.path.join(os.environ['ProgramFiles'], 'VcXsrv', 'vcxsrv.exe'),
    259              'run_command': os.path.join(os.environ['ProgramFiles'], 'VcXsrv', 'vcxsrv.exe'),
    260              'parameters': [':40', '-clipboard', '-multiwindow', '-notrayicon', '-nowinkill', '-nounixkill', '-swcursor', ],
    261          },
    262          'VcXsrv_shipped': {
    263              'display': 'localhost:40',
    264              'last_display': 'localhost:40',
    265              'process_name': 'vcxsrv.exe',
    266              'test_installed': os.path.join(os.getcwd(), 'VcXsrv', 'vcxsrv.exe'),
    267              'run_command': os.path.join(os.getcwd(), 'VcXsrv', 'vcxsrv.exe'),
    268              'parameters': [':40', '-clipboard', '-multiwindow', '-notrayicon', '-nowinkill', '-nounixkill', '-swcursor', ],
    269          },
    270          'VcXsrv_development': {
    271              'display': 'localhost:40',
    272              'last_display': 'localhost:40',
    273              'process_name': 'vcxsrv.exe',
    274              'test_installed': os.path.join(os.getcwd(), '..', 'pyhoca-contrib', 'mswin', 'vcxsrv-mswin', 'VcXsrv-1.14.2.0', 'vcxsrv.exe'),
    275              'run_command': os.path.join(os.getcwd(), '..', 'pyhoca-contrib', 'mswin', 'vcxsrv-mswin', 'VcXsrv-1.14.2.0', 'vcxsrv.exe'),
    276              'parameters': [':40', '-clipboard', '-multiwindow', '-notrayicon', '-nowinkill', '-nounixkill', '-swcursor', ],
    277          },
    278          'Xming': {
    279              'display': 'localhost:40',
    280              'last_display': 'localhost:40',
    281              'process_name': 'Xming.exe',
    282              'test_installed': os.path.join(os.environ['ProgramFiles'], 'Xming', 'Xming.exe'),
    283              'run_command': os.path.join(os.environ['ProgramFiles'], 'Xming', 'Xming.exe'),
    284              'parameters': [':40', '-clipboard', '-multiwindow', '-notrayicon', '-nowinkill', '-nounixkill', '-swcursor', ],
    285          },
    286      }
    287  else:
    288      # make the variable available when building API documentation with epydoc
    289      X2GO_CLIENTXCONFIG_DEFAULTS = {}
    290
    291  X2GO_GENERIC_APPLICATIONS = [ 'WWWBROWSER', 'MAILCLIENT', 'OFFICE', 'TERMINAL', ]
    292  """X2Go's generic applications."""
    293
    294  X2GO_SESSIONPROFILE_DEFAULTS = {
    295      'autologin': True, 'autoconnect': False, 'autostart': False, 'setsessiontitle': False, 'sessiontitle': "",
    296      'speed': 2, 'pack': '16m-jpeg', 'quality': 9,
    297      'iconvto': 'UTF-8', 'iconvfrom': 'UTF-8', 'useiconv': False,
    298      'usesshproxy': False, 'sshproxyhost': 'proxyhost.mydomain', 'sshproxyport': 22, 'sshproxyuser': '', 'sshproxykeyfile': '',
    299      'sshproxytype': 'SSH', 'sshproxysameuser': False, 'sshproxysamepass': False, 'sshproxyautologin': True,
    300      'uniquehostkeyaliases': False,
    301      'useexports': True, 'restoreexports': False, 'fstunnel': True, 'export': '',
    302      'usemimebox': False, 'mimeboxextensions': '', 'mimeboxaction': 'OPEN',
    303      'fullscreen': False,
    304      'width': 800,'height': 600, 'maxdim': False, 'dpi': 96, 'setdpi': False, 'xinerama': False, 'multidisp': False, 'display': 1,
    305      'usekbd': True, 'layout': 'us', 'type': 'pc105/us', 'variant': '',
    306      'sound': False, 'soundsystem': 'pulse', 'startsoundsystem': False, 'soundtunnel':True, 'defsndport':True, 'sndport':4713,
    307      'name': 'NEW_PROFILE', 'icon': ':icons/128x128/x2gosession.png',
    308      'host': 'server.mydomain', 'user': CURRENT_LOCAL_USER, 'key': '', 'sshport': 22, 'krblogin': False, 'forwardsshagent': False,
    309      'rootless': True, 'applications': X2GO_GENERIC_APPLICATIONS, 'command':'TERMINAL', 'published': False,
    310      'directrdp': False, 'directrdpsettings': '', 'rdpclient': 'rdesktop', 'rdpport': 3389,
    311      'rdpoptions': '-u X2GO_USER -p X2GO_PASSWORD', 'rdpserver': '',
    312      'print': False,
    313      'xdmcpserver': 'localhost',
    314  }
    315  """L{X2GoSessionProfiles} default values to fill a new session profile with."""
    316  ##
    317  ## X2Go Proxy defaults
    318  ##
    319
    320  # here is a list of NX 3.x compression methods, this is the "%"-hashed list that
    321  # can also be used for printing in help texts, docs etc.
    322  # The "%"-sign can be replaced by digits 0-9.
    323  pack_methods_nx3_noqual  = ['nopack','8','64','256','512','4k','32k','64k','256k','2m','16m',
    324                              '256-rdp','256-rdp-compressed','32k-rdp','32k-rdp-compressed','64k-rdp',
    325                              '64k-rdp-compressed','16m-rdp','16m-rdp-compressed',
    326                              'rfb-hextile','rfb-tight','rfb-tight-compressed',
    327                              '8-tight','64-tight','256-tight','512-tight','4k-tight','32k-tight',
    328                              '64k-tight','256k-tight','2m-tight','16m-tight',
    329                              '8-jpeg-%','64-jpeg','256-jpeg','512-jpeg','4k-jpeg','32k-jpeg',
    330                              '64k-jpeg','256k-jpeg','2m-jpeg','16m-jpeg-%',
    331                              '8-png-jpeg-%','64-png-jpeg','256-png-jpeg','512-png-jpeg','4k-png-jpeg',
    332                              '32k-png-jpeg','64k-png-jpeg','256k-png-jpeg','2m-png-jpeg','16m-png-jpeg-%',
    333                              '8-png-%','64-png','256-png','512-png','4k-png',
    334                              '32k-png','64k-png','256k-png','2m-png','16m-png-%',
    335                              '16m-rgb-%','16m-rle-%',]
    336  """Available NX3 compression methods."""
    337
    338  # use for printing on screen...
    339  pack_methods_nx3_formatted="""
    340      \'%s\'
    341      \'%s\'
    342      \'%s\'
    343      \'%s\'
    344      \'%s\'
    345      \'%s\'
    346      \'%s\'
    347      \'%s\'
    348      \'%s\'
    349      \'%s\'
    350      \'%s\'
    351      \'%s\'
    352      \'%s\'
    353  """ % ('\', \''.join(pack_methods_nx3_noqual[0:11]), \
    354             '\', \''.join(pack_methods_nx3_noqual[11:16]), \
    355             '\', \''.join(pack_methods_nx3_noqual[16:19]), \
    356             '\', \''.join(pack_methods_nx3_noqual[19:22]), \
    357             '\', \''.join(pack_methods_nx3_noqual[22:28]), \
    358             '\', \''.join(pack_methods_nx3_noqual[28:32]), \
    359             '\', \''.join(pack_methods_nx3_noqual[32:38]), \
    360             '\', \''.join(pack_methods_nx3_noqual[38:42]), \
    361             '\', \''.join(pack_methods_nx3_noqual[42:47]), \
    362             '\', \''.join(pack_methods_nx3_noqual[47:52]), \
    363             '\', \''.join(pack_methods_nx3_noqual[52:57]), \
    364             '\', \''.join(pack_methods_nx3_noqual[57:62]), \
    365             '\', \''.join(pack_methods_nx3_noqual[62:]))
    366
    367  # pack_methods_nx3 is the complete list of NX3 pack methods that can be used to check options
    368  # against
    369  pack_methods_nx3 = [ m for m in pack_methods_nx3_noqual if "%" not in m ]
    370  for meth in [ m for m in pack_methods_nx3_noqual if "%" in m ]:
    371      pack_methods_nx3 += [ meth.replace('%','%s' % str(i)) for i in range(0,10) ]
    372  pack_methods_nx3.sort()
    373  ##
    374  ## X2Go session defaults
    375  ##
    376
    377  X2GO_DESKTOPSESSIONS={
    378      'CINNAMON': 'cinnamon',
    379      'KDE': 'startkde',
    380      'GNOME': 'gnome-session',
    381      'MATE': 'mate-session',
    382      'XFCE': 'xfce4-session',
    383      'LXDE': 'startlxde',
    384      'TRINITY': 'starttrinity',
    385      'UNITY': 'unity',
    386  }
    387  """A dictionary with meta-commands for X2Go's window manager sessions."""
    388
    389  ##
    390  ## X2Go SFTP server defaults
    391  ##
    392
    393  RSAKEY_STRENGTH = 1024
    394  RSAHostKey = paramiko.RSAKey.generate(RSAKEY_STRENGTH)
    395  """\
    396  An RSA host key for this client session. Python X2Go does not use the
    397  system's host key but generates its own host key for each running
    398  application instance.
    399
    400  """
    401
    402  X2GO_PRINT_ACTIONS = {
    403      'PDFVIEW': 'X2GoPrintActionPDFVIEW',
    404      'PDFSAVE': 'X2GoPrintActionPDFSAVE',
    405      'PRINT': 'X2GoPrintActionPRINT',
    406      'PRINTCMD': 'X2GoPrintActionPRINTCMD',
    407      'DIALOG': 'X2GoPrintActionDIALOG',
    408  }
    409  """Relating print action names and classes."""
    410
    411  DEFAULT_PDFVIEW_CMD = 'xdg-open'
    412  """Default PDF viewer command for Linux systems (PDFVIEW print action)."""
    413  DEFAULT_PDFSAVE_LOCATION = 'PDF'
    414  """Default location for saving PDF files (PDFSAVE print action)."""
    415  DEFAULT_PRINTCMD_CMD = 'lpr'
    416  """Default command for the PRINTCMD print action."""
    417
    418  X2GO_MIMEBOX_ACTIONS = {
    419      'OPEN': 'X2GoMIMEboxActionOPEN',
    420      'OPENWITH': 'X2GoMIMEboxActionOPENWITH',
    421      'SAVEAS': 'X2GoMIMEboxActionSAVEAS',
    422  }
    423  """Relating MIME box action names and classes."""
    424
    425  X2GO_MIMEBOX_EXTENSIONS_BLACKLIST = [
    426      'LOCK', 'SYS', 'SWP',
    427      'EXE', 'COM', 'CMD', 'PS1', 'PS2', 'BAT',
    428      'JS', 'PY', 'PL', 'SH',
    429  ]
    430  """Black-listed MIME box file extenstions."""
    431
    432  # X2Go desktop sharing
    433  X2GO_SHARE_VIEWONLY=0
    434  """Constant representing read-only access to shared desktops."""
    435  X2GO_SHARE_FULLACCESS=1
    436  """Constant representing read-write (full) access to shared desktops."""
    437
    438  PUBAPP_MAX_NO_SUBMENUS=10
    439  """Less than ten applications will not get rendered into submenus."""
    440