diff --git a/.gitignore b/.gitignore index 573861baef..a3c077c104 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ disablesignups **/.pytest_cache/ venv/ .vscode/ -.sass-cache/ \ No newline at end of file +.sass-cache/ +flask_session/ \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 496cf97a39..cb8253dd8f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,7 +13,6 @@ services: - DOMAIN=localhost - SITE_NAME=Drama - GIPHY_KEY=3435tdfsdudebussylmaoxxt43 - - FORCE_HTTPS=0 - DISCORD_SERVER_ID=3435tdfsdudebussylmaoxxt43 - DISCORD_CLIENT_ID=3435tdfsdudebussylmaoxxt43 - DISCORD_CLIENT_SECRET=3435tdfsdudebussylmaoxxt43 diff --git a/env b/env index a3f4b83fb4..f96bfbb8d6 100644 --- a/env +++ b/env @@ -3,7 +3,6 @@ export MASTER_KEY="XuxGqp5NyygJrM24b5gt3YgyvFVGdQnwVDwLzLwpu3eQwY" export DOMAIN="localhost" export SITE_NAME="Drama" export GIPHY_KEY="3435tdfsdudebussylmaoxxt43" -export FORCE_HTTPS="0" export DISCORD_SERVER_ID="3435tdfsdudebussylmaoxxt43" export DISCORD_CLIENT_ID="3435tdfsdudebussylmaoxxt43" export DISCORD_CLIENT_SECRET="3435tdfsdudebussylmaoxxt43" diff --git a/files/__main__.py b/files/__main__.py index f30308c004..837ee83418 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -8,6 +8,7 @@ from flask_limiter import Limiter from flask_compress import Compress from flask_limiter.util import get_ipaddr from flask_mail import Mail +from flask_session import Session from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker, scoped_session @@ -17,6 +18,8 @@ from werkzeug.middleware.proxy_fix import ProxyFix import redis app = Flask(__name__, template_folder='templates') +app.config["SESSION_TYPE"] = "redis" +Session(app) app.wsgi_app = ProxyFix(app.wsgi_app, x_for=3) app.url_map.strict_slashes = False @@ -24,6 +27,7 @@ app.jinja_env.cache = {} app.jinja_env.auto_reload = True import faulthandler faulthandler.enable() + app.config["SITE_NAME"]=environ.get("SITE_NAME").strip() app.config["COINS_NAME"]=environ.get("COINS_NAME").strip() @@ -36,14 +40,13 @@ app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 86400 app.config["SESSION_COOKIE_NAME"] = f'session_{environ.get("DOMAIN")}'.strip().lower() app.config["VERSION"] = "1.0.0" app.config['MAX_CONTENT_LENGTH'] = 8 * 1024 * 1024 -app.config["SESSION_COOKIE_SECURE"] = bool(int(environ.get("FORCE_HTTPS", 1))) +app.config["SESSION_COOKIE_SECURE"] = True app.config["SESSION_COOKIE_SAMESITE"] = "Lax" app.config["PERMANENT_SESSION_LIFETIME"] = 60 * 60 * 24 * 365 -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 "localhost" not in app.config["SERVER_NAME"]) else 0 +app.config["FORCE_HTTPS"] = True 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() @@ -59,7 +62,7 @@ app.config["RATELIMIT_ENABLED"] = True app.config["RATELIMIT_DEFAULTS_DEDUCT_WHEN"]=lambda:True app.config["RATELIMIT_DEFAULTS_EXEMPT_WHEN"]=lambda:False app.config["RATELIMIT_HEADERS_ENABLED"]=True -app.config["CACHE_TYPE"] = "filesystem" +app.config["CACHE_TYPE"] = "redis" app.config["CACHE_DIR"] = "cache" app.config["RATELIMIT_STORAGE_URL"] = environ.get("REDIS_URL", "redis://localhost") app.config['MAIL_SERVER'] = 'smtp.gmail.com' @@ -68,6 +71,10 @@ app.config['MAIL_USE_TLS'] = True app.config['MAIL_USERNAME'] = environ.get("MAIL_USERNAME", "").strip() app.config['MAIL_PASSWORD'] = environ.get("MAIL_PASSWORD", "").strip() +app.config["SESSION_USE_SIGNER"] = True +app.config["SESSION_COOKIE_DOMAIN"] = app.config["SERVER_NAME"] + + r=redis.Redis(host=environ.get("REDIS_URL", "redis://localhost"), decode_responses=True, ssl_cert_reqs=None) limiter = Limiter( @@ -101,9 +108,9 @@ def before_request(): if not request.path.startswith("/assets") and not request.path.startswith("/images") and not request.path.startswith("/hostedimages"): session.permanent = True - if not session.get("session_id"): session["session_id"] = secrets.token_hex(16) + if not session.get("session_id"): session["session_id"] = secrets.token_hex(50) - if app.config["FORCE_HTTPS"] and request.url.startswith("http://") and "localhost" not in app.config["SERVER_NAME"]: + if 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/user.py b/files/classes/user.py index 5378ace780..0299e7e4ad 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -302,7 +302,7 @@ class User(Base): def formkey(self): if "session_id" not in session: - session["session_id"] = token_hex(16) + session["session_id"] = token_hex(50) msg = f"{session['session_id']}+{self.id}+{self.login_nonce}" @@ -377,6 +377,10 @@ class User(Base): def post_notifications_count(self): return g.db.query(Notification.id).join(Comment).filter(Notification.user_id == self.id, Notification.read == False, Comment.author_id == AUTOJANNY_ID).count() + @property + @lazy + def not_post_notifications_count(self): + return self.notifications_count - self.post_notifications_count @property @lazy diff --git a/files/routes/admin.py b/files/routes/admin.py index 8808bfdb2f..fe179b8eef 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -1030,8 +1030,12 @@ def api_sticky_post(post_id, v): else: post.stickied = None else: pins = g.db.query(Submission.id).filter(Submission.stickied != None, Submission.is_banned == False).count() - if pins > 2: return {"error": "Can't exceed 3 pinned posts limit!"}, 403 - post.stickied = v.username + if pins > 2: + if v.admin_level > 2: + t = int(time.time()) + 3600 + post.stickied = f"t:{t}" + else: return {"error": "Can't exceed 3 pinned posts limit!"}, 403 + else: post.stickied = v.username g.db.add(post) ma=ModAction( diff --git a/files/routes/login.py b/files/routes/login.py index 7252cad50a..66a35df3d0 100644 --- a/files/routes/login.py +++ b/files/routes/login.py @@ -136,7 +136,7 @@ def login_post(): session["user_id"] = account.id session["logged_in"] = account.id - session["session_id"] = token_hex(16) + session["session_id"] = token_hex(50) session["login_nonce"] = account.login_nonce session.permanent = True @@ -343,7 +343,7 @@ def sign_up_post(v): session["user_id"] = new_user.id session["logged_in"] = new_user.id - session["session_id"] = token_hex(16) + session["session_id"] = token_hex(50) g.db.commit() diff --git a/files/routes/static.py b/files/routes/static.py index 16f4602fc5..d8263f2059 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -104,10 +104,10 @@ def cached_chart(days): days = int((nowstamp - firstsignup) / 86400) if days > 31: - file = "/weekly_chart.webp" + file = "/weekly_chart.png" day_cutoffs = [today_cutoff - 86400 * 7 * i for i in range(31)][1:] else: - file = "/daily_chart.webp" + file = "/daily_chart.png" day_cutoffs = [today_cutoff - 86400 * i for i in range(31)][1:] day_cutoffs.insert(0, calendar.timegm(now)) diff --git a/files/templates/CHRISTMAS/authforms.html b/files/templates/CHRISTMAS/authforms.html index 6a86f01685..0ef68cfd27 100644 --- a/files/templates/CHRISTMAS/authforms.html +++ b/files/templates/CHRISTMAS/authforms.html @@ -14,11 +14,11 @@ {% if v %} - + {% if v.agendaposter %}{% elif v.css %}{% endif %} {% else %} - + {% endif %} diff --git a/files/templates/CHRISTMAS/default.html b/files/templates/CHRISTMAS/default.html index 24bbd5b8e4..67f5fdaf92 100644 --- a/files/templates/CHRISTMAS/default.html +++ b/files/templates/CHRISTMAS/default.html @@ -186,9 +186,9 @@ {% block stylesheets %} - + - + diff --git a/files/templates/CHRISTMAS/login.html b/files/templates/CHRISTMAS/login.html index 2124492c02..b440e3481d 100644 --- a/files/templates/CHRISTMAS/login.html +++ b/files/templates/CHRISTMAS/login.html @@ -13,9 +13,9 @@ Login - {{'SITE_NAME' | app_config}} {% endblock %} - + - + diff --git a/files/templates/CHRISTMAS/login_2fa.html b/files/templates/CHRISTMAS/login_2fa.html index 415ca9105d..8fa4ef088f 100644 --- a/files/templates/CHRISTMAS/login_2fa.html +++ b/files/templates/CHRISTMAS/login_2fa.html @@ -13,7 +13,7 @@ 2-Step Login - {{'SITE_NAME' | app_config}} - + diff --git a/files/templates/CHRISTMAS/settings.html b/files/templates/CHRISTMAS/settings.html index efc348913c..9e8986fe80 100644 --- a/files/templates/CHRISTMAS/settings.html +++ b/files/templates/CHRISTMAS/settings.html @@ -28,9 +28,9 @@ {% block stylesheets %} - + - + diff --git a/files/templates/CHRISTMAS/sign_up.html b/files/templates/CHRISTMAS/sign_up.html index d364674e22..6abca73929 100644 --- a/files/templates/CHRISTMAS/sign_up.html +++ b/files/templates/CHRISTMAS/sign_up.html @@ -26,9 +26,9 @@ {% if ref_user %}{{ref_user.username}} invites you to {{'SITE_NAME' | app_config}}{% else %}Sign up - {{'SITE_NAME' | app_config}}{% endif %} - + - + diff --git a/files/templates/CHRISTMAS/sign_up_failed_ref.html b/files/templates/CHRISTMAS/sign_up_failed_ref.html index 3cbebfe6f2..6aee3cfbb4 100644 --- a/files/templates/CHRISTMAS/sign_up_failed_ref.html +++ b/files/templates/CHRISTMAS/sign_up_failed_ref.html @@ -31,7 +31,7 @@ {% if ref_user %}{{ref_user.username}} invites you to {{'SITE_NAME' | app_config}}{% else %}{{'SITE_NAME' | app_config}}{% endif %} - + diff --git a/files/templates/CHRISTMAS/tailwind.html b/files/templates/CHRISTMAS/tailwind.html index 273cdbcff5..e3e520504c 100644 --- a/files/templates/CHRISTMAS/tailwind.html +++ b/files/templates/CHRISTMAS/tailwind.html @@ -5,7 +5,7 @@ - + Flask + Tailwind CSS diff --git a/files/templates/authforms.html b/files/templates/authforms.html index 9fe37eba77..607565bd29 100644 --- a/files/templates/authforms.html +++ b/files/templates/authforms.html @@ -14,11 +14,11 @@ {% if v %} - + {% if v.agendaposter %}{% elif v.css %}{% endif %} {% else %} - + {% endif %} diff --git a/files/templates/comments.html b/files/templates/comments.html index 22fe594dd3..6110dde155 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -297,7 +297,7 @@ Save Edit Cancel -
+
Formatting help
{% endif %} diff --git a/files/templates/default.html b/files/templates/default.html index 1adfdbc8eb..f18547295e 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -6,12 +6,12 @@ {% if v %} - + {% if v.agendaposter %}{% elif v.css %}{% endif %} {% else %} - + {% endif %} diff --git a/files/templates/log.html b/files/templates/log.html index 9436b5147c..9b9391981a 100644 --- a/files/templates/log.html +++ b/files/templates/log.html @@ -6,11 +6,11 @@ {% block content %} {% if v %} - + {% if v.agendaposter %}{% elif v.css %}{% endif %} {% else %} - + {% endif %}
diff --git a/files/templates/login.html b/files/templates/login.html index 6c45097bcb..ad945e3575 100644 --- a/files/templates/login.html +++ b/files/templates/login.html @@ -17,7 +17,7 @@ {% endblock %} - + diff --git a/files/templates/login_2fa.html b/files/templates/login_2fa.html index aed01ba8ee..7a3c08f867 100644 --- a/files/templates/login_2fa.html +++ b/files/templates/login_2fa.html @@ -13,7 +13,7 @@ 2-Step Login - {{'SITE_NAME' | app_config}} - + diff --git a/files/templates/notifications.html b/files/templates/notifications.html index e8581a7ef3..dfcf59f32b 100644 --- a/files/templates/notifications.html +++ b/files/templates/notifications.html @@ -17,7 +17,7 @@