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
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
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
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,