merge-requests/30/head
Bob Mottram 2020-12-16 10:48:40 +00:00
parent c8e9804b4a
commit c2404d0943
1 changed files with 16 additions and 63 deletions

View File

@ -10,6 +10,7 @@ import json
import os import os
import datetime import datetime
import time import time
from utils import getFullDomain
from utils import isEventPost from utils import isEventPost
from utils import removeIdEnding from utils import removeIdEnding
from utils import getProtocolPrefixes from utils import getProtocolPrefixes
@ -371,10 +372,7 @@ def savePostToInboxQueue(baseDir: str, httpPrefix: str,
if debug: if debug:
print('DEBUG: post from ' + postNickname + ' blocked') print('DEBUG: post from ' + postNickname + ' blocked')
return None return None
if postPort: postDomain = getFullDomain(postDomain, postPort)
if postPort != 80 and postPort != 443:
if ':' not in postDomain:
postDomain = postDomain + ':' + str(postPort)
if postJsonObject.get('object'): if postJsonObject.get('object'):
if isinstance(postJsonObject['object'], dict): if isinstance(postJsonObject['object'], dict):
@ -524,10 +522,7 @@ def inboxPostRecipients(baseDir: str, postJsonObject: {},
if ':' in domain: if ':' in domain:
domain = domain.split(':')[0] domain = domain.split(':')[0]
domainBase = domain domainBase = domain
if port: domain = getFullDomain(domain, port)
if port != 80 and port != 443:
if ':' not in domain:
domain = domain + ':' + str(port)
domainMatch = '/' + domain + '/users/' domainMatch = '/' + domain + '/users/'
actor = postJsonObject['actor'] actor = postJsonObject['actor']
@ -649,11 +644,7 @@ def receiveUndoFollow(session, baseDir: str, httpPrefix: str,
return False return False
domainFollower, portFollower = \ domainFollower, portFollower = \
getDomainFromActor(messageJson['object']['actor']) getDomainFromActor(messageJson['object']['actor'])
domainFollowerFull = domainFollower domainFollowerFull = getFullDomain(domainFollower, portFollower)
if portFollower:
if portFollower != 80 and portFollower != 443:
if ':' not in domainFollower:
domainFollowerFull = domainFollower + ':' + str(portFollower)
nicknameFollowing = \ nicknameFollowing = \
getNicknameFromActor(messageJson['object']['object']) getNicknameFromActor(messageJson['object']['object'])
@ -663,12 +654,7 @@ def receiveUndoFollow(session, baseDir: str, httpPrefix: str,
return False return False
domainFollowing, portFollowing = \ domainFollowing, portFollowing = \
getDomainFromActor(messageJson['object']['object']) getDomainFromActor(messageJson['object']['object'])
domainFollowingFull = domainFollowing domainFollowingFull = getFullDomain(domainFollowing, portFollowing)
if portFollowing:
if portFollowing != 80 and portFollowing != 443:
if ':' not in domainFollowing:
domainFollowingFull = \
domainFollowing + ':' + str(portFollowing)
if unfollowerOfPerson(baseDir, if unfollowerOfPerson(baseDir,
nicknameFollowing, domainFollowingFull, nicknameFollowing, domainFollowingFull,
@ -749,10 +735,7 @@ def receiveEventPost(recentPostsCache: {}, session, baseDir: str,
if not isEventPost(messageJson): if not isEventPost(messageJson):
return return
print('Receiving event: ' + str(messageJson['object'])) print('Receiving event: ' + str(messageJson['object']))
handle = nickname + '@' + domain handle = getFullDomain(nickname + '@' + domain, port)
if port:
if port != 80 and port != 443:
handle += ':' + str(port)
postId = removeIdEnding(messageJson['id']).replace('/', '#') postId = removeIdEnding(messageJson['id']).replace('/', '#')
@ -768,14 +751,8 @@ def personReceiveUpdate(baseDir: str,
""" """
if debug: if debug:
print('DEBUG: receiving actor update for ' + personJson['url']) print('DEBUG: receiving actor update for ' + personJson['url'])
domainFull = domain domainFull = getFullDomain(domain, port)
if port: updateDomainFull = getFullDomain(updateDomain, updatePort)
if port != 80 and port != 443:
domainFull = domain + ':' + str(port)
updateDomainFull = updateDomain
if updatePort:
if updatePort != 80 and updatePort != 443:
updateDomainFull = updateDomain + ':' + str(updatePort)
actor = updateDomainFull + '/users/' + updateNickname actor = updateDomainFull + '/users/' + updateNickname
if actor not in personJson['id']: if actor not in personJson['id']:
actor = updateDomainFull + '/profile/' + updateNickname actor = updateDomainFull + '/profile/' + updateNickname
@ -1124,10 +1101,7 @@ def receiveBookmark(recentPostsCache: {},
if debug: if debug:
print('DEBUG: unrecognized domain ' + handle) print('DEBUG: unrecognized domain ' + handle)
return False return False
domainFull = domain domainFull = getFullDomain(domain, port)
if port:
if port != 80 and port != 443:
domainFull = domain + ':' + str(port)
nickname = handle.split('@')[0] nickname = handle.split('@')[0]
if not messageJson['actor'].endswith(domainFull + '/users/' + nickname): if not messageJson['actor'].endswith(domainFull + '/users/' + nickname):
if debug: if debug:
@ -1192,10 +1166,7 @@ def receiveUndoBookmark(recentPostsCache: {},
print('DEBUG: "statuses" missing from like object in ' + print('DEBUG: "statuses" missing from like object in ' +
messageJson['type']) messageJson['type'])
return False return False
domainFull = domain domainFull = getFullDomain(domain, port)
if port:
if port != 80 and port != 443:
domainFull = domain + ':' + str(port)
nickname = handle.split('@')[0] nickname = handle.split('@')[0]
if domain not in handle.split('@')[1]: if domain not in handle.split('@')[1]:
if debug: if debug:
@ -1249,11 +1220,7 @@ def receiveDelete(session, handle: str, isGroup: bool, baseDir: str,
if debug: if debug:
print('DEBUG: ' + messageJson['type'] + ' object is not a string') print('DEBUG: ' + messageJson['type'] + ' object is not a string')
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)
deletePrefix = httpPrefix + '://' + domainFull + '/' deletePrefix = httpPrefix + '://' + domainFull + '/'
if (not allowDeletion and if (not allowDeletion and
(not messageJson['object'].startswith(deletePrefix) or (not messageJson['object'].startswith(deletePrefix) or
@ -1923,23 +1890,15 @@ def sendToGroupMembers(session, baseDir: str, handle: str, port: int,
nickname = handle.split('@')[0] nickname = handle.split('@')[0]
# groupname = getGroupName(baseDir, handle) # groupname = getGroupName(baseDir, handle)
domain = handle.split('@')[1] domain = handle.split('@')[1]
domainFull = domain domainFull = getFullDomain(domain, port)
if ':' not in domain:
if port:
if port != 80 and port != 443:
domain = domain + ':' + str(port)
# set sender # set sender
cc = '' cc = ''
sendingActor = postJsonObject['actor'] sendingActor = postJsonObject['actor']
sendingActorNickname = getNicknameFromActor(sendingActor) sendingActorNickname = getNicknameFromActor(sendingActor)
sendingActorDomain, sendingActorPort = \ sendingActorDomain, sendingActorPort = \
getDomainFromActor(sendingActor) getDomainFromActor(sendingActor)
sendingActorDomainFull = sendingActorDomain sendingActorDomainFull = \
if ':' in sendingActorDomain: getFullDomain(sendingActorDomain, sendingActorPort)
if sendingActorPort:
if sendingActorPort != 80 and sendingActorPort != 443:
sendingActorDomainFull = \
sendingActorDomain + ':' + str(sendingActorPort)
senderStr = '@' + sendingActorNickname + '@' + sendingActorDomainFull senderStr = '@' + sendingActorNickname + '@' + sendingActorDomainFull
if not postJsonObject['object']['content'].startswith(senderStr): if not postJsonObject['object']['content'].startswith(senderStr):
postJsonObject['object']['content'] = \ postJsonObject['object']['content'] = \
@ -2259,9 +2218,7 @@ def inboxAfterInitial(recentPostsCache: {}, maxRecentPosts: int,
if isinstance(attributedTo, str): if isinstance(attributedTo, str):
fromNickname = getNicknameFromActor(attributedTo) fromNickname = getNicknameFromActor(attributedTo)
fromDomain, fromPort = getDomainFromActor(attributedTo) fromDomain, fromPort = getDomainFromActor(attributedTo)
if fromPort: fromDomain = getFullDomain(fromDomain, fromPort)
if fromPort != 80 and fromPort != 443:
fromDomain += ':' + str(fromPort)
if receiveGitPatch(baseDir, nickname, domain, if receiveGitPatch(baseDir, nickname, domain,
jsonObj['type'], jsonObj['type'],
jsonObj['summary'], jsonObj['summary'],
@ -2352,11 +2309,7 @@ def inboxAfterInitial(recentPostsCache: {}, maxRecentPosts: int,
nickname + '/dm') nickname + '/dm')
# get the actor being replied to # get the actor being replied to
domainFull = domain domainFull = getFullDomain(domain, port)
if port:
if ':' not in domain:
if port != 80 and port != 443:
domainFull = domainFull + ':' + str(port)
actor = httpPrefix + '://' + domainFull + \ actor = httpPrefix + '://' + domainFull + \
'/users/' + handle.split('@')[0] '/users/' + handle.split('@')[0]