Example #1
0
def detain(address, profile, comment=''):
    """Detain address with the given profile"""
    _logger.debug("Trying to detain %s", address)

    username = getpass.getuser()
    candidate = find_computer_info(address)

    if profile.active_on_vlans and not is_inside_vlans(
            candidate.ip, profile.active_on_vlans):
        _logger.error(
            "%s is not inside defined vlanrange for this predefined "
            "detention",
            address,
        )
        return

    duration = find_duration(candidate, profile)

    if profile.detention_type == 'disable':
        disable(candidate, profile.justification, username, comment, duration)
    else:
        quarantine(
            candidate,
            profile.quarantine_vlan,
            profile.justification,
            username,
            comment,
            duration,
        )

    return address
Example #2
0
File: t1000.py Project: hmpf/nav
def detain(identity, candidate):
    """Detain based on identity info"""
    username = getpass.getuser()
    comment = "Detained automatically when switching ports"

    try:
        if identity.status == 'disabled':
            _logger.debug("Trying to disable %s", identity.mac)
            disable(
                candidate,
                identity.justification,
                username,
                comment,
                identity.autoenablestep,
            )

        elif identity.status == 'quarantined':
            _logger.debug("Trying to quarantine %s with vlan %s", identity.mac,
                          identity.tovlan)
            quarantine(
                candidate,
                identity.tovlan,
                identity.justification,
                username,
                comment,
                identity.autoenablestep,
            )
    except GeneralException as error:
        _logger.error(error)
Example #3
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
Example #4
0
def detain(identity, candidate):
    """Detain based on identity info"""
    username = getpass.getuser()
    comment = "Detained automatically when switching ports"

    try:
        if identity.status == 'disabled':
            LOGGER.debug("Trying to disable %s" % identity.mac)
            disable(candidate, identity.justification, username, comment,
                    identity.autoenablestep)

        elif identity.status == 'quarantined':
            LOGGER.debug("Trying to quarantine %s with vlan %s"
                         % (identity.mac, identity.tovlan))
            quarantine(candidate, identity.tovlan, identity.justification,
                       username, comment, identity.autoenablestep)
    except GeneralException, error:
        LOGGER.error(error)
Example #5
0
def detain(address, profile, comment=''):
    """Detain address with the given profile"""
    LOGGER.debug("Trying to detain %s" % address)

    username = getpass.getuser()
    candidate = find_computer_info(address)

    if profile.active_on_vlans and not is_inside_vlans(
            candidate.ip, profile.active_on_vlans):
        LOGGER.error(
            "%s is not inside defined vlanrange for this predefined "
            "detention" % address)
        return

    duration = find_duration(candidate, profile)

    if profile.detention_type == 'disable':
        disable(candidate, profile.justification, username, comment, duration)
    else:
        quarantine(candidate, profile.quarantine_vlan, profile.justification,
                   username, comment, duration)

    return address
Example #6
0
    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


def choose_detentions(request, did):
    """Find all detentions for the mac-address in the given detention"""
    detention = Identity.objects.get(pk=did)
    detentions = Identity.objects.filter(
Example #7
0
        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