def domains(request, key=None, value=None): if request.method == "POST": search_f = domain_form(request.POST) elif request.method == "GET": search_f = domain_form(QueryDict('')) search_f.data['key'] = key search_f.data['value'] = value search_f.data['fmt'] = request.GET.get('fmt','normal') search_f.data['limit'] = request.GET.get('limit', settings.LIMIT) search_f.data['filt'] = request.GET.get('filt', settings.SEARCH_KEYS[0][0]) else: return __renderErrorPage__(request, 'Bad Method.') if not search_f.is_valid(): return __renderErrorPage__(request, '', {'domain_form' : search_f}) key = urllib.unquote(search_f.cleaned_data['key']) value = urllib.unquote(search_f.cleaned_data['value']) filt_key = search_f.cleaned_data['filt'] fmt = search_f.cleaned_data['fmt'] limit = int(search_f.cleaned_data.get('limit', settings.LIMIT)) if fmt == 'list': #Only filter if a list was requested filt = {filt_key: 1, '_id': False} else: filt = {'_id': False} #All web searches are AJAXy if fmt == "normal": context = __createRequestContext__(request, data = { 'key': urllib.quote(key), 'value': urllib.quote(value), 'domain_form': search_f, }) return render_to_response('domain.html', context) else: if key == "registrant_telephone": value = int(value) results = do_search(key, value, filt=filt, limit=limit) if results['success'] == False: return __renderErrorPage__(request, results['message']) if fmt == 'json': return HttpResponse(json.dumps(results), content_type='application/json') elif fmt == 'list': data = '\n'.join([d[filt_key] for d in results['data']]) return HttpResponse(data, content_type='text/plain') else: return __renderErrorPage__(request, 'Invalid Format.')
def __createRequestContext__(data=None, include_es=True): # Default to adding search forms to every context search_f = domain_form() pdns_f_dyn = pdns_form_dynamic() rpdns_f_dyn = rpdns_form_dynamic() advdomain_f = advdomain_form() ctx_var = {'domain_form': search_f, 'advdomain_form': advdomain_f, 'pdns_form_dynamic': pdns_f_dyn, 'rpdns_form_dynamic': rpdns_f_dyn, 'pdns_sources': [ mod_data.config for mod_data in passive.PDNS_HANDLER_MODS.values()]} if include_es: ctx_var['latest_version'] = handler.lastVersion() ctx_var['health'] = handler.cluster_health().capitalize() ctx_var['record_count'] = handler.record_count() ctx_var['last_import'] = handler.lastUpdate() 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 ctx_var
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)
def __createRequestContext__(data=None): #Default to adding search forms to every context search_f = domain_form() pdns_f_dyn = pdns_form_dynamic() rpdns_f_dyn = rpdns_form_dynamic() advdomain_f = advdomain_form() ctx_var = { 'domain_form': search_f, 'advdomain_form': advdomain_f, 'pdns_form_dynamic': pdns_f_dyn, 'rpdns_form_dynamic': rpdns_f_dyn, 'latest_version': handler.lastVersion(), 'handler': settings.HANDLER, 'pdns_sources':[mod_data.config for mod_data in passive.PDNS_HANDLER_MODS.values()] } if settings.HANDLER == 'es': ctx_var['health'] = handler.cluster_health().capitalize() ctx_var['record_count'] = handler.record_count() ctx_var['last_import'] = handler.lastUpdate() 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 ctx_var
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)
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)
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)
def domains(request, key=None, value=None): if request.method == "POST": search_f = domain_form(request.POST) elif request.method == "GET": search_f = domain_form(QueryDict('')) search_f.data['key'] = key search_f.data['value'] = value search_f.data['fmt'] = request.GET.get('fmt', 'normal') search_f.data['limit'] = request.GET.get('limit', settings.LIMIT) search_f.data['filt'] = request.GET.get('filt', settings.SEARCH_KEYS[0][0]) search_f.data['latest'] = request.GET.get('latest', False) else: return __renderErrorPage__(request, 'Bad Method.') if not search_f.is_valid(): return __renderErrorResponse__(request, 'domain.html', '', {'domain_form': search_f}) key = urllib.unquote(search_f.cleaned_data['key']) value = urllib.unquote(search_f.cleaned_data['value']) filt_key = search_f.cleaned_data['filt'] fmt = search_f.cleaned_data['fmt'] limit = int(search_f.cleaned_data.get('limit', settings.LIMIT)) latest = search_f.cleaned_data['latest'] if latest: low_version = handler.lastVersion() high_version = low_version else: low_version = None high_version = None filt = None if fmt == 'list': #Only filter if a list was requested filt = filt_key #All web searches are AJAXy if fmt == "normal": low_version_js = low_version high_version_js = high_version if low_version == None: low_version_js = 'null' if high_version == None: high_version_js = 'null' context = __createRequestContext__(request, data={ 'key': urllib.quote(key), 'value': urllib.quote(value), 'low_version': low_version_js, 'high_version': high_version_js, 'domain_form': search_f, 'legacy_search': True, }) return render_to_response('domain_results.html', context) else: results = handler.search(key, value, filt=filt, limit=limit, low=low_version) if results['success'] == False: return __renderErrorPage__(request, results['message']) if fmt == 'json': return HttpResponse(json.dumps(results), content_type='application/json') elif fmt == 'list': data = '\n'.join([d[filt_key] for d in results['data']]) return HttpResponse(data, content_type='text/plain') else: return __renderErrorPage__(request, 'Invalid Format.')
def domains(request, key=None, value=None): if request.method == "POST": search_f = domain_form(request.POST) elif request.method == "GET": search_f = domain_form(QueryDict('')) search_f.data['key'] = key search_f.data['value'] = value search_f.data['fmt'] = request.GET.get('fmt','normal') search_f.data['limit'] = request.GET.get('limit', settings.LIMIT) search_f.data['filt'] = request.GET.get('filt', settings.SEARCH_KEYS[0][0]) search_f.data['latest'] = request.GET.get('latest', False) else: return __renderErrorPage__(request, 'Bad Method.') if not search_f.is_valid(): return __renderErrorResponse__(request, 'domain.html', '', {'domain_form' : search_f}) key = urllib.unquote(search_f.cleaned_data['key']) value = urllib.unquote(search_f.cleaned_data['value']) filt_key = search_f.cleaned_data['filt'] fmt = search_f.cleaned_data['fmt'] limit = int(search_f.cleaned_data.get('limit', settings.LIMIT)) latest = search_f.cleaned_data['latest'] if latest: low_version = handler.lastVersion() high_version = low_version else: low_version = None high_version = None filt = None if fmt == 'list': #Only filter if a list was requested filt = filt_key #All web searches are AJAXy if fmt == "normal": low_version_js = low_version high_version_js = high_version if low_version == None: low_version_js = 'null' if high_version == None: high_version_js = 'null' context = __createRequestContext__(request, data = { 'key': urllib.quote(key), 'value': urllib.quote(value), 'low_version': low_version_js, 'high_version': high_version_js, 'domain_form': search_f, 'legacy_search': True, }) return render_to_response('domain_results.html', context) else: results = handler.search(key, value, filt=filt, limit=limit, low = low_version) if results['success'] == False: return __renderErrorPage__(request, results['message']) if fmt == 'json': return HttpResponse(json.dumps(results), content_type='application/json') elif fmt == 'list': data = '\n'.join([d[filt_key] for d in results['data']]) return HttpResponse(data, content_type='text/plain') else: return __renderErrorPage__(request, 'Invalid Format.')