diff --git a/files/__main__.py b/files/__main__.py index 4b2dd25a9..69da97fc7 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -23,39 +23,28 @@ app.jinja_env.cache = {} app.jinja_env.auto_reload = True faulthandler.enable() -app.config["SITE_NAME"]=environ.get("SITE_NAME").strip() -app.config["GUMROAD_LINK"]=environ.get("GUMROAD_LINK", "https://marsey1.gumroad.com/l/tfcvri").strip() -app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False -app.config['DATABASE_URL'] = environ.get("DATABASE_URL", "postgresql://postgres@localhost:5432") app.config['SECRET_KEY'] = environ.get('MASTER_KEY') app.config["SERVER_NAME"] = environ.get("DOMAIN").strip() app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 3153600 app.config["SESSION_COOKIE_NAME"] = "session_" + environ.get("SITE_NAME").strip().lower() -app.config["VERSION"] = "1.0.0" app.config['MAX_CONTENT_LENGTH'] = 100 * 1024 * 1024 app.config["SESSION_COOKIE_SECURE"] = True app.config["SESSION_COOKIE_SAMESITE"] = "Lax" app.config["PERMANENT_SESSION_LIFETIME"] = 60 * 60 * 24 * 365 app.config['SESSION_REFRESH_EACH_REQUEST'] = False -app.config["DEFAULT_COLOR"] = environ.get("DEFAULT_COLOR", "ff0000").strip() -app.config["DEFAULT_THEME"] = environ.get("DEFAULT_THEME", "midnight").strip() -app.config["FORCE_HTTPS"] = 1 -app.config["UserAgent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36" -app.config["HCAPTCHA_SITEKEY"] = environ.get("HCAPTCHA_SITEKEY","").strip() -app.config["HCAPTCHA_SECRET"] = environ.get("HCAPTCHA_SECRET","").strip() -app.config["SPAM_SIMILARITY_THRESHOLD"] = float(environ.get("SPAM_SIMILARITY_THRESHOLD", 0.5)) -app.config["SPAM_URL_SIMILARITY_THRESHOLD"] = float(environ.get("SPAM_URL_SIMILARITY_THRESHOLD", 0.1)) -app.config["SPAM_SIMILAR_COUNT_THRESHOLD"] = int(environ.get("SPAM_SIMILAR_COUNT_THRESHOLD", 10)) -app.config["COMMENT_SPAM_SIMILAR_THRESHOLD"] = float(environ.get("COMMENT_SPAM_SIMILAR_THRESHOLD", 0.5)) -app.config["COMMENT_SPAM_COUNT_THRESHOLD"] = int(environ.get("COMMENT_SPAM_COUNT_THRESHOLD", 10)) + +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +app.config['SQLALCHEMY_DATABASE_URL'] = environ.get("DATABASE_URL", "postgresql://postgres@localhost:5432") + app.config["CACHE_TYPE"] = "RedisCache" app.config["CACHE_REDIS_URL"] = environ.get("REDIS_URL", "redis://localhost") + app.config['MAIL_SERVER'] = 'smtp.gmail.com' app.config['MAIL_PORT'] = 587 app.config['MAIL_USE_TLS'] = True app.config['MAIL_USERNAME'] = environ.get("MAIL_USERNAME", "").strip() app.config['MAIL_PASSWORD'] = environ.get("MAIL_PASSWORD", "").strip() -app.config['DESCRIPTION'] = environ.get("DESCRIPTION", "rdrama.net caters to drama in all forms such as: Real life, videos, photos, gossip, rumors, news sites, Reddit, and Beyond™. There isn't drama we won't touch, and we want it all!").strip() + app.config['SETTINGS'] = {} r=redis.Redis(host=environ.get("REDIS_URL", "redis://localhost"), decode_responses=True, ssl_cert_reqs=None) @@ -74,7 +63,7 @@ limiter = Limiter( Base = declarative_base() -engine = create_engine(app.config['DATABASE_URL']) +engine = create_engine(app.config['SQLALCHEMY_DATABASE_URL']) db_session = scoped_session(sessionmaker(bind=engine, autoflush=False)) diff --git a/files/helpers/const.py b/files/helpers/const.py index a82a96060..cbc7f5172 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -906,4 +906,17 @@ def is_safe_url(url): return '\\' not in url and (url.startswith('/') or tldextract.extract(url).registered_domain in approved_embed_hosts) -hosts = "|".join(approved_embed_hosts).replace('.','\.') \ No newline at end of file +hosts = "|".join(approved_embed_hosts).replace('.','\.') + +SITE_NAME = environ.get("SITE_NAME").strip() +GUMROAD_LINK = environ.get("GUMROAD_LINK", "https://marsey1.gumroad.com/l/tfcvri").strip() +DEFAULT_COLOR = environ.get("DEFAULT_COLOR", "ff0000").strip() +DEFAULT_THEME = environ.get("DEFAULT_THEME", "midnight").strip() +HCAPTCHA_SITEKEY = environ.get("HCAPTCHA_SITEKEY","").strip() +HCAPTCHA_SECRET = environ.get("HCAPTCHA_SECRET","").strip() +SPAM_SIMILARITY_THRESHOLD = float(environ.get("SPAM_SIMILARITY_THRESHOLD", 0.5)) +SPAM_URL_SIMILARITY_THRESHOLD = float(environ.get("SPAM_URL_SIMILARITY_THRESHOLD", 0.1)) +SPAM_SIMILAR_COUNT_THRESHOLD = int(environ.get("SPAM_SIMILAR_COUNT_THRESHOLD", 10)) +COMMENT_SPAM_SIMILAR_THRESHOLD = float(environ.get("COMMENT_SPAM_SIMILAR_THRESHOLD", 0.5)) +COMMENT_SPAM_COUNT_THRESHOLD = int(environ.get("COMMENT_SPAM_COUNT_THRESHOLD", 10)) +DESCRIPTION = environ.get("DESCRIPTION", "rdrama.net caters to drama in all forms such as: Real life, videos, photos, gossip, rumors, news sites, Reddit, and Beyond™. There isn't drama we won't touch, and we want it all!").strip() \ No newline at end of file diff --git a/files/helpers/jinja2.py b/files/helpers/jinja2.py index 49701af9f..1fa240c4c 100644 --- a/files/helpers/jinja2.py +++ b/files/helpers/jinja2.py @@ -53,6 +53,6 @@ def inject_constants(): return {"environ":environ, "SITE":SITE, "SITE_NAME":SITE_NAME, "SITE_FULL":SITE_FULL, "AUTOJANNY_ID":AUTOJANNY_ID, "NOTIFICATIONS_ID":NOTIFICATIONS_ID, "PUSHER_ID":PUSHER_ID, "CC":CC, "CC_TITLE":CC_TITLE, "listdir":listdir, "MOOSE_ID":MOOSE_ID, "AEVANN_ID":AEVANN_ID, - "PIZZASHILL_ID":PIZZASHILL_ID, "config":app.config.get, "DEFAULT_COLOR":DEFAULT_COLOR, + "PIZZASHILL_ID":PIZZASHILL_ID, "DEFAULT_COLOR":DEFAULT_COLOR, "COLORS":COLORS, "ADMIGGERS":ADMIGGERS, "datetime":datetime, "time":time, - "LOTTERY_ENABLED": LOTTERY_ENABLED} \ No newline at end of file + "LOTTERY_ENABLED": LOTTERY_ENABLED, "GUMROAD_LINK": GUMROAD_LINK, "DEFAULT_THEME": DEFAULT_THEME, "DESCRIPTION": DESCRIPTION} \ No newline at end of file diff --git a/files/mail/__init__.py b/files/mail/__init__.py index 391372ada..297390955 100644 --- a/files/mail/__init__.py +++ b/files/mail/__init__.py @@ -25,7 +25,7 @@ def send_verification_email(user, email=None): if not email: email = user.email - url = f"https://{app.config['SERVER_NAME']}/activate" + url = f"https://{SERVER_NAME}/activate" now = int(time.time()) token = generate_hash(f"{email}+{user.id}+{now}") diff --git a/files/routes/comments.py b/files/routes/comments.py index 15488c7cb..d3ea8ecd7 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -336,11 +336,11 @@ def api_comment(v): similar_comments = g.db.query(Comment).filter( Comment.author_id == v.id, Comment.body.op( - '<->')(body) < app.config["COMMENT_SPAM_SIMILAR_THRESHOLD"], + '<->')(body) < COMMENT_SPAM_SIMILAR_THRESHOLD, Comment.created_utc > cutoff ).all() - threshold = app.config["COMMENT_SPAM_COUNT_THRESHOLD"] + threshold = COMMENT_SPAM_COUNT_THRESHOLD if v.age >= (60 * 60 * 24 * 7): threshold *= 3 elif v.age >= (60 * 60 * 24): @@ -713,11 +713,11 @@ def edit_comment(cid, v): ).filter( Comment.author_id == v.id, Comment.body.op( - '<->')(body) < app.config["SPAM_SIMILARITY_THRESHOLD"], + '<->')(body) < SPAM_SIMILARITY_THRESHOLD, Comment.created_utc > cutoff ).all() - threshold = app.config["SPAM_SIMILAR_COUNT_THRESHOLD"] + threshold = SPAM_SIMILAR_COUNT_THRESHOLD if v.age >= (60 * 60 * 24 * 30): threshold *= 4 elif v.age >= (60 * 60 * 24 * 7): diff --git a/files/routes/discord.py b/files/routes/discord.py index c09459c97..8e40e33b7 100644 --- a/files/routes/discord.py +++ b/files/routes/discord.py @@ -26,7 +26,7 @@ def join_discord(v): state=f"{now}.{state}" - return redirect(f"https://discord.com/api/oauth2/authorize?client_id={CLIENT_ID}&redirect_uri=https%3A%2F%2F{app.config['SERVER_NAME']}%2Fdiscord_redirect&response_type=code&scope=identify%20guilds.join&state={state}") + return redirect(f"https://discord.com/api/oauth2/authorize?client_id={CLIENT_ID}&redirect_uri=https%3A%2F%2F{SERVER_NAME}%2Fdiscord_redirect&response_type=code&scope=identify%20guilds.join&state={state}") @app.get("/discord_redirect") @@ -56,7 +56,7 @@ def discord_redirect(v): 'client_secret': CLIENT_SECRET, 'grant_type': 'authorization_code', 'code': code, - 'redirect_uri': f"https://{app.config['SERVER_NAME']}/discord_redirect", + 'redirect_uri': f"https://{SERVER_NAME}/discord_redirect", 'scope': 'identify guilds.join' } headers={ diff --git a/files/routes/login.py b/files/routes/login.py index 80dab5695..132f4e50a 100644 --- a/files/routes/login.py +++ b/files/routes/login.py @@ -220,7 +220,7 @@ def sign_up_get(v): formkey=formkey, now=now, ref_user=ref_user, - hcaptcha=app.config["HCAPTCHA_SITEKEY"], + hcaptcha=HCAPTCHA_SITEKEY, error=error ) @@ -294,14 +294,14 @@ def sign_up_post(v): if existing_account: return signup_error("An account with that username already exists.") - if app.config.get("HCAPTCHA_SITEKEY"): + if HCAPTCHA_SITEKEY: token = request.values.get("h-captcha-response") if not token: return signup_error("Unable to verify captcha [1].") - data = {"secret": app.config["HCAPTCHA_SECRET"], + data = {"secret": HCAPTCHA_SECRET, "response": token, - "sitekey": app.config["HCAPTCHA_SITEKEY"]} + "sitekey": HCAPTCHA_SITEKEY} url = "https://hcaptcha.com/siteverify" x = requests.post(url, data=data, timeout=5) diff --git a/files/routes/posts.py b/files/routes/posts.py index 65426ba46..566a44cac 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -829,7 +829,7 @@ def submit_post(v, sub=None): except: pass embed += '">' - elif app.config['SERVER_NAME'] in domain and "/post/" in url and "context" not in url: + elif SERVER_NAME in domain and "/post/" in url and "context" not in url: id = url.split("/post/")[1] if "/" in id: id = id.split("/")[0] embed = str(int(id)) @@ -861,19 +861,19 @@ def submit_post(v, sub=None): similar_posts = g.db.query(Submission).filter( Submission.author_id == v.id, - Submission.title.op('<->')(title) < app.config["SPAM_SIMILARITY_THRESHOLD"], + Submission.title.op('<->')(title) < SPAM_SIMILARITY_THRESHOLD, Submission.created_utc > cutoff ).all() if url: similar_urls = g.db.query(Submission).filter( Submission.author_id == v.id, - Submission.url.op('<->')(url) < app.config["SPAM_URL_SIMILARITY_THRESHOLD"], + Submission.url.op('<->')(url) < SPAM_URL_SIMILARITY_THRESHOLD, Submission.created_utc > cutoff ).all() else: similar_urls = [] - threshold = app.config["SPAM_SIMILAR_COUNT_THRESHOLD"] + threshold = SPAM_SIMILAR_COUNT_THRESHOLD if v.age >= (60 * 60 * 24 * 7): threshold *= 3 elif v.age >= (60 * 60 * 24): threshold *= 2 diff --git a/files/routes/users.py b/files/routes/users.py index 54eef3746..71d441e38 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -808,7 +808,7 @@ def mfa_qr(secret, v): qr = qrcode.QRCode( error_correction=qrcode.constants.ERROR_CORRECT_L ) - qr.add_data(x.provisioning_uri(v.username, issuer_name=app.config["SITE_NAME"])) + qr.add_data(x.provisioning_uri(v.username, issuer_name=SITE_NAME)) img = qr.make_image(fill_color="#000000", back_color="white") mem = io.BytesIO() diff --git a/files/templates/authforms.html b/files/templates/authforms.html index 836c7d9ba..5ad2868dc 100644 --- a/files/templates/authforms.html +++ b/files/templates/authforms.html @@ -4,7 +4,7 @@ - + @@ -45,7 +45,7 @@ {% else %} - + {% endif %} diff --git a/files/templates/chat.html b/files/templates/chat.html index bbcd1432a..e34d48053 100644 --- a/files/templates/chat.html +++ b/files/templates/chat.html @@ -3,7 +3,7 @@ - + diff --git a/files/templates/default.html b/files/templates/default.html index 0b1ec5da9..77ded9307 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -3,7 +3,7 @@ - + @@ -22,7 +22,7 @@ - + diff --git a/files/templates/login_2fa.html b/files/templates/login_2fa.html index b05fc0a8a..2867d9a32 100644 --- a/files/templates/login_2fa.html +++ b/files/templates/login_2fa.html @@ -6,7 +6,7 @@ - + @@ -18,7 +18,7 @@ - + diff --git a/files/templates/settings.html b/files/templates/settings.html index e1a28994c..19b4444a5 100644 --- a/files/templates/settings.html +++ b/files/templates/settings.html @@ -3,7 +3,7 @@ - + @@ -21,7 +21,7 @@ - + @@ -29,7 +29,7 @@ - + diff --git a/files/templates/settings2.html b/files/templates/settings2.html index b435e9e50..2e4fff1a6 100644 --- a/files/templates/settings2.html +++ b/files/templates/settings2.html @@ -4,7 +4,7 @@ - + @@ -21,7 +21,7 @@ - + @@ -29,7 +29,7 @@ - + @@ -45,7 +45,7 @@ {% else %} - + {% endif %} diff --git a/files/templates/sign_up.html b/files/templates/sign_up.html index 2d60ebf0c..ca17a697d 100644 --- a/files/templates/sign_up.html +++ b/files/templates/sign_up.html @@ -5,7 +5,7 @@ - + @@ -19,7 +19,7 @@ - + @@ -27,7 +27,7 @@ - + @@ -35,7 +35,7 @@ - + diff --git a/files/templates/sign_up_failed_ref.html b/files/templates/sign_up_failed_ref.html index 08bda0d7a..a1124359a 100644 --- a/files/templates/sign_up_failed_ref.html +++ b/files/templates/sign_up_failed_ref.html @@ -6,7 +6,7 @@ - + @@ -20,7 +20,7 @@ - + @@ -28,7 +28,7 @@ - + @@ -36,7 +36,7 @@ - + diff --git a/files/templates/submit.html b/files/templates/submit.html index 71136de9b..b9a29c315 100644 --- a/files/templates/submit.html +++ b/files/templates/submit.html @@ -3,7 +3,7 @@ - + @@ -54,7 +54,7 @@ {% else %} - + {% endif %} {% endblock %}