From 377f20ce10816b19ca5a50742441242ef1871631 Mon Sep 17 00:00:00 2001 From: Fluffy Date: Mon, 26 Jun 2023 14:15:45 +0100 Subject: [PATCH] Bugs bugs bugs bugs bugs bugs I love bugs --- Caddy/Caddyfile | 8 ++++++-- TFR/server/api.py | 18 ++++++++++-------- TFR/server/auth.py | 2 +- TFR/server/config.py | 2 ++ TFR/server/extensions.py | 12 ++++++++++++ TFR/server/static/js/search.js | 3 ++- docker-compose.yml | 1 + 7 files changed, 34 insertions(+), 12 deletions(-) diff --git a/Caddy/Caddyfile b/Caddy/Caddyfile index b7a9dd1..b8b54af 100644 --- a/Caddy/Caddyfile +++ b/Caddy/Caddyfile @@ -1,4 +1,8 @@ {$THE_FRONT_ROOMS_DOMAIN} -reverse_proxy tfr:8000 -encode gzip +reverse_proxy tfr:8000 { + header_up X-Forwarded-For {http.request.remote.addr} + header_up X-Real-IP {http.request.remote.addr} +} + +encode gzip diff --git a/TFR/server/api.py b/TFR/server/api.py index 8bcd790..ae93853 100644 --- a/TFR/server/api.py +++ b/TFR/server/api.py @@ -6,7 +6,7 @@ from werkzeug.security import check_password_hash from werkzeug.utils import secure_filename from .models import Scores, Sessions, Users -from .extensions import db +from .extensions import db, logger from .config import ( GAME_VERSION, GAME_VERSIONS, @@ -55,32 +55,34 @@ def post(): difficulty = request.form.get("difficulty", GAME_DIFFICULTY) score = request.form.get("score", 0) + # logger.debug(f"Score upload attempt: {session_key} {version} {difficulty} {score}") + if not session_key: return "No session key provided!" if not score: return "Score is not valid!" try: - float(score) - int(difficulty) + score = float(score) + difficulty = int(difficulty) except TypeError: return "Invalid score and difficulty must be valid numbers!" - if int(difficulty) not in GAME_DIFFICULTIES: + if difficulty not in GAME_DIFFICULTIES: return "Invalid difficulty!" if version not in GAME_VERSIONS: return "Invalid version!" # This is a fix for a bug in the game that we dunno how to actually fix - # if score < 10: - # return "Score is impossible!" + if score < 10: + return "Score is impossible!" session_data = Sessions.query.filter_by(auth_key=session_key).first() if not session_data: return "Authentication failed!" score_upload = Scores( - score=float(score), - difficulty=int(difficulty), + score=score, + difficulty=difficulty, version=version, user_id=session_data.user_id, ) diff --git a/TFR/server/auth.py b/TFR/server/auth.py index e880801..0e6d548 100644 --- a/TFR/server/auth.py +++ b/TFR/server/auth.py @@ -77,4 +77,4 @@ def login(): login_user(user, remember=True) flash("Successfully logged in!", "success") - return redirect(url_for("account.settings")) + return redirect(url_for("account.get_settings")) diff --git a/TFR/server/config.py b/TFR/server/config.py index 9700d34..d92a7bf 100644 --- a/TFR/server/config.py +++ b/TFR/server/config.py @@ -39,3 +39,5 @@ port = 5432 SQLALCHEMY_DATABASE_URI = f"postgresql+psycopg2://{user}:{password}@{host}:{port}/{db}" SQLALCHEMY_TRACK_MODIFICATIONS = False SQLALCHEMY_POOL_RECYCLE = 621 + +LOGS_DIR = "/data/logs" diff --git a/TFR/server/extensions.py b/TFR/server/extensions.py index 9916969..f1f8a30 100644 --- a/TFR/server/extensions.py +++ b/TFR/server/extensions.py @@ -1,9 +1,21 @@ +import logging +from os import path + from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate from flask_assets import Environment from flask_caching import Cache from flask_login import LoginManager +from .config import LOGS_DIR + +logger = logging +logger.getLogger(path.join(LOGS_DIR, "server.log")) +logger.basicConfig( + level=logging.DEBUG, + format="%(asctime)s %(levelname)s %(name)s %(threadName)s : %(message)s", +) + db = SQLAlchemy() migrate = Migrate() assets = Environment() diff --git a/TFR/server/static/js/search.js b/TFR/server/static/js/search.js index 4cc1638..bed45aa 100644 --- a/TFR/server/static/js/search.js +++ b/TFR/server/static/js/search.js @@ -54,7 +54,8 @@ function getSearch() { el.innerHTML = user; el.onmousedown = function (event) { event.preventDefault(); - search = user.toString(); + search = document.querySelector('#search'); + search.value = user.toString(); search.blur(); } hint.appendChild(el); diff --git a/docker-compose.yml b/docker-compose.yml index 7fde659..36aa71a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -38,6 +38,7 @@ services: volumes: - ./TFR/storage/migrations:/data/migrations - ./TFR/storage/uploads:/data/uploads + - ./TFR/storage/logs:/data/logs environment: FLASK_KEY: ${THE_FRONT_ROOMS_SECRETE_KEY} DB_USER: ${POSTGRES_USER}