<NME> settings.py
<BEF> """
Django settings for test_project project.

Generated by 'django-admin startproject' using Django 1.11.8.

For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""

from __future__ import unicode_literals

import os
from logging.handlers import SysLogHandler

from modoboa.test_settings import *  # noqa

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.realpath(os.path.dirname(os.path.dirname(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "!8o(-dbbl3e+*bh7nx-^xysdt)1gso*%@4ze4-9_9o+i&amp;t--u_"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = "DEBUG" in os.environ

ALLOWED_HOSTS = [
    "127.0.0.1",
    "localhost",
]

SITE_ID = 1

# Security settings

X_FRAME_OPTIONS = "SAMEORIGIN"

# Application definition

INSTALLED_APPS = (
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.sites",
    "django.contrib.staticfiles",
    "reversion",
    "ckeditor",
    "ckeditor_uploader",
    "rest_framework",
    "rest_framework.authtoken",
)

# A dedicated place to register Modoboa applications
# Do not delete it.
# Do not change the order.
MODOBOA_APPS = (
    "modoboa",
    "modoboa.core",
    "modoboa.lib",
    "modoboa.admin",
    "modoboa.transport",
    "modoboa.relaydomains",
    "modoboa.limits",
    "modoboa.parameters",
    "modoboa.dnstools",
    # Modoboa extensions here.
)

    'modoboa.transport',
    'modoboa.relaydomains',
    'modoboa.limits',
    'modoboa.parameters',
    'modoboa.dnstools',
    'modoboa.policyd',

INSTALLED_APPS += MODOBOA_APPS

AUTH_USER_MODEL = "core.User"

MIDDLEWARE = (
    "x_forwarded_for.middleware.XForwardedForMiddleware",
    "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.locale.LocaleMiddleware",
    "django.middleware.clickjacking.XFrameOptionsMiddleware",
    "modoboa.core.middleware.LocalConfigMiddleware",
    "modoboa.lib.middleware.AjaxLoginRedirect",
    "modoboa.lib.middleware.CommonExceptionCatcher",
    "modoboa.lib.middleware.RequestCatcherMiddleware",
)

AUTHENTICATION_BACKENDS = (
    # 'modoboa.lib.authbackends.LDAPBackend',
    # 'modoboa.lib.authbackends.SMTPBackend',
    "django.contrib.auth.backends.ModelBackend",
)

# SMTP authentication
    'modoboa.lib.middleware.AjaxLoginRedirect',
    'modoboa.lib.middleware.CommonExceptionCatcher',
    'modoboa.lib.middleware.RequestCatcherMiddleware',
)

TEMPLATES = [
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "DIRS": [],
        "APP_DIRS": True,
        "OPTIONS": {
            "context_processors": [
                "django.template.context_processors.debug",
                "django.template.context_processors.request",
                "django.contrib.auth.context_processors.auth",
                "django.template.context_processors.i18n",
                "django.template.context_processors.media",
                "django.template.context_processors.static",
                "django.template.context_processors.tz",
                "django.contrib.messages.context_processors.messages",
                "modoboa.core.context_processors.top_notifications",
            ],
            "debug": DEBUG,
        },
    },
]

ROOT_URLCONF = "test_project.urls"

WSGI_APPLICATION = "test_project.wsgi.application"


# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/

LANGUAGE_CODE = "en-us"

TIME_ZONE = "UTC"

USE_I18N = True


WSGI_APPLICATION = 'test_project.wsgi.application'
USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/

STATIC_URL = "/sitestatic/"
STATIC_ROOT = os.path.join(BASE_DIR, "sitestatic")
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "..", "modoboa", "bower_components"),
)

MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media")

# Rest framework settings

REST_FRAMEWORK = {
    "DEFAULT_AUTHENTICATION_CLASSES": (
        "rest_framework.authentication.TokenAuthentication",
        "rest_framework.authentication.SessionAuthentication",
    ),
}

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

# DOVECOT_LOOKUP_PATH = ('/path/to/dovecot', )

MODOBOA_API_URL = "https://api.modoboa.org/1/"

# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",  # NOQA:E501
    },
    {
        "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",  # NOQA:E501
    },
    {
        "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",  # NOQA:E501
    },
    {
        "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",  # NOQA:E501
    },
    {
        "NAME": "modoboa.core.password_validation.ComplexityValidator",
        "OPTIONS": {
            "upper": 1,
            "lower": 1,
            "digits": 1,
            "specials": 0
        }
    },
]
REDIS_QUOTA_DB = 0
REDIS_URL = 'redis://{}:{}/{}'.format(REDIS_HOST, REDIS_PORT, REDIS_QUOTA_DB)

# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
CKEDITOR_ALLOW_NONIMAGE_FILES = False

CKEDITOR_CONFIGS = {
    "default": {
        "allowedContent": True,
        "toolbar": "Modoboa",
        "width": None,
        "toolbar_Modoboa": [
            ["Bold", "Italic", "Underline"],
            ["JustifyLeft", "JustifyCenter", "JustifyRight", "JustifyBlock"],
            ["BidiLtr", "BidiRtl", "Language"],
            ["NumberedList", "BulletedList", "-", "Outdent", "Indent"],
            ["Undo", "Redo"],
            ["Link", "Unlink", "Anchor", "-", "Smiley"],
            ["TextColor", "BGColor", "-", "Source"],
            ["Font", "FontSize"],
            ["Image", ],
            ["SpellChecker"]
        ],
    },
}
CKEDITOR_UPLOAD_PATH = "uploads/"
# Logging configuration

LOGGING = {
    "version": 1,
    "disable_existing_loggers": False,
    "formatters": {
        "syslog": {
            "format": "%(name)s: %(levelname)s %(message)s"
        },
    },
    "handlers": {
        "syslog-auth": {
            "class": "logging.handlers.SysLogHandler",
            "facility": SysLogHandler.LOG_AUTH,
            "formatter": "syslog"
        },
        "modoboa": {
            "class": "modoboa.core.loggers.SQLHandler",
        }
    },
    "loggers": {
        "modoboa.auth": {
            "handlers": ["syslog-auth", "modoboa"],
            "level": "INFO",
            "propagate": False
        },
        "modoboa.admin": {
            "handlers": ["modoboa"],
            "level": "INFO",
            "propagate": False
        }
    }
}

# Load settings from extensions
        'syslog-auth': {
            'class': 'logging.handlers.SysLogHandler',
            'facility': SysLogHandler.LOG_AUTH,
            'formatter': 'syslog'
        },
        'modoboa': {
            'class': 'modoboa.core.loggers.SQLHandler',
        },
        'console': {
            'class': 'logging.StreamHandler'
        },
        'django.server': {
            'level': 'INFO',
            'class': 'logging.StreamHandler',
            'formatter': 'django.server',
        },
    },
    'loggers': {
        'django': {
            'handlers': ['mail-admins'],
            'level': 'ERROR',
            'propagate': False
        },
        'modoboa.auth': {
            'handlers': ['syslog-auth', 'modoboa'],
            'level': 'INFO',
            'propagate': False
        },
        'modoboa.admin': {
            'handlers': ['modoboa'],
            'level': 'INFO',
            'propagate': False
        },
        'django.server': {
            'handlers': ['django.server'],
            'level': 'INFO',
            'propagate': False,
        },
        # 'django_auth_ldap': {
        #     'level': 'DEBUG',
        #     'handlers': ['console']
        # },
    }
}

SILENCED_SYSTEM_CHECKS = [
    "security.W019",  # modoboa uses iframes to display e-mails
]

DISABLE_DASHBOARD_EXTERNAL_QUERIES = False

# Load settings from extensions

LDAP_SERVER_PORT = os.environ.get('LDAP_SERVER_PORT', 3389)

<MSG> Update settings template and test_project's one (#1830)


<DFF> @@ -1,75 +1,83 @@
 """
 Django settings for test_project project.
 
-Generated by 'django-admin startproject' using Django 1.11.8.
-
 For more information on this file, see
-https://docs.djangoproject.com/en/1.11/topics/settings/
+https://docs.djangoproject.com/en/2.2/topics/settings/
 
 For the full list of settings and their values, see
-https://docs.djangoproject.com/en/1.11/ref/settings/
+https://docs.djangoproject.com/en/2.2/ref/settings/
 """
 
-from __future__ import unicode_literals
-
-import os
 from logging.handlers import SysLogHandler
+import os
 
 from modoboa.test_settings import *  # noqa
 
+
 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
 BASE_DIR = os.path.realpath(os.path.dirname(os.path.dirname(__file__)))
 
 
 # Quick-start development settings - unsuitable for production
-# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
+# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
 
 # SECURITY WARNING: keep the secret key used in production secret!
-SECRET_KEY = "!8o(-dbbl3e+*bh7nx-^xysdt)1gso*%@4ze4-9_9o+i&amp;t--u_"
+SECRET_KEY = '!8o(-dbbl3e+*bh7nx-^xysdt)1gso*%@4ze4-9_9o+i&amp;t--u_'
 
 # SECURITY WARNING: don't run with debug turned on in production!
-DEBUG = "DEBUG" in os.environ
+DEBUG = 'DEBUG' in os.environ
 
 ALLOWED_HOSTS = [
-    "127.0.0.1",
-    "localhost",
+    '127.0.0.1',
+    'localhost',
 ]
 
 SITE_ID = 1
 
+# A list of all the people who get code error notifications. When DEBUG=False
+# and a view raises an exception, Django will email these people with the full
+# exception information.
+# See https://docs.djangoproject.com/en/dev/ref/settings/#admins
+#ADMINS = [('Administrator', 'admin@example.net')]
+
+# The email address that error messages come from, such as those sent to ADMINS
+#SERVER_EMAIL = 'webmaster@example.net'
+
 # Security settings
 
 X_FRAME_OPTIONS = "SAMEORIGIN"
+CSRF_COOKIE_SECURE = True
+SESSION_COOKIE_SECURE = True
 
 # Application definition
 
 INSTALLED_APPS = (
-    "django.contrib.auth",
-    "django.contrib.contenttypes",
-    "django.contrib.sessions",
-    "django.contrib.messages",
-    "django.contrib.sites",
-    "django.contrib.staticfiles",
-    "reversion",
-    "ckeditor",
-    "ckeditor_uploader",
-    "rest_framework",
-    "rest_framework.authtoken",
+    'django.contrib.auth',
+    'django.contrib.contenttypes',
+    'django.contrib.sessions',
+    'django.contrib.messages',
+    'django.contrib.sites',
+    'django.contrib.staticfiles',
+    'reversion',
+    'ckeditor',
+    'ckeditor_uploader',
+    'rest_framework',
+    'rest_framework.authtoken',
 )
 
 # A dedicated place to register Modoboa applications
 # Do not delete it.
 # Do not change the order.
 MODOBOA_APPS = (
-    "modoboa",
-    "modoboa.core",
-    "modoboa.lib",
-    "modoboa.admin",
-    "modoboa.transport",
-    "modoboa.relaydomains",
-    "modoboa.limits",
-    "modoboa.parameters",
-    "modoboa.dnstools",
+    'modoboa',
+    'modoboa.core',
+    'modoboa.lib',
+    'modoboa.admin',
+    'modoboa.transport',
+    'modoboa.relaydomains',
+    'modoboa.limits',
+    'modoboa.parameters',
+    'modoboa.dnstools',
     # Modoboa extensions here.
 )
 
@@ -82,27 +90,27 @@ else:
 
 INSTALLED_APPS += MODOBOA_APPS
 
-AUTH_USER_MODEL = "core.User"
+AUTH_USER_MODEL = 'core.User'
 
 MIDDLEWARE = (
-    "x_forwarded_for.middleware.XForwardedForMiddleware",
-    "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.locale.LocaleMiddleware",
-    "django.middleware.clickjacking.XFrameOptionsMiddleware",
-    "modoboa.core.middleware.LocalConfigMiddleware",
-    "modoboa.lib.middleware.AjaxLoginRedirect",
-    "modoboa.lib.middleware.CommonExceptionCatcher",
-    "modoboa.lib.middleware.RequestCatcherMiddleware",
+    'x_forwarded_for.middleware.XForwardedForMiddleware',
+    '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.locale.LocaleMiddleware',
+    'django.middleware.clickjacking.XFrameOptionsMiddleware',
+    'modoboa.core.middleware.LocalConfigMiddleware',
+    'modoboa.lib.middleware.AjaxLoginRedirect',
+    'modoboa.lib.middleware.CommonExceptionCatcher',
+    'modoboa.lib.middleware.RequestCatcherMiddleware',
 )
 
 AUTHENTICATION_BACKENDS = (
     # 'modoboa.lib.authbackends.LDAPBackend',
     # 'modoboa.lib.authbackends.SMTPBackend',
-    "django.contrib.auth.backends.ModelBackend",
+    'django.contrib.auth.backends.ModelBackend',
 )
 
 # SMTP authentication
@@ -113,37 +121,36 @@ AUTHENTICATION_BACKENDS = (
 
 TEMPLATES = [
     {
-        "BACKEND": "django.template.backends.django.DjangoTemplates",
-        "DIRS": [],
-        "APP_DIRS": True,
-        "OPTIONS": {
-            "context_processors": [
-                "django.template.context_processors.debug",
-                "django.template.context_processors.request",
-                "django.contrib.auth.context_processors.auth",
-                "django.template.context_processors.i18n",
-                "django.template.context_processors.media",
-                "django.template.context_processors.static",
-                "django.template.context_processors.tz",
-                "django.contrib.messages.context_processors.messages",
-                "modoboa.core.context_processors.top_notifications",
+        'BACKEND': 'django.template.backends.django.DjangoTemplates',
+        'DIRS': [],
+        'APP_DIRS': True,
+        'OPTIONS': {
+            'context_processors': [
+                'django.template.context_processors.debug',
+                'django.template.context_processors.request',
+                'django.contrib.auth.context_processors.auth',
+                'django.template.context_processors.i18n',
+                'django.template.context_processors.media',
+                'django.template.context_processors.static',
+                'django.template.context_processors.tz',
+                'django.contrib.messages.context_processors.messages',
+                'modoboa.core.context_processors.top_notifications',
             ],
-            "debug": DEBUG,
+            'debug': DEBUG,
         },
     },
 ]
 
-ROOT_URLCONF = "test_project.urls"
-
-WSGI_APPLICATION = "test_project.wsgi.application"
+ROOT_URLCONF = 'test_project.urls'
 
+WSGI_APPLICATION = 'test_project.wsgi.application'
 
 # Internationalization
-# https://docs.djangoproject.com/en/1.11/topics/i18n/
+# https://docs.djangoproject.com/en/2.2/topics/i18n/
 
-LANGUAGE_CODE = "en-us"
+LANGUAGE_CODE = 'en-us'
 
-TIME_ZONE = "UTC"
+TIME_ZONE = 'UTC'
 
 USE_I18N = True
 
@@ -152,23 +159,23 @@ USE_L10N = True
 USE_TZ = True
 
 # Static files (CSS, JavaScript, Images)
-# https://docs.djangoproject.com/en/1.11/howto/static-files/
+# https://docs.djangoproject.com/en/2.2/howto/static-files/
 
-STATIC_URL = "/sitestatic/"
-STATIC_ROOT = os.path.join(BASE_DIR, "sitestatic")
+STATIC_URL = '/sitestatic/'
+STATIC_ROOT = os.path.join(BASE_DIR, 'sitestatic')
 STATICFILES_DIRS = (
-    os.path.join(BASE_DIR, "..", "modoboa", "bower_components"),
+    os.path.join(BASE_DIR, '..', 'modoboa', 'bower_components'),
 )
 
-MEDIA_URL = "/media/"
-MEDIA_ROOT = os.path.join(BASE_DIR, "media")
+MEDIA_URL = '/media/'
+MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
 
 # Rest framework settings
 
 REST_FRAMEWORK = {
-    "DEFAULT_AUTHENTICATION_CLASSES": (
-        "rest_framework.authentication.TokenAuthentication",
-        "rest_framework.authentication.SessionAuthentication",
+    'DEFAULT_AUTHENTICATION_CLASSES': (
+        'rest_framework.authentication.TokenAuthentication',
+        'rest_framework.authentication.SessionAuthentication',
     ),
 }
 
@@ -177,31 +184,31 @@ REST_FRAMEWORK = {
 
 # DOVECOT_LOOKUP_PATH = ('/path/to/dovecot', )
 
-MODOBOA_API_URL = "https://api.modoboa.org/1/"
+MODOBOA_API_URL = 'https://api.modoboa.org/1/'
 
 # Password validation
-# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
+# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
 
 AUTH_PASSWORD_VALIDATORS = [
     {
-        "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",  # NOQA:E501
+        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
     },
     {
-        "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",  # NOQA:E501
+        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
     },
     {
-        "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",  # NOQA:E501
+        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
     },
     {
-        "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",  # NOQA:E501
+        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
     },
     {
-        "NAME": "modoboa.core.password_validation.ComplexityValidator",
-        "OPTIONS": {
-            "upper": 1,
-            "lower": 1,
-            "digits": 1,
-            "specials": 0
+        'NAME': 'modoboa.core.password_validation.ComplexityValidator',
+        'OPTIONS': {
+            'upper': 1,
+            'lower': 1,
+            'digits': 1,
+            'specials': 0
         }
     },
 ]
@@ -219,21 +226,21 @@ CKEDITOR_BROWSE_SHOW_DIRS = True
 CKEDITOR_ALLOW_NONIMAGE_FILES = False
 
 CKEDITOR_CONFIGS = {
-    "default": {
-        "allowedContent": True,
-        "toolbar": "Modoboa",
-        "width": None,
-        "toolbar_Modoboa": [
-            ["Bold", "Italic", "Underline"],
-            ["JustifyLeft", "JustifyCenter", "JustifyRight", "JustifyBlock"],
-            ["BidiLtr", "BidiRtl", "Language"],
-            ["NumberedList", "BulletedList", "-", "Outdent", "Indent"],
-            ["Undo", "Redo"],
-            ["Link", "Unlink", "Anchor", "-", "Smiley"],
-            ["TextColor", "BGColor", "-", "Source"],
-            ["Font", "FontSize"],
-            ["Image", ],
-            ["SpellChecker"]
+    'default': {
+        'allowedContent': True,
+        'toolbar': 'Modoboa',
+        'width': None,
+        'toolbar_Modoboa': [
+            ['Bold', 'Italic', 'Underline'],
+            ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
+            ['BidiLtr', 'BidiRtl', 'Language'],
+            ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent'],
+            ['Undo', 'Redo'],
+            ['Link', 'Unlink', 'Anchor', '-', 'Smiley'],
+            ['TextColor', 'BGColor', '-', 'Source'],
+            ['Font', 'FontSize'],
+            ['Image', ],
+            ['SpellChecker']
         ],
     },
 }
@@ -241,35 +248,48 @@ CKEDITOR_CONFIGS = {
 # Logging configuration
 
 LOGGING = {
-    "version": 1,
-    "disable_existing_loggers": False,
-    "formatters": {
-        "syslog": {
-            "format": "%(name)s: %(levelname)s %(message)s"
+    'version': 1,
+    'formatters': {
+        'syslog': {
+            'format': '%(name)s: %(levelname)s %(message)s'
         },
     },
-    "handlers": {
-        "syslog-auth": {
-            "class": "logging.handlers.SysLogHandler",
-            "facility": SysLogHandler.LOG_AUTH,
-            "formatter": "syslog"
+    'handlers': {
+        'mail-admins': {
+            'level': 'ERROR',
+            'class': 'django.utils.log.AdminEmailHandler',
+            'include_html': True
+        },
+        'syslog-auth': {
+            'class': 'logging.handlers.SysLogHandler',
+            'facility': SysLogHandler.LOG_AUTH,
+            'formatter': 'syslog'
         },
-        "modoboa": {
-            "class": "modoboa.core.loggers.SQLHandler",
+        'modoboa': {
+            'class': 'modoboa.core.loggers.SQLHandler',
         }
     },
-    "loggers": {
-        "modoboa.auth": {
-            "handlers": ["syslog-auth", "modoboa"],
-            "level": "INFO",
-            "propagate": False
+    'loggers': {
+        'django': {
+            'handlers': ['mail-admins'],
+            'level': 'ERROR',
+            'propagate': False
         },
-        "modoboa.admin": {
-            "handlers": ["modoboa"],
-            "level": "INFO",
-            "propagate": False
+        'modoboa.auth': {
+            'handlers': ['syslog-auth', 'modoboa'],
+            'level': 'INFO',
+            'propagate': False
+        },
+        'modoboa.admin': {
+            'handlers': ['modoboa'],
+            'level': 'INFO',
+            'propagate': False
         }
     }
 }
 
+SILENCED_SYSTEM_CHECKS = [
+    "security.W019",  # modoboa uses iframes to display e-mails
+]
+
 # Load settings from extensions

Update settings template and test_project's one (#1830)