2011-10-07 19:47:50 +00:00
|
|
|
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*-
|
|
|
|
# vi: set ft=python sts=4 ts=4 sw=4 noet :
|
|
|
|
|
2004-10-12 21:45:41 +00:00
|
|
|
# This file is part of Fail2Ban.
|
|
|
|
#
|
|
|
|
# Fail2Ban is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Fail2Ban is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Fail2Ban; if not, write to the Free Software
|
2011-11-21 12:20:20 +00:00
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2004-10-12 21:45:41 +00:00
|
|
|
|
|
|
|
# Author: Cyril Jaquier
|
|
|
|
#
|
|
|
|
|
|
|
|
__author__ = "Cyril Jaquier"
|
|
|
|
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
|
|
|
__license__ = "GPL"
|
|
|
|
|
2006-09-25 17:03:48 +00:00
|
|
|
import logging
|
2006-06-26 20:05:00 +00:00
|
|
|
|
|
|
|
# Gets the instance of the logger.
|
|
|
|
logSys = logging.getLogger("fail2ban")
|
|
|
|
|
|
|
|
class FailData:
|
|
|
|
|
|
|
|
def __init__(self):
|
2006-09-19 20:38:32 +00:00
|
|
|
self.__retry = 0
|
|
|
|
self.__lastTime = 0
|
2009-02-09 22:08:21 +00:00
|
|
|
self.__lastReset = 0
|
2011-10-05 14:44:35 +00:00
|
|
|
self.__matches = []
|
|
|
|
|
2006-06-26 20:05:00 +00:00
|
|
|
def setRetry(self, value):
|
2006-09-19 20:38:32 +00:00
|
|
|
self.__retry = value
|
2011-10-05 14:44:35 +00:00
|
|
|
# keep only the last matches or reset entirely
|
2011-11-18 19:47:55 +00:00
|
|
|
# Explicit if/else for compatibility with Python 2.4
|
|
|
|
if value:
|
|
|
|
self.__matches = self.__matches[-min(len(self.__matches, value)):]
|
|
|
|
else:
|
|
|
|
self.__matches = []
|
2011-10-05 14:44:35 +00:00
|
|
|
|
2006-06-26 20:05:00 +00:00
|
|
|
def getRetry(self):
|
2006-09-19 20:38:32 +00:00
|
|
|
return self.__retry
|
2011-10-05 14:44:35 +00:00
|
|
|
|
|
|
|
def getMatches(self):
|
|
|
|
return self.__matches
|
|
|
|
|
|
|
|
def inc(self, matches=None):
|
2006-09-19 20:38:32 +00:00
|
|
|
self.__retry += 1
|
2011-10-05 14:44:35 +00:00
|
|
|
self.__matches += matches or []
|
|
|
|
|
2006-06-26 20:05:00 +00:00
|
|
|
def setLastTime(self, value):
|
2006-09-19 20:38:32 +00:00
|
|
|
if value > self.__lastTime:
|
|
|
|
self.__lastTime = value
|
2006-06-26 20:05:00 +00:00
|
|
|
|
|
|
|
def getLastTime(self):
|
2006-09-19 20:38:32 +00:00
|
|
|
return self.__lastTime
|
2009-02-09 22:08:21 +00:00
|
|
|
|
|
|
|
def getLastReset(self):
|
|
|
|
return self.__lastReset
|
|
|
|
|
|
|
|
def setLastReset(self, value):
|
|
|
|
self.__lastReset = value
|