mirror of https://github.com/fail2ban/fail2ban
BF: Require Python 2.7+ for badips.py action
parent
5c7630c4be
commit
dfb46cfda6
|
@ -17,11 +17,13 @@
|
||||||
# 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.
|
||||||
|
|
||||||
|
import sys
|
||||||
|
if sys.version_info < (2, 7):
|
||||||
|
raise ImportError("badips.py action requires Python >= 2.7")
|
||||||
import json
|
import json
|
||||||
from functools import partial
|
from functools import partial
|
||||||
import threading
|
import threading
|
||||||
import logging
|
import logging
|
||||||
import sys
|
|
||||||
if sys.version_info >= (3, ):
|
if sys.version_info >= (3, ):
|
||||||
from urllib.request import Request, urlopen
|
from urllib.request import Request, urlopen
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
|
|
|
@ -31,7 +31,11 @@ if sys.version_info >= (3, 3):
|
||||||
import importlib.machinery
|
import importlib.machinery
|
||||||
else:
|
else:
|
||||||
import imp
|
import imp
|
||||||
from collections import Mapping, OrderedDict
|
from collections import Mapping
|
||||||
|
try:
|
||||||
|
from collections import OrderedDict
|
||||||
|
except ImportError:
|
||||||
|
OrderedDict = None
|
||||||
|
|
||||||
from .banmanager import BanManager
|
from .banmanager import BanManager
|
||||||
from .jailthread import JailThread
|
from .jailthread import JailThread
|
||||||
|
@ -62,7 +66,10 @@ class Actions(JailThread, Mapping):
|
||||||
JailThread.__init__(self)
|
JailThread.__init__(self)
|
||||||
## The jail which contains this action.
|
## The jail which contains this action.
|
||||||
self._jail = jail
|
self._jail = jail
|
||||||
|
if OrderedDict is not None:
|
||||||
self._actions = OrderedDict()
|
self._actions = OrderedDict()
|
||||||
|
else:
|
||||||
|
self._actions = dict()
|
||||||
## The ban manager.
|
## The ban manager.
|
||||||
self.__banManager = BanManager()
|
self.__banManager = BanManager()
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ if os.path.exists('config/fail2ban.conf'):
|
||||||
else:
|
else:
|
||||||
CONFIG_DIR='/etc/fail2ban'
|
CONFIG_DIR='/etc/fail2ban'
|
||||||
|
|
||||||
|
if sys.version_info >= (2,7):
|
||||||
class BadIPsActionTest(unittest.TestCase):
|
class BadIPsActionTest(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -59,7 +60,8 @@ class BadIPsActionTest(unittest.TestCase):
|
||||||
self.assertTrue(len(categories) >= 10)
|
self.assertTrue(len(categories) >= 10)
|
||||||
|
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
ValueError, setattr, self.action, "category", "invalid-category")
|
ValueError, setattr, self.action, "category",
|
||||||
|
"invalid-category")
|
||||||
|
|
||||||
# Not valid for reporting category...
|
# Not valid for reporting category...
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
|
@ -74,7 +76,8 @@ class BadIPsActionTest(unittest.TestCase):
|
||||||
|
|
||||||
def testBanaction(self):
|
def testBanaction(self):
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
ValueError, setattr, self.action, "banaction", "invalid-action")
|
ValueError, setattr, self.action, "banaction",
|
||||||
|
"invalid-action")
|
||||||
self.action.banaction = "test"
|
self.action.banaction = "test"
|
||||||
|
|
||||||
def testUpdateperiod(self):
|
def testUpdateperiod(self):
|
||||||
|
|
Loading…
Reference in New Issue