· 4 years ago · Jun 09, 2021, 09:28 AM
1"""
2Django settings for jumpserver3s project.
3
4Generated by 'django-admin startproject' using Django 2.1.7.
5
6For more information on this file, see
7https://docs.djangoproject.com/en/2.1/topics/settings/
8
9For the full list of settings and their values, see
10https://docs.djangoproject.com/en/2.1/ref/settings/
11"""
12
13import os
14import ldap
15from django_auth_ldap.config import LDAPSearch
16
17# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
18BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
19TEMPLATE_DIR = os.path.join(BASE_DIR,"templates")
20STATIC_DIR = os.path.join(BASE_DIR,"static")
21MEDIA_DIR = os.path.join(BASE_DIR,"media")
22
23# Quick-start development settings - unsuitable for production
24# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
25
26# SECURITY WARNING: keep the secret key used in production secret!
27SECRET_KEY = 'bo&syjzk@$a8i%wufndyw4k82^15&jsf8xokj83*o5k=*w1+)j'
28
29
30#//////////////////////
31
32AUTH_LDAP_SERVER_URI = 'ldap://172.29.50.222'
33AUTH_LDAP_BIND_DN = "CN=pam.local CN=project,DC=pam,DC=local"
34AUTH_LDAP_BIND_PASSWORD = "Cisco123+*"
35AUTH_LDAP_USER_SEARCH = LDAPSearch(
36 "dc=pam,dc=local", ldap.SCOPE_SUBTREE, "sAMAccountName=%(user)s"
37 )
38
39AUTH_LDAP_USER_ATTR_MAP = {
40 "username": "sAMAccountName",
41 "first_name": "givenName",
42 "last_name": "sn",
43 "email": "mail",
44}
45from django_auth_ldap.config import ActiveDirectoryGroupType
46AUTH_LDAP_GROUP_SEARCH = LDAPSearch(
47 "dc=pam,dc=local", ldap.SCOPE_SUBTREE, "(objectCategory=Group)"
48 )
49AUTH_LDAP_GROUP_TYPE = ActiveDirectoryGroupType(name_attr="cn")
50AUTH_LDAP_USER_FLAGS_BY_GROUP = {
51 "is_superuser": "CN=admins,CN=project,DC=pam,DC=local",
52 "is_staff": "CN=admins,CN=project,DC=pam,DC=local",
53}
54AUTH_LDAP_FIND_GROUP_PERMS = True
55AUTH_LDAP_CACHE_GROUPS = True
56AUTH_LDAP_GROUP_CACHE_TIMEOUT = 1 # 1 hour cache
57
58AUTHENTICATION_BACKENDS = [
59 'django_auth_ldap.backend.LDAPBackend',
60 'django.contrib.auth.backends.ModelBackend',
61]
62# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
63BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
64#/////////////// END LDAP
65
66# SECURITY WARNING: don't run with debug turned on in production!
67DEBUG = True
68
69ALLOWED_HOSTS = ['*']
70#Email validation
71EMAIL_USE_TLS = True
72
73EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
74EMAIL_HOST = 'smtp.gmail.com' #EMAIL_HOST = 'cloud.supcom.tn'
75EMAIL_HOST_USER = 'mayaproject@gmail.com'
76EMAIL_HOST_PASSWORD = 'qthhthaz78084gt5'
77EMAIL_PORT = 587
78BASE_URL = '127.0.0.1:8000'
79
80#new conirmed mail
81def verified_callback(user):
82 user.is_active = True
83
84Email_ACTIVE_FIELD = 'is_active'
85EMAIL_VERIFIED_CALLBACK = verified_callback
86EMAIL_FROM_ADDRESS = 'mayaproject@gmail.com'
87Email_PASSWORD = 'qthhthaz78084gt5'
88EMAIL_MAIL_SUBJECT = 'Confirm your email'
89EMAIL_MAIL_HTML = 'mail_body.html'
90EMAIL_MAIL_PLAIN = 'mail_body.txt'
91EMAIL_TOKEN_LIFE = 60 * 60
92EMAIL_PAGE_TEMPLATE = 'confirm_template.html'
93EMAIL_PAGE_DOMAIN = 'http://mydomain.com/'
94
95# For Django Email Backend
96# EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
97# EMAIL_HOST = 'smtp.gmail.com'
98# EMAIL_PORT = 587
99# EMAIL_HOST_USER = 'mymail@gmail.com'
100# EMAIL_HOST_PASSWORD = 'mYC00lP4ssw0rd' # os.environ['password_key'] suggested
101#EMAIL_USE_TLS = True
102# Application definition
103
104INSTALLED_APPS = [
105 'channels',
106 'django.contrib.admin',
107 'django.contrib.auth',
108 'django.contrib.contenttypes',
109 'django.contrib.sessions',
110 'django.contrib.messages',
111 'django.contrib.staticfiles',
112 'multiselectfield',
113 #new to confirm mail
114 'django_email_verification', # i add this
115 # 'debug_toolbar',
116 'rest_framework',
117 'jumpserver3s',
118 'app_admin',
119 'app_auditor',
120 'app_user',
121 'app_manager',
122 'guacamole',
123 'reset_migrations',
124 #'phone_verify',
125 # for otp
126 'codes',
127 'crispy_forms'
128
129 ]
130
131
132
133
134AUTH_USER_MODEL = 'app_manager.User'
135
136#Classes that handle the request and the response between the client (user) and
137#the server
138MIDDLEWARE = [
139 'django.middleware.security.SecurityMiddleware',
140 'django.contrib.sessions.middleware.SessionMiddleware',
141 'django.middleware.common.CommonMiddleware',
142 'django.middleware.csrf.CsrfViewMiddleware',
143 'django.contrib.auth.middleware.AuthenticationMiddleware',
144 'django.contrib.messages.middleware.MessageMiddleware',
145 'django.middleware.clickjacking.XFrameOptionsMiddleware',
146 'debug_toolbar.middleware.DebugToolbarMiddleware',
147]
148
149ROOT_URLCONF = 'jumpserver3s.urls'
150
151TEMPLATES = [
152 {
153 'BACKEND': 'django.template.backends.django.DjangoTemplates',
154 'DIRS': [TEMPLATE_DIR,],
155 'APP_DIRS': True,
156 'OPTIONS': {
157 'context_processors': [
158 'django.template.context_processors.debug',
159 'django.template.context_processors.request',
160 'django.contrib.auth.context_processors.auth',
161 'django.contrib.messages.context_processors.messages',
162 ],
163 },
164 },
165]
166
167#WSGI: Web Server Gateway Interface: The path to the development server
168WSGI_APPLICATION = 'jumpserver3s.wsgi.application'
169
170# Channels settings
171# ASGI_APPLICATION = "jumpserver3s.routing.application"
172CHANNEL_LAYERS = {
173 "default": {
174 "BACKEND": "asgi_redis.RedisChannelLayer", # use redis backend
175 "CONFIG": {
176 "hosts": [("localhost", 6379)], # set redis address
177 "channel_capacity": {
178 "http.request": 1000,
179 "websocket.send*": 10000,
180 },
181 "capacity": 10000,
182 },
183 "ROUTING": "jumpserver3s.routing.channel_routing", # load routing from our routing.py file
184 },
185}
186
187TEMPLATES = [
188 {
189 'BACKEND': 'django.template.backends.django.DjangoTemplates',
190 'DIRS': [os.path.join(BASE_DIR,'templates')],
191 'APP_DIRS': True,
192 'OPTIONS': {
193 'debug': True,
194 'context_processors': [
195 'django.template.context_processors.debug',
196 'django.template.context_processors.request',
197 'django.contrib.auth.context_processors.auth',
198 'django.contrib.messages.context_processors.messages',
199 'django.template.context_processors.i18n'
200 ],
201 },
202 },
203]
204
205
206
207AUTH_PASSWORD_VALIDATORS = [
208 {
209 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
210 },
211 {
212 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
213 },
214 {
215 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
216 },
217 {
218 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
219 },
220]
221
222
223# Internationalization
224# https://docs.djangoproject.com/en/1.11/topics/i18n/
225
226LANGUAGE_CODE = 'en-us'
227
228TIME_ZONE = 'UTC'
229
230USE_I18N = True
231
232USE_L10N = True
233
234USE_TZ = True
235
236
237# Static files (CSS, JavaScript, Images)
238# https://docs.djangoproject.com/en/1.11/howto/static-files/
239
240STATIC_URL = '/static/'
241
242STATICFILES_DIRS = [
243 os.path.join(BASE_DIR, 'static'),
244]
245LOCALE_PATHS = [
246 os.path.join(BASE_DIR,'locale')
247 ]
248
249# Database
250# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
251
252DATABASES = {
253 'default': {
254 'ENGINE': 'django.db.backends.sqlite3',
255 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
256 }
257}
258
259
260# Password validation
261# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
262
263AUTH_PASSWORD_VALIDATORS = [
264 {
265 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
266 },
267 {
268 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
269 },
270 {
271 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
272 },
273 {
274 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
275 },
276]
277
278AUTHENTICATION_BACKENDS = [
279 'django.contrib.auth.backends.AllowAllUsersModelBackend',
280 'guardian.backends.ObjectPermissionBackend',
281]
282
283#Rest framework api auth config
284REST_FRAMEWORK = {
285 'DEFAULT_AUTHENTICATION_CLASSES': (
286 'rest_framework.authentication.BasicAuthentication',
287 'rest_framework.authentication.SessionAuthentication',
288 ),
289 'DEFAULT_PERMISSION_CLASSES': (
290 'rest_framework.permissions.IsAuthenticated',
291 ),
292 'DEFAULT_PARSER_CLASSES': (
293 'rest_framework.parsers.JSONParser',
294 'rest_framework.parsers.FormParser',
295 ),
296}
297
298
299# Internationalization
300# https://docs.djangoproject.com/en/2.1/topics/i18n/
301
302LANGUAGE_CODE = 'en-us'
303
304TIME_ZONE = 'UTC'
305
306USE_I18N = True
307
308USE_L10N = True
309
310USE_TZ = True
311
312
313# Static files (CSS, JavaScript, Images)
314# https://docs.djangoproject.com/en/2.1/howto/static-files/
315
316STATIC_URL = '/static/'
317STATICFILES_DIRS = [
318 STATIC_DIR,
319]
320
321#Media files
322MEDIA_ROOT = MEDIA_DIR
323MEDIA_URL = '/media/'
324
325
326# INTERNAL_IPS = ['127.0.0.1']
327
328
329CHANNELS_WS_PROTOCOLS = ["guacamole"]
330
331# guacd daemon host address and port
332GUACD_HOST = '127.0.0.1'
333GUACD_PORT = '4822'
334