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