2008-11-05 22:52:40 +00:00
|
|
|
from django.db import models
|
2014-03-05 09:43:05 +00:00
|
|
|
from django.utils import six
|
2008-11-05 22:52:40 +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(
|
|
|
|
|
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(
|
2013-04-05 00:19:52 +00:00
|
|
|
verbose_name='IP Address',
|
|
|
|
|
null=True,
|
2015-12-17 21:50:29 +00:00
|
|
|
db_index=True,
|
2013-04-05 00:19:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
username = models.CharField(
|
|
|
|
|
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
|
|
|
|
|
|
|
|
# Once a user logs in from an ip, that combination is trusted and not
|
|
|
|
|
# locked out in case of a distributed attack
|
2013-04-05 00:19:52 +00:00
|
|
|
trusted = models.BooleanField(
|
|
|
|
|
default=False,
|
2015-12-17 21:50:29 +00:00
|
|
|
db_index=True,
|
2013-04-05 00:19:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
http_accept = models.CharField(
|
|
|
|
|
verbose_name='HTTP Accept',
|
|
|
|
|
max_length=1025,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
path_info = models.CharField(
|
|
|
|
|
verbose_name='Path',
|
|
|
|
|
max_length=255,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
attempt_time = models.DateTimeField(
|
|
|
|
|
auto_now_add=True,
|
|
|
|
|
)
|
2008-11-05 22:52:40 +00:00
|
|
|
|
2012-11-25 20:46:45 +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(
|
|
|
|
|
verbose_name='GET Data',
|
|
|
|
|
)
|
2012-11-25 20:46:45 +00:00
|
|
|
|
2013-04-05 00:19:52 +00:00
|
|
|
post_data = models.TextField(
|
|
|
|
|
verbose_name='POST Data',
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
failures_since_start = models.PositiveIntegerField(
|
|
|
|
|
verbose_name='Failed Logins',
|
|
|
|
|
)
|
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
|
|
|
|
|
|
2013-04-05 00:19:52 +00:00
|
|
|
def __unicode__(self):
|
2014-03-02 10:20:21 +00:00
|
|
|
return six.u('Attempted Access: %s') % self.attempt_time
|
2013-04-05 00:19:52 +00:00
|
|
|
|
|
|
|
|
|
2012-11-25 20:46:45 +00:00
|
|
|
class AccessLog(CommonAccess):
|
2013-04-05 00:19:52 +00:00
|
|
|
logout_time = models.DateTimeField(
|
|
|
|
|
null=True,
|
|
|
|
|
blank=True,
|
|
|
|
|
)
|
2012-11-25 20:46:45 +00:00
|
|
|
|
|
|
|
|
def __unicode__(self):
|
2014-03-02 10:20:21 +00:00
|
|
|
return six.u('Access Log for %s @ %s') % (self.username, self.attempt_time)
|