forked from indymedia/epicyon
Moderators can block hashtag searches
parent
41616734dd
commit
54a1f54f36
73
blocking.py
73
blocking.py
|
@ -13,13 +13,22 @@ def addGlobalBlock(baseDir: str, \
|
|||
"""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()
|
||||
if not blockNickname.startswith('#'):
|
||||
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()
|
||||
else:
|
||||
blockHashtag=blockNickname
|
||||
if os.path.isfile(blockingFilename):
|
||||
if blockHashtag+'\n' in open(blockingFilename).read():
|
||||
return False
|
||||
blockFile=open(blockingFilename, "a+")
|
||||
blockFile.write(blockHashtag+'\n')
|
||||
blockFile.close()
|
||||
return True
|
||||
|
||||
def addBlock(baseDir: str,nickname: str,domain: str, \
|
||||
|
@ -44,18 +53,32 @@ def removeGlobalBlock(baseDir: str, \
|
|||
"""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
|
||||
if not unblockNickname.startswith('#'):
|
||||
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
|
||||
else:
|
||||
unblockHashtag=unblockNickname
|
||||
if os.path.isfile(unblockingFilename):
|
||||
if unblockHashtag+'\n' in open(unblockingFilename).read():
|
||||
with open(unblockingFilename, 'r') as fp:
|
||||
with open(unblockingFilename+'.new', 'w') as fpnew:
|
||||
for line in fp:
|
||||
blockLine=line.replace('\n','')
|
||||
if unblockHashtag not in line:
|
||||
fpnew.write(blockLine+'\n')
|
||||
if os.path.isfile(unblockingFilename+'.new'):
|
||||
os.rename(unblockingFilename+'.new',unblockingFilename)
|
||||
return True
|
||||
return False
|
||||
|
||||
def removeBlock(baseDir: str,nickname: str,domain: str, \
|
||||
|
@ -78,7 +101,17 @@ def removeBlock(baseDir: str,nickname: str,domain: str, \
|
|||
os.rename(unblockingFilename+'.new',unblockingFilename)
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def isBlockedHashtag(baseDir: str,hashtag: str) -> bool:
|
||||
"""Is the given hashtag blocked?
|
||||
"""
|
||||
globalBlockingFilename=baseDir+'/accounts/blocking.txt'
|
||||
if os.path.isfile(globalBlockingFilename):
|
||||
hashtag=hashtag.strip('\n')
|
||||
if hashtag+'\n' in open(globalBlockingFilename).read():
|
||||
return True
|
||||
return False
|
||||
|
||||
def isBlocked(baseDir: str,nickname: str,domain: str, \
|
||||
blockNickname: str,blockDomain: str) -> bool:
|
||||
"""Is the given nickname blocked?
|
||||
|
|
11
daemon.py
11
daemon.py
|
@ -66,6 +66,7 @@ from blocking import addBlock
|
|||
from blocking import removeBlock
|
||||
from blocking import addGlobalBlock
|
||||
from blocking import removeGlobalBlock
|
||||
from blocking import isBlockedHashtag
|
||||
from config import setConfigParam
|
||||
from config import getConfigParam
|
||||
from roles import outboxDelegate
|
||||
|
@ -92,6 +93,7 @@ from webinterface import htmlTermsOfService
|
|||
from webinterface import htmlHashtagSearch
|
||||
from webinterface import htmlModerationInfo
|
||||
from webinterface import htmlSearchSharedItems
|
||||
from webinterface import htmlHashtagBlocked
|
||||
from shares import getSharesFeedForPerson
|
||||
from shares import outboxShareUpload
|
||||
from shares import outboxUndoShareUpload
|
||||
|
@ -706,6 +708,11 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
hashtag=self.path.split('/tags/')[1]
|
||||
if '?page=' in hashtag:
|
||||
hashtag=hashtag.split('?page=')[0]
|
||||
if isBlockedHashtag(self.server.baseDir,hashtag):
|
||||
self._login_headers('text/html')
|
||||
self.wfile.write(htmlHashtagBlocked(self.server.baseDir).encode('utf-8'))
|
||||
self.server.GETbusy=False
|
||||
return
|
||||
hashtagStr= \
|
||||
htmlHashtagSearch(self.server.baseDir,hashtag,pageNumber, \
|
||||
maxPostsInFeed,self.server.session, \
|
||||
|
@ -2160,7 +2167,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
fullBlockDomain=blockDomain+':'+str(blockPort)
|
||||
if '@' in moderationText:
|
||||
fullBlockDomain=moderationText.split('@')[1]
|
||||
if fullBlockDomain:
|
||||
if fullBlockDomain or nickname.startswith('#'):
|
||||
addGlobalBlock(self.server.baseDir, \
|
||||
nickname,fullBlockDomain)
|
||||
if moderationButton=='unblock':
|
||||
|
@ -2174,7 +2181,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
fullBlockDomain=blockDomain+':'+str(blockPort)
|
||||
if '@' in moderationText:
|
||||
fullBlockDomain=moderationText.split('@')[1]
|
||||
if fullBlockDomain:
|
||||
if fullBlockDomain or nickname.startswith('#'):
|
||||
removeGlobalBlock(self.server.baseDir, \
|
||||
nickname,fullBlockDomain)
|
||||
if moderationButton=='remove':
|
||||
|
|
|
@ -451,6 +451,20 @@ def htmlTermsOfService(baseDir: str,httpPrefix: str,domainFull: str) -> str:
|
|||
TOSForm+=htmlFooter()
|
||||
return TOSForm
|
||||
|
||||
def htmlHashtagBlocked(baseDir: str) -> str:
|
||||
"""Show the screen for a blocked hashtag
|
||||
"""
|
||||
blockedHashtagForm=''
|
||||
with open(baseDir+'/epicyon-suspended.css', 'r') as cssFile:
|
||||
blockedHashtagCSS=cssFile.read()
|
||||
blockedHashtagForm=htmlHeader(blockedHashtagCSS)
|
||||
blockedHashtagForm+='<div><center>'
|
||||
blockedHashtagForm+=' <p class="screentitle">Hashtag Blocked</p>'
|
||||
blockedHashtagForm+=' <p>See <a href="/terms">Terms of Service</a></p>'
|
||||
blockedHashtagForm+='</center></div>'
|
||||
blockedHashtagForm+=htmlFooter()
|
||||
return blockedHashtagForm
|
||||
|
||||
def htmlSuspended(baseDir: str) -> str:
|
||||
"""Show the screen for suspended accounts
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue