From 7e9fc468fe87ba967f029b5495476a4af7f2d7fd Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Mon, 2 Aug 2021 16:27:20 +0200 Subject: [PATCH] fdfddf --- docker-compose.yml | 1 + drama/__main__.py | 22 +--------------------- drama/classes/submission.py | 12 +++++++----- drama/classes/user.py | 6 ++++-- drama/helpers/sanitize.py | 6 ++++-- drama/mail/mail.py | 6 ++++-- drama/routes/comments.py | 4 +++- drama/routes/posts.py | 15 ++++++++------- drama/routes/static.py | 3 ++- drama/routes/users.py | 4 +++- drama/templates/comments.html | 4 ++-- drama/templates/default.html | 4 ++-- drama/templates/email/2fa_remove.html | 5 ----- drama/templates/email/default.html | 2 +- drama/templates/errors/502.html | 2 +- drama/templates/formatting.html | 6 +++--- drama/templates/header.html | 4 ++-- drama/templates/settings.html | 8 ++++---- drama/templates/settings2.html | 4 ++-- drama/templates/settings_profile.html | 2 +- drama/templates/sign_up.html | 8 ++++---- drama/templates/sign_up_failed_ref.html | 8 ++++---- drama/templates/submission.html | 8 ++++---- drama/templates/submission_listing.html | 4 ++-- drama/templates/userpage.html | 2 +- 25 files changed, 70 insertions(+), 80 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index f2ea97e56..0a6aab770 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,6 +18,7 @@ services: - CLOUDFLARE_KEY=vcxvdfgfc6r554etrgd - TENOR_KEY=vcxvdfgfc6r554etrgd - MAILGUN_KEY=vcxvdfgfc6r554etrgd + - MAILGUN_DOMAIN=rdrama.net - admin_email=drama@rdrama.net - FORCE_HTTPS=0 - DISCORD_SERVER_ID=vcxvdfgfc6r554etrgd diff --git a/drama/__main__.py b/drama/__main__.py index 0f9e8d434..63a2d19b2 100644 --- a/drama/__main__.py +++ b/drama/__main__.py @@ -48,7 +48,7 @@ app.config['SQLALCHEMY_READ_URIS'] = [ ] app.config['SECRET_KEY'] = environ.get('MASTER_KEY') -app.config["SERVER_NAME"] = environ.get("domain", environ.get("SERVER_NAME", "")).strip() +app.config["SERVER_NAME"] = environ.get("domain").strip() app.config["SHORT_DOMAIN"]=environ.get("SHORT_DOMAIN","").strip() app.config["SESSION_COOKIE_NAME"] = "session_drama" @@ -115,26 +115,6 @@ Markdown(app) cache = Cache(app) Compress(app) -class CorsMatch(str): - - def __eq__(self, other): - if isinstance(other, str): - if other in ['https://rdrama.net', f'https://{app.config["SERVER_NAME"]}']: - return True - - elif other.endswith(".rdrama.net"): - return True - - elif isinstance(other, list): - if f'https://{app.config["SERVER_NAME"]}' in other: - return True - elif any([x.endswith(".rdrama.net") for x in other]): - return True - - return False - - - app.config["RATELIMIT_STORAGE_URL"] = environ.get("REDIS_URL").strip() if environ.get("REDIS_URL") else 'memory://' app.config["RATELIMIT_KEY_PREFIX"] = "flask_limiting_" app.config["RATELIMIT_ENABLED"] = True diff --git a/drama/classes/submission.py b/drama/classes/submission.py index c918abf27..eebe4b297 100644 --- a/drama/classes/submission.py +++ b/drama/classes/submission.py @@ -7,12 +7,14 @@ from drama.helpers.lazy import lazy from drama.__main__ import Base from .mix_ins import * from .flags import * +from os import environ + +domain = environ.get("domain").strip() class SubmissionAux(Base): __tablename__ = "submissions_aux" - # we don't care about this ID key_id = Column(BigInteger, primary_key=True) id = Column(BigInteger, ForeignKey("submissions.id")) title = Column(String(500)) @@ -197,11 +199,11 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing): @property @lazy def thumb_url(self): - if self.over_18: return "https://rdrama.net/assets/images/nsfw.png" - elif not self.url: return "https://rdrama.net/assets/images/default_thumb_text.png" + if self.over_18: return f"https://{domain}/assets/images/nsfw.png" + elif not self.url: return f"https://{domain}/assets/images/default_thumb_text.png" elif self.thumburl: return self.thumburl - elif "youtu.be" in self.domain or "youtube.com" in self.domain: return "https://rdrama.net/assets/images/default_thumb_yt.png" - else: return "https://rdrama.net/assets/images/default_thumb_link.png" + elif "youtu.be" in self.domain or "youtube.com" in self.domain: return f"https://{domain}/assets/images/default_thumb_yt.png" + else: return f"https://{domain}/assets/images/default_thumb_link.png" @property diff --git a/drama/classes/user.py b/drama/classes/user.py index 99b196efb..2bedff500 100644 --- a/drama/classes/user.py +++ b/drama/classes/user.py @@ -14,6 +14,8 @@ from .clients import * from drama.__main__ import Base, cache from drama.helpers.security import * +domain = environ.get("domain").strip() + class User(Base, Stndrd, Age_times): __tablename__ = "users" id = Column(Integer, primary_key=True) @@ -441,12 +443,12 @@ class User(Base, Stndrd, Age_times): @property def banner_url(self): if self.bannerurl: return self.bannerurl - else: return "https://rdrama.net/assets/images/default_bg.png" + else: return f"https://{domain}/assets/images/default_bg.png" @cache.memoize(0) def defaultpicture(self): pic = random.randint(1, 50) - return f"https://rdrama.net/assets/images/defaultpictures/{pic}.png" + return f"https://{domain}/assets/images/defaultpictures/{pic}.png" @property def profile_url(self): diff --git a/drama/helpers/sanitize.py b/drama/helpers/sanitize.py index e974d5007..755f51690 100644 --- a/drama/helpers/sanitize.py +++ b/drama/helpers/sanitize.py @@ -6,6 +6,8 @@ from functools import partial from .get import * from os import path +domain = environ.get("domain").strip() + _allowed_tags = tags = ['b', 'blockquote', 'br', @@ -66,7 +68,7 @@ def a_modify(attrs, new=False): domain = parsed_url.netloc attrs[(None, "target")] = "_blank" - if domain and not domain.endswith("rdrama.net"): + if domain and not domain.endswith(domain): attrs[(None, "rel")] = "nofollow noopener" # Force https for all external links in comments @@ -182,7 +184,7 @@ def sanitize(text, linkgen=False, flair=False): else: emojisize = 30 for i in re.finditer(':(.{1,30}?):', sanitized): if path.isfile(f'./drama/assets/images/emojis/{i.group(1)}.gif'): - sanitized = sanitized.replace(f':{i.group(1)}:', f'') + sanitized = sanitized.replace(f':{i.group(1)}:', f'') sanitized = sanitized.replace("https://www.", "https://").replace("https://youtu.be/", "https://youtube.com/embed/").replace("https://music.youtube.com/watch?v=", "https://youtube.com/embed/").replace("/watch?v=", "/embed/").replace("https://open.spotify.com/", "https://open.spotify.com/embed/").replace("https://streamable.com/", "https://streamable.com/e/").replace("https://youtube.com/shorts/", "https://youtube.com/embed/") diff --git a/drama/mail/mail.py b/drama/mail/mail.py index bcce688ae..814a4e97d 100644 --- a/drama/mail/mail.py +++ b/drama/mail/mail.py @@ -9,11 +9,13 @@ from drama.helpers.wrappers import * from drama.classes import * from drama.__main__ import app +domain = environ.get("domain").strip() +mailgun_domain = environ.get("MAILGUN_DOMAIN").strip() def send_mail(to_address, subject, html, plaintext=None, files={}, - from_address="Drama "): + from_address=f"Drama "): - url = "https://api.mailgun.net/v3/rdrama.net/messages" + url = f"https://api.mailgun.net/v3/{mailgun_domain}/messages" data = {"from": from_address, "to": [to_address], diff --git a/drama/routes/comments.py b/drama/routes/comments.py index 925dc2cec..e96c691d6 100644 --- a/drama/routes/comments.py +++ b/drama/routes/comments.py @@ -10,6 +10,8 @@ from pusher_push_notifications import PushNotifications from flask import * from drama.__main__ import app, limiter +domain = environ.get("domain").strip() + choices = ['Wow, you must be a JP fan.', 'This is one of the worst posts I have EVER seen. Delete it.', "No, don't reply like this, please do another wall of unhinged rant please.", '# 😴😴😴', "Ma'am we've been over this before. You need to stop.", "I've known more coherent downies.", "Your pulitzer's in the mail", "That's great and all, but I asked for my burger without cheese.", 'That degree finally paying off', "That's nice sweaty. Why don't you have a seat in the time out corner with Pizzashill until you calm down, then you can have your Capri Sun.", "All them words won't bring your pa back.", "You had a chance to not be completely worthless, but it looks like you threw it away. At least you're consistent.", 'Some people are able to display their intelligence by going on at length on a subject and never actually saying anything. This ability is most common in trades such as politics, public relations, and law. You have impressed me by being able to best them all, while still coming off as an absolute idiot.', "You can type 10,000 characters and you decided that these were the one's that you wanted.", 'Have you owned the libs yet?', "I don't know what you said, because I've seen another human naked.", 'Impressive. Normally people with such severe developmental disabilities struggle to write much more than a sentence or two. He really has exceded our expectations for the writing portion. Sadly the coherency of his writing, along with his abilities in the social skills and reading portions, are far behind his peers with similar disabilities.', "This is a really long way of saying you don't fuck.", "Sorry ma'am, looks like his delusions have gotten worse. We'll have to admit him,", 'https://i.kym-cdn.com/photos/images/newsfeed/001/038/094/0a1.jpg', 'If only you could put that energy into your relationships', 'Posts like this is why I do Heroine.', 'still unemployed then?', 'K', 'look im gunna have 2 ask u 2 keep ur giant dumps in the toilet not in my replys 😷😷😷', "Mommy is soooo proud of you, sweaty. Let's put this sperg out up on the fridge with all your other failures.", "Good job bobby, here's a star", "That was a mistake. You're about to find out the hard way why.", 'You sat down and wrote all this shit. You could have done so many other things with your life. What happened to your life that made you decide writing novels of bullshit on reddit was the best option?', "I don't have enough spoons to read this shit", "All those words won't bring daddy back.", 'OUT!', "Mommy is soooo proud of you, sweaty. Let's put this sperg out up on the fridge with all your other failures."] PUSHER_KEY = environ.get("PUSHER_KEY", "").strip() @@ -527,7 +529,7 @@ def api_comment(v): 'notification': { 'title': f'New reply by @{v.username}', 'body': c.body, - 'deep_link': f'https://rdrama.net{c.permalink}?context=5#context', + 'deep_link': f'https://{domain}{c.permalink}?context=5#context', }, }, }, diff --git a/drama/routes/posts.py b/drama/routes/posts.py index 12956b4bd..b3b88ab4c 100644 --- a/drama/routes/posts.py +++ b/drama/routes/posts.py @@ -18,8 +18,9 @@ from drama.__main__ import app, limiter, cache from PIL import Image as PILimage from .front import frontlist -with open("snappy.txt", "r") as f: - snappyquotes = f.read().split("{[para]}") +domain = environ.get("domain").strip() + +with open("snappy.txt", "r") as f: snappyquotes = f.read().split("{[para]}") @app.post("/publish/") @is_not_banned @@ -333,7 +334,7 @@ def edit_post(pid, v): user = g.db.query(User).filter_by(username=username).first() if user and not v.any_block_exists(user) and user.id != v.id: notify_users.add(user) - for x in notify_users: send_notification(1046, x, f"@{v.username} has mentioned you: https://rdrama.net{p.permalink}") + for x in notify_users: send_notification(1046, x, f"@{v.username} has mentioned you: https://{domain}{p.permalink}") return redirect(p.permalink) @@ -618,7 +619,7 @@ def submit_post(v): embed = requests.get("https://graph.facebook.com/v9.0/instagram_oembed", params={"url":url,"access_token":environ.get("FACEBOOK_TOKEN","").strip(),"omitscript":'true'}, headers={"User-Agent":"Instagram embedder for Drama"}).json()["html"] elif app.config['SERVER_NAME'] in domain: - matches = re.match(re.compile("^.*rdrama.net/post/+\w+/(\w+)(/\w+/(\w+))?"), url) + matches = re.match(re.compile(f"^.*{domain}/post/+\w+/(\w+)(/\w+/(\w+))?"), url) post_id = matches.group(1) comment_id = matches.group(3) if comment_id: embed = f"https://{app.config['SERVER_NAME']}/embed/comment/{comment_id}" @@ -846,12 +847,12 @@ def submit_post(v): user = g.db.query(User).filter_by(username=username).first() if user and not v.any_block_exists(user) and user.id != v.id: notify_users.add(user) - for x in notify_users: send_notification(1046, x, f"@{v.username} has mentioned you: https://rdrama.net{new_post.permalink}") + for x in notify_users: send_notification(1046, x, f"@{v.username} has mentioned you: https://{domain}{new_post.permalink}") if not new_post.private: for follow in v.followers: user = get_account(follow.user_id) - send_notification(2360, user, f"@{v.username} has made a new post: [{title}](https://rdrama.net{new_post.permalink})") + send_notification(2360, user, f"@{v.username} has made a new post: [{title}](https://{domain}{new_post.permalink})") g.db.add(new_post) g.db.commit() @@ -926,7 +927,7 @@ def submit_post(v): n = Notification(comment_id=c.id, user_id=v.id) g.db.add(n) g.db.commit() - send_message(f"https://rdrama.net{new_post.permalink}") + send_message(f"https://{domain}{new_post.permalink}") v.post_count = v.submissions.filter_by(is_banned=False, deleted_utc=0).count() g.db.add(v) diff --git a/drama/routes/static.py b/drama/routes/static.py index 390093a90..d40e05de2 100644 --- a/drama/routes/static.py +++ b/drama/routes/static.py @@ -2,6 +2,7 @@ from drama.mail import * from drama.__main__ import app, limiter from drama.helpers.alerts import * +domain = environ.get("domain").strip() @app.get("/patrons") @auth_desired @@ -77,7 +78,7 @@ def contact(v): @app.post("/contact") @auth_desired def submit_contact(v): - message = f'This message has been sent automatically to all admins via https://rdrama.net/contact, user email is "{v.email}"\n\nMessage:\n\n' + request.form.get("message", "") + message = f'This message has been sent automatically to all admins via https://{domain}/contact, user email is "{v.email}"\n\nMessage:\n\n' + request.form.get("message", "") send_admin(v.id, message) return render_template("contact.html", v=v, msg="Your message has been sent.") diff --git a/drama/routes/users.py b/drama/routes/users.py index b8b7fafaf..9d465ce89 100644 --- a/drama/routes/users.py +++ b/drama/routes/users.py @@ -12,6 +12,8 @@ from flask import * from drama.__main__ import app, limiter from pusher_push_notifications import PushNotifications +domain = environ.get("domain").strip() + PUSHER_KEY = environ.get("PUSHER_KEY", "").strip() beams_client = PushNotifications( @@ -148,7 +150,7 @@ def message2(v, username): 'notification': { 'title': f'New message from @{v.username}', 'body': message, - 'deep_link': f'https://rdrama.net/notifications', + 'deep_link': f'https://{domain}/notifications', }, }, }, diff --git a/drama/templates/comments.html b/drama/templates/comments.html index 161860211..98d618057 100644 --- a/drama/templates/comments.html +++ b/drama/templates/comments.html @@ -243,7 +243,7 @@ {% endif %} -
  • Votes
  • +
  • Votes
  • {% if v and c.id in v.saved_comment_idlist() %}
  • Unsave
  • @@ -410,7 +410,7 @@