mirror of https://gitlab.com/bashrc2/epicyon
Redirects all use the same function
parent
27b8a77729
commit
ed2b7b5c60
93
daemon.py
93
daemon.py
|
@ -527,9 +527,12 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
def _redirect_headers(self, redirect: str, cookie: str,
|
def _redirect_headers(self, redirect: str, cookie: str,
|
||||||
callingDomain: str) -> None:
|
callingDomain: str) -> None:
|
||||||
self.send_response(303)
|
self.send_response(303)
|
||||||
# self.send_header('Content-type', 'text/html')
|
|
||||||
if cookie:
|
if cookie:
|
||||||
self.send_header('Cookie', cookie)
|
if not cookie.startswith('SET:'):
|
||||||
|
self.send_header('Cookie', cookie)
|
||||||
|
else:
|
||||||
|
self.send_header('Set-Cookie',
|
||||||
|
cookie.replace('SET:', '').strip())
|
||||||
if '://' not in redirect:
|
if '://' not in redirect:
|
||||||
print('REDIRECT ERROR: redirect is not an absolute url ' +
|
print('REDIRECT ERROR: redirect is not an absolute url ' +
|
||||||
redirect)
|
redirect)
|
||||||
|
@ -986,21 +989,17 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.headers['Authorization'])
|
self.headers['Authorization'])
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _clearLoginDetails(self, nickname: str):
|
def _clearLoginDetails(self, nickname: str, callingDomain: str):
|
||||||
"""Clears login details for the given account
|
"""Clears login details for the given account
|
||||||
"""
|
"""
|
||||||
# remove any token
|
# remove any token
|
||||||
if self.server.tokens.get(nickname):
|
if self.server.tokens.get(nickname):
|
||||||
del self.server.tokensLookup[self.server.tokens[nickname]]
|
del self.server.tokensLookup[self.server.tokens[nickname]]
|
||||||
del self.server.tokens[nickname]
|
del self.server.tokens[nickname]
|
||||||
self.send_response(303)
|
self._redirect_headers(self.server.httpPrefix + '://' +
|
||||||
self.send_header('Content-Length', '0')
|
self.server.domainFull + '/login',
|
||||||
self.send_header('Set-Cookie', 'epicyon=; SameSite=Strict')
|
'epicyon=; SameSite=Strict',
|
||||||
self.send_header('Location',
|
callingDomain)
|
||||||
self.server.httpPrefix + '://' +
|
|
||||||
self.server.domainFull + '/login')
|
|
||||||
self.send_header('X-Robots-Tag', 'noindex')
|
|
||||||
self.end_headers()
|
|
||||||
|
|
||||||
def _benchmarkGETtimings(self, GETstartTime, GETtimings: [], getID: int):
|
def _benchmarkGETtimings(self, GETstartTime, GETtimings: [], getID: int):
|
||||||
"""Updates a list containing how long each segment of GET takes
|
"""Updates a list containing how long each segment of GET takes
|
||||||
|
@ -1642,24 +1641,22 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
str(divertToLoginScreen))
|
str(divertToLoginScreen))
|
||||||
print('DEBUG: authorized=' + str(authorized))
|
print('DEBUG: authorized=' + str(authorized))
|
||||||
print('DEBUG: path=' + self.path)
|
print('DEBUG: path=' + self.path)
|
||||||
self.send_response(303)
|
|
||||||
if callingDomain.endswith('.onion') and \
|
if callingDomain.endswith('.onion') and \
|
||||||
self.server.onionDomain:
|
self.server.onionDomain:
|
||||||
self.send_header('Location',
|
self._redirect_headers('http://' +
|
||||||
'http://' +
|
self.server.onionDomain +
|
||||||
self.server.onionDomain + '/login')
|
'/login',
|
||||||
|
None, callingDomain)
|
||||||
elif (callingDomain.endswith('.i2p') and
|
elif (callingDomain.endswith('.i2p') and
|
||||||
self.server.i2pDomain):
|
self.server.i2pDomain):
|
||||||
self.send_header('Location',
|
self._redirect_headers('http://' +
|
||||||
'i2p://' +
|
self.server.i2pDomain +
|
||||||
self.server.i2pDomain + '/login')
|
'/login',
|
||||||
|
None, callingDomain)
|
||||||
else:
|
else:
|
||||||
self.send_header('Location',
|
self._redirect_headers(self.server.httpPrefix + '://' +
|
||||||
self.server.httpPrefix + '://' +
|
self.server.domainFull +
|
||||||
self.server.domainFull + '/login')
|
'/login', None, callingDomain)
|
||||||
self.send_header('Content-Length', '0')
|
|
||||||
self.send_header('X-Robots-Tag', 'noindex')
|
|
||||||
self.end_headers()
|
|
||||||
return
|
return
|
||||||
|
|
||||||
self._benchmarkGETtimings(GETstartTime, GETtimings, 14)
|
self._benchmarkGETtimings(GETstartTime, GETtimings, 14)
|
||||||
|
@ -5658,7 +5655,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
loginNickname + '/outbox',
|
loginNickname + '/outbox',
|
||||||
authHeader, False):
|
authHeader, False):
|
||||||
print('Login failed: ' + loginNickname)
|
print('Login failed: ' + loginNickname)
|
||||||
self._clearLoginDetails(loginNickname)
|
self._clearLoginDetails(loginNickname, callingDomain)
|
||||||
self.server.POSTbusy = False
|
self.server.POSTbusy = False
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
@ -5672,7 +5669,6 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
return
|
return
|
||||||
# login success - redirect with authorization
|
# login success - redirect with authorization
|
||||||
print('Login success: ' + loginNickname)
|
print('Login success: ' + loginNickname)
|
||||||
self.send_response(303)
|
|
||||||
# re-activate account if needed
|
# re-activate account if needed
|
||||||
activateAccount(self.server.baseDir, loginNickname,
|
activateAccount(self.server.baseDir, loginNickname,
|
||||||
self.server.domain)
|
self.server.domain)
|
||||||
|
@ -5717,33 +5713,31 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
|
|
||||||
index = self.server.tokens[loginNickname]
|
index = self.server.tokens[loginNickname]
|
||||||
self.server.tokensLookup[index] = loginNickname
|
self.server.tokensLookup[index] = loginNickname
|
||||||
self.send_header('Set-Cookie',
|
cookieStr = 'SET:epicyon=' + \
|
||||||
'epicyon=' +
|
self.server.tokens[loginNickname] + '; SameSite=Strict'
|
||||||
self.server.tokens[loginNickname] +
|
|
||||||
'; SameSite=Strict')
|
|
||||||
if callingDomain.endswith('.onion') and \
|
if callingDomain.endswith('.onion') and \
|
||||||
self.server.onionDomain:
|
self.server.onionDomain:
|
||||||
self.send_header('Location',
|
self._redirect_headers('http://' +
|
||||||
'http://' +
|
self.server.onionDomain +
|
||||||
self.server.onionDomain +
|
'/users/' +
|
||||||
'/users/' + loginNickname + '/' +
|
loginNickname + '/' +
|
||||||
self.server.defaultTimeline)
|
self.server.defaultTimeline,
|
||||||
|
cookieStr, callingDomain)
|
||||||
elif (callingDomain.endswith('.i2p') and
|
elif (callingDomain.endswith('.i2p') and
|
||||||
self.server.i2pDomain):
|
self.server.i2pDomain):
|
||||||
self.send_header('Location',
|
self._redirect_headers('http://' +
|
||||||
'i2p://' +
|
self.server.i2pDomain +
|
||||||
self.server.i2pDomain +
|
'/users/' +
|
||||||
'/users/' + loginNickname + '/' +
|
loginNickname + '/' +
|
||||||
self.server.defaultTimeline)
|
self.server.defaultTimeline,
|
||||||
|
cookieStr, callingDomain)
|
||||||
else:
|
else:
|
||||||
self.send_header('Location',
|
self._redirect_headers(self.server.httpPrefix+'://' +
|
||||||
self.server.httpPrefix+'://' +
|
self.server.domainFull +
|
||||||
self.server.domainFull +
|
'/users/' +
|
||||||
'/users/' + loginNickname + '/' +
|
loginNickname + '/' +
|
||||||
self.server.defaultTimeline)
|
self.server.defaultTimeline,
|
||||||
self.send_header('Content-Length', '0')
|
cookieStr, callingDomain)
|
||||||
self.send_header('X-Robots-Tag', 'noindex')
|
|
||||||
self.end_headers()
|
|
||||||
self.server.POSTbusy = False
|
self.server.POSTbusy = False
|
||||||
return
|
return
|
||||||
self._200()
|
self._200()
|
||||||
|
@ -6362,7 +6356,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
deactivateAccount(self.server.baseDir,
|
deactivateAccount(self.server.baseDir,
|
||||||
nickname,
|
nickname,
|
||||||
self.server.domain)
|
self.server.domain)
|
||||||
self._clearLoginDetails(nickname)
|
self._clearLoginDetails(nickname,
|
||||||
|
callingDomain)
|
||||||
self.server.POSTbusy = False
|
self.server.POSTbusy = False
|
||||||
return
|
return
|
||||||
if callingDomain.endswith('.onion') and \
|
if callingDomain.endswith('.onion') and \
|
||||||
|
|
Loading…
Reference in New Issue