main
Bob Mottram 2024-04-11 17:29:29 +01:00
parent dde3f6231b
commit ed647fb23d
2 changed files with 45 additions and 21 deletions

View File

@ -331,7 +331,20 @@ def daemon_http_get(self) -> None:
# get nodeinfo endpoint
if get_nodeinfo(self, ua_str, calling_domain, referer_domain,
self.server.http_prefix, 5, self.server.debug,
self.server.base_dir):
self.server.base_dir,
self.server.unit_test,
self.server.domain_full,
self.path,
self.server.allow_local_network_access,
self.server.sites_unavailable,
self.server.known_crawlers,
self.server.onion_domain,
self.server.i2p_domain,
self.server.project_version,
self.server.show_node_info_version,
self.server.show_node_info_accounts,
self.server.registration,
self.server.domain):
return
fitness_performance(getreq_start_time, self.server.fitness,

View File

@ -25,18 +25,30 @@ from metadata import meta_data_node_info
def get_nodeinfo(self, ua_str: str, calling_domain: str,
referer_domain: str,
http_prefix: str, calling_site_timeout: int,
debug: bool, base_dir: str) -> bool:
if self.path.startswith('/nodeinfo/1.0'):
debug: bool, base_dir: str,
unit_test: bool,
domain_full: str,
path: str,
allow_local_network_access: bool,
sites_unavailable: [],
known_crawlers: [],
onion_domain: str,
i2p_domain: str,
project_version: str,
show_node_info_version: bool,
show_node_info_accounts: bool,
registration: bool, domain: str) -> bool:
if path.startswith('/nodeinfo/1.0'):
http_400(self)
return True
if not self.path.startswith('/nodeinfo/2.'):
if not path.startswith('/nodeinfo/2.'):
return False
if not referer_domain:
if not debug and not self.server.unit_test:
if not debug and not unit_test:
print('nodeinfo request has no referer domain ' + str(ua_str))
http_400(self)
return True
if referer_domain == self.server.domain_full:
if referer_domain == domain_full:
print('nodeinfo request from self')
http_400(self)
return True
@ -49,7 +61,7 @@ def get_nodeinfo(self, ua_str: str, calling_domain: str,
return True
self.server.nodeinfo_is_active = True
# is this a real website making the call ?
if not debug and not self.server.unit_test and referer_domain:
if not debug and not unit_test and referer_domain:
# Does calling_domain look like a domain?
if ' ' in referer_domain or \
';' in referer_domain or \
@ -59,7 +71,7 @@ def get_nodeinfo(self, ua_str: str, calling_domain: str,
http_400(self)
self.server.nodeinfo_is_active = False
return True
if not self.server.allow_local_network_access:
if not allow_local_network_access:
if local_network_host(referer_domain):
print('nodeinfo referer domain is from the ' +
'local network ' + referer_domain)
@ -70,18 +82,18 @@ def get_nodeinfo(self, ua_str: str, calling_domain: str,
if not referer_is_active(http_prefix,
referer_domain, ua_str,
calling_site_timeout,
self.server.sites_unavailable):
sites_unavailable):
print('nodeinfo referer url is not active ' +
referer_domain)
http_400(self)
self.server.nodeinfo_is_active = False
return True
if debug:
print('DEBUG: nodeinfo ' + self.path)
print('DEBUG: nodeinfo ' + path)
crawl_time = \
update_known_crawlers(ua_str,
base_dir,
self.server.known_crawlers,
known_crawlers,
self.server.last_known_crawler)
if crawl_time is not None:
self.server.last_known_crawler = crawl_time
@ -93,33 +105,32 @@ def get_nodeinfo(self, ua_str: str, calling_domain: str,
# migrate, and that information may be useful to an adversary
broch_mode = broch_mode_is_active(base_dir)
node_info_version = self.server.project_version
if not self.server.show_node_info_version or broch_mode:
node_info_version = project_version
if not show_node_info_version or broch_mode:
node_info_version = '0.0.0'
show_node_info_accounts = self.server.show_node_info_accounts
if broch_mode:
show_node_info_accounts = False
instance_url = get_instance_url(calling_domain,
http_prefix,
self.server.domain_full,
self.server.onion_domain,
self.server.i2p_domain)
domain_full,
onion_domain,
i2p_domain)
about_url = instance_url + '/about'
terms_of_service_url = instance_url + '/terms'
info = meta_data_node_info(base_dir,
about_url, terms_of_service_url,
self.server.registration,
registration,
node_info_version,
show_node_info_accounts)
if info:
msg_str = json.dumps(info)
msg_str = convert_domains(calling_domain, referer_domain,
msg_str, http_prefix,
self.server.domain,
self.server.onion_domain,
self.server.i2p_domain)
domain,
onion_domain,
i2p_domain)
msg = msg_str.encode('utf-8')
msglen = len(msg)
protocol_str = \