· 9 years ago · Nov 29, 2016, 04:30 PM
1"""
2Django settings for CERBRO Controller project.
3
4
5
6"""
7
8import os
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__)))
12PROJECT_DIR = os.path.dirname(__file__)
13
14
15# SECURITY WARNING: keep the secret key used in production secret!
16SECRET_KEY = '{django_secret}'
17
18# SECURITY WARNING: don't run with debug turned on in production!
19DEBUG = True
20
21ALLOWED_HOSTS = [
22 'localhost', '127.0.0.1', 'control.cerbro.com',
23
24
25]
26
27SECURE_PROXY_SSL_HEADER = [
28 'HTTP_X_FORWARDED_PROTO', 'https'
29]
30
31USE_X_FORWARDED_HOST = True
32
33LOGIN_URL = '/admin/login/'
34LOGOUT_URL = '/admin/logout/'
35
36ENVIRONMENT = 'dev'
37
38SITE_ID = 1
39
40
41# Application definition
42
43INSTALLED_APPS = [
44 'theme.homer',
45 'filebrowser',
46 'django.contrib.admin',
47 'django.contrib.auth',
48 'django.contrib.contenttypes',
49 'django.contrib.messages',
50 'django.contrib.staticfiles',
51 'django.contrib.sites',
52 'rest_framework',
53 'rest_framework.authtoken',
54 'rest_framework_swagger',
55 'social.apps.django_app.default',
56 'tz_detect',
57 'menu',
58 'reversion',
59 'import_export',
60 'common.report',
61 'common.user',
62 'common.certstore',
63 'common.setting',
64 'common.applog',
65 'common.router',
66 'common.cacheadmin',
67 'common.organization',
68 'apps.portal',
69 'apps.token',
70 'apps.inventory',
71 'apps.securedns',
72 'apps.dashboard',
73]
74
75MIDDLEWARE_CLASSES = [
76 'django.middleware.security.SecurityMiddleware',
77 'django.contrib.sessions.middleware.SessionMiddleware',
78 'django.middleware.common.CommonMiddleware',
79 'django.middleware.csrf.CsrfViewMiddleware',
80 'django.contrib.auth.middleware.AuthenticationMiddleware',
81 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
82 'django.contrib.messages.middleware.MessageMiddleware',
83 'django.middleware.clickjacking.XFrameOptionsMiddleware',
84 'common.utils.middleware.ThreadLocalMiddleware',
85 'common.setting.middleware.CurrentSiteMiddleware',
86 'tz_detect.middleware.TimezoneMiddleware',
87]
88
89AUTHENTICATION_BACKENDS = [
90 'common.user.backends.CentralOAuth2',
91 'common.user.backends.OrganizationModelBackend',
92]
93
94SESSION_ENGINE = 'common.user.sessions'
95SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
96
97ROOT_URLCONF = 'urls'
98
99TEMPLATES = [
100 {
101 'BACKEND': 'django.template.backends.django.DjangoTemplates',
102 'DIRS': [
103 # insert your TEMPLATE_DIRS here
104 os.path.join(BASE_DIR, 'templates'),
105 ],
106 'APP_DIRS': False,
107 'OPTIONS': {
108 'context_processors': [
109 'django.template.context_processors.debug',
110 'django.template.context_processors.request',
111 'django.contrib.auth.context_processors.auth',
112 'django.contrib.messages.context_processors.messages',
113 'social.apps.django_app.context_processors.backends',
114 'social.apps.django_app.context_processors.login_redirect',
115 ],
116 'loaders': [
117 'django.template.loaders.filesystem.Loader',
118 'django.template.loaders.app_directories.Loader',
119 'common.utils.template.DatabaseLoader',
120 ],
121 'debug': True,
122 },
123 },
124]
125
126TEMPLATE_DB_MODEL = 'portal.Template'
127
128WSGI_APPLICATION = 'wsgi.application'
129
130
131# Database
132
133DATABASES = {
134 'default': {
135 'ENGINE': 'django.db.backends.sqlite3',
136 'NAME': os.path.join(PROJECT_DIR, 'controller.db'),
137
138 }
139}
140
141
142# Caching
143
144CACHES = {
145 'locmem': {
146 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
147 'TIMEOUT': 300,
148 'OPTIONS': {
149 'MAX_ENTRIES': 5000,
150 },
151 },
152 'default': {
153 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
154 'LOCATION': [
155 '127.0.0.1:11211',
156 ],
157 },
158}
159
160
161# email configuration
162
163EMAIL_HOST = '{email_host}'
164EMAIL_HOST_USER = '{email_user}'
165EMAIL_HOST_PASSWORD = '{email_password}'
166EMAIL_PORT = '{email_port}'
167EMAIL_USE_TLS = '{email_tls}'
168EMAIL_TIMEOUT = 30
169EMAIL_SUBJECT_PREFIX = '{{ email_subject_prefix }}'
170
171DEFAULT_FROM_EMAIL = '{email_from}'
172
173
174# Password hashers
175
176PASSWORD_HASHERS = [
177 'common.user.hashers.CryptSHA512PasswordHasher',
178 'django.contrib.auth.hashers.PBKDF2PasswordHasher',
179]
180
181
182# Password validation
183
184AUTH_PASSWORD_VALIDATORS = [
185 {'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', },
186 {'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', },
187 {'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', },
188 {'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', },
189]
190
191
192# Internationalization
193
194LANGUAGE_CODE = 'en-us'
195
196TIME_ZONE = 'UTC'
197
198USE_I18N = True
199
200USE_L10N = True
201
202USE_TZ = True
203
204
205# Static files (CSS, JavaScript, Images)
206
207STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
208STATIC_URL = '/static/'
209
210STATIC_DEV = os.path.join(PROJECT_DIR, "static-dev/")
211if ENVIRONMENT == 'dev' and os.path.exists(PROJECT_DIR):
212 STATICFILES_DIRS = [
213 os.path.join(PROJECT_DIR, 'static-dev/'),
214 ]
215
216
217MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
218MEDIA_URL = '/media/'
219
220ADMINS = [
221 ('{{ admin_name }}', '{{ admin_email }}'),
222]
223
224LOGGING = {
225 'version': 1,
226 'disable_existing_loggers': False,
227 'formatters': {
228 'verbose': {
229 'format': "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] "
230 "%(message)s",
231 'datefmt': "%d/%b/%Y %H:%M:%S"
232 },
233 'simple': {
234 'format': '%(levelname)s %(message)s'
235 },
236 },
237 'handlers': {
238 'default': {
239 'level': 'DEBUG',
240 'class': 'logging.handlers.RotatingFileHandler',
241 'filename': '/var/log/cerbro/controller.log',
242 'maxBytes': 1024*1024*5,
243 'backupCount': 1,
244 'formatter': 'verbose'
245 },
246 },
247 'loggers': {
248 '': {
249 'handlers': ['default'],
250 'level': 'DEBUG',
251 'propagate': True,
252 },
253 },
254}
255
256
257AUTH_USER_MODEL = 'user.User'
258SILENCED_SYSTEM_CHECKS = ["auth.E003", "auth.W004", ]
259
260
261# API settings
262
263REST_FRAMEWORK = {
264 'PAGE_SIZE': 20,
265 'DEFAULT_PAGINATION_CLASS':
266 'rest_framework.pagination.LimitOffsetPagination',
267 # Use Django's standard `django.contrib.auth` permissions,
268 # or allow read-only access for unauthenticated users.
269 'DEFAULT_PERMISSION_CLASSES': [
270 'rest_framework.permissions.IsAuthenticated',
271 'rest_framework.permissions.DjangoModelPermissions',
272 ],
273 'DEFAULT_AUTHENTICATION_CLASSES': [
274 # 'rest_framework.authentication.BasicAuthentication',
275 # 'rest_framework.authentication.SessionAuthentication',
276 'apps.inventory.backends.SSLRestClientAuthBackend',
277 'rest_framework.authentication.TokenAuthentication',
278 # 'oauth2_provider.ext.rest_framework.OAuth2Authentication',
279 ],
280 'DEFAULT_RENDERER_CLASSES': [
281 'rest_framework.renderers.JSONRenderer',
282 ],
283 'DEFAULT_PARSER_CLASSES': [
284 'rest_framework.parsers.JSONParser',
285 'rest_framework.parsers.FormParser',
286 'rest_framework.parsers.MultiPartParser',
287 ]
288}
289
290SWAGGER_SETTINGS = {
291 'api_version': '1.0',
292 # 'base_path': '/api/doc',
293 'is_authenticated': False,
294 'is_superuser': False,
295 'token_type': 'Token',
296 # 'token_type': 'Bearer',
297 'info': {
298 'title': 'Zequenze CONTROL API',
299 },
300 'template_path': 'swagger/index.html',
301}
302
303
304# SecureDNS filtering FW integration
305
306SECUREDNS = {
307 'FILTER_HOSTNAME': '{{ securedns_filter_hostname }}',
308 'FILTER_APIKEY': '{{ securedns_filter_apikey }}',
309 'HTTP_PROXY_HOST': 'proxy01.prd.cerbro.com',
310 'HTTP_PROXY_PORT': '3128',
311}
312
313
314# Remote devices SSL authentication
315
316SSL_AUTHENTICATION_HOSTS = [
317 'control.private.cerbro.com',
318]
319
320CODEMIRROR_PATH = 'vendor/codemirror'
321
322# OAuth authentication
323
324SOCIAL_AUTH_PIPELINE = (
325 'social.pipeline.social_auth.social_details',
326 'social.pipeline.social_auth.social_uid',
327 'social.pipeline.social_auth.auth_allowed',
328 'common.user.pipeline.social_user',
329 'common.user.pipeline.get_username',
330 'common.user.pipeline.create_user',
331 'common.user.pipeline.associate_user',
332 'social.pipeline.social_auth.load_extra_data',
333 'common.user.pipeline.user_details',
334)
335
336SOCIAL_AUTH_SANITIZE_REDIRECTS = False
337
338SOCIAL_AUTH_PROTECTED_FIELDS = [
339 'source', 'organization_id', 'organization', 'is_staff', 'is_superuser'
340]
341
342
343MENU_SELECT_PARENTS = True
344
345OBJECT_HASH_SECRET = '0R3DGZ2IVZy0!V@RePAgqWDO$Vuc$Rm8%gU7uUQs'
346
347STREAM_SERVER = 'stream.zequenze.com'
348STREAM_PORT = 9999