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 Ticket:
|
|
|
|
|
2011-10-05 14:43:59 +00:00
|
|
|
def __init__(self, ip, time, matches=None):
|
|
|
|
"""Ticket constructor
|
|
|
|
|
|
|
|
@param ip the IP address
|
|
|
|
@param time the ban time
|
|
|
|
@param matches (log) lines caused the ticket
|
|
|
|
"""
|
|
|
|
|
2012-11-26 17:01:42 +00:00
|
|
|
self.setIP(ip)
|
2006-09-19 20:38:32 +00:00
|
|
|
self.__time = time
|
|
|
|
self.__attempt = 0
|
2011-11-18 15:39:39 +00:00
|
|
|
self.__file = None
|
2011-10-05 14:43:59 +00:00
|
|
|
self.__matches = matches or []
|
2011-10-06 21:18:28 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "%s: ip=%s time=%s #attempts=%d" % \
|
|
|
|
(self.__class__, self.__ip, self.__time, self.__attempt)
|
2006-06-26 20:05:00 +00:00
|
|
|
|
2011-10-05 14:43:59 +00:00
|
|
|
|
2006-06-26 20:05:00 +00:00
|
|
|
def setIP(self, value):
|
2012-11-26 17:01:42 +00:00
|
|
|
if isinstance(value, basestring):
|
|
|
|
# guarantee using regular str instead of unicode for the IP
|
|
|
|
value = str(value)
|
2006-09-19 20:38:32 +00:00
|
|
|
self.__ip = value
|
2006-06-26 20:05:00 +00:00
|
|
|
|
|
|
|
def getIP(self):
|
2006-09-19 20:38:32 +00:00
|
|
|
return self.__ip
|
2006-06-26 20:05:00 +00:00
|
|
|
|
2011-11-18 15:39:39 +00:00
|
|
|
def setFile(self, value):
|
|
|
|
self.__file = value
|
|
|
|
|
|
|
|
def getFile(self):
|
|
|
|
return self.__file
|
|
|
|
|
2006-06-26 20:05:00 +00:00
|
|
|
def setTime(self, value):
|
2006-09-19 20:38:32 +00:00
|
|
|
self.__time = value
|
2006-06-26 20:05:00 +00:00
|
|
|
|
|
|
|
def getTime(self):
|
2006-09-19 20:38:32 +00:00
|
|
|
return self.__time
|
2006-08-06 21:25:23 +00:00
|
|
|
|
|
|
|
def setAttempt(self, value):
|
2006-09-19 20:38:32 +00:00
|
|
|
self.__attempt = value
|
2006-08-06 21:25:23 +00:00
|
|
|
|
|
|
|
def getAttempt(self):
|
2006-09-19 20:38:32 +00:00
|
|
|
return self.__attempt
|
2007-12-17 20:00:36 +00:00
|
|
|
|
2011-10-05 14:43:59 +00:00
|
|
|
def getMatches(self):
|
|
|
|
return self.__matches
|
|
|
|
|
2007-12-17 20:00:36 +00:00
|
|
|
|
|
|
|
class FailTicket(Ticket):
|
2011-10-05 14:43:59 +00:00
|
|
|
pass
|
2007-12-17 20:00:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
# Ban Ticket.
|
|
|
|
#
|
|
|
|
# This class extends the Ticket class. It is mainly used by the BanManager.
|
|
|
|
|
|
|
|
class BanTicket(Ticket):
|
2011-10-05 14:43:59 +00:00
|
|
|
pass
|