mirror of https://github.com/fail2ban/fail2ban
ENH: fail2ban-iptables -- modeline + use of max()
parent
6a1bf30cf5
commit
7e16abdb08
|
@ -1,4 +1,7 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
|
||||||
|
# vi: set ft=python sts=4 ts=4 sw=4 et :
|
||||||
|
#
|
||||||
# This file is part of Fail2Ban.
|
# This file is part of Fail2Ban.
|
||||||
#
|
#
|
||||||
# Fail2Ban is free software; you can redistribute it and/or modify
|
# Fail2Ban is free software; you can redistribute it and/or modify
|
||||||
|
@ -29,17 +32,17 @@ def main(argv):
|
||||||
pline = " ".join(argv)
|
pline = " ".join(argv)
|
||||||
regv4 = re.compile('([0-9]{1,3}\.){3}[0-9]{1,3}')
|
regv4 = re.compile('([0-9]{1,3}\.){3}[0-9]{1,3}')
|
||||||
if regv4.search(pline):
|
if regv4.search(pline):
|
||||||
# we are facing to a ipv4
|
# we are facing to an ipv4
|
||||||
ret = subprocess.call([IPTABLES] + argv)
|
ret = subprocess.call([IPTABLES] + argv)
|
||||||
sys.exit(ret)
|
sys.exit(ret)
|
||||||
else:
|
else:
|
||||||
# if not, maybe it's a ipv6
|
# if not, maybe it's an ipv6
|
||||||
regv6 = re.compile('::[A-Fa-f0-9]{1,4}|(:[A-Fa-f0-9]{1,4}){2,}')
|
regv6 = re.compile('::[A-Fa-f0-9]{1,4}|(:[A-Fa-f0-9]{1,4}){2,}')
|
||||||
if regv6.search(pline):
|
if regv6.search(pline):
|
||||||
ret6 = subprocess.call([IP6TABLES] + argv)
|
ret6 = subprocess.call([IP6TABLES] + argv)
|
||||||
sys.exit(ret6)
|
sys.exit(ret6)
|
||||||
else:
|
else:
|
||||||
# if it's not a ipv6 either, we call both iptables
|
# if it's not an ipv6 either, we call both iptables
|
||||||
proc = subprocess.Popen([IPTABLES] + argv)
|
proc = subprocess.Popen([IPTABLES] + argv)
|
||||||
proc6 = subprocess.Popen([IP6TABLES] + argv)
|
proc6 = subprocess.Popen([IP6TABLES] + argv)
|
||||||
|
|
||||||
|
@ -49,10 +52,7 @@ def main(argv):
|
||||||
ret6 = proc6.wait()
|
ret6 = proc6.wait()
|
||||||
|
|
||||||
# return worst error code
|
# return worst error code
|
||||||
if ret > ret6:
|
sys.exit(max(ret, ret6))
|
||||||
sys.exit(ret)
|
|
||||||
else:
|
|
||||||
sys.exit(ret6)
|
|
||||||
|
|
||||||
# Main call, pass all variables
|
# Main call, pass all variables
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue