initial commit of ban detection project, still missing features and have to do more in regards to js
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
#!/home/nonroot/receive_motd_requests/venv/bin/python3
|
||||
from flask import Flask
|
||||
from flask import request
|
||||
from flask_cors import CORS
|
||||
from settings import token, get_connection_ban_detector
|
||||
|
||||
app = Flask(__name__)
|
||||
CORS(app)
|
||||
|
||||
@app.route('/', methods = ['POST'])
|
||||
def get_answer():
|
||||
if request.remote_addr != "127.0.0.1":
|
||||
return "invalid"
|
||||
try:
|
||||
content = request.form.get('name')
|
||||
name = content.split(" ")[0]
|
||||
ip = content.split(" ")[1]
|
||||
#print(name, ip)
|
||||
if name is None or ip is None:
|
||||
return ""
|
||||
except:
|
||||
return ""
|
||||
name = name.replace('"', '') #fingerprint
|
||||
ip = ip.replace('"', '')
|
||||
with get_connection_ban_detector() as conn:
|
||||
with conn.cursor(buffered=True) as cur: #wtf is this buffered shit even
|
||||
sql_statement = """
|
||||
INSERT IGNORE INTO ban_detector.ban_detector (fingerprint, ip) VALUES (%s, %s);
|
||||
"""
|
||||
cur.execute(sql_statement, [name, ip])
|
||||
conn.commit()
|
||||
conn.close()
|
||||
#print("name: ", name, ' ip: ', ip)
|
||||
return ""
|
||||
|
||||
if __name__ == "__main__":
|
||||
from waitress import serve
|
||||
serve(app, host="localhost", port=5085)
|
||||
Reference in New Issue
Block a user