Include port in webfinger

master
Bob Mottram 2019-07-19 14:32:58 +01:00
parent b3375c175e
commit 8411b44721
5 changed files with 29 additions and 19 deletions

View File

@ -390,7 +390,10 @@ class PubServer(BaseHTTPRequestHandler):
# get an individual post from the path /@nickname/statusnumber
if '/@' in self.path:
namedStatus=self.path.split('/@')[1]
if '/' in namedStatus:
if '/' not in namedStatus:
# show actor
nickname=namedStatus
else:
postSections=namedStatus.split('/')
if len(postSections)==2:
nickname=postSections[0]

View File

@ -243,13 +243,17 @@ if args.testsnetwork:
testClientToServer()
sys.exit()
httpPrefix='https'
if args.http:
httpPrefix='http'
if args.posts:
if '@' not in args.posts:
print('Syntax: --posts nickname@domain')
sys.exit()
nickname=args.posts.split('@')[0]
domain=args.posts.split('@')[1]
getPublicPostsOfPerson(nickname,domain,False,True)
getPublicPostsOfPerson(nickname,domain,False,True,args.tor,args.port,httpPrefix)
sys.exit()
if args.postsraw:
@ -258,7 +262,7 @@ if args.postsraw:
sys.exit()
nickname=args.postsraw.split('@')[0]
domain=args.postsraw.split('@')[1]
getPublicPostsOfPerson(nickname,domain,True,False)
getPublicPostsOfPerson(nickname,domain,False,False,args.tor,args.port,httpPrefix)
sys.exit()
baseDir=args.baseDir
@ -284,10 +288,6 @@ nickname=None
if args.nickname:
nickname=nickname
httpPrefix='https'
if args.http:
httpPrefix='http'
federationList=[]
if args.federationList:
if len(args.federationList)==1:

View File

@ -1262,23 +1262,27 @@ def archivePostsForPerson(httpPrefix: str,nickname: str,domain: str,baseDir: str
break
def getPublicPostsOfPerson(nickname: str,domain: str, \
raw: bool,simple: bool) -> None:
raw: bool,simple: bool,useTor: bool, \
port: int,httpPrefix: str) -> None:
""" This is really just for test purposes
"""
useTor=True
port=443
print("Test1")
session = createSession(domain,port,useTor)
personCache={}
cachedWebfingers={}
federationList=[]
httpPrefix='https'
handle=httpPrefix+"://"+domain+"/@"+nickname
domainFull=domain
if port!=80 and port!=443:
domainFull=domain+':'+str(port)
handle=httpPrefix+"://"+domainFull+"/@"+nickname
print("Test2 "+handle)
wfRequest = \
webfingerHandle(session,handle,httpPrefix,cachedWebfingers)
if not wfRequest:
sys.exit()
print('Test3')
personUrl,pubKeyId,pubKey,personId,shaedInbox,capabilityAcquisition= \
getPersonBox(session,wfRequest,personCache,'outbox')
wfResult = json.dumps(wfRequest, indent=4, sort_keys=True)
@ -1286,6 +1290,7 @@ def getPublicPostsOfPerson(nickname: str,domain: str, \
maxMentions=10
maxEmoji=10
maxAttachments=5
print('personUrl: '+personUrl)
userPosts = getPosts(session,personUrl,30,maxMentions,maxEmoji, \
maxAttachments,federationList, \
personCache,raw,simple)

View File

@ -39,7 +39,10 @@ def getJson(session,url: str,headers: {},params: {}) -> {}:
result=session.get(url, headers=sessionHeaders, params=sessionParams)
return result.json()
except:
pass
print('ERROR: getJson failed')
print('url: '+url)
print('headers: '+str(sessionHeaders))
print('params: '+str(sessionParams))
return None
def postJson(session,postJsonObject: {},federationList: [],inboxUrl: str,headers: {},capability: str) -> str:

View File

@ -35,13 +35,13 @@ def parseHandle(handle: str) -> (str,str):
return nickname, domain
def webfingerHandle(session,handle: str,httpPrefix: str,cachedWebfingers: {}) -> {}:
if not session:
print('WARN: No session specified for webfingerHandle')
return None
nickname, domain = parseHandle(handle)
print('wfTest2 '+nickname+' '+domain)
if not nickname:
return None
wfDomain=domain
@ -53,14 +53,13 @@ def webfingerHandle(session,handle: str,httpPrefix: str,cachedWebfingers: {}) ->
url = '{}://{}/.well-known/webfinger'.format(httpPrefix,domain)
par = {'resource': 'acct:{}'.format(nickname+'@'+wfDomain)}
hdr = {'Accept': 'application/jrd+json'}
#print('webfinger url: '+url)
#print('webfinger par: '+str(par))
#print('webfinger hdr: '+str(hdr))
try:
result = getJson(session, url, hdr, par)
except:
print("Unable to webfinger " + url)
print('headers: '+str(hdr))
print('params: '+str(par))
return None
# print("Unable to webfinger " + url + ' ' + str(hdr) + ' ' + str(par))
storeWebfingerInCache(nickname+'@'+wfDomain,result,cachedWebfingers)
return result