merge-requests/30/head
Bob Mottram 2020-03-22 20:36:19 +00:00
parent e5e6cad1b4
commit d0884fa04d
46 changed files with 1290 additions and 1126 deletions

View File

@ -507,9 +507,11 @@ def sendAnnounceViaServer(baseDir: str,session, \
authHeader=createBasicAuthHeader(fromNickname,password) authHeader=createBasicAuthHeader(fromNickname,password)
headers = {'host': fromDomain, \ headers={
'host': fromDomain, \
'Content-type': 'application/json', \ 'Content-type': 'application/json', \
'Authorization': authHeader} 'Authorization': authHeader
}
postResult= \ postResult= \
postJson(session,newAnnounceJson,[],inboxUrl,headers,"inbox:write") postJson(session,newAnnounceJson,[],inboxUrl,headers,"inbox:write")

View File

@ -103,7 +103,8 @@ def sendAvailabilityViaServer(baseDir: str,session, \
handle=httpPrefix+'://'+domainFull+'/@'+nickname handle=httpPrefix+'://'+domainFull+'/@'+nickname
# lookup the inbox for the To handle # lookup the inbox for the To handle
wfRequest = webfingerHandle(session,handle,httpPrefix,cachedWebfingers, \ wfRequest= \
webfingerHandle(session,handle,httpPrefix,cachedWebfingers, \
domain,projectVersion) domain,projectVersion)
if not wfRequest: if not wfRequest:
if debug: if debug:
@ -128,9 +129,11 @@ def sendAvailabilityViaServer(baseDir: str,session, \
authHeader=createBasicAuthHeader(Nickname,password) authHeader=createBasicAuthHeader(Nickname,password)
headers = {'host': domain, \ headers={
'host': domain, \
'Content-type': 'application/json', \ 'Content-type': 'application/json', \
'Authorization': authHeader} 'Authorization': authHeader
}
postResult= \ postResult= \
postJson(session,newAvailabilityJson,[],inboxUrl,headers,"inbox:write") postJson(session,newAvailabilityJson,[],inboxUrl,headers,"inbox:write")

View File

@ -189,7 +189,8 @@ def sendBlockViaServer(baseDir: str,session, \
handle=httpPrefix+'://'+fromDomainFull+'/@'+fromNickname handle=httpPrefix+'://'+fromDomainFull+'/@'+fromNickname
# lookup the inbox for the To handle # lookup the inbox for the To handle
wfRequest = webfingerHandle(session,handle,httpPrefix,cachedWebfingers, \ wfRequest= \
webfingerHandle(session,handle,httpPrefix,cachedWebfingers, \
fromDomain,projectVersion) fromDomain,projectVersion)
if not wfRequest: if not wfRequest:
if debug: if debug:
@ -215,9 +216,11 @@ def sendBlockViaServer(baseDir: str,session, \
authHeader=createBasicAuthHeader(fromNickname,password) authHeader=createBasicAuthHeader(fromNickname,password)
headers = {'host': fromDomain, \ headers={
'host': fromDomain, \
'Content-type': 'application/json', \ 'Content-type': 'application/json', \
'Authorization': authHeader} 'Authorization': authHeader
}
postResult= \ postResult= \
postJson(session,newBlockJson,[],inboxUrl,headers,"inbox:write") postJson(session,newBlockJson,[],inboxUrl,headers,"inbox:write")
@ -292,9 +295,11 @@ def sendUndoBlockViaServer(baseDir: str,session, \
authHeader=createBasicAuthHeader(fromNickname,password) authHeader=createBasicAuthHeader(fromNickname,password)
headers = {'host': fromDomain, \ headers={
'host': fromDomain, \
'Content-type': 'application/json', \ 'Content-type': 'application/json', \
'Authorization': authHeader} 'Authorization': authHeader
}
postResult= \ postResult= \
postJson(session,newBlockJson,[],inboxUrl,headers,"inbox:write") postJson(session,newBlockJson,[],inboxUrl,headers,"inbox:write")

View File

@ -155,7 +155,8 @@ def blurhash_decode(blurhash, width, height, punch = 1.0, linear = False):
for j in range(size_y): for j in range(size_y):
for i in range(size_x): for i in range(size_x):
basis = math.cos(math.pi * float(x) * float(i) / float(width)) * \ basis= \
math.cos(math.pi*float(x)*float(i)/float(width))* \
math.cos(math.pi*float(y)*float(j)/float(height)) math.cos(math.pi*float(y)*float(j)/float(height))
colour=colours[i+j*size_x] colour=colours[i+j*size_x]
pixel[0] += colour[0]*basis pixel[0] += colour[0]*basis
@ -213,7 +214,8 @@ def blurhash_encode(image, components_x = 4, components_y = 4, linear = False):
component=[0.0,0.0,0.0] component=[0.0,0.0,0.0]
for y in range(int(height)): for y in range(int(height)):
for x in range(int(width)): for x in range(int(width)):
basis = norm_factor * math.cos(math.pi * float(i) * float(x) / width) * \ basis= \
norm_factor * math.cos(math.pi * float(i) * float(x) / width) * \
math.cos(math.pi * float(j) * float(y) / height) math.cos(math.pi * float(j) * float(y) / height)
component[0] += basis * image_linear[y][x][0] component[0] += basis * image_linear[y][x][0]
component[1] += basis * image_linear[y][x][1] component[1] += basis * image_linear[y][x][1]
@ -225,15 +227,20 @@ def blurhash_encode(image, components_x = 4, components_y = 4, linear = False):
components.append(component) components.append(component)
if not (i==0 and j==0): if not (i==0 and j==0):
max_ac_component = max(max_ac_component, abs(component[0]), abs(component[1]), abs(component[2])) max_ac_component= \
max(max_ac_component,abs(component[0]), \
abs(component[1]),abs(component[2]))
# Encode components # Encode components
dc_value = (linear_to_srgb(components[0][0]) << 16) + \ dc_value= \
(linear_to_srgb(components[0][0]) << 16)+ \
(linear_to_srgb(components[0][1]) << 8)+ \ (linear_to_srgb(components[0][1]) << 8)+ \
linear_to_srgb(components[0][2]) linear_to_srgb(components[0][2])
quant_max_ac_component = int(max(0, min(82, math.floor(max_ac_component * 166 - 0.5)))) quant_max_ac_component= \
ac_component_norm_factor = float(quant_max_ac_component + 1) / 166.0 int(max(0, min(82, math.floor(max_ac_component * 166 - 0.5))))
ac_component_norm_factor= \
float(quant_max_ac_component+1) / 166.0
ac_values=[] ac_values=[]
for r, g, b in components[1:]: for r, g, b in components[1:]:

View File

@ -490,9 +490,11 @@ def sendBookmarkViaServer(baseDir: str,session, \
authHeader=createBasicAuthHeader(fromNickname,password) authHeader=createBasicAuthHeader(fromNickname,password)
headers = {'host': fromDomain, \ headers={
'host': fromDomain, \
'Content-type': 'application/json', \ 'Content-type': 'application/json', \
'Authorization': authHeader} 'Authorization': authHeader
}
postResult= \ postResult= \
postJson(session,newBookmarkJson,[],inboxUrl,headers,"inbox:write") postJson(session,newBookmarkJson,[],inboxUrl,headers,"inbox:write")
#if not postResult: #if not postResult:
@ -569,9 +571,11 @@ def sendUndoBookmarkViaServer(baseDir: str,session, \
authHeader=createBasicAuthHeader(fromNickname,password) authHeader=createBasicAuthHeader(fromNickname,password)
headers = {'host': fromDomain, \ headers={
'host': fromDomain, \
'Content-type': 'application/json', \ 'Content-type': 'application/json', \
'Authorization': authHeader} 'Authorization': authHeader
}
postResult= \ postResult= \
postJson(session,newUndoBookmarkJson,[],inboxUrl,headers,"inbox:write") postJson(session,newUndoBookmarkJson,[],inboxUrl,headers,"inbox:write")
#if not postResult: #if not postResult:

View File

@ -158,7 +158,8 @@ def addWebLinks(content: str) -> str:
def validHashTag(hashtag: str) -> bool: def validHashTag(hashtag: str) -> bool:
"""Returns true if the give hashtag contains valid characters """Returns true if the give hashtag contains valid characters
""" """
validChars = set('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') validChars= \
set('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
if set(hashtag).issubset(validChars): if set(hashtag).issubset(validChars):
return True return True
return False return False

View File

@ -116,7 +116,8 @@ def sendDeleteViaServer(baseDir: str,session, \
handle=httpPrefix+'://'+fromDomainFull+'/@'+fromNickname handle=httpPrefix+'://'+fromDomainFull+'/@'+fromNickname
# lookup the inbox for the To handle # lookup the inbox for the To handle
wfRequest = webfingerHandle(session,handle,httpPrefix,cachedWebfingers, \ wfRequest= \
webfingerHandle(session,handle,httpPrefix,cachedWebfingers, \
fromDomain,projectVersion) fromDomain,projectVersion)
if not wfRequest: if not wfRequest:
if debug: if debug:
@ -142,9 +143,11 @@ def sendDeleteViaServer(baseDir: str,session, \
authHeader=createBasicAuthHeader(fromNickname,password) authHeader=createBasicAuthHeader(fromNickname,password)
headers = {'host': fromDomain, \ headers={
'host': fromDomain, \
'Content-type': 'application/json', \ 'Content-type': 'application/json', \
'Authorization': authHeader} 'Authorization': authHeader
}
postResult= \ postResult= \
postJson(session,newDeleteJson,[],inboxUrl,headers,"inbox:write") postJson(session,newDeleteJson,[],inboxUrl,headers,"inbox:write")
#if not postResult: #if not postResult:

View File

@ -366,7 +366,9 @@ if args.postsraw:
if args.json: if args.json:
session=createSession(False) session=createSession(False)
asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'} asHeader={
'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
}
testJson=getJson(session,args.json,asHeader,None,__version__,httpPrefix,None) testJson=getJson(session,args.json,asHeader,None,__version__,httpPrefix,None)
pprint(testJson) pprint(testJson)
sys.exit() sys.exit()
@ -994,7 +996,9 @@ if args.actor:
else: else:
sys.exit() sys.exit()
asHeader = {'Accept': 'application/activity+json; profile="https://www.w3.org/ns/activitystreams"'} asHeader={
'Accept': 'application/activity+json; profile="https://www.w3.org/ns/activitystreams"'
}
if not personUrl: if not personUrl:
personUrl=getUserUrl(wfRequest) personUrl=getUserUrl(wfRequest)
if nickname==domain: if nickname==domain:
@ -1002,16 +1006,24 @@ if args.actor:
if not personUrl: if not personUrl:
# try single user instance # try single user instance
personUrl=httpPrefix+'://'+domain personUrl=httpPrefix+'://'+domain
asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'} asHeader={
'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
}
if '/channel/' in personUrl: if '/channel/' in personUrl:
asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'} asHeader={
'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
}
personJson = getJson(session,personUrl,asHeader,None,__version__,httpPrefix,None) personJson= \
getJson(session,personUrl,asHeader,None,__version__,httpPrefix,None)
if personJson: if personJson:
pprint(personJson) pprint(personJson)
else: else:
asHeader = {'Accept': 'application/jrd+json; profile="https://www.w3.org/ns/activitystreams"'} asHeader={
personJson = getJson(session,personUrl,asHeader,None,__version__,httpPrefix,None) 'Accept': 'application/jrd+json; profile="https://www.w3.org/ns/activitystreams"'
}
personJson= \
getJson(session,personUrl,asHeader,None,__version__,httpPrefix,None)
if personJson: if personJson:
pprint(personJson) pprint(personJson)
else: else:

View File

@ -320,7 +320,8 @@ def getFollowingFeed(baseDir: str,domain: str,port: int,path: str, \
'first': httpPrefix+'://'+domain+'/users/'+nickname+'/'+followFile+'?page=1', 'first': httpPrefix+'://'+domain+'/users/'+nickname+'/'+followFile+'?page=1',
'id': httpPrefix+'://'+domain+'/users/'+nickname+'/'+followFile, 'id': httpPrefix+'://'+domain+'/users/'+nickname+'/'+followFile,
'totalItems': getNoOfFollows(baseDir,nickname,domain,authenticated), 'totalItems': getNoOfFollows(baseDir,nickname,domain,authenticated),
'type': 'OrderedCollection'} 'type': 'OrderedCollection'
}
return following return following
if not pageNumber: if not pageNumber:
@ -333,7 +334,8 @@ def getFollowingFeed(baseDir: str,domain: str,port: int,path: str, \
'orderedItems': [], 'orderedItems': [],
'partOf': httpPrefix+'://'+domain+'/users/'+nickname+'/'+followFile, 'partOf': httpPrefix+'://'+domain+'/users/'+nickname+'/'+followFile,
'totalItems': 0, 'totalItems': 0,
'type': 'OrderedCollectionPage'} 'type': 'OrderedCollectionPage'
}
handleDomain=domain handleDomain=domain
if ':' in handleDomain: if ':' in handleDomain:
@ -825,7 +827,8 @@ def sendFollowRequestViaServer(baseDir: str,session, \
handle=httpPrefix+'://'+fromDomainFull+'/@'+fromNickname handle=httpPrefix+'://'+fromDomainFull+'/@'+fromNickname
# lookup the inbox for the To handle # lookup the inbox for the To handle
wfRequest = webfingerHandle(session,handle,httpPrefix,cachedWebfingers, \ wfRequest= \
webfingerHandle(session,handle,httpPrefix,cachedWebfingers, \
fromDomain,projectVersion) fromDomain,projectVersion)
if not wfRequest: if not wfRequest:
if debug: if debug:
@ -851,9 +854,11 @@ def sendFollowRequestViaServer(baseDir: str,session, \
authHeader=createBasicAuthHeader(fromNickname,password) authHeader=createBasicAuthHeader(fromNickname,password)
headers = {'host': fromDomain, \ headers={
'host': fromDomain, \
'Content-type': 'application/json', \ 'Content-type': 'application/json', \
'Authorization': authHeader} 'Authorization': authHeader
}
postResult= \ postResult= \
postJson(session,newFollowJson,[],inboxUrl,headers,"inbox:write") postJson(session,newFollowJson,[],inboxUrl,headers,"inbox:write")
#if not postResult: #if not postResult:
@ -910,7 +915,8 @@ def sendUnfollowRequestViaServer(baseDir: str,session, \
handle=httpPrefix+'://'+fromDomainFull+'/@'+fromNickname handle=httpPrefix+'://'+fromDomainFull+'/@'+fromNickname
# lookup the inbox for the To handle # lookup the inbox for the To handle
wfRequest = webfingerHandle(session,handle,httpPrefix,cachedWebfingers, \ wfRequest= \
webfingerHandle(session,handle,httpPrefix,cachedWebfingers, \
fromDomain,projectVersion) fromDomain,projectVersion)
if not wfRequest: if not wfRequest:
if debug: if debug:
@ -936,9 +942,11 @@ def sendUnfollowRequestViaServer(baseDir: str,session, \
authHeader=createBasicAuthHeader(fromNickname,password) authHeader=createBasicAuthHeader(fromNickname,password)
headers = {'host': fromDomain, \ headers={
'host': fromDomain, \
'Content-type': 'application/json', \ 'Content-type': 'application/json', \
'Authorization': authHeader} 'Authorization': authHeader
}
postResult= \ postResult= \
postJson(session,unfollowJson,[],inboxUrl,headers,"inbox:write") postJson(session,unfollowJson,[],inboxUrl,headers,"inbox:write")
#if not postResult: #if not postResult:

View File

@ -104,7 +104,9 @@ def createSignedHeader(privateKeyPem: str,nickname: str, \
dateStr=strftime("%a, %d %b %Y %H:%M:%S %Z", gmtime()) dateStr=strftime("%a, %d %b %Y %H:%M:%S %Z", gmtime())
if not withDigest: if not withDigest:
headers = {'(request-target)': f'post {path}','host': headerDomain,'date': dateStr} headers={
'(request-target)': f'post {path}','host': headerDomain,'date': dateStr
}
signatureHeader= \ signatureHeader= \
signPostHeaders(dateStr,privateKeyPem,nickname, \ signPostHeaders(dateStr,privateKeyPem,nickname, \
domain,port,toDomain,toPort, \ domain,port,toDomain,toPort, \
@ -119,7 +121,14 @@ def createSignedHeader(privateKeyPem: str,nickname: str, \
#print('***************************Send Content-type: '+contentType) #print('***************************Send Content-type: '+contentType)
#print('***************************Send Content-Length: '+str(len(messageBodyJsonStr))) #print('***************************Send Content-Length: '+str(len(messageBodyJsonStr)))
#print('***************************Send messageBodyJsonStr: '+messageBodyJsonStr) #print('***************************Send messageBodyJsonStr: '+messageBodyJsonStr)
headers = {'(request-target)': f'post {path}','host': headerDomain,'date': dateStr,'digest': f'SHA-256={bodyDigest}','content-length': str(contentLength),'content-type': contentType} headers={
'(request-target)': f'post {path}',
'host': headerDomain,
'date': dateStr,
'digest': f'SHA-256={bodyDigest}',
'content-length': str(contentLength),
'content-type': contentType
}
signatureHeader= \ signatureHeader= \
signPostHeaders(dateStr,privateKeyPem,nickname, \ signPostHeaders(dateStr,privateKeyPem,nickname, \
domain,port, \ domain,port, \

15
like.py
View File

@ -445,9 +445,11 @@ def sendLikeViaServer(baseDir: str,session, \
authHeader=createBasicAuthHeader(fromNickname,password) authHeader=createBasicAuthHeader(fromNickname,password)
headers = {'host': fromDomain, \ headers={
'host': fromDomain, \
'Content-type': 'application/json', \ 'Content-type': 'application/json', \
'Authorization': authHeader} 'Authorization': authHeader
}
postResult= \ postResult= \
postJson(session,newLikeJson,[],inboxUrl,headers,"inbox:write") postJson(session,newLikeJson,[],inboxUrl,headers,"inbox:write")
#if not postResult: #if not postResult:
@ -498,7 +500,8 @@ def sendUndoLikeViaServer(baseDir: str,session, \
handle=httpPrefix+'://'+fromDomainFull+'/@'+fromNickname handle=httpPrefix+'://'+fromDomainFull+'/@'+fromNickname
# lookup the inbox for the To handle # lookup the inbox for the To handle
wfRequest = webfingerHandle(session,handle,httpPrefix,cachedWebfingers, \ wfRequest= \
webfingerHandle(session,handle,httpPrefix,cachedWebfingers, \
fromDomain,projectVersion) fromDomain,projectVersion)
if not wfRequest: if not wfRequest:
if debug: if debug:
@ -524,9 +527,11 @@ def sendUndoLikeViaServer(baseDir: str,session, \
authHeader=createBasicAuthHeader(fromNickname,password) authHeader=createBasicAuthHeader(fromNickname,password)
headers = {'host': fromDomain, \ headers={
'host': fromDomain, \
'Content-type': 'application/json', \ 'Content-type': 'application/json', \
'Authorization': authHeader} 'Authorization': authHeader
}
postResult= \ postResult= \
postJson(session,newUndoLikeJson,[],inboxUrl,headers,"inbox:write") postJson(session,newUndoLikeJson,[],inboxUrl,headers,"inbox:write")
#if not postResult: #if not postResult:

View File

@ -61,7 +61,8 @@ def metaDataInstance(instanceTitle: str, \
instance={ instance={
'approval_required': False, 'approval_required': False,
'contact_account': {'acct': adminActor['preferredUsername'], 'contact_account': {
'acct': adminActor['preferredUsername'],
'avatar': adminActor['icon']['url'], 'avatar': adminActor['icon']['url'],
'avatar_static': adminActor['icon']['url'], 'avatar_static': adminActor['icon']['url'],
'bot': isBot, 'bot': isBot,

View File

@ -100,10 +100,13 @@ def setProfileImage(baseDir: str,httpPrefix :str,nickname: str,domain: str, \
personJson=loadJson(personFilename) personJson=loadJson(personFilename)
if personJson: if personJson:
personJson[iconFilenameBase]['mediaType']=mediaType personJson[iconFilenameBase]['mediaType']=mediaType
personJson[iconFilenameBase]['url']=httpPrefix+'://'+fullDomain+'/users/'+nickname+'/'+iconFilename personJson[iconFilenameBase]['url']= \
httpPrefix+'://'+fullDomain+'/users/'+nickname+'/'+iconFilename
saveJson(personJson,personFilename) saveJson(personJson,personFilename)
cmd = '/usr/bin/convert '+imageFilename+' -size '+resolution+' -quality 50 '+profileFilename cmd= \
'/usr/bin/convert '+imageFilename+' -size '+ \
resolution+' -quality 50 '+profileFilename
subprocess.call(cmd, shell=True) subprocess.call(cmd, shell=True)
removeMetaData(profileFilename,profileFilename) removeMetaData(profileFilename,profileFilename)
return True return True
@ -180,7 +183,8 @@ def createPersonBase(baseDir: str,nickname: str,domain: str,port: int, \
approveFollowers=True approveFollowers=True
personType='Application' personType='Application'
newPerson = {'@context': ['https://www.w3.org/ns/activitystreams', newPerson={
'@context': ['https://www.w3.org/ns/activitystreams',
'https://w3id.org/security/v1', 'https://w3id.org/security/v1',
{'Emoji': 'toot:Emoji', {'Emoji': 'toot:Emoji',
'Hashtag': 'as:Hashtag', 'Hashtag': 'as:Hashtag',
@ -207,13 +211,17 @@ def createPersonBase(baseDir: str,nickname: str,domain: str,port: int, \
'skills': {}, 'skills': {},
'roles': {}, 'roles': {},
'availability': None, 'availability': None,
'icon': {'mediaType': 'image/png', 'icon': {
'mediaType': 'image/png',
'type': 'Image', 'type': 'Image',
'url': personId+'/avatar'+str(randint(10000000000000,99999999999999))+'.png'}, 'url': personId+'/avatar'+str(randint(10000000000000,99999999999999))+'.png'
},
'id': personId, 'id': personId,
'image': {'mediaType': 'image/png', 'image': {
'mediaType': 'image/png',
'type': 'Image', 'type': 'Image',
'url': personId+'/image'+str(randint(10000000000000,99999999999999))+'.png'}, 'url': personId+'/image'+str(randint(10000000000000,99999999999999))+'.png'
},
'inbox': inboxStr, 'inbox': inboxStr,
'manuallyApprovesFollowers': approveFollowers, 'manuallyApprovesFollowers': approveFollowers,
'name': personName, 'name': personName,

View File

@ -165,7 +165,9 @@ def getPersonBox(baseDir: str,session,wfRequest: {},personCache: {}, \
projectVersion: str,httpPrefix: str, \ projectVersion: str,httpPrefix: str, \
nickname: str,domain: str, \ nickname: str,domain: str, \
boxName='inbox') -> (str,str,str,str,str,str,str,str): boxName='inbox') -> (str,str,str,str,str,str,str,str):
asHeader = {'Accept': 'application/activity+json; profile="https://www.w3.org/ns/activitystreams"'} asHeader={
'Accept': 'application/activity+json; profile="https://www.w3.org/ns/activitystreams"'
}
if not wfRequest.get('errors'): if not wfRequest.get('errors'):
personUrl=getUserUrl(wfRequest) personUrl=getUserUrl(wfRequest)
else: else:
@ -173,7 +175,9 @@ def getPersonBox(baseDir: str,session,wfRequest: {},personCache: {}, \
# try single user instance # try single user instance
print('getPersonBox: Trying single user instance with ld+json') print('getPersonBox: Trying single user instance with ld+json')
personUrl=httpPrefix+'://'+domain personUrl=httpPrefix+'://'+domain
asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'} asHeader={
'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
}
else: else:
personUrl=httpPrefix+'://'+domain+'/users/'+nickname personUrl=httpPrefix+'://'+domain+'/users/'+nickname
if not personUrl: if not personUrl:
@ -181,11 +185,15 @@ def getPersonBox(baseDir: str,session,wfRequest: {},personCache: {}, \
personJson=getPersonFromCache(baseDir,personUrl,personCache) personJson=getPersonFromCache(baseDir,personUrl,personCache)
if not personJson: if not personJson:
if '/channel/' in personUrl: if '/channel/' in personUrl:
asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'} asHeader={
'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
}
personJson=getJson(session,personUrl,asHeader,None, \ personJson=getJson(session,personUrl,asHeader,None, \
projectVersion,httpPrefix,domain) projectVersion,httpPrefix,domain)
if not personJson: if not personJson:
asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'} asHeader={
'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
}
personJson=getJson(session,personUrl,asHeader,None, \ personJson=getJson(session,personUrl,asHeader,None, \
projectVersion,httpPrefix,domain) projectVersion,httpPrefix,domain)
if not personJson: if not personJson:
@ -246,9 +254,13 @@ def getPosts(session,outboxUrl: str,maxPosts: int, \
personPosts={} personPosts={}
if not outboxUrl: if not outboxUrl:
return personPosts return personPosts
asHeader = {'Accept': 'application/activity+json; profile="https://www.w3.org/ns/activitystreams"'} asHeader={
'Accept': 'application/activity+json; profile="https://www.w3.org/ns/activitystreams"'
}
if '/outbox/' in outboxUrl: if '/outbox/' in outboxUrl:
asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'} asHeader={
'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
}
if raw: if raw:
result=[] result=[]
i=0 i=0
@ -1444,8 +1456,10 @@ def sendPostViaServer(projectVersion: str, \
authHeader=createBasicAuthHeader(fromNickname,password) authHeader=createBasicAuthHeader(fromNickname,password)
if attachImageFilename: if attachImageFilename:
headers = {'host': fromDomain, \ headers={
'Authorization': authHeader} 'host': fromDomain, \
'Authorization': authHeader
}
postResult= \ postResult= \
postImage(session,attachImageFilename,[], \ postImage(session,attachImageFilename,[], \
inboxUrl,headers,"inbox:write") inboxUrl,headers,"inbox:write")
@ -1454,9 +1468,11 @@ def sendPostViaServer(projectVersion: str, \
# print('DEBUG: Failed to upload image') # print('DEBUG: Failed to upload image')
# return 9 # return 9
headers = {'host': fromDomain, \ headers={
'host': fromDomain, \
'Content-type': 'application/json', \ 'Content-type': 'application/json', \
'Authorization': authHeader} 'Authorization': authHeader
}
postResult= \ postResult= \
postJsonString(session,json.dumps(postJsonObject),[], \ postJsonString(session,json.dumps(postJsonObject),[], \
inboxUrl,headers,"inbox:write",debug) inboxUrl,headers,"inbox:write",debug)
@ -1648,7 +1664,8 @@ def sendSignedJson(postJsonObject: {},session,baseDir: str, \
if debug: if debug:
print('DEBUG: starting thread to send post') print('DEBUG: starting thread to send post')
pprint(postJsonObject) pprint(postJsonObject)
thr = threadWithTrace(target=threadSendPost, \ thr= \
threadWithTrace(target=threadSendPost, \
args=(session, \ args=(session, \
postJsonStr, \ postJsonStr, \
federationList, \ federationList, \
@ -2042,18 +2059,22 @@ def createModeration(baseDir: str,nickname: str,domain: str,port: int, \
pageNumber=1 pageNumber=1
pageStr='?page='+str(pageNumber) pageStr='?page='+str(pageNumber)
boxHeader = {'@context': 'https://www.w3.org/ns/activitystreams', boxHeader={
'@context': 'https://www.w3.org/ns/activitystreams',
'first': httpPrefix+'://'+domain+'/users/'+nickname+'/'+boxname+'?page=true', 'first': httpPrefix+'://'+domain+'/users/'+nickname+'/'+boxname+'?page=true',
'id': httpPrefix+'://'+domain+'/users/'+nickname+'/'+boxname, 'id': httpPrefix+'://'+domain+'/users/'+nickname+'/'+boxname,
'last': httpPrefix+'://'+domain+'/users/'+nickname+'/'+boxname+'?page=true', 'last': httpPrefix+'://'+domain+'/users/'+nickname+'/'+boxname+'?page=true',
'totalItems': 0, 'totalItems': 0,
'type': 'OrderedCollection'} 'type': 'OrderedCollection'
boxItems = {'@context': 'https://www.w3.org/ns/activitystreams', }
boxItems={
'@context': 'https://www.w3.org/ns/activitystreams',
'id': httpPrefix+'://'+domain+'/users/'+nickname+'/'+boxname+pageStr, 'id': httpPrefix+'://'+domain+'/users/'+nickname+'/'+boxname+pageStr,
'orderedItems': [ 'orderedItems': [
], ],
'partOf': httpPrefix+'://'+domain+'/users/'+nickname+'/'+boxname, 'partOf': httpPrefix+'://'+domain+'/users/'+nickname+'/'+boxname,
'type': 'OrderedCollectionPage'} 'type': 'OrderedCollectionPage'
}
if isModerator(baseDir,nickname): if isModerator(baseDir,nickname):
moderationIndexFile=baseDir+'/accounts/moderation.txt' moderationIndexFile=baseDir+'/accounts/moderation.txt'
@ -2365,18 +2386,22 @@ def createBoxIndexed(recentPostsCache: {}, \
pageStr='?page='+str(pageNumber) pageStr='?page='+str(pageNumber)
except: except:
pass pass
boxHeader = {'@context': 'https://www.w3.org/ns/activitystreams', boxHeader={
'@context': 'https://www.w3.org/ns/activitystreams',
'first': httpPrefix+'://'+domain+'/users/'+nickname+'/'+boxname+'?page=true', 'first': httpPrefix+'://'+domain+'/users/'+nickname+'/'+boxname+'?page=true',
'id': httpPrefix+'://'+domain+'/users/'+nickname+'/'+boxname, 'id': httpPrefix+'://'+domain+'/users/'+nickname+'/'+boxname,
'last': httpPrefix+'://'+domain+'/users/'+nickname+'/'+boxname+'?page=true', 'last': httpPrefix+'://'+domain+'/users/'+nickname+'/'+boxname+'?page=true',
'totalItems': 0, 'totalItems': 0,
'type': 'OrderedCollection'} 'type': 'OrderedCollection'
boxItems = {'@context': 'https://www.w3.org/ns/activitystreams', }
boxItems={
'@context': 'https://www.w3.org/ns/activitystreams',
'id': httpPrefix+'://'+domain+'/users/'+nickname+'/'+boxname+pageStr, 'id': httpPrefix+'://'+domain+'/users/'+nickname+'/'+boxname+pageStr,
'orderedItems': [ 'orderedItems': [
], ],
'partOf': httpPrefix+'://'+domain+'/users/'+nickname+'/'+boxname, 'partOf': httpPrefix+'://'+domain+'/users/'+nickname+'/'+boxname,
'type': 'OrderedCollectionPage'} 'type': 'OrderedCollectionPage'
}
postsInBox=[] postsInBox=[]

View File

@ -229,8 +229,11 @@ def sendRoleViaServer(baseDir: str,session, \
if ':' not in delegatorDomain: if ':' not in delegatorDomain:
delegatorDomainFull=delegatorDomain+':'+str(fromPort) delegatorDomainFull=delegatorDomain+':'+str(fromPort)
toUrl = httpPrefix+'://'+delegatorDomainFull+'/users/'+nickname toUrl= \
ccUrl = httpPrefix+'://'+delegatorDomainFull+'/users/'+delegatorNickname+'/followers' httpPrefix+'://'+delegatorDomainFull+'/users/'+nickname
ccUrl= \
httpPrefix+'://'+delegatorDomainFull+'/users/'+ \
delegatorNickname+'/followers'
if role: if role:
roleStr=project.lower()+';'+role.lower() roleStr=project.lower()+';'+role.lower()
@ -279,9 +282,11 @@ def sendRoleViaServer(baseDir: str,session, \
authHeader=createBasicAuthHeader(delegatorNickname,password) authHeader=createBasicAuthHeader(delegatorNickname,password)
headers = {'host': delegatorDomain, \ headers={
'host': delegatorDomain, \
'Content-type': 'application/json', \ 'Content-type': 'application/json', \
'Authorization': authHeader} 'Authorization': authHeader
}
postResult= \ postResult= \
postJson(session,newRoleJson,[],inboxUrl,headers,"inbox:write") postJson(session,newRoleJson,[],inboxUrl,headers,"inbox:write")
#if not postResult: #if not postResult:

View File

@ -94,7 +94,8 @@ def postJsonString(session,postJsonStr: str, \
print('postJson: '+inboxUrl+' not permitted by capabilities') print('postJson: '+inboxUrl+' not permitted by capabilities')
return None,None return None,None
postResult = session.post(url = inboxUrl, data = postJsonStr, headers=headers) postResult= \
session.post(url=inboxUrl,data=postJsonStr,headers=headers)
if postResult.status_code<200 or postResult.status_code>202: if postResult.status_code<200 or postResult.status_code>202:
#if postResult.status_code==400: #if postResult.status_code==400:
# headers['content-type']='application/ld+json' # headers['content-type']='application/ld+json'

View File

@ -266,7 +266,8 @@ def getSharesFeedForPerson(baseDir: str, \
'first': httpPrefix+'://'+domain+'/users/'+nickname+'/shares?page=1', 'first': httpPrefix+'://'+domain+'/users/'+nickname+'/shares?page=1',
'id': httpPrefix+'://'+domain+'/users/'+nickname+'/shares', 'id': httpPrefix+'://'+domain+'/users/'+nickname+'/shares',
'totalItems': str(noOfShares), 'totalItems': str(noOfShares),
'type': 'OrderedCollection'} 'type': 'OrderedCollection'
}
return shares return shares
if not pageNumber: if not pageNumber:
@ -279,7 +280,8 @@ def getSharesFeedForPerson(baseDir: str, \
'orderedItems': [], 'orderedItems': [],
'partOf': httpPrefix+'://'+domain+'/users/'+nickname+'/shares', 'partOf': httpPrefix+'://'+domain+'/users/'+nickname+'/shares',
'totalItems': 0, 'totalItems': 0,
'type': 'OrderedCollectionPage'} 'type': 'OrderedCollectionPage'
}
if not os.path.isfile(sharesFilename): if not os.path.isfile(sharesFilename):
print("test5") print("test5")
@ -385,14 +387,18 @@ def sendShareViaServer(baseDir,session, \
authHeader=createBasicAuthHeader(fromNickname,password) authHeader=createBasicAuthHeader(fromNickname,password)
if imageFilename: if imageFilename:
headers = {'host': fromDomain, \ headers={
'Authorization': authHeader} 'host': fromDomain, \
'Authorization': authHeader
}
postResult= \ postResult= \
postImage(session,imageFilename,[],inboxUrl.replace('/'+postToBox,'/shares'),headers,"inbox:write") postImage(session,imageFilename,[],inboxUrl.replace('/'+postToBox,'/shares'),headers,"inbox:write")
headers = {'host': fromDomain, \ headers={
'host': fromDomain, \
'Content-type': 'application/json', \ 'Content-type': 'application/json', \
'Authorization': authHeader} 'Authorization': authHeader
}
postResult= \ postResult= \
postJson(session,newShareJson,[],inboxUrl,headers,"inbox:write") postJson(session,newShareJson,[],inboxUrl,headers,"inbox:write")
#if not postResult: #if not postResult:
@ -471,9 +477,11 @@ def sendUndoShareViaServer(baseDir: str,session, \
authHeader=createBasicAuthHeader(fromNickname,password) authHeader=createBasicAuthHeader(fromNickname,password)
headers = {'host': fromDomain, \ headers={
'host': fromDomain, \
'Content-type': 'application/json', \ 'Content-type': 'application/json', \
'Authorization': authHeader} 'Authorization': authHeader
}
postResult= \ postResult= \
postJson(session,undoShareJson,[],inboxUrl,headers,"inbox:write") postJson(session,undoShareJson,[],inboxUrl,headers,"inbox:write")
#if not postResult: #if not postResult:

View File

@ -152,9 +152,11 @@ def sendSkillViaServer(baseDir: str,session,nickname: str,password: str,
authHeader=createBasicAuthHeader(Nickname,password) authHeader=createBasicAuthHeader(Nickname,password)
headers = {'host': domain, \ headers={
'host': domain, \
'Content-type': 'application/json', \ 'Content-type': 'application/json', \
'Authorization': authHeader} 'Authorization': authHeader
}
postResult= \ postResult= \
postJson(session,newSkillJson,[],inboxUrl,headers,"inbox:write") postJson(session,newSkillJson,[],inboxUrl,headers,"inbox:write")
#if not postResult: #if not postResult:

View File

@ -103,7 +103,11 @@ def testHttpsigBase(withDigest):
privateKeyPem,publicKeyPem,person,wfEndpoint= \ privateKeyPem,publicKeyPem,person,wfEndpoint= \
createPerson(path,nickname,domain,port,httpPrefix,False,password) createPerson(path,nickname,domain,port,httpPrefix,False,password)
assert privateKeyPem assert privateKeyPem
messageBodyJson = {"a key": "a value", "another key": "A string","yet another key": "Another string"} messageBodyJson={
"a key": "a value",
"another key": "A string",
"yet another key": "Another string"
}
messageBodyJsonStr=json.dumps(messageBodyJson) messageBodyJsonStr=json.dumps(messageBodyJson)
headersDomain=domain headersDomain=domain
@ -115,7 +119,11 @@ def testHttpsigBase(withDigest):
dateStr=strftime("%a, %d %b %Y %H:%M:%S %Z", gmtime()) dateStr=strftime("%a, %d %b %Y %H:%M:%S %Z", gmtime())
boxpath='/inbox' boxpath='/inbox'
if not withDigest: if not withDigest:
headers = {'host': headersDomain,'date': dateStr,'content-type': 'application/json'} headers={
'host': headersDomain,
'date': dateStr,
'content-type': 'application/json'
}
signatureHeader= \ signatureHeader= \
signPostHeaders(dateStr,privateKeyPem, nickname, \ signPostHeaders(dateStr,privateKeyPem, nickname, \
domain, port, \ domain, port, \
@ -124,7 +132,13 @@ def testHttpsigBase(withDigest):
else: else:
bodyDigest=messageContentDigest(messageBodyJsonStr) bodyDigest=messageContentDigest(messageBodyJsonStr)
contentLength=len(messageBodyJsonStr) contentLength=len(messageBodyJsonStr)
headers = {'host': headersDomain,'date': dateStr,'digest': f'SHA-256={bodyDigest}','content-type': contentType,'content-length': str(contentLength)} headers={
'host': headersDomain,
'date': dateStr,
'digest': f'SHA-256={bodyDigest}',
'content-type': contentType,
'content-length': str(contentLength)
}
signatureHeader= \ signatureHeader= \
signPostHeaders(dateStr,privateKeyPem, nickname, \ signPostHeaders(dateStr,privateKeyPem, nickname, \
domain, port, \ domain, port, \
@ -149,13 +163,23 @@ def testHttpsigBase(withDigest):
messageBodyJsonStr,False) == False messageBodyJsonStr,False) == False
if not withDigest: if not withDigest:
# fake domain # fake domain
headers = {'host': 'bogon.domain','date': dateStr,'content-type': 'application/json'} headers={
'host': 'bogon.domain',
'date': dateStr,
'content-type': 'application/json'
}
else: else:
# correct domain but fake message # correct domain but fake message
messageBodyJsonStr='{"a key": "a value", "another key": "Fake GNUs", "yet another key": "More Fake GNUs"}' messageBodyJsonStr='{"a key": "a value", "another key": "Fake GNUs", "yet another key": "More Fake GNUs"}'
contentLength=len(messageBodyJsonStr) contentLength=len(messageBodyJsonStr)
bodyDigest=messageContentDigest(messageBodyJsonStr) bodyDigest=messageContentDigest(messageBodyJsonStr)
headers = {'host': domain,'date': dateStr,'digest': f'SHA-256={bodyDigest}','content-type': contentType,'content-length': str(contentLength)} headers={
'host': domain,
'date': dateStr,
'digest': f'SHA-256={bodyDigest}',
'content-type': contentType,
'content-length': str(contentLength)
}
headers['signature']=signatureHeader headers['signature']=signatureHeader
assert verifyPostHeaders(httpPrefix,publicKeyPem,headers, \ assert verifyPostHeaders(httpPrefix,publicKeyPem,headers, \
boxpath,True,None, \ boxpath,True,None, \
@ -184,7 +208,8 @@ def testThreadsFunction(param: str):
def testThreads(): def testThreads():
print('testThreads') print('testThreads')
thr = threadWithTrace(target=testThreadsFunction,args=('test',),daemon=True) thr= \
threadWithTrace(target=testThreadsFunction,args=('test',),daemon=True)
thr.start() thr.start()
assert thr.isAlive()==True assert thr.isAlive()==True
time.sleep(1) time.sleep(1)

View File

@ -198,17 +198,21 @@ def getDomainFromActor(actor: str) -> (str,int):
""" """
port=None port=None
if '/profile/' in actor: if '/profile/' in actor:
domain = actor.split('/profile/')[0].replace('https://','').replace('http://','').replace('i2p://','').replace('dat://','') domain= \
actor.split('/profile/')[0].replace('https://','').replace('http://','').replace('i2p://','').replace('dat://','')
else: else:
if '/channel/' in actor: if '/channel/' in actor:
domain = actor.split('/channel/')[0].replace('https://','').replace('http://','').replace('i2p://','').replace('dat://','') domain= \
actor.split('/channel/')[0].replace('https://','').replace('http://','').replace('i2p://','').replace('dat://','')
else: else:
if '/users/' not in actor: if '/users/' not in actor:
domain = actor.replace('https://','').replace('http://','').replace('i2p://','').replace('dat://','') domain= \
actor.replace('https://','').replace('http://','').replace('i2p://','').replace('dat://','')
if '/' in actor: if '/' in actor:
domain=domain.split('/')[0] domain=domain.split('/')[0]
else: else:
domain = actor.split('/users/')[0].replace('https://','').replace('http://','').replace('i2p://','').replace('dat://','') domain= \
actor.split('/users/')[0].replace('https://','').replace('http://','').replace('i2p://','').replace('dat://','')
if ':' in domain: if ':' in domain:
portStr=domain.split(':')[1] portStr=domain.split(':')[1]
if not portStr.isdigit(): if not portStr.isdigit():

View File

@ -62,8 +62,12 @@ def webfingerHandle(session,handle: str,httpPrefix: str,cachedWebfingers: {}, \
if wf: if wf:
return wf return wf
url='{}://{}/.well-known/webfinger'.format(httpPrefix,domain) url='{}://{}/.well-known/webfinger'.format(httpPrefix,domain)
par = {'resource': 'acct:{}'.format(nickname+'@'+wfDomain)} par={
hdr = {'Accept': 'application/jrd+json'} 'resource': 'acct:{}'.format(nickname+'@'+wfDomain)
}
hdr={
'Accept': 'application/jrd+json'
}
try: try:
result=getJson(session,url,hdr,par,projectVersion,httpPrefix,fromDomain) result=getJson(session,url,hdr,par,projectVersion,httpPrefix,fromDomain)
except Exception as e: except Exception as e:

View File

@ -81,17 +81,25 @@ def updateAvatarImageCache(session,baseDir: str,httpPrefix: str, \
actorStr=actor.replace('/','-') actorStr=actor.replace('/','-')
avatarImagePath=baseDir+'/cache/avatars/'+actorStr avatarImagePath=baseDir+'/cache/avatars/'+actorStr
if avatarUrl.endswith('.png') or '.png?' in avatarUrl: if avatarUrl.endswith('.png') or '.png?' in avatarUrl:
sessionHeaders = {'Accept': 'image/png'} sessionHeaders={
'Accept': 'image/png'
}
avatarImageFilename=avatarImagePath+'.png' avatarImageFilename=avatarImagePath+'.png'
elif avatarUrl.endswith('.jpg') or avatarUrl.endswith('.jpeg') or \ elif avatarUrl.endswith('.jpg') or avatarUrl.endswith('.jpeg') or \
'.jpg?' in avatarUrl or '.jpeg?' in avatarUrl: '.jpg?' in avatarUrl or '.jpeg?' in avatarUrl:
sessionHeaders = {'Accept': 'image/jpeg'} sessionHeaders={
'Accept': 'image/jpeg'
}
avatarImageFilename=avatarImagePath+'.jpg' avatarImageFilename=avatarImagePath+'.jpg'
elif avatarUrl.endswith('.gif') or '.gif?' in avatarUrl: elif avatarUrl.endswith('.gif') or '.gif?' in avatarUrl:
sessionHeaders = {'Accept': 'image/gif'} sessionHeaders={
'Accept': 'image/gif'
}
avatarImageFilename=avatarImagePath+'.gif' avatarImageFilename=avatarImagePath+'.gif'
elif avatarUrl.endswith('.webp') or '.webp?' in avatarUrl: elif avatarUrl.endswith('.webp') or '.webp?' in avatarUrl:
sessionHeaders = {'Accept': 'image/webp'} sessionHeaders={
'Accept': 'image/webp'
}
avatarImageFilename=avatarImagePath+'.webp' avatarImageFilename=avatarImagePath+'.webp'
else: else:
return None return None
@ -556,7 +564,9 @@ def htmlSkillsSearch(translate: {},baseDir: str, \
actor=actorJson['id'] actor=actorJson['id']
for skillName,skillLevel in actorJson['skills'].items(): for skillName,skillLevel in actorJson['skills'].items():
skillName=skillName.lower() skillName=skillName.lower()
if skillName in skillsearch or skillsearch in skillName: if not (skillName in skillsearch or \
skillsearch in skillName):
continue
skillLevelStr=str(skillLevel) skillLevelStr=str(skillLevel)
if skillLevel<100: if skillLevel<100:
skillLevelStr='0'+skillLevelStr skillLevelStr='0'+skillLevelStr
@ -589,7 +599,9 @@ def htmlSkillsSearch(translate: {},baseDir: str, \
actor=actorJson['id'] actor=actorJson['id']
for skillName,skillLevel in actorJson['skills'].items(): for skillName,skillLevel in actorJson['skills'].items():
skillName=skillName.lower() skillName=skillName.lower()
if skillName in skillsearch or skillsearch in skillName: if not (skillName in skillsearch or \
skillsearch in skillName):
continue
skillLevelStr=str(skillLevel) skillLevelStr=str(skillLevel)
if skillLevel<100: if skillLevel<100:
skillLevelStr='0'+skillLevelStr skillLevelStr='0'+skillLevelStr
@ -622,14 +634,17 @@ def htmlSkillsSearch(translate: {},baseDir: str, \
ctr=0 ctr=0
for skillMatch in results: for skillMatch in results:
skillMatchFields=skillMatch.split(';') skillMatchFields=skillMatch.split(';')
if len(skillMatchFields)==4: if len(skillMatchFields)!=4:
continue
actor=skillMatchFields[1] actor=skillMatchFields[1]
actorName=skillMatchFields[2] actorName=skillMatchFields[2]
avatarUrl=skillMatchFields[3] avatarUrl=skillMatchFields[3]
skillSearchForm+='<div class="search-result""><a href="'+actor+'/skills">' skillSearchForm+= \
'<div class="search-result""><a href="'+actor+'/skills">'
skillSearchForm+= \ skillSearchForm+= \
'<img loading="lazy" src="'+avatarUrl+ \ '<img loading="lazy" src="'+avatarUrl+ \
'"/><span class="search-result-text">'+actorName+'</span></a></div>' '"/><span class="search-result-text">'+actorName+ \
'</span></a></div>'
ctr+=1 ctr+=1
if ctr>=postsPerPage: if ctr>=postsPerPage:
break break
@ -640,7 +655,8 @@ def htmlSkillsSearch(translate: {},baseDir: str, \
def scheduledPostsExist(baseDir: str,nickname: str,domain: str) -> bool: def scheduledPostsExist(baseDir: str,nickname: str,domain: str) -> bool:
"""Returns true if there are posts scheduled to be delivered """Returns true if there are posts scheduled to be delivered
""" """
scheduleIndexFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/schedule.index' scheduleIndexFilename= \
baseDir+'/accounts/'+nickname+'@'+domain+'/schedule.index'
if not os.path.isfile(scheduleIndexFilename): if not os.path.isfile(scheduleIndexFilename):
return False return False
if '#users#' in open(scheduleIndexFilename).read(): if '#users#' in open(scheduleIndexFilename).read():
@ -653,7 +669,8 @@ def htmlEditProfile(translate: {},baseDir: str,path: str, \
""" """
imageFormats='.png, .jpg, .jpeg, .gif, .webp' imageFormats='.png, .jpg, .jpeg, .gif, .webp'
pathOriginal=path pathOriginal=path
path=path.replace('/inbox','').replace('/outbox','').replace('/shares','') path= \
path.replace('/inbox','').replace('/outbox','').replace('/shares','')
nickname=getNicknameFromActor(path) nickname=getNicknameFromActor(path)
if not nickname: if not nickname:
return '' return ''
@ -730,13 +747,15 @@ def htmlEditProfile(translate: {},baseDir: str,path: str, \
switchStr=switchfile.read() switchStr=switchfile.read()
blockedStr='' blockedStr=''
blockedFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/blocking.txt' blockedFilename= \
baseDir+'/accounts/'+nickname+'@'+domain+'/blocking.txt'
if os.path.isfile(blockedFilename): if os.path.isfile(blockedFilename):
with open(blockedFilename, 'r') as blockedfile: with open(blockedFilename, 'r') as blockedfile:
blockedStr=blockedfile.read() blockedStr=blockedfile.read()
allowedInstancesStr='' allowedInstancesStr=''
allowedInstancesFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/allowedinstances.txt' allowedInstancesFilename= \
baseDir+'/accounts/'+nickname+'@'+domain+'/allowedinstances.txt'
if os.path.isfile(allowedInstancesFilename): if os.path.isfile(allowedInstancesFilename):
with open(allowedInstancesFilename, 'r') as allowedInstancesFile: with open(allowedInstancesFilename, 'r') as allowedInstancesFile:
allowedInstancesStr=allowedInstancesFile.read() allowedInstancesStr=allowedInstancesFile.read()
@ -928,7 +947,8 @@ def htmlEditProfile(translate: {},baseDir: str,path: str, \
editProfileForm+=htmlFooter() editProfileForm+=htmlFooter()
return editProfileForm return editProfileForm
def htmlGetLoginCredentials(loginParams: str,lastLoginTime: int) -> (str,str,bool): def htmlGetLoginCredentials(loginParams: str, \
lastLoginTime: int) -> (str,str,bool):
"""Receives login credentials via HTTPServer POST """Receives login credentials via HTTPServer POST
""" """
if not loginParams.startswith('username='): if not loginParams.startswith('username='):
@ -4984,7 +5004,9 @@ def htmlProfileAfterSearch(recentPostsCache: {},maxRecentPosts: int, \
personUrl=getUserUrl(wf) personUrl=getUserUrl(wf)
if not personUrl: if not personUrl:
# try single user instance # try single user instance
asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'} asHeader={
'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
}
personUrl=httpPrefix+'://'+searchDomainFull personUrl=httpPrefix+'://'+searchDomainFull
profileJson=getJson(session,personUrl,asHeader,None,projectVersion,httpPrefix,domain) profileJson=getJson(session,personUrl,asHeader,None,projectVersion,httpPrefix,domain)
if not profileJson: if not profileJson: