mirror of https://gitlab.com/bashrc2/epicyon
Moderators can block hashtag searches
parent
41616734dd
commit
54a1f54f36
33
blocking.py
33
blocking.py
|
@ -13,6 +13,7 @@ def addGlobalBlock(baseDir: str, \
|
||||||
"""Global block which applies to all accounts
|
"""Global block which applies to all accounts
|
||||||
"""
|
"""
|
||||||
blockingFilename=baseDir+'/accounts/blocking.txt'
|
blockingFilename=baseDir+'/accounts/blocking.txt'
|
||||||
|
if not blockNickname.startswith('#'):
|
||||||
blockHandle=blockNickname+'@'+blockDomain
|
blockHandle=blockNickname+'@'+blockDomain
|
||||||
if os.path.isfile(blockingFilename):
|
if os.path.isfile(blockingFilename):
|
||||||
if blockHandle in open(blockingFilename).read():
|
if blockHandle in open(blockingFilename).read():
|
||||||
|
@ -20,6 +21,14 @@ def addGlobalBlock(baseDir: str, \
|
||||||
blockFile=open(blockingFilename, "a+")
|
blockFile=open(blockingFilename, "a+")
|
||||||
blockFile.write(blockHandle+'\n')
|
blockFile.write(blockHandle+'\n')
|
||||||
blockFile.close()
|
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
|
return True
|
||||||
|
|
||||||
def addBlock(baseDir: str,nickname: str,domain: str, \
|
def addBlock(baseDir: str,nickname: str,domain: str, \
|
||||||
|
@ -44,6 +53,7 @@ def removeGlobalBlock(baseDir: str, \
|
||||||
"""Unblock the given global block
|
"""Unblock the given global block
|
||||||
"""
|
"""
|
||||||
unblockingFilename=baseDir+'/accounts/blocking.txt'
|
unblockingFilename=baseDir+'/accounts/blocking.txt'
|
||||||
|
if not unblockNickname.startswith('#'):
|
||||||
unblockHandle=unblockNickname+'@'+unblockDomain
|
unblockHandle=unblockNickname+'@'+unblockDomain
|
||||||
if os.path.isfile(unblockingFilename):
|
if os.path.isfile(unblockingFilename):
|
||||||
if unblockHandle in open(unblockingFilename).read():
|
if unblockHandle in open(unblockingFilename).read():
|
||||||
|
@ -56,6 +66,19 @@ def removeGlobalBlock(baseDir: str, \
|
||||||
if os.path.isfile(unblockingFilename+'.new'):
|
if os.path.isfile(unblockingFilename+'.new'):
|
||||||
os.rename(unblockingFilename+'.new',unblockingFilename)
|
os.rename(unblockingFilename+'.new',unblockingFilename)
|
||||||
return True
|
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
|
return False
|
||||||
|
|
||||||
def removeBlock(baseDir: str,nickname: str,domain: str, \
|
def removeBlock(baseDir: str,nickname: str,domain: str, \
|
||||||
|
@ -79,6 +102,16 @@ def removeBlock(baseDir: str,nickname: str,domain: str, \
|
||||||
return True
|
return True
|
||||||
return False
|
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, \
|
def isBlocked(baseDir: str,nickname: str,domain: str, \
|
||||||
blockNickname: str,blockDomain: str) -> bool:
|
blockNickname: str,blockDomain: str) -> bool:
|
||||||
"""Is the given nickname blocked?
|
"""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 removeBlock
|
||||||
from blocking import addGlobalBlock
|
from blocking import addGlobalBlock
|
||||||
from blocking import removeGlobalBlock
|
from blocking import removeGlobalBlock
|
||||||
|
from blocking import isBlockedHashtag
|
||||||
from config import setConfigParam
|
from config import setConfigParam
|
||||||
from config import getConfigParam
|
from config import getConfigParam
|
||||||
from roles import outboxDelegate
|
from roles import outboxDelegate
|
||||||
|
@ -92,6 +93,7 @@ from webinterface import htmlTermsOfService
|
||||||
from webinterface import htmlHashtagSearch
|
from webinterface import htmlHashtagSearch
|
||||||
from webinterface import htmlModerationInfo
|
from webinterface import htmlModerationInfo
|
||||||
from webinterface import htmlSearchSharedItems
|
from webinterface import htmlSearchSharedItems
|
||||||
|
from webinterface import htmlHashtagBlocked
|
||||||
from shares import getSharesFeedForPerson
|
from shares import getSharesFeedForPerson
|
||||||
from shares import outboxShareUpload
|
from shares import outboxShareUpload
|
||||||
from shares import outboxUndoShareUpload
|
from shares import outboxUndoShareUpload
|
||||||
|
@ -706,6 +708,11 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
hashtag=self.path.split('/tags/')[1]
|
hashtag=self.path.split('/tags/')[1]
|
||||||
if '?page=' in hashtag:
|
if '?page=' in hashtag:
|
||||||
hashtag=hashtag.split('?page=')[0]
|
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= \
|
hashtagStr= \
|
||||||
htmlHashtagSearch(self.server.baseDir,hashtag,pageNumber, \
|
htmlHashtagSearch(self.server.baseDir,hashtag,pageNumber, \
|
||||||
maxPostsInFeed,self.server.session, \
|
maxPostsInFeed,self.server.session, \
|
||||||
|
@ -2160,7 +2167,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
fullBlockDomain=blockDomain+':'+str(blockPort)
|
fullBlockDomain=blockDomain+':'+str(blockPort)
|
||||||
if '@' in moderationText:
|
if '@' in moderationText:
|
||||||
fullBlockDomain=moderationText.split('@')[1]
|
fullBlockDomain=moderationText.split('@')[1]
|
||||||
if fullBlockDomain:
|
if fullBlockDomain or nickname.startswith('#'):
|
||||||
addGlobalBlock(self.server.baseDir, \
|
addGlobalBlock(self.server.baseDir, \
|
||||||
nickname,fullBlockDomain)
|
nickname,fullBlockDomain)
|
||||||
if moderationButton=='unblock':
|
if moderationButton=='unblock':
|
||||||
|
@ -2174,7 +2181,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
fullBlockDomain=blockDomain+':'+str(blockPort)
|
fullBlockDomain=blockDomain+':'+str(blockPort)
|
||||||
if '@' in moderationText:
|
if '@' in moderationText:
|
||||||
fullBlockDomain=moderationText.split('@')[1]
|
fullBlockDomain=moderationText.split('@')[1]
|
||||||
if fullBlockDomain:
|
if fullBlockDomain or nickname.startswith('#'):
|
||||||
removeGlobalBlock(self.server.baseDir, \
|
removeGlobalBlock(self.server.baseDir, \
|
||||||
nickname,fullBlockDomain)
|
nickname,fullBlockDomain)
|
||||||
if moderationButton=='remove':
|
if moderationButton=='remove':
|
||||||
|
|
|
@ -451,6 +451,20 @@ def htmlTermsOfService(baseDir: str,httpPrefix: str,domainFull: str) -> str:
|
||||||
TOSForm+=htmlFooter()
|
TOSForm+=htmlFooter()
|
||||||
return TOSForm
|
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:
|
def htmlSuspended(baseDir: str) -> str:
|
||||||
"""Show the screen for suspended accounts
|
"""Show the screen for suspended accounts
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue