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