From 800ae8d2dc89bffbcad82a9871d7cc7068176a97 Mon Sep 17 00:00:00 2001 From: Ben Rog-Wilhelm Date: Sun, 31 Jul 2022 18:53:18 -0500 Subject: [PATCH] Split SITE_NAME into computer-readable SITE_ID and human-readable SITE_TITLE. --- env | 3 +- files/__main__.py | 5 +- files/assets/js/chat.js | 8 +-- files/classes/sub.py | 1 - files/classes/submission.py | 2 +- files/classes/user.py | 2 +- files/helpers/const.py | 5 +- files/helpers/jinja2.py | 21 +++++- files/mail/__init__.py | 7 +- files/routes/comments.py | 4 +- files/routes/posts.py | 4 +- files/routes/users.py | 6 +- files/templates/admin/admin_home.html | 2 +- files/templates/admin/alt_votes.html | 2 +- files/templates/admin/content_stats.html | 2 +- files/templates/admin/sidebar.html | 2 +- files/templates/api.html | 20 +++--- files/templates/authforms.html | 4 +- files/templates/chat.html | 4 +- files/templates/comments.html | 6 +- files/templates/contact.html | 6 +- files/templates/default.html | 80 +++++++++++------------ files/templates/delete_post_modal.html | 4 +- files/templates/email/2fa_remove.html | 2 +- files/templates/email/default.html | 4 +- files/templates/email/email_change.html | 6 +- files/templates/email/email_verify.html | 6 +- files/templates/email/password_reset.html | 2 +- files/templates/forgot_password.html | 4 +- files/templates/formatting.html | 6 +- files/templates/header.html | 6 +- files/templates/home.html | 2 +- files/templates/login.html | 4 +- files/templates/login_2fa.html | 4 +- files/templates/lost_2fa.html | 2 +- files/templates/oauth.html | 2 +- files/templates/reset_password.html | 2 +- files/templates/rules.html | 2 +- files/templates/search.html | 2 +- files/templates/settings.html | 16 ++--- files/templates/settings2.html | 14 ++-- files/templates/settings_apps.html | 2 +- files/templates/settings_blocks.html | 2 +- files/templates/settings_css.html | 2 +- files/templates/settings_filters.html | 2 +- files/templates/settings_profile.html | 6 +- files/templates/settings_profilecss.html | 2 +- files/templates/settings_security.html | 6 +- files/templates/sidebar.html | 4 +- files/templates/sidebar_TheMotte.html | 4 +- files/templates/sign_up.html | 14 ++-- files/templates/sign_up_failed_ref.html | 12 ++-- files/templates/sub/settings.html | 2 +- files/templates/submission.html | 22 +++---- files/templates/submission_listing.html | 2 +- files/templates/submit.html | 4 +- files/templates/userpage.html | 6 +- files/templates/userpage_reserved.html | 2 +- files/templates/votes.html | 2 +- 59 files changed, 202 insertions(+), 180 deletions(-) diff --git a/env b/env index b9d8c0bbe..1c3669245 100644 --- a/env +++ b/env @@ -1,6 +1,7 @@ MASTER_KEY=blahblahblah DOMAIN=localhost -SITE_NAME=TheMotte +SITE_ID=TheMotte +SITE_TITLE=The Motte GIPHY_KEY=blahblahblah DISCORD_SERVER_ID=blahblahblah DISCORD_CLIENT_ID=blahblahblah diff --git a/files/__main__.py b/files/__main__.py index 9ddb096af..45ac01031 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -25,14 +25,15 @@ app.jinja_env.auto_reload = True faulthandler.enable() -app.config["SITE_NAME"]=environ.get("SITE_NAME").strip() +app.config["SITE_ID"]=environ.get("SITE_ID").strip() +app.config["SITE_TITLE"]=environ.get("SITE_TITLE").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["SESSION_COOKIE_NAME"] = "session_" + environ.get("SITE_ID").strip().lower() app.config["VERSION"] = "1.0.0" app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 app.config["SESSION_COOKIE_SECURE"] = "localhost" not in environ.get("DOMAIN") diff --git a/files/assets/js/chat.js b/files/assets/js/chat.js index f2fdaeecb..925d90735 100644 --- a/files/assets/js/chat.js +++ b/files/assets/js/chat.js @@ -7,7 +7,7 @@ const box = document.getElementById('chat-window') const textbox = document.getElementById('input-text') const icon = document.getElementById('favicon') const vid = document.getElementById('vid').value -const site_name = document.getElementById('site_name').value +const site_id = document.getElementById('site_id').value const slurreplacer = document.getElementById('slurreplacer').value let notifs = 0; @@ -20,17 +20,17 @@ function flash(){ if (notifs >= 1 && !focused){ title.innerHTML = `[+${notifs}] Chat`; if (alert) { - icon.href = escapeHTML(`/assets/images/${site_name}/alert.webp?v=2`) + icon.href = escapeHTML(`/assets/images/${site_id}/alert.webp?v=2`) alert=false; } else { - icon.href = escapeHTML(`/assets/images/${site_name}/icon.webp?v=1015`) + icon.href = escapeHTML(`/assets/images/${site_id}/icon.webp?v=1015`) alert=true; } setTimeout(flash, 500) } else { - icon.href = escapeHTML(`/assets/images/${site_name}/icon.webp?v=1015`) + icon.href = escapeHTML(`/assets/images/${site_id}/icon.webp?v=1015`) notifs = 0 title.innerHTML = 'Chat'; } diff --git a/files/classes/sub.py b/files/classes/sub.py index 8b017a550..40e581ccf 100644 --- a/files/classes/sub.py +++ b/files/classes/sub.py @@ -5,7 +5,6 @@ from files.helpers.lazy import lazy from os import environ from .sub_block import * -SITE_NAME = environ.get("SITE_NAME", '').strip() SITE = environ.get("DOMAIN", '').strip() if SITE == "localhost": SITE_FULL = 'http://' + SITE else: SITE_FULL = 'https://' + SITE diff --git a/files/classes/submission.py b/files/classes/submission.py index 044b9ecdd..b5bfe4aa4 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -267,7 +267,7 @@ class Submission(Base): @lazy def thumb_url(self): 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=1" + elif not self.url: return f"{SITE_FULL}/assets/images/{SITE_ID}/default_text.webp?v=1" elif self.thumburl: if self.thumburl.startswith('/'): return SITE_FULL + self.thumburl return self.thumburl diff --git a/files/classes/user.py b/files/classes/user.py index 43c5bb44d..880ad077c 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -529,7 +529,7 @@ class User(Base): @lazy def banner_url(self): if self.bannerurl: return self.bannerurl - else: return f"/assets/images/{SITE_NAME}/site_preview.webp?v=1015" + else: return f"/assets/images/{SITE_ID}/site_preview.webp?v=1015" @property @lazy diff --git a/files/helpers/const.py b/files/helpers/const.py index d5f423d44..b0d87d8ec 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -8,7 +8,8 @@ from files.classes.marsey import Marsey from flask import request SITE = environ.get("DOMAIN", '').strip() -SITE_NAME = environ.get("SITE_NAME", '').strip() +SITE_ID = environ.get("SITE_ID", '').strip() +SITE_TITLE = environ.get("SITE_TITLE", '').strip() if "localhost" in SITE: SITE_FULL = 'http://' + SITE else: SITE_FULL = 'https://' + SITE @@ -62,7 +63,7 @@ DAD_ID = 0 MOM_ID = 0 DONGER_ID = 0 BUG_THREAD = 0 -WELCOME_MSG = f"Welcome to {SITE_NAME}!" +WELCOME_MSG = f"Welcome to {SITE_TITLE}!" ROLES={} IMGUR_KEY = environ.get("IMGUR_KEY").strip() diff --git a/files/helpers/jinja2.py b/files/helpers/jinja2.py index 803ebfe28..ecc269425 100644 --- a/files/helpers/jinja2.py +++ b/files/helpers/jinja2.py @@ -49,4 +49,23 @@ def timestamp(timestamp): @app.context_processor 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, "COLORS":COLORS, "ADMIGGERS":ADMINISTRATORS} + return { + "environ":environ, + "SITE":SITE, + "SITE_ID":SITE_ID, + "SITE_TITLE":SITE_TITLE, + "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, + "COLORS":COLORS, + "ADMIGGERS":ADMINISTRATORS + } diff --git a/files/mail/__init__.py b/files/mail/__init__.py index 76b40b141..0bd51b228 100644 --- a/files/mail/__init__.py +++ b/files/mail/__init__.py @@ -10,11 +10,12 @@ from files.classes import * from files.__main__ import app, mail, limiter from flask_mail import Message -name = environ.get("SITE_NAME").strip() +SITE_ID = environ.get("SITE_ID").strip() +SITE_TITLE = environ.get("SITE_TITLE").strip() def send_mail(to_address, subject, html): - msg = Message(html=html, subject=subject, sender=f"{name}@{SITE}", recipients=[to_address]) + msg = Message(html=html, subject=subject, sender=f"{SITE_ID}@{SITE}", recipients=[to_address]) mail.send(msg) @@ -35,7 +36,7 @@ def send_verification_email(user, email=None): html=render_template("email/email_verify.html", action_url=link, v=user), - subject=f"Validate your {name} account email." + subject=f"Validate your {SITE_TITLE} account email." ) diff --git a/files/routes/comments.py b/files/routes/comments.py index 84730fa16..70771d6a9 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -38,7 +38,7 @@ def pusher_thread(interests, c, username): 'title': f'New reply by @{username}', 'body': notifbody, 'deep_link': f'{SITE_FULL}/comment/{c.id}?context=8&read=true#context', - 'icon': f'{SITE_FULL}/assets/images/{SITE_NAME}/icon.webp?v=1015', + 'icon': f'{SITE_FULL}/assets/images/{SITE_ID}/icon.webp?v=1015', } }, 'fcm': { @@ -185,7 +185,7 @@ def api_comment(v): body = request.values.get("body", "").strip()[:10000] if v.admin_level > 2 and parent_post.id == 37749 and level == 1: - with open(f"snappy_{SITE_NAME}.txt", "a", encoding="utf-8") as f: + with open(f"snappy_{SITE_ID}.txt", "a", encoding="utf-8") as f: f.write('\n{[para]}\n' + body) if parent_post.id not in ADMINISTRATORS: diff --git a/files/routes/posts.py b/files/routes/posts.py index 328c0cb72..0c6ef2e0e 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -22,8 +22,8 @@ from sys import stdout snappyquotes = [f':#{x}:' for x in marseys_const2] -if path.exists(f'snappy_{SITE_NAME}.txt'): - with open(f'snappy_{SITE_NAME}.txt', "r", encoding="utf-8") as f: +if path.exists(f'snappy_{SITE_ID}.txt'): + with open(f'snappy_{SITE_ID}.txt', "r", encoding="utf-8") as f: snappyquotes += f.read().split("\n{[para]}\n") discounts = { diff --git a/files/routes/users.py b/files/routes/users.py index 40e6653c3..353c0fe28 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -26,7 +26,7 @@ def pusher_thread2(interests, notifbody, username): 'title': f'New message from @{username}', 'body': notifbody, 'deep_link': f'{SITE_FULL}/notifications?messages=true', - 'icon': f'{SITE_FULL}/assets/images/{SITE_NAME}/icon.webp?v=1015', + 'icon': f'{SITE_FULL}/assets/images/{SITE_ID}/icon.webp?v=1015', } }, 'fcm': { @@ -704,7 +704,7 @@ def messagereply(v): 'title': f'New message from @{v.username}', 'body': notifbody, 'deep_link': f'{SITE_FULL}/notifications?messages=true', - 'icon': f'{SITE_FULL}/assets/images/{SITE_NAME}/icon.webp"a=1010', + 'icon': f'{SITE_FULL}/assets/images/{SITE_ID}/icon.webp"a=1010', } }, 'fcm': { @@ -742,7 +742,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=app.config["SITE_TITLE"])) img = qr.make_image(fill_color="#000000", back_color="white") mem = io.BytesIO() diff --git a/files/templates/admin/admin_home.html b/files/templates/admin/admin_home.html index 0a32fc5f4..34f83c4f5 100644 --- a/files/templates/admin/admin_home.html +++ b/files/templates/admin/admin_home.html @@ -1,7 +1,7 @@ {% extends "default.html" %} {% block title %} -{{SITE_NAME}} +{{SITE_TITLE}} {% endblock %} diff --git a/files/templates/admin/alt_votes.html b/files/templates/admin/alt_votes.html index a98688857..e9d5841a9 100644 --- a/files/templates/admin/alt_votes.html +++ b/files/templates/admin/alt_votes.html @@ -1,7 +1,7 @@ {% extends "default.html" %} {% block title %} -{{SITE_NAME}} +{{SITE_TITLE}} {% endblock %} diff --git a/files/templates/admin/content_stats.html b/files/templates/admin/content_stats.html index de5b20611..5080646cb 100644 --- a/files/templates/admin/content_stats.html +++ b/files/templates/admin/content_stats.html @@ -1,7 +1,7 @@ {% extends "default.html" %} {% block title %} -{{SITE_NAME}} +{{SITE_TITLE}} {% endblock %} diff --git a/files/templates/admin/sidebar.html b/files/templates/admin/sidebar.html index 2300ab2a0..90b4a59d8 100644 --- a/files/templates/admin/sidebar.html +++ b/files/templates/admin/sidebar.html @@ -1,6 +1,6 @@ {% extends "default.html" %} -{% block pagetitle %}Edit {{SITE_NAME}} sidebar{% endblock %} +{% block pagetitle %}Edit {{SITE_TITLE}} sidebar{% endblock %} {% block content %} diff --git a/files/templates/api.html b/files/templates/api.html index 650e37a6c..eeca0f7a2 100644 --- a/files/templates/api.html +++ b/files/templates/api.html @@ -1,7 +1,7 @@ {% extends "default.html" %} {% block title %} -{{SITE_NAME}} - API +{{SITE_TITLE}} - API {% endblock %} @@ -14,17 +14,17 @@

 

This page explains how to obtain and use an access token.

Step 1: Create your Application

-

In the apps tab of {{SITE_NAME}} settings, fill in and submit the form to request an access token. You will need:

+

In the apps tab of {{SITE_TITLE}} settings, fill in and submit the form to request an access token. You will need:

Don't worry too much about accuracy; you will be able to change all of these later.

-

{{SITE_NAME}} administrators will review and approve or deny your request for an access token. You'll know when your request has been approved when you get a private message with an access token tied to your account.

+

{{SITE_TITLE}} administrators will review and approve or deny your request for an access token. You'll know when your request has been approved when you get a private message with an access token tied to your account.

DO NOT reveal your Client ID or Access Token. Anyone with these information will be able to pretend to be you. You are responsible for keeping them a secret!

Step 2: Using the Access Token

-

To use the access token, include the following header in subsequent API requests to {{SITE_NAME}}: Authorization: access_token_goes_here

+

To use the access token, include the following header in subsequent API requests to {{SITE_TITLE}}: Authorization: access_token_goes_here

Python example:

	import requests
 
@@ -63,25 +63,25 @@
 

API Guide for Applications


-

The OAuth2 authorization flow is used to enable users to authorize third-party applications to access their {{SITE_NAME}} account without having to provide their login information to the application.

+

The OAuth2 authorization flow is used to enable users to authorize third-party applications to access their {{SITE_TITLE}} account without having to provide their login information to the application.

This page explains how to obtain API application keys, how to prompt a user for authorization, and how to obtain and use access tokens.

Step 1: Create your Application

-

In the apps tab of {{SITE_NAME}} settings, fill in and submit the form to request new API keys. You will need:

+

In the apps tab of {{SITE_TITLE}} settings, fill in and submit the form to request new API keys. You will need:

Don't worry too much about accuracy; you will be able to change all of these later.

-

{{SITE_NAME}} administrators will review and approve or deny your request for API keys. You'll know when your request has been approved when you get a private message with an access token tied to your account.

+

{{SITE_TITLE}} administrators will review and approve or deny your request for API keys. You'll know when your request has been approved when you get a private message with an access token tied to your account.

DO NOT reveal your Client ID or Access Token. Anyone with these information will be able to pretend to be you. You are responsible for keeping them a secret!

Step 2: Prompt Your User for Authorization

Send your user to {{SITE_FULL}}/authorize/?client_id=YOUR_CLIENT_ID

-

If done correctly, the user will see that your application wants to access their {{SITE_NAME}} account, and be prompted to approve or deny the request.

+

If done correctly, the user will see that your application wants to access their {{SITE_TITLE}} account, and be prompted to approve or deny the request.

Step 3: Catch the redirect

-

The user clicks "Authorize". {{SITE_NAME}} will redirect the user's browser to GET the designated redirect URI. The access token URL parameter will be included in the redirect, which your server should process.

+

The user clicks "Authorize". {{SITE_TITLE}} will redirect the user's browser to GET the designated redirect URI. The access token URL parameter will be included in the redirect, which your server should process.

Step 4: Using the Access Token

-

To use the access token, include the following header in subsequent API requests to {{SITE_NAME}}: Authorization: access_token_goes_here

+

To use the access token, include the following header in subsequent API requests to {{SITE_TITLE}}: Authorization: access_token_goes_here

Python example:

	import requests
 
diff --git a/files/templates/authforms.html b/files/templates/authforms.html
index e6788f1ff..6d00b731a 100644
--- a/files/templates/authforms.html
+++ b/files/templates/authforms.html
@@ -10,7 +10,7 @@
 
 		
 
-		{% block pagetitle %}{{SITE_NAME}}{% endblock %}
+		{% block pagetitle %}{{SITE_TITLE}}{% endblock %}
 
 
 		{% if v %}
@@ -94,7 +94,7 @@
 
 										
- cover + cover diff --git a/files/templates/chat.html b/files/templates/chat.html index 6becb0213..25e2f7482 100644 --- a/files/templates/chat.html +++ b/files/templates/chat.html @@ -9,7 +9,7 @@ - + Chat @@ -184,7 +184,7 @@ - + diff --git a/files/templates/comments.html b/files/templates/comments.html index af0e1aa58..66f656ad3 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -187,7 +187,7 @@ {% if c.is_pinned %} {% endif %} - {% if c.distinguish_level and not c.ghost %}{% endif %} + {% if c.distinguish_level and not c.ghost %}{% endif %} {% if c.is_op %}{% endif %} {% if c.is_bot %}{% endif %} {% if c.is_blocking %}{% endif %} @@ -790,9 +790,9 @@
Delete comment?
-

Your comment will be deleted everywhere on {{SITE_NAME}}.

+

Your comment will be deleted everywhere on {{SITE_TITLE}}.

-

Your comment will be deleted everywhere on {{SITE_NAME}}.

+

Your comment will be deleted everywhere on {{SITE_TITLE}}.

diff --git a/files/templates/contact.html b/files/templates/contact.html index 0ec838d5f..c74f3921c 100644 --- a/files/templates/contact.html +++ b/files/templates/contact.html @@ -1,7 +1,7 @@ {% extends "default.html" %} {% block title %} -{{SITE_NAME}} - Contact +{{SITE_TITLE}} - Contact {% endblock %} @@ -19,9 +19,9 @@ {% endif %} -

Contact {{SITE_NAME}} Admins

+

Contact {{SITE_TITLE}} Admins

-

Use this form to contact {{SITE_NAME}} Admins.

+

Use this form to contact {{SITE_TITLE}} Admins.

{% if v and v.email %} diff --git a/files/templates/default.html b/files/templates/default.html index 82cd4fbc7..b64409c7f 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -38,16 +38,16 @@ - + - + {% block title %} - {{SITE_NAME}} + {{SITE_TITLE}} - + - + @@ -55,10 +55,10 @@ - + - + {% endblock %} @@ -67,12 +67,12 @@ - - - - - - + + + + + + @@ -82,127 +82,127 @@ {% block fixedMobileBarJS %} @@ -218,7 +218,7 @@ /h/{{sub.name}} banner {% else %} - site banner + site banner {% endif %} {% endif %} @@ -258,7 +258,7 @@ {% block sidebar %} {% if home or sub and p %} - {% include "sidebar_" + SITE_NAME + ".html" %} + {% include "sidebar_" + SITE_ID + ".html" %} {% endif %} {% endblock %} diff --git a/files/templates/delete_post_modal.html b/files/templates/delete_post_modal.html index 05381601c..3fb4ed563 100644 --- a/files/templates/delete_post_modal.html +++ b/files/templates/delete_post_modal.html @@ -17,9 +17,9 @@
Delete post?
-

Your post will be deleted everywhere on {{SITE_NAME}}.

+

Your post will be deleted everywhere on {{SITE_TITLE}}.

-

Your post will be deleted everywhere on {{SITE_NAME}}.

+

Your post will be deleted everywhere on {{SITE_TITLE}}.

diff --git a/files/templates/email/2fa_remove.html b/files/templates/email/2fa_remove.html index a3d0659ba..fbfe090ec 100644 --- a/files/templates/email/2fa_remove.html +++ b/files/templates/email/2fa_remove.html @@ -20,7 +20,7 @@ -

Please note that {{SITE_NAME}} will never ask you for your email, password, or two-factor token via email, text, or phone.

+

Please note that {{SITE_TITLE}} will never ask you for your email, password, or two-factor token via email, text, or phone.