mirror of https://gitlab.com/bashrc2/epicyon
Instance allow list for receiving DMs
parent
dcb5e4d2dd
commit
702fa3167f
5
inbox.py
5
inbox.py
|
@ -11,6 +11,7 @@ import os
|
|||
import datetime
|
||||
import time
|
||||
from linked_data_sig import verifyJsonSignature
|
||||
from utils import dmAllowedFromDomain
|
||||
from utils import isRecentPost
|
||||
from utils import getConfigParam
|
||||
from utils import hasUsersPath
|
||||
|
@ -2466,6 +2467,10 @@ def _inboxAfterInitial(recentPostsCache: {}, maxRecentPosts: int,
|
|||
if not isFollowingActor(baseDir,
|
||||
nickname, domain,
|
||||
sendH):
|
||||
# DMs may always be allowed from some domains
|
||||
if not dmAllowedFromDomain(baseDir,
|
||||
nickname, domain,
|
||||
sendingActorDomain):
|
||||
# send back a bounce DM
|
||||
if postJsonObject.get('id') and \
|
||||
postJsonObject.get('object'):
|
||||
|
|
19
utils.py
19
utils.py
|
@ -2203,3 +2203,22 @@ def loadTranslationsFromFile(baseDir: str, language: str) -> ({}, str):
|
|||
translationsFile = baseDir + '/translations/' + \
|
||||
systemLanguage + '.json'
|
||||
return loadJson(translationsFile), systemLanguage
|
||||
|
||||
|
||||
def dmAllowedFromDomain(baseDir: str,
|
||||
nickname: str, domain: str,
|
||||
sendingActorDomain: str):
|
||||
"""When a DM is received and the .followDMs flag file exists
|
||||
Then optionally some domains can be specified as allowed,
|
||||
regardless of individual follows.
|
||||
i.e. Mostly you only want DMs from followers, but there are
|
||||
a few particular instances that you trust
|
||||
"""
|
||||
dmAllowedDomainsFilename = \
|
||||
baseDir + '/accounts/' + \
|
||||
nickname + '@' + domain + '/dmAllowedDomains.txt'
|
||||
if not os.path.isfile(dmAllowedDomainsFilename):
|
||||
return False
|
||||
if sendingActorDomain + '\n' in open(dmAllowedDomainsFilename).read():
|
||||
return True
|
||||
return False
|
||||
|
|
Loading…
Reference in New Issue