2024-07-02 09:52:05 +02:00
|
|
|
"""
|
|
|
|
Django settings for the DGSI project.
|
|
|
|
"""
|
|
|
|
|
2024-07-02 14:53:34 +02:00
|
|
|
import ssl
|
2024-07-02 09:52:05 +02:00
|
|
|
from pathlib import Path
|
|
|
|
|
2024-07-02 14:53:34 +02:00
|
|
|
import ldap3
|
2024-07-02 09:52:05 +02:00
|
|
|
from loadcredential import Credentials
|
|
|
|
|
|
|
|
credentials = Credentials(env_prefix="CE_")
|
|
|
|
|
|
|
|
# Build paths inside the project like this: BASE_DIR / "subdir".
|
|
|
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
|
|
|
|
|
|
# WARNING: keep the secret key used in production secret!
|
|
|
|
SECRET_KEY = credentials["SECRET_KEY"]
|
|
|
|
|
|
|
|
# WARNING: don't run with debug turned on in production!
|
|
|
|
DEBUG = credentials.get_json("DEBUG", False)
|
|
|
|
|
|
|
|
ALLOWED_HOSTS = credentials.get_json("ALLOWED_HOSTS", [])
|
|
|
|
|
2024-07-02 14:53:34 +02:00
|
|
|
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
|
|
|
|
|
2024-07-02 09:52:05 +02:00
|
|
|
###
|
|
|
|
# List the installed applications
|
|
|
|
|
|
|
|
INSTALLED_APPS = [
|
|
|
|
"django.contrib.admin",
|
|
|
|
"django.contrib.auth",
|
|
|
|
"django.contrib.contenttypes",
|
|
|
|
"django.contrib.sessions",
|
|
|
|
"django.contrib.messages",
|
|
|
|
"django.contrib.staticfiles",
|
2024-07-02 14:53:34 +02:00
|
|
|
# "cas_eleves",
|
2024-07-02 09:52:05 +02:00
|
|
|
"cas_server",
|
|
|
|
]
|
|
|
|
|
|
|
|
###
|
|
|
|
# List the installed middlewares
|
|
|
|
|
|
|
|
MIDDLEWARE = [
|
|
|
|
"django.middleware.security.SecurityMiddleware",
|
|
|
|
"django.contrib.sessions.middleware.SessionMiddleware",
|
|
|
|
"django.middleware.common.CommonMiddleware",
|
|
|
|
"django.middleware.csrf.CsrfViewMiddleware",
|
|
|
|
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
|
|
|
"django.contrib.messages.middleware.MessageMiddleware",
|
|
|
|
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
|
|
|
"django.middleware.locale.LocaleMiddleware",
|
|
|
|
]
|
|
|
|
|
|
|
|
###
|
|
|
|
# The main url configuration
|
|
|
|
|
|
|
|
ROOT_URLCONF = "app.urls"
|
|
|
|
|
2024-07-02 14:53:34 +02:00
|
|
|
###
|
|
|
|
# Template configuration:
|
|
|
|
|
2024-07-02 09:52:05 +02:00
|
|
|
TEMPLATES = [
|
|
|
|
{
|
|
|
|
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
2024-07-02 14:53:34 +02:00
|
|
|
"DIRS": [(BASE_DIR / "cas_eleves" / "templates")],
|
2024-07-02 09:52:05 +02:00
|
|
|
"APP_DIRS": True,
|
|
|
|
"OPTIONS": {
|
|
|
|
"context_processors": [
|
|
|
|
"django.template.context_processors.debug",
|
|
|
|
"django.template.context_processors.request",
|
|
|
|
"django.contrib.auth.context_processors.auth",
|
|
|
|
"django.contrib.messages.context_processors.messages",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2024-07-02 14:53:34 +02:00
|
|
|
CAS_LOGGED_TEMPLATE = "cas_eleves/logged.html"
|
|
|
|
CAS_LOGIN_TEMPLATE = "cas_eleves/login.html"
|
|
|
|
CAS_LOGOUT_TEMPLATE = "cas_eleves/logout.html"
|
|
|
|
CAS_WARN_TEMPLATE = "cas_eleves/warn.html"
|
|
|
|
|
|
|
|
###
|
|
|
|
# Static files (CSS, JavaScript, Images) configuration
|
|
|
|
# -> https://docs.djangoproject.com/en/4.2/howto/static-files/
|
|
|
|
|
|
|
|
STATIC_URL = "/static/"
|
|
|
|
STATICFILES_DIRS = [BASE_DIR / "cas_eleves" / "static"]
|
|
|
|
|
|
|
|
STATIC_ROOT = credentials["STATIC_ROOT"]
|
|
|
|
|
|
|
|
CAS_SHOW_SERVICE_MESSAGES = False
|
2024-07-02 09:52:05 +02:00
|
|
|
|
2024-07-02 14:53:34 +02:00
|
|
|
###
|
|
|
|
# WSGI application configuration
|
|
|
|
|
|
|
|
WSGI_APPLICATION = "app.wsgi.application"
|
|
|
|
|
|
|
|
###
|
|
|
|
# Authentication configuration
|
2024-07-02 09:52:05 +02:00
|
|
|
|
|
|
|
AUTH_PASSWORD_VALIDATORS = [
|
|
|
|
{
|
|
|
|
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2024-07-02 14:53:34 +02:00
|
|
|
###
|
|
|
|
# Database configuration
|
|
|
|
# -> https://docs.djangoproject.com/en/4.2/ref/settings/#databases
|
2024-07-02 09:52:05 +02:00
|
|
|
|
|
|
|
DATABASES = {
|
2024-07-02 14:53:34 +02:00
|
|
|
"default": (
|
|
|
|
{
|
|
|
|
"ENGINE": "django.db.backends.sqlite3",
|
|
|
|
"NAME": BASE_DIR / "db.sqlite3",
|
|
|
|
}
|
|
|
|
if DEBUG
|
|
|
|
else {
|
|
|
|
"ENGINE": "django.db.backends.postgresql",
|
|
|
|
"NAME": "cas_server",
|
|
|
|
"USER": "cas_server",
|
|
|
|
"HOST": "/var/run/postgresql/",
|
|
|
|
}
|
|
|
|
)
|
2024-07-02 09:52:05 +02:00
|
|
|
}
|
|
|
|
|
2024-07-02 14:53:34 +02:00
|
|
|
###
|
|
|
|
# Internationalization configuration
|
|
|
|
# -> https://docs.djangoproject.com/en/4.2/topics/i18n/
|
2024-07-02 09:52:05 +02:00
|
|
|
|
|
|
|
LANGUAGE_CODE = "fr-fr"
|
|
|
|
TIME_ZONE = "Europe/Paris"
|
|
|
|
USE_I18N = True
|
|
|
|
USE_L10N = True
|
|
|
|
USE_TZ = True
|
|
|
|
|
2024-07-02 14:53:34 +02:00
|
|
|
LOCALE_PATHS = [(BASE_DIR / "cas_eleves" / "locale")]
|
|
|
|
|
|
|
|
###
|
|
|
|
# Logging configuration
|
2024-07-02 09:52:05 +02:00
|
|
|
|
|
|
|
LOGGING = {
|
|
|
|
"version": 1,
|
|
|
|
"disable_existing_loggers": False,
|
|
|
|
"handlers": {
|
|
|
|
"console": {
|
|
|
|
"class": "logging.StreamHandler",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"root": {
|
|
|
|
"handlers": ["console"],
|
2024-07-02 14:53:34 +02:00
|
|
|
"level": "DEBUG",
|
2024-07-02 09:52:05 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2024-07-02 14:53:34 +02:00
|
|
|
###
|
|
|
|
# CAS backend configuration
|
|
|
|
# -> https://github.com/nitmir/django-cas-server#settings
|
2024-07-02 09:52:05 +02:00
|
|
|
|
|
|
|
CAS_AUTH_CLASS = "cas_server.auth.LdapAuthUser"
|
2024-07-02 14:53:34 +02:00
|
|
|
CAS_LDAP_SERVER = ldap3.Server(
|
2024-07-02 19:01:35 +02:00
|
|
|
"ldaps://ldap.spi.ens.fr:636",
|
2024-07-02 14:53:34 +02:00
|
|
|
get_info=ldap3.ALL,
|
|
|
|
tls=ldap3.Tls(
|
|
|
|
validate=ssl.CERT_REQUIRED,
|
|
|
|
version=ssl.PROTOCOL_TLSv1_1,
|
|
|
|
ciphers="AES256-SHA",
|
|
|
|
ssl_options=[ssl.OP_LEGACY_SERVER_CONNECT],
|
|
|
|
),
|
|
|
|
)
|
2024-07-02 09:52:05 +02:00
|
|
|
CAS_LDAP_BASE_DN = "dc=spi,dc=ens,dc=fr"
|
|
|
|
CAS_LDAP_USER_QUERY = "(uid=%s)"
|
|
|
|
CAS_LDAP_USERNAME_ATTR = "uid"
|
|
|
|
CAS_LDAP_PASSWORD_CHECK = "bind"
|
2024-07-02 20:37:30 +02:00
|
|
|
|
|
|
|
CAS_NEW_VERSION_EMAIL_WARNING = False
|