Exemple #1
0
def netbios_search(request):
    """Controller for displaying search for NETBIOS name"""
    if 'search' in request.GET:
        return netbios_do_search(request)
    info_dict = {'form': forms.NetbiosTrackerForm()}
    info_dict.update(NBT_DEFAULTS)
    return render(request, 'machinetracker/netbios_search.html', info_dict)
Exemple #2
0
def netbios_do_search(request):
    """Handle a search for a NETBIOS name"""
    form = forms.NetbiosTrackerForm(ProcessInput(request.GET).netbios())
    info_dict = {
        'form': form,
        'form_data': None,
        'netbios_tracker': None,
        'netbios_tracker_count': 0,
    }

    if form.is_valid():
        searchstring = form.cleaned_data['search']
        days = form.cleaned_data['days']
        dns = form.cleaned_data['dns']
        from_time = date.today() - timedelta(days=days)

        filters = (
            Q(mac__istartswith=searchstring)
            | Q(ip__istartswith=searchstring)
            | Q(name__icontains=searchstring)
        )

        result = Netbios.objects.filter(filters, end_time__gt=from_time)
        result = result.order_by('name', 'mac', 'start_time')

        nbt_count = len(result)

        netbios_tracker = track_mac(
            ('ip', 'mac', 'name', 'server', 'username', 'start_time', 'end_time'),
            result,
            dns,
        )

        info_dict.update(
            {
                'form_data': form.cleaned_data,
                'netbios_tracker': netbios_tracker,
                'netbios_tracker_count': nbt_count,
                'colspan': find_colspan('netbios', form),
            }
        )

    info_dict.update(NBT_DEFAULTS)
    return render(request, 'machinetracker/netbios_search.html', info_dict)