mirror of https://gitlab.com/bashrc2/epicyon
Option to list blocked domains for a handle
parent
5bc7a337a0
commit
d354b8a339
43
epicyon.py
43
epicyon.py
|
@ -16,6 +16,7 @@ from skills import setSkillLevel
|
|||
from roles import setRole
|
||||
from webfinger import webfingerHandle
|
||||
from posts import getPublicPostDomains
|
||||
from posts import getPublicPostDomainsBlocked
|
||||
from posts import sendBlockViaServer
|
||||
from posts import sendUndoBlockViaServer
|
||||
from posts import createPublicPost
|
||||
|
@ -157,6 +158,10 @@ parser.add_argument('--postDomains', dest='postDomains', type=str,
|
|||
default=None,
|
||||
help='Show domains referenced in public '
|
||||
'posts for the given handle')
|
||||
parser.add_argument('--postDomainsBlocked', dest='postDomainsBlocked',
|
||||
type=str, default=None,
|
||||
help='Show blocked domains referenced in public '
|
||||
'posts for the given handle')
|
||||
parser.add_argument('--socnet', dest='socnet', type=str,
|
||||
default=None,
|
||||
help='Show dot diagram for social network '
|
||||
|
@ -475,6 +480,44 @@ if args.postDomains:
|
|||
print(postDomain)
|
||||
sys.exit()
|
||||
|
||||
if args.postDomainsBlocked:
|
||||
# Domains which were referenced in public posts by a
|
||||
# given handle but which are globally blocked on this instance
|
||||
if '@' not in args.postDomainsBlocked:
|
||||
if '/users/' in args.postDomainsBlocked:
|
||||
postsNickname = getNicknameFromActor(args.posts)
|
||||
postsDomain, postsPort = getDomainFromActor(args.posts)
|
||||
args.postDomainsBlocked = postsNickname + '@' + postsDomain
|
||||
if postsPort:
|
||||
if postsPort != 80 and postsPort != 443:
|
||||
args.postDomainsBlocked += ':' + str(postsPort)
|
||||
else:
|
||||
print('Syntax: --postDomainsBlocked nickname@domain')
|
||||
sys.exit()
|
||||
if not args.http:
|
||||
args.port = 443
|
||||
nickname = args.postDomainsBlocked.split('@')[0]
|
||||
domain = args.postDomainsBlocked.split('@')[1]
|
||||
proxyType = None
|
||||
if args.tor or domain.endswith('.onion'):
|
||||
proxyType = 'tor'
|
||||
if domain.endswith('.onion'):
|
||||
args.port = 80
|
||||
elif args.i2p or domain.endswith('.i2p'):
|
||||
proxyType = 'i2p'
|
||||
if domain.endswith('.i2p'):
|
||||
args.port = 80
|
||||
elif args.gnunet:
|
||||
proxyType = 'gnunet'
|
||||
domainList = []
|
||||
domainList = getPublicPostDomainsBlocked(baseDir, nickname, domain,
|
||||
proxyType, args.port,
|
||||
httpPrefix, debug,
|
||||
__version__, domainList)
|
||||
for postDomain in domainList:
|
||||
print(postDomain)
|
||||
sys.exit()
|
||||
|
||||
if args.socnet:
|
||||
if ',' not in args.socnet:
|
||||
print('Syntax: '
|
||||
|
|
36
posts.py
36
posts.py
|
@ -3288,6 +3288,42 @@ def getPublicPostDomains(baseDir: str, nickname: str, domain: str,
|
|||
return postDomains
|
||||
|
||||
|
||||
def getPublicPostDomainsBlocked(baseDir: str, nickname: str, domain: str,
|
||||
proxyType: str, port: int, httpPrefix: str,
|
||||
debug: bool, projectVersion: str,
|
||||
domainList=[]) -> []:
|
||||
""" Returns a list of domains referenced within public posts which
|
||||
are globally blocked on this instance
|
||||
"""
|
||||
postDomains = \
|
||||
getPublicPostDomains(baseDir, nickname, domain,
|
||||
proxyType, port, httpPrefix,
|
||||
debug, projectVersion,
|
||||
domainList)
|
||||
if not postDomains:
|
||||
return []
|
||||
|
||||
blockingFilename = baseDir + '/accounts/blocking.txt'
|
||||
if not os.path.isfile(blockingFilename):
|
||||
return []
|
||||
|
||||
# read the blocked domains as a single string
|
||||
blockedStr = ''
|
||||
with open(blockingFilename, 'r') as fp:
|
||||
blockedStr = fp.read()
|
||||
|
||||
blockedDomains = []
|
||||
for domainName in postDomains:
|
||||
if '@' not in domainName:
|
||||
continue
|
||||
# get the domain after the @
|
||||
domainName = domainName.split('@')[1].strip()
|
||||
if domainName in blockedStr:
|
||||
blockedDomains.append(domainName)
|
||||
|
||||
return blockedDomains
|
||||
|
||||
|
||||
def sendCapabilitiesUpdate(session, baseDir: str, httpPrefix: str,
|
||||
nickname: str, domain: str, port: int,
|
||||
followerUrl, updateCaps: [],
|
||||
|
|
Loading…
Reference in New Issue