Example #1
0
def about(req):
    master_14 = RedisDriver().master_14
    master_13 = RedisDriver().master_13
    ip = ''
    if 'HTTP_X_FORWARDED_FOR' in req.META:
        ip = req.META['HTTP_X_FORWARDED_FOR']
    else:
        ip = req.META['REMOTE_ADDR']

    ip_attribution = sina_ip(ip)
    if req.method == "POST":
        content = req.POST.get('content', '')
        if content != '':
            key = ip_attribution + ':' + content
            value = time.strftime("%Y-%m-%d %H:%M", time.localtime())
            t = master_13.get(ip_attribution)
            if t is None:
                master_13.hset('message', key, value)
                master_13.setex(ip_attribution, 60, value)
                return HttpResponse(
                    json.dumps({
                        'status': 'ok',
                        'key': key,
                        'value': value
                    }))
            else:
                return HttpResponse(json.dumps({'status': 'fail'}))

    messages = master_13.hgetall('message')

    ips_info = {}
    ips_access = cache.get("ips_access", [])
    if ips_access:
        for ip in ips_access:
            ip_attribution = sina_ip(ip)
            ip_access_time = master_14.get(ip)
            ips_info[ip_attribution] = ip_access_time

    try:
        ips_info = sorted(ips_info.items(), key=lambda d: d[1], reverse=True)
        messages = sorted(messages.items(), key=lambda d: d[1], reverse=True)
    except Exception as e:
        pass
    return render_to_response('about_new.html', {
        "ips_info": ips_info,
        "messages": messages
    }, RequestContext(req))
Example #2
0
def about(req):
    ips_info = {}
    ips_attribution = []
    ips_access = cache.get("ips_access", [])
    if ips_access:
        for ip in ips_access:
            ip_attribution = sina_ip(ip)
            ip_access_time = cache.get(ip,'')
            ips_info[ip_attribution] = ip_access_time

    return render_to_response('about_new.html', {"ips_info": ips_info}, RequestContext(req))
Example #3
0
def about(req):
    master_14 = RedisDriver().master_14
    master_13 = RedisDriver().master_13
    ip = ''
    if 'HTTP_X_FORWARDED_FOR' in req.META:
        ip = req.META['HTTP_X_FORWARDED_FOR']
    else:
        ip = req.META['REMOTE_ADDR']

    ip_attribution = sina_ip(ip)
    if req.method == "POST":
        content = req.POST.get('content', '')
        if content != '':
            key = ip_attribution + ':' + content
            value = time.strftime("%Y-%m-%d %H:%M", time.localtime())
            t = master_13.get(ip_attribution)
            if t is None:
                master_13.hset('message', key, value)
                master_13.setex(ip_attribution, 60, value)
                return HttpResponse(json.dumps({'status': 'ok', 'key': key, 'value': value}))
            else:
                return HttpResponse(json.dumps({'status': 'fail'}))

    messages = master_13.hgetall('message')

    ips_info = {}
    ips_access = cache.get("ips_access", [])
    if ips_access:
        for ip in ips_access:
            ip_attribution = sina_ip(ip)
            ip_access_time = master_14.get(ip)
            ips_info[ip_attribution] = ip_access_time

    try:
        ips_info = sorted(ips_info.items(), key=lambda d: d[1], reverse=True)
        messages = sorted(messages.items(), key=lambda d: d[1], reverse=True)
    except Exception as e:
        pass
    return render_to_response('about_new.html', {"ips_info": ips_info, "messages": messages},
                              RequestContext(req))
Example #4
0
def ips_to_sql(req):
    master_13 = RedisDriver().master_13
    num = master_13.llen("all_ips_list")

    while master_13.llen("all_ips_list") > 0:
        ip = master_13.rpop("all_ips_list")
        ip_attribution = sina_ip(ip)[-3:-1]
        item = Access_ip()
        item.ip = ip
        item.ip_attribution = ip_attribution
        item.save()

    return HttpResponse("{0}-IP-TO_MYSQL".format(num))
Example #5
0
def ips_to_sql(req):
    master_13 = RedisDriver().master_13
    num = master_13.llen("all_ips_list")

    while master_13.llen("all_ips_list") > 0:
        ip = master_13.rpop("all_ips_list")
        ip_attribution = sina_ip(ip)[-3:-1]
        item = Access_ip()
        item.ip = ip
        item.ip_attribution = ip_attribution
        item.save()

    return HttpResponse("{0}-IP-TO_MYSQL".format(num))
Example #6
0
def ips_to_sql(req):
    ips_to_sql = cache.get("ips_to_sql", [])
    num=0
    if ips_to_sql:
        for ip in ips_to_sql:
            ips_to_sql.remove(ip)
            cache.set("ips_to_sql", ips_to_sql)
            ip_attribution = sina_ip(ip)[-3:-1]
            item = Access_ip()
            item.ip = ip
            item.ip_attribution = ip_attribution
            item.save()
            num+=1

    access_log.info("{0}-IP-TO_MYSQL".format(num))
    return HttpResponse("{0}-IP-TO_MYSQL".format(num))