settings.py 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. # -*- coding: utf-8 -*-
  2. import os
  3. import ldap
  4. from django_auth_ldap.config import LDAPSearch, PosixGroupType
  5. # from custom.coin_posix_group_type import CoinPosixGroupType
  6. # Django settings for coin project.
  7. # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  8. BASE_DIR = os.path.dirname(os.path.dirname(__file__))
  9. PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
  10. DEBUG = TEMPLATE_DEBUG = False
  11. ADMINS = (
  12. # ('Your Name', 'your_email@example.com'),
  13. )
  14. MANAGERS = ADMINS
  15. DATABASES = {
  16. # Base de donnée du SI
  17. 'default': {
  18. 'ENGINE': 'django.db.backends.postgresql_psycopg2',
  19. 'NAME': 'illyse_coin',
  20. 'USER': 'illyse_coin',
  21. 'PASSWORD': '',
  22. 'HOST': '', # Empty for localhost through domain sockets
  23. 'PORT': '', # Empty for default
  24. },
  25. # LDAP backend pour stockage et mise à jour de données
  26. 'ldap': {
  27. 'ENGINE': 'ldapdb.backends.ldap',
  28. 'NAME': 'ldap://ldapdev.illyse.org:390/',
  29. 'TLS': True,
  30. 'GLOBAL_OPTIONS': {ldap.OPT_X_TLS_REQUIRE_CERT: ldap.OPT_X_TLS_NEVER},
  31. 'USER': 'cn=illysedev,ou=services,o=ILLYSE,l=Villeurbanne,st=RHA,c=FR',
  32. 'PASSWORD': 'gfj83-E8ECgGh23JK_Ol12'
  33. }
  34. }
  35. DATABASE_ROUTERS = ['ldapdb.router.Router']
  36. # Hosts/domain names that are valid for this site; required if DEBUG is False
  37. # See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
  38. ALLOWED_HOSTS = []
  39. # Local time zone for this installation. Choices can be found here:
  40. # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
  41. # although not all choices may be available on all operating systems.
  42. # In a Windows environment this must be set to your system time zone.
  43. TIME_ZONE = 'Europe/Paris'
  44. # Language code for this installation. All choices can be found here:
  45. # http://www.i18nguy.com/unicode/language-identifiers.html
  46. LANGUAGE_CODE = 'fr-fr'
  47. SITE_ID = 1
  48. # If you set this to False, Django will make some optimizations so as not
  49. # to load the internationalization machinery.
  50. USE_I18N = True
  51. # If you set this to False, Django will not format dates, numbers and
  52. # calendars according to the current locale.
  53. USE_L10N = True
  54. # If you set this to False, Django will not use timezone-aware datetimes.
  55. USE_TZ = True
  56. # Default URL for login and logout
  57. LOGIN_URL = '/members/login'
  58. LOGIN_REDIRECT_URL = '/members'
  59. LOGOUT_URL = '/members/logout'
  60. # Absolute filesystem path to the directory that will hold user-uploaded files.
  61. # Example: "/var/www/example.com/media/"
  62. MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
  63. # URL that handles the media served from MEDIA_ROOT. Make sure to use a
  64. # trailing slash.
  65. # Examples: "http://example.com/media/", "http://media.example.com/"
  66. MEDIA_URL = '/media/'
  67. # Absolute path to the directory static files should be collected to.
  68. # Don't put anything in this directory yourself; store your static files
  69. # in apps' "static/" subdirectories and in STATICFILES_DIRS.
  70. # Example: "/var/www/example.com/static/"
  71. STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
  72. # URL prefix for static files.
  73. # Example: "http://example.com/static/", "http://static.example.com/"
  74. STATIC_URL = '/static/'
  75. # Additional locations of static files
  76. STATICFILES_DIRS = (
  77. # Put strings here, like "/home/html/static" or "C:/www/django/static".
  78. # Always use forward slashes, even on Windows.
  79. # Don't forget to use absolute paths, not relative paths.
  80. )
  81. # List of finder classes that know how to find static files in
  82. # various locations.
  83. STATICFILES_FINDERS = (
  84. 'django.contrib.staticfiles.finders.FileSystemFinder',
  85. 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
  86. #'django.contrib.staticfiles.finders.DefaultStorageFinder',
  87. )
  88. # Make this unique, and don't share it with anybody.
  89. SECRET_KEY = '!qy_)gao6q)57#mz1s-d$5^+dp1nt=lk1d19&9bb3co37vn)!3'
  90. # List of callables that know how to import templates from various sources.
  91. TEMPLATE_LOADERS = (
  92. 'django.template.loaders.filesystem.Loader',
  93. 'django.template.loaders.app_directories.Loader',
  94. #'django.template.loaders.eggs.Loader',
  95. )
  96. MIDDLEWARE_CLASSES = (
  97. 'django.middleware.common.CommonMiddleware',
  98. 'django.contrib.sessions.middleware.SessionMiddleware',
  99. 'django.middleware.csrf.CsrfViewMiddleware',
  100. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  101. 'django.contrib.messages.middleware.MessageMiddleware',
  102. # Uncomment the next line for simple clickjacking protection:
  103. # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  104. )
  105. ROOT_URLCONF = 'coin.urls'
  106. # Python dotted path to the WSGI application used by Django's runserver.
  107. WSGI_APPLICATION = 'coin.wsgi.application'
  108. TEMPLATE_DIRS = (
  109. # Only absolute paths, always forward slashes
  110. os.path.join(PROJECT_PATH, 'templates/'),
  111. )
  112. INSTALLED_APPS = (
  113. 'django.contrib.auth',
  114. 'django.contrib.contenttypes',
  115. 'django.contrib.sessions',
  116. #'django.contrib.sites',
  117. 'django.contrib.messages',
  118. 'django.contrib.staticfiles',
  119. # Uncomment the next line to enable the admin:
  120. 'django.contrib.admin',
  121. # Uncomment the next line to enable admin documentation:
  122. #'django.contrib.admindocs',
  123. 'south',
  124. 'ldapdb', # LDAP as database backend
  125. 'autocomplete_light', #Automagic autocomplete foreingkey form component
  126. 'activelink', #Detect if a link match actual page
  127. 'coin',
  128. 'coin.members',
  129. 'coin.offers',
  130. 'coin.billing',
  131. 'coin.resources',
  132. 'coin.reverse_dns',
  133. 'coin.vpn'
  134. )
  135. # A sample logging configuration. The only tangible logging
  136. # performed by this configuration is to send an email to
  137. # the site admins on every HTTP 500 error when DEBUG=False.
  138. # See http://docs.djangoproject.com/en/dev/topics/logging for
  139. # more details on how to customize your logging configuration.
  140. LOGGING = {
  141. 'version': 1,
  142. 'disable_existing_loggers': False,
  143. 'filters': {
  144. 'require_debug_false': {
  145. '()': 'django.utils.log.RequireDebugFalse'
  146. }
  147. },
  148. 'handlers': {
  149. 'mail_admins': {
  150. 'level': 'ERROR',
  151. 'filters': ['require_debug_false'],
  152. 'class': 'django.utils.log.AdminEmailHandler'
  153. }
  154. },
  155. 'loggers': {
  156. 'django.request': {
  157. 'handlers': ['mail_admins'],
  158. 'level': 'ERROR',
  159. 'propagate': True,
  160. },
  161. }
  162. }
  163. TEMPLATE_CONTEXT_PROCESSORS = (
  164. "django.contrib.auth.context_processors.auth",
  165. "django.core.context_processors.debug",
  166. "django.core.context_processors.i18n",
  167. "django.core.context_processors.media",
  168. "django.core.context_processors.static",
  169. "django.core.context_processors.tz",
  170. "django.core.context_processors.request",
  171. "django.contrib.messages.context_processors.messages")
  172. AUTHENTICATION_BACKENDS = (
  173. 'django_auth_ldap.backend.LDAPBackend',
  174. 'django.contrib.auth.backends.ModelBackend',
  175. )
  176. # LDAP Backend pour authentification
  177. AUTH_LDAP_SERVER_URI = "ldap://ldapdev.illyse.org:390"
  178. AUTH_LDAP_START_TLS = True
  179. AUTH_LDAP_GLOBAL_OPTIONS = {ldap.OPT_X_TLS_REQUIRE_CERT: ldap.OPT_X_TLS_NEVER}
  180. AUTH_LDAP_BIND_DN = "cn=illysedev,ou=services,o=ILLYSE,l=Villeurbanne,st=RHA,c=FR"
  181. AUTH_LDAP_BIND_PASSWORD = "gfj83-E8ECgGh23JK_Ol12"
  182. AUTH_LDAP_USER_SEARCH = LDAPSearch(
  183. "ou=users,ou=unix,o=ILLYSE,l=Villeurbanne,st=RHA,c=FR",
  184. ldap.SCOPE_SUBTREE,
  185. "(cn=%(user)s)"
  186. )
  187. AUTH_LDAP_CACHE_GROUPS = False
  188. AUTH_LDAP_GROUP_SEARCH = LDAPSearch(
  189. "ou=groups,ou=unix,o=ILLYSE,l=Villeurbanne,st=RHA,c=FR",
  190. ldap.SCOPE_SUBTREE,
  191. "(objectClass=posixGroup)"
  192. )
  193. AUTH_LDAP_GROUP_TYPE = PosixGroupType()
  194. # AUTH_LDAP_REQUIRE_GROUP = "cn=admin,ou=groups,o=ILLYSE,"
  195. # "l=Villeurbanne,st=RHA,c=FR"
  196. AUTH_LDAP_USER_ATTR_MAP = {
  197. "first_name": "givenName",
  198. "last_name": "sn"
  199. }
  200. AUTH_LDAP_USER_FLAGS_BY_GROUP = {
  201. "is_active": "cn=coin,ou=groups,ou=unix,o=ILLYSE,l=Villeurbanne,st=RHA,c=FR",
  202. "is_staff": "cn=coin_admin,ou=groups,ou=unix,o=ILLYSE,l=Villeurbanne,st=RHA,c=FR",
  203. "is_superuser": "cn=coin_admin,ou=groups,ou=unix,o=ILLYSE,l=Villeurbanne,st=RHA,c=FR"
  204. }
  205. # Surcharge les paramètres en utilisant le fichier settings-local.py
  206. try:
  207. from settings_local import *
  208. except ImportError:
  209. pass