Esempio n. 1
0
def domain_diff(request, domainName=None, v1=None, v2=None):
    if request.method == "GET":
        if not domainName or not v1 or not v2:
            return __renderErrorJSON__('Required Parameters Missing')
        domainName = urllib.unquote(domainName)

        try:
            v1_res = handler.search('domainName',
                                    domainName,
                                    filt=None,
                                    low=v1)
        except Exception as e:
            return __renderErrorJSON__(str(e))

        try:
            v2_res = handler.search('domainName',
                                    domainName,
                                    filt=None,
                                    low=v2)
        except Exception as e:
            return __renderErrorJSON__(str(e))

        try:
            v1_res = v1_res['data'][0]
            v2_res = v2_res['data'][0]
        except:
            return __renderErrorJSON__("Did not find results")

        keylist = set(v1_res.keys()).union(set(v2_res.keys()))

        keylist.remove('Version')
        keylist.remove('UpdateVersion')
        keylist.remove('domainName')
        keylist.remove('dataFirstSeen')

        output = {}
        data = {}
        for key in keylist:
            if key in v1_res and key in v2_res:
                if v1_res[key] == v2_res[key]:
                    data[key] = v1_res[key]
                else:
                    data[key] = [v1_res[key], v2_res[key]]
            else:
                try:
                    data[key] = [v1_res[key], '']
                except:
                    data[key] = ['', v2_res[key]]

        output['success'] = True
        output['data'] = data
        return HttpResponse(json.dumps(output),
                            content_type='application/json')
    else:
        return __renderErrorJSON__('Bad Method.')
Esempio n. 2
0
def domains(request, key, value, low = None, high = None):
    if key is None or value is None:
        return __renderErrorJSON__('Missing Key and/or Value')

    if key not in [keys[0] for keys in settings.SEARCH_KEYS]:
        return __renderErrorJSON__('Invalid Key')


    key = urllib.unquote(key)
    value = urllib.unquote(value)
    
    #TODO Support Post -- need to add cooresponding form
    if request.method == "GET":
        limit = int(request.GET.get('limit', settings.LIMIT))
    else:
        return __renderErrorJSON__('Unsupported Method')

    versionSort = False
    if key == 'domainName':
        versionSort = True

    results = handler.search(key, value, filt = None, low = low, high = high, versionSort = versionSort)
    if results['success'] == False:
        return __renderErrorJSON__(results['message'])

    return HttpResponse(json.dumps(results), content_type='application/json')
Esempio n. 3
0
def domains(request, key, value, low = None, high = None):
    if key is None or value is None:
        return __renderErrorJSON__('Missing Key and/or Value')

    if key not in [keys[0] for keys in settings.SEARCH_KEYS]:
        return __renderErrorJSON__('Invalid Key')


    key = urllib.unquote(key)
    value = urllib.unquote(value)
    
    #TODO Support Post -- need to add cooresponding form
    if request.method == "GET":
        limit = int(request.GET.get('limit', settings.LIMIT))
    else:
        return __renderErrorJSON__('Unsupported Method')

    versionSort = False
    if key == 'domainName':
        versionSort = True

    results = handler.search(key, value, filt = None, low = low, high = high, versionSort = versionSort)
    if results['success'] == False:
        return __renderErrorJSON__(results['message'])

    return HttpResponse(json.dumps(results), content_type='application/json')
Esempio n. 4
0
def domain(request, domainName=None, low=None, high=None):
    if request.method == "GET":
        if not domainName:
            return __renderErrorJSON__('Requires Domain Name Argument')
        domainName = urllib.unquote(domainName)

        results = handler.search('domainName',
                                 domainName,
                                 filt=None,
                                 low=low,
                                 high=high,
                                 versionSort=True)

        return HttpResponse(json.dumps(results),
                            content_type='application/json')
        if results['success']:  # Clean up the data
            results['data'] = results['data'][0]
            del results['total']
            del results['avail']
            return HttpResponse(json.dumps(results),
                                content_type='application/json')
        else:
            return __renderErrorJSON__(results['message'])
    else:
        return __renderErrorJSON__('Bad Method.')
Esempio n. 5
0
def domain_diff(request, domainName = None, v1 = None, v2 = None):
    if request.method == "GET":
        if not domainName or not v1 or not v2:
            return __renderErrorJSON__('Required Parameters Missing')
        domainName = urllib.unquote(domainName)

        v1_res = handler.search('domainName', domainName, filt=None, low = int(v1))
        v2_res = handler.search('domainName', domainName, filt=None, low = int(v2))

        try:
            v1_res = v1_res['data'][0]
            v2_res = v2_res['data'][0]
        except:
            return __renderErrorJSON__("Did not find results")

        keylist = set(v1_res.keys()).union(set(v2_res.keys()))

        keylist.remove('Version')
        keylist.remove('domainName')
        keylist.remove('dataUniqueID')
        keylist.remove('dataFirstSeen')

        output = {}
        data = {}
        for key in keylist: 
            if key in v1_res and key in v2_res:
                if v1_res[key] == v2_res[key]:
                    data[key] = v1_res[key]
                else:
                    data[key] = [v1_res[key], v2_res[key]]
            else:
                try:
                    data[key] = [v1_res[key], '']
                except:
                    data[key] = ['', v2_res[key]]
        
        output['success'] = True 
        output['data'] = data
        return HttpResponse(json.dumps(output), content_type='application/json')
    else:
        return __renderErrorJSON__('Bad Method.')
Esempio n. 6
0
def domain(request, domainName = None, low = None, high = None):
    if request.method == "GET":
        if not domainName:
            return __renderErrorJSON__('Requires Domain Name Argument')
        domainName = urllib.unquote(domainName)

        results = handler.search('domainName', domainName, filt=None, low = low, high = high, versionSort = True)

        return HttpResponse(json.dumps(results), content_type='application/json')
        if results['success']: #Clean up the data
            results['data'] = results['data'][0]
            del results['total']
            del results['avail']
            return HttpResponse(json.dumps(results), content_type='application/json')
        else:
            return __renderErrorJSON__(results['message'])
    else:
        return __renderErrorJSON__('Bad Method.')
Esempio n. 7
0
def domain(request, domainName=None, low=None, high=None):
    if request.method == "GET":
        if not domainName:
            return __renderErrorJSON__('Requires Domain Name Argument')
        domainName = urllib.unquote(domainName)

        try:
            results = handler.search('domainName',
                                     domainName,
                                     filt=None,
                                     low=low,
                                     high=high,
                                     versionSort=True)
        except Exception as e:
            return __renderErrorJSON__(str(e))

        return HttpResponse(json.dumps(results),
                            content_type='application/json')

    else:
        return __renderErrorJSON__('Bad Method.')
Esempio n. 8
0
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.')
Esempio n. 9
0
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.')