"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "fail2ban/server/action.py" between
fail2ban-0.10.5.tar.gz and fail2ban-0.11.1.tar.gz

About:

action.py  (fail2ban-0.10.5):action.py  (fail2ban-0.11.1)
skipping to change at line 263 skipping to change at line 263
"""Executed when a ban occurs. """Executed when a ban occurs.
Parameters Parameters
---------- ----------
aInfo : dict aInfo : dict
Dictionary which includes information in relation to Dictionary which includes information in relation to
the ban. the ban.
""" """
return self.ban(aInfo) return self.ban(aInfo)
@property
def _prolongable(self): # pragma: no cover - abstract
return False
def unban(self, aInfo): # pragma: no cover - abstract def unban(self, aInfo): # pragma: no cover - abstract
"""Executed when a ban expires. """Executed when a ban expires.
Parameters Parameters
---------- ----------
aInfo : dict aInfo : dict
Dictionary which includes information in relation to Dictionary which includes information in relation to
the ban. the ban.
""" """
pass pass
WRAP_CMD_PARAMS = {
'timeout': 'str2seconds',
'bantime': 'ignore',
}
class CommandAction(ActionBase): class CommandAction(ActionBase):
"""A action which executes OS shell commands. """A action which executes OS shell commands.
This is the default type of action which Fail2Ban uses. This is the default type of action which Fail2Ban uses.
Default sets all commands for actions as empty string, such Default sets all commands for actions as empty string, such
no command is executed. no command is executed.
Parameters Parameters
---------- ----------
skipping to change at line 346 skipping to change at line 355
self.clearAllParams() self.clearAllParams()
self._logSys.debug("Created %s" % self.__class__) self._logSys.debug("Created %s" % self.__class__)
@classmethod @classmethod
def __subclasshook__(cls, C): def __subclasshook__(cls, C):
return NotImplemented # Standard checks return NotImplemented # Standard checks
def __setattr__(self, name, value): def __setattr__(self, name, value):
if not name.startswith('_') and not self.__init and not callable( value): if not name.startswith('_') and not self.__init and not callable( value):
# special case for some parameters: # special case for some parameters:
if name in ('timeout', 'bantime'): wrp = WRAP_CMD_PARAMS.get(name)
if wrp == 'ignore': # ignore (filter) dynamic parameters
return
elif wrp == 'str2seconds':
value = MyTime.str2seconds(value) value = MyTime.str2seconds(value)
# parameters changed - clear properties and substitution cache: # parameters changed - clear properties and substitution cache:
self.__properties = None self.__properties = None
self.__substCache.clear() self.__substCache.clear()
#self._logSys.debug("Set action %r %s = %r", self._name, name, value) #self._logSys.debug("Set action %r %s = %r", self._name, name, value)
self._logSys.debug(" Set %s = %r", name, value) self._logSys.debug(" Set %s = %r", name, value)
# set: # set:
self.__dict__[name] = value self.__dict__[name] = value
__setitem__ = __setattr__ __setitem__ = __setattr__
skipping to change at line 540 skipping to change at line 552
# if we should start the action on demand (conditional by family) : # if we should start the action on demand (conditional by family) :
family = aInfo.get('family', '') family = aInfo.get('family', '')
if self._startOnDemand: if self._startOnDemand:
if not self.__started.get(family): if not self.__started.get(family):
self._start(family, forceStart=True) self._start(family, forceStart=True)
# ban: # ban:
if not self._processCmd(cmd, aInfo): if not self._processCmd(cmd, aInfo):
raise RuntimeError("Error banning %(ip)s" % aInfo) raise RuntimeError("Error banning %(ip)s" % aInfo)
self.__started[family] = self.__started.get(family, 0) | 3; # sta rted and contains items self.__started[family] = self.__started.get(family, 0) | 3; # sta rted and contains items
@property
def _prolongable(self):
return (hasattr(self, 'actionprolong') and self.actionprolong
and not str(self.actionprolong).isspace())
def prolong(self, aInfo):
"""Executes the "actionprolong" command.
Replaces the tags in the action command with actions properties
and ban information, and executes the resulting command.
Parameters
----------
aInfo : dict
Dictionary which includes information in relation to
the ban.
"""
if not self._processCmd('<actionprolong>', aInfo):
raise RuntimeError("Error prolonging %(ip)s" % aInfo)
def unban(self, aInfo): def unban(self, aInfo):
"""Executes the "actionunban" command. """Executes the "actionunban" command.
Replaces the tags in the action command with actions properties Replaces the tags in the action command with actions properties
and ban information, and executes the resulting command. and ban information, and executes the resulting command.
Parameters Parameters
---------- ----------
aInfo : dict aInfo : dict
Dictionary which includes information in relation to Dictionary which includes information in relation to
skipping to change at line 649 skipping to change at line 681
# for each started family: # for each started family:
if self.actioncheck: if self.actioncheck:
for (family, started) in self.__started.items(): for (family, started) in self.__started.items():
if started and not self._invariantCheck(family, b eforeRepair): if started and not self._invariantCheck(family, b eforeRepair):
# reset started flag and command of execu ted operation: # reset started flag and command of execu ted operation:
self.__started[family] = 0 self.__started[family] = 0
self._operationExecuted('<actionstart>', family, None) self._operationExecuted('<actionstart>', family, None)
ret &= False ret &= False
return ret return ret
@staticmethod ESCAPE_CRE = re.compile(r"""[\\#&;`|*?~<>^()\[\]{}$'"\n\r]""")
def escapeTag(value):
@classmethod
def escapeTag(cls, value):
"""Escape characters which may be used for command injection. """Escape characters which may be used for command injection.
Parameters Parameters
---------- ----------
value : str value : str
A string of which characters will be escaped. A string of which characters will be escaped.
Returns Returns
------- -------
str str
`value` with certain characters escaped. `value` with certain characters escaped.
Notes Notes
----- -----
The following characters are escaped:: The following characters are escaped::
\\#&;`|*?~<>^()[]{}$'" \\#&;`|*?~<>^()[]{}$'"\n\r
""" """
for c in '\\#&;`|*?~<>^()[]{}$\'"': _map2c = {'\n': 'n', '\r': 'r'}
if c in value: def substChar(m):
value = value.replace(c, '\\' + c) c = m.group()
return '\\' + _map2c.get(c, c)
value = cls.ESCAPE_CRE.sub(substChar, value)
return value return value
@classmethod @classmethod
def replaceTag(cls, query, aInfo, conditional='', addrepl=None, cache=Non e): def replaceTag(cls, query, aInfo, conditional='', addrepl=None, cache=Non e):
"""Replaces tags in `query` with property values. """Replaces tags in `query` with property values.
Parameters Parameters
---------- ----------
query : str query : str
String with tags. String with tags.
skipping to change at line 971 skipping to change at line 1008
bool bool
True if the command succeeded. True if the command succeeded.
Raises Raises
------ ------
OSError OSError
If command fails to be executed. If command fails to be executed.
RuntimeError RuntimeError
If command execution times out. If command execution times out.
""" """
logSys.debug(realCmd) if logSys.getEffectiveLevel() < logging.DEBUG:
logSys.log(9, realCmd)
if not realCmd: if not realCmd:
logSys.debug("Nothing to do") logSys.debug("Nothing to do")
return True return True
with _cmd_lock: with _cmd_lock:
return Utils.executeCmd(realCmd, timeout, shell=True, out put=False, **kwargs) return Utils.executeCmd(realCmd, timeout, shell=True, out put=False, **kwargs)
 End of changes. 8 change blocks. 
8 lines changed or deleted 46 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)