remotes/1693045480750635534/spooky-22
Aevann1 2021-08-21 14:30:54 +02:00
parent c6d9f236eb
commit ebb34e29a3
4 changed files with 64 additions and 77 deletions

View File

@ -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

View File

@ -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>'

View File

@ -4,7 +4,7 @@
{% block content %}
<pre class="d-none d-md-inline-block"></pre>
<h5 style="font-weight:bold;">admins</h5>
<h5 style="font-weight:bold;">Admins</h5>
<pre></pre>
<table class="table table-striped mb-5">
<thead class="bg-primary text-white">

View File

@ -98,7 +98,7 @@
<a class="nav-link{% if request.path.endswith('/leaderboard') %} active{% endif %}" href="/leaderboard"><i class="fas fa-trophy"></i>Leaderboard</a>
</li>
<li class="nav-item">
<a class="nav-link{% if request.path.endswith('/admins') %} active{% endif %}" href="/admins"><i class="fas fa-crown"></i>admins</a>
<a class="nav-link{% if request.path.endswith('/admins') %} active{% endif %}" href="/admins"><i class="fas fa-crown"></i>Admins</a>
</li>
<li class="nav-item">
<a class="nav-link{% if request.path.endswith('/log') %} active{% endif %}" href="/log"><i class="fas fa-scroll-old"></i>Moderation Log</a>