-
-
Notifications
You must be signed in to change notification settings - Fork 288
Expand file tree
/
Copy pathsettings.py
More file actions
309 lines (280 loc) · 10.3 KB
/
settings.py
File metadata and controls
309 lines (280 loc) · 10.3 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
import os
import sys
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
DEBUG = True
TESTING = os.environ.get("TESTING", False) or sys.argv[1:2] == ["test"]
SELENIUM_HEADLESS = True if os.environ.get("SELENIUM_HEADLESS", False) else False
SHELL = "shell" in sys.argv or "shell_plus" in sys.argv
REDIS_URL = os.getenv("REDIS_URL", "redis://localhost:6379")
ALLOWED_HOSTS = ["*"]
DATABASES = {
"default": {
"ENGINE": "openwisp_utils.db.backends.spatialite",
"NAME": os.path.join(BASE_DIR, "openwisp-controller.db"),
"OPTIONS": {"timeout": 10},
}
}
if TESTING and "--exclude-tag=selenium_tests" not in sys.argv:
DATABASES["default"]["TEST"] = {
"NAME": os.path.join(BASE_DIR, "openwisp-controller-test.db"),
}
SPATIALITE_LIBRARY_PATH = "mod_spatialite.so"
SECRET_KEY = "fn)t*+$)ugeyip6-#txyy$5wf2ervc0d2n#h)qb)y5@ly$t*@w"
INSTALLED_APPS = [
"daphne",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django.contrib.gis",
# all-auth
"django.contrib.sites",
"openwisp_users.accounts",
"allauth",
"allauth.account",
"allauth.socialaccount",
"django_extensions",
# openwisp2 modules
"openwisp_users",
"openwisp_controller.config",
"openwisp_controller.pki",
"openwisp_controller.geo",
"openwisp_controller.connection",
"openwisp_controller.subnet_division",
"openwisp_notifications",
"openwisp_ipam",
# openwisp2 admin theme
# (must be loaded here)
"openwisp_utils.admin_theme",
"admin_auto_filters",
# admin
"django.contrib.admin",
"django.forms",
# other dependencies
"sortedm2m",
"reversion",
"leaflet",
"flat_json_widget",
# rest framework
"rest_framework",
"rest_framework.authtoken",
"rest_framework_gis",
"django_filters",
"drf_yasg",
# channels
"channels",
"import_export",
# 'debug_toolbar',
]
EXTENDED_APPS = ("django_x509", "django_loci")
AUTH_USER_MODEL = "openwisp_users.User"
SITE_ID = 1
STATICFILES_FINDERS = [
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
"openwisp_utils.staticfiles.DependencyFinder",
]
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"allauth.account.middleware.AccountMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
# 'debug_toolbar.middleware.DebugToolbarMiddleware',
]
INTERNAL_IPS = ["127.0.0.1"]
ROOT_URLCONF = "openwisp2.urls"
ASGI_APPLICATION = "openwisp2.asgi.application"
if not TESTING:
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {"hosts": [f"{REDIS_URL}/7"]},
}
}
else:
CHANNEL_LAYERS = {"default": {"BACKEND": "channels.layers.InMemoryChannelLayer"}}
TIME_ZONE = "Europe/Rome"
LANGUAGE_CODE = "en-gb"
USE_TZ = True
USE_I18N = False
USE_L10N = False
STATIC_URL = "/static/"
MEDIA_URL = "/media/"
MEDIA_ROOT = f"{os.path.dirname(BASE_DIR)}/media/"
CORS_ORIGIN_ALLOW_ALL = True
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"OPTIONS": {
"loaders": [
"django.template.loaders.filesystem.Loader",
"openwisp_utils.loaders.DependencyLoader",
"django.template.loaders.app_directories.Loader",
],
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"openwisp_utils.admin_theme.context_processor.menu_groups",
"openwisp_notifications.context_processors.notification_api_settings",
],
},
}
]
LEAFLET_CONFIG = {"RESET_VIEW": False}
FORM_RENDERER = "django.forms.renderers.TemplatesSetting"
EMAIL_PORT = "1025" # for testing purposes
LOGIN_REDIRECT_URL = "admin:index"
ACCOUNT_LOGOUT_REDIRECT_URL = LOGIN_REDIRECT_URL
# disable allauth ratelimiting during automated tests
if TESTING:
ACCOUNT_RATE_LIMITS = False
OPENWISP_ORGANIZATION_USER_ADMIN = True # tests will fail without this setting
OPENWISP_ADMIN_DASHBOARD_ENABLED = True
OPENWISP_CONTROLLER_GROUP_PIE_CHART = True
# during development only
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": f"{REDIS_URL}/6",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
},
}
}
if not TESTING:
CELERY_BROKER_URL = f"{REDIS_URL}/1"
else:
CELERY_TASK_ALWAYS_EAGER = True
CELERY_TASK_EAGER_PROPAGATES = True
CELERY_BROKER_URL = "memory://"
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
SESSION_CACHE_ALIAS = "default"
LOGGING = {
"version": 1,
"filters": {"require_debug_true": {"()": "django.utils.log.RequireDebugTrue"}},
"handlers": {
"console": {
"level": "DEBUG",
"filters": ["require_debug_true"],
"class": "logging.StreamHandler",
}
},
}
if not TESTING and SHELL:
LOGGING.update(
{
"loggers": {
"django.db.backends": {
"level": "DEBUG",
"handlers": ["console"],
"propagate": False,
},
}
}
)
DJANGO_LOCI_GEOCODE_STRICT_TEST = False
OPENWISP_CONTROLLER_CONTEXT = {"vpnserver1": "vpn.testdomain.com"}
OPENWISP_USERS_AUTH_API = True
# GEOIP Related Settings
OPENWISP_CONTROLLER_WHOIS_GEOIP_ACCOUNT = os.getenv(
"OPENWISP_CONTROLLER_WHOIS_GEOIP_ACCOUNT", ""
)
OPENWISP_CONTROLLER_WHOIS_GEOIP_KEY = os.getenv(
"OPENWISP_CONTROLLER_WHOIS_GEOIP_KEY", ""
)
TEST_RUNNER = "openwisp_utils.tests.TimeLoggingTestRunner"
if os.environ.get("SAMPLE_APP", False):
DATABASES["default"]["NAME"] = os.path.join(
BASE_DIR, "openwisp-controller-SAMPLE_APP.db"
)
# Replace Config
config_index = INSTALLED_APPS.index("openwisp_controller.config")
INSTALLED_APPS.remove("openwisp_controller.config")
INSTALLED_APPS.insert(config_index, "openwisp2.sample_config")
# Replace Pki
pki_index = INSTALLED_APPS.index("openwisp_controller.pki")
INSTALLED_APPS.remove("openwisp_controller.pki")
INSTALLED_APPS.insert(pki_index, "openwisp2.sample_pki")
# Replace Geo
geo_index = INSTALLED_APPS.index("openwisp_controller.geo")
INSTALLED_APPS.remove("openwisp_controller.geo")
INSTALLED_APPS.insert(geo_index, "openwisp2.sample_geo")
# Replace Connection
connection_index = INSTALLED_APPS.index("openwisp_controller.connection")
INSTALLED_APPS.remove("openwisp_controller.connection")
INSTALLED_APPS.insert(connection_index, "openwisp2.sample_connection")
# Replace Openwisp_Users
users_index = INSTALLED_APPS.index("openwisp_users")
INSTALLED_APPS.remove("openwisp_users")
INSTALLED_APPS.insert(users_index, "openwisp2.sample_users")
# Replace Subnet Division
subnet_division_index = INSTALLED_APPS.index("openwisp_controller.subnet_division")
INSTALLED_APPS.remove("openwisp_controller.subnet_division")
INSTALLED_APPS.insert(subnet_division_index, "openwisp2.sample_subnet_division")
# Extended apps
EXTENDED_APPS = (
"django_x509",
"django_loci",
"openwisp_controller.config",
"openwisp_controller.pki",
"openwisp_controller.geo",
"openwisp_controller.connection",
"openwisp_controller.subnet_division",
"openwisp_users",
)
# Swapper
AUTH_USER_MODEL = "sample_users.User"
OPENWISP_USERS_GROUP_MODEL = "sample_users.Group"
OPENWISP_USERS_ORGANIZATION_MODEL = "sample_users.Organization"
OPENWISP_USERS_ORGANIZATIONUSER_MODEL = "sample_users.OrganizationUser"
OPENWISP_USERS_ORGANIZATIONOWNER_MODEL = "sample_users.OrganizationOwner"
OPENWISP_USERS_ORGANIZATIONINVITATION_MODEL = "sample_users.OrganizationInvitation"
CONFIG_DEVICE_MODEL = "sample_config.Device"
CONFIG_DEVICEGROUP_MODEL = "sample_config.DeviceGroup"
CONFIG_CONFIG_MODEL = "sample_config.Config"
CONFIG_TEMPLATETAG_MODEL = "sample_config.TemplateTag"
CONFIG_TAGGEDTEMPLATE_MODEL = "sample_config.TaggedTemplate"
CONFIG_TEMPLATE_MODEL = "sample_config.Template"
CONFIG_VPN_MODEL = "sample_config.Vpn"
CONFIG_VPNCLIENT_MODEL = "sample_config.VpnClient"
CONFIG_ORGANIZATIONCONFIGSETTINGS_MODEL = "sample_config.OrganizationConfigSettings"
CONFIG_ORGANIZATIONLIMITS_MODEL = "sample_config.OrganizationLimits"
CONFIG_WHOISINFO_MODEL = "sample_config.WHOISInfo"
DJANGO_X509_CA_MODEL = "sample_pki.Ca"
DJANGO_X509_CERT_MODEL = "sample_pki.Cert"
GEO_LOCATION_MODEL = "sample_geo.Location"
GEO_FLOORPLAN_MODEL = "sample_geo.FloorPlan"
GEO_DEVICELOCATION_MODEL = "sample_geo.DeviceLocation"
GEO_ORGANIZATIONGEOSETTINGS_MODEL = "sample_geo.OrganizationGeoSettings"
CONNECTION_CREDENTIALS_MODEL = "sample_connection.Credentials"
CONNECTION_DEVICECONNECTION_MODEL = "sample_connection.DeviceConnection"
CONNECTION_COMMAND_MODEL = "sample_connection.Command"
SUBNET_DIVISION_SUBNETDIVISIONRULE_MODEL = (
"sample_subnet_division.SubnetDivisionRule"
)
SUBNET_DIVISION_SUBNETDIVISIONINDEX_MODEL = (
"sample_subnet_division.SubnetDivisionIndex"
)
else:
# not needed, these are the default values, left here only for example purposes
# DJANGO_X509_CA_MODEL = 'pki.Ca'
# DJANGO_X509_CERT_MODEL = 'pki.Cert'
pass
if os.environ.get("SAMPLE_APP", False) and TESTING:
# Required for openwisp-users tests
OPENWISP_ORGANIZATION_USER_ADMIN = True
OPENWISP_ORGANIZATION_OWNER_ADMIN = True
OPENWISP_USERS_AUTH_API = True
# local settings must be imported before test runner otherwise they'll be ignored
try:
from .local_settings import *
except ImportError:
pass