mirror of https://gitlab.com/bashrc2/epicyon
Show user agent rather than calling domain
parent
e617de5f14
commit
d36d1817fd
|
@ -969,6 +969,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _mastoApiV1(self, path: str, callingDomain: str,
|
def _mastoApiV1(self, path: str, callingDomain: str,
|
||||||
|
uaStr: str,
|
||||||
authorized: bool,
|
authorized: bool,
|
||||||
httpPrefix: str,
|
httpPrefix: str,
|
||||||
baseDir: str, nickname: str, domain: str,
|
baseDir: str, nickname: str, domain: str,
|
||||||
|
@ -993,6 +994,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
brochMode = brochModeIsActive(baseDir)
|
brochMode = brochModeIsActive(baseDir)
|
||||||
sendJson, sendJsonStr = mastoApiV1Response(path,
|
sendJson, sendJsonStr = mastoApiV1Response(path,
|
||||||
callingDomain,
|
callingDomain,
|
||||||
|
uaStr,
|
||||||
authorized,
|
authorized,
|
||||||
httpPrefix,
|
httpPrefix,
|
||||||
baseDir,
|
baseDir,
|
||||||
|
@ -1031,6 +1033,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _mastoApi(self, path: str, callingDomain: str,
|
def _mastoApi(self, path: str, callingDomain: str,
|
||||||
|
uaStr: str,
|
||||||
authorized: bool, httpPrefix: str,
|
authorized: bool, httpPrefix: str,
|
||||||
baseDir: str, nickname: str, domain: str,
|
baseDir: str, nickname: str, domain: str,
|
||||||
domainFull: str,
|
domainFull: str,
|
||||||
|
@ -1041,7 +1044,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
projectVersion: str,
|
projectVersion: str,
|
||||||
customEmoji: [],
|
customEmoji: [],
|
||||||
showNodeInfoAccounts: bool) -> bool:
|
showNodeInfoAccounts: bool) -> bool:
|
||||||
return self._mastoApiV1(path, callingDomain, authorized,
|
return self._mastoApiV1(path, callingDomain, uaStr, authorized,
|
||||||
httpPrefix, baseDir, nickname, domain,
|
httpPrefix, baseDir, nickname, domain,
|
||||||
domainFull, onionDomain, i2pDomain,
|
domainFull, onionDomain, i2pDomain,
|
||||||
translate, registration, systemLanguage,
|
translate, registration, systemLanguage,
|
||||||
|
@ -12446,7 +12449,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
return
|
return
|
||||||
|
|
||||||
# minimal mastodon api
|
# minimal mastodon api
|
||||||
if self._mastoApi(self.path, callingDomain, authorized,
|
if self._mastoApi(self.path, callingDomain, uaStr,
|
||||||
|
authorized,
|
||||||
self.server.httpPrefix,
|
self.server.httpPrefix,
|
||||||
self.server.baseDir,
|
self.server.baseDir,
|
||||||
self.authorizedNickname,
|
self.authorizedNickname,
|
||||||
|
|
|
@ -82,6 +82,7 @@ def _getMastoApiV1Account(baseDir: str, nickname: str, domain: str) -> {}:
|
||||||
|
|
||||||
|
|
||||||
def mastoApiV1Response(path: str, callingDomain: str,
|
def mastoApiV1Response(path: str, callingDomain: str,
|
||||||
|
uaStr: str,
|
||||||
authorized: bool,
|
authorized: bool,
|
||||||
httpPrefix: str,
|
httpPrefix: str,
|
||||||
baseDir: str, nickname: str, domain: str,
|
baseDir: str, nickname: str, domain: str,
|
||||||
|
@ -100,6 +101,8 @@ def mastoApiV1Response(path: str, callingDomain: str,
|
||||||
"""
|
"""
|
||||||
sendJson = None
|
sendJson = None
|
||||||
sendJsonStr = ''
|
sendJsonStr = ''
|
||||||
|
if not uaStr:
|
||||||
|
uaStr = ''
|
||||||
|
|
||||||
# parts of the api needing authorization
|
# parts of the api needing authorization
|
||||||
if authorized and nickname:
|
if authorized and nickname:
|
||||||
|
@ -123,33 +126,33 @@ def mastoApiV1Response(path: str, callingDomain: str,
|
||||||
sendJson = []
|
sendJson = []
|
||||||
sendJsonStr = \
|
sendJsonStr = \
|
||||||
'masto API followers sent for ' + nickname + \
|
'masto API followers sent for ' + nickname + \
|
||||||
' ' + callingDomain
|
' ' + uaStr
|
||||||
elif path.endswith('/following'):
|
elif path.endswith('/following'):
|
||||||
sendJson = []
|
sendJson = []
|
||||||
sendJsonStr = \
|
sendJsonStr = \
|
||||||
'masto API following sent for ' + nickname + \
|
'masto API following sent for ' + nickname + \
|
||||||
' ' + callingDomain
|
' ' + uaStr
|
||||||
elif path.endswith('/statuses'):
|
elif path.endswith('/statuses'):
|
||||||
sendJson = []
|
sendJson = []
|
||||||
sendJsonStr = \
|
sendJsonStr = \
|
||||||
'masto API statuses sent for ' + nickname + \
|
'masto API statuses sent for ' + nickname + \
|
||||||
' ' + callingDomain
|
' ' + uaStr
|
||||||
elif path.endswith('/search'):
|
elif path.endswith('/search'):
|
||||||
sendJson = []
|
sendJson = []
|
||||||
sendJsonStr = \
|
sendJsonStr = \
|
||||||
'masto API search sent ' + originalPath + \
|
'masto API search sent ' + originalPath + \
|
||||||
' ' + callingDomain
|
' ' + uaStr
|
||||||
elif path.endswith('/relationships'):
|
elif path.endswith('/relationships'):
|
||||||
sendJson = []
|
sendJson = []
|
||||||
sendJsonStr = \
|
sendJsonStr = \
|
||||||
'masto API relationships sent ' + originalPath + \
|
'masto API relationships sent ' + originalPath + \
|
||||||
' ' + callingDomain
|
' ' + uaStr
|
||||||
else:
|
else:
|
||||||
sendJson = \
|
sendJson = \
|
||||||
_getMastoApiV1Account(baseDir, pathNickname, domain)
|
_getMastoApiV1Account(baseDir, pathNickname, domain)
|
||||||
sendJsonStr = \
|
sendJsonStr = \
|
||||||
'masto API account sent for ' + nickname + \
|
'masto API account sent for ' + nickname + \
|
||||||
' ' + callingDomain
|
' ' + uaStr
|
||||||
|
|
||||||
# NOTE: adding support for '/api/v1/directory seems to create
|
# NOTE: adding support for '/api/v1/directory seems to create
|
||||||
# federation problems, so avoid implementing that
|
# federation problems, so avoid implementing that
|
||||||
|
@ -157,37 +160,37 @@ def mastoApiV1Response(path: str, callingDomain: str,
|
||||||
if path.startswith('/api/v1/blocks'):
|
if path.startswith('/api/v1/blocks'):
|
||||||
sendJson = []
|
sendJson = []
|
||||||
sendJsonStr = \
|
sendJsonStr = \
|
||||||
'masto API instance blocks sent ' + path + ' ' + callingDomain
|
'masto API instance blocks sent ' + path + ' ' + uaStr
|
||||||
elif path.startswith('/api/v1/favorites'):
|
elif path.startswith('/api/v1/favorites'):
|
||||||
sendJson = []
|
sendJson = []
|
||||||
sendJsonStr = 'masto API favorites sent ' + path + ' ' + callingDomain
|
sendJsonStr = 'masto API favorites sent ' + path + ' ' + uaStr
|
||||||
elif path.startswith('/api/v1/follow_requests'):
|
elif path.startswith('/api/v1/follow_requests'):
|
||||||
sendJson = []
|
sendJson = []
|
||||||
sendJsonStr = \
|
sendJsonStr = \
|
||||||
'masto API follow requests sent ' + path + ' ' + callingDomain
|
'masto API follow requests sent ' + path + ' ' + uaStr
|
||||||
elif path.startswith('/api/v1/mutes'):
|
elif path.startswith('/api/v1/mutes'):
|
||||||
sendJson = []
|
sendJson = []
|
||||||
sendJsonStr = \
|
sendJsonStr = \
|
||||||
'masto API mutes sent ' + path + ' ' + callingDomain
|
'masto API mutes sent ' + path + ' ' + uaStr
|
||||||
elif path.startswith('/api/v1/notifications'):
|
elif path.startswith('/api/v1/notifications'):
|
||||||
sendJson = []
|
sendJson = []
|
||||||
sendJsonStr = \
|
sendJsonStr = \
|
||||||
'masto API notifications sent ' + path + ' ' + callingDomain
|
'masto API notifications sent ' + path + ' ' + uaStr
|
||||||
elif path.startswith('/api/v1/reports'):
|
elif path.startswith('/api/v1/reports'):
|
||||||
sendJson = []
|
sendJson = []
|
||||||
sendJsonStr = 'masto API reports sent ' + path + ' ' + callingDomain
|
sendJsonStr = 'masto API reports sent ' + path + ' ' + uaStr
|
||||||
elif path.startswith('/api/v1/statuses'):
|
elif path.startswith('/api/v1/statuses'):
|
||||||
sendJson = []
|
sendJson = []
|
||||||
sendJsonStr = 'masto API statuses sent ' + path + ' ' + callingDomain
|
sendJsonStr = 'masto API statuses sent ' + path + ' ' + uaStr
|
||||||
elif path.startswith('/api/v1/timelines'):
|
elif path.startswith('/api/v1/timelines'):
|
||||||
sendJson = {
|
sendJson = {
|
||||||
'error': 'This method requires an authenticated user'
|
'error': 'This method requires an authenticated user'
|
||||||
}
|
}
|
||||||
sendJsonStr = 'masto API timelines sent ' + path + ' ' + callingDomain
|
sendJsonStr = 'masto API timelines sent ' + path + ' ' + uaStr
|
||||||
elif path.startswith('/api/v1/custom_emojis'):
|
elif path.startswith('/api/v1/custom_emojis'):
|
||||||
sendJson = customEmoji
|
sendJson = customEmoji
|
||||||
sendJsonStr = \
|
sendJsonStr = \
|
||||||
'masto API custom emojis sent ' + path + ' ' + callingDomain
|
'masto API custom emojis sent ' + path + ' ' + uaStr
|
||||||
|
|
||||||
adminNickname = getConfigParam(baseDir, 'admin')
|
adminNickname = getConfigParam(baseDir, 'admin')
|
||||||
if adminNickname and path == '/api/v1/instance':
|
if adminNickname and path == '/api/v1/instance':
|
||||||
|
@ -224,7 +227,7 @@ def mastoApiV1Response(path: str, callingDomain: str,
|
||||||
registration,
|
registration,
|
||||||
systemLanguage,
|
systemLanguage,
|
||||||
projectVersion)
|
projectVersion)
|
||||||
sendJsonStr = 'masto API instance metadata sent ' + callingDomain
|
sendJsonStr = 'masto API instance metadata sent ' + uaStr
|
||||||
elif path.startswith('/api/v1/instance/peers'):
|
elif path.startswith('/api/v1/instance/peers'):
|
||||||
# This is just a dummy result.
|
# This is just a dummy result.
|
||||||
# Showing the full list of peers would have privacy implications.
|
# Showing the full list of peers would have privacy implications.
|
||||||
|
@ -232,8 +235,8 @@ def mastoApiV1Response(path: str, callingDomain: str,
|
||||||
# small instances a full list of peers would convey a lot of
|
# small instances a full list of peers would convey a lot of
|
||||||
# information about the interests of a small number of accounts
|
# information about the interests of a small number of accounts
|
||||||
sendJson = ['mastodon.social', domainFull]
|
sendJson = ['mastodon.social', domainFull]
|
||||||
sendJsonStr = 'masto API peers metadata sent ' + callingDomain
|
sendJsonStr = 'masto API peers metadata sent ' + uaStr
|
||||||
elif path.startswith('/api/v1/instance/activity'):
|
elif path.startswith('/api/v1/instance/activity'):
|
||||||
sendJson = []
|
sendJson = []
|
||||||
sendJsonStr = 'masto API activity metadata sent ' + callingDomain
|
sendJsonStr = 'masto API activity metadata sent ' + uaStr
|
||||||
return sendJson, sendJsonStr
|
return sendJson, sendJsonStr
|
||||||
|
|
Loading…
Reference in New Issue