settings.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. """
  2. Django settings for desecapi project.
  3. For more information on this file, see
  4. https://docs.djangoproject.com/en/1.7/topics/settings/
  5. For the full list of settings and their values, see
  6. https://docs.djangoproject.com/en/1.7/ref/settings/
  7. """
  8. # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  9. import os
  10. BASE_DIR = os.path.dirname(os.path.dirname(__file__))
  11. # Quick-start development settings - unsuitable for production
  12. # See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
  13. # SECURITY WARNING: keep the secret key used in production secret!
  14. SECRET_KEY = os.environ['DESECSTACK_API_SECRETKEY']
  15. # SECURITY WARNING: don't run with debug turned on in production!
  16. DEBUG = False
  17. if os.environ.get('DESECSTACK_API_DEBUG', "").upper() == "TRUE":
  18. DEBUG = True
  19. ALLOWED_HOSTS = [
  20. 'api',
  21. 'desec.%s' % os.environ['DESECSTACK_DOMAIN'],
  22. 'update.dedyn.%s' % os.environ['DESECSTACK_DOMAIN'],
  23. 'update6.dedyn.%s' % os.environ['DESECSTACK_DOMAIN'],
  24. ]
  25. # Application definition
  26. INSTALLED_APPS = (
  27. 'django.contrib.auth',
  28. 'django.contrib.contenttypes',
  29. 'rest_framework',
  30. 'djoser',
  31. 'desecapi',
  32. )
  33. MIDDLEWARE = (
  34. 'django.middleware.common.CommonMiddleware',
  35. 'django.middleware.csrf.CsrfViewMiddleware',
  36. )
  37. ROOT_URLCONF = 'api.urls'
  38. WSGI_APPLICATION = 'desecapi.wsgi.application'
  39. DATABASES = {
  40. 'default': {
  41. 'ENGINE': 'django.db.backends.mysql',
  42. 'NAME': 'desec',
  43. 'USER': 'desec',
  44. 'PASSWORD': os.environ['DESECSTACK_DBAPI_PASSWORD_desec'],
  45. 'HOST': 'dbapi',
  46. 'OPTIONS': {
  47. 'charset': 'utf8mb4',
  48. 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
  49. },
  50. 'TEST': {
  51. 'CHARSET': 'utf8mb4',
  52. 'COLLATION': 'utf8mb4_bin',
  53. },
  54. },
  55. }
  56. # This is necessary because the default is America/Chicago
  57. TIME_ZONE = 'UTC'
  58. USE_TZ = True
  59. REST_FRAMEWORK = {
  60. 'DEFAULT_RENDERER_CLASSES': (
  61. 'rest_framework.renderers.JSONRenderer',
  62. ),
  63. 'DEFAULT_PARSER_CLASSES': (
  64. 'rest_framework.parsers.JSONParser',
  65. ),
  66. 'DEFAULT_AUTHENTICATION_CLASSES': (
  67. 'desecapi.authentication.TokenAuthentication',
  68. ),
  69. 'TEST_REQUEST_DEFAULT_FORMAT': 'json',
  70. 'EXCEPTION_HANDLER': 'desecapi.exception_handlers.handle_db_unavailable',
  71. 'DEFAULT_VERSIONING_CLASS': 'rest_framework.versioning.NamespaceVersioning',
  72. 'ALLOWED_VERSIONS': ['v1', 'v2'],
  73. }
  74. # user management configuration
  75. DJOSER = {
  76. 'DOMAIN': 'desec.io',
  77. 'SITE_NAME': 'deSEC',
  78. 'PASSWORD_RESET_CONFIRM_URL': '#/password/reset/confirm/{uid}/{token}',
  79. 'ACTIVATION_URL': '#/activate/{uid}/{token}',
  80. 'LOGIN_AFTER_ACTIVATION': True,
  81. 'SEND_ACTIVATION_EMAIL': False,
  82. 'SERIALIZERS': {
  83. 'current_user': 'desecapi.serializers.UserSerializer',
  84. 'user': 'desecapi.serializers.UserSerializer',
  85. 'user_create': 'desecapi.serializers.UserCreateSerializer',
  86. },
  87. 'TOKEN_MODEL': 'desecapi.models.Token',
  88. }
  89. TEMPLATES = [
  90. {
  91. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  92. 'DIRS': [],
  93. 'APP_DIRS': True,
  94. 'OPTIONS': {
  95. 'context_processors': [
  96. 'django.template.context_processors.debug',
  97. 'django.template.context_processors.request',
  98. 'django.contrib.auth.context_processors.auth',
  99. 'django.contrib.messages.context_processors.messages',
  100. ],
  101. },
  102. },
  103. ]
  104. # How and where to send mail
  105. EMAIL_HOST = os.environ['DESECSTACK_API_EMAIL_HOST']
  106. EMAIL_HOST_USER = os.environ['DESECSTACK_API_EMAIL_HOST_USER']
  107. EMAIL_HOST_PASSWORD = os.environ['DESECSTACK_API_EMAIL_HOST_PASSWORD']
  108. EMAIL_PORT = os.environ['DESECSTACK_API_EMAIL_PORT']
  109. EMAIL_USE_TLS = True
  110. DEFAULT_FROM_EMAIL = 'deSEC <support@desec.io>'
  111. ADMINS = [(address.split("@")[0], address) for address in os.environ['DESECSTACK_API_ADMIN'].split()]
  112. # use our own user model
  113. AUTH_USER_MODEL = 'desecapi.User'
  114. # default NS records
  115. DEFAULT_NS = ['ns1.desec.io.', 'ns2.desec.io.']
  116. # Public Suffix settings
  117. LOCAL_PUBLIC_SUFFIXES = {'dedyn.io'}
  118. # PowerDNS API access
  119. NSLORD_PDNS_API = 'http://nslord:8081/api/v1/servers/localhost'
  120. NSLORD_PDNS_API_TOKEN = os.environ['DESECSTACK_NSLORD_APIKEY']
  121. NSMASTER_PDNS_API = 'http://nsmaster:8081/api/v1/servers/localhost'
  122. NSMASTER_PDNS_API_TOKEN = os.environ['DESECSTACK_NSMASTER_APIKEY']
  123. # pdns accepts request payloads of this size.
  124. # This will hopefully soon be configurable: https://github.com/PowerDNS/pdns/pull/7550
  125. PDNS_MAX_BODY_SIZE = 2 * 1024 * 1024
  126. # SEPA direct debit settings
  127. SEPA = {
  128. 'CREDITOR_ID': os.environ['DESECSTACK_API_SEPA_CREDITOR_ID'],
  129. 'CREDITOR_NAME': os.environ['DESECSTACK_API_SEPA_CREDITOR_NAME'],
  130. }
  131. # recaptcha
  132. NORECAPTCHA_SITE_KEY = os.environ['DESECSTACK_NORECAPTCHA_SITE_KEY']
  133. NORECAPTCHA_SECRET_KEY = os.environ['DESECSTACK_NORECAPTCHA_SECRET_KEY']
  134. NORECAPTCHA_WIDGET_TEMPLATE = 'captcha-widget.html'
  135. # abuse protection
  136. ABUSE_BY_REMOTE_IP_LIMIT = 1
  137. ABUSE_BY_REMOTE_IP_PERIOD_HRS = 48
  138. ABUSE_BY_EMAIL_HOSTNAME_LIMIT = 1
  139. ABUSE_BY_EMAIL_HOSTNAME_PERIOD_HRS = 24
  140. LIMIT_USER_DOMAIN_COUNT_DEFAULT = 5
  141. if os.environ.get('DESECSTACK_E2E_TEST', "").upper() == "TRUE":
  142. DEBUG = True
  143. EMAIL_BACKEND = 'django.core.mail.backends.dummy.EmailBackend'
  144. ABUSE_BY_REMOTE_IP_LIMIT = 100
  145. ABUSE_BY_REMOTE_IP_PERIOD_HRS = 0
  146. ABUSE_BY_EMAIL_HOSTNAME_LIMIT = 100
  147. ABUSE_BY_EMAIL_HOSTNAME_PERIOD_HRS = 0
  148. LIMIT_USER_DOMAIN_COUNT_DEFAULT = 5000