mirror of https://github.com/fail2ban/fail2ban
badip timeout option introduced, set to 30 seconds in our test cases (#1463)
cherry-picked from 0.10 (little bit modified in test_badips.py, because no --fast option in test cases)pull/1461/head^2
parent
11f7cf5ad8
commit
af8b650a37
|
@ -80,14 +80,17 @@ class BadIPsAction(ActionBase):
|
||||||
If invalid `category`, `score`, `banaction` or `updateperiod`.
|
If invalid `category`, `score`, `banaction` or `updateperiod`.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
TIMEOUT = 10
|
||||||
_badips = "http://www.badips.com"
|
_badips = "http://www.badips.com"
|
||||||
def _Request(self, url, **argv):
|
def _Request(self, url, **argv):
|
||||||
return Request(url, headers={'User-Agent': self.agent}, **argv)
|
return Request(url, headers={'User-Agent': self.agent}, **argv)
|
||||||
|
|
||||||
def __init__(self, jail, name, category, score=3, age="24h", key=None,
|
def __init__(self, jail, name, category, score=3, age="24h", key=None,
|
||||||
banaction=None, bancategory=None, bankey=None, updateperiod=900, agent="Fail2Ban"):
|
banaction=None, bancategory=None, bankey=None, updateperiod=900, agent="Fail2Ban",
|
||||||
|
timeout=TIMEOUT):
|
||||||
super(BadIPsAction, self).__init__(jail, name)
|
super(BadIPsAction, self).__init__(jail, name)
|
||||||
|
|
||||||
|
self.timeout = timeout
|
||||||
self.agent = agent
|
self.agent = agent
|
||||||
self.category = category
|
self.category = category
|
||||||
self.score = score
|
self.score = score
|
||||||
|
@ -119,7 +122,7 @@ class BadIPsAction(ActionBase):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
response = urlopen(
|
response = urlopen(
|
||||||
self._Request("/".join([self._badips, "get", "categories"])), None, 3)
|
self._Request("/".join([self._badips, "get", "categories"])), timeout=self.timeout)
|
||||||
except HTTPError as response:
|
except HTTPError as response:
|
||||||
messages = json.loads(response.read().decode('utf-8'))
|
messages = json.loads(response.read().decode('utf-8'))
|
||||||
self._logSys.error(
|
self._logSys.error(
|
||||||
|
@ -173,7 +176,7 @@ class BadIPsAction(ActionBase):
|
||||||
urlencode({'age': age})])
|
urlencode({'age': age})])
|
||||||
if key:
|
if key:
|
||||||
url = "&".join([url, urlencode({'key': key})])
|
url = "&".join([url, urlencode({'key': key})])
|
||||||
response = urlopen(self._Request(url))
|
response = urlopen(self._Request(url), timeout=self.timeout)
|
||||||
except HTTPError as response:
|
except HTTPError as response:
|
||||||
messages = json.loads(response.read().decode('utf-8'))
|
messages = json.loads(response.read().decode('utf-8'))
|
||||||
self._logSys.error(
|
self._logSys.error(
|
||||||
|
@ -358,7 +361,7 @@ class BadIPsAction(ActionBase):
|
||||||
url = "/".join([self._badips, "add", self.category, aInfo['ip']])
|
url = "/".join([self._badips, "add", self.category, aInfo['ip']])
|
||||||
if self.key:
|
if self.key:
|
||||||
url = "?".join([url, urlencode({'key': self.key})])
|
url = "?".join([url, urlencode({'key': self.key})])
|
||||||
response = urlopen(self._Request(url))
|
response = urlopen(self._Request(url), timeout=self.timeout)
|
||||||
except HTTPError as response:
|
except HTTPError as response:
|
||||||
messages = json.loads(response.read().decode('utf-8'))
|
messages = json.loads(response.read().decode('utf-8'))
|
||||||
self._logSys.error(
|
self._logSys.error(
|
||||||
|
|
|
@ -37,6 +37,7 @@ if sys.version_info >= (2,7):
|
||||||
self.jail.actions.add("badips", pythonModule, initOpts={
|
self.jail.actions.add("badips", pythonModule, initOpts={
|
||||||
'category': "ssh",
|
'category': "ssh",
|
||||||
'banaction': "test",
|
'banaction': "test",
|
||||||
|
'timeout': 30,
|
||||||
})
|
})
|
||||||
self.action = self.jail.actions["badips"]
|
self.action = self.jail.actions["badips"]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue