示例#1
0
def error_429(e, v):

    ip=request.remote_addr

    #get recent violations
    count_429s = r.get(f"429_count_{ip}")
    if not count_429s:
        count_429s=0
    else:
        count_429s=int(count_429s)

    count_429s+=1

    r.set(f"429_count_{ip}", count_429s)
    r.expire(f"429_count_{ip}", 60)

    #if you exceed 15x 429 without a 60s break, you get IP banned for 1 hr:
    if count_429s>=15:
        try:
            print("triggering IP ban", request.remote_addr, session.get("user_id"), session.get("history"))
        except:
            pass
        
        r.set(f"ban_ip_{ip}", int(time.time()))
        r.expire(f"ban_ip_{ip}", 3600)
        return "", 429



    return{"html": lambda: (render_template('errors/429.html', v=v), 429),
           "api": lambda: (jsonify({"error": "429 Too Many Requests"}), 429)
           }
示例#2
0
文件: chat.py 项目: dginovker/ruqqus
def update_chat_count(board):

    count = []
    for uid in SIDS:
        for sid in SIDS[uid]:
            for room in rooms(sid=sid):
                if room == board.fullname and uid not in count:
                    count.append(uid)
                    break

    count = len(count)

    r.set(f"{board.fullname}_chat_count", count)

    emit("count", {"count": str(count)}, to=board.fullname)