Better support for dual use of onion address

main
Bob Mottram 2020-03-27 18:11:34 +00:00
parent 7a7bcee064
commit 6e7b2e5eb9
1 changed files with 176 additions and 36 deletions

212
daemon.py
View File

@ -1176,7 +1176,11 @@ class PubServer(BaseHTTPRequestHandler):
self._set_headers('text/html',len(msg),cookie) self._set_headers('text/html',len(msg),cookie)
self._write(msg) self._write(msg)
return return
originPathStrAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+originPathStr if not callingDomain.endswith('.onion') or \
not self.server.onionDomain:
originPathStrAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+originPathStr
else:
originPathStrAbsolute='http://'+self.server.onionDomain+originPathStr
self._redirect_headers(originPathStrAbsolute,cookie) self._redirect_headers(originPathStrAbsolute,cookie)
return return
@ -1211,13 +1215,15 @@ class PubServer(BaseHTTPRequestHandler):
if htmlGET and '?rmshare=' in self.path: if htmlGET and '?rmshare=' in self.path:
shareName=self.path.split('?rmshare=')[1] shareName=self.path.split('?rmshare=')[1]
shareName=shareName.replace('%20',' ').replace('%40','@').replace('%3A',':').replace('%2F','/').replace('%23','#').strip() shareName=shareName.replace('%20',' ').replace('%40','@').replace('%3A',':').replace('%2F','/').replace('%23','#').strip()
usersPath=self.path.split('?rmshare=')[0]
actor= \ actor= \
self.server.httpPrefix+'://'+self.server.domainFull+ \ self.server.httpPrefix+'://'+self.server.domainFull+usersPath
self.path.split('?rmshare=')[0]
msg=htmlRemoveSharedItem(self.server.translate, \ msg=htmlRemoveSharedItem(self.server.translate, \
self.server.baseDir, \ self.server.baseDir, \
actor,shareName).encode() actor,shareName).encode()
if not msg: if not msg:
if callingDomain.endswith('.onion') and self.server.onionDomain:
actor='http://'+self.server.onionDomain+usersPath
self._redirect_headers(actor+'/tlshares',cookie) self._redirect_headers(actor+'/tlshares',cookie)
return return
self._set_headers('text/html',len(msg),cookie) self._set_headers('text/html',len(msg),cookie)
@ -1691,6 +1697,8 @@ class PubServer(BaseHTTPRequestHandler):
else: else:
originPathStr=self.path.split('/tags/')[0] originPathStr=self.path.split('/tags/')[0]
originPathStrAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+originPathStr originPathStrAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+originPathStr
if callingDomain.endswith('.onion') and self.server.onionDomain:
originPathStrAbsolute='http://'+self.server.onionDomain+originPathStr
self._redirect_headers(originPathStrAbsolute+'/search',cookie) self._redirect_headers(originPathStrAbsolute+'/search',cookie)
self.server.GETbusy=False self.server.GETbusy=False
return return
@ -1758,6 +1766,10 @@ class PubServer(BaseHTTPRequestHandler):
actor= \ actor= \
self.server.httpPrefix+'://'+self.server.domainFull+ \ self.server.httpPrefix+'://'+self.server.domainFull+ \
self.path.split('/eventdelete')[0] self.path.split('/eventdelete')[0]
if callingDomain.endswith('.onion') and self.server.onionDomain:
actor= \
'http://'+self.server.onionDomain+ \
self.path.split('/eventdelete')[0]
self._redirect_headers(actor+'/calendar',cookie) self._redirect_headers(actor+'/calendar',cookie)
return return
msg=msg.encode() msg=msg.encode()
@ -1815,6 +1827,8 @@ class PubServer(BaseHTTPRequestHandler):
print('WARN: unable to find nickname in '+actor) print('WARN: unable to find nickname in '+actor)
self.server.GETbusy=False self.server.GETbusy=False
actorAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+actor actorAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+actor
if callingDomain.endswith('.onion') and self.server.onionDomain:
actorAbsolute='http://'+self.server.onionDomain+actor
self._redirect_headers(actorAbsolute+'/'+timelineStr+ \ self._redirect_headers(actorAbsolute+'/'+timelineStr+ \
'?page='+str(pageNumber),cookie) '?page='+str(pageNumber),cookie)
return return
@ -1844,6 +1858,8 @@ class PubServer(BaseHTTPRequestHandler):
self._postToOutboxThread(announceJson) self._postToOutboxThread(announceJson)
self.server.GETbusy=False self.server.GETbusy=False
actorAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+actor actorAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+actor
if callingDomain.endswith('.onion') and self.server.onionDomain:
actorAbsolute='http://'+self.server.onionDomain+actor
self._redirect_headers(actorAbsolute+'/'+timelineStr+'?page='+ \ self._redirect_headers(actorAbsolute+'/'+timelineStr+'?page='+ \
str(pageNumber)+ \ str(pageNumber)+ \
timelineBookmark,cookie) timelineBookmark,cookie)
@ -1884,6 +1900,8 @@ class PubServer(BaseHTTPRequestHandler):
print('WARN: unable to find nickname in '+actor) print('WARN: unable to find nickname in '+actor)
self.server.GETbusy=False self.server.GETbusy=False
actorAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+actor actorAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+actor
if callingDomain.endswith('.onion') and self.server.onionDomain:
actorAbsolute='http://'+self.server.onionDomain+actor
self._redirect_headers(actorAbsolute+'/'+timelineStr+'?page='+ \ self._redirect_headers(actorAbsolute+'/'+timelineStr+'?page='+ \
str(pageNumber),cookie) str(pageNumber),cookie)
return return
@ -1911,6 +1929,8 @@ class PubServer(BaseHTTPRequestHandler):
self._postToOutboxThread(newUndoAnnounce) self._postToOutboxThread(newUndoAnnounce)
self.server.GETbusy=False self.server.GETbusy=False
actorAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+actor actorAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+actor
if callingDomain.endswith('.onion') and self.server.onionDomain:
actorAbsolute='http://'+self.server.onionDomain+actor
self._redirect_headers(actorAbsolute+'/'+timelineStr+'?page='+ \ self._redirect_headers(actorAbsolute+'/'+timelineStr+'?page='+ \
str(pageNumber)+ \ str(pageNumber)+ \
timelineBookmark,cookie) timelineBookmark,cookie)
@ -1943,7 +1963,11 @@ class PubServer(BaseHTTPRequestHandler):
self.server.acceptedCaps, \ self.server.acceptedCaps, \
self.server.debug, \ self.server.debug, \
self.server.projectVersion) self.server.projectVersion)
originPathStrAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+originPathStr originPathStrAbsolute= \
self.server.httpPrefix+'://'+self.server.domainFull+originPathStr
if callingDomain.endswith('.onion') and self.server.onionDomain:
originPathStrAbsolute= \
'http://'+self.server.onionDomain+originPathStr
self._redirect_headers(originPathStrAbsolute,cookie) self._redirect_headers(originPathStrAbsolute,cookie)
self.server.GETbusy=False self.server.GETbusy=False
return return
@ -1971,7 +1995,10 @@ class PubServer(BaseHTTPRequestHandler):
self.server.personCache, \ self.server.personCache, \
self.server.debug, \ self.server.debug, \
self.server.projectVersion) self.server.projectVersion)
originPathStrAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+originPathStr originPathStrAbsolute= \
self.server.httpPrefix+'://'+self.server.domainFull+originPathStr
if callingDomain.endswith('.onion') and self.server.onionDomain:
originPathStrAbsolute='http://'+self.server.onionDomain+originPathStr
self._redirect_headers(originPathStrAbsolute,cookie) self._redirect_headers(originPathStrAbsolute,cookie)
self.server.GETbusy=False self.server.GETbusy=False
return return
@ -2008,6 +2035,8 @@ class PubServer(BaseHTTPRequestHandler):
print('WARN: unable to find nickname in '+actor) print('WARN: unable to find nickname in '+actor)
self.server.GETbusy=False self.server.GETbusy=False
actorAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+actor actorAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+actor
if callingDomain.endswith('.onion') and self.server.onionDomain:
actorAbsolute='http://'+self.server.onionDomain+actor
self._redirect_headers(actorAbsolute+'/'+timelineStr+ \ self._redirect_headers(actorAbsolute+'/'+timelineStr+ \
'?page='+str(pageNumber)+ \ '?page='+str(pageNumber)+ \
timelineBookmark,cookie) timelineBookmark,cookie)
@ -2031,6 +2060,8 @@ class PubServer(BaseHTTPRequestHandler):
self._postToOutbox(likeJson,self.server.projectVersion) self._postToOutbox(likeJson,self.server.projectVersion)
self.server.GETbusy=False self.server.GETbusy=False
actorAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+actor actorAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+actor
if callingDomain.endswith('.onion') and self.server.onionDomain:
actorAbsolute='http://'+self.server.onionDomain+actor
self._redirect_headers(actorAbsolute+'/'+timelineStr+ \ self._redirect_headers(actorAbsolute+'/'+timelineStr+ \
'?page='+str(pageNumber)+ \ '?page='+str(pageNumber)+ \
timelineBookmark,cookie) timelineBookmark,cookie)
@ -2067,6 +2098,8 @@ class PubServer(BaseHTTPRequestHandler):
print('WARN: unable to find nickname in '+actor) print('WARN: unable to find nickname in '+actor)
self.server.GETbusy=False self.server.GETbusy=False
actorAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+actor actorAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+actor
if callingDomain.endswith('.onion') and self.server.onionDomain:
actorAbsolute='http://'+self.server.onionDomain+actor
self._redirect_headers(actorAbsolute+'/'+timelineStr+ \ self._redirect_headers(actorAbsolute+'/'+timelineStr+ \
'?page='+str(pageNumber),cookie) '?page='+str(pageNumber),cookie)
return return
@ -2094,6 +2127,8 @@ class PubServer(BaseHTTPRequestHandler):
self._postToOutbox(undoLikeJson,self.server.projectVersion) self._postToOutbox(undoLikeJson,self.server.projectVersion)
self.server.GETbusy=False self.server.GETbusy=False
actorAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+actor actorAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+actor
if callingDomain.endswith('.onion') and self.server.onionDomain:
actorAbsolute='http://'+self.server.onionDomain+actor
self._redirect_headers(actorAbsolute+'/'+timelineStr+ \ self._redirect_headers(actorAbsolute+'/'+timelineStr+ \
'?page='+str(pageNumber)+ \ '?page='+str(pageNumber)+ \
timelineBookmark,cookie) timelineBookmark,cookie)
@ -2131,6 +2166,8 @@ class PubServer(BaseHTTPRequestHandler):
print('WARN: unable to find nickname in '+actor) print('WARN: unable to find nickname in '+actor)
self.server.GETbusy=False self.server.GETbusy=False
actorAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+actor actorAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+actor
if callingDomain.endswith('.onion') and self.server.onionDomain:
actorAbsolute='http://'+self.server.onionDomain+actor
self._redirect_headers(actorAbsolute+'/'+timelineStr+ \ self._redirect_headers(actorAbsolute+'/'+timelineStr+ \
'?page='+str(pageNumber),cookie) '?page='+str(pageNumber),cookie)
return return
@ -2150,6 +2187,8 @@ class PubServer(BaseHTTPRequestHandler):
self._postToOutbox(bookmarkJson,self.server.projectVersion) self._postToOutbox(bookmarkJson,self.server.projectVersion)
self.server.GETbusy=False self.server.GETbusy=False
actorAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+actor actorAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+actor
if callingDomain.endswith('.onion') and self.server.onionDomain:
actorAbsolute='http://'+self.server.onionDomain+actor
self._redirect_headers(actorAbsolute+'/'+timelineStr+ \ self._redirect_headers(actorAbsolute+'/'+timelineStr+ \
'?page='+str(pageNumber)+ \ '?page='+str(pageNumber)+ \
timelineBookmark,cookie) timelineBookmark,cookie)
@ -2184,6 +2223,8 @@ class PubServer(BaseHTTPRequestHandler):
print('WARN: unable to find nickname in '+actor) print('WARN: unable to find nickname in '+actor)
self.server.GETbusy=False self.server.GETbusy=False
actorAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+actor actorAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+actor
if callingDomain.endswith('.onion') and self.server.onionDomain:
actorAbsolute='http://'+self.server.onionDomain+actor
self._redirect_headers(actorAbsolute+'/'+timelineStr+ \ self._redirect_headers(actorAbsolute+'/'+timelineStr+ \
'?page='+str(pageNumber),cookie) '?page='+str(pageNumber),cookie)
return return
@ -2208,6 +2249,8 @@ class PubServer(BaseHTTPRequestHandler):
self._postToOutbox(undoBookmarkJson,self.server.projectVersion) self._postToOutbox(undoBookmarkJson,self.server.projectVersion)
self.server.GETbusy=False self.server.GETbusy=False
actorAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+actor actorAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+actor
if callingDomain.endswith('.onion') and self.server.onionDomain:
actorAbsolute='http://'+self.server.onionDomain+actor
self._redirect_headers(actorAbsolute+'/'+timelineStr+ \ self._redirect_headers(actorAbsolute+'/'+timelineStr+ \
'?page='+str(pageNumber)+ \ '?page='+str(pageNumber)+ \
timelineBookmark,cookie) timelineBookmark,cookie)
@ -2232,9 +2275,10 @@ class PubServer(BaseHTTPRequestHandler):
timelineStr=self.path.split('?tl=')[1] timelineStr=self.path.split('?tl=')[1]
if '?' in timelineStr: if '?' in timelineStr:
timelineStr=timelineStr.split('?')[0] timelineStr=timelineStr.split('?')[0]
usersPath=self.path.split('?delete=')[0]
actor= \ actor= \
self.server.httpPrefix+'://'+ \ self.server.httpPrefix+'://'+ \
self.server.domainFull+self.path.split('?delete=')[0] self.server.domainFull+usersPath
if self.server.allowDeletion or \ if self.server.allowDeletion or \
deleteUrl.startswith(actor): deleteUrl.startswith(actor):
if self.server.debug: if self.server.debug:
@ -2243,12 +2287,16 @@ class PubServer(BaseHTTPRequestHandler):
if actor not in deleteUrl: if actor not in deleteUrl:
# You can only delete your own posts # You can only delete your own posts
self.server.GETbusy=False self.server.GETbusy=False
if callingDomain.endswith('.onion') and self.server.onionDomain:
actor='http://'+self.server.onionDomain+usersPath
self._redirect_headers(actor+'/'+timelineStr,cookie) self._redirect_headers(actor+'/'+timelineStr,cookie)
return return
self.postToNickname=getNicknameFromActor(actor) self.postToNickname=getNicknameFromActor(actor)
if not self.postToNickname: if not self.postToNickname:
print('WARN: unable to find nickname in '+actor) print('WARN: unable to find nickname in '+actor)
self.server.GETbusy=False self.server.GETbusy=False
if callingDomain.endswith('.onion') and self.server.onionDomain:
actor='http://'+self.server.onionDomain+usersPath
self._redirect_headers(actor+'/'+timelineStr,cookie) self._redirect_headers(actor+'/'+timelineStr,cookie)
return return
if not self.server.session: if not self.server.session:
@ -2269,6 +2317,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.GETbusy=False self.server.GETbusy=False
return return
self.server.GETbusy=False self.server.GETbusy=False
if callingDomain.endswith('.onion') and self.server.onionDomain:
actor='http://'+self.server.onionDomain+usersPath
self._redirect_headers(actor+'/'+timelineStr,cookie) self._redirect_headers(actor+'/'+timelineStr,cookie)
return return
@ -2302,6 +2352,10 @@ class PubServer(BaseHTTPRequestHandler):
mutePost(self.server.baseDir,nickname,self.server.domain, \ mutePost(self.server.baseDir,nickname,self.server.domain, \
muteUrl,self.server.recentPostsCache) muteUrl,self.server.recentPostsCache)
self.server.GETbusy=False self.server.GETbusy=False
if callingDomain.endswith('.onion') and self.server.onionDomain:
actor= \
'http://'+self.server.onionDomain+ \
self.path.split('?mute=')[0]
self._redirect_headers(actor+'/'+timelineStr+timelineBookmark,cookie) self._redirect_headers(actor+'/'+timelineStr+timelineBookmark,cookie)
return return
@ -2335,6 +2389,10 @@ class PubServer(BaseHTTPRequestHandler):
unmutePost(self.server.baseDir,nickname,self.server.domain, \ unmutePost(self.server.baseDir,nickname,self.server.domain, \
muteUrl,self.server.recentPostsCache) muteUrl,self.server.recentPostsCache)
self.server.GETbusy=False self.server.GETbusy=False
if callingDomain.endswith('.onion') and self.server.onionDomain:
actor= \
'http://'+ \
self.server.onionDomain+self.path.split('?unmute=')[0]
self._redirect_headers(actor+'/'+timelineStr+timelineBookmark,cookie) self._redirect_headers(actor+'/'+timelineStr+timelineBookmark,cookie)
return return
@ -2749,6 +2807,8 @@ class PubServer(BaseHTTPRequestHandler):
return return
actor=self.path.replace('/skills','') actor=self.path.replace('/skills','')
actorAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+actor actorAbsolute=self.server.httpPrefix+'://'+self.server.domainFull+actor
if callingDomain.endswith('.onion') and self.server.onionDomain:
actorAbsolute='http://'+self.server.onionDomain+actor
self._redirect_headers(actorAbsolute,cookie) self._redirect_headers(actorAbsolute,cookie)
self.server.GETbusy=False self.server.GETbusy=False
return return
@ -4380,7 +4440,12 @@ class PubServer(BaseHTTPRequestHandler):
self.server.port, \ self.server.port, \
loginNickname,loginPassword): loginNickname,loginPassword):
self.server.POSTbusy=False self.server.POSTbusy=False
self._redirect_headers(self.server.httpPrefix+'://'+self.server.domainFull+'/login',cookie) if callingDomain.endswith('.onion') and \
self.server.onionDomain:
self._redirect_headers('http://'+self.server.onionDomain+'/login',cookie)
else:
self._redirect_headers(self.server.httpPrefix+'://'+ \
self.server.domainFull+'/login',cookie)
return return
authHeader=createBasicAuthHeader(loginNickname,loginPassword) authHeader=createBasicAuthHeader(loginNickname,loginPassword)
if not authorizeBasic(self.server.baseDir,'/users/'+ \ if not authorizeBasic(self.server.baseDir,'/users/'+ \
@ -4466,9 +4531,9 @@ class PubServer(BaseHTTPRequestHandler):
# update of profile/avatar from web interface # update of profile/avatar from web interface
if authorized and self.path.endswith('/profiledata'): if authorized and self.path.endswith('/profiledata'):
usersPath=self.path.replace('/profiledata','').replace('/editprofile','')
actorStr= \ actorStr= \
self.server.httpPrefix+'://'+self.server.domainFull+ \ self.server.httpPrefix+'://'+self.server.domainFull+usersPath
self.path.replace('/profiledata','').replace('/editprofile','')
if ' boundary=' in self.headers['Content-type']: if ' boundary=' in self.headers['Content-type']:
boundary=self.headers['Content-type'].split('boundary=')[1] boundary=self.headers['Content-type'].split('boundary=')[1]
if ';' in boundary: if ';' in boundary:
@ -4476,12 +4541,18 @@ class PubServer(BaseHTTPRequestHandler):
nickname=getNicknameFromActor(actorStr) nickname=getNicknameFromActor(actorStr)
if not nickname: if not nickname:
if callingDomain.endswith('.onion') and self.server.onionDomain:
actorStr= \
'http://'+self.server.onionDomain+usersPath
print('WARN: nickname not found in '+actorStr) print('WARN: nickname not found in '+actorStr)
self._redirect_headers(actorStr,cookie) self._redirect_headers(actorStr,cookie)
self.server.POSTbusy=False self.server.POSTbusy=False
return return
length=int(self.headers['Content-length']) length=int(self.headers['Content-length'])
if length>self.server.maxPostLength: if length>self.server.maxPostLength:
if callingDomain.endswith('.onion') and self.server.onionDomain:
actorStr= \
'http://'+self.server.onionDomain+usersPath
print('Maximum profile data length exceeded '+str(length)) print('Maximum profile data length exceeded '+str(length))
self._redirect_headers(actorStr,cookie) self._redirect_headers(actorStr,cookie)
self.server.POSTbusy=False self.server.POSTbusy=False
@ -4893,6 +4964,9 @@ class PubServer(BaseHTTPRequestHandler):
self._clearLoginDetails(nickname) self._clearLoginDetails(nickname)
self.server.POSTbusy=False self.server.POSTbusy=False
return return
if callingDomain.endswith('.onion') and self.server.onionDomain:
actorStr= \
'http://'+self.server.onionDomain+usersPath
self._redirect_headers(actorStr,cookie) self._redirect_headers(actorStr,cookie)
self.server.POSTbusy=False self.server.POSTbusy=False
return return
@ -4902,9 +4976,9 @@ class PubServer(BaseHTTPRequestHandler):
# moderator action buttons # moderator action buttons
if authorized and '/users/' in self.path and \ if authorized and '/users/' in self.path and \
self.path.endswith('/moderationaction'): self.path.endswith('/moderationaction'):
usersPath=self.path.replace('/moderationaction','')
actorStr= \ actorStr= \
self.server.httpPrefix+'://'+self.server.domainFull+ \ self.server.httpPrefix+'://'+self.server.domainFull+usersPath
self.path.replace('/moderationaction','')
length=int(self.headers['Content-length']) length=int(self.headers['Content-length'])
moderationParams=self.rfile.read(length).decode('utf-8') moderationParams=self.rfile.read(length).decode('utf-8')
print('moderationParams: '+moderationParams) print('moderationParams: '+moderationParams)
@ -5009,6 +5083,9 @@ class PubServer(BaseHTTPRequestHandler):
nickname,self.server.domain, \ nickname,self.server.domain, \
postFilename, \ postFilename, \
self.server.debug) self.server.debug)
if callingDomain.endswith('.onion') and self.server.onionDomain:
actorStr= \
'http://'+self.server.onionDomain+usersPath
self._redirect_headers(actorStr+'/moderation',cookie) self._redirect_headers(actorStr+'/moderation',cookie)
self.server.POSTbusy=False self.server.POSTbusy=False
return return
@ -5035,11 +5112,14 @@ class PubServer(BaseHTTPRequestHandler):
pageNumber=int(pageNumberStr) pageNumber=int(pageNumberStr)
self.path=self.path.split('?page=')[0] self.path=self.path.split('?page=')[0]
# the actor who votes # the actor who votes
usersPath=self.path.replace('/question','')
actor= \ actor= \
self.server.httpPrefix+'://'+ \ self.server.httpPrefix+'://'+ \
self.server.domainFull+self.path.replace('/question','') self.server.domainFull+usersPath
nickname=getNicknameFromActor(actor) nickname=getNicknameFromActor(actor)
if not nickname: if not nickname:
if callingDomain.endswith('.onion') and self.server.onionDomain:
actor='http://'+self.server.onionDomain+usersPath
self._redirect_headers(actor+'/'+self.server.defaultTimeline+'?page='+ \ self._redirect_headers(actor+'/'+self.server.defaultTimeline+'?page='+ \
str(pageNumber),cookie) str(pageNumber),cookie)
self.server.POSTbusy=False self.server.POSTbusy=False
@ -5061,6 +5141,8 @@ class PubServer(BaseHTTPRequestHandler):
if '&' in answer: if '&' in answer:
answer=answer.split('&')[0] answer=answer.split('&')[0]
self._sendReplyToQuestion(nickname,messageId,answer) self._sendReplyToQuestion(nickname,messageId,answer)
if callingDomain.endswith('.onion') and self.server.onionDomain:
actor='http://'+self.server.onionDomain+usersPath
self._redirect_headers(actor+'/'+self.server.defaultTimeline+ \ self._redirect_headers(actor+'/'+self.server.defaultTimeline+ \
'?page='+str(pageNumber),cookie) '?page='+str(pageNumber),cookie)
self.server.POSTbusy=False self.server.POSTbusy=False
@ -5080,14 +5162,16 @@ class PubServer(BaseHTTPRequestHandler):
pageNumber=int(pageNumberStr) pageNumber=int(pageNumberStr)
self.path=self.path.split('?page=')[0] self.path=self.path.split('?page=')[0]
usersPath=self.path.replace('/searchhandle','')
actorStr= \ actorStr= \
self.server.httpPrefix+'://'+ \ self.server.httpPrefix+'://'+ \
self.server.domainFull+ \ self.server.domainFull+usersPath
self.path.replace('/searchhandle','')
length=int(self.headers['Content-length']) length=int(self.headers['Content-length'])
searchParams=self.rfile.read(length).decode('utf-8') searchParams=self.rfile.read(length).decode('utf-8')
if 'submitBack=' in searchParams: if 'submitBack=' in searchParams:
# go back on search screen # go back on search screen
if callingDomain.endswith('.onion') and self.server.onionDomain:
actorStr='http://'+self.server.onionDomain+usersPath
self._redirect_headers(actorStr+'/'+self.server.defaultTimeline,cookie) self._redirect_headers(actorStr+'/'+self.server.defaultTimeline,cookie)
self.server.POSTbusy=False self.server.POSTbusy=False
return return
@ -5167,6 +5251,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.POSTbusy=False self.server.POSTbusy=False
return return
else: else:
if callingDomain.endswith('.onion') and self.server.onionDomain:
actorStr='http://'+self.server.onionDomain+usersPath
self._redirect_headers(actorStr+'/search',cookie) self._redirect_headers(actorStr+'/search',cookie)
self.server.POSTbusy=False self.server.POSTbusy=False
return return
@ -5204,6 +5290,8 @@ class PubServer(BaseHTTPRequestHandler):
self._write(msg) self._write(msg)
self.server.POSTbusy=False self.server.POSTbusy=False
return return
if callingDomain.endswith('.onion') and self.server.onionDomain:
actorStr='http://'+self.server.onionDomain+usersPath
self._redirect_headers(actorStr+'/'+self.server.defaultTimeline,cookie) self._redirect_headers(actorStr+'/'+self.server.defaultTimeline,cookie)
self.server.POSTbusy=False self.server.POSTbusy=False
return return
@ -5212,9 +5300,9 @@ 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]
originPathStr= \ originPathStr= \
self.server.httpPrefix+'://'+self.server.domainFull+ \ self.server.httpPrefix+'://'+self.server.domainFull+usersPath
self.path.split('/rmshare')[0]
length=int(self.headers['Content-length']) length=int(self.headers['Content-length'])
removeShareConfirmParams=self.rfile.read(length).decode('utf-8') removeShareConfirmParams=self.rfile.read(length).decode('utf-8')
if '&submitYes=' in removeShareConfirmParams: if '&submitYes=' in removeShareConfirmParams:
@ -5231,6 +5319,9 @@ class PubServer(BaseHTTPRequestHandler):
shareDomain,sharePort=getDomainFromActor(shareActor) shareDomain,sharePort=getDomainFromActor(shareActor)
removeShare(self.server.baseDir, \ removeShare(self.server.baseDir, \
shareNickname,shareDomain,shareName) shareNickname,shareDomain,shareName)
if callingDomain.endswith('.onion') and self.server.onionDomain:
originPathStr= \
'http://'+self.server.onionDomain+usersPath
self._redirect_headers(originPathStr+'/tlshares',cookie) self._redirect_headers(originPathStr+'/tlshares',cookie)
self.server.POSTbusy=False self.server.POSTbusy=False
return return
@ -5240,9 +5331,9 @@ class PubServer(BaseHTTPRequestHandler):
# removes a post # removes a post
if authorized and self.path.endswith('/rmpost'): if authorized and self.path.endswith('/rmpost'):
pageNumber=1 pageNumber=1
usersPath=self.path.split('/rmpost')[0]
originPathStr= \ originPathStr= \
self.server.httpPrefix+'://'+self.server.domainFull+ \ self.server.httpPrefix+'://'+self.server.domainFull+usersPath
self.path.split('/rmpost')[0]
length=int(self.headers['Content-length']) length=int(self.headers['Content-length'])
removePostConfirmParams=self.rfile.read(length).decode('utf-8') removePostConfirmParams=self.rfile.read(length).decode('utf-8')
if '&submitYes=' in removePostConfirmParams: if '&submitYes=' in removePostConfirmParams:
@ -5289,6 +5380,8 @@ class PubServer(BaseHTTPRequestHandler):
int(yearStr),int(monthStr), \ int(yearStr),int(monthStr), \
removeMessageId) removeMessageId)
self._postToOutboxThread(deleteJson) self._postToOutboxThread(deleteJson)
if callingDomain.endswith('.onion') and self.server.onionDomain:
originPathStr='http://'+self.server.onionDomain+usersPath
if pageNumber==1: if pageNumber==1:
self._redirect_headers(originPathStr+'/outbox',cookie) self._redirect_headers(originPathStr+'/outbox',cookie)
else: else:
@ -5301,9 +5394,9 @@ class PubServer(BaseHTTPRequestHandler):
# decision to follow in the web interface is confirmed # decision to follow in the web interface is confirmed
if authorized and self.path.endswith('/followconfirm'): if authorized and self.path.endswith('/followconfirm'):
usersPath=self.path.split('/followconfirm')[0]
originPathStr= \ originPathStr= \
self.server.httpPrefix+'://'+self.server.domainFull+ \ self.server.httpPrefix+'://'+self.server.domainFull+usersPath
self.path.split('/followconfirm')[0]
followerNickname=getNicknameFromActor(originPathStr) followerNickname=getNicknameFromActor(originPathStr)
length=int(self.headers['Content-length']) length=int(self.headers['Content-length'])
followConfirmParams=self.rfile.read(length).decode('utf-8') followConfirmParams=self.rfile.read(length).decode('utf-8')
@ -5346,6 +5439,9 @@ class PubServer(BaseHTTPRequestHandler):
self.server.personCache, \ self.server.personCache, \
self.server.debug, \ self.server.debug, \
self.server.projectVersion) self.server.projectVersion)
if callingDomain.endswith('.onion') and self.server.onionDomain:
originPathStr= \
'http://'+self.server.onionDomain+usersPath
self._redirect_headers(originPathStr,cookie) self._redirect_headers(originPathStr,cookie)
self.server.POSTbusy=False self.server.POSTbusy=False
return return
@ -5354,9 +5450,9 @@ class PubServer(BaseHTTPRequestHandler):
# decision to unfollow in the web interface is confirmed # decision to unfollow in the web interface is confirmed
if authorized and self.path.endswith('/unfollowconfirm'): if authorized and self.path.endswith('/unfollowconfirm'):
usersPath=self.path.split('/unfollowconfirm')[0]
originPathStr= \ originPathStr= \
self.server.httpPrefix+'://'+self.server.domainFull+ \ self.server.httpPrefix+'://'+self.server.domainFull+usersPath
self.path.split('/unfollowconfirm')[0]
followerNickname=getNicknameFromActor(originPathStr) followerNickname=getNicknameFromActor(originPathStr)
length=int(self.headers['Content-length']) length=int(self.headers['Content-length'])
followConfirmParams=self.rfile.read(length).decode('utf-8') followConfirmParams=self.rfile.read(length).decode('utf-8')
@ -5396,6 +5492,9 @@ class PubServer(BaseHTTPRequestHandler):
pathUsersSection=self.path.split('/users/')[1] pathUsersSection=self.path.split('/users/')[1]
self.postToNickname=pathUsersSection.split('/')[0] self.postToNickname=pathUsersSection.split('/')[0]
self._postToOutboxThread(unfollowJson) self._postToOutboxThread(unfollowJson)
if callingDomain.endswith('.onion') and self.server.onionDomain:
originPathStr= \
'http://'+self.server.onionDomain+usersPath
self._redirect_headers(originPathStr,cookie) self._redirect_headers(originPathStr,cookie)
self.server.POSTbusy=False self.server.POSTbusy=False
return return
@ -5404,11 +5503,14 @@ class PubServer(BaseHTTPRequestHandler):
# decision to unblock in the web interface is confirmed # decision to unblock in the web interface is confirmed
if authorized and self.path.endswith('/unblockconfirm'): if authorized and self.path.endswith('/unblockconfirm'):
usersPath=self.path.split('/unblockconfirm')[0]
originPathStr= \ originPathStr= \
self.server.httpPrefix+'://'+self.server.domainFull+ \ self.server.httpPrefix+'://'+self.server.domainFull+usersPath
self.path.split('/unblockconfirm')[0]
blockerNickname=getNicknameFromActor(originPathStr) blockerNickname=getNicknameFromActor(originPathStr)
if not blockerNickname: if not blockerNickname:
if callingDomain.endswith('.onion') and self.server.onionDomain:
originPathStr= \
'http://'+self.server.onionDomain+usersPath
print('WARN: unable to find nickname in '+originPathStr) print('WARN: unable to find nickname in '+originPathStr)
self._redirect_headers(originPathStr,cookie) self._redirect_headers(originPathStr,cookie)
self.server.POSTbusy=False self.server.POSTbusy=False
@ -5422,6 +5524,9 @@ class PubServer(BaseHTTPRequestHandler):
blockingActor=blockingActor.split('&')[0] blockingActor=blockingActor.split('&')[0]
blockingNickname=getNicknameFromActor(blockingActor) blockingNickname=getNicknameFromActor(blockingActor)
if not blockingNickname: if not blockingNickname:
if callingDomain.endswith('.onion') and self.server.onionDomain:
originPathStr= \
'http://'+self.server.onionDomain+usersPath
print('WARN: unable to find nickname in '+blockingActor) print('WARN: unable to find nickname in '+blockingActor)
self._redirect_headers(originPathStr,cookie) self._redirect_headers(originPathStr,cookie)
self.server.POSTbusy=False self.server.POSTbusy=False
@ -5443,6 +5548,9 @@ class PubServer(BaseHTTPRequestHandler):
print(blockerNickname+' stops blocking '+blockingActor) print(blockerNickname+' stops blocking '+blockingActor)
removeBlock(self.server.baseDir,blockerNickname,self.server.domain, \ removeBlock(self.server.baseDir,blockerNickname,self.server.domain, \
blockingNickname,blockingDomainFull) blockingNickname,blockingDomainFull)
if callingDomain.endswith('.onion') and self.server.onionDomain:
originPathStr= \
'http://'+self.server.onionDomain+usersPath
self._redirect_headers(originPathStr,cookie) self._redirect_headers(originPathStr,cookie)
self.server.POSTbusy=False self.server.POSTbusy=False
return return
@ -5451,11 +5559,14 @@ class PubServer(BaseHTTPRequestHandler):
# decision to block in the web interface is confirmed # decision to block in the web interface is confirmed
if authorized and self.path.endswith('/blockconfirm'): if authorized and self.path.endswith('/blockconfirm'):
usersPath=self.path.split('/blockconfirm')[0]
originPathStr= \ originPathStr= \
self.server.httpPrefix+'://'+self.server.domainFull+ \ self.server.httpPrefix+'://'+self.server.domainFull+usersPath
self.path.split('/blockconfirm')[0]
blockerNickname=getNicknameFromActor(originPathStr) blockerNickname=getNicknameFromActor(originPathStr)
if not blockerNickname: if not blockerNickname:
if callingDomain.endswith('.onion') and self.server.onionDomain:
originPathStr= \
'http://'+self.server.onionDomain+usersPath
print('WARN: unable to find nickname in '+originPathStr) print('WARN: unable to find nickname in '+originPathStr)
self._redirect_headers(originPathStr,cookie) self._redirect_headers(originPathStr,cookie)
self.server.POSTbusy=False self.server.POSTbusy=False
@ -5469,6 +5580,9 @@ class PubServer(BaseHTTPRequestHandler):
blockingActor=blockingActor.split('&')[0] blockingActor=blockingActor.split('&')[0]
blockingNickname=getNicknameFromActor(blockingActor) blockingNickname=getNicknameFromActor(blockingActor)
if not blockingNickname: if not blockingNickname:
if callingDomain.endswith('.onion') and self.server.onionDomain:
originPathStr= \
'http://'+self.server.onionDomain+usersPath
print('WARN: unable to find nickname in '+blockingActor) print('WARN: unable to find nickname in '+blockingActor)
self._redirect_headers(originPathStr,cookie) self._redirect_headers(originPathStr,cookie)
self.server.POSTbusy=False self.server.POSTbusy=False
@ -5493,6 +5607,9 @@ class PubServer(BaseHTTPRequestHandler):
addBlock(self.server.baseDir,blockerNickname, \ addBlock(self.server.baseDir,blockerNickname, \
self.server.domain, \ self.server.domain, \
blockingNickname,blockingDomainFull) blockingNickname,blockingDomainFull)
if callingDomain.endswith('.onion') and self.server.onionDomain:
originPathStr= \
'http://'+self.server.onionDomain+usersPath
self._redirect_headers(originPathStr,cookie) self._redirect_headers(originPathStr,cookie)
self.server.POSTbusy=False self.server.POSTbusy=False
return return
@ -5503,11 +5620,15 @@ class PubServer(BaseHTTPRequestHandler):
# view/follow/block/report # view/follow/block/report
if authorized and self.path.endswith('/personoptions'): if authorized and self.path.endswith('/personoptions'):
pageNumber=1 pageNumber=1
usersPath=self.path.split('/personoptions')[0]
originPathStr= \ originPathStr= \
self.server.httpPrefix+'://'+self.server.domainFull+ \ self.server.httpPrefix+'://'+self.server.domainFull+usersPath
self.path.split('/personoptions')[0]
chooserNickname=getNicknameFromActor(originPathStr) chooserNickname=getNicknameFromActor(originPathStr)
if not chooserNickname: if not chooserNickname:
if callingDomain.endswith('.onion') and self.server.onionDomain:
originPathStr= \
'http://'+self.server.onionDomain+usersPath
print('WARN: unable to find nickname in '+originPathStr) print('WARN: unable to find nickname in '+originPathStr)
self._redirect_headers(originPathStr,cookie) self._redirect_headers(originPathStr,cookie)
self.server.POSTbusy=False self.server.POSTbusy=False
@ -5539,6 +5660,9 @@ class PubServer(BaseHTTPRequestHandler):
optionsNickname=getNicknameFromActor(optionsActor) optionsNickname=getNicknameFromActor(optionsActor)
if not optionsNickname: if not optionsNickname:
if callingDomain.endswith('.onion') and self.server.onionDomain:
originPathStr= \
'http://'+self.server.onionDomain+usersPath
print('WARN: unable to find nickname in '+optionsActor) print('WARN: unable to find nickname in '+optionsActor)
self._redirect_headers(originPathStr,cookie) self._redirect_headers(originPathStr,cookie)
self.server.POSTbusy=False self.server.POSTbusy=False
@ -5620,28 +5744,34 @@ class PubServer(BaseHTTPRequestHandler):
self.server.POSTbusy=False self.server.POSTbusy=False
return return
if '&submitSnooze=' in optionsConfirmParams: if '&submitSnooze=' in optionsConfirmParams:
usersPath=self.path.split('/personoptions')[0]
thisActor= \ thisActor= \
self.server.httpPrefix+'://'+self.server.domainFull+ \ self.server.httpPrefix+'://'+self.server.domainFull+usersPath
self.path.split('/personoptions')[0]
if self.server.debug: if self.server.debug:
print('Snoozing '+optionsActor+' '+thisActor) print('Snoozing '+optionsActor+' '+thisActor)
if '/users/' in thisActor: if '/users/' in thisActor:
nickname=thisActor.split('/users/')[1] nickname=thisActor.split('/users/')[1]
personSnooze(self.server.baseDir,nickname,self.server.domain,optionsActor) personSnooze(self.server.baseDir,nickname,self.server.domain,optionsActor)
if callingDomain.endswith('.onion') and self.server.onionDomain:
thisActor= \
'http://'+self.server.onionDomain+usersPath
self._redirect_headers(thisActor+ \ self._redirect_headers(thisActor+ \
'/'+self.server.defaultTimeline+ \ '/'+self.server.defaultTimeline+ \
'?page='+str(pageNumber),cookie) '?page='+str(pageNumber),cookie)
self.server.POSTbusy=False self.server.POSTbusy=False
return return
if '&submitUnSnooze=' in optionsConfirmParams: if '&submitUnSnooze=' in optionsConfirmParams:
usersPath=self.path.split('/personoptions')[0]
thisActor= \ thisActor= \
self.server.httpPrefix+'://'+self.server.domainFull+ \ self.server.httpPrefix+'://'+self.server.domainFull+usersPath
self.path.split('/personoptions')[0]
if self.server.debug: if self.server.debug:
print('Unsnoozing '+optionsActor+' '+thisActor) print('Unsnoozing '+optionsActor+' '+thisActor)
if '/users/' in thisActor: if '/users/' in thisActor:
nickname=thisActor.split('/users/')[1] nickname=thisActor.split('/users/')[1]
personUnsnooze(self.server.baseDir,nickname,self.server.domain,optionsActor) personUnsnooze(self.server.baseDir,nickname,self.server.domain,optionsActor)
if callingDomain.endswith('.onion') and self.server.onionDomain:
thisActor= \
'http://'+self.server.onionDomain+usersPath
self._redirect_headers(thisActor+ \ self._redirect_headers(thisActor+ \
'/'+self.server.defaultTimeline+ \ '/'+self.server.defaultTimeline+ \
'?page='+str(pageNumber),cookie) '?page='+str(pageNumber),cookie)
@ -5662,6 +5792,9 @@ class PubServer(BaseHTTPRequestHandler):
self.server.POSTbusy=False self.server.POSTbusy=False
return return
if callingDomain.endswith('.onion') and self.server.onionDomain:
originPathStr= \
'http://'+self.server.onionDomain+usersPath
self._redirect_headers(originPathStr,cookie) self._redirect_headers(originPathStr,cookie)
self.server.POSTbusy=False self.server.POSTbusy=False
return return
@ -5682,10 +5815,17 @@ class PubServer(BaseHTTPRequestHandler):
if '/' in nickname: if '/' in nickname:
nickname=nickname.split('/')[0] nickname=nickname.split('/')[0]
self._redirect_headers(self.server.httpPrefix+'://'+self.server.domainFull+ \ if not callingDomain.endswith('.onion') or \
'/users/'+nickname+ \ not self.server.onionDomain:
'/'+postRedirect+ \ self._redirect_headers(self.server.httpPrefix+'://'+self.server.domainFull+ \
'?page='+str(pageNumber),cookie) '/users/'+nickname+ \
'/'+postRedirect+ \
'?page='+str(pageNumber),cookie)
else:
self._redirect_headers('http://'+self.server.onionDomain+ \
'/users/'+nickname+ \
'/'+postRedirect+ \
'?page='+str(pageNumber),cookie)
self.server.POSTbusy=False self.server.POSTbusy=False
return return