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 :
|
|
|
|
|
2006-06-26 20:05:00 +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.
|
2006-06-26 20:05:00 +00:00
|
|
|
|
|
|
|
# Author: Cyril Jaquier
|
|
|
|
#
|
|
|
|
|
|
|
|
__author__ = "Cyril Jaquier"
|
|
|
|
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
|
|
|
__license__ = "GPL"
|
|
|
|
|
|
|
|
from threading import Thread
|
2006-09-25 17:03:48 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
# Gets the instance of the logger.
|
|
|
|
logSys = logging.getLogger("fail2ban.server")
|
2006-06-26 20:05:00 +00:00
|
|
|
|
|
|
|
class JailThread(Thread):
|
|
|
|
|
|
|
|
##
|
|
|
|
# Constructor.
|
|
|
|
#
|
|
|
|
# Initialize the filter object with default values.
|
|
|
|
# @param jail the jail object
|
|
|
|
|
2006-10-24 19:40:51 +00:00
|
|
|
def __init__(self):
|
2006-06-26 20:05:00 +00:00
|
|
|
Thread.__init__(self)
|
|
|
|
## Control the state of the thread.
|
2006-09-19 20:38:32 +00:00
|
|
|
self.__isRunning = False
|
2006-06-26 20:05:00 +00:00
|
|
|
## Control the idle state of the thread.
|
2006-09-19 20:38:32 +00:00
|
|
|
self.__isIdle = False
|
2006-06-26 20:05:00 +00:00
|
|
|
## The time the thread sleeps in the loop.
|
2006-09-19 20:38:32 +00:00
|
|
|
self.__sleepTime = 1
|
2006-06-26 20:05:00 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
# Set the time that the thread sleeps.
|
|
|
|
#
|
|
|
|
# This value could also be called "polling time". A value of 1 is a
|
|
|
|
# good one. This unit is "second"
|
|
|
|
# @param value the polling time (second)
|
|
|
|
|
|
|
|
def setSleepTime(self, value):
|
2006-09-19 20:38:32 +00:00
|
|
|
self.__sleepTime = value
|
2013-07-02 21:11:24 +00:00
|
|
|
logSys.info("Set sleeptime %s" % value)
|
2006-06-26 20:05:00 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
# Get the time that the thread sleeps.
|
|
|
|
#
|
|
|
|
# @return the polling time
|
|
|
|
|
|
|
|
def getSleepTime(self):
|
2006-09-19 20:38:32 +00:00
|
|
|
return self.__sleepTime
|
2006-06-26 20:05:00 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
# Set the idle flag.
|
|
|
|
#
|
|
|
|
# This flag stops the check of the log file.
|
|
|
|
# @param value boolean value
|
|
|
|
|
|
|
|
def setIdle(self, value):
|
2006-09-19 20:38:32 +00:00
|
|
|
self.__isIdle = value
|
2006-06-26 20:05:00 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
# Get the idle state.
|
|
|
|
#
|
|
|
|
# @return the idle state
|
|
|
|
|
|
|
|
def getIdle(self):
|
2006-09-19 20:38:32 +00:00
|
|
|
return self.__isIdle
|
2006-06-26 20:05:00 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
# Stop the thread.
|
|
|
|
#
|
|
|
|
# Stop the exection of the thread and quit.
|
|
|
|
|
|
|
|
def stop(self):
|
2006-09-19 20:38:32 +00:00
|
|
|
self.__isRunning = False
|
2006-06-26 20:05:00 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
# Set the isRunning flag.
|
|
|
|
#
|
|
|
|
# @param value True if the thread is running
|
|
|
|
|
|
|
|
def setActive(self, value):
|
2006-09-19 20:38:32 +00:00
|
|
|
self.__isRunning = value
|
2006-06-26 20:05:00 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
# Check if the thread is active.
|
|
|
|
#
|
|
|
|
# Check if the filter thread is running.
|
|
|
|
# @return True if the thread is running
|
|
|
|
|
2007-03-26 21:17:31 +00:00
|
|
|
def _isActive(self):
|
2006-09-19 20:38:32 +00:00
|
|
|
return self.__isRunning
|
2006-06-26 20:05:00 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
# Get the status of the thread
|
|
|
|
#
|
|
|
|
# Get some informations about the thread. This is an abstract method.
|
|
|
|
# @return a list with tuple
|
|
|
|
|
|
|
|
def status(self):
|
2006-09-19 20:38:32 +00:00
|
|
|
pass
|