"""
Django settings for bolt_website project.

Generated by 'django-admin startproject' using Django 2.1.2.

For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'lboa^bo)vd#s57f+khycpq)3i$%#_&3yylvtyhnt^(f4x0z73a'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

ALLOWED_HOSTS = ["*"]


# LDAP auth settings.
AUTHENTICATION_BACKENDS = (
    "django_python3_ldap.auth.LDAPBackend",
    'django.contrib.auth.backends.ModelBackend',
)

LDAP_AUTH_URL = os.environ.get("LDAP_AUTH_URL", "ldap://winserver2008.boltcorp.com:389")

# Initiate TLS on connection.
LDAP_AUTH_USE_TLS = False

LDAP_AUTH_SEARCH_BASE = "CN=Users,dc=BOLTCorp,dc=com"

LDAP_AUTH_OBJECT_CLASS = "user"

LDAP_AUTH_USER_FIELDS = {
    "username": "sAMAccountName",
    "first_name": "givenName",
    "last_name": "sn",
    "email": "mail",
}

LDAP_AUTH_USER_LOOKUP_FIELDS = ("username",)
LDAP_AUTH_CLEAN_USER_DATA = "django_python3_ldap.utils.clean_user_data"
LDAP_AUTH_SYNC_USER_RELATIONS = "django_python3_ldap.utils.sync_user_relations"
LDAP_AUTH_FORMAT_SEARCH_FILTERS = "django_python3_ldap.utils.format_search_filters"
LDAP_AUTH_FORMAT_USERNAME = "django_python3_ldap.utils.format_username_active_directory_principal"
LDAP_AUTH_ACTIVE_DIRECTORY_DOMAIN = "BOLTCorp.com"
# LDAP_AUTH_CONNECTION_USERNAME = "a.dozac"
# LDAP_AUTH_CONNECTION_PASSWORD = "PPz8EiAYqWfaDFNBhc"
LDAP_AUTH_CONNECTION_USERNAME = "jweathe"
LDAP_AUTH_CONNECTION_PASSWORD = "epYj0@91"

LOGGING = {
    "version": 1,
    "disable_existing_loggers": False,
    "handlers": {
        "console": {
            "class": "logging.StreamHandler",
        },
    },
    "loggers": {
        "django_python3_ldap": {
            "handlers": ["console"],
            "level": "INFO",
        },
    },
}

# Application definition

INSTALLED_APPS = [
    'home.apps.HomeConfig',
    'hmi.apps.HmiConfig',
    'hpc.apps.HpcConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django_python3_ldap',
    #'django_send_email',
    #'djcelery_email',
    'notes',
    'inventory',
    'fileshare',
    'helpdesk',
    'WebIOPi'
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'bolt_website.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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',
            ],
        },
    },
]

TEMPLATE_CONTEXT_PROCESSORS = (
    "django.contrib.auth.context_processors.auth",
    "django.core.context_processors.request",
    "django.core.context_processors.debug",
    "django.core.context_processors.i18n",
    "django.core.context_processors.media",
    "django.core.context_processors.static",
    "django.core.context_processors.tz",
    "django.contrib.messages.context_processors.messages",
)

WSGI_APPLICATION = 'bolt_website.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
import netifaces as ni
db_ip = ni.ifaddresses('eth0')[2][0]['addr'].split('.')
db_ip[3] = str(6)
db_ip = ".".join(db_ip)

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'django',
        'USER': 'djangouser',
        'PASSWORD': 'BBKjNMlA@uMdq4LVBl',
        'HOST': db_ip,
        'PORT': '3306',
        'OPTIONS': {
                'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
        }
    }
}
#DATABASES = {
#    'default': {
#        'ENGINE': 'django.db.backends.sqlite3',
#        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
#    }
#}


# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

# TIME_ZONE = 'CST'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/

STATIC_URL = '/static/'

LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'

# secure
MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.middleware.csrf.CsrfResponseMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
)
SECURE_BROWSER_XSS_FILTER = True
SECURE_CONTENT_TYPE_NOSNIFF = True
# CSRF_COOKIE_SECURE = True
# X_FRAME_OPTIONS = 'DENY'

# email
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
  
#EMAIL_USE_TLS = True
#EMAIL_HOST = 'smtp.gmail.com'
#EMAIL_PORT = 587
#EMAIL_HOST_USER = 'iucyberforce2018@gmail.com'
#EMAIL_HOST_PASSWORD = 'cybersec2018'
#DEFAULT_FROM_EMAIL = 'iucyberforce2018@gmail.com'
#EMAIL_USE_TLS = True
#EMAIL_HOST = 'smtp.gmail.com'
#EMAIL_PORT = 587
#EMAIL_HOST_USER = 'iothouse33@gmail.com'
#EMAIL_HOST_PASSWORD = 'iothouse_rock$?'
#DEFAULT_FROM_EMAIL = 'iothouse33@gmail.com'
EMAIL_USE_TLS = False
EMAIL_HOST = '10.0.22.5'
EMAIL_PORT = 25
EMAIL_HOST_USER = 'iucfc@ubuntu1604.boltcorp.com'
#EMAIL_HOST_PASSWORD = 'cybersec2018'
DEFAULT_FROM_EMAIL = 'iucfc@ubuntu1604.boltcorp.com'

#EMAIL_BACKEND = 'djcelery_email.backends.CeleryEmailBackend'
#CELERY_EMAIL_TASK_CONFIG = {
#    'name': 'djcelery_email_send',
#    'ignore_result': True,
#}
