From c6d9f236eb2ba9376826f9ed9ff2a45df93b7cac Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 21 Aug 2021 14:30:52 +0200 Subject: [PATCH 01/19] df --- files/routes/posts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/routes/posts.py b/files/routes/posts.py index ff8e173eb..8ec026c92 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -563,7 +563,7 @@ def submit_post(v): else: url = "" - if "i.imgur.com" in url: url = url.replace(".png", "_d.png").replace(".jpg", "_d.jpg").replace(".jpeg", "_d.jpeg") + "?maxwidth=8888" + if "i.imgur.com" in url: url = url.replace(".png", "_d.png").replace(".jpg", "_d.jpg").replace(".jpeg", "_d.jpeg") + "?maxwidth=9999" body = request.form.get("body", "") # check for duplicate From ebb34e29a355f11e38c9af3b587b9261adab7ce7 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 21 Aug 2021 14:30:54 +0200 Subject: [PATCH 02/19] df --- files/classes/submission.py | 2 +- files/helpers/sanitize.py | 135 +++++++++++++++------------------ files/templates/admins.html | 2 +- files/templates/settings2.html | 2 +- 4 files changed, 64 insertions(+), 77 deletions(-) diff --git a/files/classes/submission.py b/files/classes/submission.py index c31a521b8..21da28405 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -393,7 +393,7 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing): @property def is_image(self): - if self.url: return self.url.lower().endswith('.jpg') or self.url.lower().endswith('.png') or self.url.lower().endswith('.gif') or self.url.lower().endswith('.jpeg') or self.url.lower().endswith('?maxwidth=9999') or self.url.lower().endswith('?maxwidth=8888') + if self.url: return self.url.lower().endswith('.jpg') or self.url.lower().endswith('.png') or self.url.lower().endswith('.gif') or self.url.lower().endswith('.jpeg') or self.url.lower().endswith('?maxwidth=9999') else: return False @property diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 827d24fe5..746cc6df9 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -59,8 +59,7 @@ _allowed_styles =[ # filter to make all links show domain on hover - -def a_modify(attrs, new=False): +def a_modify(attrs): raw_url=attrs.get((None, "href"), None) if raw_url: @@ -85,16 +84,14 @@ def a_modify(attrs, new=False): return attrs +def sanitize(sanitized): + sanitized = sanitized.replace("\ufeff", "").replace("m.youtube.com", "youtube.com") + for i in re.finditer('https://i.imgur.com/(.*?)\.(jpg|png|jpeg|)', sanitized): + sanitized = sanitized.replace(i.group(1), i.group(1) + "_d." + i.group(2)) - -_clean_wo_links = bleach.Cleaner(tags=_allowed_tags, - attributes=_allowed_attributes, - protocols=_allowed_protocols, - ) - -_clean_w_links = bleach.Cleaner(tags=_allowed_tags, + sanitized = bleach.Cleaner(tags=_allowed_tags, attributes=_allowed_attributes, protocols=_allowed_protocols, styles=_allowed_styles, @@ -104,74 +101,64 @@ _clean_w_links = bleach.Cleaner(tags=_allowed_tags, callbacks=[a_modify] ) ] - ) + ).clean(sanitized) + + #soupify + soup = BeautifulSoup(sanitized, features="html.parser") + + #img elements - embed + for tag in soup.find_all("img"): + + url = tag.get("src", "") + if not url: continue + + if "profile-pic-20" not in tag.get("class", ""): + #print(tag.get('class')) + # set classes and wrap in link + + tag["rel"] = "nofollow" + tag["style"] = "max-height: 100px; max-width: 100%;" + tag["class"] = "in-comment-image rounded-sm my-2" + + link = soup.new_tag("a") + link["href"] = tag["src"] + link["rel"] = "nofollow noopener" + link["target"] = "_blank" + + link["onclick"] = f"expandDesktopImage('{tag['src']}');" + link["data-toggle"] = "modal" + link["data-target"] = "#expandImageModal" + + tag.wrap(link) + + #disguised link preventer + for tag in soup.find_all("a"): + + if re.match("https?://\S+", str(tag.string)): + try: + tag.string = tag["href"] + except: + tag.string = "" + + #clean up tags in code + for tag in soup.find_all("code"): + tag.contents=[x.string for x in tag.contents if x.string] + + #whatever else happens with images, there are only two sets of classes allowed + for tag in soup.find_all("img"): + if 'profile-pic-20' not in tag.attrs.get("class",""): + tag.attrs['class']="in-comment-image rounded-sm my-2" + + #table format + for tag in soup.find_all("table"): + tag.attrs['class']="table table-striped" + + for tag in soup.find_all("thead"): + tag.attrs['class']="bg-primary text-white" -def sanitize(text, linkgen=False): + sanitized = str(soup) - text = text.replace("\ufeff", "").replace("m.youtube.com", "youtube.com") - - if linkgen: - sanitized = _clean_w_links.clean(text) - - #soupify - soup = BeautifulSoup(sanitized, features="html.parser") - - #img elements - embed - for tag in soup.find_all("img"): - - url = tag.get("src", "") - if not url: continue - - if "profile-pic-20" not in tag.get("class", ""): - #print(tag.get('class')) - # set classes and wrap in link - - tag["rel"] = "nofollow" - tag["style"] = "max-height: 100px; max-width: 100%;" - tag["class"] = "in-comment-image rounded-sm my-2" - - link = soup.new_tag("a") - link["href"] = tag["src"] - link["rel"] = "nofollow noopener" - link["target"] = "_blank" - - link["onclick"] = f"expandDesktopImage('{tag['src']}');" - link["data-toggle"] = "modal" - link["data-target"] = "#expandImageModal" - - tag.wrap(link) - - #disguised link preventer - for tag in soup.find_all("a"): - - if re.match("https?://\S+", str(tag.string)): - try: - tag.string = tag["href"] - except: - tag.string = "" - - #clean up tags in code - for tag in soup.find_all("code"): - tag.contents=[x.string for x in tag.contents if x.string] - - #whatever else happens with images, there are only two sets of classes allowed - for tag in soup.find_all("img"): - if 'profile-pic-20' not in tag.attrs.get("class",""): - tag.attrs['class']="in-comment-image rounded-sm my-2" - - #table format - for tag in soup.find_all("table"): - tag.attrs['class']="table table-striped" - - for tag in soup.find_all("thead"): - tag.attrs['class']="bg-primary text-white" - - - sanitized = str(soup) - - else: - sanitized = _clean_wo_links.clean(text) start = '<s>' end = '</s>' diff --git a/files/templates/admins.html b/files/templates/admins.html index 4c1fd7d5d..280d7d5b4 100644 --- a/files/templates/admins.html +++ b/files/templates/admins.html @@ -4,7 +4,7 @@ {% block content %}

-
admins
+
Admins

 
diff --git a/files/templates/settings2.html b/files/templates/settings2.html
index 850fe2ca2..b2662ad13 100644
--- a/files/templates/settings2.html
+++ b/files/templates/settings2.html
@@ -98,7 +98,7 @@
 										Leaderboard
  • Unban user
  • {% else %}
  • Ban user
  • @@ -473,7 +473,7 @@ {% if v and (c.post and v.admin_level == 6) %} {% if c.author_id != v.id %} - {% if c.author.is_banned %} + {% if c.author.is_suspended %}
  • Unban user
  • {% else %}
  • Ban user
  • diff --git a/files/templates/submission.html b/files/templates/submission.html index 332c3b383..f36627b5c 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -159,7 +159,7 @@ {% endif %} {% if v and v.admin_level == 6 and v.id!=p.author_id %} - {% if p.author.is_banned %} + {% if p.author.is_suspended %} {% else %} @@ -194,7 +194,7 @@
    -
    +
    {% if p.thumb_url and not p.embed_url %} @@ -291,7 +291,7 @@
    - {% if v and v.id==p.author_id and not v.is_banned %} + {% if v and v.id==p.author_id and not v.is_suspended %} - {% if not v and not p.is_banned %} + {% if not v and not p.is_suspended %}
    diff --git a/files/templates/submission_banned.html b/files/templates/submission_banned.html index 572dc2a40..f7a27f368 100644 --- a/files/templates/submission_banned.html +++ b/files/templates/submission_banned.html @@ -11,7 +11,7 @@ {% block title %} {{p.realtitle(v)}} -{% if p.is_banned %} +{% if p.is_suspended %} {% else %} @@ -32,7 +32,7 @@ {% endif %} {% if v.admin_level >=1 and v.admin_level > p.author.admin_level %} -{% if p.is_banned %} +{% if p.is_suspended %}
    @@ -53,10 +53,10 @@
    -
    - +
    +
    {{p.realtitle(v)}}
    - +
    diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index 5a1613588..30ee1aa8e 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -20,7 +20,7 @@ {% endif %} -
    +
    @@ -33,7 +33,7 @@
    {% endif %} - {{score}} + {{score}} {% if voted==-1 %}
    @@ -43,7 +43,7 @@
    - {{score}} + {{score}}
    @@ -51,7 +51,7 @@
    - {{score}} + {{score}}
    @@ -201,7 +201,7 @@ {% endif %} {% if v.admin_level >=3 and v.id!=p.author_id %} - {% if p.author.is_banned %} + {% if p.author.is_suspended %}
  • Unban user
  • {% else %} @@ -248,7 +248,7 @@ {% endif %} - {{score}} + {{score}} {% if voted==-1 %} @@ -263,7 +263,7 @@ - {{score}} + {{score}} @@ -275,7 +275,7 @@ - {{score}} + {{score}} @@ -361,7 +361,7 @@ {% endif %} {% if v and v.admin_level == 6 and v.id!=p.author_id %} - {% if p.author.is_banned %} + {% if p.author.is_suspended %} {% else %} diff --git a/files/templates/userpage.html b/files/templates/userpage.html index 575b7cfdb..34cc56708 100644 --- a/files/templates/userpage.html +++ b/files/templates/userpage.html @@ -238,7 +238,7 @@
    
    -						{% if u.is_banned %}
    +						{% if u.is_suspended %}
     							
     								
     								
    @@ -457,7 +457,7 @@
    
    -						{% if u.is_banned %}
    +						{% if u.is_suspended %}
     							
     								
     								
    From 26f4024b83d4827edc49b5e7ccca2121413dda72 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 21 Aug 2021 19:56:19 +0200 Subject: [PATCH 17/19] dffd --- files/templates/userpage.html | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/files/templates/userpage.html b/files/templates/userpage.html index 34cc56708..de1149ad4 100644 --- a/files/templates/userpage.html +++ b/files/templates/userpage.html @@ -114,15 +114,13 @@ {% endif %} + {% if u.verified %} + + {% endif %} {% if u.admin_level > 1 or (u.admin_level == 1 and (not v or v.admin_level < 2)) %} - - {% if u.verified %}{% endif %} - {% elif u.admin_level == 1 %} - - {% endif %} {% if v and v.has_follower(u) %} Follows you @@ -357,15 +355,13 @@ {% endif %} + {% if u.verified %} + + {% endif %} {% if u.admin_level > 1 or (u.admin_level == 1 and (not v or v.admin_level < 2)) %} - - {% if u.verified %}{% endif %} - {% elif u.admin_level == 1 %} - - {% endif %} {% if v and v.has_follower(u) and not v.is_nofollow %} Follows you From 5d5df151c12950be11124b4912637d9f22eb22c4 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 21 Aug 2021 19:58:25 +0200 Subject: [PATCH 18/19] fdfd --- files/templates/userpage.html | 1 + 1 file changed, 1 insertion(+) diff --git a/files/templates/userpage.html b/files/templates/userpage.html index de1149ad4..2b9fb123b 100644 --- a/files/templates/userpage.html +++ b/files/templates/userpage.html @@ -115,6 +115,7 @@ {% endif %} {% if u.verified %} +   {% endif %} {% if u.admin_level > 1 or (u.admin_level == 1 and (not v or v.admin_level < 2)) %} From fc9fb22f784e70f17848ae65b1dd1a691e2fe00e Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 21 Aug 2021 20:00:19 +0200 Subject: [PATCH 19/19] dffd --- files/templates/userpage.html | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/files/templates/userpage.html b/files/templates/userpage.html index 2b9fb123b..a45891de5 100644 --- a/files/templates/userpage.html +++ b/files/templates/userpage.html @@ -114,14 +114,15 @@ {% 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)) %} + + {% elif u.admin_level == 1 %} + + {% endif %} {% if v and v.has_follower(u) %} Follows you @@ -356,13 +357,15 @@ {% 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)) %} + + {% elif u.admin_level == 1 %} + + {% endif %} {% if v and v.has_follower(u) and not v.is_nofollow %} Follows you