|
|
@ -38,7 +38,7 @@ logSys = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class JailReader(ConfigReader):
|
|
|
|
class JailReader(ConfigReader):
|
|
|
|
|
|
|
|
|
|
|
|
actionCRE = re.compile("^((?:\w|-|_|\.)+)(?:\[(.*)\])?$")
|
|
|
|
optionCRE = re.compile("^((?:\w|-|_|\.)+)(?:\[(.*)\])?$")
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, name, force_enable=False, **kwargs):
|
|
|
|
def __init__(self, name, force_enable=False, **kwargs):
|
|
|
|
ConfigReader.__init__(self, **kwargs)
|
|
|
|
ConfigReader.__init__(self, **kwargs)
|
|
|
@ -78,8 +78,10 @@ class JailReader(ConfigReader):
|
|
|
|
|
|
|
|
|
|
|
|
if self.isEnabled():
|
|
|
|
if self.isEnabled():
|
|
|
|
# Read filter
|
|
|
|
# Read filter
|
|
|
|
self.__filter = FilterReader(self.__opts["filter"], self.__name,
|
|
|
|
filterName, filterOpt = JailReader.splitOption(
|
|
|
|
basedir=self.getBaseDir())
|
|
|
|
self.__opts["filter"])
|
|
|
|
|
|
|
|
self.__filter = FilterReader(
|
|
|
|
|
|
|
|
filterName, self.__name, filterOpt, basedir=self.getBaseDir())
|
|
|
|
ret = self.__filter.read()
|
|
|
|
ret = self.__filter.read()
|
|
|
|
if ret:
|
|
|
|
if ret:
|
|
|
|
self.__filter.getOptions(self.__opts)
|
|
|
|
self.__filter.getOptions(self.__opts)
|
|
|
@ -92,8 +94,9 @@ class JailReader(ConfigReader):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
if not act: # skip empty actions
|
|
|
|
if not act: # skip empty actions
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
splitAct = JailReader.splitAction(act)
|
|
|
|
actName, actOpt = JailReader.splitOption(act)
|
|
|
|
action = ActionReader(splitAct, self.__name, basedir=self.getBaseDir())
|
|
|
|
action = ActionReader(
|
|
|
|
|
|
|
|
actName, self.__name, actOpt, basedir=self.getBaseDir())
|
|
|
|
ret = action.read()
|
|
|
|
ret = action.read()
|
|
|
|
if ret:
|
|
|
|
if ret:
|
|
|
|
action.getOptions(self.__opts)
|
|
|
|
action.getOptions(self.__opts)
|
|
|
@ -151,23 +154,23 @@ class JailReader(ConfigReader):
|
|
|
|
return stream
|
|
|
|
return stream
|
|
|
|
|
|
|
|
|
|
|
|
#@staticmethod
|
|
|
|
#@staticmethod
|
|
|
|
def splitAction(action):
|
|
|
|
def splitOption(option):
|
|
|
|
m = JailReader.actionCRE.match(action)
|
|
|
|
m = JailReader.optionCRE.match(option)
|
|
|
|
d = dict()
|
|
|
|
d = dict()
|
|
|
|
mgroups = m.groups()
|
|
|
|
mgroups = m.groups()
|
|
|
|
if len(mgroups) == 2:
|
|
|
|
if len(mgroups) == 2:
|
|
|
|
action_name, action_opts = mgroups
|
|
|
|
option_name, option_opts = mgroups
|
|
|
|
elif len(mgroups) == 1:
|
|
|
|
elif len(mgroups) == 1:
|
|
|
|
action_name, action_opts = mgroups[0], None
|
|
|
|
option_name, option_opts = mgroups[0], None
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
raise ValueError("While reading action %s we should have got up to "
|
|
|
|
raise ValueError("While reading option %s we should have got up to "
|
|
|
|
"2 groups. Got: %r" % (action, mgroups))
|
|
|
|
"2 groups. Got: %r" % (option, mgroups))
|
|
|
|
if not action_opts is None:
|
|
|
|
if not option_opts is None:
|
|
|
|
# Huge bad hack :( This method really sucks. TODO Reimplement it.
|
|
|
|
# Huge bad hack :( This method really sucks. TODO Reimplement it.
|
|
|
|
actions = ""
|
|
|
|
options = ""
|
|
|
|
escapeChar = None
|
|
|
|
escapeChar = None
|
|
|
|
allowComma = False
|
|
|
|
allowComma = False
|
|
|
|
for c in action_opts:
|
|
|
|
for c in option_opts:
|
|
|
|
if c in ('"', "'") and not allowComma:
|
|
|
|
if c in ('"', "'") and not allowComma:
|
|
|
|
# Start
|
|
|
|
# Start
|
|
|
|
escapeChar = c
|
|
|
|
escapeChar = c
|
|
|
@ -178,20 +181,20 @@ class JailReader(ConfigReader):
|
|
|
|
allowComma = False
|
|
|
|
allowComma = False
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
if c == ',' and allowComma:
|
|
|
|
if c == ',' and allowComma:
|
|
|
|
actions += "<COMMA>"
|
|
|
|
options += "<COMMA>"
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
actions += c
|
|
|
|
options += c
|
|
|
|
|
|
|
|
|
|
|
|
# Split using ,
|
|
|
|
# Split using ,
|
|
|
|
actionsSplit = actions.split(',')
|
|
|
|
optionsSplit = options.split(',')
|
|
|
|
# Replace the tag <COMMA> with ,
|
|
|
|
# Replace the tag <COMMA> with ,
|
|
|
|
actionsSplit = [n.replace("<COMMA>", ',') for n in actionsSplit]
|
|
|
|
optionsSplit = [n.replace("<COMMA>", ',') for n in optionsSplit]
|
|
|
|
|
|
|
|
|
|
|
|
for param in actionsSplit:
|
|
|
|
for param in optionsSplit:
|
|
|
|
p = param.split('=')
|
|
|
|
p = param.split('=')
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
d[p[0].strip()] = p[1].strip()
|
|
|
|
d[p[0].strip()] = p[1].strip()
|
|
|
|
except IndexError:
|
|
|
|
except IndexError:
|
|
|
|
logSys.error("Invalid argument %s in '%s'" % (p, action_opts))
|
|
|
|
logSys.error("Invalid argument %s in '%s'" % (p, option_opts))
|
|
|
|
return [action_name, d]
|
|
|
|
return [option_name, d]
|
|
|
|
splitAction = staticmethod(splitAction)
|
|
|
|
splitOption = staticmethod(splitOption)
|
|
|
|