Webfinger debug

master
Bob Mottram 2019-07-19 15:19:36 +01:00
parent 369d8cee7c
commit bc93a289f8
2 changed files with 18 additions and 6 deletions

View File

@ -97,7 +97,7 @@ class PubServer(BaseHTTPRequestHandler):
if self.server.debug: if self.server.debug:
print('DEBUG: WEBFINGER lookup '+self.path+' '+str(self.server.baseDir)) print('DEBUG: WEBFINGER lookup '+self.path+' '+str(self.server.baseDir))
wfResult=webfingerLookup(self.path,self.server.baseDir) wfResult=webfingerLookup(self.path,self.server.baseDir,self.server.debug)
if wfResult: if wfResult:
self._set_headers('application/jrd+json') self._set_headers('application/jrd+json')
self.wfile.write(json.dumps(wfResult).encode('utf-8')) self.wfile.write(json.dumps(wfResult).encode('utf-8'))

View File

@ -149,7 +149,7 @@ def webfingerMeta() -> str:
" </Link>" \ " </Link>" \
"</XRD>" "</XRD>"
def webfingerLookup(path: str,baseDir: str) -> {}: def webfingerLookup(path: str,baseDir: str,debug: bool) -> {}:
"""Lookup the webfinger endpoint for an account """Lookup the webfinger endpoint for an account
""" """
if not path.startswith('/.well-known/webfinger?'): if not path.startswith('/.well-known/webfinger?'):
@ -157,19 +157,31 @@ def webfingerLookup(path: str,baseDir: str) -> {}:
handle=None handle=None
if 'resource=acct:' in path: if 'resource=acct:' in path:
handle=path.split('resource=acct:')[1].strip() handle=path.split('resource=acct:')[1].strip()
if debug:
print('DEBUG: WEBFINGER handle '+handle)
else: else:
if 'resource=acct%3A' in path: if 'resource=acct%3A' in path:
handle=path.split('resource=acct%3A')[1].replace('%40','@').replace('%3A',':').strip() handle=path.split('resource=acct%3A')[1].replace('%40','@').replace('%3A',':').strip()
print("======== "+path) if debug:
print("======== "+handle) print('DEBUG: WEBFINGER handle '+handle)
if not handle: if not handle:
if debug:
print('DEBUG: WEBFINGER handle missing')
return None return None
if '&' in handle: if '&' in handle:
handle=handle.split('&')[0].strip() handle=handle.split('&')[0].strip()
if debug:
print('DEBUG: WEBFINGER handle with & removed '+handle)
if '@' not in handle: if '@' not in handle:
if debug:
print('DEBUG: WEBFINGER no @ in handle '+handle)
return None return None
filename=baseDir+'/wfendpoints/'+handle.lower()+'.json' filename=baseDir+'/wfendpoints/'+handle.lower()+'.json'
if debug:
print('DEBUG: WEBFINGER filename'+filename)
if not os.path.isfile(filename): if not os.path.isfile(filename):
if debug:
print('DEBUG: WEBFINGER filename not found '+filename)
return None return None
wfJson={"nickname": "unknown"} wfJson={"nickname": "unknown"}
with open(filename, 'r') as fp: with open(filename, 'r') as fp: