예제 #1
0
파일: views.py 프로젝트: mpars0ns/WhoDat
def pdns_r(request, key=None, value=None):
    if request.method == 'POST':
        pdns_r_f = pdns_r_form(request.POST)
    elif request.method == 'GET':  #Craft a form to make it easier to validate
        pdns_r_f = pdns_r_form(QueryDict(''))
        pdns_r_f.data['key'] = key
        pdns_r_f.data['value'] = value
        pdns_r_f.data['rrtypes'] = request.GET.getlist(
            'rrtypes', [settings.RRTYPE_KEYS[0][0]])
        pdns_r_f.data['fmt'] = request.GET.get('fmt', 'normal')
        pdns_r_f.data['limit'] = request.GET.get(
            'limit',
            settings.DNSDB_PAGE_LIMITS[settings.DNSDB_PAGE_LIMIT_DEFAULT])
        pdns_r_f.data['pretty'] = request.GET.get('pretty', True)
        pdns_r_f.data['filt'] = request.GET.get('filt', 'rrname')
    else:
        return __renderErrorPage__(request, 'Unsupported Method.')

    if not pdns_r_f.is_valid():
        return __renderErrorPage__(request, '', {'pdns_r_form': pdns_r_f})

    key = pdns_r_f.cleaned_data['key']
    value = pdns_r_f.cleaned_data['value']
    fmt = pdns_r_f.cleaned_data['fmt']
    limit = pdns_r_f.cleaned_data['limit']
    pretty = pdns_r_f.cleaned_data['pretty']
    filt_key = pdns_r_f.cleaned_data['filt']
    rrtypes = pdns_r_f.cleaned_data['rrtypes']

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

    results = passive.request_pdns_reverse(key, value, rrtypes, limit, pretty)
    if fmt == 'normal':
        if results['success']:
            context = __createRequestContext__(request, {
                'results': results,
                'inverse': True,
                'pdns_r_form': pdns_r_f
            })
            return render_to_response('pdns.html', context)
        else:
            return __renderErrorPage__(request, results['error'],
                                       {'pdns_r_form': pdns_r_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.')
예제 #2
0
파일: views.py 프로젝트: LubyRuffy/WhoDat
def pdns_r(request, key = None, value = None):
    if request.method == 'POST':
        pdns_r_f = pdns_r_form(request.POST)
    elif request.method == 'GET': #Craft a form to make it easier to validate
        pdns_r_f = pdns_r_form(QueryDict(''))
        pdns_r_f.data['key'] = key
        pdns_r_f.data['value']= value
        pdns_r_f.data['rrtypes'] = request.GET.getlist('rrtypes', [settings.RRTYPE_KEYS[0][0]])
        pdns_r_f.data['fmt'] = request.GET.get('fmt','normal')
        pdns_r_f.data['limit'] = request.GET.get('limit', settings.DNSDB_PAGE_LIMITS[settings.DNSDB_PAGE_LIMIT_DEFAULT])
        pdns_r_f.data['pretty'] = request.GET.get('pretty', True)
        pdns_r_f.data['filt'] = request.GET.get('filt', 'rrname')
    else:
        return __renderErrorPage__(request, 'Unsupported Method.')

    if not pdns_r_f.is_valid():
        return __renderErrorPage__(request, '', {'pdns_r_form' : pdns_r_f})

    key = pdns_r_f.cleaned_data['key']
    value = pdns_r_f.cleaned_data['value']
    fmt = pdns_r_f.cleaned_data['fmt']
    limit = pdns_r_f.cleaned_data['limit']
    pretty = pdns_r_f.cleaned_data['pretty']
    filt_key = pdns_r_f.cleaned_data['filt']
    rrtypes = pdns_r_f.cleaned_data['rrtypes']


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

    results = passive.request_pdns_reverse(key, value, rrtypes, limit, pretty)
    if fmt == 'normal':
        if results['success']:
            context = __createRequestContext__(request, {'results': results, 'inverse': True, 'pdns_r_form': pdns_r_f})
            return render_to_response('pdns_results.html', context)
        else:
            return __renderErrorPage__(request, results['error'], {'pdns_r_form':pdns_r_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.')
예제 #3
0
def __createRequestContext__(request, data=None):
    #Default to adding search forms to every context
    search_f = domain_form()
    pdns_f = pdns_form()
    pdns_r_f = pdns_r_form()
    advdomain_f = advdomain_form()

    ctx_var = {
        'domain_form': search_f,
        'advdomain_form': advdomain_f,
        'pdns_form': pdns_f,
        'pdns_r_form': pdns_r_f,
        'latest_version': handler.lastVersion(),
        'handler': settings.HANDLER
    }

    if settings.HANDLER == 'es':
        ctx_var['health'] = handler.cluster_health().capitalize()
        ctx_var['record_count'] = handler.record_count()
        ctx_var['last_import'] = handler.lastVersion()
        ctx_var['scripting'] = settings.ES_SCRIPTING_ENABLED

    if data is not None:
        ctx_var.update(data)
        if 'active' not in data:
            if 'pdns_form' in data:
                ctx_var['active'] = 1
            elif 'pdns_r_form' in data:
                ctx_var['active'] = 2
            else:
                ctx_var['active'] = 0

    return RequestContext(request, ctx_var)
예제 #4
0
파일: views.py 프로젝트: LubyRuffy/WhoDat
def __createRequestContext__(request, data = None):
    #Default to adding search forms to every context
    search_f = domain_form()
    pdns_f = pdns_form()
    pdns_r_f = pdns_r_form()
    advdomain_f = advdomain_form()

    ctx_var = { 'domain_form' : search_f,
                'advdomain_form': advdomain_f,
                'pdns_form': pdns_f,
                'pdns_r_form': pdns_r_f,
                'latest_version': handler.lastVersion(),
                'handler': settings.HANDLER
              } 

    if settings.HANDLER == 'es':
        ctx_var['health'] = handler.cluster_health().capitalize()
        ctx_var['record_count'] = handler.record_count()
        ctx_var['last_import'] = handler.lastVersion()
        ctx_var['scripting'] = settings.ES_SCRIPTING_ENABLED

    if data is not None:
        ctx_var.update(data)
        if 'active' not in data:
            if 'pdns_form' in data:
                ctx_var['active'] = 1
            elif 'pdns_r_form' in data:
                ctx_var['active'] = 2
            else:
                ctx_var['active'] = 0

    return RequestContext(request, ctx_var)
예제 #5
0
def __createRequestContext__(request, data = None):
    #Default to adding search forms to every context
    search_f = domain_form()
    pdns_f = pdns_form()
    pdns_r_f = pdns_r_form()
   
    ctx_var = { 'domain_form' : search_f,
                'pdns_form': pdns_f,
                'pdns_r_form': pdns_r_f,
              } 

    if data is not None:
        ctx_var.update(data)
        if 'active' not in data:
            if 'pdns_form' in data:
                ctx_var['active'] = 1
            elif 'pdns_r_form' in data:
                ctx_var['active'] = 2
            else:
                ctx_var['active'] = 0

    return RequestContext(request, ctx_var)
예제 #6
0
파일: views.py 프로젝트: mpars0ns/WhoDat
def __createRequestContext__(request, data=None):
    #Default to adding search forms to every context
    search_f = domain_form()
    pdns_f = pdns_form()
    pdns_r_f = pdns_r_form()

    ctx_var = {
        'domain_form': search_f,
        'pdns_form': pdns_f,
        'pdns_r_form': pdns_r_f,
        'latest_version': handler.lastVersion()
    }

    if data is not None:
        ctx_var.update(data)
        if 'active' not in data:
            if 'pdns_form' in data:
                ctx_var['active'] = 1
            elif 'pdns_r_form' in data:
                ctx_var['active'] = 2
            else:
                ctx_var['active'] = 0

    return RequestContext(request, ctx_var)