Tidying of users path detection

merge-requests/8/head
Bob Mottram 2020-12-23 10:57:44 +00:00
parent 61280ac6d0
commit 838d853a59
14 changed files with 53 additions and 118 deletions

View File

@ -7,6 +7,7 @@ __email__ = "bob@freedombone.net"
__status__ = "Production" __status__ = "Production"
import os import os
from utils import hasUsersPath
from utils import getFullDomain from utils import getFullDomain
from utils import urlPermitted from utils import urlPermitted
from utils import getDomainFromActor from utils import getDomainFromActor
@ -182,10 +183,7 @@ def receiveAcceptReject(session, baseDir: str,
if debug: if debug:
print('DEBUG: ' + messageJson['type'] + ' has no actor') print('DEBUG: ' + messageJson['type'] + ' has no actor')
return False return False
if '/users/' not in messageJson['actor'] and \ if not hasUsersPath(messageJson['actor']):
'/accounts/' not in messageJson['actor'] and \
'/channel/' not in messageJson['actor'] and \
'/profile/' not in messageJson['actor']:
if debug: if debug:
print('DEBUG: "users" or "profile" missing from actor in ' + print('DEBUG: "users" or "profile" missing from actor in ' +
messageJson['type'] + '. Assuming single user instance.') messageJson['type'] + '. Assuming single user instance.')

View File

@ -6,6 +6,7 @@ __maintainer__ = "Bob Mottram"
__email__ = "bob@freedombone.net" __email__ = "bob@freedombone.net"
__status__ = "Production" __status__ = "Production"
from utils import hasUsersPath
from utils import getFullDomain from utils import getFullDomain
from utils import getStatusNumber from utils import getStatusNumber
from utils import createOutboxDir from utils import createOutboxDir
@ -143,10 +144,7 @@ def createAnnounce(session, baseDir: str, federationList: [],
announceNickname = None announceNickname = None
announceDomain = None announceDomain = None
announcePort = None announcePort = None
if '/users/' in objectUrl or \ if hasUsersPath(objectUrl):
'/accounts/' in objectUrl or \
'/channel/' in objectUrl or \
'/profile/' in objectUrl:
announceNickname = getNicknameFromActor(objectUrl) announceNickname = getNicknameFromActor(objectUrl)
announceDomain, announcePort = getDomainFromActor(objectUrl) announceDomain, announcePort = getDomainFromActor(objectUrl)

View File

@ -12,6 +12,7 @@ import binascii
import os import os
import secrets import secrets
from utils import isSystemAccount from utils import isSystemAccount
from utils import hasUsersPath
def _hashPassword(password: str) -> str: def _hashPassword(password: str) -> str:
@ -89,10 +90,7 @@ def authorizeBasic(baseDir: str, path: str, authHeader: str,
print('DEBUG: basic auth - Authorixation header does not ' + print('DEBUG: basic auth - Authorixation header does not ' +
'contain a space character') 'contain a space character')
return False return False
if '/users/' not in path and \ if not hasUsersPath(path):
'/accounts/' not in path and \
'/channel/' not in path and \
'/profile/' not in path:
if debug: if debug:
print('DEBUG: basic auth - ' + print('DEBUG: basic auth - ' +
'path for Authorization does not contain a user') 'path for Authorization does not contain a user')

View File

@ -7,6 +7,7 @@ __email__ = "bob@freedombone.net"
__status__ = "Production" __status__ = "Production"
import os import os
from utils import hasUsersPath
from utils import getFullDomain from utils import getFullDomain
from utils import removeIdEnding from utils import removeIdEnding
from utils import isEvil from utils import isEvil
@ -246,10 +247,7 @@ def outboxBlock(baseDir: str, httpPrefix: str,
if debug: if debug:
print('DEBUG: c2s block object is not a status') print('DEBUG: c2s block object is not a status')
return return
if '/users/' not in messageId and \ if not hasUsersPath(messageId):
'/accounts/' not in messageId and \
'/channel/' not in messageId and \
'/profile/' not in messageId:
if debug: if debug:
print('DEBUG: c2s block object has no nickname') print('DEBUG: c2s block object has no nickname')
return return
@ -321,10 +319,7 @@ def outboxUndoBlock(baseDir: str, httpPrefix: str,
if debug: if debug:
print('DEBUG: c2s undo block object is not a status') print('DEBUG: c2s undo block object is not a status')
return return
if '/users/' not in messageId and \ if not hasUsersPath(messageId):
'/accounts/' not in messageId and \
'/channel/' not in messageId and \
'/profile/' not in messageId:
if debug: if debug:
print('DEBUG: c2s undo block object has no nickname') print('DEBUG: c2s undo block object has no nickname')
return return

View File

@ -8,6 +8,7 @@ __status__ = "Production"
import os import os
from pprint import pprint from pprint import pprint
from utils import hasUsersPath
from utils import getFullDomain from utils import getFullDomain
from utils import removeIdEnding from utils import removeIdEnding
from utils import removePostFromCache from utils import removePostFromCache
@ -255,10 +256,7 @@ def bookmark(recentPostsCache: {},
bookmarkedPostNickname = getNicknameFromActor(acBm) bookmarkedPostNickname = getNicknameFromActor(acBm)
bookmarkedPostDomain, bookmarkedPostPort = getDomainFromActor(acBm) bookmarkedPostDomain, bookmarkedPostPort = getDomainFromActor(acBm)
else: else:
if '/users/' in objectUrl or \ if hasUsersPath(objectUrl):
'/accounts/' in objectUrl or \
'/channel/' in objectUrl or \
'/profile/' in objectUrl:
ou = objectUrl ou = objectUrl
bookmarkedPostNickname = getNicknameFromActor(ou) bookmarkedPostNickname = getNicknameFromActor(ou)
bookmarkedPostDomain, bookmarkedPostPort = getDomainFromActor(ou) bookmarkedPostDomain, bookmarkedPostPort = getDomainFromActor(ou)
@ -322,10 +320,7 @@ def undoBookmark(recentPostsCache: {},
bookmarkedPostNickname = getNicknameFromActor(acBm) bookmarkedPostNickname = getNicknameFromActor(acBm)
bookmarkedPostDomain, bookmarkedPostPort = getDomainFromActor(acBm) bookmarkedPostDomain, bookmarkedPostPort = getDomainFromActor(acBm)
else: else:
if '/users/' in objectUrl or \ if hasUsersPath(objectUrl):
'/accounts/' in objectUrl or \
'/channel/' in objectUrl or \
'/profile/' in objectUrl:
ou = objectUrl ou = objectUrl
bookmarkedPostNickname = getNicknameFromActor(ou) bookmarkedPostNickname = getNicknameFromActor(ou)
bookmarkedPostDomain, bookmarkedPostPort = getDomainFromActor(ou) bookmarkedPostDomain, bookmarkedPostPort = getDomainFromActor(ou)

View File

@ -171,9 +171,10 @@ from shares import getSharesFeedForPerson
from shares import addShare from shares import addShare
from shares import removeShare from shares import removeShare
from shares import expireShares from shares import expireShares
from categories import setHashtagCategory
from utils import hasUsersPath
from utils import getFullDomain from utils import getFullDomain
from utils import removeHtml from utils import removeHtml
from categories import setHashtagCategory
from utils import isEditor from utils import isEditor
from utils import getImageExtensions from utils import getImageExtensions
from utils import mediaFileMimeType from utils import mediaFileMimeType
@ -2523,10 +2524,7 @@ class PubServer(BaseHTTPRequestHandler):
return return
elif ('@' in searchStr or elif ('@' in searchStr or
('://' in searchStr and ('://' in searchStr and
('/users/' in searchStr or hasUsersPath(searchStr))):
'/profile/' in searchStr or
'/accounts/' in searchStr or
'/channel/' in searchStr))):
# profile search # profile search
nickname = getNicknameFromActor(actorStr) nickname = getNicknameFromActor(actorStr)
if not self.server.session: if not self.server.session:

View File

@ -8,6 +8,7 @@ __status__ = "Production"
import os import os
from datetime import datetime from datetime import datetime
from utils import hasUsersPath
from utils import getFullDomain from utils import getFullDomain
from utils import removeIdEnding from utils import removeIdEnding
from utils import getNicknameFromActor from utils import getNicknameFromActor
@ -139,10 +140,7 @@ def outboxDelete(baseDir: str, httpPrefix: str,
if debug: if debug:
print('DEBUG: c2s delete object is not a status') print('DEBUG: c2s delete object is not a status')
return return
if '/users/' not in messageId and \ if not hasUsersPath(messageId):
'/accounts/' not in messageId and \
'/channel/' not in messageId and \
'/profile/' not in messageId:
if debug: if debug:
print('DEBUG: c2s delete object has no nickname') print('DEBUG: c2s delete object has no nickname')
return return

View File

@ -47,6 +47,7 @@ from tests import testClientToServer
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 utils import hasUsersPath
from utils import getFullDomain from utils import getFullDomain
from utils import setConfigParam from utils import setConfigParam
from utils import getConfigParam from utils import getConfigParam
@ -1318,10 +1319,7 @@ if args.actor:
for prefix in prefixes: for prefix in prefixes:
args.actor = args.actor.replace(prefix, '') args.actor = args.actor.replace(prefix, '')
args.actor = args.actor.replace('/@', '/users/') args.actor = args.actor.replace('/@', '/users/')
if '/users/' not in args.actor and \ if not hasUsersPath(args.actor):
'/accounts/' not in args.actor and \
'/channel/' not in args.actor and \
'/profile/' not in args.actor:
print('Expected actor format: ' + print('Expected actor format: ' +
'https://domain/@nick or https://domain/users/nick') 'https://domain/@nick or https://domain/users/nick')
sys.exit() sys.exit()
@ -1391,10 +1389,7 @@ if args.actor:
personUrl = None personUrl = None
if wfRequest.get('errors'): if wfRequest.get('errors'):
print('wfRequest error: ' + str(wfRequest['errors'])) print('wfRequest error: ' + str(wfRequest['errors']))
if '/users/' in args.actor or \ if hasUsersPath(args.actor):
'/accounts/' in args.actor or \
'/profile/' in args.actor or \
'/channel/' in args.actor:
personUrl = originalActor personUrl = originalActor
else: else:
sys.exit() sys.exit()

View File

@ -8,6 +8,7 @@ __status__ = "Production"
from pprint import pprint from pprint import pprint
import os import os
from utils import hasUsersPath
from utils import getFullDomain from utils import getFullDomain
from utils import isSystemAccount from utils import isSystemAccount
from utils import getFollowersList from utils import getFollowersList
@ -316,10 +317,7 @@ def _getNoOfFollows(baseDir: str, nickname: str, domain: str,
ctr += 1 ctr += 1
elif ((line.startswith('http') or elif ((line.startswith('http') or
line.startswith('dat')) and line.startswith('dat')) and
('/users/' in line or hasUsersPath(line)):
'/profile/' in line or
'/accounts/' in line or
'/channel/' in line)):
ctr += 1 ctr += 1
return ctr return ctr
@ -438,10 +436,7 @@ def getFollowingFeed(baseDir: str, domain: str, port: int, path: str,
following['orderedItems'].append(url) following['orderedItems'].append(url)
elif ((line.startswith('http') or elif ((line.startswith('http') or
line.startswith('dat')) and line.startswith('dat')) and
('/users/' in line or hasUsersPath(line)):
'/profile/' in line or
'/accounts/' in line or
'/channel/' in line)):
# https://domain/users/nickname # https://domain/users/nickname
pageCtr += 1 pageCtr += 1
totalCtr += 1 totalCtr += 1
@ -616,10 +611,7 @@ def receiveFollowRequest(session, baseDir: str, httpPrefix: str,
if debug: if debug:
print('DEBUG: follow request has no actor') print('DEBUG: follow request has no actor')
return False return False
if '/users/' not in messageJson['actor'] and \ if not hasUsersPath(messageJson['actor']):
'/accounts/' not in messageJson['actor'] and \
'/channel/' not in messageJson['actor'] and \
'/profile/' not in messageJson['actor']:
if debug: if debug:
print('DEBUG: users/profile/accounts/channel missing from actor') print('DEBUG: users/profile/accounts/channel missing from actor')
return False return False
@ -641,10 +633,7 @@ def receiveFollowRequest(session, baseDir: str, httpPrefix: str,
'nickname. Assuming single user instance.') 'nickname. Assuming single user instance.')
if not messageJson.get('to'): if not messageJson.get('to'):
messageJson['to'] = messageJson['object'] messageJson['to'] = messageJson['object']
if '/users/' not in messageJson['object'] and \ if not hasUsersPath(messageJson['object']):
'/accounts/' not in messageJson['object'] and \
'/channel/' not in messageJson['object'] and \
'/profile/' not in messageJson['object']:
if debug: if debug:
print('DEBUG: users/profile/channel/accounts ' + print('DEBUG: users/profile/channel/accounts ' +
'not found within object') 'not found within object')

View File

@ -10,6 +10,7 @@ import json
import os import os
import datetime import datetime
import time import time
from utils import hasUsersPath
from utils import validPostDate from utils import validPostDate
from utils import getFullDomain from utils import getFullDomain
from utils import isEventPost from utils import isEventPost
@ -604,10 +605,7 @@ def _receiveUndoFollow(session, baseDir: str, httpPrefix: str,
if debug: if debug:
print('DEBUG: follow request has no actor within object') print('DEBUG: follow request has no actor within object')
return False return False
if '/users/' not in messageJson['object']['actor'] and \ if not hasUsersPath(messageJson['object']['actor']):
'/accounts/' not in messageJson['object']['actor'] and \
'/channel/' not in messageJson['object']['actor'] and \
'/profile/' not in messageJson['object']['actor']:
if debug: if debug:
print('DEBUG: "users" or "profile" missing ' + print('DEBUG: "users" or "profile" missing ' +
'from actor within object') 'from actor within object')
@ -668,10 +666,7 @@ def _receiveUndo(session, baseDir: str, httpPrefix: str,
if debug: if debug:
print('DEBUG: follow request has no actor') print('DEBUG: follow request has no actor')
return False return False
if '/users/' not in messageJson['actor'] and \ if not hasUsersPath(messageJson['actor']):
'/accounts/' not in messageJson['actor'] and \
'/channel/' not in messageJson['actor'] and \
'/profile/' not in messageJson['actor']:
if debug: if debug:
print('DEBUG: "users" or "profile" missing from actor') print('DEBUG: "users" or "profile" missing from actor')
return False return False
@ -859,10 +854,7 @@ def _receiveUpdate(recentPostsCache: {}, session, baseDir: str,
if debug: if debug:
print('DEBUG: ' + messageJson['type'] + ' object has no type') print('DEBUG: ' + messageJson['type'] + ' object has no type')
return False return False
if '/users/' not in messageJson['actor'] and \ if not hasUsersPath(messageJson['actor']):
'/accounts/' not in messageJson['actor'] and \
'/channel/' not in messageJson['actor'] and \
'/profile/' not in messageJson['actor']:
if debug: if debug:
print('DEBUG: "users" or "profile" missing from actor in ' + print('DEBUG: "users" or "profile" missing from actor in ' +
messageJson['type']) messageJson['type'])
@ -943,10 +935,7 @@ def _receiveLike(recentPostsCache: {},
if debug: if debug:
print('DEBUG: ' + messageJson['type'] + ' has no "to" list') print('DEBUG: ' + messageJson['type'] + ' has no "to" list')
return False return False
if '/users/' not in messageJson['actor'] and \ if not hasUsersPath(messageJson['actor']):
'/accounts/' not in messageJson['actor'] and \
'/channel/' not in messageJson['actor'] and \
'/profile/' not in messageJson['actor']:
if debug: if debug:
print('DEBUG: "users" or "profile" missing from actor in ' + print('DEBUG: "users" or "profile" missing from actor in ' +
messageJson['type']) messageJson['type'])
@ -1014,10 +1003,7 @@ def _receiveUndoLike(recentPostsCache: {},
print('DEBUG: ' + messageJson['type'] + print('DEBUG: ' + messageJson['type'] +
' like object is not a string') ' like object is not a string')
return False return False
if '/users/' not in messageJson['actor'] and \ if not hasUsersPath(messageJson['actor']):
'/accounts/' not in messageJson['actor'] and \
'/channel/' not in messageJson['actor'] and \
'/profile/' not in messageJson['actor']:
if debug: if debug:
print('DEBUG: "users" or "profile" missing from actor in ' + print('DEBUG: "users" or "profile" missing from actor in ' +
messageJson['type'] + ' like') messageJson['type'] + ' like')
@ -1219,10 +1205,7 @@ def _receiveDelete(session, handle: str, isGroup: bool, baseDir: str,
if debug: if debug:
print('DEBUG: ' + messageJson['type'] + ' has no "to" list') print('DEBUG: ' + messageJson['type'] + ' has no "to" list')
return False return False
if '/users/' not in messageJson['actor'] and \ if not hasUsersPath(messageJson['actor']):
'/accounts/' not in messageJson['actor'] and \
'/channel/' not in messageJson['actor'] and \
'/profile/' not in messageJson['actor']:
if debug: if debug:
print('DEBUG: ' + print('DEBUG: ' +
'"users" or "profile" missing from actor in ' + '"users" or "profile" missing from actor in ' +
@ -1303,19 +1286,13 @@ def _receiveAnnounce(recentPostsCache: {},
if debug: if debug:
print('DEBUG: ' + messageJson['type'] + ' has no "to" list') print('DEBUG: ' + messageJson['type'] + ' has no "to" list')
return False return False
if '/users/' not in messageJson['actor'] and \ if not hasUsersPath(messageJson['actor']):
'/accounts/' not in messageJson['actor'] and \
'/channel/' not in messageJson['actor'] and \
'/profile/' not in messageJson['actor']:
if debug: if debug:
print('DEBUG: ' + print('DEBUG: ' +
'"users" or "profile" missing from actor in ' + '"users" or "profile" missing from actor in ' +
messageJson['type']) messageJson['type'])
return False return False
if '/users/' not in messageJson['object'] and \ if not hasUsersPath(messageJson['object']):
'/accounts/' not in messageJson['object'] and \
'/channel/' not in messageJson['object'] and \
'/profile/' not in messageJson['object']:
if debug: if debug:
print('DEBUG: ' + print('DEBUG: ' +
'"users", "channel" or "profile" missing in ' + '"users", "channel" or "profile" missing in ' +
@ -1387,10 +1364,7 @@ def _receiveAnnounce(recentPostsCache: {},
if isinstance(attrib, str): if isinstance(attrib, str):
lookupActor = attrib lookupActor = attrib
if lookupActor: if lookupActor:
if '/users/' in lookupActor or \ if hasUsersPath(lookupActor):
'/accounts/' in lookupActor or \
'/channel/' in lookupActor or \
'/profile/' in lookupActor:
if '/statuses/' in lookupActor: if '/statuses/' in lookupActor:
lookupActor = lookupActor.split('/statuses/')[0] lookupActor = lookupActor.split('/statuses/')[0]
@ -1439,10 +1413,7 @@ def _receiveUndoAnnounce(recentPostsCache: {},
return False return False
if messageJson['object']['type'] != 'Announce': if messageJson['object']['type'] != 'Announce':
return False return False
if '/users/' not in messageJson['actor'] and \ if not hasUsersPath(messageJson['actor']):
'/accounts/' not in messageJson['actor'] and \
'/channel/' not in messageJson['actor'] and \
'/profile/' not in messageJson['actor']:
if debug: if debug:
print('DEBUG: "users" or "profile" missing from actor in ' + print('DEBUG: "users" or "profile" missing from actor in ' +
messageJson['type'] + ' announce') messageJson['type'] + ' announce')
@ -1688,10 +1659,7 @@ def _obtainAvatarForReplyPost(session, baseDir: str, httpPrefix: str,
if not isinstance(lookupActor, str): if not isinstance(lookupActor, str):
return return
if not ('/users/' in lookupActor or if not hasUsersPath(lookupActor):
'/accounts/' in lookupActor or
'/channel/' in lookupActor or
'/profile/' in lookupActor):
return return
if '/statuses/' in lookupActor: if '/statuses/' in lookupActor:

View File

@ -6,6 +6,7 @@ __maintainer__ = "Bob Mottram"
__email__ = "bob@freedombone.net" __email__ = "bob@freedombone.net"
__status__ = "Production" __status__ = "Production"
from utils import hasUsersPath
from utils import getFullDomain from utils import getFullDomain
from utils import removeIdEnding from utils import removeIdEnding
from utils import urlPermitted from utils import urlPermitted
@ -87,10 +88,7 @@ def _like(recentPostsCache: {},
likedPostNickname = getNicknameFromActor(actorLiked) likedPostNickname = getNicknameFromActor(actorLiked)
likedPostDomain, likedPostPort = getDomainFromActor(actorLiked) likedPostDomain, likedPostPort = getDomainFromActor(actorLiked)
else: else:
if '/users/' in objectUrl or \ if hasUsersPath(objectUrl):
'/accounts/' in objectUrl or \
'/channel/' in objectUrl or \
'/profile/' in objectUrl:
likedPostNickname = getNicknameFromActor(objectUrl) likedPostNickname = getNicknameFromActor(objectUrl)
likedPostDomain, likedPostPort = getDomainFromActor(objectUrl) likedPostDomain, likedPostPort = getDomainFromActor(objectUrl)

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 hasUsersPath
from utils import validPostDate from utils import validPostDate
from utils import getFullDomain from utils import getFullDomain
from utils import getFollowersList from utils import getFollowersList
@ -155,10 +156,7 @@ def getUserUrl(wfRequest: {}, sourceId=0) -> str:
continue continue
if link['type'] != 'application/activity+json': if link['type'] != 'application/activity+json':
continue continue
if not ('/users/' in link['href'] or if not hasUsersPath(link['href']):
'/accounts/' in link['href'] or
'/profile/' in link['href'] or
'/channel/' in link['href']):
print('getUserUrl webfinger activity+json ' + print('getUserUrl webfinger activity+json ' +
'contains single user instance actor ' + 'contains single user instance actor ' +
str(sourceId) + ' ' + str(link)) str(sourceId) + ' ' + str(link))

View File

@ -19,6 +19,16 @@ from calendar import monthrange
from followingCalendar import addPersonToCalendar from followingCalendar import addPersonToCalendar
def hasUsersPath(pathStr: str) -> bool:
"""Whether there is a /users/ path (or equivalent) in the given string
"""
usersList = ('users', 'accounts', 'channel', 'profile')
for usersStr in usersList:
if '/' + usersStr + '/' in pathStr:
return True
return False
def validPostDate(published: str, maxAgeDays=7) -> bool: def validPostDate(published: str, maxAgeDays=7) -> bool:
"""Returns true if the published date is recent and is not in the future """Returns true if the published date is recent and is not in the future
""" """

View File

@ -8,6 +8,7 @@ __status__ = "Production"
import os import os
from pprint import pprint from pprint import pprint
from utils import hasUsersPath
from utils import getFullDomain from utils import getFullDomain
from utils import isDormant from utils import isDormant
from utils import getNicknameFromActor from utils import getNicknameFromActor
@ -61,11 +62,7 @@ def htmlProfileAfterSearch(cssCache: {},
defaultTimeline: str) -> str: defaultTimeline: str) -> str:
"""Show a profile page after a search for a fediverse address """Show a profile page after a search for a fediverse address
""" """
if '/users/' in profileHandle or \ if hasUsersPath(profileHandle) or '/@' in profileHandle:
'/accounts/' in profileHandle or \
'/channel/' in profileHandle or \
'/profile/' in profileHandle or \
'/@' in profileHandle:
searchNickname = getNicknameFromActor(profileHandle) searchNickname = getNicknameFromActor(profileHandle)
searchDomain, searchPort = getDomainFromActor(profileHandle) searchDomain, searchPort = getDomainFromActor(profileHandle)
else: else: