From cf7c31879ca2010cdd810e0eebb4caf019eb00e7 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Tue, 26 Oct 2021 23:31:39 +0200 Subject: [PATCH] misc --- env | 2 +- files/__main__.py | 6 +++--- files/classes/submission.py | 6 +++--- files/helpers/const.py | 10 +++++++++- files/routes/comments.py | 10 ++++++++-- files/routes/posts.py | 9 ++++++++- files/templates/comments.html | 2 +- files/templates/submission.html | 2 +- files/templates/submission_listing.html | 2 +- files/templates/submit.html | 2 +- files/templates/userpage.html | 4 ++-- pg_hba.conf | 4 ++-- redis.conf | 6 +++--- 13 files changed, 43 insertions(+), 22 deletions(-) diff --git a/env b/env index 9960e3d82..2639f70b2 100755 --- a/env +++ b/env @@ -1,4 +1,4 @@ -export DATABASE_URL="postgresql://postgres@127.0.0.1:5432" +export DATABASE_URL="postgresql://postgres@0.0.0.0:5432" export MASTER_KEY="-KTVciAUQFpFh2WdJ/oiHJlxl6FvzRZp8kYzAAv3l2OA=" export DOMAIN="localhost" export SITE_NAME="Drama" diff --git a/files/__main__.py b/files/__main__.py index 95628b7db..28882d1c5 100755 --- a/files/__main__.py +++ b/files/__main__.py @@ -41,7 +41,7 @@ app.config["SESSION_REFRESH_EACH_REQUEST"] = True app.config["SLOGAN"] = environ.get("SLOGAN", "").strip() app.config["DEFAULT_COLOR"] = environ.get("DEFAULT_COLOR", "ff0000").strip() app.config["DEFAULT_THEME"] = environ.get("DEFAULT_THEME", "midnight").strip() -app.config["FORCE_HTTPS"] = int(environ.get("FORCE_HTTPS", 1)) if ("localhost" not in app.config["SERVER_NAME"] and "127.0.0.1" not in app.config["SERVER_NAME"]) else 0 +app.config["FORCE_HTTPS"] = int(environ.get("FORCE_HTTPS", 1)) if ("localhost" not in app.config["SERVER_NAME"] and "0.0.0.0" not in app.config["SERVER_NAME"]) else 0 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() @@ -60,14 +60,14 @@ app.config["RATELIMIT_DEFAULTS_EXEMPT_WHEN"]=lambda:False app.config["RATELIMIT_HEADERS_ENABLED"]=True app.config["CACHE_TYPE"] = "filesystem" app.config["CACHE_DIR"] = "cache" -app.config["RATELIMIT_STORAGE_URL"] = environ.get("REDIS_URL", "redis://127.0.0.1") +app.config["RATELIMIT_STORAGE_URL"] = environ.get("REDIS_URL", "redis://0.0.0.0") 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() -r=redis.Redis(host=environ.get("REDIS_URL", "redis://127.0.0.1"), decode_responses=True, ssl_cert_reqs=None) +r=redis.Redis(host=environ.get("REDIS_URL", "redis://0.0.0.0"), decode_responses=True, ssl_cert_reqs=None) limiter = Limiter( app, diff --git a/files/classes/submission.py b/files/classes/submission.py index c7aec92ad..d7905e304 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -9,7 +9,7 @@ from sqlalchemy import * from sqlalchemy.orm import relationship, deferred from files.__main__ import Base -from files.helpers.const import AUTOPOLLER_ACCOUNT, censor_slurs +from files.helpers.const import AUTOPOLLER_ACCOUNT, censor_slurs, TROLLTITLES from files.helpers.lazy import lazy from .flags import Flag @@ -331,7 +331,7 @@ class Submission(Base): @lazy def realtitle(self, v): if self.club and not (v and v.paid_dues) and not (v and v.admin_level == 6): - if v: return f'{v.username} dox' + if v: return random.choice(TROLLTITLES).format(username=v.username) else: return 'COUNTRY CLUB MEMBERS ONLY' elif self.title_html: title = self.title_html else: title = self.title @@ -343,7 +343,7 @@ class Submission(Base): @lazy def plaintitle(self, v): if self.club and not (v and v.paid_dues) and not (v and v.admin_level == 6): - if v: return f'{v.username} dox' + if v: return random.choice(TROLLTITLES).format(username=v.username) else: return 'COUNTRY CLUB MEMBERS ONLY' else: title = self.title diff --git a/files/helpers/const.py b/files/helpers/const.py index 0aece46c6..273333b64 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -302,4 +302,12 @@ else: "color": "text-success", "price": 40000 }, - } \ No newline at end of file + } + +TROLLTITLES = [ + "how will @{username} ever recover?", + "@{username} BTFO", + "[META] Getting really sick of @{username}’s shit", + "Pretty sure this is @{username}'s Reddit account", + "Hey jannies can you please ban @{username}", +] \ No newline at end of file diff --git a/files/routes/comments.py b/files/routes/comments.py index 99744df88..18cb680c6 100755 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -500,13 +500,13 @@ def api_comment(v): if not v.shadowbanned: notify_users = set() - for x in g.db.query(Subscription.user_id).options(lazyload('*')).filter_by(submission_id=c.parent_submission).all(): - notify_users.add(x[0]) + for x in g.db.query(Subscription.user_id).options(lazyload('*')).filter_by(submission_id=c.parent_submission).all(): notify_users.add(x[0]) if parent.author.id != v.id: notify_users.add(parent.author.id) soup = BeautifulSoup(body_html, features="html.parser") mentions = soup.find_all("a", href=re.compile("^/@(\w+)")) + for mention in mentions: username = mention["href"].split("@")[1] @@ -517,6 +517,10 @@ def api_comment(v): continue if user.id != v.id: notify_users.add(user.id) + + if request.host == 'rdrama.net' and 'aevann' in body_html.lower() and 1 not in notify_users: + notify_users.append(1) + for x in notify_users: n = Notification(comment_id=c.id, user_id=x) g.db.add(n) @@ -745,6 +749,8 @@ def edit_comment(cid, v): if user.id != v.id: notify_users.add(user.id) + if request.host == 'rdrama.net' and 'aevann' in body_html.lower() and 1 not in notify_users: notify_users.append(1) + for x in notify_users: notif = notifs.filter_by(comment_id=c.id, user_id=x).first() if not notif: diff --git a/files/routes/posts.py b/files/routes/posts.py index a5f2926dc..381f291de 100755 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -66,6 +66,8 @@ def publish(pid, v): user = g.db.query(User).options(lazyload('*')).filter_by(username=username).first() if user and not v.any_block_exists(user) and user.id != v.id: notify_users.add(user) + if request.host == 'rdrama.net' and 'aevann' in post.body_html.lower() and 1 not in notify_users: notify_users.append(1) + for x in notify_users: send_notification(x.id, f"@{v.username} has mentioned you: http://{site}{new_post.permalink}") for follow in v.followers: @@ -309,6 +311,9 @@ def edit_post(pid, v): if user and not v.any_block_exists(user) and user.id != v.id: notify_users.add(user) message = f"@{v.username} has mentioned you: http://{site}{p.permalink}" + + if request.host == 'rdrama.net' and 'aevann' in body_html.lower() and 1 not in notify_users: notify_users.append(1) + for x in notify_users: existing = g.db.query(Comment).options(lazyload('*')).filter(Comment.author_id == NOTIFICATIONS_ACCOUNT, Comment.body == message, Comment.notifiedto == x.id).first() if not existing: send_notification(x.id, message) @@ -742,7 +747,9 @@ def submit_post(v): username = mention["href"].split("@")[1] user = g.db.query(User).options(lazyload('*')).filter_by(username=username).first() if user and not v.any_block_exists(user) and user.id != v.id: notify_users.add(user) - + + if request.host == 'rdrama.net' and 'aevann' in body_html.lower() and 1 not in notify_users: notify_users.append(1) + for x in notify_users: send_notification(x.id, f"@{v.username} has mentioned you: http://{site}{new_post.permalink}") for follow in v.followers: diff --git a/files/templates/comments.html b/files/templates/comments.html index 6a2acba16..96c2abeb0 100755 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -278,7 +278,7 @@ {% if c.is_blocking %}{% endif %} {% if c.is_blocked %}{% endif %} - {% if c.author.verified %} + {% if c.author.verified %} {% endif %} {{c.author.username}} diff --git a/files/templates/submission.html b/files/templates/submission.html index 40dacbf66..28b3ba208 100755 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -424,7 +424,7 @@ {% if p.over_18 %}+18{% endif %} {% if p.private %}Draft{% endif %} {% if p.active_flags %}{{p.active_flags}} Reports{% endif %} - {% if p.author.verified %} + {% if p.author.verified %} {% endif %} {{p.author.username}}{% if p.author.customtitle %}  {% if p.author.quadrant %}{% endif %}{{p.author.customtitle | safe}}{% endif %}  {{p.age_string}} diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index 8950d82c3..eb785dbf7 100755 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -192,7 +192,7 @@ {% if p.is_blocked %}{% endif %} {% if p.private %}Draft{% endif %} {% if p.active_flags %}{{p.active_flags}} Reports{% endif %} - {% if p.author.verified %} + {% if p.author.verified %} {% endif %} {{p.author.username}}{% if p.author.customtitle %}  {% if p.author.quadrant %}{% endif %}{{p.author.customtitle | safe}}{% endif %}  {{p.age_string}} diff --git a/files/templates/submit.html b/files/templates/submit.html index 101abf024..d449ef892 100755 --- a/files/templates/submit.html +++ b/files/templates/submit.html @@ -71,7 +71,7 @@
- + To post an image, use a direct image link such as i.imgur.com
diff --git a/files/templates/userpage.html b/files/templates/userpage.html index 2eabdb08b..65f5382c4 100755 --- a/files/templates/userpage.html +++ b/files/templates/userpage.html @@ -117,7 +117,7 @@ {% endif %} - {% if u.verified %}{% endif %} + {% if u.verified %}{% endif %} {% if u.admin_level > 1 or (u.admin_level == 1 and (not v or v.admin_level < 2)) %} @@ -404,7 +404,7 @@
BANNED USER{% if u.ban_reason %}: {{u.ban_reason}}{% endif %}
{% if u.unban_utc %}
{{u.unban_string}}
{% endif %} {% endif %} - {% if u.verified %} {% endif %} + {% if u.verified %} {% endif %}

{{u.username}}

{% if u.username != u.original_username %} diff --git a/pg_hba.conf b/pg_hba.conf index 4bfc29609..e9bf9ffcb 100755 --- a/pg_hba.conf +++ b/pg_hba.conf @@ -34,11 +34,11 @@ local all postgres trust # "local" is for Unix domain socket connections only local all all trust # IPv4 local connections: -host all all 127.0.0.1/32 trust +host all all 0.0.0.0/32 trust # IPv6 local connections: host all all ::1/128 trust # Allow replication connections from localhost, by a user with the # replication privilege. local replication all trust -host replication all 127.0.0.1/32 trust +host replication all 0.0.0.0/32 trust host replication all ::1/128 trust \ No newline at end of file diff --git a/redis.conf b/redis.conf index 954b2a00b..0aba26686 100755 --- a/redis.conf +++ b/redis.conf @@ -53,7 +53,7 @@ # Examples: # # bind 192.168.1.100 10.0.0.1 -# bind 127.0.0.1 ::1 +# bind 0.0.0.0 ::1 # # ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the # internet, binding to all the interfaces is dangerous and will expose the @@ -66,7 +66,7 @@ # IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES # JUST COMMENT THE FOLLOWING LINE. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -bind 127.0.0.1 ::1 +bind 0.0.0.0 ::1 # Protected mode is a layer of security protection, in order to avoid that # Redis instances left open on the internet are accessed and exploited. @@ -78,7 +78,7 @@ bind 127.0.0.1 ::1 # 2) No password is configured. # # The server only accepts connections from clients connecting from the -# IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain +# IPv4 and IPv6 loopback addresses 0.0.0.0 and ::1, and from Unix domain # sockets. # # By default protected mode is enabled. You should disable it only if