Exemple #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)
           }
Exemple #2
0
    def chat_count(self):
        count = r.get(f"{self.fullname}_chat_count")

        if count == None:
            count = 0

        return count