""" For more information on this file, see https://docs.djangoproject.com/en/5.2/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/5.2/ref/settings/ """ import json import os from pathlib import Path import ldap from django_auth_ldap.config import GroupOfNamesType, LDAPSearch from dotenv import dotenv_values, load_dotenv # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent load_dotenv(BASE_DIR / '.env', override=False) import logging LOGLEVEL = getattr(logging,os.environ.get('LOG_LEVEL', 'DEBUG').upper()) logging.basicConfig(level=LOGLEVEL) from django_proxmox_mikrotik.configs import ( env_true, env_false, ProxmoxConfig, DatabaseConfig, AuthLDAPConfig, MikrotikConfig, ) LOGIN_URL = '/frontend/login/' # fallback DatabaseConfig.NAME = DatabaseConfig.NAME or BASE_DIR / 'db.sqlite3' SECRET_KEY = 'django-insecure-o$tw_(450z^cl%mq(h1&=jltu51mfnmiown&l^dinx+z-!nzem' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS', '127.0.0.1,localhost').strip().replace(' ', '').split(',') INSTALLED_APPS = [ 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.admin', 'django_middleware_global_request', 'proxmox', 'tasklogger', 'mikrotik', 'manager', 'frontend', ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'frontend.middleware.FrontendSessionMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django_middleware_global_request.middleware.GlobalRequestMiddleware', ] ROOT_URLCONF = 'django_proxmox_mikrotik.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [BASE_DIR / 'templates'] , 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] WSGI_APPLICATION = 'django_proxmox_mikrotik.wsgi.application' # Database # https://docs.djangoproject.com/en/5.2/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.' + DatabaseConfig.ENGINE, 'NAME': DatabaseConfig.NAME, 'PASSWORD': DatabaseConfig.PASSWORD, 'USER': DatabaseConfig.USER, 'HOST': DatabaseConfig.HOST, 'PORT': DatabaseConfig.PORT, } } # Password validation # https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators 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', }, ] # Internationalization # https://docs.djangoproject.com/en/5.2/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/5.2/howto/static-files/ STATIC_URL = 'static/' STATIC_ROOT = str(BASE_DIR / 'static') STATICFILES_DIRS = [ BASE_DIR / "frontend" / "static", ] # Default primary key field type # https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' AUTH_LDAP_SERVER_URI = AuthLDAPConfig.HOST AUTH_LDAP_BIND_DN = AuthLDAPConfig.BIND_DN AUTH_LDAP_BIND_PASSWORD = AuthLDAPConfig.BIND_PASSWORD AUTH_LDAP_USER_SEARCH = LDAPSearch( AuthLDAPConfig.USER_BASE, ldap.SCOPE_SUBTREE, AuthLDAPConfig.USER_FILTER, ) AUTH_LDAP_GROUP_SEARCH = LDAPSearch( AuthLDAPConfig.GROUP_SEARCH_BASE, ldap.SCOPE_SUBTREE, AuthLDAPConfig.GROUP_SEARCH_FILTER, ) AUTH_LDAP_USER_ATTR_MAP = AuthLDAPConfig.USER_ATTR_MAP AUTH_LDAP_USER_FLAGS_BY_GROUP = AuthLDAPConfig.USER_FLAGS_BY_GROUP AUTH_LDAP_FIND_GROUP_PERMS = bool(AuthLDAPConfig.FIND_GROUP_PERMS) AUTH_LDAP_CACHE_GROUPS = bool(AuthLDAPConfig.CACHE_GROUPS) AUTH_LDAP_GROUP_CACHE_TIMEOUT = AuthLDAPConfig.GROUP_CACHE_TIMEOUT AUTH_LDAP_GROUP_TYPE = GroupOfNamesType(name_attr="cn") AUTHENTICATION_BACKENDS = [ 'django_auth_ldap.backend.LDAPBackend', 'django.contrib.auth.backends.ModelBackend', ] SESSION_COOKIE_NAME_FRONTEND = 'django_pm_mk_frontend_sessionid'