2019-02-13 12:05:24 +00:00
|
|
|
from logging import getLogger
|
2019-02-10 18:51:07 +00:00
|
|
|
|
2016-06-24 16:31:01 +00:00
|
|
|
from django import apps
|
2021-01-07 12:05:48 +00:00
|
|
|
from pkg_resources import get_distribution
|
2016-06-24 16:31:01 +00:00
|
|
|
|
2020-09-26 14:50:13 +00:00
|
|
|
log = getLogger(__name__)
|
2019-02-10 18:51:07 +00:00
|
|
|
|
2016-06-24 16:31:01 +00:00
|
|
|
|
|
|
|
|
class AppConfig(apps.AppConfig):
|
2019-09-28 16:27:50 +00:00
|
|
|
name = "axes"
|
2020-09-26 14:50:13 +00:00
|
|
|
initialized = False
|
2019-02-10 18:51:07 +00:00
|
|
|
|
|
|
|
|
@classmethod
|
2019-02-16 16:33:07 +00:00
|
|
|
def initialize(cls):
|
2019-02-10 18:51:07 +00:00
|
|
|
"""
|
|
|
|
|
Initialize Axes logging and show version information.
|
|
|
|
|
|
|
|
|
|
This method is re-entrant and can be called multiple times.
|
|
|
|
|
It displays version information exactly once at application startup.
|
|
|
|
|
"""
|
|
|
|
|
|
2020-09-26 14:50:13 +00:00
|
|
|
if cls.initialized:
|
2019-05-08 11:01:06 +00:00
|
|
|
return
|
2020-09-26 14:50:13 +00:00
|
|
|
cls.initialized = True
|
2020-09-27 13:40:01 +00:00
|
|
|
|
2020-09-27 13:01:56 +00:00
|
|
|
# Only import settings, checks, and signals one time after Django has been initialized
|
2020-09-27 13:38:14 +00:00
|
|
|
from axes.conf import settings # noqa
|
2020-09-27 13:01:56 +00:00
|
|
|
from axes import checks, signals # noqa
|
2019-05-08 11:01:06 +00:00
|
|
|
|
2020-09-27 13:21:31 +00:00
|
|
|
# Skip startup log messages if Axes is not set to verbose
|
|
|
|
|
if settings.AXES_VERBOSE:
|
|
|
|
|
log.info("AXES: BEGIN LOG")
|
|
|
|
|
log.info(
|
|
|
|
|
"AXES: Using django-axes version %s",
|
|
|
|
|
get_distribution("django-axes").version,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if settings.AXES_ONLY_USER_FAILURES:
|
|
|
|
|
log.info("AXES: blocking by username only.")
|
|
|
|
|
elif settings.AXES_LOCK_OUT_BY_COMBINATION_USER_AND_IP:
|
|
|
|
|
log.info("AXES: blocking by combination of username and IP.")
|
|
|
|
|
elif settings.AXES_LOCK_OUT_BY_USER_OR_IP:
|
|
|
|
|
log.info("AXES: blocking by username or IP.")
|
|
|
|
|
else:
|
|
|
|
|
log.info("AXES: blocking by IP only.")
|
2016-06-24 16:31:01 +00:00
|
|
|
|
|
|
|
|
def ready(self):
|
2019-02-16 16:33:07 +00:00
|
|
|
self.initialize()
|