mirror of https://gitlab.com/bashrc2/epicyon
Tidy endpoint for removal of shared items
parent
433dbbccd3
commit
5a44e82106
119
daemon.py
119
daemon.py
|
@ -2139,6 +2139,64 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
cookie, callingDomain)
|
cookie, callingDomain)
|
||||||
self.server.POSTbusy = False
|
self.server.POSTbusy = False
|
||||||
|
|
||||||
|
def _removeShare(self, callingDomain: str, cookie: str,
|
||||||
|
authorized: bool, path: str,
|
||||||
|
baseDir: str, httpPrefix: str,
|
||||||
|
domain: str, domainFull: str,
|
||||||
|
onionDomain: str, i2pDomain: str, debug: bool):
|
||||||
|
"""Removes a shared item
|
||||||
|
"""
|
||||||
|
usersPath = path.split('/rmshare')[0]
|
||||||
|
originPathStr = httpPrefix + '://' + domainFull + usersPath
|
||||||
|
|
||||||
|
length = int(self.headers['Content-length'])
|
||||||
|
|
||||||
|
try:
|
||||||
|
removeShareConfirmParams = \
|
||||||
|
self.rfile.read(length).decode('utf-8')
|
||||||
|
except SocketError as e:
|
||||||
|
if e.errno == errno.ECONNRESET:
|
||||||
|
print('WARN: POST removeShareConfirmParams ' +
|
||||||
|
'connection was reset')
|
||||||
|
else:
|
||||||
|
print('WARN: POST removeShareConfirmParams socket error')
|
||||||
|
self.send_response(400)
|
||||||
|
self.end_headers()
|
||||||
|
self.server.POSTbusy = False
|
||||||
|
return
|
||||||
|
except ValueError as e:
|
||||||
|
print('ERROR: POST removeShareConfirmParams rfile.read failed')
|
||||||
|
print(e)
|
||||||
|
self.send_response(400)
|
||||||
|
self.end_headers()
|
||||||
|
self.server.POSTbusy = False
|
||||||
|
return
|
||||||
|
|
||||||
|
if '&submitYes=' in removeShareConfirmParams:
|
||||||
|
removeShareConfirmParams = \
|
||||||
|
removeShareConfirmParams.replace('+', ' ').strip()
|
||||||
|
removeShareConfirmParams = \
|
||||||
|
urllib.parse.unquote_plus(removeShareConfirmParams)
|
||||||
|
shareActor = removeShareConfirmParams.split('actor=')[1]
|
||||||
|
if '&' in shareActor:
|
||||||
|
shareActor = shareActor.split('&')[0]
|
||||||
|
shareName = removeShareConfirmParams.split('shareName=')[1]
|
||||||
|
if '&' in shareName:
|
||||||
|
shareName = shareName.split('&')[0]
|
||||||
|
shareNickname = getNicknameFromActor(shareActor)
|
||||||
|
if shareNickname:
|
||||||
|
shareDomain, sharePort = getDomainFromActor(shareActor)
|
||||||
|
removeShare(baseDir,
|
||||||
|
shareNickname, shareDomain, shareName)
|
||||||
|
|
||||||
|
if callingDomain.endswith('.onion') and onionDomain:
|
||||||
|
originPathStr = 'http://' + onionDomain + usersPath
|
||||||
|
elif (callingDomain.endswith('.i2p') and i2pDomain):
|
||||||
|
originPathStr = 'http://' + i2pDomain + usersPath
|
||||||
|
self._redirect_headers(originPathStr + '/tlshares',
|
||||||
|
cookie, callingDomain)
|
||||||
|
self.server.POSTbusy = False
|
||||||
|
|
||||||
def _removePost(self, callingDomain: str, cookie: str,
|
def _removePost(self, callingDomain: str, cookie: str,
|
||||||
authorized: bool, path: str,
|
authorized: bool, path: str,
|
||||||
baseDir: str, httpPrefix: str,
|
baseDir: str, httpPrefix: str,
|
||||||
|
@ -9009,58 +9067,15 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
|
|
||||||
# removes a shared item
|
# removes a shared item
|
||||||
if authorized and self.path.endswith('/rmshare'):
|
if authorized and self.path.endswith('/rmshare'):
|
||||||
usersPath = self.path.split('/rmshare')[0]
|
self._removeShare(callingDomain, cookie,
|
||||||
originPathStr = \
|
authorized, self.path,
|
||||||
self.server.httpPrefix + '://' + \
|
self.server.baseDir,
|
||||||
self.server.domainFull + usersPath
|
self.server.httpPrefix,
|
||||||
length = int(self.headers['Content-length'])
|
self.server.domain,
|
||||||
try:
|
self.server.domainFull,
|
||||||
removeShareConfirmParams = \
|
self.server.onionDomain,
|
||||||
self.rfile.read(length).decode('utf-8')
|
self.server.i2pDomain,
|
||||||
except SocketError as e:
|
self.server.debug)
|
||||||
if e.errno == errno.ECONNRESET:
|
|
||||||
print('WARN: POST removeShareConfirmParams ' +
|
|
||||||
'connection was reset')
|
|
||||||
else:
|
|
||||||
print('WARN: POST removeShareConfirmParams socket error')
|
|
||||||
self.send_response(400)
|
|
||||||
self.end_headers()
|
|
||||||
self.server.POSTbusy = False
|
|
||||||
return
|
|
||||||
except ValueError as e:
|
|
||||||
print('ERROR: POST removeShareConfirmParams rfile.read failed')
|
|
||||||
print(e)
|
|
||||||
self.send_response(400)
|
|
||||||
self.end_headers()
|
|
||||||
self.server.POSTbusy = False
|
|
||||||
return
|
|
||||||
if '&submitYes=' in removeShareConfirmParams:
|
|
||||||
removeShareConfirmParams = \
|
|
||||||
removeShareConfirmParams.replace('+', ' ').strip()
|
|
||||||
removeShareConfirmParams = \
|
|
||||||
urllib.parse.unquote_plus(removeShareConfirmParams)
|
|
||||||
shareActor = removeShareConfirmParams.split('actor=')[1]
|
|
||||||
if '&' in shareActor:
|
|
||||||
shareActor = shareActor.split('&')[0]
|
|
||||||
shareName = removeShareConfirmParams.split('shareName=')[1]
|
|
||||||
if '&' in shareName:
|
|
||||||
shareName = shareName.split('&')[0]
|
|
||||||
shareNickname = getNicknameFromActor(shareActor)
|
|
||||||
if shareNickname:
|
|
||||||
shareDomain, sharePort = getDomainFromActor(shareActor)
|
|
||||||
removeShare(self.server.baseDir,
|
|
||||||
shareNickname, shareDomain, shareName)
|
|
||||||
if callingDomain.endswith('.onion') and \
|
|
||||||
self.server.onionDomain:
|
|
||||||
originPathStr = \
|
|
||||||
'http://' + self.server.onionDomain + usersPath
|
|
||||||
elif (callingDomain.endswith('.i2p') and
|
|
||||||
self.server.i2pDomain):
|
|
||||||
originPathStr = \
|
|
||||||
'http://' + self.server.i2pDomain + usersPath
|
|
||||||
self._redirect_headers(originPathStr + '/tlshares',
|
|
||||||
cookie, callingDomain)
|
|
||||||
self.server.POSTbusy = False
|
|
||||||
return
|
return
|
||||||
|
|
||||||
self._benchmarkPOSTtimings(POSTstartTime, POSTtimings, 8)
|
self._benchmarkPOSTtimings(POSTstartTime, POSTtimings, 8)
|
||||||
|
|
Loading…
Reference in New Issue