merge-requests/30/head
Bob Mottram 2023-02-20 18:19:05 +00:00
parent aa533092dd
commit 132db64f0b
1 changed files with 25 additions and 150 deletions

173
daemon.py
View File

@ -954,12 +954,7 @@ class PubServer(BaseHTTPRequestHandler):
nickname = nickname.split('#/publicKey')[0] nickname = nickname.split('#/publicKey')[0]
else: else:
return None return None
if calling_domain.endswith('.onion'): actor = self._get_instance_url(calling_domain) + '/users/' + nickname
actor = 'http://' + onion_domain + '/users/' + nickname
elif calling_domain.endswith('.i2p'):
actor = 'http://' + i2p_domain + '/users/' + nickname
else:
actor = http_prefix + '://' + domain + '/users/' + nickname
actor_json = get_person_from_cache(base_dir, actor, person_cache) actor_json = get_person_from_cache(base_dir, actor, person_cache)
if not actor_json: if not actor_json:
actor_filename = acct_dir(base_dir, nickname, domain) + '.json' actor_filename = acct_dir(base_dir, nickname, domain) + '.json'
@ -1008,14 +1003,7 @@ class PubServer(BaseHTTPRequestHandler):
def _logout_redirect(self, redirect: str, cookie: str, def _logout_redirect(self, redirect: str, cookie: str,
calling_domain: str) -> None: calling_domain: str) -> None:
if '://' not in redirect: if '://' not in redirect:
if calling_domain.endswith('.onion') and self.server.onion_domain: redirect = self._get_instance_url(calling_domain) + redirect
redirect = 'http://' + self.server.onion_domain + redirect
elif calling_domain.endswith('.i2p') and self.server.i2p_domain:
redirect = 'http://' + self.server.i2p_domain + redirect
else:
redirect = \
self.server.http_prefix + '://' + \
self.server.domain_full + redirect
print('WARN: redirect was not an absolute url, changed to ' + print('WARN: redirect was not an absolute url, changed to ' +
redirect) redirect)
@ -1139,14 +1127,7 @@ class PubServer(BaseHTTPRequestHandler):
calling_domain: str, calling_domain: str,
code: int = 303) -> None: code: int = 303) -> None:
if '://' not in redirect: if '://' not in redirect:
if calling_domain.endswith('.onion') and self.server.onion_domain: redirect = self._get_instance_url(calling_domain) + redirect
redirect = 'http://' + self.server.onion_domain + redirect
elif calling_domain.endswith('.i2p') and self.server.i2p_domain:
redirect = 'http://' + self.server.i2p_domain + redirect
else:
redirect = \
self.server.http_prefix + '://' + \
self.server.domain_full + redirect
print('WARN: redirect was not an absolute url, changed to ' + print('WARN: redirect was not an absolute url, changed to ' +
redirect) redirect)
@ -2391,36 +2372,18 @@ class PubServer(BaseHTTPRequestHandler):
if register: if register:
if not valid_password(login_password): if not valid_password(login_password):
self.server.postreq_busy = False self.server.postreq_busy = False
if calling_domain.endswith('.onion') and onion_domain: login_url = \
self._redirect_headers('http://' + onion_domain + self._get_instance_url(calling_domain) + '/login'
'/login', cookie, self._redirect_headers(login_url, cookie, calling_domain)
calling_domain)
elif (calling_domain.endswith('.i2p') and i2p_domain):
self._redirect_headers('http://' + i2p_domain +
'/login', cookie,
calling_domain)
else:
self._redirect_headers(http_prefix + '://' +
domain_full + '/login',
cookie, calling_domain)
return return
if not register_account(base_dir, http_prefix, domain, port, if not register_account(base_dir, http_prefix, domain, port,
login_nickname, login_password, login_nickname, login_password,
self.server.manual_follower_approval): self.server.manual_follower_approval):
self.server.postreq_busy = False self.server.postreq_busy = False
if calling_domain.endswith('.onion') and onion_domain: login_url = \
self._redirect_headers('http://' + onion_domain + self._get_instance_url(calling_domain) + '/login'
'/login', cookie, self._redirect_headers(login_url, cookie, calling_domain)
calling_domain)
elif (calling_domain.endswith('.i2p') and i2p_domain):
self._redirect_headers('http://' + i2p_domain +
'/login', cookie,
calling_domain)
else:
self._redirect_headers(http_prefix + '://' +
domain_full + '/login',
cookie, calling_domain)
return return
auth_header = \ auth_header = \
create_basic_auth_header(login_nickname, login_password) create_basic_auth_header(login_nickname, login_password)
@ -2510,26 +2473,9 @@ class PubServer(BaseHTTPRequestHandler):
self.server.tokens_lookup[index] = login_nickname self.server.tokens_lookup[index] = login_nickname
cookie_str = 'SET:epicyon=' + \ cookie_str = 'SET:epicyon=' + \
self.server.tokens[login_nickname] + '; SameSite=Strict' self.server.tokens[login_nickname] + '; SameSite=Strict'
if calling_domain.endswith('.onion') and onion_domain: tl_url = self._get_instance_url(calling_domain) + '/users/' + \
self._redirect_headers('http://' + login_nickname + '/' + self.server.default_timeline
onion_domain + self._redirect_headers(tl_url, cookie_str, calling_domain)
'/users/' +
login_nickname + '/' +
self.server.default_timeline,
cookie_str, calling_domain)
elif (calling_domain.endswith('.i2p') and i2p_domain):
self._redirect_headers('http://' +
i2p_domain +
'/users/' +
login_nickname + '/' +
self.server.default_timeline,
cookie_str, calling_domain)
else:
self._redirect_headers(http_prefix + '://' +
domain_full + '/users/' +
login_nickname + '/' +
self.server.default_timeline,
cookie_str, calling_domain)
self.server.postreq_busy = False self.server.postreq_busy = False
return return
else: else:
@ -8914,15 +8860,8 @@ class PubServer(BaseHTTPRequestHandler):
cookie, calling_domain) cookie, calling_domain)
return return
if calling_domain.endswith('.onion') and onion_domain:
origin_path_str_absolute = \ origin_path_str_absolute = \
'http://' + onion_domain + origin_path_str self._get_instance_url(calling_domain) + origin_path_str
elif calling_domain.endswith('.i2p') and i2p_domain:
origin_path_str_absolute = \
'http://' + i2p_domain + origin_path_str
else:
origin_path_str_absolute = \
http_prefix + '://' + domain_full + origin_path_str
self._redirect_headers(origin_path_str_absolute, cookie, self._redirect_headers(origin_path_str_absolute, cookie,
calling_domain) calling_domain)
@ -15756,12 +15695,7 @@ class PubServer(BaseHTTPRequestHandler):
self._404() self._404()
return False return False
accept_str = self.headers['Accept'] accept_str = self.headers['Accept']
if onion_domain and calling_domain.endswith('.onion'): actor_domain_url = self._get_instance_url(calling_domain)
actor_domain_url = 'http://' + onion_domain
elif i2p_domain and calling_domain.endswith('.i2p'):
actor_domain_url = 'http://' + i2p_domain
else:
actor_domain_url = http_prefix + '://' + domain_full
actor_url = actor_domain_url + '/users/Actor' actor_url = actor_domain_url + '/users/Actor'
remove_fields = ( remove_fields = (
'icon', 'image', 'tts', 'shares', 'icon', 'image', 'tts', 'shares',
@ -15921,18 +15855,8 @@ class PubServer(BaseHTTPRequestHandler):
str(divert_to_login_screen)) str(divert_to_login_screen))
print('DEBUG: authorized=' + str(authorized)) print('DEBUG: authorized=' + str(authorized))
print('DEBUG: path=' + path) print('DEBUG: path=' + path)
if calling_domain.endswith('.onion') and onion_domain: redirect_url = self._get_instance_url(calling_domain) + divert_path
self._redirect_headers('http://' + self._redirect_headers(redirect_url, None, calling_domain)
onion_domain + divert_path,
None, calling_domain)
elif calling_domain.endswith('.i2p') and i2p_domain:
self._redirect_headers('http://' +
i2p_domain + divert_path,
None, calling_domain)
else:
self._redirect_headers(http_prefix + '://' +
domain_full +
divert_path, None, calling_domain)
fitness_performance(getreq_start_time, fitness_performance(getreq_start_time,
self.server.fitness, self.server.fitness,
'_GET', '_redirect_to_login_screen', '_GET', '_redirect_to_login_screen',
@ -16966,24 +16890,9 @@ class PubServer(BaseHTTPRequestHandler):
self._logout_headers('text/html', msglen, calling_domain) self._logout_headers('text/html', msglen, calling_domain)
self._write(msg) self._write(msg)
else: else:
if calling_domain.endswith('.onion') and \ news_url = \
self.server.onion_domain: self._get_instance_url(calling_domain) + '/users/news'
self._logout_redirect('http://' + self._logout_redirect(news_url, None, calling_domain)
self.server.onion_domain +
'/users/news', None,
calling_domain)
elif (calling_domain.endswith('.i2p') and
self.server.i2p_domain):
self._logout_redirect('http://' +
self.server.i2p_domain +
'/users/news', None,
calling_domain)
else:
self._logout_redirect(self.server.http_prefix +
'://' +
self.server.domain_full +
'/users/news',
None, calling_domain)
fitness_performance(getreq_start_time, self.server.fitness, fitness_performance(getreq_start_time, self.server.fitness,
'_GET', 'logout', '_GET', 'logout',
self.server.debug) self.server.debug)
@ -18763,24 +18672,8 @@ class PubServer(BaseHTTPRequestHandler):
if self.path == '/' and \ if self.path == '/' and \
not authorized and \ not authorized and \
self.server.news_instance: self.server.news_instance:
if calling_domain.endswith('.onion') and \ news_url = self._get_instance_url(calling_domain) + '/users/news'
self.server.onion_domain: self._logout_redirect(news_url, None, calling_domain)
self._logout_redirect('http://' +
self.server.onion_domain +
'/users/news', None,
calling_domain)
elif (calling_domain.endswith('.i2p') and
self.server.i2p_domain):
self._logout_redirect('http://' +
self.server.i2p_domain +
'/users/news', None,
calling_domain)
else:
self._logout_redirect(self.server.http_prefix +
'://' +
self.server.domain_full +
'/users/news',
None, calling_domain)
fitness_performance(getreq_start_time, self.server.fitness, fitness_performance(getreq_start_time, self.server.fitness,
'_GET', 'news front page shown', '_GET', 'news front page shown',
self.server.debug) self.server.debug)
@ -18947,27 +18840,9 @@ class PubServer(BaseHTTPRequestHandler):
if os.path.isfile(tags_filename): if os.path.isfile(tags_filename):
# redirect to the local hashtag screen # redirect to the local hashtag screen
self.server.getreq_busy = False self.server.getreq_busy = False
if calling_domain.endswith('.onion') and \ ht_url = self._get_instance_url(calling_domain) + \
self.server.onion_domain: '/users/' + nickname + '/tags/' + hashtag
self._redirect_headers('http://' + self._redirect_headers(ht_url, cookie, calling_domain)
self.server.onion_domain +
'/users/' +
nickname + '/tags/' +
hashtag, cookie, calling_domain)
elif (calling_domain.endswith('.i2p') and
self.server.i2p_domain):
self._redirect_headers('http://' +
self.server.i2p_domain +
'/users/' +
nickname + '/tags/' +
hashtag, cookie, calling_domain)
else:
self._redirect_headers(self.server.http_prefix +
'://' +
self.server.domain_full +
'/users/' + nickname +
'/tags/' + hashtag,
cookie, calling_domain)
else: else:
# redirect to the upstream hashtag url # redirect to the upstream hashtag url
self.server.getreq_busy = False self.server.getreq_busy = False