Exemplo n.º 1
0
class JailReader(ConfigReader):

    actionCRE = re.compile("^((?:\w|-|_|\.)+)(?:\[(.*)\])?$")

    def __init__(self, name):
        ConfigReader.__init__(self)
        self.__name = name
        self.__filter = None
        self.__actions = list()

    def setName(self, value):
        self.__name = value

    def getName(self):
        return self.__name

    def read(self):
        ConfigReader.read(self, "jail")

    def isEnabled(self):
        return self.__opts["enabled"]

    def getOptions(self):
        opts = [["bool", "enabled", "false"],
                ["string", "logpath", "/var/log/messages"],
                ["string", "backend", "auto"], ["int", "maxretry", 3],
                ["int", "findtime", 600], ["int", "bantime", 600],
                ["string", "usedns", "warn"], ["string", "failregex", None],
                ["string", "failmodel", None], ["string", "ignoreregex", None],
                ["string", "ignoreip", None], ["string", "filter", ""],
                ["string", "action", ""]]
        self.__opts = ConfigReader.getOptions(self, self.__name, opts)

        if self.isEnabled():
            # Read filter
            self.__filter = FilterReader(self.__opts["filter"], self.__name)
            ret = self.__filter.read()
            if ret:
                self.__filter.getOptions(self.__opts)
            else:
                logSys.error("Unable to read the filter")
                return False

            # Read action
            for act in self.__opts["action"].split('\n'):
                try:
                    splitAct = JailReader.splitAction(act)
                    action = ActionReader(splitAct, self.__name)
                    ret = action.read()
                    if ret:
                        action.getOptions(self.__opts)
                        self.__actions.append(action)
                    else:
                        raise AttributeError("Unable to read action")
                except Exception, e:
                    logSys.error("Error in action definition " + act)
                    logSys.debug(e)
                    return False
        return True
Exemplo n.º 2
0
class JailReader(ConfigReader):
	
	actionCRE = re.compile("^((?:\w|-|_|\.)+)(?:\[(.*)\])?$")
	
	def __init__(self, name):
		ConfigReader.__init__(self)
		self.__name = name
		self.__filter = None
		self.__actions = list()
	
	def setName(self, value):
		self.__name = value
	
	def getName(self):
		return self.__name
	
	def read(self):
		ConfigReader.read(self, "jail")
	
	def isEnabled(self):
		return self.__opts["enabled"]
	
	def getOptions(self):
		opts = [["bool", "enabled", "false"],
				["string", "logpath", "/var/log/messages"],
				["string", "backend", "auto"],
				["int", "maxretry", 3],
				["int", "findtime", 600],
				["int", "bantime", 600],
				["string", "failregex", None],
				["string", "ignoreregex", None],
				["string", "ignoreip", None],
				["string", "filter", ""],
				["string", "action", ""]]
		self.__opts = ConfigReader.getOptions(self, self.__name, opts)
		
		if self.isEnabled():
			
			self.__filter = FilterReader(self.__opts["filter"], self.__name)
			ret = self.__filter.read()
			if ret:
				self.__filter.getOptions(self.__opts)
			else:
				logSys.error("Unable to read the filter")
				return False
			
			
			for act in self.__opts["action"].split('\n'):
				try:
					splitAct = JailReader.splitAction(act)
					action = ActionReader(splitAct, self.__name)
					ret = action.read()
					if ret:
						action.getOptions(self.__opts)
						self.__actions.append(action)
					else:
						raise AttributeError("Unable to read action")
				except AttributeError, e:
					logSys.error("Error in action definition " + act)
					logSys.debug(e)
					return False
		return True
Exemplo n.º 3
0
class JailReader(ConfigReader):

    actionCRE = re.compile("^((?:\w|-|_|\.)+)(?:\[(.*)\])?$")

    def __init__(self, name, force_enable=False, **kwargs):
        ConfigReader.__init__(self, **kwargs)
        self.__name = name
        self.__filter = None
        self.__force_enable = force_enable
        self.__actions = list()

    def setName(self, value):
        self.__name = value

    def getName(self):
        return self.__name

    def read(self):
        return ConfigReader.read(self, "jail")

    def isEnabled(self):
        return self.__force_enable or self.__opts["enabled"]

    def getOptions(self):
        opts = [
            ["bool", "enabled", "false"],
            ["string", "logpath", "/var/log/messages"],
            ["string", "backend", "auto"],
            ["int", "maxretry", 3],
            ["int", "findtime", 600],
            ["int", "bantime", 600],
            ["string", "usedns", "warn"],
            ["string", "failregex", None],
            ["string", "ignoreregex", None],
            ["string", "ignoreip", None],
            ["string", "filter", ""],
            ["string", "action", ""],
        ]
        self.__opts = ConfigReader.getOptions(self, self.__name, opts)

        if self.isEnabled():
            # Read filter
            self.__filter = FilterReader(self.__opts["filter"], self.__name, basedir=self.getBaseDir())
            ret = self.__filter.read()
            if ret:
                self.__filter.getOptions(self.__opts)
            else:
                logSys.error("Unable to read the filter")
                return False

                # Read action
            for act in self.__opts["action"].split("\n"):
                try:
                    if not act:  # skip empty actions
                        continue
                    splitAct = JailReader.splitAction(act)
                    action = ActionReader(splitAct, self.__name, basedir=self.getBaseDir())
                    ret = action.read()
                    if ret:
                        action.getOptions(self.__opts)
                        self.__actions.append(action)
                    else:
                        raise AttributeError("Unable to read action")
                except Exception, e:
                    logSys.error("Error in action definition " + act)
                    logSys.debug("Caught exception: %s" % (e,))
                    return False
            if not len(self.__actions):
                logSys.warn("No actions were defined for %s" % self.__name)
        return True
Exemplo n.º 4
0
class JailReader(ConfigReader):
	
	actionCRE = re.compile("^([\w_.-]+)(?:\[(.*)\])?$")
	
	def __init__(self, name, force_enable=False, **kwargs):
		ConfigReader.__init__(self, **kwargs)
		self.__name = name
		self.__filter = None
		self.__force_enable = force_enable
		self.__actions = list()
		self.__opts = None
	
	def getRawOptions(self):
		return self.__opts

	def setName(self, value):
		self.__name = value
	
	def getName(self):
		return self.__name
	
	def read(self):
		return ConfigReader.read(self, "jail")
	
	def isEnabled(self):
		return self.__force_enable or ( self.__opts and self.__opts["enabled"] )

	@staticmethod
	def _glob(path):
		"""Given a path for glob return list of files to be passed to server.

		Dangling symlinks are warned about and not returned
		"""
		pathList = []
		for p in glob.glob(path):
			if os.path.exists(p):
				pathList.append(p)
			else:
				logSys.warning("File %s is a dangling link, thus cannot be monitored" % p)
		return pathList

	def getOptions(self):
		opts = [["bool", "enabled", "false"],
				["string", "logpath", "/var/log/messages"],
				["string", "backend", "auto"],
				["int", "maxretry", 3],
				["int", "findtime", 600],
				["int", "bantime", 600],
				["string", "usedns", "warn"],
				["string", "failregex", None],
				["string", "ignoreregex", None],
				["string", "ignorecommand", None],
				["string", "ignoreip", None],
				["string", "filter", ""],
				["string", "action", ""]]
		self.__opts = ConfigReader.getOptions(self, self.__name, opts)
		if not self.__opts:
			return False
		
		if self.isEnabled():
			# Read filter
			if self.__opts["filter"]:
				self.__filter = FilterReader(self.__opts["filter"], self.__name,
											 basedir=self.getBaseDir())
				ret = self.__filter.read()
				if ret:
					self.__filter.getOptions(self.__opts)
				else:
					logSys.error("Unable to read the filter")
					return False
			else:
				self.__filter = None
				logSys.warn("No filter set for jail %s" % self.__name)
		
			# Read action
			for act in self.__opts["action"].split('\n'):
				try:
					if not act:			  # skip empty actions
						continue
					splitAct = JailReader.splitAction(act)
					action = ActionReader(splitAct, self.__name, basedir=self.getBaseDir())
					ret = action.read()
					if ret:
						action.getOptions(self.__opts)
						self.__actions.append(action)
					else:
						raise AttributeError("Unable to read action")
				except Exception, e:
					logSys.error("Error in action definition " + act)
					logSys.debug("Caught exception: %s" % (e,))
					return False
			if not len(self.__actions):
				logSys.warn("No actions were defined for %s" % self.__name)
		return True