forked from indymedia/epicyon
Maximum limit on emoji within a post
parent
1e9bffa6a3
commit
96fd59d295
|
@ -4853,7 +4853,7 @@ def runDaemon(enableSharedInbox: bool,registration: bool, \
|
|||
instanceId: str,clientToServer: bool, \
|
||||
baseDir: str,domain: str, \
|
||||
port=80,proxyPort=80,httpPrefix='https', \
|
||||
fedList=[],maxMentions=10, \
|
||||
fedList=[],maxMentions=10,maxEmoji=10, \
|
||||
authenticatedFetch=False, \
|
||||
noreply=False,nolike=False,nopics=False, \
|
||||
noannounce=False,cw=False,ocapAlways=False, \
|
||||
|
@ -5027,7 +5027,8 @@ def runDaemon(enableSharedInbox: bool,registration: bool, \
|
|||
domain,port,useTor,httpd.federationList, \
|
||||
httpd.ocapAlways,maxReplies, \
|
||||
domainMaxPostsPerDay,accountMaxPostsPerDay, \
|
||||
allowDeletion,debug,maxMentions,httpd.translate, \
|
||||
allowDeletion,debug,maxMentions,maxEmoji, \
|
||||
httpd.translate, \
|
||||
unitTest,httpd.acceptedCaps),daemon=True)
|
||||
if not unitTest:
|
||||
httpd.thrWatchdog= \
|
||||
|
|
|
@ -243,6 +243,8 @@ parser.add_argument('--maxreplies', dest='maxReplies', type=int,default=64, \
|
|||
help='Maximum number of replies to a post')
|
||||
parser.add_argument('--maxMentions','--hellthread', dest='maxMentions', type=int,default=10, \
|
||||
help='Maximum number of mentions within a post')
|
||||
parser.add_argument('--maxEmoji','--maxemoji', dest='maxEmoji', type=int,default=10, \
|
||||
help='Maximum number of emoji within a post')
|
||||
parser.add_argument('--role', dest='role', type=str,default=None, \
|
||||
help='Set a role for a person')
|
||||
parser.add_argument('--organization','--project', dest='project', type=str,default=None, \
|
||||
|
@ -1482,7 +1484,7 @@ runDaemon(not args.nosharedinbox, \
|
|||
instanceId,args.client,baseDir, \
|
||||
domain,port,proxyPort,httpPrefix, \
|
||||
federationList,args.maxMentions, \
|
||||
args.authenticatedFetch, \
|
||||
args.maxEmoji,args.authenticatedFetch, \
|
||||
args.noreply,args.nolike,args.nopics, \
|
||||
args.noannounce,args.cw,ocapAlways, \
|
||||
useTor,args.maxReplies, \
|
||||
|
|
39
inbox.py
39
inbox.py
|
@ -1181,14 +1181,14 @@ def populateReplies(baseDir :str,httpPrefix :str,domain :str, \
|
|||
def estimateNumberOfMentions(content: str) -> int:
|
||||
"""Returns a rough estimate of the number of mentions
|
||||
"""
|
||||
words=content.split(' ')
|
||||
ctr=0
|
||||
for word in words:
|
||||
if word.startswith('@') or '>@' in word:
|
||||
ctr+=1
|
||||
return ctr
|
||||
return int(content.count('@')/2)
|
||||
|
||||
def validPostContent(messageJson: {},maxMentions: int) -> bool:
|
||||
def estimateNumberOfEmoji(content: str) -> int:
|
||||
"""Returns a rough estimate of the number of emoji
|
||||
"""
|
||||
return int(content.count(':')/2)
|
||||
|
||||
def validPostContent(messageJson: {},maxMentions: int,maxEmoji: int) -> bool:
|
||||
"""Is the content of a received post valid?
|
||||
Check for bad html
|
||||
Check for hellthreads
|
||||
|
@ -1205,14 +1205,19 @@ def validPostContent(messageJson: {},maxMentions: int) -> bool:
|
|||
for badStr in invalidStrings:
|
||||
if badStr in messageJson['object']['content']:
|
||||
if messageJson['object'].get('id'):
|
||||
print('REJECT: '+messageJson['object']['id'])
|
||||
print('REJECT: bad string in post - '+messageJson['object']['content'])
|
||||
print('REJECT ARBITRARY HTML: '+messageJson['object']['id'])
|
||||
print('REJECT ARBITRARY HTML: bad string in post - '+messageJson['object']['content'])
|
||||
return False
|
||||
# check (rough) number of mentions
|
||||
if estimateNumberOfMentions(messageJson['object']['content'])>maxMentions:
|
||||
if messageJson['object'].get('id'):
|
||||
print('REJECT: '+messageJson['object']['id'])
|
||||
print('REJECT: Too many mentions in post - '+messageJson['object']['content'])
|
||||
print('REJECT HELLTHREAD: '+messageJson['object']['id'])
|
||||
print('REJECT HELLTHREAD: Too many mentions in post - '+messageJson['object']['content'])
|
||||
return False
|
||||
if estimateNumberOfEmoji(messageJson['object']['content'])>maxEmoji:
|
||||
if messageJson['object'].get('id'):
|
||||
print('REJECT EMOJI OVERLOAD: '+messageJson['object']['id'])
|
||||
print('REJECT EMOJI OVERLOAD: Too many emoji in post - '+messageJson['object']['content'])
|
||||
return False
|
||||
# check number of tags
|
||||
if messageJson['object'].get('tag'):
|
||||
|
@ -1476,7 +1481,7 @@ def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \
|
|||
acceptedCaps: [], \
|
||||
queueFilename :str,destinationFilename :str, \
|
||||
maxReplies: int,allowDeletion: bool, \
|
||||
maxMentions: int,translate: {}, \
|
||||
maxMentions: int,maxEmoji: int,translate: {}, \
|
||||
unitTest: bool) -> bool:
|
||||
""" Anything which needs to be done after capabilities checks have passed
|
||||
"""
|
||||
|
@ -1562,7 +1567,7 @@ def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \
|
|||
else:
|
||||
postJsonObject=messageJson
|
||||
|
||||
if validPostContent(postJsonObject,maxMentions):
|
||||
if validPostContent(postJsonObject,maxMentions,maxEmoji):
|
||||
# list of indexes to be updated
|
||||
updateIndexList=['inbox']
|
||||
populateReplies(baseDir,httpPrefix,domain,messageJson,maxReplies,debug)
|
||||
|
@ -1682,7 +1687,7 @@ def runInboxQueue(projectVersion: str, \
|
|||
ocapAlways: bool,maxReplies: int, \
|
||||
domainMaxPostsPerDay: int,accountMaxPostsPerDay: int, \
|
||||
allowDeletion: bool,debug: bool,maxMentions: int, \
|
||||
translate: {},unitTest: bool, \
|
||||
maxEmoji: int,translate: {},unitTest: bool, \
|
||||
acceptedCaps=["inbox:write","objects:read"]) -> None:
|
||||
"""Processes received items and moves them to
|
||||
the appropriate directories
|
||||
|
@ -2034,7 +2039,8 @@ def runInboxQueue(projectVersion: str, \
|
|||
debug,acceptedCaps, \
|
||||
queueFilename,destination, \
|
||||
maxReplies,allowDeletion, \
|
||||
maxMentions,translate,unitTest)
|
||||
maxMentions,maxEmoji, \
|
||||
translate,unitTest)
|
||||
else:
|
||||
if debug:
|
||||
print('DEBUG: object capabilities check has failed')
|
||||
|
@ -2052,7 +2058,8 @@ def runInboxQueue(projectVersion: str, \
|
|||
debug,acceptedCaps, \
|
||||
queueFilename,destination, \
|
||||
maxReplies,allowDeletion, \
|
||||
maxMentions,translate,unitTest)
|
||||
maxMentions,maxEmoji, \
|
||||
translate,unitTest)
|
||||
if debug:
|
||||
pprint(queueJson['post'])
|
||||
print('No capability list within post')
|
||||
|
|
9
tests.py
9
tests.py
|
@ -228,10 +228,11 @@ def createServerAlice(path: str,domain: str,port: int,federationList: [], \
|
|||
global testServerAliceRunning
|
||||
testServerAliceRunning = True
|
||||
maxMentions=10
|
||||
maxEmoji=10
|
||||
print('Server running: Alice')
|
||||
runDaemon(True,True,'en',__version__, \
|
||||
"instanceId",False,path,domain,port,port, \
|
||||
httpPrefix,federationList,maxMentions,False, \
|
||||
httpPrefix,federationList,maxMentions,maxEmoji,False, \
|
||||
noreply,nolike,nopics,noannounce,cw,ocapAlways, \
|
||||
useTor,maxReplies, \
|
||||
domainMaxPostsPerDay,accountMaxPostsPerDay, \
|
||||
|
@ -283,10 +284,11 @@ def createServerBob(path: str,domain: str,port: int,federationList: [], \
|
|||
global testServerBobRunning
|
||||
testServerBobRunning = True
|
||||
maxMentions=10
|
||||
maxEmoji=10
|
||||
print('Server running: Bob')
|
||||
runDaemon(True,True,'en',__version__, \
|
||||
"instanceId",False,path,domain,port,port, \
|
||||
httpPrefix,federationList,maxMentions,False, \
|
||||
httpPrefix,federationList,maxMentions,maxEmoji,False, \
|
||||
noreply,nolike,nopics,noannounce,cw,ocapAlways, \
|
||||
useTor,maxReplies, \
|
||||
domainMaxPostsPerDay,accountMaxPostsPerDay, \
|
||||
|
@ -318,10 +320,11 @@ def createServerEve(path: str,domain: str,port: int,federationList: [], \
|
|||
global testServerEveRunning
|
||||
testServerEveRunning = True
|
||||
maxMentions=10
|
||||
maxEmoji=10
|
||||
print('Server running: Eve')
|
||||
runDaemon(True,True,'en',__version__, \
|
||||
"instanceId",False,path,domain,port,port, \
|
||||
httpPrefix,federationList,maxMentions,False, \
|
||||
httpPrefix,federationList,maxMentions,maxEmoji,False, \
|
||||
noreply,nolike,nopics,noannounce,cw,ocapAlways, \
|
||||
useTor,maxReplies,allowDeletion,True,True,False,sendThreads)
|
||||
|
||||
|
|
Loading…
Reference in New Issue