2019-04-11 19:40:37 +12:00
|
|
|
__package__ = 'archivebox.core'
|
2019-04-03 11:53:21 +13:00
|
|
|
|
2024-01-25 23:22:23 +13:00
|
|
|
# TODO: add this after we upgrade to Django >=3.2
|
|
|
|
# https://github.com/typeddjango/django-stubs
|
|
|
|
# import django_stubs_ext
|
|
|
|
# django_stubs_ext.monkeypatch()
|
|
|
|
|
2019-04-17 19:49:18 +12:00
|
|
|
import os
|
2019-04-23 11:07:39 +12:00
|
|
|
import sys
|
2021-02-16 14:51:23 +13:00
|
|
|
import re
|
|
|
|
import logging
|
2021-03-27 19:17:12 +13:00
|
|
|
import tempfile
|
2020-10-31 20:08:03 +13:00
|
|
|
|
2020-10-01 08:54:32 +13:00
|
|
|
from pathlib import Path
|
2020-04-23 13:14:43 +12:00
|
|
|
from django.utils.crypto import get_random_string
|
2019-04-03 11:53:21 +13:00
|
|
|
|
2021-04-11 19:57:04 +12:00
|
|
|
from ..config import (
|
2020-07-28 15:26:45 +12:00
|
|
|
DEBUG,
|
2019-05-03 11:15:16 +12:00
|
|
|
SECRET_KEY,
|
|
|
|
ALLOWED_HOSTS,
|
2020-10-31 20:08:03 +13:00
|
|
|
PACKAGE_DIR,
|
2020-12-12 03:21:09 +13:00
|
|
|
TEMPLATES_DIR_NAME,
|
2021-04-06 16:57:20 +12:00
|
|
|
CUSTOM_TEMPLATES_DIR,
|
2019-05-03 11:15:16 +12:00
|
|
|
SQL_INDEX_FILENAME,
|
2020-07-28 15:26:45 +12:00
|
|
|
OUTPUT_DIR,
|
2021-02-16 14:51:23 +13:00
|
|
|
LOGS_DIR,
|
2022-06-09 15:00:29 +12:00
|
|
|
TIMEZONE,
|
2023-08-17 14:53:49 +12:00
|
|
|
|
|
|
|
LDAP,
|
|
|
|
LDAP_SERVER_URI,
|
|
|
|
LDAP_BIND_DN,
|
|
|
|
LDAP_BIND_PASSWORD,
|
|
|
|
LDAP_USER_BASE,
|
|
|
|
LDAP_USER_FILTER,
|
|
|
|
LDAP_USERNAME_ATTR,
|
|
|
|
LDAP_FIRSTNAME_ATTR,
|
|
|
|
LDAP_LASTNAME_ATTR,
|
|
|
|
LDAP_EMAIL_ATTR,
|
2019-05-03 11:15:16 +12:00
|
|
|
)
|
2019-04-17 21:42:09 +12:00
|
|
|
|
2020-10-31 20:08:03 +13:00
|
|
|
IS_MIGRATING = 'makemigrations' in sys.argv[:3] or 'migrate' in sys.argv[:3]
|
|
|
|
IS_TESTING = 'test' in sys.argv[:3] or 'PYTEST_CURRENT_TEST' in os.environ
|
2019-04-23 11:07:39 +12:00
|
|
|
IS_SHELL = 'shell' in sys.argv[:3] or 'shell_plus' in sys.argv[:3]
|
2019-04-03 11:53:21 +13:00
|
|
|
|
2020-10-31 20:08:03 +13:00
|
|
|
################################################################################
|
|
|
|
### Django Core Settings
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
WSGI_APPLICATION = 'core.wsgi.application'
|
|
|
|
ROOT_URLCONF = 'core.urls'
|
|
|
|
|
|
|
|
LOGIN_URL = '/accounts/login/'
|
2022-04-01 08:40:14 +13:00
|
|
|
LOGOUT_REDIRECT_URL = os.environ.get('LOGOUT_REDIRECT_URL', '/')
|
|
|
|
|
2020-10-31 20:08:03 +13:00
|
|
|
PASSWORD_RESET_URL = '/accounts/password_reset/'
|
|
|
|
APPEND_SLASH = True
|
2020-04-23 13:14:43 +12:00
|
|
|
|
2021-02-17 10:23:09 +13:00
|
|
|
DEBUG = DEBUG or ('--debug' in sys.argv)
|
2021-01-31 00:07:35 +13:00
|
|
|
|
2019-04-03 11:53:21 +13:00
|
|
|
INSTALLED_APPS = [
|
2019-04-17 19:49:18 +12:00
|
|
|
'django.contrib.auth',
|
|
|
|
'django.contrib.contenttypes',
|
|
|
|
'django.contrib.sessions',
|
|
|
|
'django.contrib.messages',
|
|
|
|
'django.contrib.staticfiles',
|
2020-07-28 15:26:45 +12:00
|
|
|
'django.contrib.admin',
|
2024-01-24 21:07:07 +13:00
|
|
|
'solo',
|
|
|
|
|
2019-04-03 11:53:21 +13:00
|
|
|
|
|
|
|
'core',
|
2024-01-18 02:14:43 +13:00
|
|
|
|
|
|
|
# Plugins
|
2024-01-24 21:07:07 +13:00
|
|
|
|
|
|
|
'plugins.defaults',
|
|
|
|
'plugins.system',
|
2024-02-09 02:54:18 +13:00
|
|
|
# 'plugins.replaywebpage', # provides UI to view WARC files
|
|
|
|
# 'plugins.gallerydl', # provides gallerydl dependency + extractor
|
|
|
|
# 'plugins.browsertrix', # provides browsertrix dependency + extractor
|
|
|
|
# 'plugins.playwright', # provides playwright dependency
|
2024-01-18 02:14:43 +13:00
|
|
|
# ...
|
|
|
|
# someday we may have enough plugins to justify dynamic loading:
|
|
|
|
# *(path.parent.name for path in (Path(PACKAGE_DIR) / 'plugins').glob('*/apps.py')),,
|
2019-04-17 21:42:09 +12:00
|
|
|
|
2019-04-17 19:49:18 +12:00
|
|
|
'django_extensions',
|
2019-04-03 11:53:21 +13:00
|
|
|
]
|
2021-02-17 10:23:09 +13:00
|
|
|
|
2024-01-20 04:09:24 +13:00
|
|
|
################################################################################
|
|
|
|
### Staticfile and Template Settings
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
STATIC_URL = '/static/'
|
|
|
|
|
|
|
|
STATIC_ROOT = Path(PACKAGE_DIR) / 'collected_static'
|
|
|
|
|
|
|
|
STATICFILES_DIRS = [
|
|
|
|
*([str(CUSTOM_TEMPLATES_DIR / 'static')] if CUSTOM_TEMPLATES_DIR else []),
|
|
|
|
str(Path(PACKAGE_DIR) / TEMPLATES_DIR_NAME / 'static'),
|
|
|
|
|
|
|
|
# Plugins
|
2024-01-24 21:07:07 +13:00
|
|
|
# str(Path(PACKAGE_DIR) / 'plugins/defaults/static'),
|
|
|
|
# str(Path(PACKAGE_DIR) / 'plugins/replaywebpage/static'),
|
|
|
|
# str(Path(PACKAGE_DIR) / 'plugins/gallerydl/static'),
|
2024-01-20 04:09:24 +13:00
|
|
|
# str(Path(PACKAGE_DIR) / 'plugins/browsertrix/static'),
|
|
|
|
# str(Path(PACKAGE_DIR) / 'plugins/playwright/static'),
|
|
|
|
# ...
|
|
|
|
# someday if there are many more plugins / user-addable plugins:
|
|
|
|
# *(str(path) for path in (Path(PACKAGE_DIR) / 'plugins').glob('*/static')),
|
|
|
|
]
|
|
|
|
|
|
|
|
MEDIA_URL = '/archive/'
|
|
|
|
MEDIA_ROOT = OUTPUT_DIR / 'archive'
|
|
|
|
|
|
|
|
|
|
|
|
TEMPLATE_DIRS = [
|
|
|
|
*([str(CUSTOM_TEMPLATES_DIR)] if CUSTOM_TEMPLATES_DIR else []),
|
|
|
|
str(Path(PACKAGE_DIR) / TEMPLATES_DIR_NAME / 'core'),
|
|
|
|
str(Path(PACKAGE_DIR) / TEMPLATES_DIR_NAME / 'admin'),
|
|
|
|
str(Path(PACKAGE_DIR) / TEMPLATES_DIR_NAME),
|
|
|
|
|
|
|
|
# Plugins
|
2024-01-24 21:07:07 +13:00
|
|
|
# added by plugins.<PluginName>.apps.<AppName>.ready -> .settings.register_plugin_settings
|
|
|
|
# str(Path(PACKAGE_DIR) / 'plugins/defaults/templates'),
|
|
|
|
# str(Path(PACKAGE_DIR) / 'plugins/replaywebpage/templates'),
|
|
|
|
# str(Path(PACKAGE_DIR) / 'plugins/gallerydl/templates'),
|
2024-01-20 04:09:24 +13:00
|
|
|
# str(Path(PACKAGE_DIR) / 'plugins/browsertrix/templates'),
|
|
|
|
# str(Path(PACKAGE_DIR) / 'plugins/playwright/templates'),
|
|
|
|
# ...
|
|
|
|
#
|
|
|
|
# someday if there are many more plugins / user-addable plugins:
|
|
|
|
# *(str(path) for path in (Path(PACKAGE_DIR) / 'plugins').glob('*/templates')),
|
|
|
|
]
|
|
|
|
|
|
|
|
TEMPLATES = [
|
|
|
|
{
|
|
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
|
|
'DIRS': TEMPLATE_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',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
2023-09-14 21:41:27 +12:00
|
|
|
|
|
|
|
# For usage with https://www.jetadmin.io/integrations/django
|
|
|
|
# INSTALLED_APPS += ['jet_django']
|
|
|
|
# JET_PROJECT = 'archivebox'
|
|
|
|
# JET_TOKEN = 'some-api-token-here'
|
|
|
|
|
|
|
|
|
2021-02-17 10:23:09 +13:00
|
|
|
MIDDLEWARE = [
|
2021-04-10 20:16:12 +12:00
|
|
|
'core.middleware.TimezoneMiddleware',
|
2021-02-17 10:23:09 +13:00
|
|
|
'django.middleware.security.SecurityMiddleware',
|
|
|
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
|
|
|
'django.middleware.common.CommonMiddleware',
|
|
|
|
'django.middleware.csrf.CsrfViewMiddleware',
|
|
|
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
2021-10-01 04:40:13 +13:00
|
|
|
'core.middleware.ReverseProxyAuthMiddleware',
|
2021-02-17 10:23:09 +13:00
|
|
|
'django.contrib.messages.middleware.MessageMiddleware',
|
2021-04-10 20:16:12 +12:00
|
|
|
'core.middleware.CacheControlMiddleware',
|
2021-02-17 10:23:09 +13:00
|
|
|
]
|
|
|
|
|
2023-08-17 14:53:49 +12:00
|
|
|
################################################################################
|
|
|
|
### Authentication Settings
|
|
|
|
################################################################################
|
|
|
|
|
2021-02-17 10:23:09 +13:00
|
|
|
AUTHENTICATION_BACKENDS = [
|
2021-10-01 04:40:13 +13:00
|
|
|
'django.contrib.auth.backends.RemoteUserBackend',
|
2021-02-17 10:23:09 +13:00
|
|
|
'django.contrib.auth.backends.ModelBackend',
|
|
|
|
]
|
|
|
|
|
2023-08-17 14:53:49 +12:00
|
|
|
if LDAP:
|
2023-10-20 14:05:59 +13:00
|
|
|
try:
|
|
|
|
import ldap
|
|
|
|
from django_auth_ldap.config import LDAPSearch
|
|
|
|
|
|
|
|
global AUTH_LDAP_SERVER_URI
|
|
|
|
global AUTH_LDAP_BIND_DN
|
|
|
|
global AUTH_LDAP_BIND_PASSWORD
|
2023-10-21 00:08:38 +13:00
|
|
|
global AUTH_LDAP_USER_SEARCH
|
|
|
|
global AUTH_LDAP_USER_ATTR_MAP
|
|
|
|
|
|
|
|
AUTH_LDAP_SERVER_URI = LDAP_SERVER_URI
|
|
|
|
AUTH_LDAP_BIND_DN = LDAP_BIND_DN
|
2023-10-20 14:05:59 +13:00
|
|
|
AUTH_LDAP_BIND_PASSWORD = LDAP_BIND_PASSWORD
|
|
|
|
|
2023-10-21 00:08:38 +13:00
|
|
|
assert AUTH_LDAP_SERVER_URI and LDAP_USERNAME_ATTR and LDAP_USER_FILTER, 'LDAP_* config options must all be set if LDAP=True'
|
|
|
|
|
2023-10-20 14:05:59 +13:00
|
|
|
AUTH_LDAP_USER_SEARCH = LDAPSearch(
|
|
|
|
LDAP_USER_BASE,
|
|
|
|
ldap.SCOPE_SUBTREE,
|
|
|
|
'(&(' + LDAP_USERNAME_ATTR + '=%(user)s)' + LDAP_USER_FILTER + ')',
|
|
|
|
)
|
|
|
|
|
|
|
|
AUTH_LDAP_USER_ATTR_MAP = {
|
|
|
|
'username': LDAP_USERNAME_ATTR,
|
|
|
|
'first_name': LDAP_FIRSTNAME_ATTR,
|
|
|
|
'last_name': LDAP_LASTNAME_ATTR,
|
|
|
|
'email': LDAP_EMAIL_ATTR,
|
|
|
|
}
|
|
|
|
|
|
|
|
AUTHENTICATION_BACKENDS = [
|
2023-12-07 01:16:51 +13:00
|
|
|
'django.contrib.auth.backends.ModelBackend',
|
2023-10-20 14:05:59 +13:00
|
|
|
'django_auth_ldap.backend.LDAPBackend',
|
|
|
|
]
|
|
|
|
except ModuleNotFoundError:
|
|
|
|
sys.stderr.write('[X] Error: Found LDAP=True config but LDAP packages not installed. You may need to run: pip install archivebox[ldap]\n\n')
|
|
|
|
# dont hard exit here. in case the user is just running "archivebox version" or "archivebox help", we still want those to work despite broken ldap
|
|
|
|
# sys.exit(1)
|
|
|
|
|
2023-08-17 14:53:49 +12:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
### Debug Settings
|
|
|
|
################################################################################
|
|
|
|
|
2021-02-19 02:04:26 +13:00
|
|
|
# only enable debug toolbar when in DEBUG mode with --nothreading (it doesnt work in multithreaded mode)
|
|
|
|
DEBUG_TOOLBAR = DEBUG and ('--nothreading' in sys.argv) and ('--reload' not in sys.argv)
|
|
|
|
if DEBUG_TOOLBAR:
|
2021-02-17 10:23:09 +13:00
|
|
|
try:
|
2021-02-17 10:29:41 +13:00
|
|
|
import debug_toolbar # noqa
|
2021-02-17 10:23:09 +13:00
|
|
|
DEBUG_TOOLBAR = True
|
|
|
|
except ImportError:
|
2021-02-19 02:04:26 +13:00
|
|
|
DEBUG_TOOLBAR = False
|
2021-02-17 10:23:09 +13:00
|
|
|
|
2021-02-16 20:50:05 +13:00
|
|
|
if DEBUG_TOOLBAR:
|
|
|
|
INSTALLED_APPS = [*INSTALLED_APPS, 'debug_toolbar']
|
|
|
|
INTERNAL_IPS = ['0.0.0.0', '127.0.0.1', '*']
|
|
|
|
DEBUG_TOOLBAR_CONFIG = {
|
|
|
|
"SHOW_TOOLBAR_CALLBACK": lambda request: True,
|
2021-02-17 09:50:39 +13:00
|
|
|
"RENDER_PANELS": True,
|
2021-02-16 20:50:05 +13:00
|
|
|
}
|
2021-02-17 09:50:39 +13:00
|
|
|
DEBUG_TOOLBAR_PANELS = [
|
|
|
|
'debug_toolbar.panels.history.HistoryPanel',
|
|
|
|
'debug_toolbar.panels.versions.VersionsPanel',
|
|
|
|
'debug_toolbar.panels.timer.TimerPanel',
|
|
|
|
'debug_toolbar.panels.settings.SettingsPanel',
|
|
|
|
'debug_toolbar.panels.headers.HeadersPanel',
|
|
|
|
'debug_toolbar.panels.request.RequestPanel',
|
|
|
|
'debug_toolbar.panels.sql.SQLPanel',
|
|
|
|
'debug_toolbar.panels.staticfiles.StaticFilesPanel',
|
2024-01-18 02:14:43 +13:00
|
|
|
# 'debug_toolbar.panels.templates.TemplatesPanel', # buggy/slow
|
2021-02-17 09:50:39 +13:00
|
|
|
'debug_toolbar.panels.cache.CachePanel',
|
|
|
|
'debug_toolbar.panels.signals.SignalsPanel',
|
|
|
|
'debug_toolbar.panels.logging.LoggingPanel',
|
|
|
|
'debug_toolbar.panels.redirects.RedirectsPanel',
|
|
|
|
'debug_toolbar.panels.profiling.ProfilingPanel',
|
|
|
|
'djdt_flamegraph.FlamegraphPanel',
|
|
|
|
]
|
|
|
|
MIDDLEWARE = [*MIDDLEWARE, 'debug_toolbar.middleware.DebugToolbarMiddleware']
|
2019-04-03 11:53:21 +13:00
|
|
|
|
|
|
|
|
2020-10-31 20:08:03 +13:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
### External Service Settings
|
|
|
|
################################################################################
|
2019-04-03 11:53:21 +13:00
|
|
|
|
2020-10-25 15:12:39 +13:00
|
|
|
DATABASE_FILE = Path(OUTPUT_DIR) / SQL_INDEX_FILENAME
|
2021-01-21 12:42:10 +13:00
|
|
|
DATABASE_NAME = os.environ.get("ARCHIVEBOX_DATABASE_NAME", str(DATABASE_FILE))
|
2020-12-09 12:05:37 +13:00
|
|
|
|
2019-04-03 11:53:21 +13:00
|
|
|
DATABASES = {
|
|
|
|
'default': {
|
|
|
|
'ENGINE': 'django.db.backends.sqlite3',
|
2020-12-09 12:05:37 +13:00
|
|
|
'NAME': DATABASE_NAME,
|
2021-03-01 16:55:00 +13:00
|
|
|
'OPTIONS': {
|
|
|
|
'timeout': 60,
|
|
|
|
'check_same_thread': False,
|
|
|
|
},
|
2022-06-09 15:00:29 +12:00
|
|
|
'TIME_ZONE': TIMEZONE,
|
2021-02-17 00:18:39 +13:00
|
|
|
# DB setup is sometimes modified at runtime by setup_django() in config.py
|
2019-04-03 11:53:21 +13:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-18 12:25:23 +13:00
|
|
|
CACHE_BACKEND = 'django.core.cache.backends.locmem.LocMemCache'
|
|
|
|
# CACHE_BACKEND = 'django.core.cache.backends.db.DatabaseCache'
|
|
|
|
# CACHE_BACKEND = 'django.core.cache.backends.dummy.DummyCache'
|
|
|
|
|
|
|
|
CACHES = {
|
|
|
|
'default': {
|
|
|
|
'BACKEND': CACHE_BACKEND,
|
|
|
|
'LOCATION': 'django_cache_default',
|
|
|
|
}
|
|
|
|
}
|
2021-02-17 00:18:39 +13:00
|
|
|
|
2020-10-31 20:08:03 +13:00
|
|
|
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
|
|
|
|
|
2019-04-03 11:53:21 +13:00
|
|
|
|
2019-04-23 11:07:39 +12:00
|
|
|
################################################################################
|
|
|
|
### Security Settings
|
|
|
|
################################################################################
|
2020-10-31 20:08:03 +13:00
|
|
|
|
2021-02-16 14:45:42 +13:00
|
|
|
SECRET_KEY = SECRET_KEY or get_random_string(50, 'abcdefghijklmnopqrstuvwxyz0123456789_')
|
2020-10-31 20:08:03 +13:00
|
|
|
|
|
|
|
ALLOWED_HOSTS = ALLOWED_HOSTS.split(',')
|
|
|
|
|
2019-04-23 11:07:39 +12:00
|
|
|
SECURE_BROWSER_XSS_FILTER = True
|
|
|
|
SECURE_CONTENT_TYPE_NOSNIFF = True
|
2021-04-10 20:19:30 +12:00
|
|
|
SECURE_REFERRER_POLICY = 'strict-origin-when-cross-origin'
|
2020-10-31 20:08:03 +13:00
|
|
|
|
2019-04-23 11:07:39 +12:00
|
|
|
CSRF_COOKIE_SECURE = False
|
2020-10-31 20:08:03 +13:00
|
|
|
SESSION_COOKIE_SECURE = False
|
2019-04-23 11:07:39 +12:00
|
|
|
SESSION_COOKIE_DOMAIN = None
|
2020-10-31 20:08:03 +13:00
|
|
|
SESSION_COOKIE_AGE = 1209600 # 2 weeks
|
2019-04-23 11:07:39 +12:00
|
|
|
SESSION_EXPIRE_AT_BROWSER_CLOSE = False
|
|
|
|
SESSION_SAVE_EVERY_REQUEST = True
|
|
|
|
|
2021-02-17 00:18:39 +13:00
|
|
|
SESSION_ENGINE = "django.contrib.sessions.backends.db"
|
|
|
|
|
2020-10-31 20:08:03 +13:00
|
|
|
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'},
|
|
|
|
]
|
|
|
|
|
2024-01-04 16:00:07 +13:00
|
|
|
# WIP: broken by Django 3.1.2 -> 4.0 migration
|
|
|
|
DEFAULT_AUTO_FIELD = 'django.db.models.UUIDField'
|
2020-10-31 20:08:03 +13:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
### Shell Settings
|
|
|
|
################################################################################
|
2019-04-23 11:07:39 +12:00
|
|
|
|
|
|
|
SHELL_PLUS = 'ipython'
|
|
|
|
SHELL_PLUS_PRINT_SQL = False
|
|
|
|
IPYTHON_ARGUMENTS = ['--no-confirm-exit', '--no-banner']
|
|
|
|
IPYTHON_KERNEL_DISPLAY_NAME = 'ArchiveBox Django Shell'
|
|
|
|
if IS_SHELL:
|
2020-10-31 20:08:03 +13:00
|
|
|
os.environ['PYTHONSTARTUP'] = str(Path(PACKAGE_DIR) / 'core' / 'welcome_message.py')
|
2019-04-23 11:07:39 +12:00
|
|
|
|
2019-04-03 11:53:21 +13:00
|
|
|
|
2020-10-31 20:08:03 +13:00
|
|
|
################################################################################
|
|
|
|
### Internationalization & Localization Settings
|
|
|
|
################################################################################
|
|
|
|
|
2019-04-03 11:53:21 +13:00
|
|
|
LANGUAGE_CODE = 'en-us'
|
2021-04-10 20:19:30 +12:00
|
|
|
USE_I18N = True
|
|
|
|
USE_L10N = True
|
|
|
|
USE_TZ = True
|
2020-07-28 21:51:18 +12:00
|
|
|
DATETIME_FORMAT = 'Y-m-d g:iA'
|
|
|
|
SHORT_DATETIME_FORMAT = 'Y-m-d h:iA'
|
2022-06-09 15:00:29 +12:00
|
|
|
TIME_ZONE = TIMEZONE # django convention is TIME_ZONE, archivebox config uses TIMEZONE, they are equivalent
|
|
|
|
|
2021-02-16 14:51:23 +13:00
|
|
|
|
2021-04-10 20:19:30 +12:00
|
|
|
from django.conf.locale.en import formats as en_formats
|
|
|
|
|
|
|
|
en_formats.DATETIME_FORMAT = DATETIME_FORMAT
|
|
|
|
en_formats.SHORT_DATETIME_FORMAT = SHORT_DATETIME_FORMAT
|
|
|
|
|
2021-02-16 14:51:23 +13:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
### Logging Settings
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
IGNORABLE_404_URLS = [
|
|
|
|
re.compile(r'apple-touch-icon.*\.png$'),
|
|
|
|
re.compile(r'favicon\.ico$'),
|
|
|
|
re.compile(r'robots\.txt$'),
|
|
|
|
re.compile(r'.*\.(css|js)\.map$'),
|
|
|
|
]
|
|
|
|
|
|
|
|
class NoisyRequestsFilter(logging.Filter):
|
2024-01-25 23:22:23 +13:00
|
|
|
def filter(self, record) -> bool:
|
2021-02-16 14:51:23 +13:00
|
|
|
logline = record.getMessage()
|
|
|
|
|
|
|
|
# ignore harmless 404s for the patterns in IGNORABLE_404_URLS
|
|
|
|
for ignorable_url_pattern in IGNORABLE_404_URLS:
|
|
|
|
ignorable_log_pattern = re.compile(f'^"GET /.*/?{ignorable_url_pattern.pattern[:-1]} HTTP/.*" (200|30.|404) .+$', re.I | re.M)
|
|
|
|
if ignorable_log_pattern.match(logline):
|
2024-01-25 23:22:23 +13:00
|
|
|
return False
|
2021-02-16 14:51:23 +13:00
|
|
|
|
|
|
|
# ignore staticfile requests that 200 or 30*
|
|
|
|
ignoreable_200_log_pattern = re.compile(r'"GET /static/.* HTTP/.*" (200|30.) .+', re.I | re.M)
|
|
|
|
if ignoreable_200_log_pattern.match(logline):
|
2024-01-25 23:22:23 +13:00
|
|
|
return False
|
2021-02-16 14:51:23 +13:00
|
|
|
|
2024-01-25 23:22:23 +13:00
|
|
|
return True
|
2021-02-16 14:51:23 +13:00
|
|
|
|
2021-03-27 19:17:12 +13:00
|
|
|
if LOGS_DIR.exists():
|
|
|
|
ERROR_LOG = (LOGS_DIR / 'errors.log')
|
|
|
|
else:
|
2023-09-14 21:41:27 +12:00
|
|
|
# historically too many edge cases here around creating log dir w/ correct permissions early on
|
|
|
|
# if there's an issue on startup, we trash the log and let user figure it out via stdout/stderr
|
2021-03-27 19:17:12 +13:00
|
|
|
ERROR_LOG = tempfile.NamedTemporaryFile().name
|
2021-02-16 19:23:01 +13:00
|
|
|
|
2021-02-16 14:51:23 +13:00
|
|
|
LOGGING = {
|
|
|
|
'version': 1,
|
|
|
|
'disable_existing_loggers': False,
|
|
|
|
'handlers': {
|
|
|
|
'console': {
|
|
|
|
'class': 'logging.StreamHandler',
|
|
|
|
},
|
|
|
|
'logfile': {
|
|
|
|
'level': 'ERROR',
|
|
|
|
'class': 'logging.handlers.RotatingFileHandler',
|
2021-02-16 19:23:01 +13:00
|
|
|
'filename': ERROR_LOG,
|
2021-02-16 14:51:23 +13:00
|
|
|
'maxBytes': 1024 * 1024 * 25, # 25 MB
|
|
|
|
'backupCount': 10,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'filters': {
|
|
|
|
'noisyrequestsfilter': {
|
|
|
|
'()': NoisyRequestsFilter,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'loggers': {
|
|
|
|
'django': {
|
|
|
|
'handlers': ['console', 'logfile'],
|
2021-02-16 20:50:05 +13:00
|
|
|
'level': 'INFO',
|
2021-02-16 14:51:23 +13:00
|
|
|
'filters': ['noisyrequestsfilter'],
|
|
|
|
},
|
|
|
|
'django.server': {
|
|
|
|
'handlers': ['console', 'logfile'],
|
2021-02-16 20:50:05 +13:00
|
|
|
'level': 'INFO',
|
2021-02-16 14:51:23 +13:00
|
|
|
'filters': ['noisyrequestsfilter'],
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|