2020-02-20 15:52:50 +00:00
|
|
|
"""
|
|
|
|
Django settings for uncloud project.
|
|
|
|
|
|
|
|
Generated by 'django-admin startproject' using Django 3.0.3.
|
|
|
|
|
|
|
|
For more information on this file, see
|
|
|
|
https://docs.djangoproject.com/en/3.0/topics/settings/
|
|
|
|
|
|
|
|
For the full list of settings and their values, see
|
|
|
|
https://docs.djangoproject.com/en/3.0/ref/settings/
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
2020-12-20 11:20:54 +00:00
|
|
|
import re
|
2020-02-22 10:49:00 +00:00
|
|
|
import ldap
|
2021-07-19 14:36:10 +00:00
|
|
|
import sys
|
2021-07-24 12:27:08 +00:00
|
|
|
import environ
|
2020-02-22 10:49:00 +00:00
|
|
|
|
2020-05-01 22:16:29 +00:00
|
|
|
from django.core.management.utils import get_random_secret_key
|
2020-02-25 18:23:39 +00:00
|
|
|
from django_auth_ldap.config import LDAPSearch, LDAPSearchUnion
|
2020-02-22 10:49:00 +00:00
|
|
|
|
2021-08-24 12:25:28 +00:00
|
|
|
LOGGING = {
|
|
|
|
'version': 1,
|
|
|
|
'disable_existing_loggers': False,
|
|
|
|
'handlers': {
|
|
|
|
'console': {
|
|
|
|
'class': 'logging.StreamHandler',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'root': {
|
|
|
|
'handlers': ['console'],
|
|
|
|
'level': 'DEBUG',
|
|
|
|
},
|
|
|
|
}
|
2020-05-01 22:16:29 +00:00
|
|
|
|
2021-07-24 12:27:08 +00:00
|
|
|
# Initialise environment variables
|
|
|
|
env = environ.Env()
|
|
|
|
environ.Env.read_env()
|
|
|
|
|
2020-02-20 15:52:50 +00:00
|
|
|
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
|
|
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
|
2020-05-01 22:16:29 +00:00
|
|
|
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
|
2021-07-24 12:27:08 +00:00
|
|
|
|
2020-02-20 15:52:50 +00:00
|
|
|
# Quick-start development settings - unsuitable for production
|
|
|
|
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
|
|
|
|
|
|
|
|
# SECURITY WARNING: don't run with debug turned on in production!
|
|
|
|
DEBUG = True
|
|
|
|
|
2021-07-19 14:36:10 +00:00
|
|
|
SITE_ID = 1
|
2020-02-20 15:52:50 +00:00
|
|
|
|
|
|
|
# Application definition
|
|
|
|
|
|
|
|
INSTALLED_APPS = [
|
|
|
|
'django.contrib.admin',
|
|
|
|
'django.contrib.auth',
|
|
|
|
'django.contrib.contenttypes',
|
|
|
|
'django.contrib.sessions',
|
|
|
|
'django.contrib.messages',
|
2021-07-19 14:36:10 +00:00
|
|
|
'django.contrib.sites',
|
2020-02-20 15:52:50 +00:00
|
|
|
'django.contrib.staticfiles',
|
2020-03-17 12:30:48 +00:00
|
|
|
'django_extensions',
|
2021-12-26 20:19:03 +00:00
|
|
|
'bootstrap5',
|
2021-12-26 19:36:31 +00:00
|
|
|
# 'mathfilters',
|
|
|
|
# 'compressor',
|
|
|
|
# 'wkhtmltopdf',
|
2020-02-21 09:41:22 +00:00
|
|
|
'rest_framework',
|
2021-07-19 14:36:10 +00:00
|
|
|
'django_q',
|
2021-12-26 19:36:31 +00:00
|
|
|
# 'notifications',
|
2020-03-22 19:55:11 +00:00
|
|
|
'uncloud',
|
2020-02-21 15:33:37 +00:00
|
|
|
'uncloud_auth',
|
2020-04-03 17:27:49 +00:00
|
|
|
'uncloud_net',
|
2020-02-28 13:48:01 +00:00
|
|
|
'uncloud_storage',
|
2020-02-25 19:53:12 +00:00
|
|
|
'uncloud_vm',
|
2020-04-13 09:39:49 +00:00
|
|
|
'uncloud_service',
|
2021-07-19 14:36:10 +00:00
|
|
|
'opennebula',
|
2021-12-26 19:36:31 +00:00
|
|
|
# env('ACTIVE_APP'),
|
2021-09-10 07:58:42 +00:00
|
|
|
'uncloud_pay', # should be after the active app to load the templates from the active app first
|
2021-12-26 19:36:31 +00:00
|
|
|
# 'allauth',
|
|
|
|
# 'allauth.account',
|
|
|
|
# 'allauth.socialaccount',
|
2020-02-20 15:52:50 +00:00
|
|
|
]
|
|
|
|
|
2021-12-26 19:36:31 +00:00
|
|
|
DEFAULT_AUTO_FIELD='django.db.models.AutoField'
|
|
|
|
|
2020-02-20 15:52:50 +00:00
|
|
|
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',
|
|
|
|
]
|
|
|
|
|
|
|
|
ROOT_URLCONF = 'uncloud.urls'
|
2021-12-26 19:36:31 +00:00
|
|
|
#WKHTMLTOPDF_CMD = env('WKHTMLTOPDF_CMD')
|
2020-02-20 15:52:50 +00:00
|
|
|
|
|
|
|
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.contrib.messages.context_processors.messages',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
WSGI_APPLICATION = 'uncloud.wsgi.application'
|
2021-07-26 14:11:19 +00:00
|
|
|
DJANGO_NOTIFICATIONS_CONFIG = { 'USE_JSONFIELD': True}
|
2020-02-20 15:52:50 +00:00
|
|
|
|
|
|
|
# Password validation
|
|
|
|
# https://docs.djangoproject.com/en/3.0/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',
|
|
|
|
},
|
|
|
|
]
|
2021-07-19 14:36:10 +00:00
|
|
|
###############################################################################
|
|
|
|
# Authall Settings
|
|
|
|
ACCOUNT_AUTHENTICATION_METHOD = "username"
|
|
|
|
ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 1
|
2021-08-24 12:25:28 +00:00
|
|
|
ACCOUNT_EMAIL_REQUIRED = True
|
|
|
|
ACCOUNT_UNIQUE_EMAIL = True
|
|
|
|
MAX_EMAIL_ADDRESSES = 1
|
2020-02-21 10:32:41 +00:00
|
|
|
################################################################################
|
|
|
|
# AUTH/LDAP
|
|
|
|
|
2021-08-24 12:25:28 +00:00
|
|
|
LDAP_ENABLED = True
|
|
|
|
AUTH_LDAP_SERVER_HOST = env('AUTH_LDAP_SERVER_HOST')
|
|
|
|
AUTH_LDAP_SERVER_URI = env('AUTH_LDAP_SERVER_URI')
|
|
|
|
AUTH_LDAP_BIND_DN = env('AUTH_LDAP_BIND_DN')
|
|
|
|
AUTH_LDAP_BIND_PASSWORD = env('AUTH_LDAP_BIND_PASSWORD')
|
|
|
|
|
|
|
|
AUTH_LDAP_USER_DN_TEMPLATE = "uid=%(user)s,ou=customers,dc=ungleich,dc=ch"
|
|
|
|
AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=customers,dc=ungleich,dc=ch",
|
2020-05-01 22:16:29 +00:00
|
|
|
ldap.SCOPE_SUBTREE,
|
|
|
|
"(uid=%(user)s)")
|
2021-08-24 12:25:28 +00:00
|
|
|
# BIND_AS_AUTHENTICATING_USER = True
|
|
|
|
START_TLS = True
|
|
|
|
LDAP_ADMIN_DN = env("LDAP_ADMIN_DN")
|
|
|
|
LDAP_ADMIN_PASSWORD = env("LDAP_ADMIN_PASSWORD")
|
|
|
|
LDAP_CUSTOMER_GROUP_ID = env("LDAP_CUSTOMER_GROUP_ID")
|
|
|
|
LDAP_CUSTOMER_DN=env("LDAP_CUSTOMER_DN")
|
|
|
|
|
|
|
|
#AUTH_LDAP_USER_QUERY_FIELD = "email"
|
2020-02-23 15:52:30 +00:00
|
|
|
AUTH_LDAP_USER_ATTR_MAP = {
|
2021-08-24 12:25:28 +00:00
|
|
|
"first_name": "cn",
|
2020-02-23 15:52:30 +00:00
|
|
|
"last_name": "sn",
|
|
|
|
"email": "mail"
|
|
|
|
}
|
2021-08-24 12:25:28 +00:00
|
|
|
LDAP_DEFAULT_START_UID = int(env('LDAP_DEFAULT_START_UID'))
|
2020-02-20 17:58:07 +00:00
|
|
|
|
2021-08-24 12:25:28 +00:00
|
|
|
LDAP_MAX_UID_FILE_PATH = os.environ.get('LDAP_MAX_UID_FILE_PATH',
|
|
|
|
os.path.join(os.path.abspath(os.path.dirname(__file__)), 'ldap_max_uid_file')
|
|
|
|
)
|
2020-02-21 10:32:41 +00:00
|
|
|
################################################################################
|
|
|
|
# AUTH/Django
|
|
|
|
AUTHENTICATION_BACKENDS = [
|
|
|
|
"django_auth_ldap.backend.LDAPBackend",
|
2021-07-19 14:36:10 +00:00
|
|
|
"django.contrib.auth.backends.ModelBackend",
|
2021-12-26 19:36:31 +00:00
|
|
|
# 'allauth.account.auth_backends.AuthenticationBackend',
|
2020-02-21 10:32:41 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-08-24 12:25:28 +00:00
|
|
|
AUTH_USER_MODEL = 'uncloud_auth.User'
|
|
|
|
ACCOUNT_FORMS = {
|
2021-12-26 19:36:31 +00:00
|
|
|
'signup': 'uncloud_auth.forms.MySignupForm',
|
2021-08-24 12:25:28 +00:00
|
|
|
'change_password': 'uncloud_auth.forms.MyChangePasswordForm',
|
|
|
|
'set_password': 'uncloud_auth.forms.MySetPasswordForm',
|
|
|
|
'reset_password_from_key': 'uncloud_auth.forms.MyResetPasswordKeyForm',
|
|
|
|
}
|
|
|
|
|
2020-02-20 17:58:07 +00:00
|
|
|
################################################################################
|
|
|
|
# AUTH/REST
|
|
|
|
REST_FRAMEWORK = {
|
|
|
|
'DEFAULT_AUTHENTICATION_CLASSES': [
|
2020-02-25 17:15:22 +00:00
|
|
|
'rest_framework.authentication.BasicAuthentication',
|
2020-02-20 17:58:07 +00:00
|
|
|
'rest_framework.authentication.SessionAuthentication',
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-20 15:52:50 +00:00
|
|
|
# Internationalization
|
|
|
|
# https://docs.djangoproject.com/en/3.0/topics/i18n/
|
|
|
|
|
|
|
|
LANGUAGE_CODE = 'en-us'
|
|
|
|
|
|
|
|
TIME_ZONE = 'UTC'
|
|
|
|
|
|
|
|
USE_I18N = True
|
|
|
|
|
|
|
|
USE_L10N = True
|
|
|
|
|
|
|
|
USE_TZ = True
|
|
|
|
|
|
|
|
|
|
|
|
# Static files (CSS, JavaScript, Images)
|
|
|
|
# https://docs.djangoproject.com/en/3.0/howto/static-files/
|
|
|
|
STATIC_URL = '/static/'
|
2021-08-04 10:03:55 +00:00
|
|
|
STATIC_ROOT = os.path.join(BASE_DIR, "static")
|
2021-01-01 12:25:52 +00:00
|
|
|
STATICFILES_FINDERS = [
|
|
|
|
'django.contrib.staticfiles.finders.FileSystemFinder',
|
|
|
|
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
|
2021-08-04 10:03:55 +00:00
|
|
|
'compressor.finders.CompressorFinder',
|
2021-01-01 12:25:52 +00:00
|
|
|
]
|
2021-08-04 10:03:55 +00:00
|
|
|
COMPRESS_ENABLED = True
|
2021-01-01 12:25:52 +00:00
|
|
|
|
2021-07-19 14:36:10 +00:00
|
|
|
#VM Deployment TEMPLATE
|
2021-07-24 12:27:08 +00:00
|
|
|
GITLAB_SERVER = env('GITLAB_SERVER')
|
|
|
|
GITLAB_OAUTH_TOKEN = env('GITLAB_OAUTH_TOKEN')
|
2021-08-09 07:43:11 +00:00
|
|
|
GITLAB_PROJECT_ID = env('GITLAB_PROJECT_ID')
|
2021-07-24 12:27:08 +00:00
|
|
|
GITLAB_AUTHOR_EMAIL = env('GITLAB_AUTHOR_EMAIL')
|
|
|
|
GITLAB_AUTHOR_NAME = env('GITLAB_AUTHOR_NAME')
|
2021-08-09 07:43:11 +00:00
|
|
|
GITLAB_YAML_DIR = env('GITLAB_YAML_DIR')
|
2021-09-10 07:58:42 +00:00
|
|
|
GITLAB_DNS_PROJECT_ID = env('GITLAB_DNS_PROJECT_ID')
|
|
|
|
MATRIX_DNS_MAIN_DOMAIN = env('MATRIX_DNS_MAIN_DOMAIN')
|
|
|
|
GITLAB_DNS_OAUTH_TOKEN = env('GITLAB_DNS_OAUTH_TOKEN')
|
2020-05-01 22:16:29 +00:00
|
|
|
|
|
|
|
# XML-RPC interface of opennebula
|
|
|
|
OPENNEBULA_URL = 'https://opennebula.example.com:2634/RPC2'
|
|
|
|
|
|
|
|
# user:pass for accessing opennebula
|
|
|
|
OPENNEBULA_USER_PASS = 'user:password'
|
|
|
|
|
|
|
|
# Stripe (Credit Card payments)
|
2021-07-24 12:27:08 +00:00
|
|
|
STRIPE_KEY=env('STRIPE_KEY')
|
|
|
|
STRIPE_PUBLIC_KEY=env('STRIPE_PUBLIC_KEY')
|
2021-07-19 14:36:10 +00:00
|
|
|
BILL_PAYMENT_DELAY = 0
|
2021-08-12 10:28:19 +00:00
|
|
|
MIN_PER_TRANSACTION = 5
|
2020-05-01 22:16:29 +00:00
|
|
|
# The django secret key
|
|
|
|
SECRET_KEY=get_random_secret_key()
|
|
|
|
|
2021-12-26 19:36:31 +00:00
|
|
|
ALLOWED_HOSTS = ''
|
2020-05-01 22:16:29 +00:00
|
|
|
|
2020-05-17 21:34:13 +00:00
|
|
|
# required for hardcopy / pdf rendering: https://github.com/loftylabs/django-hardcopy
|
|
|
|
CHROME_PATH = '/usr/bin/chromium-browser'
|
|
|
|
|
2020-10-08 17:54:04 +00:00
|
|
|
# Username that is created by default and owns the configuration objects
|
|
|
|
UNCLOUD_ADMIN_NAME = "uncloud-admin"
|
2020-05-17 21:34:13 +00:00
|
|
|
|
2020-12-09 19:22:33 +00:00
|
|
|
LOGIN_REDIRECT_URL = '/'
|
|
|
|
LOGOUT_REDIRECT_URL = '/'
|
|
|
|
|
2021-07-19 14:36:10 +00:00
|
|
|
EMAIL_USE_TLS = True
|
2021-07-24 12:27:08 +00:00
|
|
|
EMAIL_HOST = env('EMAIL_HOST')
|
2021-08-24 12:25:28 +00:00
|
|
|
|
2021-07-24 12:27:08 +00:00
|
|
|
EMAIL_PORT = 25
|
|
|
|
EMAIL_HOST_USER = DEFAULT_FROM_EMAIL = env('EMAIL_HOST_USER')
|
|
|
|
EMAIL_HOST_PASSWORD = env('EMAIL_HOST_PASSWORD')
|
|
|
|
DEFAULT_FROM_EMAIL = 'support@ungleich.ch'
|
|
|
|
RENEWAL_FROM_EMAIL = 'support@ungleich.ch'
|
2021-07-19 14:36:10 +00:00
|
|
|
|
|
|
|
##############
|
|
|
|
# Jobs
|
|
|
|
Q_CLUSTER = {
|
2021-09-10 07:58:42 +00:00
|
|
|
'name': 'uncloud',
|
2021-07-19 14:36:10 +00:00
|
|
|
'workers': 1,
|
|
|
|
'recycle': 500,
|
|
|
|
'timeout': 60,
|
|
|
|
'compress': True,
|
|
|
|
'cpu_affinity': 1,
|
|
|
|
'save_limit': 250,
|
|
|
|
'queue_limit': 500,
|
|
|
|
'label': 'Django Q',
|
|
|
|
'redis': {
|
|
|
|
'host': '127.0.0.1',
|
|
|
|
'port': 6379,
|
|
|
|
'db': 0, }
|
2020-12-20 11:54:02 +00:00
|
|
|
}
|
2020-12-13 18:50:36 +00:00
|
|
|
|
2021-08-09 07:43:11 +00:00
|
|
|
REPORT_FORMAT = {
|
|
|
|
'page_height': 200,
|
|
|
|
'page_width':175,
|
|
|
|
'orientation': 'Portrait',
|
|
|
|
'header_spacing': 65,
|
|
|
|
'margin_bottom':25,
|
|
|
|
'header_line': False,
|
|
|
|
}
|
|
|
|
|
2021-08-12 10:28:19 +00:00
|
|
|
|
2020-05-01 22:16:29 +00:00
|
|
|
# Overwrite settings with local settings, if existing
|
|
|
|
try:
|
|
|
|
from uncloud.local_settings import *
|
|
|
|
except (ModuleNotFoundError, ImportError):
|
|
|
|
pass
|