Esempio n. 1
0
def get_client_ip(request):
    """
    This fct return the client ip. If not private in the request use it.
    Otherwise, use the ip provided by the client itself.
    """

    client_addr = request.client_addr
    # If the ip_addresses is private, check if the client provided one.
    int_ip = resources.get_int_from_ip(client_addr)
    if ((167772160 <= int_ip <= 184549375)
            or (2886729728 <= int_ip <= 2887778303)
            or (3232235520 <= int_ip <= 3232301055)):  # is_private
        ip = request.json_body.get("ip", "")
        if ip:
            int_ip = resources.get_int_from_ip(ip)
            if not ((167772160 <= int_ip <= 184549375) or
                    (2886729728 <= int_ip <= 2887778303) or
                    (3232235520 <= int_ip <= 3232301055)):  # is_private
                client_addr = ip
    return client_addr
Esempio n. 2
0
def get_client_ip(request):
    """
    This fct return the client ip. If not private in the request use it.
    Otherwise, use the ip provided by the client itself.
    """

    client_addr = request.client_addr
    # If the ip_addresses is private, check if the client provided one.
    int_ip = resources.get_int_from_ip(client_addr)
    if ((167772160 <= int_ip <= 184549375) or
        (2886729728 <= int_ip <= 2887778303) or
        (3232235520 <= int_ip <= 3232301055)):  # is_private
        ip = request.json_body.get("ip", "")
        if ip:
            int_ip = resources.get_int_from_ip(ip)
            if not ((167772160 <= int_ip <= 184549375) or
                    (2886729728 <= int_ip <= 2887778303) or
                    (3232235520 <= int_ip <= 3232301055)):  # is_private
                client_addr = ip
    return client_addr
Esempio n. 3
0
def feedback(request):
    global nb_feedback

    if not request.path_qs.startswith("/feedback.py"):
        raise HTTPBadRequest('Malformed input')

    parameters = request.params
    # override real IP for testing
    ip = parameters.get('ip', request.client_addr)

    # If the client have a private ip, it is on the same network as
    # the server. So we use the server ip as there isn't have geoip
    # info for private ip.
    int_ip = resources.get_int_from_ip(ip)
    if ((167772160 <= int_ip <= 184549375) or
        (2886729728 <= int_ip <= 2887778303) or
        (3232235520 <= int_ip <= 3232301055)):  # is_private
        ip = server_ip

    # Get parameters
    measurements = parameters.get('measurements', '')
    html = not bool(parameters.get('text_only', ''))
    full_page = bool(parameters.get('full_page', ''))

    # Limit the number of ip used in the analysis to limit the time.
    if len(measurements) == '':
        raise HTTPBadRequest('Malformed input. No measurements received.')
    ms = [m for m in measurements.split('-') if m]
    if time_table_idx == 0:
        nb = 20
    elif time_table_idx == 1:
        nb = 15
    else:
        nb = 10
    measurements = '-'.join(ms[-nb:])

    response = display_stats(ip, measurements, html, full_page)
    if full_page:
        response = response.encode('utf-8')
        content_type = 'text/html' if html else 'text/plain'
    else:
        response = json.dumps({'content': response})  # already utf-8 encoded
        # wrap the reponse in jsonp
        response = parameters.get('jsoncallback',
                                  'jsoncallback') + '(' + response + ')'
        content_type = 'application/json'
    res = Response(response,
                   content_type=content_type,
                   charset='utf-8')
    nb_feedback += 1
    return res
Esempio n. 4
0
def feedback(request):
    global nb_feedback

    if not request.path_qs.startswith("/feedback.py"):
        raise HTTPBadRequest('Malformed input')

    parameters = request.params
    # override real IP for testing
    ip = parameters.get('ip', request.client_addr)

    # If the client have a private ip, it is on the same network as
    # the server. So we use the server ip as there isn't have geoip
    # info for private ip.
    int_ip = resources.get_int_from_ip(ip)
    if ((167772160 <= int_ip <= 184549375)
            or (2886729728 <= int_ip <= 2887778303)
            or (3232235520 <= int_ip <= 3232301055)):  # is_private
        ip = server_ip

    # Get parameters
    measurements = parameters.get('measurements', '')
    html = not bool(parameters.get('text_only', ''))
    full_page = bool(parameters.get('full_page', ''))

    # Limit the number of ip used in the analysis to limit the time.
    if len(measurements) == '':
        raise HTTPBadRequest('Malformed input. No measurements received.')
    ms = [m for m in measurements.split('-') if m]
    if time_table_idx == 0:
        nb = 20
    elif time_table_idx == 1:
        nb = 15
    else:
        nb = 10
    measurements = '-'.join(ms[-nb:])

    response = display_stats(ip, measurements, html, full_page)
    if full_page:
        response = response.encode('utf-8')
        content_type = 'text/html' if html else 'text/plain'
    else:
        response = json.dumps({'content': response})  # already utf-8 encoded
        # wrap the reponse in jsonp
        response = parameters.get('jsoncallback',
                                  'jsoncallback') + '(' + response + ')'
        content_type = 'application/json'
    res = Response(response, content_type=content_type, charset='utf-8')
    nb_feedback += 1
    return res