main
Bob Mottram 2024-04-12 11:19:56 +01:00
parent fbb91fc8f1
commit 48f0830db9
2 changed files with 51 additions and 59 deletions

View File

@ -2628,7 +2628,15 @@ def daemon_http_get(self) -> None:
return return
# get webfinger endpoint for a person # get webfinger endpoint for a person
if get_webfinger(self, calling_domain, referer_domain, cookie): if get_webfinger(self, calling_domain, referer_domain, cookie,
self.path, self.server.debug,
self.server.onion_domain,
self.server.i2p_domain,
self.server.http_prefix,
self.server.domain,
self.server.domain_full,
self.server.base_dir,
self.server.port):
fitness_performance(getreq_start_time, self.server.fitness, fitness_performance(getreq_start_time, self.server.fitness,
'_GET', 'webfinger called', '_GET', 'webfinger called',
self.server.debug) self.server.debug)

View File

@ -22,27 +22,29 @@ from daemon_utils import has_accept
def get_webfinger(self, calling_domain: str, referer_domain: str, def get_webfinger(self, calling_domain: str, referer_domain: str,
cookie: str) -> bool: cookie: str, path: str, debug: bool,
if not self.path.startswith('/.well-known'): onion_domain: str, i2p_domain: str,
http_prefix: str, domain: str, domain_full: str,
base_dir: str, port: int) -> bool:
if not path.startswith('/.well-known'):
return False return False
if self.server.debug: if debug:
print('DEBUG: WEBFINGER well-known') print('DEBUG: WEBFINGER well-known')
if self.server.debug: if debug:
print('DEBUG: WEBFINGER host-meta') print('DEBUG: WEBFINGER host-meta')
if self.path.startswith('/.well-known/host-meta'): if path.startswith('/.well-known/host-meta'):
if calling_domain.endswith('.onion') and \ if calling_domain.endswith('.onion') and \
self.server.onion_domain: onion_domain:
wf_result = \ wf_result = \
webfinger_meta('http', self.server.onion_domain) webfinger_meta('http', onion_domain)
elif (calling_domain.endswith('.i2p') and elif (calling_domain.endswith('.i2p') and
self.server.i2p_domain): i2p_domain):
wf_result = \ wf_result = \
webfinger_meta('http', self.server.i2p_domain) webfinger_meta('http', i2p_domain)
else: else:
wf_result = \ wf_result = \
webfinger_meta(self.server.http_prefix, webfinger_meta(http_prefix, domain_full)
self.server.domain_full)
if wf_result: if wf_result:
msg = wf_result.encode('utf-8') msg = wf_result.encode('utf-8')
msglen = len(msg) msglen = len(msg)
@ -52,28 +54,24 @@ def get_webfinger(self, calling_domain: str, referer_domain: str,
return True return True
http_404(self, 6) http_404(self, 6)
return True return True
if self.path.startswith('/api/statusnet') or \ if path.startswith('/api/statusnet') or \
self.path.startswith('/api/gnusocial') or \ path.startswith('/api/gnusocial') or \
self.path.startswith('/siteinfo') or \ path.startswith('/siteinfo') or \
self.path.startswith('/poco') or \ path.startswith('/poco') or \
self.path.startswith('/friendi'): path.startswith('/friendi'):
http_404(self, 7) http_404(self, 7)
return True return True
# protocol handler. See https://fedi-to.github.io/protocol-handler.html # protocol handler. See https://fedi-to.github.io/protocol-handler.html
if self.path.startswith('/.well-known/protocol-handler'): if path.startswith('/.well-known/protocol-handler'):
if calling_domain.endswith('.onion'): if calling_domain.endswith('.onion'):
protocol_url, _ = \ protocol_url, _ = \
wellknown_protocol_handler(self.path, 'http', wellknown_protocol_handler(path, 'http', onion_domain)
self.server.onion_domain)
elif calling_domain.endswith('.i2p'): elif calling_domain.endswith('.i2p'):
protocol_url, _ = \ protocol_url, _ = \
wellknown_protocol_handler(self.path, wellknown_protocol_handler(path, 'http', i2p_domain)
'http', self.server.i2p_domain)
else: else:
protocol_url, _ = \ protocol_url, _ = \
wellknown_protocol_handler(self.path, wellknown_protocol_handler(path, http_prefix, domain_full)
self.server.http_prefix,
self.server.domain_full)
if protocol_url: if protocol_url:
redirect_headers(self, protocol_url, cookie, redirect_headers(self, protocol_url, cookie,
calling_domain, 308) calling_domain, 308)
@ -81,29 +79,22 @@ def get_webfinger(self, calling_domain: str, referer_domain: str,
http_404(self, 8) http_404(self, 8)
return True return True
# nodeinfo # nodeinfo
if self.path.startswith('/.well-known/nodeinfo') or \ if path.startswith('/.well-known/nodeinfo') or \
self.path.startswith('/.well-known/x-nodeinfo'): path.startswith('/.well-known/x-nodeinfo'):
if calling_domain.endswith('.onion') and \ if calling_domain.endswith('.onion') and onion_domain:
self.server.onion_domain:
wf_result = \ wf_result = \
webfinger_node_info('http', self.server.onion_domain) webfinger_node_info('http', onion_domain)
elif (calling_domain.endswith('.i2p') and elif (calling_domain.endswith('.i2p') and i2p_domain):
self.server.i2p_domain):
wf_result = \ wf_result = \
webfinger_node_info('http', self.server.i2p_domain) webfinger_node_info('http', i2p_domain)
else: else:
wf_result = \ wf_result = \
webfinger_node_info(self.server.http_prefix, webfinger_node_info(http_prefix, domain_full)
self.server.domain_full)
if wf_result: if wf_result:
msg_str = json.dumps(wf_result) msg_str = json.dumps(wf_result)
msg_str = convert_domains(calling_domain, msg_str = convert_domains(calling_domain, referer_domain,
referer_domain, msg_str, http_prefix, domain,
msg_str, onion_domain, i2p_domain)
self.server.http_prefix,
self.server.domain,
self.server.onion_domain,
self.server.i2p_domain)
msg = msg_str.encode('utf-8') msg = msg_str.encode('utf-8')
msglen = len(msg) msglen = len(msg)
if has_accept(self, calling_domain): if has_accept(self, calling_domain):
@ -120,31 +111,24 @@ def get_webfinger(self, calling_domain: str, referer_domain: str,
http_404(self, 9) http_404(self, 9)
return True return True
if self.server.debug: if debug:
print('DEBUG: WEBFINGER lookup ' + self.path + ' ' + print('DEBUG: WEBFINGER lookup ' + path + ' ' + str(base_dir))
str(self.server.base_dir))
wf_result = \ wf_result = \
webfinger_lookup(self.path, self.server.base_dir, webfinger_lookup(path, base_dir,
self.server.domain, domain, onion_domain,
self.server.onion_domain, i2p_domain, port, debug)
self.server.i2p_domain,
self.server.port, self.server.debug)
if wf_result: if wf_result:
msg_str = json.dumps(wf_result) msg_str = json.dumps(wf_result)
msg_str = convert_domains(calling_domain, msg_str = convert_domains(calling_domain, referer_domain,
referer_domain, msg_str, http_prefix, domain,
msg_str, onion_domain, i2p_domain)
self.server.http_prefix,
self.server.domain,
self.server.onion_domain,
self.server.i2p_domain)
msg = msg_str.encode('utf-8') msg = msg_str.encode('utf-8')
msglen = len(msg) msglen = len(msg)
set_headers(self, 'application/jrd+json', msglen, set_headers(self, 'application/jrd+json', msglen,
None, calling_domain, True) None, calling_domain, True)
write2(self, msg) write2(self, msg)
else: else:
if self.server.debug: if debug:
print('DEBUG: WEBFINGER lookup 404 ' + self.path) print('DEBUG: WEBFINGER lookup 404 ' + path)
http_404(self, 10) http_404(self, 10)
return True return True