From 040e47be5a98f7daa22242c02d918bf8db379f2f Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Sun, 1 Oct 2006 21:22:27 +0000 Subject: [PATCH] - Added version and usage output git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@397 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- fail2ban-regex | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/fail2ban-regex b/fail2ban-regex index 2f38d882..c8b42f8f 100755 --- a/fail2ban-regex +++ b/fail2ban-regex @@ -39,11 +39,37 @@ class Fail2banRegex: def __init__(self): self.__filter = Filter(None) + def dispVersion(self): + print "Fail2Ban v" + version + print + print "Copyright (c) 2004-2006 Cyril Jaquier" + print "Copyright of modifications held by their respective authors." + print "Licensed under the GNU General Public License v2 (GPL)." + print + print "Written by Cyril Jaquier ." + print "Many contributions by Yaroslav O. Halchenko ." + def dispUsage(self): print "Usage: "+sys.argv[0]+" " print print "Fail2Ban v" + version + " reads log file that contains password failure report" print "and bans the corresponding IP addresses using firewall rules." + print + print "This tools can test and benchmark your regular expressions for the \"failregex\"" + print "option." + print + print "Report bugs to " + + def getCmdLineOptions(self, optList): + """ Gets the command line options + """ + for opt in optList: + if opt[0] in ["-h", "--help"]: + self.dispUsage() + sys.exit(0) + elif opt[0] in ["-V", "--version"]: + self.dispVersion() + sys.exit(0) def setRegex(self, value): self.__filter.setFailRegex(value) @@ -99,6 +125,17 @@ class Fail2banRegex: if __name__ == "__main__": regex = Fail2banRegex() + # Reads the command line options. + try: + cmdOpts = 'hV' + cmdLongOpts = ['help', 'version'] + optList, args = getopt.getopt(sys.argv[1:], cmdOpts, cmdLongOpts) + except getopt.GetoptError: + regex.dispUsage() + sys.exit(-1) + # Process command line + regex.getCmdLineOptions(optList) + # We need exactly 3 parameters if len(sys.argv) <> 3: regex.dispUsage() sys.exit(-1)