From c288c09e6095654d49cefbb789879f455535417c Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Wed, 19 Jan 2022 17:35:08 +0200 Subject: [PATCH 01/27] dfs --- files/routes/settings.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/files/routes/settings.py b/files/routes/settings.py index 427e3fe1b..d81b5b955 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -857,7 +857,7 @@ def settings_name_change(v): v=v, error=f"Username `{new_name}` is already in use.") - v=g.db.query(User).with_for_update().filter_by(id=v.id).one_or_none() + v=g.db.query(User).filter_by(id=v.id).one_or_none() v.username=new_name v.name_changed_utc=int(time.time()) @@ -876,8 +876,9 @@ def settings_name_change(v): def settings_song_change(v): song=request.values.get("song").strip() - if song == "" and v.song and path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User.id).filter_by(song=v.song).count() == 1: - os.remove(f"/songs/{v.song}.mp3") + if song == "" and v.song: + if path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User.id).filter_by(song=v.song).count() == 1: + os.remove(f"/songs/{v.song}.mp3") v.song = None g.db.add(v) g.db.commit() From 8c2ec9f6f481b51cb0c786a8f7d44a2a4549ab89 Mon Sep 17 00:00:00 2001 From: idio3 <95141553+idio3@users.noreply.github.com> Date: Thu, 20 Jan 2022 13:03:50 -0600 Subject: [PATCH 05/27] Update const.py for badass outlaw badge --- files/helpers/const.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/files/helpers/const.py b/files/helpers/const.py index 4f7a01c45..8f6abf28c 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -477,6 +477,10 @@ BADGES = { 'name': 'Benefactor', 'description': 'Gave the Benefactor award to someone' }, + 104: { + 'name': 'BADASS OUTLAW', + 'description': 'Bad boy who does not play by the rules' + }, } AWARDS = { @@ -792,4 +796,4 @@ NOTIFIED_USERS = { } num_banners = len(listdir('files/assets/images/Drama/banners')) + 1 -num_sidebar = len(listdir('files/assets/images/Drama/sidebar')) + 1 \ No newline at end of file +num_sidebar = len(listdir('files/assets/images/Drama/sidebar')) + 1 From 9ca4b8f0679b65ffec0fb0df1ed58a09c2b56b9e Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 21 Jan 2022 10:44:19 +0200 Subject: [PATCH 06/27] fsd --- files/routes/admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/routes/admin.py b/files/routes/admin.py index f83209d96..55a48302a 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -1170,7 +1170,7 @@ def api_unban_comment(c_id, v): comment = g.db.query(Comment).filter_by(id=c_id).one_or_none() if not comment: abort(404) - if comment.author.agendaposter and 'black lives matters' not in comment.body.lower(): + if comment.author.agendaposter and AGENDAPOSTER_PHRASE not in comment.body.lower(): return {"error": "You can't bypass the agendaposter award!"} if comment.is_banned: From da3cb04dc8d6efada5e0be674208d20d5158fd7b Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 21 Jan 2022 12:14:50 +0200 Subject: [PATCH 07/27] et --- .github/CODEOWNERS | 1 + files/templates/authforms.html | 4 ++-- files/templates/default.html | 6 +++--- files/templates/log.html | 4 ++-- files/templates/login.html | 4 ++-- files/templates/login_2fa.html | 2 +- files/templates/settings.html | 2 +- files/templates/settings2.html | 4 ++-- files/templates/sign_up.html | 2 +- files/templates/sign_up_failed_ref.html | 2 +- files/templates/submit.html | 6 +++--- requirements.txt | 4 ++-- 12 files changed, 21 insertions(+), 20 deletions(-) create mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 000000000..f1e5b454c --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @Aevann1 \ No newline at end of file diff --git a/files/templates/authforms.html b/files/templates/authforms.html index 921680209..5993154bf 100644 --- a/files/templates/authforms.html +++ b/files/templates/authforms.html @@ -15,7 +15,7 @@ {% if v %} - + {% if v.agendaposter %} - + {% endif %} diff --git a/files/templates/default.html b/files/templates/default.html index 73109ff07..359252334 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -7,8 +7,8 @@ {% if v %} - - + + {% if v.agendaposter %} - + {% endif %} diff --git a/files/templates/log.html b/files/templates/log.html index 84841813e..281e10d40 100644 --- a/files/templates/log.html +++ b/files/templates/log.html @@ -6,7 +6,7 @@ {% block content %} {% if v %} - + {% if v.agendaposter %} - + {% endif %}
diff --git a/files/templates/login.html b/files/templates/login.html index 7063169dd..1fc69d8a2 100644 --- a/files/templates/login.html +++ b/files/templates/login.html @@ -18,8 +18,8 @@ {% endblock %} - - + + diff --git a/files/templates/login_2fa.html b/files/templates/login_2fa.html index 9ba4654a1..031d6e5b1 100644 --- a/files/templates/login_2fa.html +++ b/files/templates/login_2fa.html @@ -14,7 +14,7 @@ 2-Step Login - {{SITE_NAME}} - + diff --git a/files/templates/settings.html b/files/templates/settings.html index 1a30655c4..f403c45f9 100644 --- a/files/templates/settings.html +++ b/files/templates/settings.html @@ -34,7 +34,7 @@ - + {% if v.agendaposter %} - + {% else %} - + {% endif %} diff --git a/files/templates/sign_up.html b/files/templates/sign_up.html index b927f5752..db4f5991e 100644 --- a/files/templates/sign_up.html +++ b/files/templates/sign_up.html @@ -31,7 +31,7 @@ {% if ref_user %}{{ref_user.username}} invites you to {{SITE_NAME}}{% else %}Sign up - {{SITE_NAME}}{% endif %} - + diff --git a/files/templates/sign_up_failed_ref.html b/files/templates/sign_up_failed_ref.html index 04855c638..f8902b593 100644 --- a/files/templates/sign_up_failed_ref.html +++ b/files/templates/sign_up_failed_ref.html @@ -32,7 +32,7 @@ {% if ref_user %}{{ref_user.username}} invites you to {{SITE_NAME}}{% else %}{{SITE_NAME}}{% endif %} - + diff --git a/files/templates/submit.html b/files/templates/submit.html index d02d803db..e50330ae0 100644 --- a/files/templates/submit.html +++ b/files/templates/submit.html @@ -26,7 +26,7 @@ {% block stylesheets %} {% if v %} - + {% if v.agendaposter %} - - + + {% endif %} {% endblock %} diff --git a/requirements.txt b/requirements.txt index f444eafa5..2b9065681 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,11 +4,11 @@ Flask Flask-Caching Flask-Compress Flask-Limiter==1.1.0 -Flask-Mail==0.9.1 +Flask-Mail gevent greenlet gunicorn -markdown +mistletoe matplotlib Pillow psutil From 7275a0b8c4a72c9d0a20b2933a8c4a57ec627d71 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 21 Jan 2022 12:44:12 +0200 Subject: [PATCH 08/27] fds --- files/routes/login.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/files/routes/login.py b/files/routes/login.py index c263cb600..0aa7d5195 100644 --- a/files/routes/login.py +++ b/files/routes/login.py @@ -396,6 +396,8 @@ def get_reset(): user = g.db.query(User).filter_by(id=user_id).one_or_none() + if not user: abort(400) + if not validate_hash(f"{user_id}+{timestamp}+forgot+{user.login_nonce}", token): abort(400) From 1e22d766f95ed289d6e20e258c040b81b821533f Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 21 Jan 2022 13:14:24 +0200 Subject: [PATCH 09/27] testing --- files/__main__.py | 14 +++++++++++++- files/helpers/const.py | 7 +++++++ files/helpers/sanitize.py | 2 -- files/routes/comments.py | 2 +- files/routes/static.py | 6 ------ files/routes/users.py | 4 ++-- requirements.txt | 2 +- 7 files changed, 24 insertions(+), 13 deletions(-) diff --git a/files/__main__.py b/files/__main__.py index effabd220..062b0ff56 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -17,6 +17,7 @@ import redis import time from sys import stdout import faulthandler +import atexit app = Flask(__name__, template_folder='templates') app.wsgi_app = ProxyFix(app.wsgi_app, x_for=3) @@ -84,6 +85,8 @@ mail = Mail(app) @app.before_request def before_request(): + print(request.access_route[0]) + print(request.remote_addr) if request.method.lower() != "get" and app.config["READ_ONLY"]: return {"error":f"{app.config['SITE_NAME']} is currently in read-only mode."}, 500 @@ -109,4 +112,13 @@ def after_request(response): response.headers.add("X-Frame-Options", "deny") return response -from files.routes import * \ No newline at end of file +from files.routes import * + +def close_running_threads(): + with open("marsey_count.json", 'r') as f: marsey_file = loads(f.read()) + print(marsey_count['marseylove']) + if marsey_file != marsey_count: + with open('marsey_count.json', 'w') as f: dump(marsey_count, f) + print("Marsey count saved!") + stdout.flush() +atexit.register(close_running_threads) diff --git a/files/helpers/const.py b/files/helpers/const.py index 8f6abf28c..7af17ba08 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -797,3 +797,10 @@ NOTIFIED_USERS = { num_banners = len(listdir('files/assets/images/Drama/banners')) + 1 num_sidebar = len(listdir('files/assets/images/Drama/sidebar')) + 1 + + +with open("marsey_count.json", 'r') as f: marsey_count = loads(f.read()) +marsey_counted = [] +for k, val in marseys.items(): + marsey_counted.append((k, val, marsey_count[k])) +marsey_counted = sorted(marsey_counted, key=lambda x: x[2], reverse=True) \ No newline at end of file diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index d205648f4..228d49099 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -178,7 +178,6 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): sanitized = re.sub('\|\|(.*?)\|\|', r'\1', sanitized) if comment: - with open("marsey_count.json", 'r') as f: marsey_count = loads(f.read()) marseys_used = set() for i in re.finditer("[^a]>\s*(:[!#]{0,2}\w+:\s*)+<\/", sanitized): @@ -260,7 +259,6 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): if comment: for emoji in marseys_used: if emoji in marsey_count: marsey_count[emoji] += 1 - with open('marsey_count.json', 'w') as f: dump(marsey_count, f) return sanitized diff --git a/files/routes/comments.py b/files/routes/comments.py index a771710bb..e2bb0e51b 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -481,7 +481,7 @@ def api_comment(v): 'body': notifbody, }, 'data': { - 'url': f'comment/{c.id}?context=9&read=true#context', + 'url': f'/comment/{c.id}?context=9&read=true#context', } } }, diff --git a/files/routes/static.py b/files/routes/static.py index 2f78698fa..02ba09982 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -17,12 +17,6 @@ def privacy(v): @app.get("/marseys") @auth_required def emojis(v): - with open("marsey_count.json", 'r') as file: - marsey_count = loads(file.read()) - marsey_counted = [] - for k, val in marseys.items(): - marsey_counted.append((k, val, marsey_count[k])) - marsey_counted = sorted(marsey_counted, key=lambda x: x[2], reverse=True) return render_template("marseys.html", v=v, marseys=marsey_counted) @app.get("/terms") diff --git a/files/routes/users.py b/files/routes/users.py index e24dd1809..75fa36059 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -503,7 +503,7 @@ def message2(v, username): 'body': notifbody, }, 'data': { - 'url': 'notifications?messages=true', + 'url': '/notifications?messages=true', } } }, @@ -570,7 +570,7 @@ def messagereply(v): 'body': notifbody, }, 'data': { - 'url': 'notifications?messages=true', + 'url': '/notifications?messages=true', } } }, diff --git a/requirements.txt b/requirements.txt index 2b9065681..0a46c4b26 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ bleach Flask Flask-Caching Flask-Compress -Flask-Limiter==1.1.0 +Flask-Limiter Flask-Mail gevent greenlet From 68f0ff9a8a513cc4e58d6f946cd2ea58e7cdafba Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 21 Jan 2022 13:16:24 +0200 Subject: [PATCH 10/27] fds --- files/__main__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/__main__.py b/files/__main__.py index 062b0ff56..19cd10fb9 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -85,8 +85,8 @@ mail = Mail(app) @app.before_request def before_request(): - print(request.access_route[0]) - print(request.remote_addr) + print('first: ' + request.access_route[0]) + print('second: ' + request.remote_addr) if request.method.lower() != "get" and app.config["READ_ONLY"]: return {"error":f"{app.config['SITE_NAME']} is currently in read-only mode."}, 500 From 0679acba9bc88b037cea4733cb22cf9f369fc18d Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 21 Jan 2022 13:18:33 +0200 Subject: [PATCH 11/27] fds --- files/__main__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/files/__main__.py b/files/__main__.py index 19cd10fb9..a684a3c20 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -85,8 +85,6 @@ mail = Mail(app) @app.before_request def before_request(): - print('first: ' + request.access_route[0]) - print('second: ' + request.remote_addr) if request.method.lower() != "get" and app.config["READ_ONLY"]: return {"error":f"{app.config['SITE_NAME']} is currently in read-only mode."}, 500 @@ -108,6 +106,9 @@ def teardown_request(error): @app.after_request def after_request(response): + print('first: ' + request.access_route[0]) + print('second: ' + request.remote_addr) + response.headers.add("Strict-Transport-Security", "max-age=31536000") response.headers.add("X-Frame-Options", "deny") return response From a0c1187c673a6c07c5dbff15e717149ad4d33824 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 21 Jan 2022 13:20:08 +0200 Subject: [PATCH 12/27] ds --- files/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/__main__.py b/files/__main__.py index a684a3c20..877c3e65a 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -20,7 +20,7 @@ import faulthandler import atexit app = Flask(__name__, template_folder='templates') -app.wsgi_app = ProxyFix(app.wsgi_app, x_for=3) +app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1) app.url_map.strict_slashes = False app.jinja_env.cache = {} app.jinja_env.auto_reload = True From b4f083b1a00c811f14bf1ffd73b7bfb616004945 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 21 Jan 2022 13:20:53 +0200 Subject: [PATCH 13/27] fds --- files/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/__main__.py b/files/__main__.py index 877c3e65a..8b69758b3 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -20,7 +20,7 @@ import faulthandler import atexit app = Flask(__name__, template_folder='templates') -app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1) +app.wsgi_app = ProxyFix(app.wsgi_app, x_for=2) app.url_map.strict_slashes = False app.jinja_env.cache = {} app.jinja_env.auto_reload = True From 9f59fce8cfd45a096c1aa0e8ea0abce29e31d1c3 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 21 Jan 2022 13:22:18 +0200 Subject: [PATCH 14/27] fds --- files/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/__main__.py b/files/__main__.py index 8b69758b3..9ee146a18 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -20,7 +20,6 @@ import faulthandler import atexit app = Flask(__name__, template_folder='templates') -app.wsgi_app = ProxyFix(app.wsgi_app, x_for=2) app.url_map.strict_slashes = False app.jinja_env.cache = {} app.jinja_env.auto_reload = True @@ -108,6 +107,7 @@ def after_request(response): print('first: ' + request.access_route[0]) print('second: ' + request.remote_addr) + print('third: ' + request.headers['True-Client-IP']) response.headers.add("Strict-Transport-Security", "max-age=31536000") response.headers.add("X-Frame-Options", "deny") From 7b6cd365cb15de3dac46c4fdd51b2fc043f79004 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 21 Jan 2022 13:22:59 +0200 Subject: [PATCH 15/27] fds --- files/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/__main__.py b/files/__main__.py index 9ee146a18..1e3700357 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -107,7 +107,7 @@ def after_request(response): print('first: ' + request.access_route[0]) print('second: ' + request.remote_addr) - print('third: ' + request.headers['True-Client-IP']) + print('third: ' + request.headers.get('True-Client-IP')) response.headers.add("Strict-Transport-Security", "max-age=31536000") response.headers.add("X-Frame-Options", "deny") From 223ec90f556bcfd235c7907ee0a5ae55fb0c3a49 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 21 Jan 2022 13:23:41 +0200 Subject: [PATCH 16/27] sfd --- files/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/__main__.py b/files/__main__.py index 1e3700357..3dd1fa9bc 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -107,7 +107,7 @@ def after_request(response): print('first: ' + request.access_route[0]) print('second: ' + request.remote_addr) - print('third: ' + request.headers.get('True-Client-IP')) + print('third: ' + request.headers.get('CF-Connecting-IP')) response.headers.add("Strict-Transport-Security", "max-age=31536000") response.headers.add("X-Frame-Options", "deny") From 9098ccd6cc1fa7c14104a72f1856cba0f83db92b Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 21 Jan 2022 13:24:21 +0200 Subject: [PATCH 17/27] fds --- files/__main__.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/files/__main__.py b/files/__main__.py index 3dd1fa9bc..c1c342f93 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -65,7 +65,7 @@ r=redis.Redis(host=environ.get("REDIS_URL", "redis://localhost"), decode_respons limiter = Limiter( app, - key_func=get_ipaddr, + key_func=request.headers.get('CF-Connecting-IP'), default_limits=["3/second;30/minute;200/hour;1000/day"], application_limits=["10/second;200/minute;5000/hour;10000/day"], storage_uri=environ.get("REDIS_URL", "redis://localhost") @@ -104,11 +104,6 @@ def teardown_request(error): @app.after_request def after_request(response): - - print('first: ' + request.access_route[0]) - print('second: ' + request.remote_addr) - print('third: ' + request.headers.get('CF-Connecting-IP')) - response.headers.add("Strict-Transport-Security", "max-age=31536000") response.headers.add("X-Frame-Options", "deny") return response From a861e8ca0a668429cb4c23d1af1c617a84e81e81 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 21 Jan 2022 13:26:20 +0200 Subject: [PATCH 18/27] fds --- files/__main__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/files/__main__.py b/files/__main__.py index c1c342f93..280071577 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -19,6 +19,10 @@ from sys import stdout import faulthandler import atexit +def get_CF() -> str: + with app.app_context(): + return request.headers.get('CF-Connecting-IP') + app = Flask(__name__, template_folder='templates') app.url_map.strict_slashes = False app.jinja_env.cache = {} @@ -65,7 +69,7 @@ r=redis.Redis(host=environ.get("REDIS_URL", "redis://localhost"), decode_respons limiter = Limiter( app, - key_func=request.headers.get('CF-Connecting-IP'), + key_func=, default_limits=["3/second;30/minute;200/hour;1000/day"], application_limits=["10/second;200/minute;5000/hour;10000/day"], storage_uri=environ.get("REDIS_URL", "redis://localhost") From 085a94b8cd39a58ee68f69d564857825a7f5236d Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 21 Jan 2022 13:26:40 +0200 Subject: [PATCH 19/27] sfd --- files/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/__main__.py b/files/__main__.py index 280071577..dc0ddbdf1 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -20,7 +20,7 @@ import faulthandler import atexit def get_CF() -> str: - with app.app_context(): + with app.app_context(): return request.headers.get('CF-Connecting-IP') app = Flask(__name__, template_folder='templates') From 5f2b2d9a7b89b9947e8f65a5818714f933418269 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 21 Jan 2022 13:27:10 +0200 Subject: [PATCH 20/27] fds --- files/__main__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/files/__main__.py b/files/__main__.py index dc0ddbdf1..49c480d6a 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -19,10 +19,6 @@ from sys import stdout import faulthandler import atexit -def get_CF() -> str: - with app.app_context(): - return request.headers.get('CF-Connecting-IP') - app = Flask(__name__, template_folder='templates') app.url_map.strict_slashes = False app.jinja_env.cache = {} @@ -67,9 +63,13 @@ app.config['DESCRIPTION'] = environ.get("DESCRIPTION", "rdrama.net caters to dra r=redis.Redis(host=environ.get("REDIS_URL", "redis://localhost"), decode_responses=True, ssl_cert_reqs=None) +def get_CF() -> str: + with app.app_context(): + return request.headers.get('CF-Connecting-IP') + limiter = Limiter( app, - key_func=, + key_func=get_CF, default_limits=["3/second;30/minute;200/hour;1000/day"], application_limits=["10/second;200/minute;5000/hour;10000/day"], storage_uri=environ.get("REDIS_URL", "redis://localhost") From 54e75ad5bef6dd379c90e7e4d821e3bef2f6344f Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 21 Jan 2022 13:27:24 +0200 Subject: [PATCH 21/27] fds --- files/__main__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/files/__main__.py b/files/__main__.py index 49c480d6a..4be612ae0 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -6,7 +6,6 @@ from flask import * from flask_caching import Cache from flask_limiter import Limiter from flask_compress import Compress -from flask_limiter.util import get_ipaddr from flask_mail import Mail from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker, scoped_session From 549f10d166903455af535afb9424bc1e7812c718 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 21 Jan 2022 13:29:05 +0200 Subject: [PATCH 22/27] fcx --- files/__main__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/files/__main__.py b/files/__main__.py index 4be612ae0..5a9bbae64 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -6,6 +6,7 @@ from flask import * from flask_caching import Cache from flask_limiter import Limiter from flask_compress import Compress +from flask_limiter.util import get_remote_address from flask_mail import Mail from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker, scoped_session @@ -62,8 +63,11 @@ app.config['DESCRIPTION'] = environ.get("DESCRIPTION", "rdrama.net caters to dra r=redis.Redis(host=environ.get("REDIS_URL", "redis://localhost"), decode_responses=True, ssl_cert_reqs=None) +print('first: ' + get_remote_address()) + def get_CF() -> str: with app.app_context(): + print('second: ' + request.headers.get('CF-Connecting-IP')) return request.headers.get('CF-Connecting-IP') limiter = Limiter( From e1324b57fdf56c3d08813809cd00f4662b544415 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 21 Jan 2022 13:29:29 +0200 Subject: [PATCH 23/27] fsdfsd --- files/__main__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/files/__main__.py b/files/__main__.py index 5a9bbae64..a011ea0e7 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -63,7 +63,8 @@ app.config['DESCRIPTION'] = environ.get("DESCRIPTION", "rdrama.net caters to dra r=redis.Redis(host=environ.get("REDIS_URL", "redis://localhost"), decode_responses=True, ssl_cert_reqs=None) -print('first: ' + get_remote_address()) +with app.app_context(): + print('first: ' + get_remote_address()) def get_CF() -> str: with app.app_context(): From f209720b3eceb0b70fd2b241e748b3cb270bc3b4 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 21 Jan 2022 13:30:36 +0200 Subject: [PATCH 24/27] fsd --- files/__main__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/files/__main__.py b/files/__main__.py index a011ea0e7..d3181ce9a 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -63,12 +63,9 @@ app.config['DESCRIPTION'] = environ.get("DESCRIPTION", "rdrama.net caters to dra r=redis.Redis(host=environ.get("REDIS_URL", "redis://localhost"), decode_responses=True, ssl_cert_reqs=None) -with app.app_context(): - print('first: ' + get_remote_address()) - def get_CF() -> str: with app.app_context(): - print('second: ' + request.headers.get('CF-Connecting-IP')) + print('real: ' + request.headers.get('CF-Connecting-IP')) return request.headers.get('CF-Connecting-IP') limiter = Limiter( @@ -91,6 +88,9 @@ mail = Mail(app) @app.before_request def before_request(): + print('first: ' + request.access_route[0]) + print('second: ' + request.remote_addr) + print('third: ' + request.headers.get('CF-Connecting-IP')) if request.method.lower() != "get" and app.config["READ_ONLY"]: return {"error":f"{app.config['SITE_NAME']} is currently in read-only mode."}, 500 From 99cb28918373becbeaa2744fa98fcf85b4b92139 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 21 Jan 2022 13:31:41 +0200 Subject: [PATCH 25/27] fsd --- files/__main__.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/files/__main__.py b/files/__main__.py index d3181ce9a..6aa20a8b4 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -65,7 +65,6 @@ r=redis.Redis(host=environ.get("REDIS_URL", "redis://localhost"), decode_respons def get_CF() -> str: with app.app_context(): - print('real: ' + request.headers.get('CF-Connecting-IP')) return request.headers.get('CF-Connecting-IP') limiter = Limiter( @@ -88,10 +87,6 @@ mail = Mail(app) @app.before_request def before_request(): - print('first: ' + request.access_route[0]) - print('second: ' + request.remote_addr) - print('third: ' + request.headers.get('CF-Connecting-IP')) - if request.method.lower() != "get" and app.config["READ_ONLY"]: return {"error":f"{app.config['SITE_NAME']} is currently in read-only mode."}, 500 From 18a9903086ad6200419932f286150626ad120175 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 21 Jan 2022 13:55:53 +0200 Subject: [PATCH 26/27] vxc --- files/__main__.py | 14 ++------------ files/classes/user.py | 2 +- files/helpers/const.py | 9 +-------- files/helpers/sanitize.py | 2 ++ files/routes/admin.py | 1 + files/routes/static.py | 5 +++++ 6 files changed, 12 insertions(+), 21 deletions(-) diff --git a/files/__main__.py b/files/__main__.py index 6aa20a8b4..28fcc52cb 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -6,18 +6,15 @@ from flask import * from flask_caching import Cache from flask_limiter import Limiter from flask_compress import Compress -from flask_limiter.util import get_remote_address from flask_mail import Mail from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker, scoped_session from sqlalchemy import * import gevent -from werkzeug.middleware.proxy_fix import ProxyFix import redis import time from sys import stdout import faulthandler -import atexit app = Flask(__name__, template_folder='templates') app.url_map.strict_slashes = False @@ -111,13 +108,6 @@ def after_request(response): response.headers.add("X-Frame-Options", "deny") return response -from files.routes import * +with open("marsey_count.json", 'r') as f: cache.set("marsey_count", loads(f.read())) -def close_running_threads(): - with open("marsey_count.json", 'r') as f: marsey_file = loads(f.read()) - print(marsey_count['marseylove']) - if marsey_file != marsey_count: - with open('marsey_count.json', 'w') as f: dump(marsey_count, f) - print("Marsey count saved!") - stdout.flush() -atexit.register(close_running_threads) +from files.routes import * \ No newline at end of file diff --git a/files/classes/user.py b/files/classes/user.py index eeba5aa7f..f7fd02ef6 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -315,7 +315,7 @@ class User(Base): return f"/@{self.username}" def __repr__(self): - return f"" + return f"" @property @lazy diff --git a/files/helpers/const.py b/files/helpers/const.py index 7af17ba08..fccfb47a6 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -796,11 +796,4 @@ NOTIFIED_USERS = { } num_banners = len(listdir('files/assets/images/Drama/banners')) + 1 -num_sidebar = len(listdir('files/assets/images/Drama/sidebar')) + 1 - - -with open("marsey_count.json", 'r') as f: marsey_count = loads(f.read()) -marsey_counted = [] -for k, val in marseys.items(): - marsey_counted.append((k, val, marsey_count[k])) -marsey_counted = sorted(marsey_counted, key=lambda x: x[2], reverse=True) \ No newline at end of file +num_sidebar = len(listdir('files/assets/images/Drama/sidebar')) + 1 \ No newline at end of file diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 228d49099..473368652 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -178,6 +178,7 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): sanitized = re.sub('\|\|(.*?)\|\|', r'\1', sanitized) if comment: + marsey_count = cache.get("marsey_count") marseys_used = set() for i in re.finditer("[^a]>\s*(:[!#]{0,2}\w+:\s*)+<\/", sanitized): @@ -259,6 +260,7 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): if comment: for emoji in marseys_used: if emoji in marsey_count: marsey_count[emoji] += 1 + cache.set("marsey_count", marsey_count) return sanitized diff --git a/files/routes/admin.py b/files/routes/admin.py index 55a48302a..34e142d94 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -1211,6 +1211,7 @@ def admin_distinguish_comment(c_id, v): @app.get("/admin/dump_cache") @admin_level_required(2) def admin_dump_cache(v): + with open('marsey_count.json', 'w') as f: dump(cache.get("marsey_count"), f) cache.clear() return {"message": "Internal cache cleared."} diff --git a/files/routes/static.py b/files/routes/static.py index 02ba09982..462ac9521 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -17,6 +17,11 @@ def privacy(v): @app.get("/marseys") @auth_required def emojis(v): + marsey_count = cache.get("marsey_count") + marsey_counted = [] + for k, val in marseys.items(): + marsey_counted.append((k, val, marsey_count[k])) + marsey_counted = sorted(marsey_counted, key=lambda x: x[2], reverse=True) return render_template("marseys.html", v=v, marseys=marsey_counted) @app.get("/terms") From 1692fd17b147dc8a0c9a3c4f85c10dbb0956b513 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 21 Jan 2022 13:58:00 +0200 Subject: [PATCH 27/27] fsd --- files/__main__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/files/__main__.py b/files/__main__.py index 28fcc52cb..e58ed4284 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -15,6 +15,7 @@ import redis import time from sys import stdout import faulthandler +from json import loads app = Flask(__name__, template_folder='templates') app.url_map.strict_slashes = False