f06b301a2d1755931e32a963c654fd9dc25bbe0b
[x2gobroker.git] / x2gobroker / defaults.py
1 # -*- coding: utf-8 -*-
2
3 # Copyright (C) 2012-2014 by Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
4 # Copyright (C) 2012-2014 by Oleksandr Shneyder <oleksandr.shneyder@obviously-nice.de>
5 # Copyright (C) 2012-2014 by Heinz-Markus Graesing <heinz-m.graesing@obviously-nice.de>
6 #
7 # X2Go Session Broker is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # X2Go Session Broker is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU Affero General Public License for more details.
16 #
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program; if not, write to the
19 # Free Software Foundation, Inc.,
20 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
21
22 # modules
23 import os
24 import sys
25 import uuid
26 import getpass
27 import socket
28 import ConfigParser
29
30 import logging
31 from loggers import logger_broker, logger_access, logger_error, X2GOBROKER_DAEMON_USER
32
33 X2GOBROKER_USER =  getpass.getuser()
34
35 PROG_NAME = os.path.basename(sys.argv[0])
36
37 iniconfig_loaded = None
38 iniconfig_section = '-'.join(PROG_NAME.split('-')[1:])
39 X2GOBROKER_DEFAULTS = "/etc/x2go/broker/defaults.conf"
40 if os.path.isfile(X2GOBROKER_DEFAULTS) and os.access(X2GOBROKER_DEFAULTS, os.R_OK):
41     iniconfig = ConfigParser.SafeConfigParser()
42     iniconfig.optionxform = str
43     iniconfig_loaded = iniconfig.read(X2GOBROKER_DEFAULTS)
44
45 if os.environ.has_key('X2GOBROKER_DAEMON_GROUP'):
46     X2GOBROKER_DAEMON_GROUP=os.environ['X2GOBROKER_DAEMON_GROUP']
47 elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_DAEMON_GROUP'):
48     X2GOBROKER_DAEMON_GROUP=iniconfig.get(iniconfig_section, 'X2GOBROKER_DAEMON_GROUP')
49 elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_DAEMON_GROUP'):
50     X2GOBROKER_DAEMON_GROUP=iniconfig.get('common', 'X2GOBROKER_DAEMON_GROUP')
51 else:
52     X2GOBROKER_DAEMON_GROUP="x2gobroker"
53 if os.environ.has_key('X2GOBROKER_AGENT_USER'):
54     X2GOBROKER_AGENT_USER=os.environ['X2GOBROKER_AGENT_USER']
55 elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_AGENT_USER'):
56     X2GOBROKER_AGENT_USER=iniconfig.get(iniconfig_section, 'X2GOBROKER_AGENT_USER')
57 elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_AGENT_USER'):
58     X2GOBROKER_AGENT_USER=iniconfig.get('common', 'X2GOBROKER_AGENT_USER')
59 else:
60     X2GOBROKER_AGENT_USER="x2gobroker"
61
62 ###
63 ### dynamic default values, influencable through os.environ...
64 ###
65
66 if os.environ.has_key('X2GOBROKER_DEBUG'):
67     X2GOBROKER_DEBUG = ( os.environ['X2GOBROKER_DEBUG'].lower() in ('1', 'on', 'true', 'yes', ) )
68 elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_DEBUG'):
69     X2GOBROKER_DEBUG=iniconfig.get(iniconfig_section, 'X2GOBROKER_DEBUG')
70 elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_DEBUG'):
71     X2GOBROKER_DEBUG=iniconfig.get('common', 'X2GOBROKER_DEBUG')
72 else:
73     X2GOBROKER_DEBUG = False
74 if os.environ.has_key('X2GOBROKER_DEBUG_INTERACTIVELY'):
75     X2GOBROKER_DEBUG_INTERACTIVELY = ( os.environ['X2GOBROKER_DEBUG_INTERACTIVELY'].lower() in ('1', 'on', 'true', 'yes', ) )
76 elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_DEBUG_INTERACTIVELY'):
77     X2GOBROKER_DEBUG_INTERACTIVELY=iniconfig.get(iniconfig_section, 'X2GOBROKER_DEBUG_INTERACTIVELY')
78 elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_DEBUG_INTERACTIVELY'):
79     X2GOBROKER_DEBUG_INTERACTIVELY=iniconfig.get('common', 'X2GOBROKER_DEBUG_INTERACTIVELY')
80 else:
81     X2GOBROKER_DEBUG_INTERACTIVELY = False
82 if os.environ.has_key('X2GOBROKER_TESTSUITE'):
83     X2GOBROKER_TESTSUITE = ( os.environ['X2GOBROKER_TESTSUITE'].lower() in ('1', 'on', 'true', 'yes', ) )
84 elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_TESTSUITE'):
85     X2GOBROKER_TESTSUITE=iniconfig.get(iniconfig_section, 'X2GOBROKER_TESTSUITE')
86 elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_TESTSUITE'):
87     X2GOBROKER_TESTSUITE=iniconfig.get('common', 'X2GOBROKER_TESTSUITE')
88 else:
89     X2GOBROKER_TESTSUITE = False
90
91 # enforce debugging for interactive usage
92 if X2GOBROKER_USER != X2GOBROKER_DAEMON_USER:
93     X2GOBROKER_DEBUG = True
94
95 # raise log levels to CRITICAL if we are running the unittests...
96 if X2GOBROKER_TESTSUITE:
97     logger_broker.setLevel(logging.CRITICAL)
98     logger_access.setLevel(logging.CRITICAL)
99     logger_error.setLevel(logging.CRITICAL)
100
101 if os.environ.has_key('X2GOBROKER_CONFIG'):
102     X2GOBROKER_CONFIG = os.environ['X2GOBROKER_CONFIG']
103 elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_CONFIG'):
104     X2GOBROKER_CONFIG=iniconfig.get(iniconfig_section, 'X2GOBROKER_CONFIG')
105 elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_CONFIG'):
106     X2GOBROKER_CONFIG=iniconfig.get('common', 'X2GOBROKER_CONFIG')
107 else:
108     X2GOBROKER_CONFIG = "/etc/x2go/x2gobroker.conf"
109
110 if os.environ.has_key('X2GOBROKER_SESSIONPROFILES'):
111     X2GOBROKER_SESSIONPROFILES = os.environ['X2GOBROKER_SESSIONPROFILES']
112 elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_SESSIONPROFILES'):
113     X2GOBROKER_SESSIONPROFILES=iniconfig.get(iniconfig_section, 'X2GOBROKER_SESSIONPROFILES')
114 elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_SESSIONPROFILES'):
115     X2GOBROKER_SESSIONPROFILES=iniconfig.get('common', 'X2GOBROKER_SESSIONPROFILES')
116 else:
117     X2GOBROKER_SESSIONPROFILES = "/etc/x2go/broker/x2gobroker-sessionprofiles.conf"
118
119 if os.environ.has_key('X2GOBROKER_AGENT_CMD'):
120     X2GOBROKER_AGENT_CMD = os.environ['X2GOBROKER_AGENT_CMD']
121 elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_AGENT_CMD'):
122     X2GOBROKER_AGENT_CMD=iniconfig.get(iniconfig_section, 'X2GOBROKER_AGENT_CMD')
123 elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_AGENT_CMD'):
124     X2GOBROKER_AGENT_CMD=iniconfig.get('common', 'X2GOBROKER_AGENT_CMD')
125 else:
126     X2GOBROKER_AGENT_CMD = "/usr/lib/x2go/x2gobroker-agent"
127
128 if os.environ.has_key('X2GOBROKER_AUTHSERVICE_SOCKET'):
129     X2GOBROKER_AUTHSERVICE_SOCKET=os.environ['X2GOBROKER_AUTHSERVICE_SOCKET']
130 elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_AUTHSERVICE_SOCKET'):
131     X2GOBROKER_AUTHSERVICE_SOCKET=iniconfig.get(iniconfig_section, 'X2GOBROKER_AUTHSERVICE_SOCKET')
132 elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_AUTHSERVICE_SOCKET'):
133     X2GOBROKER_AUTHSERVICE_SOCKET=iniconfig.get('common', 'X2GOBROKER_AUTHSERVICE_SOCKET')
134 else:
135     if os.path.isdir('/run'):
136         RUNDIR = '/run'
137     else:
138         RUNDIR = '/var/run'
139     X2GOBROKER_AUTHSERVICE_SOCKET="{run}/x2gobroker/x2gobroker-authservice.socket".format(run=RUNDIR)
140
141 if os.environ.has_key('X2GOBROKER_DEFAULT_BACKEND'):
142     X2GOBROKER_DEFAULT_BACKEND = os.environ['X2GOBROKER_DEFAULT_BACKEND']
143 elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_DEFAULT_BACKEND'):
144     X2GOBROKER_DEFAULT_BACKEND=iniconfig.get(iniconfig_section, 'X2GOBROKER_DEFAULT_BACKEND')
145 elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_DEFAULT_BACKEND'):
146     X2GOBROKER_DEFAULT_BACKEND=iniconfig.get('common', 'X2GOBROKER_DEFAULT_BACKEND')
147 else:
148     X2GOBROKER_DEFAULT_BACKEND = "inifile"
149
150 if os.environ.has_key('X2GOBROKER_SSL_CERTFILE'):
151     X2GOBROKER_SSL_CERTFILE = os.environ['X2GOBROKER_SSL_CERTFILE']
152 elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_SSL_CERTFILE'):
153     X2GOBROKER_SSL_CERTFILE=iniconfig.get(iniconfig_section, 'X2GOBROKER_SSL_CERTFILE')
154 elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_SSL_CERTFILE'):
155     X2GOBROKER_SSL_CERTFILE=iniconfig.get('common', 'X2GOBROKER_SSL_CERTFILE')
156 else:
157     X2GOBROKER_SSL_CERTFILE = ""
158
159 if os.environ.has_key('X2GOBROKER_SSL_KEYFILE'):
160     X2GOBROKER_SSL_KEYFILE = os.environ['X2GOBROKER_SSL_KEYFILE']
161 elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_SSL_KEYFILE'):
162     X2GOBROKER_SSL_KEYFILE=iniconfig.get(iniconfig_section, 'X2GOBROKER_SSL_KEYFILE')
163 elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_SSL_KEYFILE'):
164     X2GOBROKER_SSL_KEYFILE=iniconfig.get('common', 'X2GOBROKER_SSL_KEYFILE')
165 else:
166     X2GOBROKER_SSL_KEYFILE = ""
167
168 ###
169 ### static / hard-coded defaults
170 ###
171
172 if socket.gethostname().find('.') >= 0:
173     X2GOBROKER_HOSTNAME = socket.gethostname()
174 else:
175     X2GOBROKER_HOSTNAME = socket.gethostbyaddr(socket.gethostname())[0]
176
177 # the home directory of the user that the daemon/cgi runs as
178 X2GOBROKER_HOME = os.path.normpath(os.path.expanduser('~{broker_uid}'.format(broker_uid=X2GOBROKER_DAEMON_USER)))
179
180 # defaults for X2Go Sessino Broker configuration file
181 X2GOBROKER_CONFIG_DEFAULTS = {
182     'global': {
183         u'require-password': True,
184         u'require-cookie': False,
185         u'use-static-cookie': True,
186         u'auth-timeout': 36000,
187         u'cookie-directory': '/var/lib/x2gobroker/cookies',
188         u'verify-ip': True,
189         u'pre_auth_scripts': [],
190         u'post_auth_scripts': [],
191         u'select_session_scripts': [],
192         u'my-cookie': uuid.uuid4(),
193         u'enable-plain-output': True,
194         u'enable-json-output': True,
195         u'enable-uccs-output': False,
196         u'my-uccs-url-base': 'http://localhost:8080/',
197         u'default-auth-mech': u'pam',
198         u'default-user-db': u'libnss',
199         u'default-group-db': u'libnss',
200         u'ignore-primary-group-memberships': True,
201         u'default-session-autologin': False,
202         u'default-authorized-keys': u'%h/.x2go/authorized_keys',
203         u'default-agent-query-mode': u'NONE',
204     },
205     'broker_base': {
206         u'enable': False,
207     },
208     'broker_zeroconf': {
209         u'enable': False,
210         u'auth-mech': u'pam',
211         u'user-db': u'libnss',
212         u'group-db': u'libnss',
213         u'desktop-shell': u'KDE',
214     },
215     'broker_inifile': {
216         u'enable': True,
217         u'session-profiles': u'/etc/x2go/broker/x2gobroker-sessionprofiles.conf',
218         u'auth-mech': u'',
219         u'user-db': u'',
220         u'group-db': u'',
221     },
222     'broker_ldap': {
223         u'enable': False,
224         u'auth-mech': u'ldap',
225         u'user-db': u'ldap',
226         u'group-db': u'ldap',
227         u'uri': u'ldap://localhost:389',
228         u'base': u'dc=example,dc=org',
229         u'user-search-filter': u'(&(objectClass=posixAccount)(uid=*))',
230         u'host-search-filter': u'(&(objectClass=ipHost)(serial=X2GoServer)(cn=*))',
231         u'group-search-filter': u'(&(objectClass=posifxGroup)(cn=*))',
232         u'starttls': False,
233         u'agent-query-mode': u'SSH',
234     },
235 }
236
237 X2GO_DESKTOP_SESSIONS= [
238     'KDE',
239     'GNOME',
240     'XFCE',
241     'CINNAMON',
242     'MATE',
243     'XFCE',
244     'LXDE',
245     'TRINITY',
246     'UNITY',
247     'XDMCP',
248 ]
249
250 # defaults for X2Go Sessino Broker session profiles file
251 X2GOBROKER_SESSIONPROFILE_DEFAULTS = {
252     u'DEFAULT': {
253         u'command': u'TERMINAL',
254         u'defsndport': True,
255         u'useiconv': False,
256         u'iconvfrom': u'UTF-8',
257         u'height': 600,
258         u'export': u'',
259         u'quality': 9,
260         u'fullscreen': False,
261         u'layout': u'',
262         u'useexports': True,
263         u'width': 800,
264         u'speed': 2,
265         u'soundsystem': u'pulse',
266         u'print': True,
267         u'type': u'auto',
268         u'sndport': 4713,
269         u'xinerama': True,
270         u'variant': u'',
271         u'usekbd': True,
272         u'fstunnel': True,
273         u'applications': [u'TERMINAL',u'WWWBROWSER',u'MAILCLIENT',u'OFFICE'],
274         u'multidisp': False,
275         u'sshproxyport': 22,
276         u'sound': True,
277         u'rootless': True,
278         u'iconvto': u'UTF-8',
279         u'soundtunnel': True,
280         u'dpi': 96,
281         u'sshport': 22,
282         u'setdpi': 0,
283         u'pack': u'16m-jpeg',
284         u'user': 'BROKER_USER',
285         u'host': [ u'localhost', ],
286         u'directrdp': False,
287         u'acl-users-allow': [],
288         u'acl-users-deny': [],
289         u'acl-users-order': '',
290         u'acl-groups-allow': [],
291         u'acl-groups-deny': [],
292         u'acl-groups-order': '',
293         u'acl-clients-allow': [],
294         u'acl-clients-deny': [],
295         u'acl-clients-order': '',
296         u'acl-any-order': u'deny-allow',
297     },
298 }