Repository navigation
Expand file tree
/
Copy pathsettings.py
More file actions
192 lines (158 loc) · 5.47 KB
/
Copy pathsettings.py
File metadata and controls
192 lines (158 loc) · 5.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
"""
Django settings for ServerManager project.
Generated by 'django-admin startproject' using Django 4.2.7.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""
import os
import sys
import logging
import dj_database_url
from pathlib import Path
from util.logger import Log
from .logger import InterceptHandler
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# sys.path.insert(0,os.path.join(BASE_DIR,'apps'))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-h$p@2x!f5$2n8-f0d4xp#t1=d0_uhn2ld0sg2h3g^t2otbltz&'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.getenv('DEBUG', 'True') == 'True'
ALLOWED_HOSTS = ["*"]
# Application definition
INSTALLED_APPS = [
'daphne', # WebSocket
'channels', # CHANNEL_LAYER
'django_eventstream', # SSE
'apps.command_tool', # 命令工具
'apps.setting', # 配置与设置
'apps.auth', # 认证
'apps.user_manager', # 用户管理器
'apps.permission_manager', # 权限管理器
'apps.node_manager', # 节点管理器
"apps.group.manager", # 集群管理器
'apps.dashboard', # 仪表盘
'apps.audit', # 审计
'apps.message', # 消息
'apps.patrol', # 巡检
"apps.task", # 任务管理
"apps.web_status", # 网站监控
"apps.group.group_task", # 集群任务
"apps.group.commandExecution", # 集群执行
"apps.group.file_send", # 集群文件分发
"apps.screen",
'django.contrib.contenttypes',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
# 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'middleware.AuthMiddleware.AuthMiddleware',
# 'middleware.PermissionsMiddleware.PermissionsMiddleware',
'middleware.APICallCounterMiddleware.APICallCounterMiddleware',
]
ROOT_URLCONF = 'ServerManager.urls'
WSGI_APPLICATION = 'ServerManager.wsgi.application'
ASGI_APPLICATION = 'ServerManager.asgi.application'
# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
if DEBUG:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / './db.sqlite3',
}
}
else:
DATABASES = {
'default': dj_database_url.parse(os.getenv('DATABASE_URL'))
}
# Password validation
# https://docs.djangoproject.com/en/4.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/4.2/topics/i18n/
LANGUAGE_CODE = 'zh-hans'
TIME_ZONE = 'Asia/Shanghai'
USE_I18N = True
# 存储带时区的时间
USE_TZ = False
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/
# STATIC_ROOT = os.path.join(BASE_DIR, 'static/assets')
# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
'hosts': [os.getenv('REDIS_URL', 'redis://localhost:6379')],
},
},
}
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.redis.RedisCache",
"LOCATION": os.getenv('REDIS_URL', "redis://localhost:6379"),
}
}
# SECURE_CONTENT_TYPE_NOSNIFF = False
# 清空默认的Django日志配置
LOGGING_CONFIG = None
# 配置Django使用Loguru的日志处理器
logging.basicConfig(handlers=[InterceptHandler()], level=logging.INFO if DEBUG else logging.WARNING)
LOGGING = {
'version': 1,
'disable_existing_loggers': True, # 禁用所有存在的日志记录器
'handlers': {
'loguru': {
'class': 'ServerManager.logger.InterceptHandler', # 将此路径替换为你定义的InterceptHandler的路径
},
},
'root': {
'handlers': ['loguru'],
'level': "INFO", # 仅输出INFO及以上级别的日志
},
'loggers': {
'django': {
'handlers': ['loguru'],
'level': 'INFO',
'propagate': False,
},
'django.request': {
'handlers': ['loguru'],
'level': 'INFO',
'propagate': False,
},
'django.db.backends': {
'handlers': ['loguru'],
'level': 'INFO',
'propagate': False,
},
}
}
# 禁用所有默认的日志记录器
for logger_name in logging.root.manager.loggerDict.keys():
logging.getLogger(logger_name).disabled = True