2018-04-18 12:21:09 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
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
|
|
|
|
2012-11-25 20:46:45 +00:00
|
|
|
class CommonAccess(models.Model):
|
2013-04-05 00:19:52 +00:00
|
|
|
user_agent = models.CharField(
|
2018-07-17 13:20:45 +00:00
|
|
|
_('User Agent'),
|
2013-04-05 00:19:52 +00:00
|
|
|
max_length=255,
|
2015-12-17 21:50:29 +00:00
|
|
|
db_index=True,
|
2013-04-05 00:19:52 +00:00
|
|
|
)
|
|
|
|
|
|
2014-07-31 16:57:33 +00:00
|
|
|
ip_address = models.GenericIPAddressField(
|
2018-07-17 13:20:45 +00:00
|
|
|
_('IP Address'),
|
2013-04-05 00:19:52 +00:00
|
|
|
null=True,
|
2015-12-17 21:50:29 +00:00
|
|
|
db_index=True,
|
2013-04-05 00:19:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
username = models.CharField(
|
2018-07-17 13:20:45 +00:00
|
|
|
_('Username'),
|
2013-04-05 00:19:52 +00:00
|
|
|
max_length=255,
|
|
|
|
|
null=True,
|
2015-12-17 21:50:29 +00:00
|
|
|
db_index=True,
|
2013-04-05 00:19:52 +00:00
|
|
|
)
|
2012-08-26 06:36:52 +00:00
|
|
|
|
2013-04-05 00:19:52 +00:00
|
|
|
http_accept = models.CharField(
|
2018-07-17 13:20:45 +00:00
|
|
|
_('HTTP Accept'),
|
2013-04-05 00:19:52 +00:00
|
|
|
max_length=1025,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
path_info = models.CharField(
|
2018-07-17 13:20:45 +00:00
|
|
|
_('Path'),
|
2013-04-05 00:19:52 +00:00
|
|
|
max_length=255,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
attempt_time = models.DateTimeField(
|
2018-07-17 13:20:45 +00:00
|
|
|
_('Attempt Time'),
|
2013-04-05 00:19:52 +00:00
|
|
|
auto_now_add=True,
|
|
|
|
|
)
|
2008-11-05 22:52:40 +00:00
|
|
|
|
2018-12-08 13:38:00 +00:00
|
|
|
class Meta:
|
2016-05-23 13:02:33 +00:00
|
|
|
app_label = 'axes'
|
2012-11-25 20:46:45 +00:00
|
|
|
abstract = True
|
|
|
|
|
ordering = ['-attempt_time']
|
|
|
|
|
|
2013-04-05 00:19:52 +00:00
|
|
|
|
2012-11-25 20:46:45 +00:00
|
|
|
class AccessAttempt(CommonAccess):
|
2013-04-05 00:19:52 +00:00
|
|
|
get_data = models.TextField(
|
2018-07-17 13:20:45 +00:00
|
|
|
_('GET Data'),
|
2013-04-05 00:19:52 +00:00
|
|
|
)
|
2012-11-25 20:46:45 +00:00
|
|
|
|
2013-04-05 00:19:52 +00:00
|
|
|
post_data = models.TextField(
|
2018-07-17 13:20:45 +00:00
|
|
|
_('POST Data'),
|
2013-04-05 00:19:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
failures_since_start = models.PositiveIntegerField(
|
2018-07-17 13:20:45 +00:00
|
|
|
_('Failed Logins'),
|
2013-04-05 00:19:52 +00:00
|
|
|
)
|
2008-11-05 22:52:40 +00:00
|
|
|
|
2011-03-16 15:13:06 +00:00
|
|
|
@property
|
2008-11-05 22:52:40 +00:00
|
|
|
def failures(self):
|
|
|
|
|
return self.failures_since_start
|
|
|
|
|
|
2017-07-20 14:06:41 +00:00
|
|
|
def __str__(self):
|
|
|
|
|
return 'Attempted Access: %s' % self.attempt_time
|
2013-04-05 00:19:52 +00:00
|
|
|
|
2018-12-08 13:38:00 +00:00
|
|
|
class Meta:
|
2018-07-17 13:41:06 +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
|
|
|
|
2012-11-25 20:46:45 +00:00
|
|
|
class AccessLog(CommonAccess):
|
2018-12-23 15:04:56 +00:00
|
|
|
# Once a user logs in from an ip, that combination is trusted and not
|
|
|
|
|
# locked out in case of a distributed attack
|
|
|
|
|
trusted = models.BooleanField(
|
|
|
|
|
default=False,
|
|
|
|
|
db_index=True,
|
|
|
|
|
)
|
|
|
|
|
|
2013-04-05 00:19:52 +00:00
|
|
|
logout_time = models.DateTimeField(
|
2018-07-17 13:20:45 +00:00
|
|
|
_('Logout Time'),
|
2013-04-05 00:19:52 +00:00
|
|
|
null=True,
|
|
|
|
|
blank=True,
|
|
|
|
|
)
|
2012-11-25 20:46:45 +00:00
|
|
|
|
2017-07-20 14:06:41 +00:00
|
|
|
def __str__(self):
|
|
|
|
|
return 'Access Log for %s @ %s' % (self.username, self.attempt_time)
|
2018-07-17 13:41:06 +00:00
|
|
|
|
2018-12-08 13:38:00 +00:00
|
|
|
class Meta:
|
2018-07-17 13:41:06 +00:00
|
|
|
verbose_name = _('access log')
|
|
|
|
|
verbose_name_plural = _('access logs')
|