1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-02 17:06:09 +00:00
webvirtcloud/accounts/checks.py
catborise 29a1cbcace feat: an installation's own settings in data/local_settings.py; settings.py is part of the code
Every update rebuilt settings.py from the template, and the operator put
back their own values by reading a diff: a forgotten DATABASES started
the panel on a new, empty sqlite database. Docker users who needed an
option only settings.py has (LDAP, OTP_ENABLED, LOGIN_TRUSTED_PROXIES)
mounted their own copy and kept it up to date by hand.

webvirtcloud/settings.py is now the tracked file (no template, no copy
in the installer, the image, the container's start or CI), and it runs
data/local_settings.py last: the installation's own values, which an
update does not touch, kept in Docker's data volume, in the panel's
backups and readable by the panel's user only. The installer writes the
time zone, the noVNC port (now checked to be a number), ALLOWED_HOSTS
and CSRF_TRUSTED_ORIGINS there instead of editing settings.py with sed.
LDAP is set up there too; settings.py keeps only python-ldap's
timeouts. The README's update steps move an older version's own
settings.py into the backup before git pull and have its values moved
into the local file once.
2026-11-20 17:50:43 +03:00

53 lines
2 KiB
Python

from django.conf import settings
from django.core.checks import Error, Tags, Warning, register
@register(Tags.security)
def password_change_middleware_check(app_configs, **kwargs):
middleware = list(settings.MIDDLEWARE)
required = "accounts.middleware.ForcePasswordChangeMiddleware"
authentication = "django.contrib.auth.middleware.AuthenticationMiddleware"
if required not in middleware or (
authentication in middleware
and middleware.index(required) < middleware.index(authentication)
):
return [
Error(
"ForcePasswordChangeMiddleware must follow AuthenticationMiddleware.",
hint=f"data/local_settings.py sets MIDDLEWARE: keep '{required}' after AuthenticationMiddleware, as webvirtcloud/settings.py has it.",
id="accounts.E001",
)
]
return []
@register(Tags.security)
def login_required_middleware_check(app_configs, **kwargs):
middleware = list(settings.MIDDLEWARE)
required = "django.contrib.auth.middleware.LoginRequiredMiddleware"
old = "login_required.middleware.LoginRequiredMiddleware"
if old in middleware or required not in middleware:
return [
Error(
"MIDDLEWARE must use Django's LoginRequiredMiddleware.",
hint=f"data/local_settings.py sets MIDDLEWARE: replace '{old}' with '{required}' "
"and delete LOGIN_REQUIRED_IGNORE_VIEW_NAMES, as webvirtcloud/settings.py has it.",
id="accounts.E002",
)
]
return []
@register()
def obsolete_settings_check(app_configs, **kwargs):
if hasattr(settings, "SHOW_PROFILE_EDIT_PASSWORD"):
return [
Warning(
"SHOW_PROFILE_EDIT_PASSWORD is no longer used.",
hint="Remove it from data/local_settings.py. Whether a user may change their own "
"password is the 'Can change password' permission, per user or group.",
id="accounts.W001",
)
]
return []