mirror of https://github.com/fail2ban/fail2ban
- Added "fail2ban-regex". This is a tool to help finding "failregex"
git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@329 a942ae1a-1317-0410-a47c-b1dcaea8d6050.x
parent
90d46d177d
commit
a998e54bb9
|
@ -18,6 +18,8 @@ ver. 0.7.2 (2006/??/??) - ???
|
|||
- Added interactive mode. Use "-i"
|
||||
- Added a date detector. "timeregex" and "timepattern" are no
|
||||
more needed
|
||||
- Added "fail2ban-regex". This is a tool to help finding
|
||||
"failregex"
|
||||
|
||||
ver. 0.7.1 (2006/08/23) - alpha
|
||||
----------
|
||||
|
|
1
MANIFEST
1
MANIFEST
|
@ -4,6 +4,7 @@ TODO
|
|||
fail2ban-client
|
||||
fail2ban-server
|
||||
fail2ban-testcases
|
||||
fail2ban-regex
|
||||
client/beautifier.py
|
||||
client/configreader.py
|
||||
client/jailreader.py
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
#!/usr/bin/env python
|
||||
# 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
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
# Author: Cyril Jaquier
|
||||
#
|
||||
# $Revision: 300 $
|
||||
|
||||
__author__ = "Cyril Jaquier"
|
||||
__version__ = "$Revision: 300 $"
|
||||
__date__ = "$Date: 2006-08-23 21:53:09 +0200 (Wed, 23 Aug 2006) $"
|
||||
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
||||
__license__ = "GPL"
|
||||
|
||||
import locale, getopt, sys, time
|
||||
|
||||
# Inserts our own modules path first in the list
|
||||
# fix for bug #343821
|
||||
sys.path.insert(1, "/usr/lib/fail2ban")
|
||||
|
||||
from version import version
|
||||
from server.filter import Filter
|
||||
|
||||
class Fail2banRegex:
|
||||
|
||||
def __init__(self):
|
||||
self.filter = Filter(None)
|
||||
|
||||
def dispUsage(self):
|
||||
print "Usage: "+sys.argv[0]+" <logline> <failregex>"
|
||||
print
|
||||
print "Fail2Ban v" + version + " reads log file that contains password failure report"
|
||||
print "and bans the corresponding IP addresses using firewall rules."
|
||||
|
||||
def setRegex(self, value):
|
||||
self.filter.setFailRegex(value)
|
||||
|
||||
def testRegex(self, line):
|
||||
print
|
||||
try:
|
||||
ret = self.filter.findFailure(line)
|
||||
except IndexError:
|
||||
print "Sorry, but no <host> found in regex"
|
||||
return False
|
||||
if len(ret) == 0:
|
||||
print "Sorry, no match"
|
||||
return False
|
||||
else:
|
||||
print "Success, the following data were found:"
|
||||
timeTuple = time.localtime(ret[0][1])
|
||||
print "Date: " + time.strftime("%a %b %d %H:%M:%S %Y", timeTuple)
|
||||
ipList = ""
|
||||
for i in ret:
|
||||
ipList = ipList + " " + i[0]
|
||||
print "IP :" + ipList
|
||||
return True
|
||||
|
||||
if __name__ == "__main__":
|
||||
regex = Fail2banRegex()
|
||||
if len(sys.argv) <> 3:
|
||||
regex.dispUsage()
|
||||
sys.exit(-1)
|
||||
else:
|
||||
regex.setRegex(sys.argv[2])
|
||||
ret = regex.testRegex(sys.argv[1])
|
||||
if ret:
|
||||
sys.exit(0)
|
||||
else:
|
||||
sys.exit(-1)
|
Loading…
Reference in New Issue