From 1d6d263a673e07aa3224d031783d08c4cb75c36e Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Mon, 26 Jul 2021 20:47:42 +0200 Subject: [PATCH] fddf --- drama/__main__.py | 7 +++---- drama/classes/__init__.py | 2 +- drama/classes/award.py | 2 +- drama/classes/badges.py | 1 - drama/classes/comment.py | 1 - drama/classes/submission.py | 2 +- drama/helpers/jinja2.py | 1 - drama/helpers/sanitize.py | 4 ++-- drama/helpers/wrappers.py | 2 +- drama/routes/admin.py | 12 ++++-------- drama/routes/comments.py | 2 -- drama/routes/discord.py | 2 +- drama/routes/login.py | 9 +++++---- drama/routes/posts.py | 2 +- drama/routes/settings.py | 10 +++++----- drama/routes/users.py | 2 +- 16 files changed, 26 insertions(+), 35 deletions(-) diff --git a/drama/__main__.py b/drama/__main__.py index 21654ac75..b390c20bb 100644 --- a/drama/__main__.py +++ b/drama/__main__.py @@ -1,8 +1,7 @@ import gevent.monkey gevent.monkey.patch_all() -import os -from os import environ +from os import environ, path import secrets from flask import * from flask_caching import Cache @@ -35,7 +34,7 @@ app.config["SITE_NAME"]=environ.get("SITE_NAME", "Drama").strip() app.config["SITE_COLOR"]=environ.get("SITE_COLOR", "805ad5").strip() -app.config["DRAMAPATH"]=environ.get("DRAMAPATH", os.path.dirname(os.path.realpath(__file__))) +app.config["DRAMAPATH"]=environ.get("DRAMAPATH", path.dirname(path.realpath(__file__))) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['DATABASE_URL'] = environ.get( @@ -300,7 +299,7 @@ def log_event(name, link): text = f'> **{name}**\r> {link}' - url = os.environ.get("DISCORD_WEBHOOK") + url = environ.get("DISCORD_WEBHOOK") headers = {"Content-Type": "application/json"} data = {"username": "drama", "content": text diff --git a/drama/classes/__init__.py b/drama/classes/__init__.py index 8f7333980..6e0e68d78 100644 --- a/drama/classes/__init__.py +++ b/drama/classes/__init__.py @@ -2,7 +2,7 @@ from .alts import * from .badges import * from .clients import * from .comment import * -from .domains import Domain +from .domains import * from .flags import * from .user import * from .userblock import * diff --git a/drama/classes/award.py b/drama/classes/award.py index dfe3b5ec2..f8e3cc835 100644 --- a/drama/classes/award.py +++ b/drama/classes/award.py @@ -3,7 +3,7 @@ from sqlalchemy import * from sqlalchemy.orm import relationship #from .mix_ins import * -from drama.__main__ import Base, app +from drama.__main__ import Base AWARDS = { "ban": { diff --git a/drama/classes/badges.py b/drama/classes/badges.py index 89db37751..fdc376001 100644 --- a/drama/classes/badges.py +++ b/drama/classes/badges.py @@ -1,4 +1,3 @@ -from flask import render_template from sqlalchemy import * from sqlalchemy.orm import relationship diff --git a/drama/classes/comment.py b/drama/classes/comment.py index be5f170bb..9821a07de 100644 --- a/drama/classes/comment.py +++ b/drama/classes/comment.py @@ -1,7 +1,6 @@ from flask import * from sqlalchemy import * from sqlalchemy.orm import relationship, deferred -from sqlalchemy.ext.associationproxy import association_proxy from .mix_ins import * from drama.helpers.base36 import * from drama.helpers.lazy import lazy diff --git a/drama/classes/submission.py b/drama/classes/submission.py index 3e110fbdd..6ffcc537f 100644 --- a/drama/classes/submission.py +++ b/drama/classes/submission.py @@ -1,4 +1,4 @@ -from flask import render_template, request, g +from flask import render_template, g from sqlalchemy import * from sqlalchemy.orm import relationship, deferred import re, random diff --git a/drama/helpers/jinja2.py b/drama/helpers/jinja2.py index 2c3a6abab..d19bdbdfc 100644 --- a/drama/helpers/jinja2.py +++ b/drama/helpers/jinja2.py @@ -1,5 +1,4 @@ from os import environ, path -import calendar from .get import * from drama.__main__ import app, cache diff --git a/drama/helpers/sanitize.py b/drama/helpers/sanitize.py index 8473180d2..2ad979376 100644 --- a/drama/helpers/sanitize.py +++ b/drama/helpers/sanitize.py @@ -4,7 +4,7 @@ from bleach.linkifier import LinkifyFilter from urllib.parse import ParseResult, urlunparse from functools import partial from .get import * -import os.path +from os import path _allowed_tags = tags = ['b', 'blockquote', @@ -189,7 +189,7 @@ def sanitize(text, linkgen=False, flair=False): if flair: emojisize = 20 else: emojisize = 30 for i in re.finditer(':(.{1,30}?):', sanitized): - if os.path.isfile(f'/d/drama/assets/images/emojis/{i.group(1)}.gif'): + if path.isfile(f'/d/drama/assets/images/emojis/{i.group(1)}.gif'): 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/helpers/wrappers.py b/drama/helpers/wrappers.py index 0793e5921..a88b2aae6 100644 --- a/drama/helpers/wrappers.py +++ b/drama/helpers/wrappers.py @@ -1,7 +1,7 @@ from werkzeug.wrappers.response import Response as RespObj from .get import * from .alerts import send_notification -from drama.__main__ import Base, app, db_session +from drama.__main__ import app def get_logged_in_user(db=None): diff --git a/drama/routes/admin.py b/drama/routes/admin.py index 36541081c..f3b126bac 100644 --- a/drama/routes/admin.py +++ b/drama/routes/admin.py @@ -1,12 +1,8 @@ -from urllib.parse import urlparse import time import calendar -from sqlalchemy import func from sqlalchemy.orm import lazyload -import threading -import subprocess import imagehash -from os import remove, environ +from os import remove, path from PIL import Image as IMAGE from drama.helpers.wrappers import * @@ -545,9 +541,9 @@ def agendaposter(user_id, v): @admin_level_required(6) @validate_formkey def disablesignups(v): - - environ["DISABLESIGNUPS"] = "0" if app.config.get("DISABLESIGNUPS") else "1" - app.config["DISABLESIGNUPS"] = not app.config.get("DISABLESIGNUPS") + with open('./disablesignups', 'w') as f: + if f.read() == "yes": f.write("no") + else: f.write("yes") return "", 204 diff --git a/drama/routes/comments.py b/drama/routes/comments.py index 4908f4e92..8bc2e2cb4 100644 --- a/drama/routes/comments.py +++ b/drama/routes/comments.py @@ -1,5 +1,3 @@ -import threading - from drama.helpers.wrappers import * from drama.helpers.filters import * from drama.helpers.alerts import * diff --git a/drama/routes/discord.py b/drama/routes/discord.py index 778e92162..ee9656fba 100644 --- a/drama/routes/discord.py +++ b/drama/routes/discord.py @@ -1,6 +1,6 @@ from drama.helpers.wrappers import * from drama.helpers.security import * -from drama.helpers.discord import add_role, delete_role +from drama.helpers.discord import add_role from drama.__main__ import app SERVER_ID = environ.get("DISCORD_SERVER_ID",'').strip() diff --git a/drama/routes/login.py b/drama/routes/login.py index 64d59af57..d8887d855 100644 --- a/drama/routes/login.py +++ b/drama/routes/login.py @@ -134,6 +134,7 @@ def login_post(): @app.route("/me", methods=["GET"]) +@app.route("/@me", methods=["GET"]) @auth_required def me(v): return redirect(v.url) @@ -156,8 +157,8 @@ def logout(v): @no_cors @auth_desired def sign_up_get(v): - #if app.config.get("DISABLESIGNUPS", False): - # return "Signups are disable for the time being.", 403 + with open('./disablesignups', 'r') as f: + if f.read() == "yes": return "Signups are disable for the time being.", 403 if v: return redirect("/") @@ -213,8 +214,8 @@ def sign_up_get(v): @no_cors @auth_desired def sign_up_post(v): - #if app.config.get("DISABLESIGNUPS", False): - # return "Signups are disable for the time being.", 403 + with open('./disablesignups', 'r') as f: + if f.read() == "yes": return "Signups are disable for the time being.", 403 if v: abort(403) diff --git a/drama/routes/posts.py b/drama/routes/posts.py index 61150d4c0..db2045e2e 100644 --- a/drama/routes/posts.py +++ b/drama/routes/posts.py @@ -16,7 +16,7 @@ from drama.classes import * from .front import frontlist from flask import * from io import BytesIO -from drama.__main__ import app, limiter, cache, db_session +from drama.__main__ import app, limiter, cache from PIL import Image as PILimage with open("snappy.txt", "r") as f: diff --git a/drama/routes/settings.py b/drama/routes/settings.py index 6944e22bb..0660b701c 100644 --- a/drama/routes/settings.py +++ b/drama/routes/settings.py @@ -575,7 +575,7 @@ def settings_name_change(v): def settings_song_change(v): song=request.form.get("song").strip() - if song == "" and v.song and os.path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User).filter_by(song=v.song).count() == 1: + if song == "" and v.song and path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User).filter_by(song=v.song).count() == 1: os.remove(f"/songs/{v.song}.mp3") v.song=None g.db.add(v) @@ -594,7 +594,7 @@ def settings_song_change(v): if "?" in id: id = id.split("?")[0] if "&" in id: id = id.split("&")[0] - if os.path.isfile(f'/songs/{id}.mp3'): + if path.isfile(f'/songs/{id}.mp3'): v.song=id g.db.add(v) g.db.commit() @@ -619,7 +619,7 @@ def settings_song_change(v): error=f"Duration of the video must not exceed 10 minutes.") - if v.song and os.path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User).filter_by(song=v.song).count() == 1: + if v.song and path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User).filter_by(song=v.song).count() == 1: os.remove(f"/songs/{v.song}.mp3") ydl_opts = { @@ -641,8 +641,8 @@ def settings_song_change(v): error=f"Age-restricted videos aren't allowed.") files = os.listdir("/songs/") - paths = [os.path.join("/songs/", basename) for basename in files] - songfile = max(paths, key=os.path.getctime) + paths = [path.join("/songs/", basename) for basename in files] + songfile = max(paths, key=path.getctime) os.rename(songfile, f"/songs/{id}.mp3") v.song=id diff --git a/drama/routes/users.py b/drama/routes/users.py index c7a40ad80..ff8ae264d 100644 --- a/drama/routes/users.py +++ b/drama/routes/users.py @@ -9,7 +9,7 @@ from drama.helpers.sanitize import * from drama.helpers.markdown import * from drama.mail import * from flask import * -from drama.__main__ import app, cache, limiter, db_session +from drama.__main__ import app, limiter from pusher_push_notifications import PushNotifications PUSHER_KEY = environ.get("PUSHER_KEY", "").strip()