Exemplo n.º 1
0
def pdns(request, domain = None):
    if request.method == 'POST':
        pdns_f = pdns_form(request.POST)
    elif request.method == 'GET':
        pdns_f = pdns_form(QueryDict(''))
        pdns_f.data['domain'] = domain
        pdns_f.data['limit'] = request.GET.get('limit', settings.DNSDB_PAGE_LIMITS[settings.DNSDB_PAGE_LIMIT_DEFAULT])
        pdns_f.data['rrtypes'] = request.GET.getlist('rrtypes', [settings.RRTYPE_KEYS[0][0]])
        pdns_f.data['fmt'] = request.GET.get('fmt', 'normal')
        pdns_f.data['absolute'] = request.GET.get('absolute', False)
        pdns_f.data['pretty'] = request.GET.get('pretty', True)
        pdns_f.data['filt'] = request.GET.get('filt', 'rrname')

    else:
        return __renderErrorPage__(request, 'Bad Method')
    

    if not pdns_f.is_valid():
        return __renderErrorPage__(request, '', {'pdns_form': pdns_f})

    domain = pdns_f.cleaned_data['domain']
    fmt = pdns_f.cleaned_data['fmt']
    absolute = pdns_f.cleaned_data['absolute']
    limit = pdns_f.cleaned_data['limit']
    rrtypes = pdns_f.cleaned_data['rrtypes']
    pretty = pdns_f.cleaned_data['pretty']
    filt_key = pdns_f.cleaned_data['filt']

    if limit is None:
        limit = settings.DNSDB_PAGE_LIMITS[settings.DNSDB_PAGE_LIMIT_DEFAULT]

    if absolute is None:
        absolute = False

    results = passive.request_pdns(domain, absolute, rrtypes, limit, pretty)
    if fmt == 'normal':
        if results['success']:
            context = __createRequestContext__(request, {'results': results,
                                                         'inverse': False,
                                                         'pdns_form': pdns_f,
                                                        })
            return render_to_response('pdns.html', context)
        else:
            return __renderErrorPage__(request, results['error'], {'pdns_form': pdns_f})
    elif fmt == 'json':
        return HttpResponse(json.dumps(results), content_type='application/json')
    elif fmt == 'list':
        data = ''
        for rrtype in results['data'].keys():
            for record in results['data'][rrtype]:
                if not isinstance(record[filt_key], basestring): #it's a list
                    for item in record[filt_key]:
                        data += '\n%s' % item
                else: #it's just a string
                    data += '\n%s' % record[filt_key]
        data = data[1:]
        return HttpResponse(data, content_type='text/plain')
    else:
        return __renderErrorPage__(request, 'Invalid Format.')
Exemplo n.º 2
0
def pdns(request, search_value=None):
    if request.method == 'POST':
        pdns_f_dyn = pdns_form_dynamic(request.POST)
    elif request.method == 'GET':
        pdns_f_dyn = pdns_form_dynamic(QueryDict(''))
        pdns_f_dyn.data['search_value'] = search_value
        pdns_f_dyn.data['result_format'] = request.GET.get('result_format', 'none')

        # Filling form with all empty fields for a forward passive-DNS request
        for passive_field in passive.PDNS_UI_FIELDS_BASE + passive.PDNS_UI_FIELDS_FORWARD:
            pdns_f_dyn.data[passive_field.django_field_name] = request.GET.get(
                passive_field.django_field_name,
                passive_field.field_value_default)

    else:
        return __renderErrorResponse__(request,
                                       'pdns.html',
                                       'Bad Method')

    if not pdns_f_dyn.is_valid():
        return __renderErrorResponse__(request,
                                   'pdns.html',
                                   'Unable to verify form data',
                                    data = {"passive_form": pdns_f_dyn})
    
    # Get clean values for all common passive form fields
    search_value = pdns_f_dyn.cleaned_data['search_value']
    result_format = pdns_f_dyn.cleaned_data['result_format']


    dynamic_fields = {}
    # Obtain cleaned data for every passive-DNS field
    for passive_field in passive.PDNS_UI_FIELDS_BASE + passive.PDNS_UI_FIELDS_FORWARD:
        if passive_field.source_name not in dynamic_fields:
            dynamic_fields[passive_field.source_name] = {}

        cleaned_value = pdns_f_dyn.cleaned_data[passive_field.django_field_name]
        # If user did not enter a required field, grab a defined default value
        if not cleaned_value:
            cleaned_value = passive_field.field_value_default

        dynamic_fields[passive_field.source_name][passive_field.field_key] = cleaned_value

    results = passive.request_pdns(search_value, result_format, dynamic_fields)

    if not results['success']:
        return __renderErrorResponse__(request,
                                       'pdns.html',
                                       results['error'],
                                       data = {'passive_form': pdns_f_dyn ,})

    context = __createRequestContext__(data={'results': results['responses'],
                                             'inverse': False,
                                             'pdns_form_dynamic': pdns_f_dyn,
                                             'fmt': result_format})

    return render(request, 'pdns_results.html', context=context)
Exemplo n.º 3
0
def pdns(request, domain=None):
    if request.method == 'POST':
        pdns_f = pdns_form(request.POST)
    elif request.method == 'GET':
        pdns_f = pdns_form(QueryDict(''))
        pdns_f.data['domain'] = domain
        pdns_f.data['limit'] = request.GET.get(
            'limit',
            settings.DNSDB_PAGE_LIMITS[settings.DNSDB_PAGE_LIMIT_DEFAULT])
        pdns_f.data['rrtypes'] = request.GET.getlist(
            'rrtypes', [settings.RRTYPE_KEYS[0][0]])
        pdns_f.data['fmt'] = request.GET.get('fmt', 'normal')
        pdns_f.data['absolute'] = request.GET.get('absolute', False)
        pdns_f.data['pretty'] = request.GET.get('pretty', True)
        pdns_f.data['filt'] = request.GET.get('filt', 'rrname')
    else:
        return __renderErrorPage__(request, 'Bad Method')

    if not pdns_f.is_valid():
        return __renderErrorPage__(request, '', {'pdns_form': pdns_f})

    domain = pdns_f.cleaned_data['domain']
    fmt = pdns_f.cleaned_data['fmt']
    absolute = pdns_f.cleaned_data['absolute']
    limit = pdns_f.cleaned_data['limit']
    rrtypes = pdns_f.cleaned_data['rrtypes']
    pretty = pdns_f.cleaned_data['pretty']
    filt_key = pdns_f.cleaned_data['filt']

    if limit is None:
        limit = settings.DNSDB_PAGE_LIMITS[settings.DNSDB_PAGE_LIMIT_DEFAULT]

    if absolute is None:
        absolute = False

    results = passive.request_pdns(domain, absolute, rrtypes, limit, pretty)
    if fmt == 'normal':
        if results['success']:
            context = __createRequestContext__(request, {
                'results': results,
                'inverse': False,
                'pdns_form': pdns_f,
            })
            return render_to_response('pdns_results.html', context)
        else:
            return __renderErrorPage__(request, results['error'],
                                       {'pdns_form': pdns_f})
    elif fmt == 'json':
        return HttpResponse(json.dumps(results),
                            content_type='application/json')
    elif fmt == 'list':
        data = ''
        for set_ in results['sets']:
            # Only handle DNSDB in list format.
            if set_['type'] != 'DNSDB':
                continue
            for rrtype in set_['data'].keys():
                for record in set_['data'][rrtype]:
                    if not isinstance(record[filt_key],
                                      basestring):  #it's a list
                        for item in record[filt_key]:
                            data += '\n%s' % item
                    else:  #it's just a string
                        data += '\n%s' % record[filt_key]
        data = data[1:]
        return HttpResponse(data, content_type='text/plain')
    else:
        return __renderErrorPage__(request, 'Invalid Format.')
Exemplo n.º 4
0
def pdns(request, search_value=None):
    if request.method == 'POST':
        pdns_f_dyn = pdns_form_dynamic(request.POST)
    elif request.method == 'GET':
        pdns_f_dyn = pdns_form_dynamic(QueryDict(''))
        pdns_f_dyn.data['search_value'] = search_value
        pdns_f_dyn.data['result_format'] = \
            request.GET.get('result_format', 'none')

        # Filling form with all empty fields for a forward passive-DNS request
        for passive_field in (passive.PDNS_UI_FIELDS_BASE +
                              passive.PDNS_UI_FIELDS_FORWARD):
            pdns_f_dyn.data[passive_field.django_field_name] = request.GET.get(
                passive_field.django_field_name,
                passive_field.field_value_default)

    else:
        return __renderErrorResponse__(request,
                                       'pdns.html',
                                       'Bad Method')

    if not pdns_f_dyn.is_valid():
        return __renderErrorResponse__(
            request,
            'pdns.html',
            'Unable to verify form data',
            data={"passive_form": pdns_f_dyn})

    # Get clean values for all common passive form fields
    search_value = pdns_f_dyn.cleaned_data['search_value']
    result_format = pdns_f_dyn.cleaned_data['result_format']

    dynamic_fields = {}
    # Obtain cleaned data for every passive-DNS field
    for passive_field in (passive.PDNS_UI_FIELDS_BASE +
                          passive.PDNS_UI_FIELDS_FORWARD):
        if passive_field.source_name not in dynamic_fields:
            dynamic_fields[passive_field.source_name] = {}

        cleaned_value = pdns_f_dyn.cleaned_data[
            passive_field.django_field_name]
        # If user did not enter a required field, grab a defined default value
        if not cleaned_value:
            cleaned_value = passive_field.field_value_default

        dynamic_fields[
            passive_field.source_name][passive_field.field_key] = cleaned_value

    results = passive.request_pdns(search_value, result_format, dynamic_fields)

    if not results['success']:
        return __renderErrorResponse__(request,
                                       'pdns.html',
                                       results['error'],
                                       data={'passive_form': pdns_f_dyn})

    context = __createRequestContext__(data={'results': results['responses'],
                                             'inverse': False,
                                             'pdns_form_dynamic': pdns_f_dyn,
                                             'fmt': result_format})

    return render(request, 'pdns_results.html', context=context)