Exemplo n.º 1
0
    def __add(self, obj, parent_id=None, *args):
        dataMapper = self.mappers_manager.getMapper(obj.class_signature)
        old_obj = dataMapper.find(obj.getID())
        if old_obj:
            if not old_obj.needs_merge(obj):
                # the object is exactly the same,
                # so return and do nothing
                return True
            if not self.addUpdate(old_obj, obj):
                return False
            dataMapper.save(old_obj)
            notifier.editHost(old_obj.getHost())
        else:
            object_parent = self.mappers_manager.find(parent_id)
            if object_parent:
                object_parent.addChild(obj)
            # we have to make sure that certain objects have to have a parent
            if (
                obj.class_signature
                in [
                    model.hosts.Interface.class_signature,
                    model.hosts.Service.class_signature,
                    model.common.ModelObjectNote.class_signature,
                    model.common.ModelObjectVuln.class_signature,
                    model.common.ModelObjectVulnWeb.class_signature,
                    model.common.ModelObjectCred.class_signature,
                ]
                and object_parent is None
            ):
                # TODO: refactor log module. We need to log twice to see it in
                # qt and in the terminal. Ugly.
                msg = "A parent is needed for %s objects" % obj.class_signature
                getLogger(self).error(msg)
                return False
            dataMapper.save(obj)
            self.treeWordsTries.addWord(obj.getName())
            if obj.class_signature == model.hosts.Host.class_signature:
                notifier.addHost(obj)
            else:
                notifier.editHost(obj.getHost())

        return True
Exemplo n.º 2
0
    def __add(self,  obj, parent_id=None, *args):
        dataMapper = self.mappers_manager.getMapper(obj.class_signature)
        old_obj = dataMapper.find(obj.getID())
        if old_obj:
            if not self.addUpdate(old_obj, obj):
                return False
            dataMapper.save(old_obj)
            notifier.editHost(old_obj.getHost())
        else:
            object_parent = self.mappers_manager.find(parent_id)
            if object_parent:
                object_parent.addChild(obj)
            dataMapper.save(obj)
            self.treeWordsTries.addWord(obj.getName())
            if obj.class_signature == model.hosts.Host.class_signature:
                notifier.addHost(obj)
            else:
                notifier.editHost(obj.getHost())

        return True
Exemplo n.º 3
0
    def __add(self, obj, parent_id=None, *args):
        dataMapper = self.mappers_manager.getMapper(obj.class_signature)
        old_obj = dataMapper.find(obj.getID())
        if old_obj:
            if not self.addUpdate(old_obj, obj):
                return False
            dataMapper.save(old_obj)
            notifier.editHost(old_obj.getHost())
        else:
            object_parent = self.mappers_manager.find(parent_id)
            if object_parent:
                object_parent.addChild(obj)
            dataMapper.save(obj)
            self.treeWordsTries.addWord(obj.getName())
            if obj.class_signature == model.hosts.Host.class_signature:
                notifier.addHost(obj)
            else:
                notifier.editHost(obj.getHost())

        return True
Exemplo n.º 4
0
    def __add(self, obj, parent_id=None, *args):
        dataMapper = self.mappers_manager.getMapper(obj.class_signature)
        old_obj = dataMapper.find(obj.getID())
        if old_obj:
            if not old_obj.needs_merge(obj):
                # the object is exactly the same,
                # so return and do nothing
                return True
            if not self.addUpdate(old_obj, obj):
                return False
            dataMapper.save(old_obj)
            notifier.editHost(old_obj.getHost())
        else:
            object_parent = self.mappers_manager.find(parent_id)
            if object_parent:
                object_parent.addChild(obj)
            # we have to make sure that certain objects have to have a parent
            if (obj.class_signature in [
                    model.hosts.Interface.class_signature,
                    model.hosts.Service.class_signature,
                    model.common.ModelObjectNote.class_signature,
                    model.common.ModelObjectVuln.class_signature,
                    model.common.ModelObjectVulnWeb.class_signature,
                    model.common.ModelObjectCred.class_signature
            ] and object_parent is None):
                # TODO: refactor log module. We need to log twice to see it in
                # qt and in the terminal. Ugly.
                msg = "A parent is needed for %s objects" % obj.class_signature
                getLogger(self).error(msg)
                model.api.log(msg)
                return False
            dataMapper.save(obj)
            self.treeWordsTries.addWord(obj.getName())
            if obj.class_signature == model.hosts.Host.class_signature:
                notifier.addHost(obj)
            else:
                notifier.editHost(obj.getHost())

        return True