Ejemplo n.º 1
0
def process_manual_detention_form(form, account):
    """Execute a manual detention based on form data"""
    _logger.debug('process_manual_detention_form')

    target = form.cleaned_data['target']
    justification = Justification.objects.get(
        pk=form.cleaned_data['justification'])
    username = account.login
    comment = form.cleaned_data['comment']
    days = form.cleaned_data['days']
    camtuple = form.cleaned_data['camtuple']

    cam = Cam.objects.get(pk=camtuple)
    try:
        interface = Interface.objects.get(netbox=cam.netbox,
                                          ifindex=cam.ifindex)
    except Interface.DoesNotExist as error:
        return error

    identity = Identity()
    identity.interface = interface
    identity.mac = cam.mac
    if find_input_type(target) == 'IP':
        identity.ip = target

    if form.cleaned_data['method'] == 'disable':
        try:
            disable(identity,
                    justification,
                    username,
                    comment=comment,
                    autoenablestep=days)
        except GeneralException as error:
            return error
    elif form.cleaned_data['method'] == 'quarantine':
        qvlan = QuarantineVlan.objects.get(pk=form.cleaned_data['qvlan'])
        try:
            quarantine(
                identity,
                qvlan,
                justification,
                username,
                comment=comment,
                autoenablestep=days,
            )
        except GeneralException as error:
            return error
Ejemplo n.º 2
0
Archivo: arnold.py Proyecto: yytsui/nav
def check_identity(candidate):
    """Create or return existing identity object based on target"""
    try:
        identity = Identity.objects.get(interface=candidate.interface,
                                        mac=candidate.mac)
        if identity.status != 'enabled':
            raise AlreadyBlockedError
        identity.ip = candidate.ip
    except Identity.DoesNotExist:
        identity = Identity()
        identity.interface = candidate.interface
        identity.ip = candidate.ip
        identity.mac = candidate.mac

    # Check if we should not detain this interface for some reason
    raise_if_detainment_not_allowed(identity.interface)

    return identity
Ejemplo n.º 3
0
def check_identity(candidate):
    """Create or return existing identity object based on target"""
    try:
        identity = Identity.objects.get(interface=candidate.interface,
                                        mac=candidate.mac)
        if identity.status != 'enabled':
            raise AlreadyBlockedError
        identity.ip = candidate.ip
    except Identity.DoesNotExist:
        identity = Identity()
        identity.interface = candidate.interface
        identity.ip = candidate.ip
        identity.mac = candidate.mac

    # Check if we should not detain this interface for some reason
    raise_if_detainment_not_allowed(identity.interface)

    return identity
Ejemplo n.º 4
0
    comment = form.cleaned_data['comment']
    days = form.cleaned_data['days']
    camtuple = form.cleaned_data['camtuple']

    cam = Cam.objects.get(pk=camtuple)
    try:
        interface = Interface.objects.get(
            netbox=cam.netbox, ifindex=cam.ifindex)
    except Interface.DoesNotExist, error:
        return error

    identity = Identity()
    identity.interface = interface
    identity.mac = cam.mac
    if find_input_type(target) == 'IP':
        identity.ip = target

    if form.cleaned_data['method'] == 'disable':
        try:
            disable(identity, justification, username, comment=comment,
                    autoenablestep=days)
        except GeneralException, error:
            return error
    elif form.cleaned_data['method'] == 'quarantine':
        qvlan = QuarantineVlan.objects.get(pk=form.cleaned_data['qvlan'])
        try:
            quarantine(identity, qvlan, justification,
                       username, comment=comment, autoenablestep=days)
        except GeneralException, error:
            return error
Ejemplo n.º 5
0
    comment = form.cleaned_data['comment']
    days = form.cleaned_data['days']
    camtuple = form.cleaned_data['camtuple']

    cam = Cam.objects.get(pk=camtuple)
    try:
        interface = Interface.objects.get(netbox=cam.netbox,
                                          ifindex=cam.ifindex)
    except Interface.DoesNotExist, error:
        return error

    identity = Identity()
    identity.interface = interface
    identity.mac = cam.mac
    if find_input_type(target) == 'IP':
        identity.ip = target

    if form.cleaned_data['method'] == 'disable':
        try:
            disable(identity,
                    justification,
                    username,
                    comment=comment,
                    autoenablestep=days)
        except GeneralException, error:
            return error
    elif form.cleaned_data['method'] == 'quarantine':
        qvlan = QuarantineVlan.objects.get(pk=form.cleaned_data['qvlan'])
        try:
            quarantine(identity,
                       qvlan,