예제 #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 = do_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.')
예제 #2
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)
예제 #3
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)
예제 #4
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)
예제 #5
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)
예제 #6
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.')