mirror of https://gitlab.com/bashrc2/epicyon
Move redirect to login screen to its own module
parent
eaac57228e
commit
0a656ab9ca
109
daemon.py
109
daemon.py
|
@ -6787,6 +6787,61 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self._404()
|
self._404()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def _redirectToLoginScreen(self, callingDomain: str, path: str,
|
||||||
|
httpPrefix: str, domainFull: str,
|
||||||
|
onionDomain: str, i2pDomain: str,
|
||||||
|
GETstartTime, GETtimings: {},
|
||||||
|
authorized: bool, debug: bool):
|
||||||
|
"""Redirects to the login screen if necessary
|
||||||
|
"""
|
||||||
|
divertToLoginScreen = False
|
||||||
|
if '/media/' not in path and \
|
||||||
|
'/sharefiles/' not in path and \
|
||||||
|
'/statuses/' not in path and \
|
||||||
|
'/emoji/' not in path and \
|
||||||
|
'/tags/' not in path and \
|
||||||
|
'/avatars/' not in path and \
|
||||||
|
'/fonts/' not in path and \
|
||||||
|
'/icons/' not in path:
|
||||||
|
divertToLoginScreen = True
|
||||||
|
if path.startswith('/users/'):
|
||||||
|
nickStr = path.split('/users/')[1]
|
||||||
|
if '/' not in nickStr and '?' not in nickStr:
|
||||||
|
divertToLoginScreen = False
|
||||||
|
else:
|
||||||
|
if path.endswith('/following') or \
|
||||||
|
'/following?page=' in path or \
|
||||||
|
path.endswith('/followers') or \
|
||||||
|
'/followers?page=' in path or \
|
||||||
|
path.endswith('/skills') or \
|
||||||
|
path.endswith('/roles') or \
|
||||||
|
path.endswith('/shares'):
|
||||||
|
divertToLoginScreen = False
|
||||||
|
|
||||||
|
if divertToLoginScreen and not authorized:
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: divertToLoginScreen=' +
|
||||||
|
str(divertToLoginScreen))
|
||||||
|
print('DEBUG: authorized=' + str(authorized))
|
||||||
|
print('DEBUG: path=' + path)
|
||||||
|
if callingDomain.endswith('.onion') and onionDomain:
|
||||||
|
self._redirect_headers('http://' +
|
||||||
|
onionDomain + '/login',
|
||||||
|
None, callingDomain)
|
||||||
|
elif callingDomain.endswith('.i2p') and i2pDomain:
|
||||||
|
self._redirect_headers('http://' +
|
||||||
|
i2pDomain + '/login',
|
||||||
|
None, callingDomain)
|
||||||
|
else:
|
||||||
|
self._redirect_headers(httpPrefix + '://' +
|
||||||
|
domainFull +
|
||||||
|
'/login', None, callingDomain)
|
||||||
|
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
||||||
|
'robots txt',
|
||||||
|
'show login screen')
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def do_GET(self):
|
def do_GET(self):
|
||||||
callingDomain = self.server.domainFull
|
callingDomain = self.server.domainFull
|
||||||
if self.headers.get('Host'):
|
if self.headers.get('Host'):
|
||||||
|
@ -7238,53 +7293,13 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
# if not authorized then show the login screen
|
# if not authorized then show the login screen
|
||||||
if htmlGET and self.path != '/login' and \
|
if htmlGET and self.path != '/login' and \
|
||||||
not self._pathIsImage(self.path) and self.path != '/':
|
not self._pathIsImage(self.path) and self.path != '/':
|
||||||
if '/media/' not in self.path and \
|
if self._redirectToLoginScreen(callingDomain, self.path,
|
||||||
'/sharefiles/' not in self.path and \
|
self.server.httpPrefix,
|
||||||
'/statuses/' not in self.path and \
|
self.server.domainFull,
|
||||||
'/emoji/' not in self.path and \
|
self.server.onionDomain,
|
||||||
'/tags/' not in self.path and \
|
self.server.i2pDomain,
|
||||||
'/avatars/' not in self.path and \
|
GETstartTime, GETtimings,
|
||||||
'/fonts/' not in self.path and \
|
authorized, self.server.debug):
|
||||||
'/icons/' not in self.path:
|
|
||||||
divertToLoginScreen = True
|
|
||||||
if self.path.startswith('/users/'):
|
|
||||||
nickStr = self.path.split('/users/')[1]
|
|
||||||
if '/' not in nickStr and '?' not in nickStr:
|
|
||||||
divertToLoginScreen = False
|
|
||||||
else:
|
|
||||||
if self.path.endswith('/following') or \
|
|
||||||
'/following?page=' in self.path or \
|
|
||||||
self.path.endswith('/followers') or \
|
|
||||||
'/followers?page=' in self.path or \
|
|
||||||
self.path.endswith('/skills') or \
|
|
||||||
self.path.endswith('/roles') or \
|
|
||||||
self.path.endswith('/shares'):
|
|
||||||
divertToLoginScreen = False
|
|
||||||
if divertToLoginScreen and not authorized:
|
|
||||||
if self.server.debug:
|
|
||||||
print('DEBUG: divertToLoginScreen=' +
|
|
||||||
str(divertToLoginScreen))
|
|
||||||
print('DEBUG: authorized=' + str(authorized))
|
|
||||||
print('DEBUG: path=' + self.path)
|
|
||||||
if callingDomain.endswith('.onion') and \
|
|
||||||
self.server.onionDomain:
|
|
||||||
self._redirect_headers('http://' +
|
|
||||||
self.server.onionDomain +
|
|
||||||
'/login',
|
|
||||||
None, callingDomain)
|
|
||||||
elif (callingDomain.endswith('.i2p') and
|
|
||||||
self.server.i2pDomain):
|
|
||||||
self._redirect_headers('http://' +
|
|
||||||
self.server.i2pDomain +
|
|
||||||
'/login',
|
|
||||||
None, callingDomain)
|
|
||||||
else:
|
|
||||||
self._redirect_headers(self.server.httpPrefix + '://' +
|
|
||||||
self.server.domainFull +
|
|
||||||
'/login', None, callingDomain)
|
|
||||||
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
|
||||||
'robots txt',
|
|
||||||
'show login screen')
|
|
||||||
return
|
return
|
||||||
|
|
||||||
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
||||||
|
|
Loading…
Reference in New Issue