2008-11-05 22:52:40 +00:00
|
|
|
from django.db import models
|
2018-07-17 13:14:17 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2008-11-05 22:52:40 +00:00
|
|
|
|
2016-06-24 14:42:18 +00:00
|
|
|
|
2019-02-12 21:11:13 +00:00
|
|
|
class AccessBase(models.Model):
|
2019-09-28 16:27:50 +00:00
|
|
|
user_agent = models.CharField(_("User Agent"), max_length=255, db_index=True)
|
|
|
|
|
|
|
|
|
|
ip_address = models.GenericIPAddressField(_("IP Address"), null=True, db_index=True)
|
|
|
|
|
|
|
|
|
|
username = models.CharField(_("Username"), max_length=255, null=True, db_index=True)
|
|
|
|
|
|
|
|
|
|
http_accept = models.CharField(_("HTTP Accept"), max_length=1025)
|
|
|
|
|
|
|
|
|
|
path_info = models.CharField(_("Path"), max_length=255)
|
|
|
|
|
|
|
|
|
|
attempt_time = models.DateTimeField(_("Attempt Time"), auto_now_add=True)
|
2008-11-05 22:52:40 +00:00
|
|
|
|
2018-12-08 13:38:00 +00:00
|
|
|
class Meta:
|
2019-09-28 16:27:50 +00:00
|
|
|
app_label = "axes"
|
2012-11-25 20:46:45 +00:00
|
|
|
abstract = True
|
2019-09-28 16:27:50 +00:00
|
|
|
ordering = ["-attempt_time"]
|
2012-11-25 20:46:45 +00:00
|
|
|
|
2013-04-05 00:19:52 +00:00
|
|
|
|
2019-02-12 21:11:13 +00:00
|
|
|
class AccessAttempt(AccessBase):
|
2019-09-28 16:27:50 +00:00
|
|
|
get_data = models.TextField(_("GET Data"))
|
2012-11-25 20:46:45 +00:00
|
|
|
|
2019-09-28 16:27:50 +00:00
|
|
|
post_data = models.TextField(_("POST Data"))
|
2013-04-05 00:19:52 +00:00
|
|
|
|
2019-09-28 16:27:50 +00:00
|
|
|
failures_since_start = models.PositiveIntegerField(_("Failed Logins"))
|
2008-11-05 22:52:40 +00:00
|
|
|
|
2017-07-20 14:06:41 +00:00
|
|
|
def __str__(self):
|
2019-09-28 16:27:50 +00:00
|
|
|
return f"Attempted Access: {self.attempt_time}"
|
2013-04-05 00:19:52 +00:00
|
|
|
|
2018-12-08 13:38:00 +00:00
|
|
|
class Meta:
|
2019-09-28 16:27:50 +00:00
|
|
|
verbose_name = _("access attempt")
|
|
|
|
|
verbose_name_plural = _("access attempts")
|
2013-04-05 00:19:52 +00:00
|
|
|
|
2018-10-26 12:45:06 +00:00
|
|
|
|
2019-02-12 21:11:13 +00:00
|
|
|
class AccessLog(AccessBase):
|
2019-09-28 16:27:50 +00:00
|
|
|
logout_time = models.DateTimeField(_("Logout Time"), null=True, blank=True)
|
2012-11-25 20:46:45 +00:00
|
|
|
|
2017-07-20 14:06:41 +00:00
|
|
|
def __str__(self):
|
2019-09-28 16:27:50 +00:00
|
|
|
return f"Access Log for {self.username} @ {self.attempt_time}"
|
2018-07-17 13:41:06 +00:00
|
|
|
|
2018-12-08 13:38:00 +00:00
|
|
|
class Meta:
|
2019-09-28 16:27:50 +00:00
|
|
|
verbose_name = _("access log")
|
|
|
|
|
verbose_name_plural = _("access logs")
|