initial commit of ban detection project, still missing features and have to do more in regards to js

This commit is contained in:
jenz
2023-02-02 00:19:27 +01:00
parent 0b300cf5f4
commit b080d9cc6f
11 changed files with 870 additions and 0 deletions
+38
View File
@@ -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)
+29
View File
@@ -0,0 +1,29 @@
python3 app.py
pip3 list:
Package Version
---------------------- ---------
certifi 2022.6.15
charset-normalizer 2.1.0
click 8.1.3
Flask 2.1.2
Flask-Cors 3.0.10
idna 3.3
importlib-metadata 4.12.0
itsdangerous 2.1.2
Jinja2 3.1.2
MarkupSafe 2.1.1
mysql-connector-python 8.0.32
pip 20.3.4
pkg-resources 0.0.0
protobuf 3.20.3
requests 2.28.1
setuptools 44.1.1
six 1.16.0
urllib3 1.26.9
uWSGI 2.0.20
waitress 2.1.2
Werkzeug 2.1.2
zipp 3.8.0
+10
View File
@@ -0,0 +1,10 @@
import mysql.connector
token = ""
def get_connection_ban_detector():
return mysql.connector.connect(
host="127.0.0.1",
port=3306,
user="",
password="")