382fac5f3eb7db245c8c119a7156432e17c95012
[x2gobroker.git] / x2gobroker / defaults.py
1 # -*- coding: utf-8 -*-
2
3 # Copyright (C) 2012-2015 by Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
4 #
5 # X2Go Session Broker 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 # X2Go Session Broker 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 # modules
21 import os
22 import uuid
23 import socket
24 import pwd, grp
25
26 import logging
27 from loggers import logger_broker, logger_access, logger_error, X2GOBROKER_DAEMON_USER
28 from loggers import iniconfig_loaded
29 if iniconfig_loaded:
30     from loggers import iniconfig, iniconfig_section
31
32 X2GOBROKER_USER =  pwd.getpwuid(os.geteuid())[0]
33 X2GOBROKER_GROUP =  grp.getgrgid(pwd.getpwuid(os.geteuid())[3])[0]
34 os.environ['HOME'] = pwd.getpwuid(os.geteuid())[5]
35
36 if os.environ.has_key('X2GOBROKER_DAEMON_GROUP'):
37     X2GOBROKER_DAEMON_GROUP=os.environ['X2GOBROKER_DAEMON_GROUP']
38 elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_DAEMON_GROUP'):
39     X2GOBROKER_DAEMON_GROUP=iniconfig.get(iniconfig_section, 'X2GOBROKER_DAEMON_GROUP')
40 elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_DAEMON_GROUP'):
41     X2GOBROKER_DAEMON_GROUP=iniconfig.get('common', 'X2GOBROKER_DAEMON_GROUP')
42 else:
43     X2GOBROKER_DAEMON_GROUP="x2gobroker"
44 if os.environ.has_key('X2GOBROKER_AGENT_USER'):
45     X2GOBROKER_AGENT_USER=os.environ['X2GOBROKER_AGENT_USER']
46 elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_AGENT_USER'):
47     X2GOBROKER_AGENT_USER=iniconfig.get(iniconfig_section, 'X2GOBROKER_AGENT_USER')
48 elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_AGENT_USER'):
49     X2GOBROKER_AGENT_USER=iniconfig.get('common', 'X2GOBROKER_AGENT_USER')
50 else:
51     X2GOBROKER_AGENT_USER="x2gobroker"
52
53 ###
54 ### dynamic default values, influencable through os.environ...
55 ###
56
57 if os.environ.has_key('X2GOBROKER_DEBUG'):
58     X2GOBROKER_DEBUG = ( os.environ['X2GOBROKER_DEBUG'].lower() in ('1', 'on', 'true', 'yes', ) )
59 elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_DEBUG'):
60     X2GOBROKER_DEBUG=iniconfig.get(iniconfig_section, 'X2GOBROKER_DEBUG')
61 elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_DEBUG'):
62     X2GOBROKER_DEBUG=iniconfig.get('common', 'X2GOBROKER_DEBUG')
63 else:
64     X2GOBROKER_DEBUG = False
65 if os.environ.has_key('X2GOBROKER_DEBUG_INTERACTIVELY'):
66     X2GOBROKER_DEBUG_INTERACTIVELY = ( os.environ['X2GOBROKER_DEBUG_INTERACTIVELY'].lower() in ('1', 'on', 'true', 'yes', ) )
67 elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_DEBUG_INTERACTIVELY'):
68     X2GOBROKER_DEBUG_INTERACTIVELY=iniconfig.get(iniconfig_section, 'X2GOBROKER_DEBUG_INTERACTIVELY')
69 elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_DEBUG_INTERACTIVELY'):
70     X2GOBROKER_DEBUG_INTERACTIVELY=iniconfig.get('common', 'X2GOBROKER_DEBUG_INTERACTIVELY')
71 else:
72     X2GOBROKER_DEBUG_INTERACTIVELY = False
73 if os.environ.has_key('X2GOBROKER_TESTSUITE'):
74     X2GOBROKER_TESTSUITE = ( os.environ['X2GOBROKER_TESTSUITE'].lower() in ('1', 'on', 'true', 'yes', ) )
75 elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_TESTSUITE'):
76     X2GOBROKER_TESTSUITE=iniconfig.get(iniconfig_section, 'X2GOBROKER_TESTSUITE')
77 elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_TESTSUITE'):
78     X2GOBROKER_TESTSUITE=iniconfig.get('common', 'X2GOBROKER_TESTSUITE')
79 else:
80     X2GOBROKER_TESTSUITE = False
81
82 # enforce debugging for interactive usage
83 if X2GOBROKER_USER != X2GOBROKER_DAEMON_USER:
84     X2GOBROKER_DEBUG = True
85
86 # raise log levels to CRITICAL if we are running the unittests...
87 if X2GOBROKER_TESTSUITE:
88     logger_broker.setLevel(logging.CRITICAL)
89     logger_access.setLevel(logging.CRITICAL)
90     logger_error.setLevel(logging.CRITICAL)
91
92 if os.environ.has_key('X2GOBROKER_CONFIG'):
93     X2GOBROKER_CONFIG = os.environ['X2GOBROKER_CONFIG']
94 elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_CONFIG'):
95     X2GOBROKER_CONFIG=iniconfig.get(iniconfig_section, 'X2GOBROKER_CONFIG')
96 elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_CONFIG'):
97     X2GOBROKER_CONFIG=iniconfig.get('common', 'X2GOBROKER_CONFIG')
98 else:
99     X2GOBROKER_CONFIG = "/etc/x2go/x2gobroker.conf"
100
101 if os.environ.has_key('X2GOBROKER_SESSIONPROFILES'):
102     X2GOBROKER_SESSIONPROFILES = os.environ['X2GOBROKER_SESSIONPROFILES']
103 elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_SESSIONPROFILES'):
104     X2GOBROKER_SESSIONPROFILES=iniconfig.get(iniconfig_section, 'X2GOBROKER_SESSIONPROFILES')
105 elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_SESSIONPROFILES'):
106     X2GOBROKER_SESSIONPROFILES=iniconfig.get('common', 'X2GOBROKER_SESSIONPROFILES')
107 else:
108     X2GOBROKER_SESSIONPROFILES = "/etc/x2go/broker/x2gobroker-sessionprofiles.conf"
109
110 if os.environ.has_key('X2GOBROKER_AGENT_CMD'):
111     X2GOBROKER_AGENT_CMD = os.environ['X2GOBROKER_AGENT_CMD']
112 elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_AGENT_CMD'):
113     X2GOBROKER_AGENT_CMD=iniconfig.get(iniconfig_section, 'X2GOBROKER_AGENT_CMD')
114 elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_AGENT_CMD'):
115     X2GOBROKER_AGENT_CMD=iniconfig.get('common', 'X2GOBROKER_AGENT_CMD')
116 else:
117     X2GOBROKER_AGENT_CMD = "/usr/lib/x2go/x2gobroker-agent"
118
119 if os.environ.has_key('X2GOBROKER_AUTHSERVICE_SOCKET'):
120     X2GOBROKER_AUTHSERVICE_SOCKET=os.environ['X2GOBROKER_AUTHSERVICE_SOCKET']
121 elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_AUTHSERVICE_SOCKET'):
122     X2GOBROKER_AUTHSERVICE_SOCKET=iniconfig.get(iniconfig_section, 'X2GOBROKER_AUTHSERVICE_SOCKET')
123 elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_AUTHSERVICE_SOCKET'):
124     X2GOBROKER_AUTHSERVICE_SOCKET=iniconfig.get('common', 'X2GOBROKER_AUTHSERVICE_SOCKET')
125 else:
126     if os.path.isdir('/run/x2gobroker'):
127         RUNDIR = '/run'
128     else:
129         RUNDIR = '/var/run/x2gobroker'
130     X2GOBROKER_AUTHSERVICE_SOCKET="{run}/x2gobroker/x2gobroker-authservice.socket".format(run=RUNDIR)
131
132 if os.environ.has_key('X2GOBROKER_LOADCHECKER_SOCKET'):
133     X2GOBROKER_LOADCHECKER_SOCKET=os.environ['X2GOBROKER_LOADCHECKER_SOCKET']
134 elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_LOADCHECKER_SOCKET'):
135     X2GOBROKER_LOADCHECKER_SOCKET=iniconfig.get(iniconfig_section, 'X2GOBROKER_LOADCHECKER_SOCKET')
136 elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_LOADCHECKER_SOCKET'):
137     X2GOBROKER_LOADCHECKER_SOCKET=iniconfig.get('common', 'X2GOBROKER_LOADCHECKER_SOCKET')
138 else:
139     if os.path.isdir('/run/x2gobroker'):
140         RUNDIR = '/run'
141     else:
142         RUNDIR = '/var/run/x2gobroker'
143     X2GOBROKER_LOADCHECKER_SOCKET="{run}/x2gobroker/x2gobroker-loadchecker.socket".format(run=RUNDIR)
144
145 if os.environ.has_key('X2GOBROKER_DEFAULT_BACKEND'):
146     X2GOBROKER_DEFAULT_BACKEND = os.environ['X2GOBROKER_DEFAULT_BACKEND']
147 elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_DEFAULT_BACKEND'):
148     X2GOBROKER_DEFAULT_BACKEND=iniconfig.get(iniconfig_section, 'X2GOBROKER_DEFAULT_BACKEND')
149 elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_DEFAULT_BACKEND'):
150     X2GOBROKER_DEFAULT_BACKEND=iniconfig.get('common', 'X2GOBROKER_DEFAULT_BACKEND')
151 else:
152     X2GOBROKER_DEFAULT_BACKEND = "inifile"
153
154 if os.environ.has_key('DAEMON_BIND_ADDRESS'):
155     DAEMON_BIND_ADDRESS = os.environ['DAEMON_BIND_ADDRESS']
156 elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'DAEMON_BIND_ADDRESS'):
157     DAEMON_BIND_ADDRESS = iniconfig.get(iniconfig_section, 'DAEMON_BIND_ADDRESS')
158 elif iniconfig_loaded and iniconfig.has_option('daemon', 'DAEMON_BIND_ADDRESS'):
159     DAEMON_BIND_ADDRESS = iniconfig.get('daemon', 'DAEMON_BIND_ADDRESS')
160 else:
161     DAEMON_BIND_ADDRESS = ""
162
163 if os.environ.has_key('X2GOBROKER_SSL_CERTFILE'):
164     X2GOBROKER_SSL_CERTFILE = os.environ['X2GOBROKER_SSL_CERTFILE']
165 elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_SSL_CERTFILE'):
166     X2GOBROKER_SSL_CERTFILE = iniconfig.get(iniconfig_section, 'X2GOBROKER_SSL_CERTFILE')
167 elif iniconfig_loaded and iniconfig.has_option('daemon', 'X2GOBROKER_SSL_CERTFILE'):
168     X2GOBROKER_SSL_CERTFILE = iniconfig.get('daemon', 'X2GOBROKER_SSL_CERTFILE')
169 else:
170     X2GOBROKER_SSL_CERTFILE = ""
171
172 if os.environ.has_key('X2GOBROKER_SSL_KEYFILE'):
173     X2GOBROKER_SSL_KEYFILE = os.environ['X2GOBROKER_SSL_KEYFILE']
174 elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_SSL_KEYFILE'):
175     X2GOBROKER_SSL_KEYFILE = iniconfig.get(iniconfig_section, 'X2GOBROKER_SSL_KEYFILE')
176 elif iniconfig_loaded and iniconfig.has_option('daemon', 'X2GOBROKER_SSL_KEYFILE'):
177     X2GOBROKER_SSL_KEYFILE = iniconfig.get('daemon', 'X2GOBROKER_SSL_KEYFILE')
178 else:
179     X2GOBROKER_SSL_KEYFILE = ""
180
181 ###
182 ### static / hard-coded defaults
183 ###
184
185 if socket.gethostname().find('.') >= 0:
186     X2GOBROKER_HOSTNAME = socket.gethostname()
187 else:
188     X2GOBROKER_HOSTNAME = socket.gethostbyaddr(socket.gethostname())[0]
189
190 # the home directory of the user that the daemon/cgi runs as
191 X2GOBROKER_HOME = os.path.normpath(os.path.expanduser('~{broker_uid}'.format(broker_uid=X2GOBROKER_DAEMON_USER)))
192
193 # defaults for X2Go Sessino Broker configuration file
194 X2GOBROKER_CONFIG_DEFAULTS = {
195     'global': {
196         # legacy support for X2Go Session Broker << 0.0.3.0
197         # the check-credentials parameter has been slit up into the two params above
198         u'check-credentials': True,
199         # use these two instead of check-credentials...
200         u'require-password': True,
201         u'require-cookie': False,
202         u'use-static-cookie': True,
203         u'auth-timeout': 36000,
204         u'cookie-directory': '/var/lib/x2gobroker/cookies',
205         u'verify-ip': True,
206         u'pre_auth_scripts': [],
207         u'post_auth_scripts': [],
208         u'select_session_scripts': [],
209         u'my-cookie': uuid.uuid4(),
210         u'my-cookie-file': '/etc/x2go/broker/x2gobroker.authid',
211         u'enable-plain-output': True,
212         u'enable-json-output': True,
213         u'enable-uccs-output': False,
214         u'my-uccs-url-base': 'http://localhost:8080/',
215         u'default-auth-mech': u'pam',
216         u'default-user-db': u'libnss',
217         u'default-group-db': u'libnss',
218         u'ignore-primary-group-memberships': True,
219         u'default-session-autologin': False,
220         u'default-authorized-keys': u'%h/.x2go/authorized_keys',
221         u'default-sshproxy-authorized-keys': u'%h/.x2go/authorized_keys',
222         u'default-agent-query-mode': u'NONE',
223         u'default-portscan-x2goservers': True,
224         u'default-use-load-checker': False,
225         u'load-checker-intervals': 300,
226     },
227     'broker_base': {
228         u'enable': False,
229     },
230     'broker_zeroconf': {
231         u'enable': False,
232         u'auth-mech': u'pam',
233         u'user-db': u'libnss',
234         u'group-db': u'libnss',
235         u'desktop-shell': u'KDE',
236         u'load-checker': False,
237     },
238     'broker_inifile': {
239         u'enable': True,
240         u'session-profiles': u'/etc/x2go/broker/x2gobroker-sessionprofiles.conf',
241         u'auth-mech': u'',
242         u'user-db': u'',
243         u'group-db': u'',
244         u'use-load-checker': True,
245     },
246     'broker_ldap': {
247         u'enable': False,
248         u'auth-mech': u'ldap',
249         u'user-db': u'ldap',
250         u'group-db': u'ldap',
251         u'uri': u'ldap://localhost:389',
252         u'base': u'dc=example,dc=org',
253         u'user-search-filter': u'(&(objectClass=posixAccount)(uid=*))',
254         u'host-search-filter': u'(&(objectClass=ipHost)(serial=X2GoServer)(cn=*))',
255         u'group-search-filter': u'(&(objectClass=posifxGroup)(cn=*))',
256         u'starttls': False,
257         u'agent-query-mode': u'SSH',
258         u'load-checker': True,
259     },
260 }
261
262 X2GO_DESKTOP_SESSIONS= [
263     'KDE',
264     'GNOME',
265     'XFCE',
266     'CINNAMON',
267     'MATE',
268     'XFCE',
269     'LXDE',
270     'TRINITY',
271     'UNITY',
272     'XDMCP',
273 ]
274
275 # defaults for X2Go Sessino Broker session profiles file
276 X2GOBROKER_SESSIONPROFILE_DEFAULTS = {
277     u'DEFAULT': {
278         u'command': u'TERMINAL',
279         u'defsndport': True,
280         u'useiconv': False,
281         u'iconvfrom': u'UTF-8',
282         u'height': 600,
283         u'export': u'',
284         u'quality': 9,
285         u'fullscreen': False,
286         u'layout': u'',
287         u'useexports': True,
288         u'width': 800,
289         u'speed': 2,
290         u'soundsystem': u'pulse',
291         u'print': True,
292         u'type': u'auto',
293         u'sndport': 4713,
294         u'xinerama': True,
295         u'variant': u'',
296         u'usekbd': True,
297         u'fstunnel': True,
298         u'applications': [u'TERMINAL',u'WWWBROWSER',u'MAILCLIENT',u'OFFICE'],
299         u'multidisp': False,
300         u'sshproxyport': 22,
301         u'sound': True,
302         u'rootless': True,
303         u'iconvto': u'UTF-8',
304         u'soundtunnel': True,
305         u'dpi': 96,
306         u'sshport': 22,
307         u'setdpi': 0,
308         u'pack': u'16m-jpeg',
309         u'user': 'BROKER_USER',
310         u'host': [ u'localhost', ],
311         u'directrdp': False,
312         u'acl-users-allow': [],
313         u'acl-users-deny': [],
314         u'acl-users-order': '',
315         u'acl-groups-allow': [],
316         u'acl-groups-deny': [],
317         u'acl-groups-order': '',
318         u'acl-clients-allow': [],
319         u'acl-clients-deny': [],
320         u'acl-clients-order': '',
321         u'acl-any-order': u'deny-allow',
322     },
323 }