Exemplo n.º 1
0
 def __editService(self, service, name=None, description=None,
                   protocol=None, ports=None, status=None,
                   version=None, owned=None):
     res = False
     if service is not None:
         service.updateAttributes(name, description, protocol, ports, status, version, owned)
         notifier.editHost(service.getHost())
         res = True
     return res
Exemplo n.º 2
0
    def __edit(self, obj, *args, **kwargs):
        obj.updateAttributes(*args, **kwargs)
        self.mappers_manager.update(obj)

        # if obj.class_signature == model.hosts.Host.class_signature:
        notifier.editHost(obj)
        # else:
        # notifier.editHost(obj.getHost())
        return True
Exemplo n.º 3
0
    def __edit(self, obj, *args, **kwargs):
        obj.updateAttributes(*args, **kwargs)
        self.mappers_manager.update(obj)

        # if obj.class_signature == model.hosts.Host.class_signature:
        notifier.editHost(obj)
        # else:
        # notifier.editHost(obj.getHost())
        return True
Exemplo n.º 4
0
 def __editService(self, service, name=None, description=None,
                   protocol=None, ports=None, status=None,
                   version=None, owned=None):
     res = False
     if service is not None:
         service.updateAttributes(
             name, description, protocol, ports, status, version, owned)
         notifier.editHost(service.getHost())
         res = True
     return res
Exemplo n.º 5
0
    def __edit(self, obj, *args, **kwargs):
        dataMapper = self.mappers_manager.getMapper(obj.class_signature)
        obj.updateAttributes(*args, **kwargs)
        dataMapper.save(obj)
        # self.treeWordsTries.addWord(obj.getName())

        if obj.class_signature == model.hosts.Host.class_signature:
            notifier.editHost(obj)
        else:
            notifier.editHost(obj.getHost())
        return True
Exemplo n.º 6
0
    def __edit(self, obj, *args, **kwargs):
        dataMapper = self.mappers_manager.getMapper(obj.class_signature)
        obj.updateAttributes(*args, **kwargs)
        dataMapper.save(obj)
        # self.treeWordsTries.addWord(obj.getName())

        if obj.class_signature == model.hosts.Host.class_signature:
            notifier.editHost(obj)
        else:
            notifier.editHost(obj.getHost())
        return True
Exemplo n.º 7
0
 def addUpdate(self, old_object, new_object):
     # Returns True if the update was resolved without user interaction
     try:
         mergeAction = old_object.addUpdate(new_object)
         if mergeAction:
             if old_object not in self.objects_with_updates:
                 self.objects_with_updates.append(old_object)
             notifier.conflictUpdate(1)
             return False
     except:
         api.devlog("(%s).addUpdate(%s, %s) - failed" % (self, old_object, new_object))
         return False
     self.mappers_manager.update(old_object)
     notifier.editHost(old_object)
     return True
Exemplo n.º 8
0
 def addUpdate(self, old_object, new_object, command_id):
     # Returns True if the update was resolved without user interaction
     try:
         mergeAction = old_object.addUpdate(new_object, command_id)
         if mergeAction:
             if old_object not in self.objects_with_updates:
                 self.objects_with_updates.append(old_object)
             notifier.conflictUpdate(1)
             return False
     except Exception as ex:
         api.devlog("(%s).addUpdate(%s, %s) - failed" %
                    (self, old_object, new_object))
         return False
     self.mappers_manager.update(old_object, command_id)
     notifier.editHost(old_object)
     return True
Exemplo n.º 9
0
    def __del(self, objId, *args):
        obj = self.mappers_manager.find(objId)
        if obj:
            obj_parent = obj.getParent()
            if obj_parent:
                obj_parent.deleteChild(objId)

            self.removeConflictsByObject(obj)

            self.mappers_manager.remove(objId, obj.class_signature)

            if obj.class_signature == models.Host.class_signature:
                notifier.delHost(objId)
            else:
                notifier.editHost(obj.getHost())
            return True
        return False
Exemplo n.º 10
0
    def __del(self, objId, *args):
        obj = self.mappers_manager.find(objId)
        if obj:
            obj_parent = obj.getParent()
            if obj_parent:
                obj_parent.deleteChild(objId)

            self.removeConflictsByObject(obj)

            self.mappers_manager.remove(objId, obj.class_signature)

            if obj.class_signature == models.Host.class_signature:
                notifier.delHost(objId)
            else:
                notifier.editHost(obj.getHost())
            return True
        return False
Exemplo n.º 11
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.º 12
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.º 13
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.º 14
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
Exemplo n.º 15
0
 def __edit(self, obj, command_id=None, *args, **kwargs):
     obj.updateAttributes(*args, **kwargs)
     self.mappers_manager.update(obj, command_id)
     notifier.editHost(obj)
     return True
Exemplo n.º 16
0
 def __edit(self, obj, command_id=None, *args, **kwargs):
     obj.updateAttributes(*args, **kwargs)
     self.mappers_manager.update(obj, command_id)
     notifier.editHost(obj)
     return True