diff --git a/env b/env index 2e376463b..81b53135a 100644 --- a/env +++ b/env @@ -1,6 +1,5 @@ export FLASK_APP="/rDrama/files/cli:app" export SITE="localhost" -export SITE_HOSTS="localhost,127.0.0.1" export SITE_NAME="rDrama" export SECRET_KEY="blahblahblah" export DATABASE_URL="postgresql://postgres@localhost:5432" diff --git a/files/__main__.py b/files/__main__.py index ced14b7a2..8a4090b54 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -25,8 +25,8 @@ app.jinja_env.add_extension('jinja2.ext.do') faulthandler.enable() SITE = environ.get("SITE").strip() -SITE_HOSTS = environ.get("SITE_HOSTS").split(',') +app.config['SERVER_NAME'] = SITE app.config['SECRET_KEY'] = environ.get('SECRET_KEY').strip() app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 3153600 app.config["SESSION_COOKIE_NAME"] = "session_" + environ.get("SITE_NAME").strip().lower() @@ -75,9 +75,7 @@ if not path.isfile(f'/site_settings.json'): @app.before_request def before_request(): - if SITE != 'localhost': - app.config['SESSION_COOKIE_DOMAIN'] = f'.{request.host}' - if request.host == 'marsey.world' and request.path != '/kofi': + if SITE == 'marsey.world' and request.path != '/kofi': abort(404) g.agent = request.headers.get("User-Agent") @@ -90,7 +88,7 @@ def before_request(): with open('/site_settings.json', 'r', encoding='utf_8') as f: app.config['SETTINGS'] = json.load(f) - if request.host not in SITE_HOSTS: + 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 diff --git a/files/classes/comment.py b/files/classes/comment.py index 7a97a666e..e7c2fcc6a 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -11,7 +11,6 @@ from files.helpers.const import * from files.helpers.regex import * from files.helpers.lazy import lazy from files.helpers.sorting_and_time import * -from files.helpers.hosts import current_host from .flags import CommentFlag from .votes import CommentVote from .saves import CommentSaveRelationship @@ -183,12 +182,12 @@ class Comment(Base): @property @lazy def permalink(self): - return f"{current_host()}{self.shortlink}" + return f"{SITE_FULL}{self.shortlink}" @property @lazy def log_link(self): - return f"{current_host()}/transfers/{self.id}" + return f"{SITE_FULL}/transfers/{self.id}" @property @lazy diff --git a/files/classes/submission.py b/files/classes/submission.py index aa2093654..27dfdea36 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -10,7 +10,6 @@ from files.helpers.const import * from files.helpers.regex import * from files.helpers.lazy import lazy from files.helpers.sorting_and_time import make_age_string -from files.helpers.hosts import current_host from .flags import Flag from .comment import Comment, normalize_urls_runtime from .saves import SaveRelationship @@ -139,7 +138,7 @@ class Submission(Base): @property @lazy def permalink(self): - return current_host() + self.shortlink + return SITE_FULL + self.shortlink @property @lazy @@ -164,17 +163,16 @@ class Submission(Base): @property @lazy def thumb_url(self): - host = current_host() - if self.over_18: return f"{host}/assets/images/nsfw.webp?v=1" - elif not self.url: return f"{host}/assets/images/{SITE_NAME}/default_text.webp?v=2" + if self.over_18: return f"{SITE_FULL}/assets/images/nsfw.webp?v=1" + elif not self.url: return f"{SITE_FULL}/assets/images/{SITE_NAME}/default_text.webp?v=2" elif self.thumburl: - if self.thumburl.startswith('/'): return host + self.thumburl + if self.thumburl.startswith('/'): return SITE_FULL + self.thumburl return self.thumburl - elif self.is_youtube or self.is_video: return f"{host}/assets/images/default_thumb_video.webp?v=1" - elif self.is_audio: return f"{host}/assets/images/default_thumb_audio.webp?v=1" + elif self.is_youtube or self.is_video: return f"{SITE_FULL}/assets/images/default_thumb_video.webp?v=1" + elif self.is_audio: return f"{SITE_FULL}/assets/images/default_thumb_audio.webp?v=1" elif self.domain.split('.')[0] == SITE.split('.')[0]: - return f"{host}/assets/images/{SITE_NAME}/site_preview.webp?v=3009" - else: return f"{host}/assets/images/default_thumb_link.webp?v=1" + return f"{SITE_FULL}/assets/images/{SITE_NAME}/site_preview.webp?v=3009" + else: return f"{SITE_FULL}/assets/images/default_thumb_link.webp?v=1" @property @lazy @@ -254,7 +252,7 @@ class Submission(Base): if not url: return '' - if url.startswith('/'): return current_host() + url + if url.startswith('/'): return SITE_FULL + url url = normalize_urls_runtime(url, v) diff --git a/files/classes/user.py b/files/classes/user.py index efb91a80e..589c4701a 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -24,7 +24,6 @@ from .sub_join import * from .hats import * from files.__main__ import Base, cache from files.helpers.security import * -from files.helpers.hosts import current_host from copy import deepcopy import random from os import remove, path @@ -756,13 +755,12 @@ class User(Base): @property @lazy def profile_url(self): - host = current_host() if self.agendaposter: return f"{host}/e/chudsey.webp" if self.rainbow: - return f"{host}/e/marseysalutepride.webp" + return f"{SITE_FULL}/e/marseysalutepride.webp" if self.profileurl: - if self.profileurl.startswith('/'): return host + self.profileurl + if self.profileurl.startswith('/'): return SITE_FULL + self.profileurl return self.profileurl return f"{host}/assets/images/default-profile-pic.webp?v=1008" diff --git a/files/helpers/const.py b/files/helpers/const.py index 605fbdb1f..dcdfba078 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -11,7 +11,6 @@ from os import path SITE = environ.get("SITE").strip() SITE_NAME = environ.get("SITE_NAME").strip() -SITE_HOSTS = environ.get("SITE_HOSTS").strip().split(',') SECRET_KEY = environ.get("SECRET_KEY").strip() PROXY_URL = environ.get("PROXY_URL").strip() GIPHY_KEY = environ.get('GIPHY_KEY').strip() @@ -41,7 +40,7 @@ MAILGUN_KEY = environ.get("MAILGUN_KEY").strip() DESCRIPTION = environ.get("DESCRIPTION").strip() CF_KEY = environ.get("CF_KEY").strip() CF_ZONE = environ.get("CF_ZONE").strip() -TELEGRAM_LINK = environ.get("TELEGRAM_LINK", "blahblahblah").strip() +TELEGRAM_LINK = environ.get("TELEGRAM_LINK").strip() GLOBAL = environ.get("GLOBAL", "").strip() blackjack = environ.get("BLACKJACK", "").strip() diff --git a/files/helpers/hosts.py b/files/helpers/hosts.py deleted file mode 100644 index 47eb832ac..000000000 --- a/files/helpers/hosts.py +++ /dev/null @@ -1,8 +0,0 @@ -from .const import * - -def current_host(): - if SITE == "localhost": prefix = "http://" - else: prefix = "https://" - - if request.host not in SITE_HOSTS: return SITE_FULL - return prefix + request.host diff --git a/files/helpers/jinja2.py b/files/helpers/jinja2.py index 490d9ea9c..b4ad87454 100644 --- a/files/helpers/jinja2.py +++ b/files/helpers/jinja2.py @@ -6,7 +6,6 @@ from .const import * import time from files.helpers.assetcache import assetcache_path from files.helpers.wrappers import calc_users -from files.helpers.hosts import current_host @app.template_filter("post_embed") def post_embed(id, v): @@ -53,5 +52,4 @@ def inject_constants(): "EMAIL_REGEX_PATTERN":EMAIL_REGEX_PATTERN, "CONTENT_SECURITY_POLICY_DEFAULT":CONTENT_SECURITY_POLICY_DEFAULT, "CONTENT_SECURITY_POLICY_HOME":CONTENT_SECURITY_POLICY_HOME, - "current_host": current_host() } diff --git a/files/helpers/wrappers.py b/files/helpers/wrappers.py index 8be3c61cd..86c31c803 100644 --- a/files/helpers/wrappers.py +++ b/files/helpers/wrappers.py @@ -97,7 +97,7 @@ def auth_desired_with_logingate(f): if app.config['SETTINGS']['login_required'] and not v: abort(401) #### WPD TEMP #### disable this /logged_out thing on .co - if request.host == 'watchpeopledie.co': + if SITE == 'watchpeopledie.co': return make_response(f(*args, v=v, **kwargs)) #### END WPD TEMP #### diff --git a/files/routes/front.py b/files/routes/front.py index e30e62426..5ec23171d 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -21,13 +21,13 @@ def front_all(v, sub=None, subdomain=None): from files.helpers.security import generate_hash, validate_hash from datetime import datetime now = datetime.utcnow() - if request.host == 'watchpeopledie.co': + if SITE == 'watchpeopledie.co': if v and not v.admin_level and not v.id <= 9: # security: don't auto login admins or bots hash = generate_hash(f'{v.id}+{now.year}+{now.month}+{now.day}+{now.hour}+WPDusermigration') return redirect(f'https://watchpeopledie.tv/logged_out?user={v.id}&code={hash}', 301) else: return redirect('https://watchpeopledie.tv/logged_out', 301) - elif request.host == 'watchpeopledie.tv' and not v: # security: don't try to login people into accounts more than once + elif SITE == 'watchpeopledie.tv' and not v: # security: don't try to login people into accounts more than once req_user = request.values.get('user') req_code = request.values.get('code') if req_user and req_code: diff --git a/files/routes/login.py b/files/routes/login.py index 62ec876be..7a2df43e0 100644 --- a/files/routes/login.py +++ b/files/routes/login.py @@ -5,7 +5,6 @@ from files.helpers.const import * from files.helpers.regex import * from files.helpers.actions import * from files.helpers.get import * -from files.helpers.hosts import current_host import requests import secrets @@ -190,7 +189,7 @@ def sign_up_get(v): if not app.config['SETTINGS']['Signups']: return {"error": "New account registration is currently closed. Please come back later."}, 403 - if v: return redirect(current_host()) + if v: return redirect(SITE_FULL) ref = request.values.get("ref") diff --git a/files/routes/posts.py b/files/routes/posts.py index 3fe88bd0d..82a8a91a8 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -11,7 +11,6 @@ from files.helpers.slots import * from files.helpers.get import * from files.helpers.actions import * from files.helpers.sorting_and_time import * -from files.helpers.hosts import current_host from files.classes import * from flask import * from io import BytesIO @@ -537,7 +536,7 @@ def thumbnail_thread(pid): fetch_url = post.url if fetch_url.startswith('/') and '\\' not in fetch_url: - fetch_url = f"{SITE}{fetch_url}" + fetch_url = f"{SITE_FULL}{fetch_url}" headers={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.72 Safari/537.36"} diff --git a/files/routes/users.py b/files/routes/users.py index 46afdf705..87ec8a4e5 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -9,7 +9,6 @@ from files.helpers.sanitize import * from files.helpers.const import * from files.helpers.sorting_and_time import * from files.helpers.actions import * -from files.helpers.hosts import current_host from files.mail import * from flask import * from files.__main__ import app, limiter, db_session @@ -759,7 +758,7 @@ def u_username(username, v=None): if username != u.username: - return redirect(current_host() + request.full_path.replace(username, u.username)) + return redirect(SITE_FULL + request.full_path.replace(username, u.username)) if v and v.id not in (u.id, DAD_ID) and u.viewers_recorded: g.db.flush()