mirror of https://github.com/fail2ban/fail2ban
ENH+BF: filtergamin -- to be more inline with current design of filterinotify
parent
337f3f6f7b
commit
c6f5d854d3
|
@ -17,14 +17,10 @@
|
||||||
# along with Fail2Ban; if not, write to the Free Software
|
# along with Fail2Ban; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
# Author: Cyril Jaquier
|
# Author: Cyril Jaquier, Yaroslav Halchenko
|
||||||
#
|
|
||||||
# $Revision$
|
|
||||||
|
|
||||||
__author__ = "Cyril Jaquier"
|
__author__ = "Cyril Jaquier, Yaroslav Halchenko"
|
||||||
__version__ = "$Revision$"
|
__copyright__ = "Copyright (c) 2004 Cyril Jaquier, 2012 Yaroslav Halchenko"
|
||||||
__date__ = "$Date$"
|
|
||||||
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
|
||||||
__license__ = "GPL"
|
__license__ = "GPL"
|
||||||
|
|
||||||
from failmanager import FailManagerEmpty
|
from failmanager import FailManagerEmpty
|
||||||
|
@ -50,7 +46,7 @@ class FilterGamin(FileFilter):
|
||||||
#
|
#
|
||||||
# Initialize the filter object with default values.
|
# Initialize the filter object with default values.
|
||||||
# @param jail the jail object
|
# @param jail the jail object
|
||||||
|
|
||||||
def __init__(self, jail):
|
def __init__(self, jail):
|
||||||
FileFilter.__init__(self, jail)
|
FileFilter.__init__(self, jail)
|
||||||
self.__modified = False
|
self.__modified = False
|
||||||
|
@ -63,9 +59,26 @@ class FilterGamin(FileFilter):
|
||||||
logSys.debug("Got event: " + `event` + " for " + path)
|
logSys.debug("Got event: " + `event` + " for " + path)
|
||||||
if event in (gamin.GAMCreated, gamin.GAMChanged, gamin.GAMExists):
|
if event in (gamin.GAMCreated, gamin.GAMChanged, gamin.GAMExists):
|
||||||
logSys.debug("File changed: " + path)
|
logSys.debug("File changed: " + path)
|
||||||
self.getFailures(path)
|
|
||||||
self.__modified = True
|
self.__modified = True
|
||||||
|
|
||||||
|
self._process_file(path)
|
||||||
|
|
||||||
|
|
||||||
|
def _process_file(self, path):
|
||||||
|
"""Process a given file
|
||||||
|
|
||||||
|
TODO -- RF:
|
||||||
|
this is a common logic and must be shared/provided by FileFilter
|
||||||
|
"""
|
||||||
|
self.getFailures(path)
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
ticket = self.failManager.toBan()
|
||||||
|
self.jail.putFailTicket(ticket)
|
||||||
|
except FailManagerEmpty:
|
||||||
|
self.failManager.cleanup(MyTime.time())
|
||||||
|
self.dateDetector.sortTemplate()
|
||||||
|
self.__modified = False
|
||||||
|
|
||||||
##
|
##
|
||||||
# Add a log file path
|
# Add a log file path
|
||||||
|
@ -80,7 +93,7 @@ class FilterGamin(FileFilter):
|
||||||
#
|
#
|
||||||
# @param path the log file to delete
|
# @param path the log file to delete
|
||||||
|
|
||||||
def delLogPath(self, path):
|
def _delLogPath(self, path):
|
||||||
self.monitor.stop_watch(path)
|
self.monitor.stop_watch(path)
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -92,30 +105,22 @@ class FilterGamin(FileFilter):
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.setActive(True)
|
self.setActive(True)
|
||||||
|
# Gamin needs a loop to collect and dispatch events
|
||||||
while self._isActive():
|
while self._isActive():
|
||||||
if not self.getIdle():
|
if not self.getIdle():
|
||||||
# We cannot block here because we want to be able to
|
# We cannot block here because we want to be able to
|
||||||
# exit.
|
# exit.
|
||||||
if self.monitor.event_pending():
|
if self.monitor.event_pending():
|
||||||
self.monitor.handle_events()
|
self.monitor.handle_events()
|
||||||
|
time.sleep(self.getSleepTime())
|
||||||
if self.__modified:
|
|
||||||
try:
|
|
||||||
while True:
|
|
||||||
ticket = self.failManager.toBan()
|
|
||||||
self.jail.putFailTicket(ticket)
|
|
||||||
except FailManagerEmpty:
|
|
||||||
self.failManager.cleanup(MyTime.time())
|
|
||||||
self.dateDetector.sortTemplate()
|
|
||||||
self.__modified = False
|
|
||||||
time.sleep(self.getSleepTime())
|
|
||||||
else:
|
|
||||||
time.sleep(self.getSleepTime())
|
|
||||||
# Cleanup Gamin
|
|
||||||
self.__cleanup()
|
|
||||||
logSys.debug(self.jail.getName() + ": filter terminated")
|
logSys.debug(self.jail.getName() + ": filter terminated")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
super(FilterGamin, self).stop()
|
||||||
|
self.__cleanup()
|
||||||
|
|
||||||
##
|
##
|
||||||
# Desallocates the resources used by Gamin.
|
# Desallocates the resources used by Gamin.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue