mirror of https://gitlab.com/bashrc2/epicyon
Blocking and upblocking from web interface dropdown
parent
0fb0f89462
commit
e04db12604
96
daemon.py
96
daemon.py
|
@ -53,6 +53,8 @@ from like import outboxLike
|
||||||
from like import outboxUndoLike
|
from like import outboxUndoLike
|
||||||
from blocking import outboxBlock
|
from blocking import outboxBlock
|
||||||
from blocking import outboxUndoBlock
|
from blocking import outboxUndoBlock
|
||||||
|
from blocking import addBlock
|
||||||
|
from blocking import removeBlock
|
||||||
from config import setConfigParam
|
from config import setConfigParam
|
||||||
from roles import outboxDelegate
|
from roles import outboxDelegate
|
||||||
from skills import outboxSkills
|
from skills import outboxSkills
|
||||||
|
@ -624,6 +626,23 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.server.GETbusy=False
|
self.server.GETbusy=False
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# block a person from the web interface by selecting Block on the dropdown
|
||||||
|
if '/users/' in self.path:
|
||||||
|
if '?block=' in self.path:
|
||||||
|
blockStr=self.path.split('?block=')[1]
|
||||||
|
originPathStr=self.path.split('?block=')[0]
|
||||||
|
if ';' in blockStr:
|
||||||
|
blockActor=blockStr.split(';')[0]
|
||||||
|
blockProfileUrl=blockStr.split(';')[1]
|
||||||
|
# show the confirm block screen
|
||||||
|
self._set_headers('text/html',cookie)
|
||||||
|
self.wfile.write(htmlBlockConfirm(self.server.baseDir,originPathStr,blockActor,blockProfileUrl).encode())
|
||||||
|
self.server.GETbusy=False
|
||||||
|
return
|
||||||
|
self._redirect_headers(originPathStr,cookie)
|
||||||
|
self.server.GETbusy=False
|
||||||
|
return
|
||||||
|
|
||||||
# search for a fediverse address from the web interface by selecting search icon
|
# search for a fediverse address from the web interface by selecting search icon
|
||||||
if '/users/' in self.path:
|
if '/users/' in self.path:
|
||||||
if self.path.endswith('/search'):
|
if self.path.endswith('/search'):
|
||||||
|
@ -650,6 +669,23 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.server.GETbusy=False
|
self.server.GETbusy=False
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Unblock a person from the web interface by selecting Unblock on the dropdown
|
||||||
|
if '/users/' in self.path:
|
||||||
|
if '?unblock=' in self.path:
|
||||||
|
blockStr=self.path.split('?unblock=')[1]
|
||||||
|
originPathStr=self.path.split('?unblock=')[0]
|
||||||
|
if ';' in blockStr:
|
||||||
|
blockActor=blockStr.split(';')[0]
|
||||||
|
blockProfileUrl=blockStr.split(';')[1]
|
||||||
|
# show the confirm unblock screen
|
||||||
|
self._set_headers('text/html',cookie)
|
||||||
|
self.wfile.write(htmlUnblockConfirm(self.server.baseDir,originPathStr,blockActor,blockProfileUrl).encode())
|
||||||
|
self.server.GETbusy=False
|
||||||
|
return
|
||||||
|
self._redirect_headers(originPathStr,cookie)
|
||||||
|
self.server.GETbusy=False
|
||||||
|
return
|
||||||
|
|
||||||
# announce/repeat from the web interface
|
# announce/repeat from the web interface
|
||||||
if authorized and '?repeat=' in self.path:
|
if authorized and '?repeat=' in self.path:
|
||||||
repeatUrl=self.path.split('?repeat=')[1]
|
repeatUrl=self.path.split('?repeat=')[1]
|
||||||
|
@ -1872,6 +1908,66 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.server.POSTbusy=False
|
self.server.POSTbusy=False
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# decision to unblock in the web interface is confirmed
|
||||||
|
if authorized and self.path.endswith('/unblockconfirm'):
|
||||||
|
originPathStr=self.path.split('/unblockconfirm')[0]
|
||||||
|
blockerNickname=getNicknameFromActor(originPathStr)
|
||||||
|
length = int(self.headers['Content-length'])
|
||||||
|
blockConfirmParams=self.rfile.read(length).decode('utf-8')
|
||||||
|
if '&submitYes=' in blockConfirmParams:
|
||||||
|
blockingActor=blockConfirmParams.replace('%3A',':').replace('%2F','/').split('actor=')[1]
|
||||||
|
if '&' in blockingActor:
|
||||||
|
blockingActor=blockingActor.split('&')[0]
|
||||||
|
blockingNickname=getNicknameFromActor(blockingActor)
|
||||||
|
blockingDomain,blockingPort=getDomainFromActor(blockingActor)
|
||||||
|
blockingDomainFull=blockingDomain
|
||||||
|
if blockingPort:
|
||||||
|
if blockingPort!=80 and blockingPort!=443:
|
||||||
|
blockingDomainFull=blockingDomain+':'+str(blockingPort)
|
||||||
|
if blockerNickname==blockingNickname and \
|
||||||
|
blockingDomain==self.server.domain and \
|
||||||
|
blockingPort==self.server.port:
|
||||||
|
if self.server.debug:
|
||||||
|
print('You cannot unblock yourself!')
|
||||||
|
else:
|
||||||
|
if self.server.debug:
|
||||||
|
print(blockerNickname+' stops blocking '+blockingActor)
|
||||||
|
removeBlock(self.server.baseDir,blockerNickname,self.server.domain, \
|
||||||
|
blockingNickname,blockingDomainFull)
|
||||||
|
self._redirect_headers(originPathStr,cookie)
|
||||||
|
self.server.POSTbusy=False
|
||||||
|
return
|
||||||
|
|
||||||
|
# decision to block in the web interface is confirmed
|
||||||
|
if authorized and self.path.endswith('/blockconfirm'):
|
||||||
|
originPathStr=self.path.split('/blockconfirm')[0]
|
||||||
|
blockerNickname=getNicknameFromActor(originPathStr)
|
||||||
|
length = int(self.headers['Content-length'])
|
||||||
|
blockConfirmParams=self.rfile.read(length).decode('utf-8')
|
||||||
|
if '&submitYes=' in blockConfirmParams:
|
||||||
|
blockingActor=blockConfirmParams.replace('%3A',':').replace('%2F','/').split('actor=')[1]
|
||||||
|
if '&' in blockingActor:
|
||||||
|
blockingActor=blockingActor.split('&')[0]
|
||||||
|
blockingNickname=getNicknameFromActor(blockingActor)
|
||||||
|
blockingDomain,blockingPort=getDomainFromActor(blockingActor)
|
||||||
|
blockingDomainFull=blockingDomain
|
||||||
|
if blockingPort:
|
||||||
|
if blockingPort!=80 and blockingPort!=443:
|
||||||
|
blockingDomainFull=blockingDomain+':'+str(blockingPort)
|
||||||
|
if blockerNickname==blockingNickname and \
|
||||||
|
blockingDomain==self.server.domain and \
|
||||||
|
blockingPort==self.server.port:
|
||||||
|
if self.server.debug:
|
||||||
|
print('You cannot block yourself!')
|
||||||
|
else:
|
||||||
|
if self.server.debug:
|
||||||
|
print('Adding block by '+blockerNickname+' of '+blockingActor)
|
||||||
|
addBlock(self.server.baseDir,blockerNickname,self.server.domain, \
|
||||||
|
blockingNickname,blockingDomainFull)
|
||||||
|
self._redirect_headers(originPathStr,cookie)
|
||||||
|
self.server.POSTbusy=False
|
||||||
|
return
|
||||||
|
|
||||||
postState=self._receiveNewPost(authorized,'newpost')
|
postState=self._receiveNewPost(authorized,'newpost')
|
||||||
if postState!=0:
|
if postState!=0:
|
||||||
nickname=self.path.split('/users/')[1]
|
nickname=self.path.split('/users/')[1]
|
||||||
|
|
|
@ -25,6 +25,7 @@ from session import getJson
|
||||||
from auth import createPassword
|
from auth import createPassword
|
||||||
from like import likedByPerson
|
from like import likedByPerson
|
||||||
from announce import announcedByPerson
|
from announce import announcedByPerson
|
||||||
|
from blocking import isBlocked
|
||||||
|
|
||||||
def htmlEditProfile(baseDir: str,path: str,domain: str,port: int) -> str:
|
def htmlEditProfile(baseDir: str,path: str,domain: str,port: int) -> str:
|
||||||
"""Shows the edit profile screen
|
"""Shows the edit profile screen
|
||||||
|
@ -640,13 +641,22 @@ def individualPostAsHtml(baseDir: str, \
|
||||||
if isFollowingActor(baseDir,nickname,domain,postJsonObject['actor']):
|
if isFollowingActor(baseDir,nickname,domain,postJsonObject['actor']):
|
||||||
followUnfollowStr='<a href="/users/'+nickname+'?unfollow='+postJsonObject['actor']+';'+avatarUrl+'">Unfollow</a>'
|
followUnfollowStr='<a href="/users/'+nickname+'?unfollow='+postJsonObject['actor']+';'+avatarUrl+'">Unfollow</a>'
|
||||||
|
|
||||||
|
blockUnblockStr='<a href="/users/'+nickname+'?block='+postJsonObject['actor']+';'+avatarUrl+'">Block</a>'
|
||||||
|
# if blocking then show "Unblock" in the dropdown
|
||||||
|
actorDomainFull=actorDomain
|
||||||
|
if actorPort:
|
||||||
|
if actorPort!=80 and actorPort!=443:
|
||||||
|
actorDomainFull=actorDomain+':'+str(actorPort)
|
||||||
|
if isBlocked(baseDir,nickname,domain,actorNickname,actorDomainFull):
|
||||||
|
blockUnblockStr='<a href="/users/'+nickname+'?unblock='+postJsonObject['actor']+';'+avatarUrl+'">Unblock</a>'
|
||||||
|
|
||||||
avatarDropdown= \
|
avatarDropdown= \
|
||||||
' <div class="dropdown-timeline">' \
|
' <div class="dropdown-timeline">' \
|
||||||
' <img src="'+avatarUrl+'" '+avatarPosition+'/>' \
|
' <img src="'+avatarUrl+'" '+avatarPosition+'/>' \
|
||||||
' <div class="dropdown-timeline-content">' \
|
' <div class="dropdown-timeline-content">' \
|
||||||
' <a href="'+postJsonObject['actor']+'">Visit</a>'+ \
|
' <a href="'+postJsonObject['actor']+'">Visit</a>'+ \
|
||||||
followUnfollowStr+ \
|
followUnfollowStr+ \
|
||||||
' <a href="/users/'+nickname+'?block='+postJsonObject['actor']+';'+avatarUrl+'">Block</a>' \
|
blockUnblockStr+ \
|
||||||
' <a href="/users/'+nickname+'?report='+postJsonObject['actor']+';'+avatarUrl+'">Report</a>' \
|
' <a href="/users/'+nickname+'?report='+postJsonObject['actor']+';'+avatarUrl+'">Report</a>' \
|
||||||
' </div>' \
|
' </div>' \
|
||||||
' </div>'
|
' </div>'
|
||||||
|
@ -857,6 +867,66 @@ def htmlUnfollowConfirm(baseDir: str,originPathStr: str,followActor: str,followP
|
||||||
followStr+=htmlFooter()
|
followStr+=htmlFooter()
|
||||||
return followStr
|
return followStr
|
||||||
|
|
||||||
|
def htmlBlockConfirm(baseDir: str,originPathStr: str,blockActor: str,blockProfileUrl: str) -> str:
|
||||||
|
"""Asks to confirm a block
|
||||||
|
"""
|
||||||
|
blockDomain,port=getDomainFromActor(blockActor)
|
||||||
|
|
||||||
|
if os.path.isfile(baseDir+'/img/block-background.png'):
|
||||||
|
if not os.path.isfile(baseDir+'/accounts/block-background.png'):
|
||||||
|
copyfile(baseDir+'/img/block-background.png',baseDir+'/accounts/block-background.png')
|
||||||
|
|
||||||
|
with open(baseDir+'/epicyon-follow.css', 'r') as cssFile:
|
||||||
|
profileStyle = cssFile.read()
|
||||||
|
blockStr=htmlHeader(profileStyle)
|
||||||
|
blockStr+='<div class="block">'
|
||||||
|
blockStr+=' <div class="blockAvatar">'
|
||||||
|
blockStr+=' <center>'
|
||||||
|
blockStr+=' <a href="'+blockActor+'">'
|
||||||
|
blockStr+=' <img src="'+blockProfileUrl+'"/></a>'
|
||||||
|
blockStr+=' <p class="blockText">Block '+getNicknameFromActor(blockActor)+'@'+blockDomain+' ?</p>'
|
||||||
|
blockStr+= \
|
||||||
|
' <form method="POST" action="'+originPathStr+'/blockconfirm">' \
|
||||||
|
' <input type="hidden" name="actor" value="'+blockActor+'">' \
|
||||||
|
' <button type="submit" class="button" name="submitYes">Yes</button>' \
|
||||||
|
' <a href="'+originPathStr+'"><button class="button">No</button></a>' \
|
||||||
|
' </form>'
|
||||||
|
blockStr+='</center>'
|
||||||
|
blockStr+='</div>'
|
||||||
|
blockStr+='</div>'
|
||||||
|
blockStr+=htmlFooter()
|
||||||
|
return blockStr
|
||||||
|
|
||||||
|
def htmlUnblockConfirm(baseDir: str,originPathStr: str,blockActor: str,blockProfileUrl: str) -> str:
|
||||||
|
"""Asks to confirm unblocking an actor
|
||||||
|
"""
|
||||||
|
blockDomain,port=getDomainFromActor(blockActor)
|
||||||
|
|
||||||
|
if os.path.isfile(baseDir+'/img/block-background.png'):
|
||||||
|
if not os.path.isfile(baseDir+'/accounts/block-background.png'):
|
||||||
|
copyfile(baseDir+'/img/block-background.png',baseDir+'/accounts/block-background.png')
|
||||||
|
|
||||||
|
with open(baseDir+'/epicyon-follow.css', 'r') as cssFile:
|
||||||
|
profileStyle = cssFile.read()
|
||||||
|
blockStr=htmlHeader(profileStyle)
|
||||||
|
blockStr+='<div class="block">'
|
||||||
|
blockStr+=' <div class="blockAvatar">'
|
||||||
|
blockStr+=' <center>'
|
||||||
|
blockStr+=' <a href="'+blockActor+'">'
|
||||||
|
blockStr+=' <img src="'+blockProfileUrl+'"/></a>'
|
||||||
|
blockStr+=' <p class="blockText">Stop blocking '+getNicknameFromActor(blockActor)+'@'+blockDomain+' ?</p>'
|
||||||
|
blockStr+= \
|
||||||
|
' <form method="POST" action="'+originPathStr+'/unblockconfirm">' \
|
||||||
|
' <input type="hidden" name="actor" value="'+blockActor+'">' \
|
||||||
|
' <button type="submit" class="button" name="submitYes">Yes</button>' \
|
||||||
|
' <a href="'+originPathStr+'"><button class="button">No</button></a>' \
|
||||||
|
' </form>'
|
||||||
|
blockStr+='</center>'
|
||||||
|
blockStr+='</div>'
|
||||||
|
blockStr+='</div>'
|
||||||
|
blockStr+=htmlFooter()
|
||||||
|
return blockStr
|
||||||
|
|
||||||
def htmlSearch(baseDir: str,path: str) -> str:
|
def htmlSearch(baseDir: str,path: str) -> str:
|
||||||
"""Search called from the timeline icon
|
"""Search called from the timeline icon
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue