forked from indymedia/epicyon
Global block and unblock addresses or domains from moderation timeline
parent
febb4258bd
commit
812ad29de2
43
blocking.py
43
blocking.py
|
@ -8,6 +8,20 @@ __status__ = "Production"
|
|||
|
||||
import os
|
||||
|
||||
def addGlobalBlock(baseDir: str, \
|
||||
blockNickname: str,blockDomain: str) -> bool:
|
||||
"""Global block which applies to all accounts
|
||||
"""
|
||||
blockingFilename=baseDir+'/accounts/blocking.txt'
|
||||
blockHandle=blockNickName+'@'+blockDomain
|
||||
if os.path.isfile(blockingFilename):
|
||||
if blockHandle in open(blockingFilename).read():
|
||||
return False
|
||||
blockFile=open(blockingFilename, "a+")
|
||||
blockFile.write(blockHandle+'\n')
|
||||
blockFile.close()
|
||||
return True
|
||||
|
||||
def addBlock(baseDir: str,nickname: str,domain: str, \
|
||||
blockNickname: str,blockDomain: str) -> bool:
|
||||
"""Block the given account
|
||||
|
@ -24,6 +38,26 @@ def addBlock(baseDir: str,nickname: str,domain: str, \
|
|||
blockFile.close()
|
||||
return True
|
||||
|
||||
def removeGlobalBlock(baseDir: str, \
|
||||
unblockNickname: str, \
|
||||
unblockDomain: str) -> bool:
|
||||
"""Unblock the given global block
|
||||
"""
|
||||
unblockingFilename=baseDir+'/accounts/blocking.txt'
|
||||
unblockHandle=unblockNickName+'@'+unblockDomain
|
||||
if os.path.isfile(unblockingFilename):
|
||||
if unblockHandle in open(unblockingFilename).read():
|
||||
with open(unblockingFilename, 'r') as fp:
|
||||
with open(unblockingFilename+'.new', 'w') as fpnew:
|
||||
for line in fp:
|
||||
handle=line.replace('\n','')
|
||||
if unblockHandle not in line:
|
||||
fpnew.write(handle+'\n')
|
||||
if os.path.isfile(unblockingFilename+'.new'):
|
||||
os.rename(unblockingFilename+'.new',unblockingFilename)
|
||||
return True
|
||||
return False
|
||||
|
||||
def removeBlock(baseDir: str,nickname: str,domain: str, \
|
||||
unblockNickname: str,unblockDomain: str) -> bool:
|
||||
"""Unblock the given account
|
||||
|
@ -49,15 +83,22 @@ def isBlocked(baseDir: str,nickname: str,domain: str, \
|
|||
blockNickname: str,blockDomain: str) -> bool:
|
||||
"""Is the given nickname blocked?
|
||||
"""
|
||||
globalBlockingFilename=baseDir+'/accounts/blocking.txt'
|
||||
if os.path.isfile(globalBlockingFilename):
|
||||
if '*@'+blockDomain in open(globalBlockingFilename).read():
|
||||
return True
|
||||
blockHandle=blockNickname+'@'+blockDomain
|
||||
if blockHandle in open(globalBlockingFilename).read():
|
||||
return True
|
||||
allowFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/allowedinstances.txt'
|
||||
if os.path.isfile(allowFilename):
|
||||
if blockDomain not in open(allowFilename).read():
|
||||
return True
|
||||
blockingFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/blocking.txt'
|
||||
blockHandle=blockNickname+'@'+blockDomain
|
||||
if os.path.isfile(blockingFilename):
|
||||
if '*@'+blockDomain in open(blockingFilename).read():
|
||||
return True
|
||||
blockHandle=blockNickname+'@'+blockDomain
|
||||
if blockHandle in open(blockingFilename).read():
|
||||
return True
|
||||
return False
|
||||
|
|
18
daemon.py
18
daemon.py
|
@ -64,6 +64,8 @@ from blocking import outboxBlock
|
|||
from blocking import outboxUndoBlock
|
||||
from blocking import addBlock
|
||||
from blocking import removeBlock
|
||||
from blocking import addGlobalBlock
|
||||
from blocking import removeGlobalBlock
|
||||
from config import setConfigParam
|
||||
from config import getConfigParam
|
||||
from roles import outboxDelegate
|
||||
|
@ -2141,6 +2143,22 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
suspendAccount(self.server.baseDir,nickname,self.server.salts)
|
||||
if moderationButton=='unsuspend':
|
||||
unsuspendAccount(self.server.baseDir,nickname)
|
||||
if moderationButton=='block':
|
||||
blockDomain,blockPort=getDomainFromActor(moderationText)
|
||||
fullBlockDomain=blockDomain
|
||||
if blockPort:
|
||||
if blockPort!=80 and blockPort!=443:
|
||||
fullBlockDomain=blockDomain+':'+str(blockPort)
|
||||
addGlobalBlock(self.server.baseDir, \
|
||||
nickname,fullBlockDomain)
|
||||
if moderationButton=='unblock':
|
||||
blockDomain,blockPort=getDomainFromActor(moderationText)
|
||||
fullBlockDomain=blockDomain
|
||||
if blockPort:
|
||||
if blockPort!=80 and blockPort!=443:
|
||||
fullBlockDomain=blockDomain+':'+str(blockPort)
|
||||
removeGlobalBlock(self.server.baseDir, \
|
||||
nickname,fullBlockDomain)
|
||||
if moderationButton=='remove':
|
||||
if '/statuses/' not in moderationText:
|
||||
removeAccount(self.server.baseDir, \
|
||||
|
|
Loading…
Reference in New Issue