2016-07-08 17:09:35 -04:00
|
|
|
import logging
|
2016-03-01 11:23:03 -05:00
|
|
|
import os
|
|
|
|
import socket
|
|
|
|
|
2016-05-23 12:55:03 -04:00
|
|
|
from django.contrib.messages import constants as messages
|
2016-05-24 11:46:55 -04:00
|
|
|
from django.core.exceptions import ImproperlyConfigured
|
|
|
|
|
|
|
|
try:
|
2017-01-23 22:44:29 +01:00
|
|
|
from netbox import configuration
|
2016-05-24 11:46:55 -04:00
|
|
|
except ImportError:
|
2017-03-21 13:53:07 -04:00
|
|
|
raise ImproperlyConfigured(
|
|
|
|
"Configuration file is not present. Please define netbox/netbox/configuration.py per the documentation."
|
|
|
|
)
|
2016-05-24 11:46:55 -04:00
|
|
|
|
|
|
|
|
2017-03-23 17:14:41 -04:00
|
|
|
VERSION = '2.0.0-dev'
|
2016-06-29 14:05:01 -04:00
|
|
|
|
2016-05-24 11:46:55 -04:00
|
|
|
# Import local configuration
|
2017-03-21 13:53:07 -04:00
|
|
|
ALLOWED_HOSTS = DATABASE = SECRET_KEY = None
|
2016-05-24 14:24:35 -04:00
|
|
|
for setting in ['ALLOWED_HOSTS', 'DATABASE', 'SECRET_KEY']:
|
2016-05-24 11:46:55 -04:00
|
|
|
try:
|
|
|
|
globals()[setting] = getattr(configuration, setting)
|
|
|
|
except AttributeError:
|
2017-03-21 13:53:07 -04:00
|
|
|
raise ImproperlyConfigured(
|
|
|
|
"Mandatory setting {} is missing from configuration.py.".format(setting)
|
|
|
|
)
|
2016-05-24 11:46:55 -04:00
|
|
|
|
|
|
|
# Default configurations
|
2016-05-24 14:24:35 -04:00
|
|
|
ADMINS = getattr(configuration, 'ADMINS', [])
|
2016-05-24 11:46:55 -04:00
|
|
|
DEBUG = getattr(configuration, 'DEBUG', False)
|
2016-05-24 14:24:35 -04:00
|
|
|
EMAIL = getattr(configuration, 'EMAIL', {})
|
2016-05-24 11:46:55 -04:00
|
|
|
LOGIN_REQUIRED = getattr(configuration, 'LOGIN_REQUIRED', False)
|
2016-09-29 16:32:16 -04:00
|
|
|
BASE_PATH = getattr(configuration, 'BASE_PATH', '')
|
|
|
|
if BASE_PATH:
|
|
|
|
BASE_PATH = BASE_PATH.strip('/') + '/' # Enforce trailing slash only
|
2016-05-24 12:52:05 -04:00
|
|
|
MAINTENANCE_MODE = getattr(configuration, 'MAINTENANCE_MODE', False)
|
2016-05-24 11:46:55 -04:00
|
|
|
PAGINATE_COUNT = getattr(configuration, 'PAGINATE_COUNT', 50)
|
|
|
|
NETBOX_USERNAME = getattr(configuration, 'NETBOX_USERNAME', '')
|
|
|
|
NETBOX_PASSWORD = getattr(configuration, 'NETBOX_PASSWORD', '')
|
2016-05-24 12:52:05 -04:00
|
|
|
TIME_ZONE = getattr(configuration, 'TIME_ZONE', 'UTC')
|
2016-06-22 13:22:59 -04:00
|
|
|
DATE_FORMAT = getattr(configuration, 'DATE_FORMAT', 'N j, Y')
|
|
|
|
SHORT_DATE_FORMAT = getattr(configuration, 'SHORT_DATE_FORMAT', 'Y-m-d')
|
|
|
|
TIME_FORMAT = getattr(configuration, 'TIME_FORMAT', 'g:i a')
|
|
|
|
SHORT_TIME_FORMAT = getattr(configuration, 'SHORT_TIME_FORMAT', 'H:i:s')
|
|
|
|
DATETIME_FORMAT = getattr(configuration, 'DATETIME_FORMAT', 'N j, Y g:i a')
|
|
|
|
SHORT_DATETIME_FORMAT = getattr(configuration, 'SHORT_DATETIME_FORMAT', 'Y-m-d H:i')
|
2016-06-28 11:12:36 -04:00
|
|
|
BANNER_TOP = getattr(configuration, 'BANNER_TOP', False)
|
|
|
|
BANNER_BOTTOM = getattr(configuration, 'BANNER_BOTTOM', False)
|
2016-07-13 11:15:37 -04:00
|
|
|
PREFER_IPV4 = getattr(configuration, 'PREFER_IPV4', False)
|
2016-07-14 16:13:02 -04:00
|
|
|
ENFORCE_GLOBAL_UNIQUE = getattr(configuration, 'ENFORCE_GLOBAL_UNIQUE', False)
|
2017-03-21 13:53:07 -04:00
|
|
|
CORS_ORIGIN_ALLOW_ALL = getattr(configuration, 'CORS_ORIGIN_ALLOW_ALL', False)
|
|
|
|
CORS_ORIGIN_WHITELIST = getattr(configuration, 'CORS_ORIGIN_WHITELIST', [])
|
|
|
|
CORS_ORIGIN_REGEX_WHITELIST = getattr(configuration, 'CORS_ORIGIN_REGEX_WHITELIST', [])
|
2016-07-11 13:29:58 -04:00
|
|
|
CSRF_TRUSTED_ORIGINS = ALLOWED_HOSTS
|
2016-05-23 12:55:03 -04:00
|
|
|
|
2016-07-08 17:09:35 -04:00
|
|
|
# Attempt to import LDAP configuration if it has been defined
|
|
|
|
LDAP_IGNORE_CERT_ERRORS = False
|
|
|
|
try:
|
2017-01-23 22:44:29 +01:00
|
|
|
from netbox.ldap_config import *
|
2016-07-08 17:09:35 -04:00
|
|
|
LDAP_CONFIGURED = True
|
|
|
|
except ImportError:
|
|
|
|
LDAP_CONFIGURED = False
|
|
|
|
|
|
|
|
# LDAP configuration (optional)
|
|
|
|
if LDAP_CONFIGURED:
|
|
|
|
try:
|
2016-07-08 22:56:54 -04:00
|
|
|
import ldap
|
|
|
|
import django_auth_ldap
|
2016-07-08 17:09:35 -04:00
|
|
|
# Prepend LDAPBackend to the default ModelBackend
|
|
|
|
AUTHENTICATION_BACKENDS = [
|
|
|
|
'django_auth_ldap.backend.LDAPBackend',
|
|
|
|
'django.contrib.auth.backends.ModelBackend',
|
|
|
|
]
|
|
|
|
# Optionally disable strict certificate checking
|
|
|
|
if LDAP_IGNORE_CERT_ERRORS:
|
|
|
|
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
|
|
|
|
# Enable logging for django_auth_ldap
|
|
|
|
logger = logging.getLogger('django_auth_ldap')
|
|
|
|
logger.addHandler(logging.StreamHandler())
|
|
|
|
logger.setLevel(logging.DEBUG)
|
|
|
|
except ImportError:
|
2017-03-21 13:53:07 -04:00
|
|
|
raise ImproperlyConfigured(
|
|
|
|
"LDAP authentication has been configured, but django-auth-ldap is not installed. You can remove "
|
|
|
|
"netbox/ldap_config.py to disable LDAP."
|
|
|
|
)
|
2016-07-08 17:09:35 -04:00
|
|
|
|
2016-03-01 11:23:03 -05:00
|
|
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
|
2016-05-24 11:46:55 -04:00
|
|
|
# Database
|
|
|
|
configuration.DATABASE.update({'ENGINE': 'django.db.backends.postgresql'})
|
|
|
|
DATABASES = {
|
|
|
|
'default': configuration.DATABASE,
|
|
|
|
}
|
|
|
|
|
2016-05-24 14:24:35 -04:00
|
|
|
# Email
|
|
|
|
EMAIL_HOST = EMAIL.get('SERVER')
|
|
|
|
EMAIL_PORT = EMAIL.get('PORT', 25)
|
2016-05-24 14:37:50 -04:00
|
|
|
EMAIL_HOST_USER = EMAIL.get('USERNAME')
|
2016-05-24 14:24:35 -04:00
|
|
|
EMAIL_HOST_PASSWORD = EMAIL.get('PASSWORD')
|
|
|
|
EMAIL_TIMEOUT = EMAIL.get('TIMEOUT', 10)
|
|
|
|
SERVER_EMAIL = EMAIL.get('FROM_EMAIL')
|
|
|
|
EMAIL_SUBJECT_PREFIX = '[NetBox] '
|
|
|
|
|
2016-05-23 12:55:03 -04:00
|
|
|
# Installed applications
|
2016-03-01 11:23:03 -05:00
|
|
|
INSTALLED_APPS = (
|
|
|
|
'django.contrib.admin',
|
|
|
|
'django.contrib.auth',
|
|
|
|
'django.contrib.contenttypes',
|
|
|
|
'django.contrib.sessions',
|
|
|
|
'django.contrib.messages',
|
|
|
|
'django.contrib.staticfiles',
|
2016-05-26 15:35:48 -04:00
|
|
|
'django.contrib.humanize',
|
2017-03-21 13:53:07 -04:00
|
|
|
'corsheaders',
|
2016-03-01 11:23:03 -05:00
|
|
|
'debug_toolbar',
|
|
|
|
'django_tables2',
|
2017-02-28 16:10:53 -05:00
|
|
|
'mptt',
|
2016-03-01 11:23:03 -05:00
|
|
|
'rest_framework',
|
2017-02-01 12:37:19 -05:00
|
|
|
'rest_framework_swagger',
|
2016-03-01 11:23:03 -05:00
|
|
|
'circuits',
|
|
|
|
'dcim',
|
|
|
|
'ipam',
|
|
|
|
'extras',
|
|
|
|
'secrets',
|
2016-07-26 14:58:37 -04:00
|
|
|
'tenancy',
|
2016-03-01 11:23:03 -05:00
|
|
|
'users',
|
|
|
|
'utilities',
|
|
|
|
)
|
|
|
|
|
2016-05-23 12:55:03 -04:00
|
|
|
# Middleware
|
2016-12-26 10:48:15 -05:00
|
|
|
MIDDLEWARE = (
|
2016-12-29 13:45:57 -05:00
|
|
|
'debug_toolbar.middleware.DebugToolbarMiddleware',
|
2017-03-21 13:53:07 -04:00
|
|
|
'corsheaders.middleware.CorsMiddleware',
|
2016-03-01 11:23:03 -05:00
|
|
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
|
|
|
'django.middleware.common.CommonMiddleware',
|
|
|
|
'django.middleware.csrf.CsrfViewMiddleware',
|
|
|
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
|
|
|
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
|
|
|
|
'django.contrib.messages.middleware.MessageMiddleware',
|
|
|
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
|
|
|
'django.middleware.security.SecurityMiddleware',
|
|
|
|
'utilities.middleware.LoginRequiredMiddleware',
|
2017-03-21 13:23:56 -04:00
|
|
|
'utilities.middleware.APIVersionMiddleware',
|
2016-03-01 11:23:03 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
ROOT_URLCONF = 'netbox.urls'
|
|
|
|
|
|
|
|
TEMPLATES = [
|
|
|
|
{
|
|
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
|
|
'DIRS': [BASE_DIR + '/templates/'],
|
|
|
|
'APP_DIRS': True,
|
|
|
|
'OPTIONS': {
|
|
|
|
'context_processors': [
|
|
|
|
'django.template.context_processors.debug',
|
|
|
|
'django.template.context_processors.request',
|
|
|
|
'django.contrib.auth.context_processors.auth',
|
|
|
|
'django.contrib.messages.context_processors.messages',
|
|
|
|
'utilities.context_processors.settings',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2016-05-23 12:55:03 -04:00
|
|
|
# WSGI
|
2016-03-01 11:23:03 -05:00
|
|
|
WSGI_APPLICATION = 'netbox.wsgi.application'
|
|
|
|
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|
2016-05-24 14:24:35 -04:00
|
|
|
USE_X_FORWARDED_HOST = True
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
# Internationalization
|
|
|
|
# https://docs.djangoproject.com/en/1.8/topics/i18n/
|
|
|
|
LANGUAGE_CODE = 'en-us'
|
|
|
|
USE_I18N = True
|
|
|
|
USE_TZ = True
|
|
|
|
|
|
|
|
# Static files (CSS, JavaScript, Images)
|
|
|
|
# https://docs.djangoproject.com/en/1.8/howto/static-files/
|
2016-05-24 14:24:35 -04:00
|
|
|
STATIC_ROOT = BASE_DIR + '/static/'
|
2016-10-13 16:27:09 -04:00
|
|
|
STATIC_URL = '/{}static/'.format(BASE_PATH)
|
2016-03-01 11:23:03 -05:00
|
|
|
STATICFILES_DIRS = (
|
|
|
|
os.path.join(BASE_DIR, "project-static"),
|
|
|
|
)
|
|
|
|
|
2016-08-18 10:12:43 -04:00
|
|
|
# Disable default limit of 1000 fields per request. Needed for bulk deletion of objects. (Added in Django 1.10.)
|
|
|
|
DATA_UPLOAD_MAX_NUMBER_FIELDS = None
|
|
|
|
|
2016-03-01 11:23:03 -05:00
|
|
|
# Messages
|
|
|
|
MESSAGE_TAGS = {
|
|
|
|
messages.ERROR: 'danger',
|
|
|
|
}
|
|
|
|
|
2016-05-23 12:55:03 -04:00
|
|
|
# Authentication URLs
|
2016-10-13 16:27:09 -04:00
|
|
|
LOGIN_URL = '/{}login/'.format(BASE_PATH)
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
# Secrets
|
|
|
|
SECRETS_MIN_PUBKEY_SIZE = 2048
|
|
|
|
|
2017-01-27 14:54:12 -05:00
|
|
|
# Django REST framework (API)
|
2017-03-21 12:59:44 -04:00
|
|
|
REST_FRAMEWORK_VERSION = VERSION[0:3] # Use major.minor as API version
|
2016-03-01 11:23:03 -05:00
|
|
|
REST_FRAMEWORK = {
|
2017-03-07 17:17:39 -05:00
|
|
|
'DEFAULT_AUTHENTICATION_CLASSES': (
|
|
|
|
'rest_framework.authentication.SessionAuthentication',
|
|
|
|
'utilities.api.TokenAuthentication',
|
|
|
|
),
|
|
|
|
'DEFAULT_FILTER_BACKENDS': (
|
|
|
|
'rest_framework.filters.DjangoFilterBackend',
|
|
|
|
),
|
2017-01-27 14:54:12 -05:00
|
|
|
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
|
2017-03-07 17:17:39 -05:00
|
|
|
'DEFAULT_PERMISSION_CLASSES': (
|
|
|
|
'utilities.api.TokenPermissions',
|
|
|
|
),
|
2017-03-20 12:33:42 -04:00
|
|
|
'DEFAULT_VERSION': REST_FRAMEWORK_VERSION,
|
2017-03-21 12:59:44 -04:00
|
|
|
'ALLOWED_VERSIONS': [REST_FRAMEWORK_VERSION],
|
2017-03-02 16:20:16 -05:00
|
|
|
'DEFAULT_VERSIONING_CLASS': 'rest_framework.versioning.AcceptHeaderVersioning',
|
2017-01-27 14:54:12 -05:00
|
|
|
'PAGE_SIZE': PAGINATE_COUNT,
|
2016-03-01 11:23:03 -05:00
|
|
|
}
|
|
|
|
|
2016-12-26 12:15:14 -05:00
|
|
|
# Django debug toolbar
|
|
|
|
INTERNAL_IPS = (
|
|
|
|
'127.0.0.1',
|
|
|
|
'::1',
|
|
|
|
)
|
|
|
|
|
2016-05-24 15:09:17 -04:00
|
|
|
|
2016-03-01 11:23:03 -05:00
|
|
|
try:
|
|
|
|
HOSTNAME = socket.gethostname()
|
|
|
|
except:
|
|
|
|
HOSTNAME = 'localhost'
|