WIP Limit one chat every 30 seconds per IP
This commit is contained in:
parent
af9213cab6
commit
1725ecd4c7
@ -1,8 +1,12 @@
|
||||
import calendar
|
||||
import logging
|
||||
import subprocess
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
import redis
|
||||
from flask import Flask, request
|
||||
|
||||
conn = redis.Redis('localhost')
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
@ -15,6 +19,12 @@ def setup_logging():
|
||||
@app.route('/chat/', methods=['POST'])
|
||||
def send_chat():
|
||||
if request.method == 'POST':
|
||||
ip = request.headers.get('X-Forwarded-For', request.remote_addr)
|
||||
recent_ips = conn.hgetall("minecraft_chat_recent_ips")
|
||||
now = datetime.utcnow()
|
||||
if ip in recent_ips:
|
||||
if (now - datetime.fromutctimestamp(recent_ips[ip])) > timedelta.seconds(30):
|
||||
recent_ips[ip] = calendar.timegm(now.utctimetuple())
|
||||
if request.form.get('email', None):
|
||||
return 'Text was entered into honeypot!', 200
|
||||
if not request.form.get('say-text', None):
|
||||
@ -27,5 +37,6 @@ def send_chat():
|
||||
'/say {}\015'.format(request.form['say-text'])])
|
||||
return 'Sending chat: ' + request.form.get('say-username', '') + ': ' + request.form['say-text']
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host='0.0.0.0', port="8888")
|
||||
|
Loading…
Reference in New Issue
Block a user