Projet

Général

Profil

Télécharger (6,33 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / univnautes / sp / sp / settings.py @ 80f5b222

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 = os.environ.get('DEBUG') == 'yes'
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
MANAGERS = ADMINS
17

    
18
DATABASES = {
19
    'default': {
20
        'ENGINE': 'django.db.backends.sqlite3',
21
        'NAME': '/var/db/univnautes-sp.sqlite3',
22
    }
23
}
24

    
25
# Hosts/domain names that are valid for this site; required if DEBUG is False
26
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
27
ALLOWED_HOSTS = ['*']
28

    
29
# Local time zone for this installation. Choices can be found here:
30
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
31
# although not all choices may be available on all operating systems.
32
# In a Windows environment this must be set to your system time zone.
33
TIME_ZONE = 'Europe/Paris'
34

    
35
# Language code for this installation. All choices can be found here:
36
# http://www.i18nguy.com/unicode/language-identifiers.html
37
LANGUAGE_CODE = 'fr-fr'
38

    
39
SITE_ID = 1
40

    
41
# If you set this to False, Django will make some optimizations so as not
42
# to load the internationalization machinery.
43
USE_I18N = True
44

    
45
# If you set this to False, Django will not format dates, numbers and
46
# calendars according to the current locale.
47
USE_L10N = True
48

    
49
# If you set this to False, Django will not use timezone-aware datetimes.
50
USE_TZ = True
51

    
52
# Absolute filesystem path to the directory that will hold user-uploaded files.
53
# Example: "/var/www/example.com/media/"
54
MEDIA_ROOT = ''
55

    
56
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
57
# trailing slash.
58
# Examples: "http://example.com/media/", "http://media.example.com/"
59
MEDIA_URL = ''
60

    
61
# Absolute path to the directory static files should be collected to.
62
# Don't put anything in this directory yourself; store your static files
63
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
64
# Example: "/var/www/example.com/static/"
65
STATIC_ROOT = os.path.join(PROJECT_PATH, 'www', 'static')
66

    
67
# URL prefix for static files.
68
# Example: "http://example.com/static/", "http://static.example.com/"
69
STATIC_URL = '/static/'
70

    
71
# Additional locations of static files
72
STATICFILES_DIRS = (
73
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
74
    # Always use forward slashes, even on Windows.
75
    # Don't forget to use absolute paths, not relative paths.
76
)
77

    
78
# List of finder classes that know how to find static files in
79
# various locations.
80
STATICFILES_FINDERS = (
81
    'django.contrib.staticfiles.finders.FileSystemFinder',
82
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
83
)
84

    
85
# Make this unique, and don't share it with anybody.
86
SECRET_KEY_FILENAME='/usr/local/univnautes/sp/secret.key'
87
try:
88
    with open(SECRET_KEY_FILENAME, 'rb') as sk:
89
        SECRET_KEY = sk.read()
90
except IOError:
91
    import random, string
92
    SECRET_KEY = "".join([random.SystemRandom().choice(string.digits + string.letters + string.punctuation) for i in range(100)])
93
    with open(SECRET_KEY_FILENAME, 'wb') as sk:
94
        sk.write(SECRET_KEY)
95

    
96
# List of callables that know how to import templates from various sources.
97
TEMPLATE_LOADERS = (
98
    'django.template.loaders.filesystem.Loader',
99
    'django.template.loaders.app_directories.Loader',
100
)
101

    
102
MIDDLEWARE_CLASSES = (
103
    'django.middleware.common.CommonMiddleware',
104
    'django.contrib.sessions.middleware.SessionMiddleware',
105
    'django.middleware.csrf.CsrfViewMiddleware',
106
    'django.contrib.auth.middleware.AuthenticationMiddleware',
107
    'django.contrib.messages.middleware.MessageMiddleware',
108
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
109
)
110

    
111
ROOT_URLCONF = 'sp.urls'
112

    
113
# Python dotted path to the WSGI application used by Django's runserver.
114
WSGI_APPLICATION = 'sp.wsgi.application'
115

    
116
TEMPLATE_DIRS = (
117
    os.path.join(PROJECT_PATH, 'sp', 'templates'),
118
)
119

    
120
INSTALLED_APPS = (
121
    'django.contrib.auth',
122
    'django.contrib.contenttypes',
123
    'django.contrib.sessions',
124
    'django.contrib.sites',
125
    'django.contrib.messages',
126
    'django.contrib.staticfiles',
127
    'authentic2.idp',
128
    'authentic2.attribute_aggregator',
129
    'authentic2.saml',
130
    'authentic2.authsaml2',
131
    'sp',
132
)
133

    
134
if DEBUG:
135
    INSTALLED_APPS += ('django.contrib.admin',)
136

    
137
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'
138

    
139
SESSION_COOKIE_NAME = 'univnautes-sp-sessionid'
140
SESSION_ENGINE = 'django.contrib.sessions.backends.file'
141
SESSION_FILE_PATH = '/var/tmp/univnautes-sp-sessions'
142
try:
143
    os.mkdir(SESSION_FILE_PATH)
144
except:
145
    pass
146

    
147
MESSAGE_STORAGE = 'django.contrib.messages.storage.cookie.CookieStorage'
148

    
149
LOGIN_REDIRECT_URL = '/'
150

    
151

    
152
# logging configuration
153
# FIXME : syslog (freebsd -> /var/run/log) / local4 / debug
154
LOGGING = {
155
    'version': 1,
156
    'disable_existing_loggers': False,
157
    'handlers': {
158
    'tmpspfile': {
159
            'level': 'DEBUG',
160
            'class': 'logging.FileHandler',
161
            'filename': '/tmp/sp.log'
162
    },
163
    },
164
    'loggers': {
165
        'django.request': {
166
            'handlers': ['tmpspfile'],
167
            'level': 'DEBUG',
168
            'propagate': True,
169
        },
170
    }
171
}
172

    
173
# authentic2 settings (SP)
174
LOCAL_METADATA_CACHE_TIMEOUT = 600
175
SAML_METADATA_ROOT = 'metadata'
176
SAML_METADATA_AUTOLOAD = 'none'
177

    
178
AUTH_FRONTENDS = ('authentic2.authsaml2.frontend.AuthSAML2Frontend',)
179
AUTHENTICATION_BACKENDS = (
180
        'django.contrib.auth.backends.ModelBackend',
181
        'authentic2.authsaml2.backends.AuthSAML2PersistentBackend',
182
        'authentic2.authsaml2.backends.AuthSAML2TransientBackend')
183

    
184

    
185
# get some values from config.xml
186
# => server must be restarted if config.xml is changed
187

    
188
if 'CONFIG_XML' in os.environ:
189
    # for run this application outside a real pfSense
190
    CONFIG_XML = os.environ['CONFIG_XML']
191
else:
192
    CONFIG_XML = '/cf/conf/config.xml'
193

    
194
sp = pfconfigxml.get_sp()
195
# SAML certificate
196
SAML_SIGNATURE_PUBLIC_KEY = sp.get('saml_cert', {}).get('crt')
197
SAML_SIGNATURE_PRIVATE_KEY = sp.get('saml_cert', {}).get('prv')
198

    
199
# SESSION_COOKIE_AGE from pfsenseid, at least 2 minutes
200
SESSION_COOKIE_AGE = max(sp.get('cp', {}).get('idletimeout', 2)*60, 2*60)
201

    
202
# SP User Interface parameters
203
SP_UI = sp.get('ui', {})
204
TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
205
    'sp.context_processors.sp',
206
    )
207

    
208
# FIXME: get this from SP_UI config
209
PROXYMAP_URL  = 'http://lactuca.entrouvert.org/proxymap/mapbox/%(z)d/%(x)d/%(y)d.png32'
210

    
(4-4/8)