mirror of https://gitlab.com/bashrc2/epicyon
Merge branch 'main' of ssh://code.freedombone.net:2222/bashrc/epicyon into main
commit
a5936185f5
20
content.py
20
content.py
|
|
@ -16,6 +16,8 @@ from utils import loadJson
|
||||||
from utils import fileLastModified
|
from utils import fileLastModified
|
||||||
from utils import getLinkPrefixes
|
from utils import getLinkPrefixes
|
||||||
from utils import dangerousMarkup
|
from utils import dangerousMarkup
|
||||||
|
from utils import isPGPEncrypted
|
||||||
|
from utils import containsPGPPublicKey
|
||||||
from petnames import getPetName
|
from petnames import getPetName
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -65,8 +67,7 @@ def _removeQuotesWithinQuotes(content: str) -> str:
|
||||||
def htmlReplaceEmailQuote(content: str) -> str:
|
def htmlReplaceEmailQuote(content: str) -> str:
|
||||||
"""Replaces an email style quote "> Some quote" with html blockquote
|
"""Replaces an email style quote "> Some quote" with html blockquote
|
||||||
"""
|
"""
|
||||||
if '--BEGIN PGP MESSAGE--' in content or \
|
if isPGPEncrypted(content) or containsPGPPublicKey(content):
|
||||||
'--BEGIN PGP PUBLIC KEY BLOCK--' in content:
|
|
||||||
return content
|
return content
|
||||||
# replace quote paragraph
|
# replace quote paragraph
|
||||||
if '<p>"' in content:
|
if '<p>"' in content:
|
||||||
|
|
@ -109,8 +110,7 @@ def htmlReplaceQuoteMarks(content: str) -> str:
|
||||||
"""Replaces quotes with html formatting
|
"""Replaces quotes with html formatting
|
||||||
"hello" becomes <q>hello</q>
|
"hello" becomes <q>hello</q>
|
||||||
"""
|
"""
|
||||||
if '--BEGIN PGP MESSAGE--' in content or \
|
if isPGPEncrypted(content) or containsPGPPublicKey(content):
|
||||||
'--BEGIN PGP PUBLIC KEY BLOCK--' in content:
|
|
||||||
return content
|
return content
|
||||||
if '"' not in content:
|
if '"' not in content:
|
||||||
if '"' not in content:
|
if '"' not in content:
|
||||||
|
|
@ -203,8 +203,7 @@ def dangerousCSS(filename: str, allowLocalNetworkAccess: bool) -> bool:
|
||||||
def switchWords(baseDir: str, nickname: str, domain: str, content: str) -> str:
|
def switchWords(baseDir: str, nickname: str, domain: str, content: str) -> str:
|
||||||
"""Performs word replacements. eg. Trump -> The Orange Menace
|
"""Performs word replacements. eg. Trump -> The Orange Menace
|
||||||
"""
|
"""
|
||||||
if '--BEGIN PGP MESSAGE--' in content or \
|
if isPGPEncrypted(content) or containsPGPPublicKey(content):
|
||||||
'--BEGIN PGP PUBLIC KEY BLOCK--' in content:
|
|
||||||
return content
|
return content
|
||||||
switchWordsFilename = baseDir + '/accounts/' + \
|
switchWordsFilename = baseDir + '/accounts/' + \
|
||||||
nickname + '@' + domain + '/replacewords.txt'
|
nickname + '@' + domain + '/replacewords.txt'
|
||||||
|
|
@ -591,8 +590,7 @@ def _addMention(wordStr: str, httpPrefix: str, following: str, petnames: str,
|
||||||
def replaceContentDuplicates(content: str) -> str:
|
def replaceContentDuplicates(content: str) -> str:
|
||||||
"""Replaces invalid duplicates within content
|
"""Replaces invalid duplicates within content
|
||||||
"""
|
"""
|
||||||
if '--BEGIN PGP MESSAGE--' in content or \
|
if isPGPEncrypted(content) or containsPGPPublicKey(content):
|
||||||
'--BEGIN PGP PUBLIC KEY BLOCK--' in content:
|
|
||||||
return content
|
return content
|
||||||
while '<<' in content:
|
while '<<' in content:
|
||||||
content = content.replace('<<', '<')
|
content = content.replace('<<', '<')
|
||||||
|
|
@ -605,8 +603,7 @@ def replaceContentDuplicates(content: str) -> str:
|
||||||
def removeTextFormatting(content: str) -> str:
|
def removeTextFormatting(content: str) -> str:
|
||||||
"""Removes markup for bold, italics, etc
|
"""Removes markup for bold, italics, etc
|
||||||
"""
|
"""
|
||||||
if '--BEGIN PGP MESSAGE--' in content or \
|
if isPGPEncrypted(content) or containsPGPPublicKey(content):
|
||||||
'--BEGIN PGP PUBLIC KEY BLOCK--' in content:
|
|
||||||
return content
|
return content
|
||||||
if '<' not in content:
|
if '<' not in content:
|
||||||
return content
|
return content
|
||||||
|
|
@ -625,8 +622,7 @@ def removeLongWords(content: str, maxWordLength: int,
|
||||||
"""Breaks up long words so that on mobile screens this doesn't
|
"""Breaks up long words so that on mobile screens this doesn't
|
||||||
disrupt the layout
|
disrupt the layout
|
||||||
"""
|
"""
|
||||||
if '--BEGIN PGP MESSAGE--' in content or \
|
if isPGPEncrypted(content) or containsPGPPublicKey(content):
|
||||||
'--BEGIN PGP PUBLIC KEY BLOCK--' in content:
|
|
||||||
return content
|
return content
|
||||||
content = replaceContentDuplicates(content)
|
content = replaceContentDuplicates(content)
|
||||||
if ' ' not in content:
|
if ' ' not in content:
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ from utils import saveJson
|
||||||
from utils import getNicknameFromActor
|
from utils import getNicknameFromActor
|
||||||
from utils import getDomainFromActor
|
from utils import getDomainFromActor
|
||||||
from utils import getFullDomain
|
from utils import getFullDomain
|
||||||
|
from utils import isPGPEncrypted
|
||||||
from session import createSession
|
from session import createSession
|
||||||
from speaker import getSpeakerFromServer
|
from speaker import getSpeakerFromServer
|
||||||
from speaker import getSpeakerPitch
|
from speaker import getSpeakerPitch
|
||||||
|
|
@ -31,7 +32,6 @@ from announce import sendAnnounceViaServer
|
||||||
from pgp import pgpDecrypt
|
from pgp import pgpDecrypt
|
||||||
from pgp import hasLocalPGPkey
|
from pgp import hasLocalPGPkey
|
||||||
from pgp import pgpEncryptToActor
|
from pgp import pgpEncryptToActor
|
||||||
from pgp import isPGPEncrypted
|
|
||||||
|
|
||||||
|
|
||||||
def _waitForKeypress(timeout: int, debug: bool) -> str:
|
def _waitForKeypress(timeout: int, debug: bool) -> str:
|
||||||
|
|
@ -373,7 +373,7 @@ def _notificationNewDM(session, toHandle: str,
|
||||||
|
|
||||||
|
|
||||||
def _storeMessage(speakerJson: {}) -> None:
|
def _storeMessage(speakerJson: {}) -> None:
|
||||||
"""Stores a message for later reading
|
"""Stores a message in your home directory for later reading
|
||||||
"""
|
"""
|
||||||
if not speakerJson.get('published'):
|
if not speakerJson.get('published'):
|
||||||
return
|
return
|
||||||
|
|
@ -549,6 +549,8 @@ def runNotificationsClient(baseDir: str, proxyType: str, httpPrefix: str,
|
||||||
if speakerJson.get('content'):
|
if speakerJson.get('content'):
|
||||||
if not encryptedMessage:
|
if not encryptedMessage:
|
||||||
content = speakerJson['content']
|
content = speakerJson['content']
|
||||||
|
else:
|
||||||
|
content = '🔓 ' + messageStr
|
||||||
|
|
||||||
# say the speaker's name
|
# say the speaker's name
|
||||||
_sayCommand(nameStr, nameStr, screenreader,
|
_sayCommand(nameStr, nameStr, screenreader,
|
||||||
|
|
|
||||||
20
pgp.py
20
pgp.py
|
|
@ -10,6 +10,8 @@ import os
|
||||||
import subprocess
|
import subprocess
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from person import getActorJson
|
from person import getActorJson
|
||||||
|
from utils import containsPGPPublicKey
|
||||||
|
from utils import isPGPEncrypted
|
||||||
|
|
||||||
|
|
||||||
def getEmailAddress(actorJson: {}) -> str:
|
def getEmailAddress(actorJson: {}) -> str:
|
||||||
|
|
@ -369,24 +371,6 @@ def pgpEncryptToActor(content: str, toHandle: str) -> str:
|
||||||
return _pgpEncrypt(content, recipientPubKey)
|
return _pgpEncrypt(content, recipientPubKey)
|
||||||
|
|
||||||
|
|
||||||
def isPGPEncrypted(content: str) -> bool:
|
|
||||||
"""Returns true if the given content is PGP encrypted
|
|
||||||
"""
|
|
||||||
if '--BEGIN PGP MESSAGE--' in content:
|
|
||||||
if '--END PGP MESSAGE--' in content:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def containsPGPPublicKey(content: str) -> bool:
|
|
||||||
"""Returns true if the given content contains a PGP public key
|
|
||||||
"""
|
|
||||||
if '--BEGIN PGP PUBLIC KEY BLOCK--' in content:
|
|
||||||
if '--END PGP PUBLIC KEY BLOCK--' in content:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def pgpDecrypt(content: str, fromHandle: str) -> str:
|
def pgpDecrypt(content: str, fromHandle: str) -> str:
|
||||||
""" Encrypt using your default pgp key to the given recipient
|
""" Encrypt using your default pgp key to the given recipient
|
||||||
fromHandle can be a handle or actor url
|
fromHandle can be a handle or actor url
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ from utils import removeHtml
|
||||||
from utils import loadJson
|
from utils import loadJson
|
||||||
from utils import saveJson
|
from utils import saveJson
|
||||||
from utils import getFullDomain
|
from utils import getFullDomain
|
||||||
|
from utils import isPGPEncrypted
|
||||||
from content import htmlReplaceQuoteMarks
|
from content import htmlReplaceQuoteMarks
|
||||||
|
|
||||||
speakerRemoveChars = ('.\n', '. ', ',', ';', '?', '!')
|
speakerRemoveChars = ('.\n', '. ', ',', ';', '?', '!')
|
||||||
|
|
@ -413,7 +414,7 @@ def _postToSpeakerJson(baseDir: str, httpPrefix: str,
|
||||||
content = urllib.parse.unquote_plus(postJsonObject['object']['content'])
|
content = urllib.parse.unquote_plus(postJsonObject['object']['content'])
|
||||||
content = html.unescape(content)
|
content = html.unescape(content)
|
||||||
content = content.replace('<p>', '').replace('</p>', ' ')
|
content = content.replace('<p>', '').replace('</p>', ' ')
|
||||||
if '--BEGIN PGP MESSAGE--' not in content:
|
if not isPGPEncrypted(content):
|
||||||
# replace some emoji before removing html
|
# replace some emoji before removing html
|
||||||
if ' <3' in content:
|
if ' <3' in content:
|
||||||
content = content.replace(' <3', ' ' + translate['heart'])
|
content = content.replace(' <3', ' ' + translate['heart'])
|
||||||
|
|
|
||||||
4
tests.py
4
tests.py
|
|
@ -52,6 +52,8 @@ from utils import getStatusNumber
|
||||||
from utils import getFollowersOfPerson
|
from utils import getFollowersOfPerson
|
||||||
from utils import removeHtml
|
from utils import removeHtml
|
||||||
from utils import dangerousMarkup
|
from utils import dangerousMarkup
|
||||||
|
from pgp import extractPGPPublicKey
|
||||||
|
from utils import containsPGPPublicKey
|
||||||
from follow import followerOfPerson
|
from follow import followerOfPerson
|
||||||
from follow import unfollowAccount
|
from follow import unfollowAccount
|
||||||
from follow import unfollowerOfAccount
|
from follow import unfollowerOfAccount
|
||||||
|
|
@ -102,8 +104,6 @@ from mastoapiv1 import getNicknameFromMastoApiV1Id
|
||||||
from webapp_post import prepareHtmlPostNickname
|
from webapp_post import prepareHtmlPostNickname
|
||||||
from webapp_utils import markdownToHtml
|
from webapp_utils import markdownToHtml
|
||||||
from speaker import speakerReplaceLinks
|
from speaker import speakerReplaceLinks
|
||||||
from pgp import extractPGPPublicKey
|
|
||||||
from pgp import containsPGPPublicKey
|
|
||||||
|
|
||||||
testServerAliceRunning = False
|
testServerAliceRunning = False
|
||||||
testServerBobRunning = False
|
testServerBobRunning = False
|
||||||
|
|
|
||||||
|
|
@ -400,5 +400,6 @@
|
||||||
"heart": "قلب",
|
"heart": "قلب",
|
||||||
"counselor": "مستشار",
|
"counselor": "مستشار",
|
||||||
"Counselors": "المستشارين",
|
"Counselors": "المستشارين",
|
||||||
"shocked": "صدمت"
|
"shocked": "صدمت",
|
||||||
|
"Encrypted": "مشفر"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -400,5 +400,6 @@
|
||||||
"heart": "cor",
|
"heart": "cor",
|
||||||
"counselor": "conseller",
|
"counselor": "conseller",
|
||||||
"Counselors": "Consellers",
|
"Counselors": "Consellers",
|
||||||
"shocked": "sorprès"
|
"shocked": "sorprès",
|
||||||
|
"Encrypted": "Xifrat"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -400,5 +400,6 @@
|
||||||
"heart": "galon",
|
"heart": "galon",
|
||||||
"counselor": "cynghorydd",
|
"counselor": "cynghorydd",
|
||||||
"Counselors": "Cynghorwyr",
|
"Counselors": "Cynghorwyr",
|
||||||
"shocked": "sioc"
|
"shocked": "sioc",
|
||||||
|
"Encrypted": "Amgryptio"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -400,5 +400,6 @@
|
||||||
"heart": "herz",
|
"heart": "herz",
|
||||||
"counselor": "Beraterin",
|
"counselor": "Beraterin",
|
||||||
"Counselors": "Berater",
|
"Counselors": "Berater",
|
||||||
"shocked": "schockiert"
|
"shocked": "schockiert",
|
||||||
|
"Encrypted": "Verschlüsselt"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -400,5 +400,6 @@
|
||||||
"heart": "heart",
|
"heart": "heart",
|
||||||
"counselor": "counselor",
|
"counselor": "counselor",
|
||||||
"Counselors": "Counselors",
|
"Counselors": "Counselors",
|
||||||
"shocked": "shocked"
|
"shocked": "shocked",
|
||||||
|
"Encrypted": "Encrypted"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -400,5 +400,6 @@
|
||||||
"heart": "corazón",
|
"heart": "corazón",
|
||||||
"counselor": "Consejera",
|
"counselor": "Consejera",
|
||||||
"Counselors": "Consejeras",
|
"Counselors": "Consejeras",
|
||||||
"shocked": "conmocionada"
|
"shocked": "conmocionada",
|
||||||
|
"Encrypted": "Cifrada"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -400,5 +400,6 @@
|
||||||
"heart": "cœur",
|
"heart": "cœur",
|
||||||
"counselor": "Conseillère",
|
"counselor": "Conseillère",
|
||||||
"Counselors": "Conseillères",
|
"Counselors": "Conseillères",
|
||||||
"shocked": "sous le choc"
|
"shocked": "sous le choc",
|
||||||
|
"Encrypted": "Crypté"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -400,5 +400,6 @@
|
||||||
"heart": "chroí",
|
"heart": "chroí",
|
||||||
"counselor": "Comhairleoir",
|
"counselor": "Comhairleoir",
|
||||||
"Counselors": "Comhairleoirí",
|
"Counselors": "Comhairleoirí",
|
||||||
"shocked": "ionadh"
|
"shocked": "ionadh",
|
||||||
|
"Encrypted": "Criptithe"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -400,5 +400,6 @@
|
||||||
"heart": "दिल",
|
"heart": "दिल",
|
||||||
"counselor": "काउंसलर",
|
"counselor": "काउंसलर",
|
||||||
"Counselors": "सलाहकार",
|
"Counselors": "सलाहकार",
|
||||||
"shocked": "हैरान"
|
"shocked": "हैरान",
|
||||||
|
"Encrypted": "को गोपित"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -400,5 +400,6 @@
|
||||||
"heart": "cuore",
|
"heart": "cuore",
|
||||||
"counselor": "Consulente",
|
"counselor": "Consulente",
|
||||||
"Counselors": "Consiglieri",
|
"Counselors": "Consiglieri",
|
||||||
"shocked": "scioccata"
|
"shocked": "scioccata",
|
||||||
|
"Encrypted": "Crittografato"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -400,5 +400,6 @@
|
||||||
"heart": "ハート",
|
"heart": "ハート",
|
||||||
"counselor": "カウンセラー",
|
"counselor": "カウンセラー",
|
||||||
"Counselors": "カウンセラー",
|
"Counselors": "カウンセラー",
|
||||||
"shocked": "ショックを受けた"
|
"shocked": "ショックを受けた",
|
||||||
|
"Encrypted": "暗号化"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -400,5 +400,6 @@
|
||||||
"heart": "dil",
|
"heart": "dil",
|
||||||
"counselor": "Pêşnîyarvan",
|
"counselor": "Pêşnîyarvan",
|
||||||
"Counselors": "Selêwirmendan",
|
"Counselors": "Selêwirmendan",
|
||||||
"shocked": "şok kirin"
|
"shocked": "şok kirin",
|
||||||
|
"Encrypted": "Encîfre kirin"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -396,5 +396,6 @@
|
||||||
"heart": "heart",
|
"heart": "heart",
|
||||||
"counselor": "Counselors",
|
"counselor": "Counselors",
|
||||||
"Counselors": "Counselors",
|
"Counselors": "Counselors",
|
||||||
"shocked": "shocked"
|
"shocked": "shocked",
|
||||||
|
"Encrypted": "Encrypted"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -400,5 +400,6 @@
|
||||||
"heart": "coração",
|
"heart": "coração",
|
||||||
"counselor": "Conselheira",
|
"counselor": "Conselheira",
|
||||||
"Counselors": "Conselheiras",
|
"Counselors": "Conselheiras",
|
||||||
"shocked": "chocada"
|
"shocked": "chocada",
|
||||||
|
"Encrypted": "Criptografada"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -400,5 +400,6 @@
|
||||||
"heart": "сердце",
|
"heart": "сердце",
|
||||||
"counselor": "Советник",
|
"counselor": "Советник",
|
||||||
"Counselors": "Советники",
|
"Counselors": "Советники",
|
||||||
"shocked": "потрясенный"
|
"shocked": "потрясенный",
|
||||||
|
"Encrypted": "Зашифрованный"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -400,5 +400,6 @@
|
||||||
"heart": "心",
|
"heart": "心",
|
||||||
"counselor": "顾问",
|
"counselor": "顾问",
|
||||||
"Counselors": "辅导员",
|
"Counselors": "辅导员",
|
||||||
"shocked": "震惊的"
|
"shocked": "震惊的",
|
||||||
|
"Encrypted": "加密的"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
18
utils.py
18
utils.py
|
|
@ -2130,3 +2130,21 @@ def isReply(postJsonObject: {}, actor: str) -> bool:
|
||||||
if actor in tag['href']:
|
if actor in tag['href']:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def containsPGPPublicKey(content: str) -> bool:
|
||||||
|
"""Returns true if the given content contains a PGP public key
|
||||||
|
"""
|
||||||
|
if '--BEGIN PGP PUBLIC KEY BLOCK--' in content:
|
||||||
|
if '--END PGP PUBLIC KEY BLOCK--' in content:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def isPGPEncrypted(content: str) -> bool:
|
||||||
|
"""Returns true if the given content is PGP encrypted
|
||||||
|
"""
|
||||||
|
if '--BEGIN PGP MESSAGE--' in content:
|
||||||
|
if '--END PGP MESSAGE--' in content:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ from posts import postIsMuted
|
||||||
from posts import getPersonBox
|
from posts import getPersonBox
|
||||||
from posts import downloadAnnounce
|
from posts import downloadAnnounce
|
||||||
from posts import populateRepliesJson
|
from posts import populateRepliesJson
|
||||||
|
from utils import isPGPEncrypted
|
||||||
from utils import isDM
|
from utils import isDM
|
||||||
from utils import rejectPostId
|
from utils import rejectPostId
|
||||||
from utils import isRecentPost
|
from utils import isRecentPost
|
||||||
|
|
@ -1570,17 +1571,20 @@ def individualPostAsHtml(allowDownloads: bool,
|
||||||
|
|
||||||
_logPostTiming(enableTimingLog, postStartTime, '16')
|
_logPostTiming(enableTimingLog, postStartTime, '16')
|
||||||
|
|
||||||
if not isPatch:
|
if not isPGPEncrypted(postJsonObject['object']['content']):
|
||||||
objectContent = \
|
if not isPatch:
|
||||||
removeLongWords(postJsonObject['object']['content'], 40, [])
|
objectContent = \
|
||||||
objectContent = removeTextFormatting(objectContent)
|
removeLongWords(postJsonObject['object']['content'], 40, [])
|
||||||
objectContent = \
|
objectContent = removeTextFormatting(objectContent)
|
||||||
switchWords(baseDir, nickname, domain, objectContent)
|
objectContent = \
|
||||||
objectContent = htmlReplaceEmailQuote(objectContent)
|
switchWords(baseDir, nickname, domain, objectContent)
|
||||||
objectContent = htmlReplaceQuoteMarks(objectContent)
|
objectContent = htmlReplaceEmailQuote(objectContent)
|
||||||
|
objectContent = htmlReplaceQuoteMarks(objectContent)
|
||||||
|
else:
|
||||||
|
objectContent = \
|
||||||
|
postJsonObject['object']['content']
|
||||||
else:
|
else:
|
||||||
objectContent = \
|
objectContent = '🔒 ' + translate['Encrypted']
|
||||||
postJsonObject['object']['content']
|
|
||||||
|
|
||||||
objectContent = '<article>' + objectContent + '</article>'
|
objectContent = '<article>' + objectContent + '</article>'
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue