Mastodon-style user agent

master
Bob Mottram 2019-08-14 21:12:27 +01:00
parent 89136958b9
commit ef89dda935
18 changed files with 326 additions and 185 deletions

View File

@ -173,7 +173,7 @@ def createAnnounce(session,baseDir: str,federationList: [], \
clientToServer: bool, \ clientToServer: bool, \
sendThreads: [],postLog: [], \ sendThreads: [],postLog: [], \
personCache: {},cachedWebfingers: {}, \ personCache: {},cachedWebfingers: {}, \
debug: bool) -> {}: debug: bool,projectVersion: str) -> {}:
"""Creates an announce message """Creates an announce message
Typically toUrl will be https://www.w3.org/ns/activitystreams#Public Typically toUrl will be https://www.w3.org/ns/activitystreams#Public
and ccUrl might be a specific person favorited or repeated and the and ccUrl might be a specific person favorited or repeated and the
@ -224,7 +224,8 @@ def createAnnounce(session,baseDir: str,federationList: [], \
announceNickname,announceDomain,announcePort, \ announceNickname,announceDomain,announcePort, \
'https://www.w3.org/ns/activitystreams#Public', \ 'https://www.w3.org/ns/activitystreams#Public', \
httpPrefix,True,clientToServer,federationList, \ httpPrefix,True,clientToServer,federationList, \
sendThreads,postLog,cachedWebfingers,personCache,debug) sendThreads,postLog,cachedWebfingers,personCache, \
debug,projectVersion)
return newAnnounce return newAnnounce
@ -233,7 +234,7 @@ def announcePublic(session,baseDir: str,federationList: [], \
objectUrl: str,clientToServer: bool, \ objectUrl: str,clientToServer: bool, \
sendThreads: [],postLog: [], \ sendThreads: [],postLog: [], \
personCache: {},cachedWebfingers: {}, \ personCache: {},cachedWebfingers: {}, \
debug: bool) -> {}: debug: bool,projectVersion: str) -> {}:
"""Makes a public announcement """Makes a public announcement
""" """
fromDomain=domain fromDomain=domain
@ -249,7 +250,7 @@ def announcePublic(session,baseDir: str,federationList: [], \
objectUrl,True,clientToServer, \ objectUrl,True,clientToServer, \
sendThreads,postLog, \ sendThreads,postLog, \
personCache,cachedWebfingers, \ personCache,cachedWebfingers, \
debug) debug,projectVersion)
def repeatPost(session,baseDir: str,federationList: [], \ def repeatPost(session,baseDir: str,federationList: [], \
nickname: str, domain: str, port: int, httpPrefix: str, \ nickname: str, domain: str, port: int, httpPrefix: str, \
@ -258,7 +259,7 @@ def repeatPost(session,baseDir: str,federationList: [], \
announceStatusNumber: int,clientToServer: bool, \ announceStatusNumber: int,clientToServer: bool, \
sendThreads: [],postLog: [], \ sendThreads: [],postLog: [], \
personCache: {},cachedWebfingers: {}, \ personCache: {},cachedWebfingers: {}, \
debug: bool) -> {}: debug: bool,projectVersion: str) -> {}:
"""Repeats a given status post """Repeats a given status post
""" """
announcedDomain=announceDomain announcedDomain=announceDomain
@ -274,7 +275,7 @@ def repeatPost(session,baseDir: str,federationList: [], \
objectUrl,clientToServer, \ objectUrl,clientToServer, \
sendThreads,postLog, \ sendThreads,postLog, \
personCache,cachedWebfingers, \ personCache,cachedWebfingers, \
debug) debug,projectVersion)
def undoAnnounce(session,baseDir: str,federationList: [], \ def undoAnnounce(session,baseDir: str,federationList: [], \
nickname: str, domain: str, port: int, \ nickname: str, domain: str, port: int, \
@ -385,7 +386,7 @@ def sendAnnounceViaServer(session,fromNickname: str,password: str,
fromDomain: str,fromPort: int, \ fromDomain: str,fromPort: int, \
httpPrefix: str,repeatObjectUrl: str, \ httpPrefix: str,repeatObjectUrl: str, \
cachedWebfingers: {},personCache: {}, \ cachedWebfingers: {},personCache: {}, \
debug: bool) -> {}: debug: bool,projectVersion: str) -> {}:
"""Creates an announce message via c2s """Creates an announce message via c2s
""" """
if not session: if not session:
@ -418,7 +419,9 @@ def sendAnnounceViaServer(session,fromNickname: str,password: str,
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)
if not wfRequest: if not wfRequest:
if debug: if debug:
print('DEBUG: announce webfinger failed for '+handle) print('DEBUG: announce webfinger failed for '+handle)
@ -428,7 +431,8 @@ def sendAnnounceViaServer(session,fromNickname: str,password: str,
# get the actor inbox for the To handle # get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \ inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \
getPersonBox(session,wfRequest,personCache,postToBox) getPersonBox(session,wfRequest,personCache, \
projectVersion,httpPrefix,fromDomain,postToBox)
if not inboxUrl: if not inboxUrl:
if debug: if debug:

View File

@ -73,7 +73,7 @@ def sendAvailabilityViaServer(session,nickname: str,password: str,
httpPrefix: str, \ httpPrefix: str, \
status: str, \ status: str, \
cachedWebfingers: {},personCache: {}, \ cachedWebfingers: {},personCache: {}, \
debug: bool) -> {}: debug: bool,projectVersion: str) -> {}:
"""Sets the availability for a person via c2s """Sets the availability for a person via c2s
""" """
if not session: if not session:
@ -98,7 +98,8 @@ def sendAvailabilityViaServer(session,nickname: str,password: str,
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)
if not wfRequest: if not wfRequest:
if debug: if debug:
print('DEBUG: announce webfinger failed for '+handle) print('DEBUG: announce webfinger failed for '+handle)
@ -108,7 +109,8 @@ def sendAvailabilityViaServer(session,nickname: str,password: str,
# get the actor inbox for the To handle # get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \ inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \
getPersonBox(session,wfRequest,personCache,postToBox) getPersonBox(session,wfRequest,personCache, \
projectVersion,httpPrefix,domain,postToBox)
if not inboxUrl: if not inboxUrl:
if debug: if debug:

View File

@ -140,7 +140,7 @@ def sendBlockViaServer(session,fromNickname: str,password: str,
fromDomain: str,fromPort: int, \ fromDomain: str,fromPort: int, \
httpPrefix: str,blockedUrl: str, \ httpPrefix: str,blockedUrl: str, \
cachedWebfingers: {},personCache: {}, \ cachedWebfingers: {},personCache: {}, \
debug: bool) -> {}: debug: bool,projectVersion: str) -> {}:
"""Creates a block via c2s """Creates a block via c2s
""" """
if not session: if not session:
@ -166,7 +166,8 @@ def sendBlockViaServer(session,fromNickname: str,password: str,
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)
if not wfRequest: if not wfRequest:
if debug: if debug:
print('DEBUG: announce webfinger failed for '+handle) print('DEBUG: announce webfinger failed for '+handle)
@ -176,7 +177,8 @@ def sendBlockViaServer(session,fromNickname: str,password: str,
# get the actor inbox for the To handle # get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \ inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \
getPersonBox(session,wfRequest,personCache,postToBox) getPersonBox(session,wfRequest,personCache, \
projectVersion,httpPrefix,fromDomain,postToBox)
if not inboxUrl: if not inboxUrl:
if debug: if debug:
@ -208,7 +210,7 @@ def sendUndoBlockViaServer(session,fromNickname: str,password: str,
fromDomain: str,fromPort: int, \ fromDomain: str,fromPort: int, \
httpPrefix: str,blockedUrl: str, \ httpPrefix: str,blockedUrl: str, \
cachedWebfingers: {},personCache: {}, \ cachedWebfingers: {},personCache: {}, \
debug: bool) -> {}: debug: bool,projectVersion: str) -> {}:
"""Creates a block via c2s """Creates a block via c2s
""" """
if not session: if not session:
@ -238,7 +240,8 @@ def sendUndoBlockViaServer(session,fromNickname: str,password: str,
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)
if not wfRequest: if not wfRequest:
if debug: if debug:
print('DEBUG: announce webfinger failed for '+handle) print('DEBUG: announce webfinger failed for '+handle)
@ -248,7 +251,8 @@ def sendUndoBlockViaServer(session,fromNickname: str,password: str,
# get the actor inbox for the To handle # get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \ inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \
getPersonBox(session,wfRequest,personCache,postToBox) getPersonBox(session,wfRequest,personCache, \
projectVersion,httpPrefix,fromDomain,postToBox)
if not inboxUrl: if not inboxUrl:
if debug: if debug:

View File

@ -304,7 +304,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.postLog, \ self.server.postLog, \
self.server.cachedWebfingers, \ self.server.cachedWebfingers, \
self.server.personCache, \ self.server.personCache, \
messageJson,self.server.debug) messageJson,self.server.debug, \
self.server.projectVersion)
if self.server.debug: if self.server.debug:
print('DEBUG: handle any unfollow requests') print('DEBUG: handle any unfollow requests')
outboxUndoFollow(self.server.baseDir,messageJson,self.server.debug) outboxUndoFollow(self.server.baseDir,messageJson,self.server.debug)
@ -369,7 +370,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.postLog, \ self.server.postLog, \
self.server.cachedWebfingers, \ self.server.cachedWebfingers, \
self.server.personCache, \ self.server.personCache, \
messageJson,self.server.debug) messageJson,self.server.debug, \
self.server.projectVersion)
return True return True
def _updateInboxQueue(self,nickname: str,messageJson: {}) -> int: def _updateInboxQueue(self,nickname: str,messageJson: {}) -> int:
@ -717,7 +719,9 @@ class PubServer(BaseHTTPRequestHandler):
htmlHashtagSearch(self.server.baseDir,hashtag,pageNumber, \ htmlHashtagSearch(self.server.baseDir,hashtag,pageNumber, \
maxPostsInFeed,self.server.session, \ maxPostsInFeed,self.server.session, \
self.server.cachedWebfingers, \ self.server.cachedWebfingers, \
self.server.personCache) self.server.personCache, \
self.server.httpPrefix, \
self.server.projectVersion)
self._set_headers('text/html',cookie) self._set_headers('text/html',cookie)
if hashtagStr: if hashtagStr:
self.wfile.write(hashtagStr.encode()) self.wfile.write(hashtagStr.encode())
@ -791,7 +795,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.postLog, \ self.server.postLog, \
self.server.personCache, \ self.server.personCache, \
self.server.cachedWebfingers, \ self.server.cachedWebfingers, \
self.server.debug) self.server.debug, \
self.server.projectVersion)
if announceJson: if announceJson:
self._postToOutbox(announceJson) self._postToOutbox(announceJson)
self.server.GETbusy=False self.server.GETbusy=False
@ -845,7 +850,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.cachedWebfingers, \ self.server.cachedWebfingers, \
self.server.personCache, \ self.server.personCache, \
self.server.acceptedCaps, \ self.server.acceptedCaps, \
self.server.debug) self.server.debug, \
self.server.projectVersion)
self._redirect_headers(originPathStr,cookie) self._redirect_headers(originPathStr,cookie)
self.server.GETbusy=False self.server.GETbusy=False
return return
@ -1022,7 +1028,9 @@ class PubServer(BaseHTTPRequestHandler):
self.server.session, \ self.server.session, \
self.server.cachedWebfingers,self.server.personCache, \ self.server.cachedWebfingers,self.server.personCache, \
nickname,self.server.domain,self.server.port, \ nickname,self.server.domain,self.server.port, \
authorized,postJsonObject).encode('utf-8')) authorized,postJsonObject, \
self.server.httpPrefix, \
self.server.projectVersion).encode('utf-8'))
else: else:
self._set_headers('application/json',None) self._set_headers('application/json',None)
self.wfile.write(json.dumps(postJsonObject).encode('utf-8')) self.wfile.write(json.dumps(postJsonObject).encode('utf-8'))
@ -1074,7 +1082,9 @@ class PubServer(BaseHTTPRequestHandler):
nickname, \ nickname, \
self.server.domain, \ self.server.domain, \
self.server.port, \ self.server.port, \
repliesJson).encode('utf-8')) repliesJson, \
self.server.httpPrefix, \
self.server.projectVersion).encode('utf-8'))
else: else:
self._set_headers('application/json',None) self._set_headers('application/json',None)
self.wfile.write(json.dumps(repliesJson).encode('utf-8')) self.wfile.write(json.dumps(repliesJson).encode('utf-8'))
@ -1113,7 +1123,9 @@ class PubServer(BaseHTTPRequestHandler):
nickname, \ nickname, \
self.server.domain, \ self.server.domain, \
self.server.port, \ self.server.port, \
repliesJson).encode('utf-8')) repliesJson, \
self.server.httpPrefix, \
self.server.projectVersion).encode('utf-8'))
else: else:
self._set_headers('application/json',None) self._set_headers('application/json',None)
self.wfile.write(json.dumps(repliesJson).encode('utf-8')) self.wfile.write(json.dumps(repliesJson).encode('utf-8'))
@ -1136,7 +1148,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.baseDir) self.server.baseDir)
if getPerson: if getPerson:
self._set_headers('text/html',cookie) self._set_headers('text/html',cookie)
self.wfile.write(htmlProfile(self.server.baseDir, \ self.wfile.write(htmlProfile(self.server.projectVersion, \
self.server.baseDir, \
self.server.httpPrefix, \ self.server.httpPrefix, \
True, \ True, \
self.server.ocapAlways, \ self.server.ocapAlways, \
@ -1167,7 +1180,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.baseDir) self.server.baseDir)
if getPerson: if getPerson:
self._set_headers('text/html',cookie) self._set_headers('text/html',cookie)
self.wfile.write(htmlProfile(self.server.baseDir, \ self.wfile.write(htmlProfile(self.server.projectVersion, \
self.server.baseDir, \
self.server.httpPrefix, \ self.server.httpPrefix, \
True, \ True, \
self.server.ocapAlways, \ self.server.ocapAlways, \
@ -1210,7 +1224,9 @@ class PubServer(BaseHTTPRequestHandler):
self.server.session, \ self.server.session, \
self.server.cachedWebfingers,self.server.personCache, \ self.server.cachedWebfingers,self.server.personCache, \
nickname,self.server.domain,self.server.port, \ nickname,self.server.domain,self.server.port, \
authorized,postJsonObject).encode('utf-8')) authorized,postJsonObject, \
self.server.httpPrefix, \
self.server.projectVersion).encode('utf-8'))
else: else:
self._set_headers('application/json',None) self._set_headers('application/json',None)
self.wfile.write(json.dumps(postJsonObject).encode('utf-8')) self.wfile.write(json.dumps(postJsonObject).encode('utf-8'))
@ -1262,7 +1278,9 @@ class PubServer(BaseHTTPRequestHandler):
self.server.domain, \ self.server.domain, \
self.server.port, \ self.server.port, \
inboxFeed, \ inboxFeed, \
self.server.allowDeletion).encode('utf-8')) self.server.allowDeletion, \
self.server.httpPrefix, \
self.server.projectVersion).encode('utf-8'))
else: else:
self._set_headers('application/json',None) self._set_headers('application/json',None)
self.wfile.write(json.dumps(inboxFeed).encode('utf-8')) self.wfile.write(json.dumps(inboxFeed).encode('utf-8'))
@ -1319,7 +1337,9 @@ class PubServer(BaseHTTPRequestHandler):
self.server.domain, \ self.server.domain, \
self.server.port, \ self.server.port, \
outboxFeed, \ outboxFeed, \
self.server.allowDeletion).encode('utf-8')) self.server.allowDeletion, \
self.server.httpPrefix, \
self.server.projectVersion).encode('utf-8'))
else: else:
self._set_headers('application/json',None) self._set_headers('application/json',None)
self.wfile.write(json.dumps(outboxFeed).encode('utf-8')) self.wfile.write(json.dumps(outboxFeed).encode('utf-8'))
@ -1369,7 +1389,9 @@ class PubServer(BaseHTTPRequestHandler):
self.server.domain, \ self.server.domain, \
self.server.port, \ self.server.port, \
moderationFeed, \ moderationFeed, \
True).encode('utf-8')) True, \
self.server.httpPrefix, \
self.server.projectVersion).encode('utf-8'))
else: else:
self._set_headers('application/json',None) self._set_headers('application/json',None)
self.wfile.write(json.dumps(moderationFeed).encode('utf-8')) self.wfile.write(json.dumps(moderationFeed).encode('utf-8'))
@ -1410,7 +1432,8 @@ class PubServer(BaseHTTPRequestHandler):
createSession(self.server.domain,self.server.port,self.server.useTor) createSession(self.server.domain,self.server.port,self.server.useTor)
self._set_headers('text/html',cookie) self._set_headers('text/html',cookie)
self.wfile.write(htmlProfile(self.server.baseDir, \ self.wfile.write(htmlProfile(self.server.projectVersion, \
self.server.baseDir, \
self.server.httpPrefix, \ self.server.httpPrefix, \
authorized, \ authorized, \
self.server.ocapAlways, \ self.server.ocapAlways, \
@ -1449,7 +1472,8 @@ class PubServer(BaseHTTPRequestHandler):
createSession(self.server.domain,self.server.port,self.server.useTor) createSession(self.server.domain,self.server.port,self.server.useTor)
self._set_headers('text/html',cookie) self._set_headers('text/html',cookie)
self.wfile.write(htmlProfile(self.server.baseDir, \ self.wfile.write(htmlProfile(self.server.projectVersion, \
self.server.baseDir, \
self.server.httpPrefix, \ self.server.httpPrefix, \
authorized, \ authorized, \
self.server.ocapAlways, \ self.server.ocapAlways, \
@ -1486,7 +1510,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.session= \ self.server.session= \
createSession(self.server.domain,self.server.port,self.server.useTor) createSession(self.server.domain,self.server.port,self.server.useTor)
self._set_headers('text/html',cookie) self._set_headers('text/html',cookie)
self.wfile.write(htmlProfile(self.server.baseDir, \ self.wfile.write(htmlProfile(self.server.projectVersion, \
self.server.baseDir, \
self.server.httpPrefix, \ self.server.httpPrefix, \
authorized, \ authorized, \
self.server.ocapAlways, \ self.server.ocapAlways, \
@ -1513,7 +1538,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.session= \ self.server.session= \
createSession(self.server.domain,self.server.port,self.server.useTor) createSession(self.server.domain,self.server.port,self.server.useTor)
self._set_headers('text/html',cookie) self._set_headers('text/html',cookie)
self.wfile.write(htmlProfile(self.server.baseDir, \ self.wfile.write(htmlProfile(self.server.projectVersion, \
self.server.baseDir, \
self.server.httpPrefix, \ self.server.httpPrefix, \
authorized, \ authorized, \
self.server.ocapAlways, \ self.server.ocapAlways, \
@ -2236,7 +2262,9 @@ class PubServer(BaseHTTPRequestHandler):
htmlHashtagSearch(self.server.baseDir,searchStr[1:],1, \ htmlHashtagSearch(self.server.baseDir,searchStr[1:],1, \
maxPostsInFeed,self.server.session, \ maxPostsInFeed,self.server.session, \
self.server.cachedWebfingers, \ self.server.cachedWebfingers, \
self.server.personCache) self.server.personCache, \
self.server.httpPrefix, \
self.server.projectVersion)
if hashtagStr: if hashtagStr:
self._login_headers('text/html') self._login_headers('text/html')
self.wfile.write(hashtagStr.encode('utf-8')) self.wfile.write(hashtagStr.encode('utf-8'))
@ -2260,7 +2288,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.session, \ self.server.session, \
self.server.cachedWebfingers, \ self.server.cachedWebfingers, \
self.server.personCache, \ self.server.personCache, \
self.server.debug) self.server.debug, \
self.server.projectVersion)
if profileStr: if profileStr:
self._login_headers('text/html') self._login_headers('text/html')
self.wfile.write(profileStr.encode('utf-8')) self.wfile.write(profileStr.encode('utf-8'))
@ -2314,7 +2343,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.postLog, \ self.server.postLog, \
self.server.cachedWebfingers, \ self.server.cachedWebfingers, \
self.server.personCache, \ self.server.personCache, \
self.server.debug) self.server.debug, \
self.server.projectVersion)
self._redirect_headers(originPathStr,cookie) self._redirect_headers(originPathStr,cookie)
self.server.POSTbusy=False self.server.POSTbusy=False
return return
@ -2661,7 +2691,8 @@ class PubServer(BaseHTTPRequestHandler):
self.end_headers() self.end_headers()
self.server.POSTbusy=False self.server.POSTbusy=False
def runDaemon(instanceId,clientToServer: bool, \ def runDaemon(projectVersion, \
instanceId,clientToServer: bool, \
baseDir: str,domain: str, \ baseDir: str,domain: str, \
port=80,proxyPort=80,httpPrefix='https', \ port=80,proxyPort=80,httpPrefix='https', \
fedList=[],noreply=False,nolike=False,nopics=False, \ fedList=[],noreply=False,nolike=False,nopics=False, \
@ -2679,6 +2710,7 @@ def runDaemon(instanceId,clientToServer: bool, \
serverAddress = ('', proxyPort) serverAddress = ('', proxyPort)
httpd = ThreadingHTTPServer(serverAddress, PubServer) httpd = ThreadingHTTPServer(serverAddress, PubServer)
# max POST size of 10M # max POST size of 10M
httpd.projectVersion=projectVersion
httpd.maxPostLength=1024*1024*10 httpd.maxPostLength=1024*1024*10
httpd.domain=domain httpd.domain=domain
httpd.port=port httpd.port=port
@ -2732,7 +2764,8 @@ def runDaemon(instanceId,clientToServer: bool, \
print('Creating inbox queue') print('Creating inbox queue')
httpd.thrInboxQueue= \ httpd.thrInboxQueue= \
threadWithTrace(target=runInboxQueue, \ threadWithTrace(target=runInboxQueue, \
args=(baseDir,httpPrefix,httpd.sendThreads, \ args=(projectVersion, \
baseDir,httpPrefix,httpd.sendThreads, \
httpd.postLog,httpd.cachedWebfingers, \ httpd.postLog,httpd.cachedWebfingers, \
httpd.personCache,httpd.inboxQueue, \ httpd.personCache,httpd.inboxQueue, \
domain,port,useTor,httpd.federationList, \ domain,port,useTor,httpd.federationList, \

View File

@ -83,7 +83,7 @@ def sendDeleteViaServer(session,fromNickname: str,password: str,
fromDomain: str,fromPort: int, \ fromDomain: str,fromPort: int, \
httpPrefix: str,deleteObjectUrl: str, \ httpPrefix: str,deleteObjectUrl: str, \
cachedWebfingers: {},personCache: {}, \ cachedWebfingers: {},personCache: {}, \
debug: bool) -> {}: debug: bool,projectVersion: str) -> {}:
"""Creates a delete request message via c2s """Creates a delete request message via c2s
""" """
if not session: if not session:
@ -108,7 +108,8 @@ def sendDeleteViaServer(session,fromNickname: str,password: str,
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)
if not wfRequest: if not wfRequest:
if debug: if debug:
print('DEBUG: announce webfinger failed for '+handle) print('DEBUG: announce webfinger failed for '+handle)
@ -118,7 +119,8 @@ def sendDeleteViaServer(session,fromNickname: str,password: str,
# get the actor inbox for the To handle # get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \ inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \
getPersonBox(session,wfRequest,personCache,postToBox) getPersonBox(session,wfRequest,personCache, \
projectVersion,httpPrefix,fromDomain,postToBox)
if not inboxUrl: if not inboxUrl:
if debug: if debug:

View File

@ -296,7 +296,8 @@ if args.posts:
nickname=args.posts.split('@')[0] nickname=args.posts.split('@')[0]
domain=args.posts.split('@')[1] domain=args.posts.split('@')[1]
getPublicPostsOfPerson(nickname,domain,False,True, \ getPublicPostsOfPerson(nickname,domain,False,True, \
args.tor,args.port,httpPrefix,debug) args.tor,args.port,httpPrefix,debug, \
__version__)
sys.exit() sys.exit()
if args.postsraw: if args.postsraw:
@ -308,7 +309,8 @@ if args.postsraw:
nickname=args.postsraw.split('@')[0] nickname=args.postsraw.split('@')[0]
domain=args.postsraw.split('@')[1] domain=args.postsraw.split('@')[1]
getPublicPostsOfPerson(nickname,domain,False,False, \ getPublicPostsOfPerson(nickname,domain,False,False, \
args.tor,args.port,httpPrefix,debug) args.tor,args.port,httpPrefix,debug, \
__version__)
sys.exit() sys.exit()
baseDir=args.baseDir baseDir=args.baseDir
@ -429,7 +431,7 @@ if args.approve:
sendThreads,postLog, \ sendThreads,postLog, \
cachedWebfingers,personCache, \ cachedWebfingers,personCache, \
acceptedCaps, \ acceptedCaps, \
debug) debug,__version__)
sys.exit() sys.exit()
if args.deny: if args.deny:
@ -514,7 +516,8 @@ if args.message:
followersOnly=False followersOnly=False
print('Sending post to '+args.sendto) print('Sending post to '+args.sendto)
sendPostViaServer(baseDir,session,args.nickname,args.password, \ sendPostViaServer(__version__, \
baseDir,session,args.nickname,args.password, \
domain,port, \ domain,port, \
toNickname,toDomain,toPort,ccUrl, \ toNickname,toDomain,toPort,ccUrl, \
httpPrefix,sendMessage,followersOnly, \ httpPrefix,sendMessage,followersOnly, \
@ -544,7 +547,7 @@ if args.announce:
domain,port, \ domain,port, \
httpPrefix,args.announce, \ httpPrefix,args.announce, \
cachedWebfingers,personCache, \ cachedWebfingers,personCache, \
True) True,__version__)
for i in range(10): for i in range(10):
# TODO detect send success/fail # TODO detect send success/fail
time.sleep(1) time.sleep(1)
@ -596,7 +599,7 @@ if args.itemName:
args.location, \ args.location, \
args.duration, \ args.duration, \
cachedWebfingers,personCache, \ cachedWebfingers,personCache, \
debug) debug,__version__)
for i in range(10): for i in range(10):
# TODO detect send success/fail # TODO detect send success/fail
time.sleep(1) time.sleep(1)
@ -622,7 +625,7 @@ if args.undoItemName:
httpPrefix, \ httpPrefix, \
args.undoItemName, \ args.undoItemName, \
cachedWebfingers,personCache, \ cachedWebfingers,personCache, \
debug) debug,__version__)
for i in range(10): for i in range(10):
# TODO detect send success/fail # TODO detect send success/fail
time.sleep(1) time.sleep(1)
@ -646,7 +649,7 @@ if args.like:
domain,port, \ domain,port, \
httpPrefix,args.like, \ httpPrefix,args.like, \
cachedWebfingers,personCache, \ cachedWebfingers,personCache, \
True) True,__version__)
for i in range(10): for i in range(10):
# TODO detect send success/fail # TODO detect send success/fail
time.sleep(1) time.sleep(1)
@ -670,7 +673,7 @@ if args.undolike:
domain,port, \ domain,port, \
httpPrefix,args.undolike, \ httpPrefix,args.undolike, \
cachedWebfingers,personCache, \ cachedWebfingers,personCache, \
True) True,__version__)
for i in range(10): for i in range(10):
# TODO detect send success/fail # TODO detect send success/fail
time.sleep(1) time.sleep(1)
@ -694,7 +697,7 @@ if args.delete:
domain,port, \ domain,port, \
httpPrefix,args.delete, \ httpPrefix,args.delete, \
cachedWebfingers,personCache, \ cachedWebfingers,personCache, \
True) True,__version__)
for i in range(10): for i in range(10):
# TODO detect send success/fail # TODO detect send success/fail
time.sleep(1) time.sleep(1)
@ -727,7 +730,7 @@ if args.follow:
followNickname,followDomain,followPort, \ followNickname,followDomain,followPort, \
httpPrefix, \ httpPrefix, \
cachedWebfingers,personCache, \ cachedWebfingers,personCache, \
debug) debug,__version__)
for t in range(20): for t in range(20):
time.sleep(1) time.sleep(1)
# TODO some method to know if it worked # TODO some method to know if it worked
@ -761,7 +764,7 @@ if args.unfollow:
followNickname,followDomain,followPort, \ followNickname,followDomain,followPort, \
httpPrefix, \ httpPrefix, \
cachedWebfingers,personCache, \ cachedWebfingers,personCache, \
debug) debug,__version__)
for t in range(20): for t in range(20):
time.sleep(1) time.sleep(1)
# TODO some method to know if it worked # TODO some method to know if it worked
@ -798,13 +801,14 @@ if args.actor:
httpPrefix='https' httpPrefix='https'
port=443 port=443
session = createSession(domain,port,useTor) session = createSession(domain,port,useTor)
wfRequest = webfingerHandle(session,nickname+'@'+domain,httpPrefix,wfCache) wfRequest = webfingerHandle(session,nickname+'@'+domain,httpPrefix,wfCache, \
domain,__version__)
if not wfRequest: if not wfRequest:
print('Unable to webfinger '+nickname+'@'+domain) print('Unable to webfinger '+nickname+'@'+domain)
sys.exit() sys.exit()
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 = getUserUrl(wfRequest) personUrl = getUserUrl(wfRequest)
personJson = getJson(session,personUrl,asHeader,None) personJson = getJson(session,personUrl,asHeader,None,__version__,httpPrefix,domain)
if personJson: if personJson:
pprint(personJson) pprint(personJson)
else: else:
@ -814,7 +818,7 @@ if args.actor:
if args.json: if args.json:
session = createSession(domain,port,True) session = createSession(domain,port,True)
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) testJson = getJson(session,args.json,asHeader,None,__version__,httpPrefix,domain)
pprint(testJson) pprint(testJson)
sys.exit() sys.exit()
@ -986,7 +990,7 @@ if args.skill:
httpPrefix, \ httpPrefix, \
args.skill,args.skillLevelPercent, \ args.skill,args.skillLevelPercent, \
cachedWebfingers,personCache, \ cachedWebfingers,personCache, \
True) True,__version__)
for i in range(10): for i in range(10):
# TODO detect send success/fail # TODO detect send success/fail
time.sleep(1) time.sleep(1)
@ -1011,7 +1015,7 @@ if args.availability:
httpPrefix, \ httpPrefix, \
args.availability, \ args.availability, \
cachedWebfingers,personCache, \ cachedWebfingers,personCache, \
True) True,__version__)
for i in range(10): for i in range(10):
# TODO detect send success/fail # TODO detect send success/fail
time.sleep(1) time.sleep(1)
@ -1055,7 +1059,7 @@ if args.block:
domain,port, \ domain,port, \
httpPrefix,args.block, \ httpPrefix,args.block, \
cachedWebfingers,personCache, \ cachedWebfingers,personCache, \
True) True,__version__)
for i in range(10): for i in range(10):
# TODO detect send success/fail # TODO detect send success/fail
time.sleep(1) time.sleep(1)
@ -1092,7 +1096,7 @@ if args.delegate:
httpPrefix,args.delegate, \ httpPrefix,args.delegate, \
args.project,args.role, \ args.project,args.role, \
cachedWebfingers,personCache, \ cachedWebfingers,personCache, \
True) True,__version__)
for i in range(10): for i in range(10):
# TODO detect send success/fail # TODO detect send success/fail
time.sleep(1) time.sleep(1)
@ -1125,7 +1129,7 @@ if args.undelegate:
httpPrefix,args.delegate, \ httpPrefix,args.delegate, \
args.project,None, \ args.project,None, \
cachedWebfingers,personCache, \ cachedWebfingers,personCache, \
True) True,__version__)
for i in range(10): for i in range(10):
# TODO detect send success/fail # TODO detect send success/fail
time.sleep(1) time.sleep(1)
@ -1159,7 +1163,7 @@ if args.unblock:
domain,port, \ domain,port, \
httpPrefix,args.unblock, \ httpPrefix,args.unblock, \
cachedWebfingers,personCache, \ cachedWebfingers,personCache, \
True) True,__version__)
for i in range(10): for i in range(10):
# TODO detect send success/fail # TODO detect send success/fail
time.sleep(1) time.sleep(1)
@ -1257,7 +1261,8 @@ if args.testdata:
followerOfPerson(baseDir,nickname,domain,'maxboardroom',domainFull,federationList,False) followerOfPerson(baseDir,nickname,domain,'maxboardroom',domainFull,federationList,False)
setConfigParam(baseDir,'admin',nickname) setConfigParam(baseDir,'admin',nickname)
runDaemon(instanceId,args.client,baseDir, \ runDaemon(__version__, \
instanceId,args.client,baseDir, \
domain,port,proxyPort,httpPrefix, \ domain,port,proxyPort,httpPrefix, \
federationList, \ federationList, \
args.noreply,args.nolike,args.nopics, \ args.noreply,args.nolike,args.nopics, \

View File

@ -332,7 +332,7 @@ def receiveFollowRequest(session,baseDir: str,httpPrefix: str, \
port: int,sendThreads: [],postLog: [], \ port: int,sendThreads: [],postLog: [], \
cachedWebfingers: {},personCache: {}, \ cachedWebfingers: {},personCache: {}, \
messageJson: {},federationList: [], \ messageJson: {},federationList: [], \
debug : bool, \ debug : bool,projectVersion: str, \
acceptedCaps=["inbox:write","objects:read"]) -> bool: acceptedCaps=["inbox:write","objects:read"]) -> bool:
"""Receives a follow request within the POST section of HTTPServer """Receives a follow request within the POST section of HTTPServer
""" """
@ -412,7 +412,7 @@ def receiveFollowRequest(session,baseDir: str,httpPrefix: str, \
messageJson,acceptedCaps, \ messageJson,acceptedCaps, \
sendThreads,postLog, \ sendThreads,postLog, \
cachedWebfingers,personCache, \ cachedWebfingers,personCache, \
debug) debug,projectVersion)
def followedAccountAccepts(session,baseDir: str,httpPrefix: str, \ def followedAccountAccepts(session,baseDir: str,httpPrefix: str, \
nicknameToFollow: str,domainToFollow: str,port: int, \ nicknameToFollow: str,domainToFollow: str,port: int, \
@ -421,7 +421,7 @@ def followedAccountAccepts(session,baseDir: str,httpPrefix: str, \
followJson: {},acceptedCaps: [], \ followJson: {},acceptedCaps: [], \
sendThreads: [],postLog: [], \ sendThreads: [],postLog: [], \
cachedWebfingers: {},personCache: {}, \ cachedWebfingers: {},personCache: {}, \
debug: bool): debug: bool,projectVersion: str):
"""The person receiving a follow request accepts the new follower """The person receiving a follow request accepts the new follower
and sends back an Accept activity and sends back an Accept activity
""" """
@ -445,7 +445,7 @@ def followedAccountAccepts(session,baseDir: str,httpPrefix: str, \
httpPrefix,True,clientToServer, \ httpPrefix,True,clientToServer, \
federationList, \ federationList, \
sendThreads,postLog,cachedWebfingers, \ sendThreads,postLog,cachedWebfingers, \
personCache,debug) personCache,debug,projectVersion)
def sendFollowRequest(session,baseDir: str, \ def sendFollowRequest(session,baseDir: str, \
nickname: str,domain: str,port: int,httpPrefix: str, \ nickname: str,domain: str,port: int,httpPrefix: str, \
@ -453,7 +453,8 @@ def sendFollowRequest(session,baseDir: str, \
followPort: int,followHttpPrefix: str, \ followPort: int,followHttpPrefix: str, \
clientToServer: bool,federationList: [], \ clientToServer: bool,federationList: [], \
sendThreads: [],postLog: [],cachedWebfingers: {}, \ sendThreads: [],postLog: [],cachedWebfingers: {}, \
personCache: {},debug : bool) -> {}: personCache: {},debug : bool, \
projectVersion: str) -> {}:
"""Gets the json object for sending a follow request """Gets the json object for sending a follow request
""" """
if not domainPermitted(followDomain,federationList): if not domainPermitted(followDomain,federationList):
@ -487,7 +488,8 @@ def sendFollowRequest(session,baseDir: str, \
'https://www.w3.org/ns/activitystreams#Public', \ 'https://www.w3.org/ns/activitystreams#Public', \
httpPrefix,True,clientToServer, \ httpPrefix,True,clientToServer, \
federationList, \ federationList, \
sendThreads,postLog,cachedWebfingers,personCache, debug) sendThreads,postLog,cachedWebfingers,personCache, \
debug,projectVersion)
return newFollowJson return newFollowJson
@ -496,7 +498,7 @@ def sendFollowRequestViaServer(session,fromNickname: str,password: str,
followNickname: str,followDomain: str,followPort: int, \ followNickname: str,followDomain: str,followPort: int, \
httpPrefix: str, \ httpPrefix: str, \
cachedWebfingers: {},personCache: {}, \ cachedWebfingers: {},personCache: {}, \
debug: bool) -> {}: debug: bool,projectVersion: str) -> {}:
"""Creates a follow request via c2s """Creates a follow request via c2s
""" """
if not session: if not session:
@ -527,7 +529,8 @@ def sendFollowRequestViaServer(session,fromNickname: str,password: str,
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)
if not wfRequest: if not wfRequest:
if debug: if debug:
print('DEBUG: announce webfinger failed for '+handle) print('DEBUG: announce webfinger failed for '+handle)
@ -537,7 +540,8 @@ def sendFollowRequestViaServer(session,fromNickname: str,password: str,
# get the actor inbox for the To handle # get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \ inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \
getPersonBox(session,wfRequest,personCache,postToBox) getPersonBox(session,wfRequest,personCache, \
projectVersion,httpPrefix,fromDomain,postToBox)
if not inboxUrl: if not inboxUrl:
if debug: if debug:
@ -570,7 +574,7 @@ def sendUnfollowRequestViaServer(session,fromNickname: str,password: str,
followNickname: str,followDomain: str,followPort: int, \ followNickname: str,followDomain: str,followPort: int, \
httpPrefix: str, \ httpPrefix: str, \
cachedWebfingers: {},personCache: {}, \ cachedWebfingers: {},personCache: {}, \
debug: bool) -> {}: debug: bool,projectVersion: str) -> {}:
"""Creates a unfollow request via c2s """Creates a unfollow request via c2s
""" """
if not session: if not session:
@ -602,7 +606,8 @@ def sendUnfollowRequestViaServer(session,fromNickname: str,password: str,
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)
if not wfRequest: if not wfRequest:
if debug: if debug:
print('DEBUG: announce webfinger failed for '+handle) print('DEBUG: announce webfinger failed for '+handle)
@ -612,7 +617,8 @@ def sendUnfollowRequestViaServer(session,fromNickname: str,password: str,
# get the actor inbox for the To handle # get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \ inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \
getPersonBox(session,wfRequest,personCache,postToBox) getPersonBox(session,wfRequest,personCache, \
projectVersion,httpPrefix,fromDomain,postToBox)
if not inboxUrl: if not inboxUrl:
if debug: if debug:

View File

@ -83,7 +83,8 @@ def validInboxFilenames(baseDir: str,nickname: str,domain: str, \
return False return False
return True return True
def getPersonPubKey(session,personUrl: str,personCache: {},debug: bool) -> str: def getPersonPubKey(session,personUrl: str,personCache: {},debug: bool, \
projectVersion: str,httpPrefix: str,domain: str) -> str:
if not personUrl: if not personUrl:
return None return None
personUrl=personUrl.replace('#main-key','') personUrl=personUrl.replace('#main-key','')
@ -96,7 +97,7 @@ def getPersonPubKey(session,personUrl: str,personCache: {},debug: bool) -> str:
if debug: if debug:
print('DEBUG: Obtaining public key for '+personUrl) print('DEBUG: Obtaining public key for '+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)
if not personJson: if not personJson:
return None return None
pubKey=None pubKey=None
@ -980,7 +981,8 @@ def restoreQueueItems(baseDir: str,queue: []) -> None:
for qfile in queuefiles: for qfile in queuefiles:
queue.append(os.path.join(queueDir, qfile)) queue.append(os.path.join(queueDir, qfile))
def runInboxQueue(baseDir: str,httpPrefix: str,sendThreads: [],postLog: [], \ def runInboxQueue(projectVersion: str, \
baseDir: str,httpPrefix: str,sendThreads: [],postLog: [], \
cachedWebfingers: {},personCache: {},queue: [], \ cachedWebfingers: {},personCache: {},queue: [], \
domain: str,port: int,useTor: bool,federationList: [], \ domain: str,port: int,useTor: bool,federationList: [], \
ocapAlways: bool,maxReplies: int, \ ocapAlways: bool,maxReplies: int, \
@ -1104,7 +1106,9 @@ def runInboxQueue(baseDir: str,httpPrefix: str,sendThreads: [],postLog: [], \
queue.pop(0) queue.pop(0)
continue continue
pubKey=getPersonPubKey(session,keyId,personCache,debug) pubKey= \
getPersonPubKey(session,keyId,personCache,debug, \
projectVersion,httpPrefix,domain)
if pubKey: if pubKey:
print('DEBUG: public key: '+str(pubKey)) print('DEBUG: public key: '+str(pubKey))
break break
@ -1161,7 +1165,7 @@ def runInboxQueue(baseDir: str,httpPrefix: str,sendThreads: [],postLog: [], \
personCache, \ personCache, \
queueJson['post'], \ queueJson['post'], \
federationList, \ federationList, \
debug, \ debug,projectVersion, \
acceptedCaps=["inbox:write","objects:read"]): acceptedCaps=["inbox:write","objects:read"]):
if debug: if debug:
print('DEBUG: Follow accepted from '+keyId) print('DEBUG: Follow accepted from '+keyId)

31
like.py
View File

@ -127,7 +127,7 @@ def updateLikesCollection(postFilename: str,objectUrl: str, actor: str,debug: bo
def like(session,baseDir: str,federationList: [],nickname: str,domain: str,port: int, \ def like(session,baseDir: str,federationList: [],nickname: str,domain: str,port: int, \
ccList: [],httpPrefix: str,objectUrl: str,clientToServer: bool, \ ccList: [],httpPrefix: str,objectUrl: str,clientToServer: bool, \
sendThreads: [],postLog: [],personCache: {},cachedWebfingers: {}, \ sendThreads: [],postLog: [],personCache: {},cachedWebfingers: {}, \
debug: bool) -> {}: debug: bool,projectVersion: str) -> {}:
"""Creates a like """Creates a like
actor is the person doing the liking actor is the person doing the liking
'to' might be a specific person (actor) whose post was liked 'to' might be a specific person (actor) whose post was liked
@ -176,7 +176,8 @@ def like(session,baseDir: str,federationList: [],nickname: str,domain: str,port:
likedPostNickname,likedPostDomain,likedPostPort, \ likedPostNickname,likedPostDomain,likedPostPort, \
'https://www.w3.org/ns/activitystreams#Public', \ 'https://www.w3.org/ns/activitystreams#Public', \
httpPrefix,True,clientToServer,federationList, \ httpPrefix,True,clientToServer,federationList, \
sendThreads,postLog,cachedWebfingers,personCache,debug) sendThreads,postLog,cachedWebfingers,personCache, \
debug,projectVersion)
return newLikeJson return newLikeJson
@ -187,7 +188,7 @@ def likePost(session,baseDir: str,federationList: [], \
likeStatusNumber: int,clientToServer: bool, \ likeStatusNumber: int,clientToServer: bool, \
sendThreads: [],postLog: [], \ sendThreads: [],postLog: [], \
personCache: {},cachedWebfingers: {}, \ personCache: {},cachedWebfingers: {}, \
debug: bool) -> {}: debug: bool,projectVersion: str) -> {}:
"""Likes a given status post """Likes a given status post
""" """
likeDomain=likeDomain likeDomain=likeDomain
@ -205,12 +206,13 @@ def likePost(session,baseDir: str,federationList: [], \
return like(session,baseDir,federationList,nickname,domain,port, \ return like(session,baseDir,federationList,nickname,domain,port, \
ccList,httpPrefix,objectUrl,clientToServer, \ ccList,httpPrefix,objectUrl,clientToServer, \
sendThreads,postLog,personCache,cachedWebfingers,debug) sendThreads,postLog,personCache,cachedWebfingers, \
debug,projectVersion)
def undolike(session,baseDir: str,federationList: [],nickname: str,domain: str,port: int, \ def undolike(session,baseDir: str,federationList: [],nickname: str,domain: str,port: int, \
ccList: [],httpPrefix: str,objectUrl: str,clientToServer: bool, \ ccList: [],httpPrefix: str,objectUrl: str,clientToServer: bool, \
sendThreads: [],postLog: [],personCache: {},cachedWebfingers: {}, \ sendThreads: [],postLog: [],personCache: {},cachedWebfingers: {}, \
debug: bool) -> {}: debug: bool,projectVersion: str) -> {}:
"""Removes a like """Removes a like
actor is the person doing the liking actor is the person doing the liking
'to' might be a specific person (actor) whose post was liked 'to' might be a specific person (actor) whose post was liked
@ -266,7 +268,8 @@ def undolike(session,baseDir: str,federationList: [],nickname: str,domain: str,p
likedPostNickname,likedPostDomain,likedPostPort, \ likedPostNickname,likedPostDomain,likedPostPort, \
'https://www.w3.org/ns/activitystreams#Public', \ 'https://www.w3.org/ns/activitystreams#Public', \
httpPrefix,True,clientToServer,federationList, \ httpPrefix,True,clientToServer,federationList, \
sendThreads,postLog,cachedWebfingers,personCache,debug) sendThreads,postLog,cachedWebfingers,personCache, \
debug,projectVersion)
else: else:
return None return None
@ -303,7 +306,7 @@ def sendLikeViaServer(session,fromNickname: str,password: str,
fromDomain: str,fromPort: int, \ fromDomain: str,fromPort: int, \
httpPrefix: str,likeUrl: str, \ httpPrefix: str,likeUrl: str, \
cachedWebfingers: {},personCache: {}, \ cachedWebfingers: {},personCache: {}, \
debug: bool) -> {}: debug: bool,projectVersion: str) -> {}:
"""Creates a like via c2s """Creates a like via c2s
""" """
if not session: if not session:
@ -331,7 +334,8 @@ def sendLikeViaServer(session,fromNickname: str,password: str,
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)
if not wfRequest: if not wfRequest:
if debug: if debug:
print('DEBUG: announce webfinger failed for '+handle) print('DEBUG: announce webfinger failed for '+handle)
@ -341,7 +345,8 @@ def sendLikeViaServer(session,fromNickname: str,password: str,
# get the actor inbox for the To handle # get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \ inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \
getPersonBox(session,wfRequest,personCache,postToBox) getPersonBox(session,wfRequest,personCache, \
projectVersion,httpPrefix,fromDomain,postToBox)
if not inboxUrl: if not inboxUrl:
if debug: if debug:
@ -373,7 +378,7 @@ def sendUndoLikeViaServer(session,fromNickname: str,password: str,
fromDomain: str,fromPort: int, \ fromDomain: str,fromPort: int, \
httpPrefix: str,likeUrl: str, \ httpPrefix: str,likeUrl: str, \
cachedWebfingers: {},personCache: {}, \ cachedWebfingers: {},personCache: {}, \
debug: bool) -> {}: debug: bool,projectVersion: str) -> {}:
"""Undo a like via c2s """Undo a like via c2s
""" """
if not session: if not session:
@ -405,7 +410,8 @@ def sendUndoLikeViaServer(session,fromNickname: str,password: str,
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)
if not wfRequest: if not wfRequest:
if debug: if debug:
print('DEBUG: announce webfinger failed for '+handle) print('DEBUG: announce webfinger failed for '+handle)
@ -415,7 +421,8 @@ def sendUndoLikeViaServer(session,fromNickname: str,password: str,
# get the actor inbox for the To handle # get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \ inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \
getPersonBox(session,wfRequest,personCache,postToBox) getPersonBox(session,wfRequest,personCache, \
projectVersion,httpPrefix,fromDomain,postToBox)
if not inboxUrl: if not inboxUrl:
if debug: if debug:

View File

@ -41,7 +41,8 @@ def manualApproveFollowRequest(session,baseDir: str, \
sendThreads: [],postLog: [], \ sendThreads: [],postLog: [], \
cachedWebfingers: {},personCache: {}, \ cachedWebfingers: {},personCache: {}, \
acceptedCaps: [], \ acceptedCaps: [], \
debug: bool) -> None: debug: bool, \
projectVersion: str) -> None:
"""Manually approve a follow request """Manually approve a follow request
""" """
handle=nickname+'@'+domain handle=nickname+'@'+domain
@ -81,7 +82,7 @@ def manualApproveFollowRequest(session,baseDir: str, \
followJson,acceptedCaps, \ followJson,acceptedCaps, \
sendThreads,postLog, \ sendThreads,postLog, \
cachedWebfingers,personCache, \ cachedWebfingers,personCache, \
debug) debug,projectVersion)
os.remove(followActivityfilename) os.remove(followActivityfilename)
else: else:
approvefilenew.write(handle) approvefilenew.write(handle)

View File

@ -117,8 +117,10 @@ def getUserUrl(wfRequest) -> str:
return link['href'] return link['href']
return None return None
def parseUserFeed(session,feedUrl: str,asHeader: {}) -> None: def parseUserFeed(session,feedUrl: str,asHeader: {}, \
feedJson = getJson(session,feedUrl,asHeader,None) projectVersion: str,httpPrefix: str,domain: str) -> None:
feedJson = getJson(session,feedUrl,asHeader,None, \
projectVersion,httpPrefix,domain)
if not feedJson: if not feedJson:
return return
@ -133,10 +135,12 @@ def parseUserFeed(session,feedUrl: str,asHeader: {}) -> None:
nextUrl = feedJson['next'] nextUrl = feedJson['next']
if nextUrl: if nextUrl:
for item in parseUserFeed(session,nextUrl,asHeader): for item in parseUserFeed(session,nextUrl,asHeader, \
projectVersion,httpPrefix,domain):
yield item yield item
def getPersonBox(session,wfRequest: {},personCache: {}, \ def getPersonBox(session,wfRequest: {},personCache: {}, \
projectVersion: str,httpPrefix: 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/ld+json; profile="https://www.w3.org/ns/activitystreams"'} asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'}
personUrl = getUserUrl(wfRequest) personUrl = getUserUrl(wfRequest)
@ -144,7 +148,8 @@ def getPersonBox(session,wfRequest: {},personCache: {}, \
return None,None,None,None,None,None,None,None return None,None,None,None,None,None,None,None
personJson = getPersonFromCache(personUrl,personCache) personJson = getPersonFromCache(personUrl,personCache)
if not personJson: if not personJson:
personJson = getJson(session,personUrl,asHeader,None) personJson = getJson(session,personUrl,asHeader,None, \
projectVersion,httpPrefix,domain)
if not personJson: if not personJson:
return None,None,None,None,None,None,None,None return None,None,None,None,None,None,None,None
boxJson=None boxJson=None
@ -195,7 +200,8 @@ def getPosts(session,outboxUrl: str,maxPosts: int, \
maxEmoji: int,maxAttachments: int, \ maxEmoji: int,maxAttachments: int, \
federationList: [], \ federationList: [], \
personCache: {},raw: bool, \ personCache: {},raw: bool, \
simple: bool,debug: bool) -> {}: simple: bool,debug: bool, \
projectVersion: str,httpPrefix: str,domain: str) -> {}:
"""Gets public posts from an outbox """Gets public posts from an outbox
""" """
personPosts={} personPosts={}
@ -206,7 +212,8 @@ def getPosts(session,outboxUrl: str,maxPosts: int, \
if raw: if raw:
result = [] result = []
i = 0 i = 0
for item in parseUserFeed(session,outboxUrl,asHeader): for item in parseUserFeed(session,outboxUrl,asHeader, \
projectVersion,httpPrefix,domain):
result.append(item) result.append(item)
i += 1 i += 1
if i == maxPosts: if i == maxPosts:
@ -215,7 +222,8 @@ def getPosts(session,outboxUrl: str,maxPosts: int, \
return None return None
i = 0 i = 0
for item in parseUserFeed(session,outboxUrl,asHeader): for item in parseUserFeed(session,outboxUrl,asHeader, \
projectVersion,httpPrefix,domain):
if not item.get('id'): if not item.get('id'):
if debug: if debug:
print('No id') print('No id')
@ -896,7 +904,8 @@ def threadSendPost(session,postJsonObject: {},federationList: [],\
time.sleep(backoffTime) time.sleep(backoffTime)
backoffTime *= 2 backoffTime *= 2
def sendPost(session,baseDir: str,nickname: str, domain: str, port: int, \ def sendPost(projectVersion: str, \
session,baseDir: str,nickname: str, domain: str, port: int, \
toNickname: str, toDomain: str, toPort: int, cc: str, \ toNickname: str, toDomain: str, toPort: int, cc: str, \
httpPrefix: str, content: str, followersOnly: bool, \ httpPrefix: str, content: str, followersOnly: bool, \
saveToFile: bool, clientToServer: bool, \ saveToFile: bool, clientToServer: bool, \
@ -915,7 +924,8 @@ def sendPost(session,baseDir: str,nickname: str, domain: str, port: int, \
handle=httpPrefix+'://'+toDomain+'/@'+toNickname handle=httpPrefix+'://'+toDomain+'/@'+toNickname
# 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)
if not wfRequest: if not wfRequest:
return 1 return 1
@ -926,7 +936,8 @@ def sendPost(session,baseDir: str,nickname: str, domain: str, port: int, \
# get the actor inbox for the To handle # get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,toPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \ inboxUrl,pubKeyId,pubKey,toPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \
getPersonBox(session,wfRequest,personCache,postToBox) getPersonBox(session,wfRequest,personCache, \
projectVersion,httpPrefix,domain,postToBox)
# If there are more than one followers on the target domain # If there are more than one followers on the target domain
# then send to the shared inbox indead of the individual inbox # then send to the shared inbox indead of the individual inbox
@ -982,7 +993,8 @@ def sendPost(session,baseDir: str,nickname: str, domain: str, port: int, \
thr.start() thr.start()
return 0 return 0
def sendPostViaServer(baseDir,session,fromNickname: str,password: str, \ def sendPostViaServer(projectVersion: str, \
baseDir,session,fromNickname: str,password: str, \
fromDomain: str, fromPort: int, \ fromDomain: str, fromPort: int, \
toNickname: str, toDomain: str, toPort: int, cc: str, \ toNickname: str, toDomain: str, toPort: int, cc: str, \
httpPrefix: str, content: str, followersOnly: bool, \ httpPrefix: str, content: str, followersOnly: bool, \
@ -1003,7 +1015,8 @@ def sendPostViaServer(baseDir,session,fromNickname: str,password: str, \
handle=httpPrefix+'://'+fromDomain+'/@'+fromNickname handle=httpPrefix+'://'+fromDomain+'/@'+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)
if not wfRequest: if not wfRequest:
if debug: if debug:
print('DEBUG: webfinger failed for '+handle) print('DEBUG: webfinger failed for '+handle)
@ -1013,7 +1026,8 @@ def sendPostViaServer(baseDir,session,fromNickname: str,password: str, \
# get the actor inbox for the To handle # get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \ inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \
getPersonBox(session,wfRequest,personCache,postToBox) getPersonBox(session,wfRequest,personCache, \
projectVersion,httpPrefix,fromDomain,postToBox)
if not inboxUrl: if not inboxUrl:
if debug: if debug:
@ -1103,7 +1117,7 @@ def sendSignedJson(postJsonObject: {},session,baseDir: str, \
httpPrefix: str, saveToFile: bool, clientToServer: bool, \ httpPrefix: str, saveToFile: bool, clientToServer: bool, \
federationList: [], \ federationList: [], \
sendThreads: [], postLog: [], cachedWebfingers: {}, \ sendThreads: [], postLog: [], cachedWebfingers: {}, \
personCache: {}, debug: bool) -> int: personCache: {}, debug: bool,projectVersion: str) -> int:
"""Sends a signed json object to an inbox/outbox """Sends a signed json object to an inbox/outbox
""" """
if debug: if debug:
@ -1126,7 +1140,8 @@ def sendSignedJson(postJsonObject: {},session,baseDir: str, \
print('DEBUG: handle - '+handle+' toPort '+str(toPort)) print('DEBUG: handle - '+handle+' toPort '+str(toPort))
# 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)
if not wfRequest: if not wfRequest:
if debug: if debug:
print('DEBUG: webfinger for '+handle+' failed') print('DEBUG: webfinger for '+handle+' failed')
@ -1139,7 +1154,8 @@ def sendSignedJson(postJsonObject: {},session,baseDir: str, \
# get the actor inbox/outbox/capabilities for the To handle # get the actor inbox/outbox/capabilities for the To handle
inboxUrl,pubKeyId,pubKey,toPersonId,sharedInboxUrl,capabilityAcquisition,avatarUrl,preferredName = \ inboxUrl,pubKeyId,pubKey,toPersonId,sharedInboxUrl,capabilityAcquisition,avatarUrl,preferredName = \
getPersonBox(session,wfRequest,personCache,postToBox) getPersonBox(session,wfRequest,personCache, \
projectVersion,httpPrefix,domain,postToBox)
if nickname=='capabilities': if nickname=='capabilities':
inboxUrl=capabilityAcquisition inboxUrl=capabilityAcquisition
@ -1209,7 +1225,8 @@ def sendToNamedAddresses(session,baseDir: str, \
httpPrefix: str,federationList: [], \ httpPrefix: str,federationList: [], \
sendThreads: [],postLog: [], \ sendThreads: [],postLog: [], \
cachedWebfingers: {},personCache: {}, \ cachedWebfingers: {},personCache: {}, \
postJsonObject: {},debug: bool) -> None: postJsonObject: {},debug: bool, \
projectVersion: str) -> None:
"""sends a post to the specific named addresses in to/cc """sends a post to the specific named addresses in to/cc
""" """
if not session: if not session:
@ -1265,14 +1282,15 @@ def sendToNamedAddresses(session,baseDir: str, \
cc,httpPrefix,True,clientToServer, \ cc,httpPrefix,True,clientToServer, \
federationList, \ federationList, \
sendThreads,postLog,cachedWebfingers, \ sendThreads,postLog,cachedWebfingers, \
personCache,debug) personCache,debug,projectVersion)
def sendToFollowers(session,baseDir: str, \ def sendToFollowers(session,baseDir: str, \
nickname: str, domain: str, port: int, \ nickname: str, domain: str, port: int, \
httpPrefix: str,federationList: [], \ httpPrefix: str,federationList: [], \
sendThreads: [],postLog: [], \ sendThreads: [],postLog: [], \
cachedWebfingers: {},personCache: {}, \ cachedWebfingers: {},personCache: {}, \
postJsonObject: {},debug: bool) -> None: postJsonObject: {},debug: bool, \
projectVersion: str) -> None:
"""sends a post to the followers of the given nickname """sends a post to the followers of the given nickname
""" """
if not session: if not session:
@ -1317,7 +1335,7 @@ def sendToFollowers(session,baseDir: str, \
cc,httpPrefix,True,clientToServer, \ cc,httpPrefix,True,clientToServer, \
federationList, \ federationList, \
sendThreads,postLog,cachedWebfingers, \ sendThreads,postLog,cachedWebfingers, \
personCache,debug) personCache,debug,projectVersion)
if debug: if debug:
print('DEBUG: End of sendToFollowers') print('DEBUG: End of sendToFollowers')
@ -1629,7 +1647,7 @@ def archivePostsForPerson(httpPrefix: str,nickname: str,domain: str,baseDir: str
def getPublicPostsOfPerson(nickname: str,domain: str, \ def getPublicPostsOfPerson(nickname: str,domain: str, \
raw: bool,simple: bool,useTor: bool, \ raw: bool,simple: bool,useTor: bool, \
port: int,httpPrefix: str, \ port: int,httpPrefix: str, \
debug: bool) -> None: debug: bool,projectVersion: str) -> None:
""" This is really just for test purposes """ This is really just for test purposes
""" """
session = createSession(domain,port,useTor) session = createSession(domain,port,useTor)
@ -1642,12 +1660,14 @@ def getPublicPostsOfPerson(nickname: str,domain: str, \
domainFull=domain+':'+str(port) domainFull=domain+':'+str(port)
handle=httpPrefix+"://"+domainFull+"/@"+nickname handle=httpPrefix+"://"+domainFull+"/@"+nickname
wfRequest = \ wfRequest = \
webfingerHandle(session,handle,httpPrefix,cachedWebfingers) webfingerHandle(session,handle,httpPrefix,cachedWebfingers, \
domain,projectVersion)
if not wfRequest: if not wfRequest:
sys.exit() sys.exit()
personUrl,pubKeyId,pubKey,personId,shaedInbox,capabilityAcquisition,avatarUrl,preferredName= \ personUrl,pubKeyId,pubKey,personId,shaedInbox,capabilityAcquisition,avatarUrl,preferredName= \
getPersonBox(session,wfRequest,personCache,'outbox') getPersonBox(session,wfRequest,personCache, \
projectVersion,httpPrefix,domain,'outbox')
wfResult = json.dumps(wfRequest, indent=4, sort_keys=True) wfResult = json.dumps(wfRequest, indent=4, sort_keys=True)
maxMentions=10 maxMentions=10
@ -1655,7 +1675,8 @@ def getPublicPostsOfPerson(nickname: str,domain: str, \
maxAttachments=5 maxAttachments=5
userPosts = getPosts(session,personUrl,30,maxMentions,maxEmoji, \ userPosts = getPosts(session,personUrl,30,maxMentions,maxEmoji, \
maxAttachments,federationList, \ maxAttachments,federationList, \
personCache,raw,simple,debug) personCache,raw,simple,debug, \
projectVersion,httpPrefix,domain)
#print(str(userPosts)) #print(str(userPosts))
def sendCapabilitiesUpdate(session,baseDir: str,httpPrefix: str, \ def sendCapabilitiesUpdate(session,baseDir: str,httpPrefix: str, \
@ -1663,7 +1684,8 @@ def sendCapabilitiesUpdate(session,baseDir: str,httpPrefix: str, \
followerUrl,updateCaps: [], \ followerUrl,updateCaps: [], \
sendThreads: [],postLog: [], \ sendThreads: [],postLog: [], \
cachedWebfingers: {},personCache: {}, \ cachedWebfingers: {},personCache: {}, \
federationList :[],debug :bool) -> int: federationList :[],debug :bool, \
projectVersion: str) -> int:
"""When the capabilities for a follower are changed this """When the capabilities for a follower are changed this
sends out an update. followerUrl is the actor of the follower. sends out an update. followerUrl is the actor of the follower.
""" """
@ -1690,7 +1712,7 @@ def sendCapabilitiesUpdate(session,baseDir: str,httpPrefix: str, \
httpPrefix,True,clientToServer, \ httpPrefix,True,clientToServer, \
federationList, \ federationList, \
sendThreads,postLog,cachedWebfingers, \ sendThreads,postLog,cachedWebfingers, \
personCache,debug) personCache,debug,projectVersion)
def populateRepliesJson(baseDir: str,nickname: str,domain: str,postRepliesFilename: str,authorized: bool,repliesJson: {}) -> None: def populateRepliesJson(baseDir: str,nickname: str,domain: str,postRepliesFilename: str,authorized: bool,repliesJson: {}) -> None:
# populate the items list with replies # populate the items list with replies

View File

@ -207,7 +207,7 @@ def sendRoleViaServer(session,delegatorNickname: str,password: str,
httpPrefix: str,nickname: str, \ httpPrefix: str,nickname: str, \
project: str,role: str, \ project: str,role: str, \
cachedWebfingers: {},personCache: {}, \ cachedWebfingers: {},personCache: {}, \
debug: bool) -> {}: debug: bool,projectVersion: str) -> {}:
"""A delegator creates a role for a person via c2s """A delegator creates a role for a person via c2s
Setting role to an empty string or None removes the role Setting role to an empty string or None removes the role
""" """
@ -243,7 +243,8 @@ def sendRoleViaServer(session,delegatorNickname: str,password: str,
handle=httpPrefix+'://'+delegatorDomainFull+'/@'+delegatorNickname handle=httpPrefix+'://'+delegatorDomainFull+'/@'+delegatorNickname
# 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, \
delegatorDomain,projectVersion)
if not wfRequest: if not wfRequest:
if debug: if debug:
print('DEBUG: announce webfinger failed for '+handle) print('DEBUG: announce webfinger failed for '+handle)
@ -253,7 +254,8 @@ def sendRoleViaServer(session,delegatorNickname: str,password: str,
# get the actor inbox for the To handle # get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \ inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \
getPersonBox(session,wfRequest,personCache,postToBox) getPersonBox(session,wfRequest,personCache, \
projectVersion,httpPrefix,delegatorDomain,postToBox)
if not inboxUrl: if not inboxUrl:
if debug: if debug:

View File

@ -26,7 +26,7 @@ def createSession(domain: str, port: int, onionRoute: bool):
return session return session
def getJson(session,url: str,headers: {},params: {}, \ def getJson(session,url: str,headers: {},params: {}, \
version='0.01',httpPrefix='https',domain='testdomain') -> {}: version='0.0.1',httpPrefix='https',domain='testdomain') -> {}:
sessionParams={} sessionParams={}
sessionHeaders={} sessionHeaders={}
if headers: if headers:

View File

@ -274,7 +274,8 @@ def sendShareViaServer(session,fromNickname: str,password: str,
location: str, \ location: str, \
duration: str, \ duration: str, \
cachedWebfingers: {},personCache: {}, \ cachedWebfingers: {},personCache: {}, \
debug: bool) -> {}: debug: bool, \
projectVersion: str) -> {}:
"""Creates an item share via c2s """Creates an item share via c2s
""" """
if not session: if not session:
@ -310,7 +311,8 @@ def sendShareViaServer(session,fromNickname: str,password: str,
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)
if not wfRequest: if not wfRequest:
if debug: if debug:
print('DEBUG: announce webfinger failed for '+handle) print('DEBUG: announce webfinger failed for '+handle)
@ -320,7 +322,8 @@ def sendShareViaServer(session,fromNickname: str,password: str,
# get the actor inbox for the To handle # get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \ inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \
getPersonBox(session,wfRequest,personCache,postToBox) getPersonBox(session,wfRequest,personCache, \
projectVersion,httpPrefix,fromDomain,postToBox)
if not inboxUrl: if not inboxUrl:
if debug: if debug:
@ -359,7 +362,7 @@ def sendUndoShareViaServer(session,fromNickname: str,password: str,
httpPrefix: str, \ httpPrefix: str, \
displayName: str, \ displayName: str, \
cachedWebfingers: {},personCache: {}, \ cachedWebfingers: {},personCache: {}, \
debug: bool) -> {}: debug: bool,projectVersion: str) -> {}:
"""Undoes a share via c2s """Undoes a share via c2s
""" """
if not session: if not session:
@ -390,7 +393,8 @@ def sendUndoShareViaServer(session,fromNickname: str,password: str,
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)
if not wfRequest: if not wfRequest:
if debug: if debug:
print('DEBUG: announce webfinger failed for '+handle) print('DEBUG: announce webfinger failed for '+handle)
@ -400,7 +404,8 @@ def sendUndoShareViaServer(session,fromNickname: str,password: str,
# get the actor inbox for the To handle # get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \ inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \
getPersonBox(session,wfRequest,personCache,postToBox) getPersonBox(session,wfRequest,personCache, \
projectVersion,httpPrefix,fromDomain,postToBox)
if not inboxUrl: if not inboxUrl:
if debug: if debug:

View File

@ -90,7 +90,7 @@ def sendSkillViaServer(session,nickname: str,password: str,
httpPrefix: str, \ httpPrefix: str, \
skill: str,skillLevelPercent: int, \ skill: str,skillLevelPercent: int, \
cachedWebfingers: {},personCache: {}, \ cachedWebfingers: {},personCache: {}, \
debug: bool) -> {}: debug: bool,projectVersion: str) -> {}:
"""Sets a skill for a person via c2s """Sets a skill for a person via c2s
""" """
if not session: if not session:
@ -119,7 +119,8 @@ def sendSkillViaServer(session,nickname: str,password: str,
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)
if not wfRequest: if not wfRequest:
if debug: if debug:
print('DEBUG: announce webfinger failed for '+handle) print('DEBUG: announce webfinger failed for '+handle)
@ -129,7 +130,8 @@ def sendSkillViaServer(session,nickname: str,password: str,
# get the actor inbox for the To handle # get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \ inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,preferredName = \
getPersonBox(session,wfRequest,personCache,postToBox) getPersonBox(session,wfRequest,personCache, \
projectVersion,httpPrefix,domain,postToBox)
if not inboxUrl: if not inboxUrl:
if debug: if debug:

View File

@ -191,7 +191,7 @@ def createServerAlice(path: str,domain: str,port: int,federationList: [], \
global testServerAliceRunning global testServerAliceRunning
testServerAliceRunning = True testServerAliceRunning = True
print('Server running: Alice') print('Server running: Alice')
runDaemon("instanceId",False,path,domain,port,port, \ runDaemon(__version__,"instanceId",False,path,domain,port,port, \
httpPrefix,federationList, \ httpPrefix,federationList, \
noreply,nolike,nopics,noannounce,cw,ocapAlways, \ noreply,nolike,nopics,noannounce,cw,ocapAlways, \
useTor,maxReplies, \ useTor,maxReplies, \
@ -244,7 +244,7 @@ def createServerBob(path: str,domain: str,port: int,federationList: [], \
global testServerBobRunning global testServerBobRunning
testServerBobRunning = True testServerBobRunning = True
print('Server running: Bob') print('Server running: Bob')
runDaemon("instanceId",False,path,domain,port,port, \ runDaemon(__version__,"instanceId",False,path,domain,port,port, \
httpPrefix,federationList, \ httpPrefix,federationList, \
noreply,nolike,nopics,noannounce,cw,ocapAlways, \ noreply,nolike,nopics,noannounce,cw,ocapAlways, \
useTor,maxReplies, \ useTor,maxReplies, \
@ -277,7 +277,7 @@ def createServerEve(path: str,domain: str,port: int,federationList: [], \
global testServerEveRunning global testServerEveRunning
testServerEveRunning = True testServerEveRunning = True
print('Server running: Eve') print('Server running: Eve')
runDaemon("instanceId",False,path,domain,port,port, \ runDaemon(__version__,"instanceId",False,path,domain,port,port, \
httpPrefix,federationList, \ httpPrefix,federationList, \
noreply,nolike,nopics,noannounce,cw,ocapAlways, \ noreply,nolike,nopics,noannounce,cw,ocapAlways, \
useTor,maxReplies,allowDeletion,True) useTor,maxReplies,allowDeletion,True)
@ -354,7 +354,8 @@ def testPostMessageBetweenServers():
assert len([name for name in os.listdir(outboxPath) if os.path.isfile(os.path.join(outboxPath, name))])==0 assert len([name for name in os.listdir(outboxPath) if os.path.isfile(os.path.join(outboxPath, name))])==0
sendResult = \ sendResult = \
sendPost(sessionAlice,aliceDir,'alice', aliceDomain, alicePort, \ sendPost(__version__, \
sessionAlice,aliceDir,'alice', aliceDomain, alicePort, \
'bob', bobDomain, bobPort, ccUrl, httpPrefix, \ 'bob', bobDomain, bobPort, ccUrl, httpPrefix, \
'Why is a mouse when it spins? #sillyquestion', followersOnly, \ 'Why is a mouse when it spins? #sillyquestion', followersOnly, \
saveToFile, clientToServer,attachedImageFilename, \ saveToFile, clientToServer,attachedImageFilename, \
@ -410,7 +411,8 @@ def testPostMessageBetweenServers():
'bob',bobDomain,bobPort,httpPrefix, \ 'bob',bobDomain,bobPort,httpPrefix, \
'alice',aliceDomain,alicePort,[], \ 'alice',aliceDomain,alicePort,[], \
statusNumber,False,bobSendThreads,bobPostLog, \ statusNumber,False,bobSendThreads,bobPostLog, \
bobPersonCache,bobCachedWebfingers,True) bobPersonCache,bobCachedWebfingers, \
True,__version__)
for i in range(20): for i in range(20):
if 'likes' in open(outboxPostFilename).read(): if 'likes' in open(outboxPostFilename).read():
@ -436,7 +438,7 @@ def testPostMessageBetweenServers():
objectUrl, \ objectUrl, \
False,bobSendThreads,bobPostLog, \ False,bobSendThreads,bobPostLog, \
bobPersonCache,bobCachedWebfingers, \ bobPersonCache,bobCachedWebfingers, \
True) True,__version__)
announceMessageArrived=False announceMessageArrived=False
for i in range(10): for i in range(10):
time.sleep(1) time.sleep(1)
@ -558,7 +560,8 @@ def testFollowBetweenServers():
'bob',bobDomain,bobPort,httpPrefix, \ 'bob',bobDomain,bobPort,httpPrefix, \
clientToServer,federationList, \ clientToServer,federationList, \
aliceSendThreads,alicePostLog, \ aliceSendThreads,alicePostLog, \
aliceCachedWebfingers,alicePersonCache,True) aliceCachedWebfingers,alicePersonCache, \
True,__version__)
print('sendResult: '+str(sendResult)) print('sendResult: '+str(sendResult))
bobCapsFilename=bobDir+'/accounts/bob@'+bobDomain+'/ocap/accept/'+httpPrefix+':##'+aliceDomain+':'+str(alicePort)+'#users#alice.json' bobCapsFilename=bobDir+'/accounts/bob@'+bobDomain+'/ocap/accept/'+httpPrefix+':##'+aliceDomain+':'+str(alicePort)+'#users#alice.json'
@ -592,7 +595,8 @@ def testFollowBetweenServers():
evePostLog=[] evePostLog=[]
useBlurhash=False useBlurhash=False
sendResult = \ sendResult = \
sendPost(sessionEve,eveDir,'eve', eveDomain, evePort, \ sendPost(__version__, \
sessionEve,eveDir,'eve', eveDomain, evePort, \
'bob', bobDomain, bobPort, ccUrl, \ 'bob', bobDomain, bobPort, ccUrl, \
httpPrefix, 'Eve message', followersOnly, \ httpPrefix, 'Eve message', followersOnly, \
saveToFile, clientToServer,None,None, \ saveToFile, clientToServer,None,None, \
@ -626,7 +630,8 @@ def testFollowBetweenServers():
alicePostLog=[] alicePostLog=[]
useBlurhash=False useBlurhash=False
sendResult = \ sendResult = \
sendPost(sessionAlice,aliceDir,'alice', aliceDomain, alicePort, \ sendPost(__version__, \
sessionAlice,aliceDir,'alice', aliceDomain, alicePort, \
'bob', bobDomain, bobPort, ccUrl, \ 'bob', bobDomain, bobPort, ccUrl, \
httpPrefix, 'Alice message', followersOnly, saveToFile, \ httpPrefix, 'Alice message', followersOnly, saveToFile, \
clientToServer,None,None,useBlurhash, federationList, \ clientToServer,None,None,useBlurhash, federationList, \
@ -679,7 +684,7 @@ def testFollowBetweenServers():
newCapabilities, \ newCapabilities, \
bobSendThreads, bobPostLog, \ bobSendThreads, bobPostLog, \
bobCachedWebfingers,bobPersonCache, \ bobCachedWebfingers,bobPersonCache, \
federationList,True) federationList,True,__version__)
bobChanged=False bobChanged=False
bobNewCapsJson=None bobNewCapsJson=None
@ -1120,7 +1125,8 @@ def testClientToServer():
assert len([name for name in os.listdir(outboxPath) if os.path.isfile(os.path.join(outboxPath, name))])==0 assert len([name for name in os.listdir(outboxPath) if os.path.isfile(os.path.join(outboxPath, name))])==0
assert len([name for name in os.listdir(inboxPath) if os.path.isfile(os.path.join(inboxPath, name))])==0 assert len([name for name in os.listdir(inboxPath) if os.path.isfile(os.path.join(inboxPath, name))])==0
sendResult= \ sendResult= \
sendPostViaServer(aliceDir,sessionAlice,'alice',password, \ sendPostViaServer(__version__, \
aliceDir,sessionAlice,'alice',password, \
aliceDomain,alicePort, \ aliceDomain,alicePort, \
'bob',bobDomain,bobPort,None, \ 'bob',bobDomain,bobPort,None, \
httpPrefix,'Sent from my ActivityPub client',followersOnly, \ httpPrefix,'Sent from my ActivityPub client',followersOnly, \
@ -1170,7 +1176,7 @@ def testClientToServer():
'bob',bobDomain,bobPort, \ 'bob',bobDomain,bobPort, \
httpPrefix, \ httpPrefix, \
cachedWebfingers,personCache, \ cachedWebfingers,personCache, \
True) True,__version__)
for t in range(10): for t in range(10):
if os.path.isfile(bobDir+'/accounts/bob@'+bobDomain+'/followers.txt'): if os.path.isfile(bobDir+'/accounts/bob@'+bobDomain+'/followers.txt'):
if 'alice@'+aliceDomain+':'+str(alicePort) in open(bobDir+'/accounts/bob@'+bobDomain+'/followers.txt').read(): if 'alice@'+aliceDomain+':'+str(alicePort) in open(bobDir+'/accounts/bob@'+bobDomain+'/followers.txt').read():
@ -1192,7 +1198,7 @@ def testClientToServer():
'alice',aliceDomain,alicePort, \ 'alice',aliceDomain,alicePort, \
httpPrefix, \ httpPrefix, \
cachedWebfingers,personCache, \ cachedWebfingers,personCache, \
True) True,__version__)
for t in range(10): for t in range(10):
if os.path.isfile(aliceDir+'/accounts/alice@'+aliceDomain+'/followers.txt'): if os.path.isfile(aliceDir+'/accounts/alice@'+aliceDomain+'/followers.txt'):
if 'bob@'+bobDomain+':'+str(bobPort) in open(aliceDir+'/accounts/alice@'+aliceDomain+'/followers.txt').read(): if 'bob@'+bobDomain+':'+str(bobPort) in open(aliceDir+'/accounts/alice@'+aliceDomain+'/followers.txt').read():
@ -1220,7 +1226,7 @@ def testClientToServer():
bobDomain,bobPort, \ bobDomain,bobPort, \
httpPrefix,outboxPostId, \ httpPrefix,outboxPostId, \
cachedWebfingers,personCache, \ cachedWebfingers,personCache, \
True) True,__version__)
for i in range(20): for i in range(20):
if os.path.isdir(outboxPath) and os.path.isdir(inboxPath): if os.path.isdir(outboxPath) and os.path.isdir(inboxPath):
if len([name for name in os.listdir(outboxPath) if os.path.isfile(os.path.join(outboxPath, name))])==2: if len([name for name in os.listdir(outboxPath) if os.path.isfile(os.path.join(outboxPath, name))])==2:
@ -1240,7 +1246,7 @@ def testClientToServer():
bobDomain,bobPort, \ bobDomain,bobPort, \
httpPrefix,outboxPostId, \ httpPrefix,outboxPostId, \
cachedWebfingers, \ cachedWebfingers, \
personCache,True) personCache,True,__version__)
for i in range(20): for i in range(20):
if os.path.isdir(outboxPath) and os.path.isdir(inboxPath): if os.path.isdir(outboxPath) and os.path.isdir(inboxPath):
if len([name for name in os.listdir(outboxPath) if os.path.isfile(os.path.join(outboxPath, name))])==3: if len([name for name in os.listdir(outboxPath) if os.path.isfile(os.path.join(outboxPath, name))])==3:
@ -1262,7 +1268,7 @@ def testClientToServer():
aliceDomain,alicePort, \ aliceDomain,alicePort, \
httpPrefix,outboxPostId, \ httpPrefix,outboxPostId, \
cachedWebfingers,personCache, \ cachedWebfingers,personCache, \
True) True,__version__)
for i in range(30): for i in range(30):
if os.path.isdir(inboxPath): if os.path.isdir(inboxPath):
if len([name for name in os.listdir(inboxPath) if os.path.isfile(os.path.join(inboxPath, name))])==postsBefore-1: if len([name for name in os.listdir(inboxPath) if os.path.isfile(os.path.join(inboxPath, name))])==postsBefore-1:
@ -1282,7 +1288,7 @@ def testClientToServer():
'bob',bobDomain,bobPort, \ 'bob',bobDomain,bobPort, \
httpPrefix, \ httpPrefix, \
cachedWebfingers,personCache, \ cachedWebfingers,personCache, \
True) True,__version__)
for t in range(10): for t in range(10):
if 'alice@'+aliceDomain+':'+str(alicePort) not in open(bobDir+'/accounts/bob@'+bobDomain+'/followers.txt').read(): if 'alice@'+aliceDomain+':'+str(alicePort) not in open(bobDir+'/accounts/bob@'+bobDomain+'/followers.txt').read():
if 'bob@'+bobDomain+':'+str(bobPort) not in open(aliceDir+'/accounts/alice@'+aliceDomain+'/following.txt').read(): if 'bob@'+bobDomain+':'+str(bobPort) not in open(aliceDir+'/accounts/alice@'+aliceDomain+'/following.txt').read():

View File

@ -35,7 +35,8 @@ def parseHandle(handle: str) -> (str,str):
return nickname, domain return nickname, domain
def webfingerHandle(session,handle: str,httpPrefix: str,cachedWebfingers: {}) -> {}: def webfingerHandle(session,handle: str,httpPrefix: str,cachedWebfingers: {}, \
fromDomain: str,projectVersion: str) -> {}:
if not session: if not session:
print('WARN: No session specified for webfingerHandle') print('WARN: No session specified for webfingerHandle')
return None return None
@ -55,7 +56,7 @@ def webfingerHandle(session,handle: str,httpPrefix: str,cachedWebfingers: {}) ->
par = {'resource': 'acct:{}'.format(nickname+'@'+wfDomain)} par = {'resource': 'acct:{}'.format(nickname+'@'+wfDomain)}
hdr = {'Accept': 'application/jrd+json'} hdr = {'Accept': 'application/jrd+json'}
try: try:
result = getJson(session, url, hdr, par) result = getJson(session, url, hdr, par,projectVersion,httpPrefix,fromDomain)
except: except:
print("Unable to webfinger " + url) print("Unable to webfinger " + url)
print('headers: '+str(hdr)) print('headers: '+str(hdr))

View File

@ -153,7 +153,8 @@ def htmlModerationInfo(baseDir: str) -> str:
return infoForm return infoForm
def htmlHashtagSearch(baseDir: str,hashtag: str,pageNumber: int,postsPerPage: int, def htmlHashtagSearch(baseDir: str,hashtag: str,pageNumber: int,postsPerPage: int,
session,wfRequest: {},personCache: {}) -> str: session,wfRequest: {},personCache: {}, \
httpPrefix: str,projectVersion: str) -> str:
"""Show a page containing search results for a hashtag """Show a page containing search results for a hashtag
""" """
if hashtag.startswith('#'): if hashtag.startswith('#'):
@ -204,7 +205,9 @@ def htmlHashtagSearch(baseDir: str,hashtag: str,pageNumber: int,postsPerPage: in
hashtagSearchForm+= \ hashtagSearchForm+= \
individualPostAsHtml(baseDir,session,wfRequest,personCache, \ individualPostAsHtml(baseDir,session,wfRequest,personCache, \
nickname,domain,port,postJsonObject, \ nickname,domain,port,postJsonObject, \
None,True,False,False) None,True,False, \
httpPrefix,projectVersion, \
False)
index-=1 index-=1
if endIndex>0: if endIndex>0:
@ -643,7 +646,8 @@ def htmlFooter() -> str:
def htmlProfilePosts(baseDir: str,httpPrefix: str, \ def htmlProfilePosts(baseDir: str,httpPrefix: str, \
authorized: bool,ocapAlways: bool, \ authorized: bool,ocapAlways: bool, \
nickname: str,domain: str,port: int, \ nickname: str,domain: str,port: int, \
session,wfRequest: {},personCache: {}) -> str: session,wfRequest: {},personCache: {}, \
projectVersion: str) -> str:
"""Shows posts on the profile screen """Shows posts on the profile screen
""" """
profileStr='' profileStr=''
@ -659,14 +663,16 @@ def htmlProfilePosts(baseDir: str,httpPrefix: str, \
if item['type']=='Create' or item['type']=='Announce': if item['type']=='Create' or item['type']=='Announce':
profileStr+= \ profileStr+= \
individualPostAsHtml(baseDir,session,wfRequest,personCache, \ individualPostAsHtml(baseDir,session,wfRequest,personCache, \
nickname,domain,port,item,None,True,False,False) nickname,domain,port,item,None,True,False, \
httpPrefix,projectVersion, \
False)
return profileStr return profileStr
def htmlProfileFollowing(baseDir: str,httpPrefix: str, \ def htmlProfileFollowing(baseDir: str,httpPrefix: str, \
authorized: bool,ocapAlways: bool, \ authorized: bool,ocapAlways: bool, \
nickname: str,domain: str,port: int, \ nickname: str,domain: str,port: int, \
session,wfRequest: {},personCache: {}, \ session,wfRequest: {},personCache: {}, \
followingJson: {}, \ followingJson: {},projectVersion: str, \
buttons: []) -> str: buttons: []) -> str:
"""Shows following on the profile screen """Shows following on the profile screen
""" """
@ -674,7 +680,9 @@ def htmlProfileFollowing(baseDir: str,httpPrefix: str, \
for item in followingJson['orderedItems']: for item in followingJson['orderedItems']:
profileStr+= \ profileStr+= \
individualFollowAsHtml(session,wfRequest,personCache, \ individualFollowAsHtml(session,wfRequest,personCache, \
domain,item,authorized,nickname,buttons) domain,item,authorized,nickname, \
httpPrefix,projectVersion, \
buttons)
return profileStr return profileStr
def htmlProfileRoles(nickname: str,domain: str,rolesJson: {}) -> str: def htmlProfileRoles(nickname: str,domain: str,rolesJson: {}) -> str:
@ -724,7 +732,8 @@ def htmlProfileShares(nickname: str,domain: str,sharesJson: {}) -> str:
profileStr='<div class="share-title">'+profileStr+'</div>' profileStr='<div class="share-title">'+profileStr+'</div>'
return profileStr return profileStr
def htmlProfile(baseDir: str,httpPrefix: str,authorized: bool, \ def htmlProfile(projectVersion: str, \
baseDir: str,httpPrefix: str,authorized: bool, \
ocapAlways: bool,profileJson: {},selected: str, \ ocapAlways: bool,profileJson: {},selected: str, \
session,wfRequest: {},personCache: {}, \ session,wfRequest: {},personCache: {}, \
extraJson=None) -> str: extraJson=None) -> str:
@ -837,13 +846,15 @@ def htmlProfile(baseDir: str,httpPrefix: str,authorized: bool, \
profileStr+= \ profileStr+= \
htmlProfilePosts(baseDir,httpPrefix,authorized, \ htmlProfilePosts(baseDir,httpPrefix,authorized, \
ocapAlways,nickname,domain,port, \ ocapAlways,nickname,domain,port, \
session,wfRequest,personCache) session,wfRequest,personCache, \
projectVersion)
if selected=='following': if selected=='following':
profileStr+= \ profileStr+= \
htmlProfileFollowing(baseDir,httpPrefix, \ htmlProfileFollowing(baseDir,httpPrefix, \
authorized,ocapAlways,nickname, \ authorized,ocapAlways,nickname, \
domain,port,session, \ domain,port,session, \
wfRequest,personCache,extraJson, \ wfRequest,personCache,extraJson, \
projectVersion, \
["unfollow"]) ["unfollow"])
if selected=='followers': if selected=='followers':
profileStr+= \ profileStr+= \
@ -851,6 +862,7 @@ def htmlProfile(baseDir: str,httpPrefix: str,authorized: bool, \
authorized,ocapAlways,nickname, \ authorized,ocapAlways,nickname, \
domain,port,session, \ domain,port,session, \
wfRequest,personCache,extraJson, \ wfRequest,personCache,extraJson, \
projectVersion,
["block"]) ["block"])
if selected=='roles': if selected=='roles':
profileStr+= \ profileStr+= \
@ -869,6 +881,8 @@ def individualFollowAsHtml(session,wfRequest: {}, \
followUrl: str, \ followUrl: str, \
authorized: bool, \ authorized: bool, \
actorNickname: str, \ actorNickname: str, \
httpPrefix: str, \
projectVersion: str, \
buttons=[]) -> str: buttons=[]) -> str:
nickname=getNicknameFromActor(followUrl) nickname=getNicknameFromActor(followUrl)
domain,port=getDomainFromActor(followUrl) domain,port=getDomainFromActor(followUrl)
@ -876,7 +890,8 @@ def individualFollowAsHtml(session,wfRequest: {}, \
avatarUrl=followUrl+'/avatar.png' avatarUrl=followUrl+'/avatar.png'
if domain not in followUrl: if domain not in followUrl:
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl2,preferredName = \ inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl2,preferredName = \
getPersonBox(session,wfRequest,personCache,'outbox') getPersonBox(session,wfRequest,personCache, \
projectVersion,httpPrefix,domain,'outbox')
if avatarUrl2: if avatarUrl2:
avatarUrl=avatarUrl2 avatarUrl=avatarUrl2
if preferredName: if preferredName:
@ -916,7 +931,9 @@ def individualPostAsHtml(baseDir: str, \
nickname: str,domain: str,port: int, \ nickname: str,domain: str,port: int, \
postJsonObject: {}, \ postJsonObject: {}, \
avatarUrl: str, showAvatarDropdown: bool, avatarUrl: str, showAvatarDropdown: bool,
allowDeletion: bool,showIcons=False) -> str: allowDeletion: bool, \
httpPrefix: str, projectVersion: str, \
showIcons=False) -> str:
""" Shows a single post as html """ Shows a single post as html
""" """
titleStr='' titleStr=''
@ -925,7 +942,7 @@ def individualPostAsHtml(baseDir: str, \
if isinstance(postJsonObject['object'], str): if isinstance(postJsonObject['object'], str):
# get the announced post # get the announced post
asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'} asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'}
announcedJson = getJson(session,postJsonObject['object'],asHeader,None) announcedJson = getJson(session,postJsonObject['object'],asHeader,None,projectVersion,httpPrefix,domain)
if announcedJson: if announcedJson:
if not announcedJson.get('type'): if not announcedJson.get('type'):
return '' return ''
@ -1000,7 +1017,8 @@ def individualPostAsHtml(baseDir: str, \
if fullDomain not in postJsonObject['actor']: if fullDomain not in postJsonObject['actor']:
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl2,preferredName = \ inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl2,preferredName = \
getPersonBox(session,wfRequest,personCache,'outbox') getPersonBox(session,wfRequest,personCache, \
projectVersion,httpPrefix,domain,'outbox')
if avatarUrl2: if avatarUrl2:
avatarUrl=avatarUrl2 avatarUrl=avatarUrl2
if preferredName: if preferredName:
@ -1129,7 +1147,8 @@ def individualPostAsHtml(baseDir: str, \
def htmlTimeline(pageNumber: int,itemsPerPage: int,session,baseDir: str, \ def htmlTimeline(pageNumber: int,itemsPerPage: int,session,baseDir: str, \
wfRequest: {},personCache: {}, \ wfRequest: {},personCache: {}, \
nickname: str,domain: str,port: int,timelineJson: {}, \ nickname: str,domain: str,port: int,timelineJson: {}, \
boxName: str,allowDeletion: bool) -> str: boxName: str,allowDeletion: bool, \
httpPrefix: str,projectVersion: str) -> str:
"""Show the timeline as html """Show the timeline as html
""" """
with open(baseDir+'/epicyon-profile.css', 'r') as cssFile: with open(baseDir+'/epicyon-profile.css', 'r') as cssFile:
@ -1212,7 +1231,9 @@ def htmlTimeline(pageNumber: int,itemsPerPage: int,session,baseDir: str, \
itemCtr+=1 itemCtr+=1
tlStr+=individualPostAsHtml(baseDir,session,wfRequest,personCache, \ tlStr+=individualPostAsHtml(baseDir,session,wfRequest,personCache, \
nickname,domain,port,item,None,True, \ nickname,domain,port,item,None,True, \
allowDeletion,showIndividualPostIcons) allowDeletion, \
httpPrefix,projectVersion,
showIndividualPostIcons)
# page down arrow # page down arrow
if itemCtr>=itemsPerPage: if itemCtr>=itemsPerPage:
@ -1223,39 +1244,46 @@ def htmlTimeline(pageNumber: int,itemsPerPage: int,session,baseDir: str, \
def htmlInbox(pageNumber: int,itemsPerPage: int, \ def htmlInbox(pageNumber: int,itemsPerPage: int, \
session,baseDir: str,wfRequest: {},personCache: {}, \ session,baseDir: str,wfRequest: {},personCache: {}, \
nickname: str,domain: str,port: int,inboxJson: {}, \ nickname: str,domain: str,port: int,inboxJson: {}, \
allowDeletion: bool) -> str: allowDeletion: bool, \
httpPrefix: str,projectVersion: str) -> str:
"""Show the inbox as html """Show the inbox as html
""" """
return htmlTimeline(pageNumber,itemsPerPage,session,baseDir,wfRequest,personCache, \ return htmlTimeline(pageNumber,itemsPerPage,session,baseDir,wfRequest,personCache, \
nickname,domain,port,inboxJson,'inbox',allowDeletion) nickname,domain,port,inboxJson,'inbox',allowDeletion, \
httpPrefix,projectVersion)
def htmlModeration(pageNumber: int,itemsPerPage: int, \ def htmlModeration(pageNumber: int,itemsPerPage: int, \
session,baseDir: str,wfRequest: {},personCache: {}, \ session,baseDir: str,wfRequest: {},personCache: {}, \
nickname: str,domain: str,port: int,inboxJson: {}, \ nickname: str,domain: str,port: int,inboxJson: {}, \
allowDeletion: bool) -> str: allowDeletion: bool, \
httpPrefix: str,projectVersion: str) -> str:
"""Show the moderation feed as html """Show the moderation feed as html
""" """
return htmlTimeline(pageNumber,itemsPerPage,session,baseDir,wfRequest,personCache, \ return htmlTimeline(pageNumber,itemsPerPage,session,baseDir,wfRequest,personCache, \
nickname,domain,port,inboxJson,'moderation',allowDeletion) nickname,domain,port,inboxJson,'moderation',allowDeletion, \
httpPrefix,projectVersion)
def htmlOutbox(pageNumber: int,itemsPerPage: int, \ def htmlOutbox(pageNumber: int,itemsPerPage: int, \
session,baseDir: str,wfRequest: {},personCache: {}, \ session,baseDir: str,wfRequest: {},personCache: {}, \
nickname: str,domain: str,port: int,outboxJson: {}, \ nickname: str,domain: str,port: int,outboxJson: {}, \
allowDeletion: bool) -> str: allowDeletion: bool,
httpPrefix: str,projectVersion: str) -> str:
"""Show the Outbox as html """Show the Outbox as html
""" """
return htmlTimeline(pageNumber,itemsPerPage,session,baseDir,wfRequest,personCache, \ return htmlTimeline(pageNumber,itemsPerPage,session,baseDir,wfRequest,personCache, \
nickname,domain,port,outboxJson,'outbox',allowDeletion) nickname,domain,port,outboxJson,'outbox',allowDeletion, \
httpPrefix,projectVersion)
def htmlIndividualPost(baseDir: str,session,wfRequest: {},personCache: {}, \ def htmlIndividualPost(baseDir: str,session,wfRequest: {},personCache: {}, \
nickname: str,domain: str,port: int,authorized: bool, \ nickname: str,domain: str,port: int,authorized: bool, \
postJsonObject: {}) -> str: postJsonObject: {},httpPrefix: str,projectVersion: str) -> str:
"""Show an individual post as html """Show an individual post as html
""" """
postStr='<script>'+contentWarningScript()+'</script>' postStr='<script>'+contentWarningScript()+'</script>'
postStr+= \ postStr+= \
individualPostAsHtml(baseDir,session,wfRequest,personCache, \ individualPostAsHtml(baseDir,session,wfRequest,personCache, \
nickname,domain,port,postJsonObject,None,True,False,False) nickname,domain,port,postJsonObject,None,True,False, \
httpPrefix,projectVersion,False)
messageId=postJsonObject['id'].replace('/activity','') messageId=postJsonObject['id'].replace('/activity','')
# show the previous posts # show the previous posts
@ -1268,7 +1296,9 @@ def htmlIndividualPost(baseDir: str,session,wfRequest: {},personCache: {}, \
postStr= \ postStr= \
individualPostAsHtml(baseDir,session,wfRequest,personCache, \ individualPostAsHtml(baseDir,session,wfRequest,personCache, \
nickname,domain,port,postJsonObject, \ nickname,domain,port,postJsonObject, \
None,True,False,False)+postStr None,True,False, \
httpPrefix,projectVersion, \
False)+postStr
# show the following posts # show the following posts
postFilename=locatePost(baseDir,nickname,domain,messageId) postFilename=locatePost(baseDir,nickname,domain,messageId)
@ -1283,18 +1313,21 @@ def htmlIndividualPost(baseDir: str,session,wfRequest: {},personCache: {}, \
for item in repliesJson['orderedItems']: for item in repliesJson['orderedItems']:
postStr+= \ postStr+= \
individualPostAsHtml(baseDir,session,wfRequest,personCache, \ individualPostAsHtml(baseDir,session,wfRequest,personCache, \
nickname,domain,port,item,None,True,False,False) nickname,domain,port,item,None,True,False, \
httpPrefix,projectVersion,False)
return htmlHeader()+postStr+htmlFooter() return htmlHeader()+postStr+htmlFooter()
def htmlPostReplies(baseDir: str,session,wfRequest: {},personCache: {}, \ def htmlPostReplies(baseDir: str,session,wfRequest: {},personCache: {}, \
nickname: str,domain: str,port: int,repliesJson: {}) -> str: nickname: str,domain: str,port: int,repliesJson: {}, \
httpPrefix: str,projectVersion: str) -> str:
"""Show the replies to an individual post as html """Show the replies to an individual post as html
""" """
repliesStr='' repliesStr=''
if repliesJson.get('orderedItems'): if repliesJson.get('orderedItems'):
for item in repliesJson['orderedItems']: for item in repliesJson['orderedItems']:
repliesStr+=individualPostAsHtml(baseDir,session,wfRequest,personCache, \ repliesStr+=individualPostAsHtml(baseDir,session,wfRequest,personCache, \
nickname,domain,port,item,None,True,False,False) nickname,domain,port,item,None,True,False, \
httpPrefix,projectVersion,False)
return htmlHeader()+repliesStr+htmlFooter() return htmlHeader()+repliesStr+htmlFooter()
@ -1453,7 +1486,7 @@ def htmlProfileAfterSearch(baseDir: str,path: str,httpPrefix: str, \
nickname: str,domain: str,port: int, \ nickname: str,domain: str,port: int, \
profileHandle: str, \ profileHandle: str, \
session,wfRequest: {},personCache: {}, session,wfRequest: {},personCache: {},
debug: bool) -> str: debug: bool,projectVersion: 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: if '/users/' in profileHandle:
@ -1491,14 +1524,15 @@ def htmlProfileAfterSearch(baseDir: str,path: str,httpPrefix: str, \
profileStr='' profileStr=''
with open(baseDir+'/epicyon-profile.css', 'r') as cssFile: with open(baseDir+'/epicyon-profile.css', 'r') as cssFile:
wf = webfingerHandle(session,searchNickname+'@'+searchDomainFull,httpPrefix,wfRequest) wf = webfingerHandle(session,searchNickname+'@'+searchDomainFull,httpPrefix,wfRequest, \
domain,projectVersion)
if not wf: if not wf:
if debug: if debug:
print('DEBUG: Unable to webfinger '+searchNickname+'@'+searchDomainFull) print('DEBUG: Unable to webfinger '+searchNickname+'@'+searchDomainFull)
return None return None
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 = getUserUrl(wf) personUrl = getUserUrl(wf)
profileJson = getJson(session,personUrl,asHeader,None) profileJson = getJson(session,personUrl,asHeader,None,projectVersion,httpPrefix,domain)
if not profileJson: if not profileJson:
if debug: if debug:
print('DEBUG: No actor returned from '+personUrl) print('DEBUG: No actor returned from '+personUrl)
@ -1566,7 +1600,8 @@ def htmlProfileAfterSearch(baseDir: str,path: str,httpPrefix: str, \
individualPostAsHtml(baseDir, \ individualPostAsHtml(baseDir, \
session,wfRequest,personCache, \ session,wfRequest,personCache, \
nickname,domain,port, \ nickname,domain,port, \
item,avatarUrl,False,False,False) item,avatarUrl,False,False, \
httpPrefix,projectVersion,False)
i+=1 i+=1
if i>=20: if i>=20:
break break