main
Bob Mottram 2020-12-16 11:04:46 +00:00
parent c2404d0943
commit 6ec956e312
6 changed files with 42 additions and 165 deletions

31
like.py
View File

@ -6,6 +6,7 @@ __maintainer__ = "Bob Mottram"
__email__ = "bob@freedombone.net" __email__ = "bob@freedombone.net"
__status__ = "Production" __status__ = "Production"
from utils import getFullDomain
from utils import removeIdEnding from utils import removeIdEnding
from utils import urlPermitted from utils import urlPermitted
from utils import getNicknameFromActor from utils import getNicknameFromActor
@ -66,11 +67,7 @@ def like(recentPostsCache: {},
if not urlPermitted(objectUrl, federationList): if not urlPermitted(objectUrl, federationList):
return None return None
fullDomain = domain fullDomain = getFullDomain(domain, port)
if port:
if port != 80 and port != 443:
if ':' not in domain:
fullDomain = domain + ':' + str(port)
newLikeJson = { newLikeJson = {
"@context": "https://www.w3.org/ns/activitystreams", "@context": "https://www.w3.org/ns/activitystreams",
@ -132,11 +129,7 @@ def likePost(recentPostsCache: {},
debug: bool, projectVersion: str) -> {}: debug: bool, projectVersion: str) -> {}:
"""Likes a given status post. This is only used by unit tests """Likes a given status post. This is only used by unit tests
""" """
likeDomain = likeDomain likeDomain = getFullDomain(likeDomain, likePort)
if likePort:
if likePort != 80 and likePort != 443:
if ':' not in likeDomain:
likeDomain = likeDomain + ':' + str(likePort)
actorLiked = httpPrefix + '://' + likeDomain + '/users/' + likeNickname actorLiked = httpPrefix + '://' + likeDomain + '/users/' + likeNickname
objectUrl = actorLiked + '/statuses/' + str(likeStatusNumber) objectUrl = actorLiked + '/statuses/' + str(likeStatusNumber)
@ -165,11 +158,7 @@ def undolike(recentPostsCache: {},
if not urlPermitted(objectUrl, federationList): if not urlPermitted(objectUrl, federationList):
return None return None
fullDomain = domain fullDomain = getFullDomain(domain, port)
if port:
if port != 80 and port != 443:
if ':' not in domain:
fullDomain = domain + ':' + str(port)
newUndoLikeJson = { newUndoLikeJson = {
"@context": "https://www.w3.org/ns/activitystreams", "@context": "https://www.w3.org/ns/activitystreams",
@ -234,11 +223,7 @@ def sendLikeViaServer(baseDir: str, session,
print('WARN: No session for sendLikeViaServer') print('WARN: No session for sendLikeViaServer')
return 6 return 6
fromDomainFull = fromDomain fromDomainFull = getFullDomain(fromDomain, fromPort)
if fromPort:
if fromPort != 80 and fromPort != 443:
if ':' not in fromDomain:
fromDomainFull = fromDomain + ':' + str(fromPort)
actor = httpPrefix + '://' + fromDomainFull + '/users/' + fromNickname actor = httpPrefix + '://' + fromDomainFull + '/users/' + fromNickname
@ -313,11 +298,7 @@ def sendUndoLikeViaServer(baseDir: str, session,
print('WARN: No session for sendUndoLikeViaServer') print('WARN: No session for sendUndoLikeViaServer')
return 6 return 6
fromDomainFull = fromDomain fromDomainFull = getFullDomain(fromDomain, fromPort)
if fromPort:
if fromPort != 80 and fromPort != 443:
if ':' not in fromDomain:
fromDomainFull = fromDomain + ':' + str(fromPort)
actor = httpPrefix + '://' + fromDomainFull + '/users/' + fromNickname actor = httpPrefix + '://' + fromDomainFull + '/users/' + fromNickname

View File

@ -13,6 +13,7 @@ import os
import datetime import datetime
from hashlib import sha1 from hashlib import sha1
from auth import createPassword from auth import createPassword
from utils import getFullDomain
from utils import getImageExtensions from utils import getImageExtensions
from utils import getVideoExtensions from utils import getVideoExtensions
from utils import getAudioExtensions from utils import getAudioExtensions
@ -163,10 +164,7 @@ def attachMedia(baseDir: str, httpPrefix: str, domain: str, port: int,
if mediaType == 'audio/mpeg': if mediaType == 'audio/mpeg':
fileExtension = 'mp3' fileExtension = 'mp3'
if port: domain = getFullDomain(domain, port)
if port != 80 and port != 443:
if ':' not in domain:
domain = domain + ':' + str(port)
mPath = getMediaPath() mPath = getMediaPath()
mediaPath = mPath + '/' + createPassword(32) + '.' + fileExtension mediaPath = mPath + '/' + createPassword(32) + '.' + fileExtension

View File

@ -26,6 +26,7 @@ from posts import archivePostsForPerson
from content import removeHtmlTag from content import removeHtmlTag
from content import dangerousMarkup from content import dangerousMarkup
from content import validHashTag from content import validHashTag
from utils import getFullDomain
from utils import loadJson from utils import loadJson
from utils import saveJson from utils import saveJson
from utils import getStatusNumber from utils import getStatusNumber
@ -245,10 +246,7 @@ def newswireHashtagProcessing(session, baseDir: str, postJsonObject: {},
with open(rulesFilename, "r") as f: with open(rulesFilename, "r") as f:
rules = f.readlines() rules = f.readlines()
domainFull = domain domainFull = getFullDomain(domain, port)
if port:
if port != 80 and port != 443:
domainFull = domain + ':' + str(port)
# get the full text content of the post # get the full text content of the post
content = '' content = ''
@ -584,10 +582,7 @@ def convertRSStoActivityPub(baseDir: str, httpPrefix: str,
blog['object']['content'] = rssDescription blog['object']['content'] = rssDescription
blog['object']['contentMap']['en'] = rssDescription blog['object']['contentMap']['en'] = rssDescription
domainFull = domain domainFull = getFullDomain(domain, port)
if port:
if port != 80 and port != 443:
domainFull = domain + ':' + str(port)
hashtags = item[6] hashtags = item[6]

View File

@ -14,6 +14,7 @@ from posts import outboxMessageCreateWrap
from posts import savePostToBox from posts import savePostToBox
from posts import sendToFollowersThread from posts import sendToFollowersThread
from posts import sendToNamedAddresses from posts import sendToNamedAddresses
from utils import getFullDomain
from utils import removeIdEnding from utils import removeIdEnding
from utils import getDomainFromActor from utils import getDomainFromActor
from blocking import isBlockedDomain from blocking import isBlockedDomain
@ -113,9 +114,7 @@ def postMessageToOutbox(messageJson: {}, postToNickname: str,
str(messageJson)) str(messageJson))
return False return False
testDomain, testPort = getDomainFromActor(messageJson['actor']) testDomain, testPort = getDomainFromActor(messageJson['actor'])
if testPort: testDomain = getFullDomain(testDomain, testPort)
if testPort != 80 and testPort != 443:
testDomain = testDomain + ':' + str(testPort)
if isBlockedDomain(baseDir, testDomain): if isBlockedDomain(baseDir, testDomain):
if debug: if debug:
print('DEBUG: domain is blocked: ' + messageJson['actor']) print('DEBUG: domain is blocked: ' + messageJson['actor'])

View File

@ -35,6 +35,7 @@ from auth import storeBasicCredentials
from auth import removePassword from auth import removePassword
from roles import setRole from roles import setRole
from media import removeMetaData from media import removeMetaData
from utils import getFullDomain
from utils import validNickname from utils import validNickname
from utils import loadJson from utils import loadJson
from utils import saveJson from utils import saveJson
@ -68,11 +69,7 @@ def setProfileImage(baseDir: str, httpPrefix: str, nickname: str, domain: str,
if ':' in domain: if ':' in domain:
domain = domain.split(':')[0] domain = domain.split(':')[0]
fullDomain = domain fullDomain = getFullDomain(domain, port)
if port:
if port != 80 and port != 443:
if ':' not in domain:
fullDomain = domain + ':' + str(port)
handle = nickname + '@' + domain handle = nickname + '@' + domain
personFilename = baseDir + '/accounts/' + handle + '.json' personFilename = baseDir + '/accounts/' + handle + '.json'
@ -213,10 +210,7 @@ def createPersonBase(baseDir: str, nickname: str, domain: str, port: int,
handle = nickname + '@' + domain handle = nickname + '@' + domain
originalDomain = domain originalDomain = domain
if port: domain = getFullDomain(domain, port)
if port != 80 and port != 443:
if ':' not in domain:
domain = domain + ':' + str(port)
personType = 'Person' personType = 'Person'
# Enable follower approval by default # Enable follower approval by default
@ -418,10 +412,7 @@ def savePersonQrcode(baseDir: str,
nickname + '@' + domain + '/qrcode.png' nickname + '@' + domain + '/qrcode.png'
if os.path.isfile(qrcodeFilename): if os.path.isfile(qrcodeFilename):
return return
handle = '@' + nickname + '@' + domain handle = getFullDomain('@' + nickname + '@' + domain, port)
if port:
if port != 80 and port != 443:
handle = handle + ':' + str(port)
url = pyqrcode.create(handle) url = pyqrcode.create(handle)
url.png(qrcodeFilename, scale) url.png(qrcodeFilename, scale)
@ -868,11 +859,7 @@ def canRemovePost(baseDir: str, nickname: str,
if '/statuses/' not in postId: if '/statuses/' not in postId:
return False return False
domainFull = domain domainFull = getFullDomain(domain, port)
if port:
if port != 80 and port != 443:
if ':' not in domain:
domainFull = domain + ':' + str(port)
# is the post by the admin? # is the post by the admin?
adminNickname = getConfigParam(baseDir, 'admin') adminNickname = getConfigParam(baseDir, 'admin')
@ -898,11 +885,7 @@ def removeTagsForNickname(baseDir: str, nickname: str,
""" """
if not os.path.isdir(baseDir + '/tags'): if not os.path.isdir(baseDir + '/tags'):
return return
domainFull = domain domainFull = getFullDomain(domain, port)
if port:
if port != 80 and port != 443:
if ':' not in domain:
domainFull = domain + ':' + str(port)
matchStr = domainFull + '/users/' + nickname + '/' matchStr = domainFull + '/users/' + nickname + '/'
directory = os.fsencode(baseDir + '/tags/') directory = os.fsencode(baseDir + '/tags/')
for f in os.scandir(directory): for f in os.scandir(directory):

125
posts.py
View File

@ -30,6 +30,7 @@ from session import postJsonString
from session import postImage from session import postImage
from webfinger import webfingerHandle from webfinger import webfingerHandle
from httpsig import createSignedHeader from httpsig import createSignedHeader
from utils import getFullDomain
from utils import getFollowersList from utils import getFollowersList
from utils import isEvil from utils import isEvil
from utils import removeIdEnding from utils import removeIdEnding
@ -740,10 +741,7 @@ def createPostBase(baseDir: str, nickname: str, domain: str, port: int,
tags = [] tags = []
hashtagsDict = {} hashtagsDict = {}
if port: domain = getFullDomain(domain, port)
if port != 80 and port != 443:
if ':' not in domain:
domain = domain + ':' + str(port)
# add tags # add tags
if nickname != 'news': if nickname != 'news':
@ -1070,10 +1068,7 @@ def outboxMessageCreateWrap(httpPrefix: str,
https://www.w3.org/TR/activitypub/#object-without-create https://www.w3.org/TR/activitypub/#object-without-create
""" """
if port: domain = getFullDomain(domain, port)
if port != 80 and port != 443:
if ':' not in domain:
domain = domain + ':' + str(port)
statusNumber, published = getStatusNumber() statusNumber, published = getStatusNumber()
if messageJson.get('published'): if messageJson.get('published'):
published = messageJson['published'] published = messageJson['published']
@ -1108,10 +1103,7 @@ def postIsAddressedToFollowers(baseDir: str,
postJsonObject: {}) -> bool: postJsonObject: {}) -> bool:
"""Returns true if the given post is addressed to followers of the nickname """Returns true if the given post is addressed to followers of the nickname
""" """
if port: domain = getFullDomain(domain, port)
if port != 80 and port != 443:
if ':' not in domain:
domain = domain + ':' + str(port)
if not postJsonObject.get('object'): if not postJsonObject.get('object'):
return False return False
@ -1174,11 +1166,7 @@ def createPublicPost(baseDir: str,
eventDate=None, eventTime=None, location=None) -> {}: eventDate=None, eventTime=None, location=None) -> {}:
"""Public post """Public post
""" """
domainFull = domain domainFull = getFullDomain(domain, port)
if port:
if port != 80 and port != 443:
if ':' not in domain:
domainFull = domain + ':' + str(port)
return createPostBase(baseDir, nickname, domain, port, return createPostBase(baseDir, nickname, domain, port,
'https://www.w3.org/ns/activitystreams#Public', 'https://www.w3.org/ns/activitystreams#Public',
httpPrefix + '://' + domainFull + '/users/' + httpPrefix + '://' + domainFull + '/users/' +
@ -1278,11 +1266,7 @@ def createQuestionPost(baseDir: str,
subject: str, durationDays: int) -> {}: subject: str, durationDays: int) -> {}:
"""Question post with multiple choice options """Question post with multiple choice options
""" """
domainFull = domain domainFull = getFullDomain(domain, port)
if port:
if port != 80 and port != 443:
if ':' not in domain:
domainFull = domain + ':' + str(port)
messageJson = \ messageJson = \
createPostBase(baseDir, nickname, domain, port, createPostBase(baseDir, nickname, domain, port,
'https://www.w3.org/ns/activitystreams#Public', 'https://www.w3.org/ns/activitystreams#Public',
@ -1328,11 +1312,7 @@ def createUnlistedPost(baseDir: str,
eventDate=None, eventTime=None, location=None) -> {}: eventDate=None, eventTime=None, location=None) -> {}:
"""Unlisted post. This has the #Public and followers links inverted. """Unlisted post. This has the #Public and followers links inverted.
""" """
domainFull = domain domainFull = getFullDomain(domain, port)
if port:
if port != 80 and port != 443:
if ':' not in domain:
domainFull = domain + ':' + str(port)
return createPostBase(baseDir, nickname, domain, port, return createPostBase(baseDir, nickname, domain, port,
httpPrefix + '://' + domainFull + '/users/' + httpPrefix + '://' + domainFull + '/users/' +
nickname + '/followers', nickname + '/followers',
@ -1361,11 +1341,7 @@ def createFollowersOnlyPost(baseDir: str,
location=None) -> {}: location=None) -> {}:
"""Followers only post """Followers only post
""" """
domainFull = domain domainFull = getFullDomain(domain, port)
if port:
if port != 80 and port != 443:
if ':' not in domain:
domainFull = domain + ':' + str(port)
return createPostBase(baseDir, nickname, domain, port, return createPostBase(baseDir, nickname, domain, port,
httpPrefix + '://' + domainFull + '/users/' + httpPrefix + '://' + domainFull + '/users/' +
nickname + '/followers', nickname + '/followers',
@ -1404,11 +1380,7 @@ def createEventPost(baseDir: str,
if not category: if not category:
print('Event has no category') print('Event has no category')
return None return None
domainFull = domain domainFull = getFullDomain(domain, port)
if port:
if port != 80 and port != 443:
if ':' not in domain:
domainFull = domain + ':' + str(port)
# create event uuid # create event uuid
eventUUID = str(uuid.uuid1()) eventUUID = str(uuid.uuid1())
@ -1524,11 +1496,7 @@ def createReportPost(baseDir: str,
debug: bool, subject=None) -> {}: debug: bool, subject=None) -> {}:
"""Send a report to moderators """Send a report to moderators
""" """
domainFull = domain domainFull = getFullDomain(domain, port)
if port:
if port != 80 and port != 443:
if ':' not in domain:
domainFull = domain + ':' + str(port)
# add a title to distinguish moderation reports from other posts # add a title to distinguish moderation reports from other posts
reportTitle = 'Moderation Report' reportTitle = 'Moderation Report'
@ -1698,10 +1666,7 @@ def sendPost(projectVersion: str,
# shared inbox actor on @domain@domain # shared inbox actor on @domain@domain
toNickname = toDomain toNickname = toDomain
if toPort: toDomain = getFullDomain(toDomain, toPort)
if toPort != 80 and toPort != 443:
if ':' not in toDomain:
toDomain = toDomain + ':' + str(toPort)
handle = httpPrefix + '://' + toDomain + '/@' + toNickname handle = httpPrefix + '://' + toDomain + '/@' + toNickname
@ -1863,11 +1828,7 @@ def sendPostViaServer(projectVersion: str,
clientToServer = True clientToServer = True
if toDomain.lower().endswith('public'): if toDomain.lower().endswith('public'):
toPersonId = 'https://www.w3.org/ns/activitystreams#Public' toPersonId = 'https://www.w3.org/ns/activitystreams#Public'
fromDomainFull = fromDomain fromDomainFull = getFullDomain(fromDomain, fromPort)
if fromPort:
if fromPort != 80 and fromPort != 443:
if ':' not in fromDomain:
fromDomainFull = fromDomain + ':' + str(fromPort)
cc = httpPrefix + '://' + fromDomainFull + '/users/' + \ cc = httpPrefix + '://' + fromDomainFull + '/users/' + \
fromNickname + '/followers' fromNickname + '/followers'
else: else:
@ -1877,11 +1838,7 @@ def sendPostViaServer(projectVersion: str,
httpPrefix + '://' + \ httpPrefix + '://' + \
fromDomainFull + '/users/' + fromNickname + '/followers' fromDomainFull + '/users/' + fromNickname + '/followers'
else: else:
toDomainFull = toDomain toDomainFull = getFullDomain(toDomain, toPort)
if toPort:
if toPort != 80 and toPort != 443:
if ':' not in toDomain:
toDomainFull = toDomain + ':' + str(toPort)
toPersonId = httpPrefix + '://' + toDomainFull + \ toPersonId = httpPrefix + '://' + toDomainFull + \
'/users/' + toNickname '/users/' + toNickname
@ -2010,10 +1967,7 @@ def sendSignedJson(postJsonObject: {}, session, baseDir: str,
toNickname = toDomain toNickname = toDomain
# sharedInbox = True # sharedInbox = True
if toPort: toDomain = getFullDomain(toDomain, toPort)
if toPort != 80 and toPort != 443:
if ':' not in toDomain:
toDomain = toDomain + ':' + str(toPort)
toDomainUrl = httpPrefix + '://' + toDomain toDomainUrl = httpPrefix + '://' + toDomain
if not siteIsActive(toDomainUrl): if not siteIsActive(toDomainUrl):
@ -2290,16 +2244,8 @@ def sendToNamedAddresses(session, baseDir: str,
if not toDomain: if not toDomain:
continue continue
if debug: if debug:
domainFull = domain domainFull = getFullDomain(domain, port)
if port: toDomainFull = getFullDomain(toDomain, toPort)
if port != 80 and port != 443:
if ':' not in domain:
domainFull = domain + ':' + str(port)
toDomainFull = toDomain
if toPort:
if toPort != 80 and toPort != 443:
if ':' not in toDomain:
toDomainFull = toDomain + ':' + str(toPort)
print('DEBUG: Post sending s2s: ' + nickname + '@' + domainFull + print('DEBUG: Post sending s2s: ' + nickname + '@' + domainFull +
' to ' + toNickname + '@' + toDomainFull) ' to ' + toNickname + '@' + toDomainFull)
@ -2618,10 +2564,7 @@ def createModeration(baseDir: str, nickname: str, domain: str, port: int,
boxDir = createPersonDir(nickname, domain, baseDir, 'inbox') boxDir = createPersonDir(nickname, domain, baseDir, 'inbox')
boxname = 'moderation' boxname = 'moderation'
if port: domain = getFullDomain(domain, port)
if port != 80 and port != 443:
if ':' not in domain:
domain = domain + ':' + str(port)
if not pageNumber: if not pageNumber:
pageNumber = 1 pageNumber = 1
@ -2939,10 +2882,7 @@ def createBoxIndexed(recentPostsCache: {},
indexBoxName = boxname indexBoxName = boxname
timelineNickname = 'news' timelineNickname = 'news'
if port: domain = getFullDomain(domain, port)
if port != 80 and port != 443:
if ':' not in domain:
domain = domain + ':' + str(port)
boxActor = httpPrefix + '://' + domain + '/users/' + nickname boxActor = httpPrefix + '://' + domain + '/users/' + nickname
@ -3332,11 +3272,7 @@ def getPublicPostsOfPerson(baseDir: str, nickname: str, domain: str,
cachedWebfingers = {} cachedWebfingers = {}
federationList = [] federationList = []
domainFull = domain domainFull = getFullDomain(domain, port)
if port:
if port != 80 and port != 443:
if ':' not in domain:
domainFull = domain + ':' + str(port)
handle = httpPrefix + "://" + domainFull + "/@" + nickname handle = httpPrefix + "://" + domainFull + "/@" + nickname
wfRequest = \ wfRequest = \
webfingerHandle(session, handle, httpPrefix, cachedWebfingers, webfingerHandle(session, handle, httpPrefix, cachedWebfingers,
@ -3377,11 +3313,7 @@ def getPublicPostDomains(session, baseDir: str, nickname: str, domain: str,
cachedWebfingers = {} cachedWebfingers = {}
federationList = [] federationList = []
domainFull = domain domainFull = getFullDomain(domain, port)
if port:
if port != 80 and port != 443:
if ':' not in domain:
domainFull = domain + ':' + str(port)
handle = httpPrefix + "://" + domainFull + "/@" + nickname handle = httpPrefix + "://" + domainFull + "/@" + nickname
wfRequest = \ wfRequest = \
webfingerHandle(session, handle, httpPrefix, cachedWebfingers, webfingerHandle(session, handle, httpPrefix, cachedWebfingers,
@ -3740,10 +3672,7 @@ def downloadAnnounce(session, baseDir: str, httpPrefix: str,
attributedDomain, attributedPort = \ attributedDomain, attributedPort = \
getDomainFromActor(announcedJson['object']['id']) getDomainFromActor(announcedJson['object']['id'])
if attributedNickname and attributedDomain: if attributedNickname and attributedDomain:
if attributedPort: attributedDomain = getFullDomain(attributedDomain, attributedPort)
if attributedPort != 80 and attributedPort != 443:
attributedDomain = \
attributedDomain + ':' + str(attributedPort)
if isBlocked(baseDir, nickname, domain, if isBlocked(baseDir, nickname, domain,
attributedNickname, attributedDomain): attributedNickname, attributedDomain):
rejectAnnounce(announceFilename) rejectAnnounce(announceFilename)
@ -3859,11 +3788,7 @@ def sendBlockViaServer(baseDir: str, session,
print('WARN: No session for sendBlockViaServer') print('WARN: No session for sendBlockViaServer')
return 6 return 6
fromDomainFull = fromDomain fromDomainFull = getFullDomain(fromDomain, fromPort)
if fromPort:
if fromPort != 80 and fromPort != 443:
if ':' not in fromDomain:
fromDomainFull = fromDomain + ':' + str(fromPort)
toUrl = 'https://www.w3.org/ns/activitystreams#Public' toUrl = 'https://www.w3.org/ns/activitystreams#Public'
ccUrl = httpPrefix + '://' + fromDomainFull + '/users/' + \ ccUrl = httpPrefix + '://' + fromDomainFull + '/users/' + \
@ -3942,11 +3867,7 @@ def sendUndoBlockViaServer(baseDir: str, session,
print('WARN: No session for sendBlockViaServer') print('WARN: No session for sendBlockViaServer')
return 6 return 6
fromDomainFull = fromDomain fromDomainFull = getFullDomain(fromDomain, fromPort)
if fromPort:
if fromPort != 80 and fromPort != 443:
if ':' not in fromDomain:
fromDomainFull = fromDomain + ':' + str(fromPort)
toUrl = 'https://www.w3.org/ns/activitystreams#Public' toUrl = 'https://www.w3.org/ns/activitystreams#Public'
ccUrl = httpPrefix + '://' + fromDomainFull + '/users/' + \ ccUrl = httpPrefix + '://' + fromDomainFull + '/users/' + \