mirror of https://gitlab.com/bashrc2/epicyon
Tidy pwa manifest
parent
47d68b3c4e
commit
7043f79355
170
daemon.py
170
daemon.py
|
@ -3435,86 +3435,10 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self._redirect_headers(actorStr, cookie, callingDomain)
|
self._redirect_headers(actorStr, cookie, callingDomain)
|
||||||
self.server.POSTbusy = False
|
self.server.POSTbusy = False
|
||||||
|
|
||||||
def do_GET(self):
|
def _progressiveWebAppManifest(self, callingDomain: str,
|
||||||
callingDomain = self.server.domainFull
|
GETstartTime, GETtimings: {}):
|
||||||
if self.headers.get('Host'):
|
"""gets the PWA manifest
|
||||||
callingDomain = self.headers['Host']
|
"""
|
||||||
if self.server.onionDomain:
|
|
||||||
if callingDomain != self.server.domain and \
|
|
||||||
callingDomain != self.server.domainFull and \
|
|
||||||
callingDomain != self.server.onionDomain:
|
|
||||||
print('GET domain blocked: ' + callingDomain)
|
|
||||||
self._400()
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
if callingDomain != self.server.domain and \
|
|
||||||
callingDomain != self.server.domainFull:
|
|
||||||
print('GET domain blocked: ' + callingDomain)
|
|
||||||
self._400()
|
|
||||||
return
|
|
||||||
|
|
||||||
GETstartTime = time.time()
|
|
||||||
GETtimings = {}
|
|
||||||
|
|
||||||
self._benchmarkGETtimings(GETstartTime, GETtimings, None, 'start')
|
|
||||||
|
|
||||||
# Since fediverse crawlers are quite active,
|
|
||||||
# make returning info to them high priority
|
|
||||||
# get nodeinfo endpoint
|
|
||||||
if self._nodeinfo(callingDomain):
|
|
||||||
return
|
|
||||||
|
|
||||||
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
|
||||||
'start', '_nodeinfo(callingDomain)')
|
|
||||||
|
|
||||||
# minimal mastodon api
|
|
||||||
if self._mastoApi(callingDomain):
|
|
||||||
return
|
|
||||||
|
|
||||||
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
|
||||||
'_nodeinfo(callingDomain)',
|
|
||||||
'_mastoApi(callingDomain)')
|
|
||||||
|
|
||||||
if self.path == '/logout':
|
|
||||||
msg = \
|
|
||||||
htmlLogin(self.server.translate,
|
|
||||||
self.server.baseDir, False).encode('utf-8')
|
|
||||||
self._logout_headers('text/html', len(msg), callingDomain)
|
|
||||||
self._write(msg)
|
|
||||||
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
|
||||||
'_nodeinfo(callingDomain)',
|
|
||||||
'logout')
|
|
||||||
return
|
|
||||||
|
|
||||||
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
|
||||||
'_nodeinfo(callingDomain)',
|
|
||||||
'show logout')
|
|
||||||
|
|
||||||
# replace https://domain/@nick with https://domain/users/nick
|
|
||||||
if self.path.startswith('/@'):
|
|
||||||
self.path = self.path.replace('/@', '/users/')
|
|
||||||
|
|
||||||
# redirect music to #nowplaying list
|
|
||||||
if self.path == '/music' or self.path == '/nowplaying':
|
|
||||||
self.path = '/tags/nowplaying'
|
|
||||||
|
|
||||||
if self.server.debug:
|
|
||||||
print('DEBUG: GET from ' + self.server.baseDir +
|
|
||||||
' path: ' + self.path + ' busy: ' +
|
|
||||||
str(self.server.GETbusy))
|
|
||||||
|
|
||||||
if self.server.debug:
|
|
||||||
print(str(self.headers))
|
|
||||||
|
|
||||||
cookie = None
|
|
||||||
if self.headers.get('Cookie'):
|
|
||||||
cookie = self.headers['Cookie']
|
|
||||||
|
|
||||||
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
|
||||||
'show logout', 'get cookie')
|
|
||||||
|
|
||||||
# manifest for progressive web apps
|
|
||||||
if '/manifest.json' in self.path:
|
|
||||||
app1 = "https://f-droid.org/en/packages/eu.siacs.conversations"
|
app1 = "https://f-droid.org/en/packages/eu.siacs.conversations"
|
||||||
app2 = "https://staging.f-droid.org/en/packages/im.vector.app"
|
app2 = "https://staging.f-droid.org/en/packages/im.vector.app"
|
||||||
manifest = {
|
manifest = {
|
||||||
|
@ -3598,14 +3522,96 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
}
|
}
|
||||||
msg = json.dumps(manifest,
|
msg = json.dumps(manifest,
|
||||||
ensure_ascii=False).encode('utf-8')
|
ensure_ascii=False).encode('utf-8')
|
||||||
self._set_headers('application/json',
|
self._set_headers('application/json', len(msg),
|
||||||
len(msg),
|
|
||||||
None, callingDomain)
|
None, callingDomain)
|
||||||
self._write(msg)
|
self._write(msg)
|
||||||
if self.server.debug:
|
if self.server.debug:
|
||||||
print('Sent manifest: ' + callingDomain)
|
print('Sent manifest: ' + callingDomain)
|
||||||
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
||||||
'show logout', 'send manifest')
|
'show logout', 'send manifest')
|
||||||
|
|
||||||
|
def do_GET(self):
|
||||||
|
callingDomain = self.server.domainFull
|
||||||
|
if self.headers.get('Host'):
|
||||||
|
callingDomain = self.headers['Host']
|
||||||
|
if self.server.onionDomain:
|
||||||
|
if callingDomain != self.server.domain and \
|
||||||
|
callingDomain != self.server.domainFull and \
|
||||||
|
callingDomain != self.server.onionDomain:
|
||||||
|
print('GET domain blocked: ' + callingDomain)
|
||||||
|
self._400()
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
if callingDomain != self.server.domain and \
|
||||||
|
callingDomain != self.server.domainFull:
|
||||||
|
print('GET domain blocked: ' + callingDomain)
|
||||||
|
self._400()
|
||||||
|
return
|
||||||
|
|
||||||
|
GETstartTime = time.time()
|
||||||
|
GETtimings = {}
|
||||||
|
|
||||||
|
self._benchmarkGETtimings(GETstartTime, GETtimings, None, 'start')
|
||||||
|
|
||||||
|
# Since fediverse crawlers are quite active,
|
||||||
|
# make returning info to them high priority
|
||||||
|
# get nodeinfo endpoint
|
||||||
|
if self._nodeinfo(callingDomain):
|
||||||
|
return
|
||||||
|
|
||||||
|
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
||||||
|
'start', '_nodeinfo(callingDomain)')
|
||||||
|
|
||||||
|
# minimal mastodon api
|
||||||
|
if self._mastoApi(callingDomain):
|
||||||
|
return
|
||||||
|
|
||||||
|
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
||||||
|
'_nodeinfo(callingDomain)',
|
||||||
|
'_mastoApi(callingDomain)')
|
||||||
|
|
||||||
|
if self.path == '/logout':
|
||||||
|
msg = \
|
||||||
|
htmlLogin(self.server.translate,
|
||||||
|
self.server.baseDir, False).encode('utf-8')
|
||||||
|
self._logout_headers('text/html', len(msg), callingDomain)
|
||||||
|
self._write(msg)
|
||||||
|
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
||||||
|
'_nodeinfo(callingDomain)',
|
||||||
|
'logout')
|
||||||
|
return
|
||||||
|
|
||||||
|
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
||||||
|
'_nodeinfo(callingDomain)',
|
||||||
|
'show logout')
|
||||||
|
|
||||||
|
# replace https://domain/@nick with https://domain/users/nick
|
||||||
|
if self.path.startswith('/@'):
|
||||||
|
self.path = self.path.replace('/@', '/users/')
|
||||||
|
|
||||||
|
# redirect music to #nowplaying list
|
||||||
|
if self.path == '/music' or self.path == '/nowplaying':
|
||||||
|
self.path = '/tags/nowplaying'
|
||||||
|
|
||||||
|
if self.server.debug:
|
||||||
|
print('DEBUG: GET from ' + self.server.baseDir +
|
||||||
|
' path: ' + self.path + ' busy: ' +
|
||||||
|
str(self.server.GETbusy))
|
||||||
|
|
||||||
|
if self.server.debug:
|
||||||
|
print(str(self.headers))
|
||||||
|
|
||||||
|
cookie = None
|
||||||
|
if self.headers.get('Cookie'):
|
||||||
|
cookie = self.headers['Cookie']
|
||||||
|
|
||||||
|
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
||||||
|
'show logout', 'get cookie')
|
||||||
|
|
||||||
|
# manifest for progressive web apps
|
||||||
|
if '/manifest.json' in self.path:
|
||||||
|
self._progressiveWebAppManifest(callingDomain,
|
||||||
|
GETstartTime, GETtimings)
|
||||||
return
|
return
|
||||||
|
|
||||||
# favicon image
|
# favicon image
|
||||||
|
|
Loading…
Reference in New Issue