diff --git a/addons/aldryn-django/aldryn_config.py b/addons/aldryn-django/aldryn_config.py index ce2e926..e3134c5 100644 --- a/addons/aldryn-django/aldryn_config.py +++ b/addons/aldryn-django/aldryn_config.py @@ -75,7 +75,9 @@ class Form(forms.BaseForm): initial=False, help_text=( 'For example, http://example.com/ rather than ' - 'http://example.com/en/ if en (English) is the default language.' + 'http://example.com/en/ if en (English) is the default language. ' + 'If multiple languages are configured, this option will be ignored ' + 'for Django versions prior to 1.10.' ) ) session_timeout = forms.NumberField( @@ -137,6 +139,7 @@ class Form(forms.BaseForm): settings['CACHES']['default'] = django_cache_url.parse(settings['CACHE_URL']) settings['ROOT_URLCONF'] = env('ROOT_URLCONF', 'urls') + settings['ADDON_URLS'].append('aldryn_django.urls') settings['ADDON_URLS_I18N'].append('aldryn_django.i18n_urls') settings['WSGI_APPLICATION'] = 'wsgi.application' @@ -166,13 +169,13 @@ class Form(forms.BaseForm): 'context_processors': [ 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', - 'django.template.context_processors.i18n', - 'django.template.context_processors.debug', - 'django.template.context_processors.request', - 'django.template.context_processors.media', - 'django.template.context_processors.csrf', - 'django.template.context_processors.tz', - 'django.template.context_processors.static', + 'django.core.context_processors.i18n', + 'django.core.context_processors.debug', + 'django.core.context_processors.request', + 'django.core.context_processors.media', + 'django.core.context_processors.csrf', + 'django.core.context_processors.tz', + 'django.core.context_processors.static', 'aldryn_django.context_processors.debug', ], 'loaders': loader_list_class([ @@ -223,6 +226,8 @@ class Form(forms.BaseForm): return settings def domain_settings(self, data, settings, env): + from aldryn_addons.utils import boolean_ish + settings['ALLOWED_HOSTS'] = env('ALLOWED_HOSTS', ['localhost', '*']) # will take a full config dict from ALDRYN_SITES_DOMAINS if available, # otherwise fall back to constructing the dict from DOMAIN, @@ -232,6 +237,8 @@ class Form(forms.BaseForm): settings['DOMAIN'] = domain domains = env('ALDRYN_SITES_DOMAINS', {}) + permanent_redirect = boolean_ish(env('ALDRYN_SITES_REDIRECT_PERMANENT', False)) + if not domains and domain: domain_aliases = [ d.strip() @@ -252,6 +259,7 @@ class Form(forms.BaseForm): }, } settings['ALDRYN_SITES_DOMAINS'] = domains + settings['ALDRYN_SITES_REDIRECT_PERMANENT'] = permanent_redirect # This is ensured again by aldryn-sites, but we already do it here # as we need the full list of domains later when configuring @@ -296,11 +304,47 @@ class Form(forms.BaseForm): 'django.middleware.security.SecurityMiddleware', ) + # Add the debreach middlewares to counter CRIME/BREACH attacks. + # We always add it even if the GZipMiddleware is not enabled because + # we cannot assume that every upstream proxy implements a + # countermeasure itself. + s['RANDOM_COMMENT_EXCLUDED_VIEWS'] = set([]) + if 'django.middleware.gzip.GZipMiddleware' in s['MIDDLEWARE_CLASSES']: + index = s['MIDDLEWARE_CLASSES'].index('django.middleware.gzip.GZipMiddleware') + 1 + else: + index = 0 + s['MIDDLEWARE_CLASSES'].insert(index, 'aldryn_django.middleware.RandomCommentExclusionMiddleware') + s['MIDDLEWARE_CLASSES'].insert(index, 'debreach.middleware.RandomCommentMiddleware') + if 'django.middleware.csrf.CsrfViewMiddleware' in s['MIDDLEWARE_CLASSES']: + s['MIDDLEWARE_CLASSES'].insert( + s['MIDDLEWARE_CLASSES'].index('django.middleware.csrf.CsrfViewMiddleware'), + 'debreach.middleware.CSRFCryptMiddleware', + ) + def server_settings(self, settings, env): settings['PORT'] = env('PORT', 80) settings['BACKEND_PORT'] = env('BACKEND_PORT', 8000) + settings['ENABLE_NGINX'] = env('ENABLE_NGINX', False) + settings['ENABLE_PAGESPEED'] = env( + 'ENABLE_PAGESPEED', + env('PAGESPEED', False), + ) settings['STATICFILES_DEFAULT_MAX_AGE'] = env( - 'STATICFILES_DEFAULT_MAX_AGE', 300) + 'STATICFILES_DEFAULT_MAX_AGE', + # Keep BROWSERCACHE_MAX_AGE for backwards compatibility + env('BROWSERCACHE_MAX_AGE', 300), + ) + settings['NGINX_CONF_PATH'] = env('NGINX_CONF_PATH') + settings['NGINX_PROCFILE_PATH'] = env('NGINX_PROCFILE_PATH') + settings['PAGESPEED_ADMIN_HTPASSWD_PATH'] = env( + 'PAGESPEED_ADMIN_HTPASSWD_PATH', + os.path.join( + os.path.dirname(settings['NGINX_CONF_PATH']), + 'pagespeed_admin.htpasswd', + ) + ) + settings['PAGESPEED_ADMIN_USER'] = env('PAGESPEED_ADMIN_USER') + settings['PAGESPEED_ADMIN_PASSWORD'] = env('PAGESPEED_ADMIN_PASSWORD') settings['DJANGO_WEB_WORKERS'] = env('DJANGO_WEB_WORKERS', 3) settings['DJANGO_WEB_MAX_REQUESTS'] = env('DJANGO_WEB_MAX_REQUESTS', 500) settings['DJANGO_WEB_TIMEOUT'] = env('DJANGO_WEB_TIMEOUT', 120) @@ -359,11 +403,7 @@ class Form(forms.BaseForm): if sentry_dsn: settings['INSTALLED_APPS'].append('raven.contrib.django') - settings['RAVEN_CONFIG'] = { - 'dsn': sentry_dsn, - 'release': env('GIT_COMMIT', 'develop'), - 'environment': env('STAGE', 'local'), - } + settings['RAVEN_CONFIG'] = {'dsn': sentry_dsn} settings['LOGGING']['handlers']['sentry'] = { 'level': 'ERROR', 'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler', @@ -496,7 +536,12 @@ class Form(forms.BaseForm): settings['LOCALE_PATHS'] = [ os.path.join(settings['BASE_DIR'], 'locale'), ] - settings['PREFIX_DEFAULT_LANGUAGE'] = not data['disable_default_language_prefix'] + + if len(settings['LANGUAGES']) <= 1: + settings['PREFIX_DEFAULT_LANGUAGE'] = not data['disable_default_language_prefix'] + else: + # this is not supported for django versions < 1.10 + settings['PREFIX_DEFAULT_LANGUAGE'] = True if not settings['PREFIX_DEFAULT_LANGUAGE']: settings['MIDDLEWARE_CLASSES'].insert( diff --git a/requirements.in b/requirements.in index cdbf888..cfab83b 100644 --- a/requirements.in +++ b/requirements.in @@ -1,6 +1,6 @@ # # Warning: text inside the INSTALLED_ADDONS tags is auto-generated. Manual changes will be overwritten. https://control.divio.com/api/v1/apps/serve/aldryn-addons/1.0.2/24f5d1c8-66fe-43b2-a540-17d61045a72b/aldryn-addons-1.0.2.tar.gz#egg=aldryn-addons==1.0.2 -https://control.divio.com/api/v1/apps/serve/aldryn-django/1.11.11.1/002e1533-c0b2-41c6-9384-60594e7afeed/aldryn-django-1.11.11.1.tar.gz#egg=aldryn-django==1.11.11.1 +https://control.divio.com/api/v1/apps/serve/aldryn-django/1.9.13.5/5b23a95a-a626-40a7-9db7-87b6bc1e2ff8/aldryn-django-1.9.13.5.tar.gz#egg=aldryn-django==1.9.13.5 https://control.divio.com/api/v1/apps/serve/aldryn-sso/1.1.16/dbe0c45a-c981-4beb-8624-b0d2c4196aa0/aldryn-sso-1.1.16.tar.gz#egg=aldryn-sso==1.1.16 https://control.divio.com/api/v1/apps/serve/aldryn-django-cms/3.5.1.3/2dd6f80a-825c-4aaf-b37f-519a6c46108e/aldryn-django-cms-3.5.1.3.tar.gz#egg=aldryn-django-cms==3.5.1.3 https://control.divio.com/api/v1/apps/serve/aldryn-forms/2.2.8/fbefab76-74bf-445a-8288-7937b5750aa4/aldryn-forms-2.2.8.tar.gz#egg=aldryn-forms==2.2.8