1
|
# Django settings for sp project.
|
2
|
|
3
|
import os
|
4
|
import pfconfigxml
|
5
|
from django.conf import global_settings
|
6
|
|
7
|
PROJECT_PATH = os.path.dirname(os.path.dirname(__file__))
|
8
|
|
9
|
DEBUG = False
|
10
|
TEMPLATE_DEBUG = DEBUG
|
11
|
|
12
|
# fastcgi (see http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/)
|
13
|
FORCE_SCRIPT_NAME=''
|
14
|
|
15
|
ADMINS = (
|
16
|
# ('Your Name', 'your_email@example.com'),
|
17
|
)
|
18
|
MANAGERS = ADMINS
|
19
|
|
20
|
DATABASES = {
|
21
|
'default': {
|
22
|
'ENGINE': 'django.db.backends.sqlite3',
|
23
|
'NAME': '/var/db/univnautes-sp.sqlite3',
|
24
|
}
|
25
|
}
|
26
|
|
27
|
# Hosts/domain names that are valid for this site; required if DEBUG is False
|
28
|
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
|
29
|
ALLOWED_HOSTS = ['*']
|
30
|
|
31
|
# Local time zone for this installation. Choices can be found here:
|
32
|
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
|
33
|
# although not all choices may be available on all operating systems.
|
34
|
# In a Windows environment this must be set to your system time zone.
|
35
|
TIME_ZONE = 'Europe/Paris'
|
36
|
|
37
|
# Language code for this installation. All choices can be found here:
|
38
|
# http://www.i18nguy.com/unicode/language-identifiers.html
|
39
|
LANGUAGE_CODE = 'fr-fr'
|
40
|
|
41
|
SITE_ID = 1
|
42
|
|
43
|
# If you set this to False, Django will make some optimizations so as not
|
44
|
# to load the internationalization machinery.
|
45
|
USE_I18N = True
|
46
|
|
47
|
# If you set this to False, Django will not format dates, numbers and
|
48
|
# calendars according to the current locale.
|
49
|
USE_L10N = True
|
50
|
|
51
|
# If you set this to False, Django will not use timezone-aware datetimes.
|
52
|
USE_TZ = True
|
53
|
|
54
|
# Absolute filesystem path to the directory that will hold user-uploaded files.
|
55
|
# Example: "/var/www/example.com/media/"
|
56
|
MEDIA_ROOT = ''
|
57
|
|
58
|
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
|
59
|
# trailing slash.
|
60
|
# Examples: "http://example.com/media/", "http://media.example.com/"
|
61
|
MEDIA_URL = ''
|
62
|
|
63
|
# Absolute path to the directory static files should be collected to.
|
64
|
# Don't put anything in this directory yourself; store your static files
|
65
|
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
|
66
|
# Example: "/var/www/example.com/static/"
|
67
|
STATIC_ROOT = os.path.join(PROJECT_PATH, 'www', 'static')
|
68
|
|
69
|
# URL prefix for static files.
|
70
|
# Example: "http://example.com/static/", "http://static.example.com/"
|
71
|
STATIC_URL = '/static/'
|
72
|
|
73
|
# Additional locations of static files
|
74
|
STATICFILES_DIRS = (
|
75
|
# Put strings here, like "/home/html/static" or "C:/www/django/static".
|
76
|
# Always use forward slashes, even on Windows.
|
77
|
# Don't forget to use absolute paths, not relative paths.
|
78
|
)
|
79
|
|
80
|
# List of finder classes that know how to find static files in
|
81
|
# various locations.
|
82
|
STATICFILES_FINDERS = (
|
83
|
'django.contrib.staticfiles.finders.FileSystemFinder',
|
84
|
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
|
85
|
)
|
86
|
|
87
|
# Make this unique, and don't share it with anybody.
|
88
|
SECRET_KEY_FILENAME='/usr/local/univnautes/sp/secret.key'
|
89
|
try:
|
90
|
with open(SECRET_KEY_FILENAME, 'rb') as sk:
|
91
|
SECRET_KEY = sk.read()
|
92
|
except IOError:
|
93
|
import random, string
|
94
|
SECRET_KEY = "".join([random.SystemRandom().choice(string.digits + string.letters + string.punctuation) for i in range(100)])
|
95
|
with open(SECRET_KEY_FILENAME, 'wb') as sk:
|
96
|
sk.write(SECRET_KEY)
|
97
|
|
98
|
# List of callables that know how to import templates from various sources.
|
99
|
TEMPLATE_LOADERS = (
|
100
|
'django.template.loaders.filesystem.Loader',
|
101
|
'django.template.loaders.app_directories.Loader',
|
102
|
)
|
103
|
|
104
|
MIDDLEWARE_CLASSES = (
|
105
|
'django.middleware.common.CommonMiddleware',
|
106
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
107
|
'django.middleware.csrf.CsrfViewMiddleware',
|
108
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
109
|
'django.contrib.messages.middleware.MessageMiddleware',
|
110
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
111
|
)
|
112
|
|
113
|
ROOT_URLCONF = 'sp.urls'
|
114
|
|
115
|
# Python dotted path to the WSGI application used by Django's runserver.
|
116
|
WSGI_APPLICATION = 'sp.wsgi.application'
|
117
|
|
118
|
TEMPLATE_DIRS = (
|
119
|
os.path.join(PROJECT_PATH, 'sp', 'templates'),
|
120
|
)
|
121
|
|
122
|
INSTALLED_APPS = (
|
123
|
'django.contrib.auth',
|
124
|
'django.contrib.contenttypes',
|
125
|
'django.contrib.sessions',
|
126
|
'django.contrib.sites',
|
127
|
'django.contrib.messages',
|
128
|
'django.contrib.staticfiles',
|
129
|
'authentic2.idp',
|
130
|
'authentic2.attribute_aggregator',
|
131
|
'authentic2.saml',
|
132
|
'authentic2.authsaml2',
|
133
|
'sp',
|
134
|
)
|
135
|
|
136
|
if DEBUG:
|
137
|
INSTALLED_APPS += ('django.contrib.admin',)
|
138
|
|
139
|
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'
|
140
|
|
141
|
SESSION_COOKIE_NAME = 'univnautes-sp-sessionid'
|
142
|
SESSION_ENGINE = 'django.contrib.sessions.backends.file'
|
143
|
SESSION_FILE_PATH = '/var/tmp/univnautes-sp-sessions'
|
144
|
try:
|
145
|
os.mkdir(SESSION_FILE_PATH)
|
146
|
except:
|
147
|
pass
|
148
|
|
149
|
MESSAGE_STORAGE = 'django.contrib.messages.storage.cookie.CookieStorage'
|
150
|
|
151
|
LOGIN_REDIRECT_URL = '/'
|
152
|
|
153
|
|
154
|
# logging configuration
|
155
|
# FIXME : syslog (freebsd -> /var/run/log) / local4 / debug
|
156
|
LOGGING = {
|
157
|
'version': 1,
|
158
|
'disable_existing_loggers': False,
|
159
|
'handlers': {
|
160
|
'tmpspfile': {
|
161
|
'level': 'DEBUG',
|
162
|
'class': 'logging.FileHandler',
|
163
|
'filename': '/tmp/sp.log'
|
164
|
},
|
165
|
},
|
166
|
'loggers': {
|
167
|
'django.request': {
|
168
|
'handlers': ['tmpspfile'],
|
169
|
'level': 'DEBUG',
|
170
|
'propagate': True,
|
171
|
},
|
172
|
}
|
173
|
}
|
174
|
|
175
|
# authentic2 settings (SP)
|
176
|
LOCAL_METADATA_CACHE_TIMEOUT = 600
|
177
|
SAML_METADATA_ROOT = 'metadata'
|
178
|
SAML_METADATA_AUTOLOAD = 'none'
|
179
|
|
180
|
AUTH_FRONTENDS = ('authentic2.authsaml2.frontend.AuthSAML2Frontend',)
|
181
|
AUTHENTICATION_BACKENDS = (
|
182
|
'django.contrib.auth.backends.ModelBackend',
|
183
|
'authentic2.authsaml2.backends.AuthSAML2PersistentBackend',
|
184
|
'authentic2.authsaml2.backends.AuthSAML2TransientBackend')
|
185
|
|
186
|
|
187
|
# get some values from config.xml
|
188
|
# => server must be restarted if config.xml is changed
|
189
|
|
190
|
sp = pfconfigxml.get_sp()
|
191
|
# SAML certificate
|
192
|
SAML_SIGNATURE_PUBLIC_KEY = sp.get('saml_cert', {}).get('crt')
|
193
|
SAML_SIGNATURE_PRIVATE_KEY = sp.get('saml_cert', {}).get('prv')
|
194
|
|
195
|
# SESSION_COOKIE_AGE from pfsenseid, at least 2 minutes
|
196
|
SESSION_COOKIE_AGE = max(sp.get('cp', {}).get('idletimeout', 2)*60, 2*60)
|
197
|
|
198
|
# SP User Interface parameters
|
199
|
SP_UI = sp.get('ui', {})
|
200
|
TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
|
201
|
'sp.context_processors.sp',
|
202
|
)
|
203
|
|
204
|
# FIXME: get this from SP_UI config
|
205
|
PROXYMAP_URL = 'http://lactuca.entrouvert.org/proxymap/mapbox/%(z)d/%(x)d/%(y)d.png32'
|
206
|
|