rustdesk-api-server/rustdesk_server_api/settings.py
2024-08-28 18:42:48 +08:00

194 lines
6.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
Django settings for rustdesk_server_api project.
Generated by 'django-admin startproject' using Django 3.1.7.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
import os
from pathlib import Path
import environ
env = environ.Env()
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Set a default environment file path: project/.env
ENV_PATH_DEFAULT = BASE_DIR.joinpath(".env")
# try to read the environment file path from the ENV_PATH environment variable, if not found, use the default path
ENV_PATH = env.str("ENV_PATH", default=ENV_PATH_DEFAULT.as_posix())
# read the environment variables from the file
environ.Env.read_env(ENV_PATH)
# read RUSTSERK_API_URL from environment variable
RUSTSERK_API_URL = env.str("RUSTSERK_API_URL", default="http://127.0.0.1:21114")
if env("CSRF_TRUSTED_ORIGINS", default="") != "":
# Set the CSRF_TRUSTED_ORIGINS environment variable to a list of trusted origins to allow POST requests from them without a CSRF token.
CSRF_TRUSTED_ORIGINS = env.list("CSRF_TRUSTED_ORIGINS", default=[RUSTSERK_API_URL])
else:
CSRF_TRUSTED_ORIGINS = [RUSTSERK_API_URL]
SECURE_CROSS_ORIGIN_OPENER_POLICY = 'None'
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = env.str("SECRET_KEY", default="j%7yjvygpih=6b%qf!q%&ixpn+27dngzdu-i3xh-^3xgy3^nnc")
# ID服务器IP或域名一般与中继服务器用于web client
ID_SERVER = env.str("ID_SERVER", default="")
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = env.bool("DEBUG", default=False)
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
# If it's debug mode, allow all hosts
# If the ALLOWED_HOSTS environment variable is not set, allow all hosts
ALLOWED_HOSTS = ["*"] if DEBUG else env.list("ALLOWED_HOSTS", default=["*"])
AUTH_USER_MODEL = 'api.UserProfile' # AppName.自定义user
# If allow registration is set to False, the registration page will not be accessible. default is True
ALLOW_REGISTRATION = env.bool("ALLOW_REGISTRATION", default=True)
# ==========数据库配置 开始=====================
DATABASE_TYPE = env.str("DATABASE_TYPE", default="SQLITE")
MYSQL_DBNAME = env.str("MYSQL_DBNAME", default="-")
MYSQL_HOST = env.str("MYSQL_HOST", default="127.0.0.1")
MYSQL_USER = env.str("MYSQL_USER", default="-")
MYSQL_PASSWORD = env.str("MYSQL_PASSWORD", default="-")
MYSQL_PORT = env.int("MYSQL_PORT", default="3306")
# ==========数据库配置 结束=====================
LANGUAGE_CODE = env.str("LANGUAGE_CODE", default="zh-hans")
# LANGUAGE_CODE=env.str("LANGUAGE_CODE", default="en")
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'api',
'webui',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
# 'django.middleware.csrf.CsrfViewMiddleware', # 取消post的验证。
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'rustdesk_server_api.urls'
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',
'api.util.settings',
],
},
},
]
WSGI_APPLICATION = 'rustdesk_server_api.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db/db.sqlite3',
}
}
if DATABASE_TYPE == 'MYSQL' and MYSQL_DBNAME != '-' and MYSQL_USER != '-' and MYSQL_PASSWORD != '-':
# 简单通过数据库名、账密信息过滤下防止用户未配置mysql却使用mysql
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': MYSQL_DBNAME, # 数据库名
'HOST': MYSQL_HOST, # 数据库服务器IP
'USER': MYSQL_USER, # 数据库用户名
'PASSWORD': MYSQL_PASSWORD, # 数据库密码
'PORT': MYSQL_PORT, # 端口
'OPTIONS': {'charset': 'utf8'},
}
}
# Password validation
# https://docs.djangoproject.com/en/3.1/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/3.1/topics/i18n/
# LANGUAGE_CODE = 'zh-hans'
TIME_ZONE = env.str("TIME_ZONE", default="Asia/Shanghai")
USE_I18N = True
USE_L10N = True
# USE_TZ = True
USE_TZ = False
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_URL = 'static/'
if DEBUG:
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
else:
STATIC_ROOT = os.path.join(BASE_DIR, 'static') # 新增
LANGUAGES = (
('zh-hans', '中文简体'),
('en', 'English'),
)
LOCALE_PATHS = (
os.path.join(BASE_DIR, 'locale'),
)