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