Basic Email Protection

This commit is contained in:
BlenderDumbass 2024-11-25 23:53:31 +02:00
parent a4da8a4f52
commit 1a9d3d0b39

View file

@ -38,10 +38,11 @@ def headers(server, code):
server.end_headers()
def head(title="", description="", image="", config={}):
def head(title="", description="", image="", config={}, author=""):
if image.startswith("/"): image = config.get("url","")+image
favicon = config.get("favicon", "/icon/internet")
html = """
@ -65,6 +66,32 @@ def head(title="", description="", image="", config={}):
<meta property="og:description" content=\""""+Simplify(description, False)+"""">
<meta property="og:image" content=\""""+image+"""">
"""
# Author tags.
if author:
account = accounts().get(author, {})
name = account.get("title", account)
mastodon = account.get("mastodon", "")
try:
if "/" in mastodon:
mastodon = mastodon.replace("https://", "").replace("http://", "")
mastodon = mastodon.split("/")[1]+"@"+mastodon.split("/")[0]
except:
pass
if mastodon:
html = html + """
<meta name=article:author content=\""""+name+"""">
<meta name=fediverse:creator content=\""""+mastodon+"""">
"""
html = html + """
<!-- This meta tag is needed for pretty rendering on phones -->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
@ -406,7 +433,9 @@ def ArticlePage(server, url):
# Generating <head>
html = head(title = Articles.get(article, {}).get("title", article),
description = Articles.get(article, {}).get("description", ""),
config = config
image = Articles.get(article, {}).get("thumbnail", ""),
config = config,
author = Articles.get(article, {}).get("author")
)
@ -550,68 +579,71 @@ def AccountPage(server, account):
html = html + '</center>'
# Protecting emails and stuff from scrubbers
if len(str(server.cookie)) == 50:
# Website
website = Safe(Accounts.get(account, {}).get("website" , ""))
if website:
# Website
webtitle = website.replace("https://", "").replace("http://", "")
if not website.startswith("http"): website = "http://"+website
html = html + '<center>'
html = html + '<img style="vertical-align: middle" src="/icon/internet">'
html = html + '<a href="'+website+'"> '+webtitle+'</a>'
html = html + '</center>'
website = Safe(Accounts.get(account, {}).get("website" , ""))
if website:
# Email
email = Safe(Accounts.get(account, {}).get("email" , ""))
if email:
html = html + '<center>'
html = html + '<img style="vertical-align: middle" src="/icon/frase">'
html = html + '<a href="mailto:'+email+'"> '+email+'</a>'
html = html + '</center>'
# Mastodon
mastodon = Safe(Accounts.get(account, {}).get("mastodon" , ""))
if mastodon:
# It could be mastodon url and not handle.
try:
if "/" in mastodon:
mastodon = mastodon.replace("https://", "").replace("http://", "")
mastodon = mastodon.split("/")[1]+"@"+mastodon.split("/")[0]
mastolink = "https://"+mastodon[1:].split("@")[1]+"/@"+mastodon[1:].split("@")[0]
webtitle = website.replace("https://", "").replace("http://", "")
if not website.startswith("http"): website = "http://"+website
html = html + '<center>'
html = html + '<img style="vertical-align: middle" src="/icon/mastodon">'
html = html + '<a href="'+mastolink+'"> '+mastodon+'</a>'
html = html + '<img style="vertical-align: middle" src="/icon/internet">'
html = html + '<a href="'+website+'"> '+webtitle+'</a>'
html = html + '</center>'
except:
pass
# Matrix
# Email
matrix = Safe(Accounts.get(account, {}).get("matrix" , ""))
if matrix:
email = Safe(Accounts.get(account, {}).get("email" , ""))
if email:
# Matrix could be the matrix.to link
if "/" in matrix:
matrix = matrix[matrix.rfind("/")+1:]
matrixlink = "https://matrix.to/#/"+matrix
html = html + '<center>'
html = html + '<img style="vertical-align: middle" src="/icon/element">'
html = html + '<a href="'+matrixlink+'"> '+matrix+'</a>'
html = html + '</center>'
html = html + '<center>'
html = html + '<img style="vertical-align: middle" src="/icon/frase">'
html = html + '<a href="mailto:'+email+'"> '+email+'</a>'
html = html + '</center>'
if any((website, email, mastodon, matrix)):
html = html + '<br>'
# Mastodon
mastodon = Safe(Accounts.get(account, {}).get("mastodon" , ""))
if mastodon:
# It could be mastodon url and not handle.
try:
if "/" in mastodon:
mastodon = mastodon.replace("https://", "").replace("http://", "")
mastodon = mastodon.split("/")[1]+"@"+mastodon.split("/")[0]
mastolink = "https://"+mastodon[1:].split("@")[1]+"/@"+mastodon[1:].split("@")[0]
html = html + '<center>'
html = html + '<img style="vertical-align: middle" src="/icon/mastodon">'
html = html + '<a href="'+mastolink+'"> '+mastodon+'</a>'
html = html + '</center>'
except:
pass
# Matrix
matrix = Safe(Accounts.get(account, {}).get("matrix" , ""))
if matrix:
# Matrix could be the matrix.to link
if "/" in matrix:
matrix = matrix[matrix.rfind("/")+1:]
matrixlink = "https://matrix.to/#/"+matrix
html = html + '<center>'
html = html + '<img style="vertical-align: middle" src="/icon/element">'
html = html + '<a href="'+matrixlink+'"> '+matrix+'</a>'
html = html + '</center>'
if any((website, email, mastodon, matrix)):
html = html + '<br>'
html = html + '</div>'