Separate function for extracting domain name

merge-requests/30/head
Bob Mottram 2021-06-23 22:31:50 +01:00
parent 7c0b0fb195
commit e0aac3c6a3
21 changed files with 93 additions and 107 deletions

View File

@ -7,6 +7,7 @@ __email__ = "bob@freedombone.net"
__status__ = "Production" __status__ = "Production"
__module_group__ = "ActivityPub" __module_group__ = "ActivityPub"
from domainhandler import removeDomainPort
from utils import hasObjectDict from utils import hasObjectDict
from utils import removeIdEnding from utils import removeIdEnding
from utils import hasUsersPath from utils import hasUsersPath
@ -128,8 +129,7 @@ def createAnnounce(session, baseDir: str, federationList: [],
if not urlPermitted(objectUrl, federationList): if not urlPermitted(objectUrl, federationList):
return None return None
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
fullDomain = getFullDomain(domain, port) fullDomain = getFullDomain(domain, port)
statusNumber, published = getStatusNumber() statusNumber, published = getStatusNumber()
@ -399,8 +399,7 @@ def outboxUndoAnnounce(recentPostsCache: {},
print('DEBUG: c2s undo announce request arrived in outbox') print('DEBUG: c2s undo announce request arrived in outbox')
messageId = removeIdEnding(messageJson['object']['object']) messageId = removeIdEnding(messageJson['object']['object'])
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
postFilename = locatePost(baseDir, nickname, domain, messageId) postFilename = locatePost(baseDir, nickname, domain, messageId)
if not postFilename: if not postFilename:
if debug: if debug:

View File

@ -11,6 +11,7 @@ import os
import json import json
import time import time
from datetime import datetime from datetime import datetime
from domainhandler import removeDomainPort
from utils import hasObjectDict from utils import hasObjectDict
from utils import isAccountDir from utils import isAccountDir
from utils import getCachedPostFilename from utils import getCachedPostFilename
@ -58,8 +59,7 @@ def addBlock(baseDir: str, nickname: str, domain: str,
blockNickname: str, blockDomain: str) -> bool: blockNickname: str, blockDomain: str) -> bool:
"""Block the given account """Block the given account
""" """
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
blockingFilename = baseDir + '/accounts/' + \ blockingFilename = baseDir + '/accounts/' + \
nickname + '@' + domain + '/blocking.txt' nickname + '@' + domain + '/blocking.txt'
blockHandle = blockNickname + '@' + blockDomain blockHandle = blockNickname + '@' + blockDomain
@ -111,8 +111,7 @@ def removeBlock(baseDir: str, nickname: str, domain: str,
unblockNickname: str, unblockDomain: str) -> bool: unblockNickname: str, unblockDomain: str) -> bool:
"""Unblock the given account """Unblock the given account
""" """
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
unblockingFilename = baseDir + '/accounts/' + \ unblockingFilename = baseDir + '/accounts/' + \
nickname + '@' + domain + '/blocking.txt' nickname + '@' + domain + '/blocking.txt'
unblockHandle = unblockNickname + '@' + unblockDomain unblockHandle = unblockNickname + '@' + unblockDomain
@ -338,8 +337,7 @@ def outboxBlock(baseDir: str, httpPrefix: str,
if debug: if debug:
print('DEBUG: c2s block object has no nickname') print('DEBUG: c2s block object has no nickname')
return return
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
postFilename = locatePost(baseDir, nickname, domain, messageId) postFilename = locatePost(baseDir, nickname, domain, messageId)
if not postFilename: if not postFilename:
if debug: if debug:
@ -406,8 +404,7 @@ def outboxUndoBlock(baseDir: str, httpPrefix: str,
if debug: if debug:
print('DEBUG: c2s undo block object has no nickname') print('DEBUG: c2s undo block object has no nickname')
return return
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
postFilename = locatePost(baseDir, nickname, domain, messageId) postFilename = locatePost(baseDir, nickname, domain, messageId)
if not postFilename: if not postFilename:
if debug: if debug:
@ -605,8 +602,7 @@ def outboxMute(baseDir: str, httpPrefix: str,
if debug: if debug:
print('DEBUG: c2s mute object has no nickname') print('DEBUG: c2s mute object has no nickname')
return return
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
postFilename = locatePost(baseDir, nickname, domain, messageId) postFilename = locatePost(baseDir, nickname, domain, messageId)
if not postFilename: if not postFilename:
if debug: if debug:
@ -663,8 +659,7 @@ def outboxUndoMute(baseDir: str, httpPrefix: str,
if debug: if debug:
print('DEBUG: c2s undo mute object has no nickname') print('DEBUG: c2s undo mute object has no nickname')
return return
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
postFilename = locatePost(baseDir, nickname, domain, messageId) postFilename = locatePost(baseDir, nickname, domain, messageId)
if not postFilename: if not postFilename:
if debug: if debug:

View File

@ -11,6 +11,7 @@ import os
from pprint import pprint from pprint import pprint
from webfinger import webfingerHandle from webfinger import webfingerHandle
from auth import createBasicAuthHeader from auth import createBasicAuthHeader
from domainhandler import removeDomainPort
from utils import hasUsersPath from utils import hasUsersPath
from utils import getFullDomain from utils import getFullDomain
from utils import removeIdEnding from utils import removeIdEnding
@ -560,8 +561,7 @@ def outboxBookmark(recentPostsCache: {},
print('DEBUG: c2s bookmark Add request arrived in outbox') print('DEBUG: c2s bookmark Add request arrived in outbox')
messageUrl = removeIdEnding(messageJson['object']['url']) messageUrl = removeIdEnding(messageJson['object']['url'])
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
postFilename = locatePost(baseDir, nickname, domain, messageUrl) postFilename = locatePost(baseDir, nickname, domain, messageUrl)
if not postFilename: if not postFilename:
if debug: if debug:
@ -625,8 +625,7 @@ def outboxUndoBookmark(recentPostsCache: {},
print('DEBUG: c2s unbookmark Remove request arrived in outbox') print('DEBUG: c2s unbookmark Remove request arrived in outbox')
messageUrl = removeIdEnding(messageJson['object']['url']) messageUrl = removeIdEnding(messageJson['object']['url'])
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
postFilename = locatePost(baseDir, nickname, domain, messageUrl) postFilename = locatePost(baseDir, nickname, domain, messageUrl)
if not postFilename: if not postFilename:
if debug: if debug:

View File

@ -10,6 +10,7 @@ import os
import email.parser import email.parser
import urllib.parse import urllib.parse
from shutil import copyfile from shutil import copyfile
from domainhandler import removeDomainPort
from utils import isValidLanguage from utils import isValidLanguage
from utils import getImageExtensions from utils import getImageExtensions
from utils import loadJson from utils import loadJson
@ -772,8 +773,7 @@ def addHtmlTags(baseDir: str, httpPrefix: str,
replaceEmoji = {} replaceEmoji = {}
emojiDict = {} emojiDict = {}
originalDomain = domain originalDomain = domain
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
followingFilename = baseDir + '/accounts/' + \ followingFilename = baseDir + '/accounts/' + \
nickname + '@' + domain + '/following.txt' nickname + '@' + domain + '/following.txt'

View File

@ -9,6 +9,7 @@ __module_group__ = "ActivityPub"
import os import os
from datetime import datetime from datetime import datetime
from domainhandler import removeDomainPort
from utils import hasUsersPath from utils import hasUsersPath
from utils import getFullDomain from utils import getFullDomain
from utils import removeIdEnding from utils import removeIdEnding
@ -154,8 +155,7 @@ def outboxDelete(baseDir: str, httpPrefix: str,
"wasn't created by you (nickname does not match)") "wasn't created by you (nickname does not match)")
return return
deleteDomain, deletePort = getDomainFromActor(messageId) deleteDomain, deletePort = getDomainFromActor(messageId)
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
if deleteDomain != domain: if deleteDomain != domain:
if debug: if debug:
print("DEBUG: you can't delete a post which " + print("DEBUG: you can't delete a post which " +

17
domainhandler.py 100644
View File

@ -0,0 +1,17 @@
__filename__ = "domainhandler.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
__version__ = "1.2.0"
__maintainer__ = "Bob Mottram"
__email__ = "bob@freedombone.net"
__status__ = "Production"
__module_group__ = "Core"
def removeDomainPort(domain: str) -> str:
"""If the domain has a port appended then remove it
eg. mydomain.com:80 becomes mydomain.com
"""
if ':' in domain:
domain = domain.split(':')[0]
return domain

View File

@ -61,6 +61,7 @@ from tests import testUpdateActor
from tests import runAllTests from tests import runAllTests
from auth import storeBasicCredentials from auth import storeBasicCredentials
from auth import createPassword from auth import createPassword
from domainhandler import removeDomainPort
from utils import hasUsersPath from utils import hasUsersPath
from utils import getFullDomain from utils import getFullDomain
from utils import setConfigParam from utils import setConfigParam
@ -1081,7 +1082,7 @@ if args.message:
toPort = 443 toPort = 443
if ':' in toDomain: if ':' in toDomain:
toPort = toDomain.split(':')[1] toPort = toDomain.split(':')[1]
toDomain = toDomain.split(':')[0] toDomain = removeDomainPort(toDomain)
else: else:
if args.sendto.endswith('followers'): if args.sendto.endswith('followers'):
toNickname = None toNickname = None

View File

@ -9,6 +9,7 @@ __module_group__ = "ActivityPub"
from pprint import pprint from pprint import pprint
import os import os
from domainhandler import removeDomainPort
from utils import hasObjectDict from utils import hasObjectDict
from utils import hasUsersPath from utils import hasUsersPath
from utils import getFullDomain from utils import getFullDomain
@ -153,8 +154,7 @@ def isFollowingActor(baseDir: str,
"""Is the given nickname following the given actor? """Is the given nickname following the given actor?
The actor can also be a handle: nickname@domain The actor can also be a handle: nickname@domain
""" """
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
handle = nickname + '@' + domain handle = nickname + '@' + domain
if not os.path.isdir(baseDir + '/accounts/' + handle): if not os.path.isdir(baseDir + '/accounts/' + handle):
return False return False
@ -205,8 +205,7 @@ def isFollowerOfPerson(baseDir: str, nickname: str, domain: str,
followerNickname: str, followerDomain: str) -> bool: followerNickname: str, followerDomain: str) -> bool:
"""is the given nickname a follower of followerNickname? """is the given nickname a follower of followerNickname?
""" """
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
followersFile = baseDir + '/accounts/' + \ followersFile = baseDir + '/accounts/' + \
nickname + '@' + domain + '/followers.txt' nickname + '@' + domain + '/followers.txt'
if not os.path.isfile(followersFile): if not os.path.isfile(followersFile):
@ -243,8 +242,7 @@ def unfollowAccount(baseDir: str, nickname: str, domain: str,
debug: bool = False) -> bool: debug: bool = False) -> bool:
"""Removes a person to the follow list """Removes a person to the follow list
""" """
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
handle = nickname + '@' + domain handle = nickname + '@' + domain
handleToUnfollow = followNickname + '@' + followDomain handleToUnfollow = followNickname + '@' + followDomain
if not os.path.isdir(baseDir + '/accounts'): if not os.path.isdir(baseDir + '/accounts'):
@ -433,8 +431,7 @@ def getFollowingFeed(baseDir: str, domain: str, port: int, path: str,
} }
handleDomain = domain handleDomain = domain
if ':' in handleDomain: handleDomain = removeDomainPort(handleDomain)
handleDomain = domain.split(':')[0]
handle = nickname + '@' + handleDomain handle = nickname + '@' + handleDomain
filename = baseDir + '/accounts/' + handle + '/' + followFile + '.txt' filename = baseDir + '/accounts/' + handle + '/' + followFile + '.txt'
if not os.path.isfile(filename): if not os.path.isfile(filename):
@ -493,8 +490,7 @@ def _followApprovalRequired(baseDir: str, nicknameToFollow: str,
return False return False
manuallyApproveFollows = False manuallyApproveFollows = False
if ':' in domainToFollow: domainToFollow = removeDomainPort(domainToFollow)
domainToFollow = domainToFollow.split(':')[0]
actorFilename = baseDir + '/accounts/' + \ actorFilename = baseDir + '/accounts/' + \
nicknameToFollow + '@' + domainToFollow + '.json' nicknameToFollow + '@' + domainToFollow + '.json'
if os.path.isfile(actorFilename): if os.path.isfile(actorFilename):

View File

@ -8,6 +8,7 @@ __status__ = "Production"
__module_group__ = "Calendar" __module_group__ = "Calendar"
import os import os
from domainhandler import removeDomainPort
def receivingCalendarEvents(baseDir: str, nickname: str, domain: str, def receivingCalendarEvents(baseDir: str, nickname: str, domain: str,
@ -43,8 +44,7 @@ def _receiveCalendarEvents(baseDir: str, nickname: str, domain: str,
indicating whether to receive calendar events from that account indicating whether to receive calendar events from that account
""" """
# check that a following file exists # check that a following file exists
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
followingFilename = baseDir + '/accounts/' + \ followingFilename = baseDir + '/accounts/' + \
nickname + '@' + domain + '/following.txt' nickname + '@' + domain + '/following.txt'
if not os.path.isfile(followingFilename): if not os.path.isfile(followingFilename):

View File

@ -13,6 +13,7 @@ import datetime
import time import time
import random import random
from linked_data_sig import verifyJsonSignature from linked_data_sig import verifyJsonSignature
from domainhandler import removeDomainPort
from utils import hasObjectDict from utils import hasObjectDict
from utils import dmAllowedFromDomain from utils import dmAllowedFromDomain
from utils import isRecentPost from utils import isRecentPost
@ -186,8 +187,7 @@ def _inboxStorePostToHtmlCache(recentPostsCache: {}, maxRecentPosts: int,
def validInbox(baseDir: str, nickname: str, domain: str) -> bool: def validInbox(baseDir: str, nickname: str, domain: str) -> bool:
"""Checks whether files were correctly saved to the inbox """Checks whether files were correctly saved to the inbox
""" """
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
inboxDir = baseDir + '/accounts/' + nickname + '@' + domain + '/inbox' inboxDir = baseDir + '/accounts/' + nickname + '@' + domain + '/inbox'
if not os.path.isdir(inboxDir): if not os.path.isdir(inboxDir):
return True return True
@ -209,8 +209,7 @@ def validInboxFilenames(baseDir: str, nickname: str, domain: str,
"""Used by unit tests to check that the port number gets appended to """Used by unit tests to check that the port number gets appended to
domain names within saved post filenames domain names within saved post filenames
""" """
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
inboxDir = baseDir + '/accounts/' + nickname + '@' + domain + '/inbox' inboxDir = baseDir + '/accounts/' + nickname + '@' + domain + '/inbox'
if not os.path.isdir(inboxDir): if not os.path.isdir(inboxDir):
return True return True
@ -358,8 +357,7 @@ def savePostToInboxQueue(baseDir: str, httpPrefix: str,
str(len(messageBytes)) + ' bytes') str(len(messageBytes)) + ' bytes')
return None return None
originalDomain = domain originalDomain = domain
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
# block at the ealiest stage possible, which means the data # block at the ealiest stage possible, which means the data
# isn't written to file # isn't written to file
@ -536,8 +534,7 @@ def _inboxPostRecipients(baseDir: str, postJsonObject: {},
print('WARNING: inbox post has no actor') print('WARNING: inbox post has no actor')
return recipientsDict, recipientsDictFollowers return recipientsDict, recipientsDictFollowers
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
domainBase = domain domainBase = domain
domain = getFullDomain(domain, port) domain = getFullDomain(domain, port)
domainMatch = '/' + domain + '/users/' domainMatch = '/' + domain + '/users/'
@ -1124,8 +1121,7 @@ def _receiveBookmark(recentPostsCache: {},
print('DEBUG: c2s inbox bookmark Add request arrived in outbox') print('DEBUG: c2s inbox bookmark Add request arrived in outbox')
messageUrl = removeIdEnding(messageJson['object']['url']) messageUrl = removeIdEnding(messageJson['object']['url'])
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
postFilename = locatePost(baseDir, nickname, domain, messageUrl) postFilename = locatePost(baseDir, nickname, domain, messageUrl)
if not postFilename: if not postFilename:
if debug: if debug:
@ -1200,8 +1196,7 @@ def _receiveUndoBookmark(recentPostsCache: {},
'request arrived in outbox') 'request arrived in outbox')
messageUrl = removeIdEnding(messageJson['object']['url']) messageUrl = removeIdEnding(messageJson['object']['url'])
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
postFilename = locatePost(baseDir, nickname, domain, messageUrl) postFilename = locatePost(baseDir, nickname, domain, messageUrl)
if not postFilename: if not postFilename:
if debug: if debug:
@ -1975,8 +1970,7 @@ def _sendToGroupMembers(session, baseDir: str, handle: str, port: int,
# set subject # set subject
if not postJsonObject['object'].get('summary'): if not postJsonObject['object'].get('summary'):
postJsonObject['object']['summary'] = 'General Discussion' postJsonObject['object']['summary'] = 'General Discussion'
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
with open(followersFile, 'r') as groupMembers: with open(followersFile, 'r') as groupMembers:
for memberHandle in groupMembers: for memberHandle in groupMembers:
if memberHandle != handle: if memberHandle != handle:
@ -1987,7 +1981,7 @@ def _sendToGroupMembers(session, baseDir: str, handle: str, port: int,
memberPortStr = memberDomain.split(':')[1] memberPortStr = memberDomain.split(':')[1]
if memberPortStr.isdigit(): if memberPortStr.isdigit():
memberPort = int(memberPortStr) memberPort = int(memberPortStr)
memberDomain = memberDomain.split(':')[0] memberDomain = removeDomainPort(memberDomain)
sendSignedJson(postJsonObject, session, baseDir, sendSignedJson(postJsonObject, session, baseDir,
nickname, domain, port, nickname, domain, port,
memberNickname, memberDomain, memberPort, cc, memberNickname, memberDomain, memberPort, cc,
@ -2078,8 +2072,7 @@ def _updateLastSeen(baseDir: str, handle: str, actor: str) -> None:
return return
nickname = handle.split('@')[0] nickname = handle.split('@')[0]
domain = handle.split('@')[1] domain = handle.split('@')[1]
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
accountPath = baseDir + '/accounts/' + nickname + '@' + domain accountPath = baseDir + '/accounts/' + nickname + '@' + domain
if not os.path.isdir(accountPath): if not os.path.isdir(accountPath):
return return
@ -2133,7 +2126,7 @@ def _bounceDM(senderPostId: str, session, httpPrefix: str,
senderPortStr = senderDomain.split(':')[1] senderPortStr = senderDomain.split(':')[1]
if senderPortStr.isdigit(): if senderPortStr.isdigit():
senderPort = int(senderPortStr) senderPort = int(senderPortStr)
senderDomain = senderDomain.split(':')[0] senderDomain = removeDomainPort(senderDomain)
cc = [] cc = []
# create the bounce DM # create the bounce DM

View File

@ -7,6 +7,7 @@ __email__ = "bob@freedombone.net"
__status__ = "Production" __status__ = "Production"
__module_group__ = "ActivityPub" __module_group__ = "ActivityPub"
from domainhandler import removeDomainPort
from utils import hasObjectDict from utils import hasObjectDict
from utils import hasUsersPath from utils import hasUsersPath
from utils import getFullDomain from utils import getFullDomain
@ -327,8 +328,7 @@ def outboxLike(recentPostsCache: {},
print('DEBUG: c2s like request arrived in outbox') print('DEBUG: c2s like request arrived in outbox')
messageId = removeIdEnding(messageJson['object']) messageId = removeIdEnding(messageJson['object'])
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
postFilename = locatePost(baseDir, nickname, domain, messageId) postFilename = locatePost(baseDir, nickname, domain, messageId)
if not postFilename: if not postFilename:
if debug: if debug:
@ -377,8 +377,7 @@ def outboxUndoLike(recentPostsCache: {},
print('DEBUG: c2s undo like request arrived in outbox') print('DEBUG: c2s undo like request arrived in outbox')
messageId = removeIdEnding(messageJson['object']['object']) messageId = removeIdEnding(messageJson['object']['object'])
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
postFilename = locatePost(baseDir, nickname, domain, messageId) postFilename = locatePost(baseDir, nickname, domain, messageId)
if not postFilename: if not postFilename:
if debug: if debug:

View File

@ -12,6 +12,7 @@ from follow import followedAccountAccepts
from follow import followedAccountRejects from follow import followedAccountRejects
from follow import removeFromFollowRequests from follow import removeFromFollowRequests
from utils import loadJson from utils import loadJson
from domainhandler import removeDomainPort
def manualDenyFollowRequest(session, baseDir: str, def manualDenyFollowRequest(session, baseDir: str,
@ -50,7 +51,7 @@ def manualDenyFollowRequest(session, baseDir: str,
denyPort = port denyPort = port
if ':' in denyDomain: if ':' in denyDomain:
denyPort = denyDomain.split(':')[1] denyPort = denyDomain.split(':')[1]
denyDomain = denyDomain.split(':')[0] denyDomain = removeDomainPort(denyDomain)
followedAccountRejects(session, baseDir, httpPrefix, followedAccountRejects(session, baseDir, httpPrefix,
nickname, domain, port, nickname, domain, port,
denyNickname, denyDomain, denyPort, denyNickname, denyDomain, denyPort,
@ -159,7 +160,7 @@ def manualApproveFollowRequest(session, baseDir: str,
approvePort = port2 approvePort = port2
if ':' in approveDomain: if ':' in approveDomain:
approvePort = approveDomain.split(':')[1] approvePort = approveDomain.split(':')[1]
approveDomain = approveDomain.split(':')[0] approveDomain = removeDomainPort(approveDomain)
print('Manual follow accept: Sending Accept for ' + print('Manual follow accept: Sending Accept for ' +
handle + ' follow request from ' + handle + ' follow request from ' +
approveNickname + '@' + approveDomain) approveNickname + '@' + approveDomain)

View File

@ -38,6 +38,7 @@ from roles import setRole
from roles import setRolesFromList from roles import setRolesFromList
from roles import getActorRolesList from roles import getActorRolesList
from media import processMetaData from media import processMetaData
from domainhandler import removeDomainPort
from utils import getStatusNumber from utils import getStatusNumber
from utils import getFullDomain from utils import getFullDomain
from utils import validNickname from utils import validNickname
@ -93,8 +94,7 @@ def setProfileImage(baseDir: str, httpPrefix: str, nickname: str, domain: str,
if imageFilename.startswith('~/'): if imageFilename.startswith('~/'):
imageFilename = imageFilename.replace('~/', str(Path.home()) + '/') imageFilename = imageFilename.replace('~/', str(Path.home()) + '/')
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
fullDomain = getFullDomain(domain, port) fullDomain = getFullDomain(domain, port)
handle = nickname + '@' + domain handle = nickname + '@' + domain
@ -147,8 +147,7 @@ def setProfileImage(baseDir: str, httpPrefix: str, nickname: str, domain: str,
def _accountExists(baseDir: str, nickname: str, domain: str) -> bool: def _accountExists(baseDir: str, nickname: str, domain: str) -> bool:
"""Returns true if the given account exists """Returns true if the given account exists
""" """
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
return os.path.isdir(baseDir + '/accounts/' + nickname + '@' + domain) or \ return os.path.isdir(baseDir + '/accounts/' + nickname + '@' + domain) or \
os.path.isdir(baseDir + '/deactivated/' + nickname + '@' + domain) os.path.isdir(baseDir + '/deactivated/' + nickname + '@' + domain)
@ -720,8 +719,7 @@ def personLookup(domain: str, path: str, baseDir: str) -> {}:
return None return None
if not isSharedInbox and not validNickname(domain, nickname): if not isSharedInbox and not validNickname(domain, nickname):
return None return None
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
handle = nickname + '@' + domain handle = nickname + '@' + domain
filename = baseDir + '/accounts/' + handle + '.json' filename = baseDir + '/accounts/' + handle + '.json'
if not os.path.isfile(filename): if not os.path.isfile(filename):

View File

@ -32,6 +32,7 @@ from session import postImage
from webfinger import webfingerHandle from webfinger import webfingerHandle
from httpsig import createSignedHeader from httpsig import createSignedHeader
from siteactive import siteIsActive from siteactive import siteIsActive
from domainhandler import removeDomainPort
from utils import hasObjectDict from utils import hasObjectDict
from utils import rejectPostId from utils import rejectPostId
from utils import removeInvalidChars from utils import removeInvalidChars
@ -683,8 +684,7 @@ def savePostToBox(baseDir: str, httpPrefix: str, postId: str,
boxname != 'scheduled': boxname != 'scheduled':
return None return None
originalDomain = domain originalDomain = domain
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
if not postId: if not postId:
statusNumber, published = getStatusNumber() statusNumber, published = getStatusNumber()
@ -1689,7 +1689,7 @@ def getMentionedPeople(baseDir: str, httpPrefix: str,
mentionedNickname = handle.split('@')[0] mentionedNickname = handle.split('@')[0]
mentionedDomain = handle.split('@')[1].strip('\n').strip('\r') mentionedDomain = handle.split('@')[1].strip('\n').strip('\r')
if ':' in mentionedDomain: if ':' in mentionedDomain:
mentionedDomain = mentionedDomain.split(':')[0] mentionedDomain = removeDomainPort(mentionedDomain)
if not validNickname(mentionedDomain, mentionedNickname): if not validNickname(mentionedDomain, mentionedNickname):
continue continue
actor = \ actor = \
@ -2666,7 +2666,7 @@ def sendToFollowers(session, baseDir: str,
toDomain = followerHandles[index].split('@')[1] toDomain = followerHandles[index].split('@')[1]
if ':' in toDomain: if ':' in toDomain:
toPort = toDomain.split(':')[1] toPort = toDomain.split(':')[1]
toDomain = toDomain.split(':')[0] toDomain = removeDomainPort(toDomain)
cc = '' cc = ''

View File

@ -10,6 +10,7 @@ import os
from utils import loadJson from utils import loadJson
from utils import saveJson from utils import saveJson
from utils import getStatusNumber from utils import getStatusNumber
from domainhandler import removeDomainPort
def _clearRoleStatus(baseDir: str, role: str) -> None: def _clearRoleStatus(baseDir: str, role: str) -> None:
@ -75,8 +76,7 @@ def _addRole(baseDir: str, nickname: str, domain: str,
"""Adds a role nickname to the file. """Adds a role nickname to the file.
This is a file containing the nicknames of accounts having this role This is a file containing the nicknames of accounts having this role
""" """
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
roleFile = baseDir + '/accounts/' + roleFilename roleFile = baseDir + '/accounts/' + roleFilename
if os.path.isfile(roleFile): if os.path.isfile(roleFile):
# is this nickname already in the file? # is this nickname already in the file?

View File

@ -20,6 +20,7 @@ from utils import loadJson
from utils import saveJson from utils import saveJson
from utils import getImageExtensions from utils import getImageExtensions
from utils import hasObjectDict from utils import hasObjectDict
from domainhandler import removeDomainPort
from media import processMetaData from media import processMetaData
@ -187,9 +188,7 @@ def expireShares(baseDir: str) -> None:
def _expireSharesForAccount(baseDir: str, nickname: str, domain: str) -> None: def _expireSharesForAccount(baseDir: str, nickname: str, domain: str) -> None:
"""Removes expired items from shares for a particular account """Removes expired items from shares for a particular account
""" """
handleDomain = domain handleDomain = removeDomainPort(domain)
if ':' in handleDomain:
handleDomain = domain.split(':')[0]
handle = nickname + '@' + handleDomain handle = nickname + '@' + handleDomain
sharesFilename = baseDir + '/accounts/' + handle + '/shares.json' sharesFilename = baseDir + '/accounts/' + handle + '/shares.json'
if os.path.isfile(sharesFilename): if os.path.isfile(sharesFilename):
@ -250,9 +249,7 @@ def getSharesFeedForPerson(baseDir: str,
domain = getFullDomain(domain, port) domain = getFullDomain(domain, port)
handleDomain = domain handleDomain = removeDomainPort(domain)
if ':' in handleDomain:
handleDomain = domain.split(':')[0]
handle = nickname + '@' + handleDomain handle = nickname + '@' + handleDomain
sharesFilename = baseDir + '/accounts/' + handle + '/shares.json' sharesFilename = baseDir + '/accounts/' + handle + '/shares.json'

View File

@ -15,6 +15,7 @@ import json
import idna import idna
import locale import locale
from pprint import pprint from pprint import pprint
from domainhandler import removeDomainPort
from followingCalendar import addPersonToCalendar from followingCalendar import addPersonToCalendar
from cryptography.hazmat.backends import default_backend from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives import hashes
@ -417,8 +418,7 @@ def getFollowersOfPerson(baseDir: str,
Used by the shared inbox to know who to send incoming mail to Used by the shared inbox to know who to send incoming mail to
""" """
followers = [] followers = []
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
handle = nickname + '@' + domain handle = nickname + '@' + domain
if not os.path.isdir(baseDir + '/accounts/' + handle): if not os.path.isdir(baseDir + '/accounts/' + handle):
return followers return followers
@ -645,8 +645,7 @@ def createInboxQueueDir(nickname: str, domain: str, baseDir: str) -> str:
def domainPermitted(domain: str, federationList: []): def domainPermitted(domain: str, federationList: []):
if len(federationList) == 0: if len(federationList) == 0:
return True return True
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
if domain in federationList: if domain in federationList:
return True return True
return False return False
@ -923,7 +922,7 @@ def getDomainFromActor(actor: str) -> (str, int):
if not portStr.isdigit(): if not portStr.isdigit():
return None, None return None, None
port = int(portStr) port = int(portStr)
domain = domain.split(':')[0] domain = removeDomainPort(domain)
return domain, port return domain, port
@ -932,8 +931,7 @@ def _setDefaultPetName(baseDir: str, nickname: str, domain: str,
"""Sets a default petname """Sets a default petname
This helps especially when using onion or i2p address This helps especially when using onion or i2p address
""" """
if ':' in domain: domain = removeDomainPort(domain)
domain = domain.split(':')[0]
userPath = baseDir + '/accounts/' + nickname + '@' + domain userPath = baseDir + '/accounts/' + nickname + '@' + domain
petnamesFilename = userPath + '/petnames.txt' petnamesFilename = userPath + '/petnames.txt'
@ -975,7 +973,8 @@ def followPerson(baseDir: str, nickname: str, domain: str,
print('DEBUG: follow of domain ' + followDomain) print('DEBUG: follow of domain ' + followDomain)
if ':' in domain: if ':' in domain:
handle = nickname + '@' + domain.split(':')[0] domainOnly = removeDomainPort(domain)
handle = nickname + '@' + domainOnly
else: else:
handle = nickname + '@' + domain handle = nickname + '@' + domain
@ -984,7 +983,8 @@ def followPerson(baseDir: str, nickname: str, domain: str,
return False return False
if ':' in followDomain: if ':' in followDomain:
handleToFollow = followNickname + '@' + followDomain.split(':')[0] followDomainOnly = removeDomainPort(followDomain)
handleToFollow = followNickname + '@' + followDomainOnly
else: else:
handleToFollow = followNickname + '@' + followDomain handleToFollow = followNickname + '@' + followDomain

View File

@ -18,6 +18,7 @@ from utils import getDomainFromActor
from utils import locatePost from utils import locatePost
from utils import loadJson from utils import loadJson
from utils import weekDayOfMonthStart from utils import weekDayOfMonthStart
from domainhandler import removeDomainPort
from happening import getTodaysEvents from happening import getTodaysEvents
from happening import getCalendarEvents from happening import getCalendarEvents
from webapp_utils import htmlHeaderWithExternalStyle from webapp_utils import htmlHeaderWithExternalStyle
@ -247,9 +248,7 @@ def htmlCalendar(personCache: {}, cssCache: {}, translate: {},
textModeBanner: str, accessKeys: {}) -> str: textModeBanner: str, accessKeys: {}) -> str:
"""Show the calendar for a person """Show the calendar for a person
""" """
domain = domainFull domain = removeDomainPort(domainFull)
if ':' in domainFull:
domain = domainFull.split(':')[0]
monthNumber = 0 monthNumber = 0
dayNumber = None dayNumber = None

View File

@ -11,6 +11,7 @@ import os
from utils import getConfigParam from utils import getConfigParam
from utils import getNicknameFromActor from utils import getNicknameFromActor
from utils import isEditor from utils import isEditor
from domainhandler import removeDomainPort
from webapp_utils import sharesTimelineJson from webapp_utils import sharesTimelineJson
from webapp_utils import htmlPostSeparator from webapp_utils import htmlPostSeparator
from webapp_utils import getLeftImageFile from webapp_utils import getLeftImageFile
@ -76,9 +77,7 @@ def getLeftColumnContent(baseDir: str, nickname: str, domainFull: str,
htmlStr = '' htmlStr = ''
separatorStr = htmlPostSeparator(baseDir, 'left') separatorStr = htmlPostSeparator(baseDir, 'left')
domain = domainFull domain = removeDomainPort(domainFull)
if ':' in domain:
domain = domain.split(':')
editImageClass = '' editImageClass = ''
if showHeaderImage: if showHeaderImage:
@ -298,9 +297,7 @@ def htmlLinksMobile(cssCache: {}, baseDir: str,
else: else:
editor = isEditor(baseDir, nickname) editor = isEditor(baseDir, nickname)
domain = domainFull domain = removeDomainPort(domainFull)
if ':' in domain:
domain = domain.split(':')[0]
instanceTitle = \ instanceTitle = \
getConfigParam(baseDir, 'instanceTitle') getConfigParam(baseDir, 'instanceTitle')

View File

@ -17,6 +17,7 @@ from utils import votesOnNewswireItem
from utils import getNicknameFromActor from utils import getNicknameFromActor
from utils import isEditor from utils import isEditor
from utils import getConfigParam from utils import getConfigParam
from domainhandler import removeDomainPort
from posts import isModerator from posts import isModerator
from webapp_utils import getRightImageFile from webapp_utils import getRightImageFile
from webapp_utils import htmlHeaderWithExternalStyle from webapp_utils import htmlHeaderWithExternalStyle
@ -58,9 +59,7 @@ def getRightColumnContent(baseDir: str, nickname: str, domainFull: str,
""" """
htmlStr = '' htmlStr = ''
domain = domainFull domain = removeDomainPort(domainFull)
if ':' in domain:
domain = domain.split(':')
if authorized: if authorized:
# only show the publish button if logged in, otherwise replace it with # only show the publish button if logged in, otherwise replace it with

View File

@ -17,6 +17,7 @@ from utils import loadJson
from utils import loadJsonOnionify from utils import loadJsonOnionify
from utils import saveJson from utils import saveJson
from utils import getProtocolPrefixes from utils import getProtocolPrefixes
from domainhandler import removeDomainPort
def _parseHandle(handle: str) -> (str, str): def _parseHandle(handle: str) -> (str, str):
@ -53,13 +54,8 @@ def webfingerHandle(session, handle: str, httpPrefix: str,
nickname, domain = _parseHandle(handle) nickname, domain = _parseHandle(handle)
if not nickname: if not nickname:
return None return None
wfDomain = domain wfDomain = removeDomainPort(domain)
if ':' in wfDomain:
# wfPortStr=wfDomain.split(':')[1]
# if wfPortStr.isdigit():
# wfPort=int(wfPortStr)
# if wfPort==80 or wfPort==443:
wfDomain = wfDomain.split(':')[0]
wf = getWebfingerFromCache(nickname + '@' + wfDomain, wf = getWebfingerFromCache(nickname + '@' + wfDomain,
cachedWebfingers) cachedWebfingers)
if wf: if wf: