main
Bob Mottram 2024-04-23 13:24:13 +01:00
parent ae8f845d08
commit 38000f73b9
3 changed files with 27 additions and 15 deletions

View File

@ -1250,7 +1250,9 @@ def daemon_http_get(self) -> None:
referer_domain, referer_domain,
self.server.debug, self.server.debug,
self.server.known_crawlers, self.server.known_crawlers,
self.server.sites_unavailable): self.server.sites_unavailable,
self.server.unit_test,
self.server.allow_local_network_access):
return return
fitness_performance(getreq_start_time, self.server.fitness, fitness_performance(getreq_start_time, self.server.fitness,
@ -1379,7 +1381,8 @@ def daemon_http_get(self) -> None:
proxy_type, proxy_type,
getreq_start_time, getreq_start_time,
self.server.debug, self.server.debug,
curr_session) curr_session,
self.server.fitness)
return return
if self.path == '/newswire.xml': if self.path == '/newswire.xml':

View File

@ -262,7 +262,7 @@ def get_hashtag_categories_feed2(self, calling_domain: str, path: str,
base_dir: str, proxy_type: str, base_dir: str, proxy_type: str,
getreq_start_time, getreq_start_time,
debug: bool, debug: bool,
curr_session) -> None: curr_session, fitness: {}) -> None:
"""Returns the hashtag categories feed """Returns the hashtag categories feed
""" """
curr_session = \ curr_session = \
@ -285,7 +285,7 @@ def get_hashtag_categories_feed2(self, calling_domain: str, path: str,
if debug: if debug:
print('Sent rss2 categories feed: ' + print('Sent rss2 categories feed: ' +
path + ' ' + calling_domain) path + ' ' + calling_domain)
fitness_performance(getreq_start_time, self.server.fitness, fitness_performance(getreq_start_time, fitness,
'_GET', '_get_hashtag_categories_feed', debug) '_GET', '_get_hashtag_categories_feed', debug)
return return
if debug: if debug:

View File

@ -38,7 +38,9 @@ def masto_api(self, path: str, calling_domain: str,
show_node_info_accounts: bool, show_node_info_accounts: bool,
referer_domain: str, debug: bool, referer_domain: str, debug: bool,
known_crawlers: {}, known_crawlers: {},
sites_unavailable: []) -> bool: sites_unavailable: [],
unit_test: bool,
allow_local_network_access: bool) -> bool:
if _masto_api_v2(self, path, calling_domain, ua_str, authorized, if _masto_api_v2(self, path, calling_domain, ua_str, authorized,
http_prefix, base_dir, nickname, domain, http_prefix, base_dir, nickname, domain,
domain_full, onion_domain, i2p_domain, domain_full, onion_domain, i2p_domain,
@ -46,7 +48,8 @@ def masto_api(self, path: str, calling_domain: str,
project_version, project_version,
show_node_info_accounts, show_node_info_accounts,
referer_domain, debug, 5, referer_domain, debug, 5,
known_crawlers, sites_unavailable): known_crawlers, sites_unavailable, unit_test,
allow_local_network_access):
return True return True
return _masto_api_v1(self, path, calling_domain, ua_str, authorized, return _masto_api_v1(self, path, calling_domain, ua_str, authorized,
http_prefix, base_dir, nickname, domain, http_prefix, base_dir, nickname, domain,
@ -55,7 +58,9 @@ def masto_api(self, path: str, calling_domain: str,
project_version, custom_emoji, project_version, custom_emoji,
show_node_info_accounts, show_node_info_accounts,
referer_domain, debug, 5, referer_domain, debug, 5,
known_crawlers, sites_unavailable) known_crawlers, sites_unavailable,
unit_test,
allow_local_network_access)
def _masto_api_v1(self, path: str, calling_domain: str, def _masto_api_v1(self, path: str, calling_domain: str,
@ -75,7 +80,9 @@ def _masto_api_v1(self, path: str, calling_domain: str,
debug: bool, debug: bool,
calling_site_timeout: int, calling_site_timeout: int,
known_crawlers: {}, known_crawlers: {},
sites_unavailable: []) -> bool: sites_unavailable: [],
unit_test: bool,
allow_local_network_access: bool) -> bool:
"""This is a vestigil mastodon API for the purpose """This is a vestigil mastodon API for the purpose
of returning an empty result to sites like of returning an empty result to sites like
https://mastopeek.app-dist.eu https://mastopeek.app-dist.eu
@ -84,7 +91,7 @@ def _masto_api_v1(self, path: str, calling_domain: str,
return False return False
if not referer_domain: if not referer_domain:
if not (debug and self.server.unit_test): if not (debug and unit_test):
print('mastodon api request has no referer domain ' + print('mastodon api request has no referer domain ' +
str(ua_str)) str(ua_str))
http_400(self) http_400(self)
@ -100,7 +107,7 @@ def _masto_api_v1(self, path: str, calling_domain: str,
return True return True
self.server.masto_api_is_active = True self.server.masto_api_is_active = True
# is this a real website making the call ? # 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? # Does calling_domain look like a domain?
if ' ' in referer_domain or \ if ' ' in referer_domain or \
';' in referer_domain or \ ';' in referer_domain or \
@ -111,7 +118,7 @@ def _masto_api_v1(self, path: str, calling_domain: str,
http_400(self) http_400(self)
self.server.masto_api_is_active = False self.server.masto_api_is_active = False
return True return True
if not self.server.allow_local_network_access: if not allow_local_network_access:
if local_network_host(referer_domain): if local_network_host(referer_domain):
print('mastodon api referer domain is from the ' + print('mastodon api referer domain is from the ' +
'local network ' + referer_domain) 'local network ' + referer_domain)
@ -202,7 +209,9 @@ def _masto_api_v2(self, path: str, calling_domain: str,
debug: bool, debug: bool,
calling_site_timeout: int, calling_site_timeout: int,
known_crawlers: {}, known_crawlers: {},
sites_unavailable: []) -> bool: sites_unavailable: [],
unit_test: bool,
allow_local_network_access: bool) -> bool:
"""This is a vestigil mastodon v2 API for the purpose """This is a vestigil mastodon v2 API for the purpose
of returning an empty result to sites like of returning an empty result to sites like
https://mastopeek.app-dist.eu https://mastopeek.app-dist.eu
@ -211,7 +220,7 @@ def _masto_api_v2(self, path: str, calling_domain: str,
return False return False
if not referer_domain: if not referer_domain:
if not (debug and self.server.unit_test): if not (debug and unit_test):
print('mastodon api v2 request has no referer domain ' + print('mastodon api v2 request has no referer domain ' +
str(ua_str)) str(ua_str))
http_400(self) http_400(self)
@ -227,7 +236,7 @@ def _masto_api_v2(self, path: str, calling_domain: str,
return True return True
self.server.masto_api_is_active = True self.server.masto_api_is_active = True
# is this a real website making the call ? # 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? # Does calling_domain look like a domain?
if ' ' in referer_domain or \ if ' ' in referer_domain or \
';' in referer_domain or \ ';' in referer_domain or \
@ -238,7 +247,7 @@ def _masto_api_v2(self, path: str, calling_domain: str,
http_400(self) http_400(self)
self.server.masto_api_is_active = False self.server.masto_api_is_active = False
return True return True
if not self.server.allow_local_network_access: if not allow_local_network_access:
if local_network_host(referer_domain): if local_network_host(referer_domain):
print('mastodon api v2 referer domain is from the ' + print('mastodon api v2 referer domain is from the ' +
'local network ' + referer_domain) 'local network ' + referer_domain)