From aeea97941c29225851d5dd24676ff23e131c3059 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 26 Nov 2021 21:28:55 +0200 Subject: [PATCH] 1 --- docker-compose.yml | 2 +- env | 4 +- files/__main__.py | 8 +- files/classes/comment.py | 2 +- files/classes/mod_logs.py | 20 --- files/classes/submission.py | 2 +- files/classes/user.py | 16 +-- files/routes/admin.py | 27 +--- files/routes/settings.py | 5 +- files/routes/static.py | 2 +- files/templates/api.html | 4 +- files/templates/comments.html | 2 +- files/templates/submission.html | 10 -- files/templates/submission_listing.html | 7 +- files/templates/userpage.html | 20 +-- files/templates/userpage_blocking.html | 7 +- pg_hba.conf | 18 +-- readme.md | 8 +- redis.conf | 170 ++++++++++++------------ restart | 2 +- setup | 2 +- supervisord.conf | 2 +- 22 files changed, 141 insertions(+), 199 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 009424fa2..12416fbff 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ services: - DATABASE_URL=postgresql://postgres@postgres:5432 - MASTER_KEY=XuxGqp5NyygJrM24b5gt3YgyvFVGdQnwVDwLzLwpu3eQwY - REDIS_URL=redis://redis - - DOMAIN=0.0.0.0 + - DOMAIN=localhost - SITE_NAME=Drama - GIPHY_KEY=3435tdfsdudebussylmaoxxt43 - FORCE_HTTPS=0 diff --git a/env b/env index f897886da..7054dabfd 100644 --- a/env +++ b/env @@ -1,6 +1,6 @@ -export DATABASE_URL="postgresql://postgres@0.0.0.0:5432" +export DATABASE_URL="postgresql://postgres@localhost:5432" export MASTER_KEY="XuxGqp5NyygJrM24b5gt3YgyvFVGdQnwVDwLzLwpu3eQwY" -export DOMAIN="0.0.0.0" +export DOMAIN="localhost" export SITE_NAME="Drama" export GIPHY_KEY="3435tdfsdudebussylmaoxxt43" export FORCE_HTTPS="0" diff --git a/files/__main__.py b/files/__main__.py index 1b694e42c..fb6c44613 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -42,7 +42,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 ("0.0.0.0" not in app.config["SERVER_NAME"] and "0.0.0.0" 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 "localhost" 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() @@ -61,14 +61,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://0.0.0.0") +app.config["RATELIMIT_STORAGE_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() -r=redis.Redis(host=environ.get("REDIS_URL", "redis://0.0.0.0"), decode_responses=True, ssl_cert_reqs=None) +r=redis.Redis(host=environ.get("REDIS_URL", "redis://localhost"), decode_responses=True, ssl_cert_reqs=None) limiter = Limiter( app, @@ -103,7 +103,7 @@ def before_request(): session.permanent = True if not session.get("session_id"): session["session_id"] = secrets.token_hex(16) - if app.config["FORCE_HTTPS"] and request.url.startswith("http://") and "0.0.0.0" not in app.config["SERVER_NAME"]: + if app.config["FORCE_HTTPS"] and request.url.startswith("http://") and "localhost" not in app.config["SERVER_NAME"]: url = request.url.replace("http://", "https://", 1) return redirect(url, code=301) diff --git a/files/classes/comment.py b/files/classes/comment.py index 18932c696..b370833d1 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -27,7 +27,7 @@ class Comment(Base): edited_utc = Column(Integer, default=0) is_banned = Column(Boolean, default=False) removed_by = Column(Integer) - bannedfor = Column(Boolean) + bannedfor = Column(Boolean, default=False) distinguish_level = Column(Integer, default=0) deleted_utc = Column(Integer, default=0) is_approved = Column(Integer, default=0) diff --git a/files/classes/mod_logs.py b/files/classes/mod_logs.py index 9bb308732..8e4cf6af6 100644 --- a/files/classes/mod_logs.py +++ b/files/classes/mod_logs.py @@ -163,16 +163,6 @@ ACTIONTYPES={ "icon": "fa-user-slash", "color": "bg-muted", }, - "club_allow":{ - "str":'allowed user {self.target_link} into the {cc}', - "icon":"fa-user-slash", - "color": "bg-danger", - }, - "club_ban":{ - "str":'disallowed user {self.target_link} from the {cc}', - "icon": "fa-user-slash", - "color": "bg-muted", - }, "nuke_user":{ "str":'removed all content of {self.target_link}', "icon":"fa-user-slash", @@ -253,16 +243,6 @@ ACTIONTYPES={ "icon":"fa-feather-alt", "color": "bg-muted", }, - "club":{ - "str": 'marked post {self.target_link} as club-only', - "icon":"fa-eye-slash", - "color": "bg-danger", - }, - "unclub":{ - "str": 'unmarked post {self.target_link} as club-only', - "icon":"fa-eye", - "color": "bg-muted", - }, "ban_comment":{ "str": 'removed {self.target_link}', "icon":"fa-comment", diff --git a/files/classes/submission.py b/files/classes/submission.py index 2ab1d9940..0655ae2a5 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -28,7 +28,7 @@ class Submission(Base): thumburl = Column(String) is_banned = Column(Boolean, default=False) removed_by = Column(Integer) - bannedfor = Column(Boolean) + bannedfor = Column(Boolean, default=False) views = Column(Integer, default=0) deleted_utc = Column(Integer, default=0) distinguish_level = Column(Integer, default=0) diff --git a/files/classes/user.py b/files/classes/user.py index 964d65aea..6115b827f 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -51,7 +51,7 @@ class User(Base): verifiedcolor = Column(String) marseyawarded = Column(Integer) longpost = Column(Integer) - unblockable = Column(Boolean) + unblockable = Column(Boolean, default=False) bird = Column(Integer) email = deferred(Column(String)) css = deferred(Column(String)) @@ -81,12 +81,12 @@ class User(Base): newtab = Column(Boolean, default=False) newtabexternal = Column(Boolean, default=True) oldreddit = Column(Boolean, default=True) - teddit = Column(Boolean) - nitter = Column(Boolean) - mute = Column(Boolean) - unmutable = Column(Boolean) - eye = Column(Boolean) - alt = Column(Boolean) + teddit = Column(Boolean, default=False) + nitter = Column(Boolean, default=False) + mute = Column(Boolean, default=False) + unmutable = Column(Boolean, default=False) + eye = Column(Boolean, default=False) + alt = Column(Boolean, default=False) frontsize = Column(Integer, default=25) controversial = Column(Boolean, default=False) bio = deferred(Column(String)) @@ -94,7 +94,7 @@ class User(Base): sig = deferred(Column(String)) sig_html = Column(String) fp = Column(String) - sigs_disabled = Column(Boolean) + sigs_disabled = Column(Boolean, default=False) friends = deferred(Column(String)) friends_html = deferred(Column(String)) enemies = deferred(Column(String)) diff --git a/files/routes/admin.py b/files/routes/admin.py index 5d87bb2e5..eebe599a9 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -97,14 +97,6 @@ def club_allow(v, username): x.club_banned = False g.db.add(x) - - ma=ModAction( - kind="club_allow", - user_id=v.id, - target_user_id=u.id, - ) - g.db.add(ma) - g.db.commit() return {"message": f"@{username} has been allowed into the {cc}!"} @@ -127,13 +119,6 @@ def club_ban(v, username): u.club_allowed = False g.db.add(x) - ma=ModAction( - kind="club_ban", - user_id=v.id, - target_user_id=u.id, - ) - g.db.add(ma) - g.db.commit() return {"message": f"@{username} has been kicked from the {cc}. Deserved."} @@ -164,30 +149,30 @@ def remove_admin(v, username): return {"message": "Admin removed!"} -@app.post("/@/make_fake_admin") +@app.post("/@/make_meme_admin") @limiter.limit("1/second") @admin_level_required(2) -def make_fake_admin(v, username): +def make_meme_admin(v, username): if 'pcm' in request.host or (SITE_NAME == 'Drama' and v.admin_level > 2) or ('rama' not in request.host and 'pcm' not in request.host): user = get_user(username) if not user: abort(404) user.admin_level = 1 g.db.add(user) g.db.commit() - return {"message": "User has been made fake admin!"} + return {"message": "User has been made meme admin!"} -@app.post("/@/remove_fake_admin") +@app.post("/@/remove_meme_admin") @limiter.limit("1/second") @admin_level_required(2) -def remove_fake_admin(v, username): +def remove_meme_admin(v, username): if 'pcm' in request.host or (SITE_NAME == 'Drama' and v.admin_level > 2) or ('rama' not in request.host and 'pcm' not in request.host): user = get_user(username) if not user: abort(404) user.admin_level = 0 g.db.add(user) g.db.commit() - return {"message": "Fake admin removed!"} + return {"message": "Meme admin removed!"} @app.post("/admin/monthly") diff --git a/files/routes/settings.py b/files/routes/settings.py index e67fa212b..142fda70f 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -853,8 +853,7 @@ def settings_block_user(v): g.db.commit() - if v.admin_level == 1: return {"message": f"@{user.username} banned!"} - else: return {"message": f"@{user.username} blocked."} + return {"message": f"@{user.username} blocked."} @app.post("/settings/unblock") @@ -878,8 +877,6 @@ def settings_unblock_user(v): g.db.commit() - if v.admin_level == 1: return {"message": f"@{user.username} unbanned!"} - return {"message": f"@{user.username} unblocked."} diff --git a/files/routes/static.py b/files/routes/static.py index 924104ac7..3d9b2b566 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -173,7 +173,7 @@ def log(v): actions = g.db.query(ModAction) if not (v and v.admin_level > 1): - actions = actions.filter(ModAction.kind.notin_(["shadowban","unshadowban","club","unclub","club_allow","club_ban","check"])) + actions = actions.filter(ModAction.kind.notin_(["shadowban","unshadowban","check"])) if admin_id: actions = actions.filter_by(user_id=admin_id) if kind: actions = actions.filter_by(kind=kind) diff --git a/files/templates/api.html b/files/templates/api.html index 82b209790..97ba4c444 100644 --- a/files/templates/api.html +++ b/files/templates/api.html @@ -17,7 +17,7 @@

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

  • an application name
  • -
  • a Redirect URI. May not use HTTP unless using 0.0.0.0 (use HTTPS instead).
  • +
  • a Redirect URI. May not use HTTP unless using localhost (use HTTPS instead).
  • a brief description of what your bot is intended to do

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

@@ -54,7 +54,7 @@

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

  • an application name
  • -
  • a Redirect URI. May not use HTTP unless using 0.0.0.0 (use HTTPS instead).
  • +
  • a Redirect URI. May not use HTTP unless using localhost (use HTTPS instead).
  • a brief description of what your application is intended to do

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

diff --git a/files/templates/comments.html b/files/templates/comments.html index 7ec9b2e74..9b33b7aba 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -773,7 +773,7 @@ } .popover { - max-width: 100%; + max-width: 80%; box-shadow: 0 1rem 3rem rgba(0, 0, 0, .175); border-color: #dadada; } diff --git a/files/templates/submission.html b/files/templates/submission.html index 051a40337..a7014db0d 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -392,11 +392,6 @@ {% endif %} - {% if not v.id==p.author_id and v.admin_level == 1 %} - - - {% endif %} - {% if v and v.admin_level > 1 and v.id!=p.author_id %} @@ -686,11 +681,6 @@ Block user {% endif %} - {% if not v.id==p.author_id and v.admin_level == 1 %} - Ban user - Unban user - {% endif %} - {% if v.admin_level > 1 and v.id!=p.author_id %} Ban user Unban user diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index 52f9321c2..fcabdb7d2 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -484,11 +484,6 @@ {% endif %} - {% if not v.id==p.author_id and v.admin_level == 1 %} - - - {% endif %} - {% if v and v.admin_level > 1 and v.id!=p.author_id %} @@ -616,7 +611,7 @@