From 05e8dec716d0e8bf9cc53fceda89cd3661d4d0dc Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 21 Oct 2022 13:15:26 +0200 Subject: [PATCH] allow multiple hosts (thanks JC I love you) --- files/__main__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/files/__main__.py b/files/__main__.py index cfd06350a..5a15843db 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -25,7 +25,7 @@ app.jinja_env.add_extension('jinja2.ext.do') faulthandler.enable() app.config['SECRET_KEY'] = environ.get('SECRET_KEY').strip() -app.config["SERVER_NAME"] = environ.get("SITE").strip() +SITE = environ.get("SITE").strip() app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 3153600 app.config["SESSION_COOKIE_NAME"] = "session_" + environ.get("SITE_NAME").strip().lower() app.config['MAX_CONTENT_LENGTH'] = 100 * 1024 * 1024 @@ -84,11 +84,11 @@ def before_request(): with open('/site_settings.json', 'r', encoding='utf_8') as f: app.config['SETTINGS'] = json.load(f) ### WPD TEMP #### - if request.host != app.config["SERVER_NAME"] and app.config["SERVER_NAME"] != "watchpeopledie.co": + if request.host != SITE and SITE != "watchpeopledie.co": return {"error": "Unauthorized host provided"}, 403 #### END WPD TEMP #### # uncomment below after done with WPD migration - # if request.host != app.config["SERVER_NAME"]: return {"error": "Unauthorized host provided."}, 403 + # if request.host != SITE: return {"error": "Unauthorized host provided."}, 403 if request.headers.get("CF-Worker"): return {"error": "Cloudflare workers are not allowed to access this website."}, 403 if not app.config['SETTINGS']['Bots'] and request.headers.get("Authorization"): abort(403) @@ -98,7 +98,7 @@ def before_request(): g.inferior_browser = 'iphone' in ua or 'ipad' in ua or 'ipod' in ua or 'mac os' in ua or ' firefox/' in ua #### WPD TEMP #### temporary WPD migration logic: redirect to / - if request.host == 'watchpeopledie.co' and app.config["SERVER_NAME"] == "watchpeopledie.co": + if request.host == 'watchpeopledie.co' and SITE == "watchpeopledie.co": request.path = request.path.rstrip('/') if not request.path: request.path = '/' if request.path != '/':