2019-07-20 18:25:40 +00:00
|
|
|
__filename__ = "manualapprove.py"
|
|
|
|
__author__ = "Bob Mottram"
|
|
|
|
__license__ = "AGPL3+"
|
|
|
|
__version__ = "0.0.1"
|
|
|
|
__maintainer__ = "Bob Mottram"
|
|
|
|
__email__ = "bob@freedombone.net"
|
|
|
|
__status__ = "Production"
|
|
|
|
|
|
|
|
import os
|
|
|
|
import json
|
|
|
|
import commentjson
|
|
|
|
|
|
|
|
from follow import followedAccountAccepts
|
|
|
|
|
|
|
|
def manualDenyFollowRequest(baseDir: str,nickname: str,domain: str,denyHandle: str) -> None:
|
|
|
|
"""Manually deny a follow request
|
|
|
|
"""
|
2019-08-07 13:42:23 +00:00
|
|
|
handle=nickname+'@'+domain
|
2019-07-20 18:25:40 +00:00
|
|
|
accountsDir=baseDir+'/accounts/'+handle
|
2019-08-07 12:55:22 +00:00
|
|
|
approveFollowsFilename=accountsDir+'/followrequests.txt'
|
2019-08-07 13:31:11 +00:00
|
|
|
if not os.path.isfile(approveFollowsFilename):
|
|
|
|
if debug:
|
|
|
|
print('WARN: Follow requests file '+approveFollowsFilename+' not found')
|
|
|
|
return
|
|
|
|
if denyHandle not in open(approveFollowsFilename).read():
|
2019-08-07 13:05:09 +00:00
|
|
|
return
|
2019-08-07 13:50:31 +00:00
|
|
|
approvefilenew = open(approveFollowsFilename+'.new', 'w+')
|
2019-08-07 13:51:54 +00:00
|
|
|
with open(approveFollowsFilename, 'r') as approvefile:
|
|
|
|
for approveHandle in approvefile:
|
|
|
|
if not approveHandle.startswith(denyHandle):
|
|
|
|
approvefilenew.write(approveHandle)
|
2019-08-07 13:49:21 +00:00
|
|
|
approvefilenew.close()
|
2019-08-07 13:05:09 +00:00
|
|
|
os.rename(approveFollowsFilename+'.new',approveFollowsFilename)
|
|
|
|
print('Follow request from '+denyHandle+' was denied.')
|
2019-07-20 18:25:40 +00:00
|
|
|
|
|
|
|
def manualApproveFollowRequest(session,baseDir: str, \
|
|
|
|
httpPrefix: str,
|
|
|
|
nickname: str,domain: str,port: int, \
|
|
|
|
approveHandle: str, \
|
|
|
|
federationList: [], \
|
|
|
|
sendThreads: [],postLog: [], \
|
|
|
|
cachedWebfingers: {},personCache: {}, \
|
|
|
|
acceptedCaps: [], \
|
2019-08-07 13:05:09 +00:00
|
|
|
debug: bool) -> None:
|
2019-07-20 18:25:40 +00:00
|
|
|
"""Manually approve a follow request
|
|
|
|
"""
|
|
|
|
handle=nickname+'@'+domain
|
|
|
|
accountsDir=baseDir+'/accounts/'+handle
|
2019-08-07 12:55:22 +00:00
|
|
|
approveFollowsFilename=accountsDir+'/followrequests.txt'
|
2019-08-07 13:05:09 +00:00
|
|
|
if not os.path.isfile(approveFollowsFilename):
|
|
|
|
if debug:
|
|
|
|
print('WARN: Follow requests file '+approveFollowsFilename+' not found')
|
|
|
|
return
|
2019-08-07 13:31:11 +00:00
|
|
|
if approveHandle not in open(approveFollowsFilename).read():
|
2019-08-07 13:05:09 +00:00
|
|
|
if debug:
|
|
|
|
print(handle+' not in '+approveFollowsFilename)
|
|
|
|
return
|
2019-08-07 13:52:38 +00:00
|
|
|
approvefilenew = open(approveFollowsFilename+'.new', 'w+')
|
2019-08-07 13:51:54 +00:00
|
|
|
with open(approveFollowsFilename, 'r') as approvefile:
|
|
|
|
for handle in approvefile:
|
|
|
|
if handle.startswith(approveHandle):
|
|
|
|
port2=port
|
|
|
|
if ':' in handle:
|
|
|
|
port2=int(handle.split(':')[1].replace('\n',''))
|
|
|
|
requestsDir=accountsDir+'/requests'
|
|
|
|
followActivityfilename=requestsDir+'/'+handle+'.follow'
|
|
|
|
if os.path.isfile(followActivityfilename):
|
|
|
|
with open(followActivityfilename, 'r') as fp:
|
|
|
|
followJson=commentjson.load(fp)
|
|
|
|
approveNickname=approveHandle.split('@')[0]
|
|
|
|
approveDomain=approveHandle.split('@')[1].replace('\n','')
|
|
|
|
approvePort=port2
|
|
|
|
if ':' in approveDomain:
|
|
|
|
approvePort=approveDomain.split(':')[1]
|
|
|
|
approveDomain=approveDomain.split(':')[0]
|
|
|
|
followedAccountAccepts(session,baseDir,httpPrefix, \
|
|
|
|
nickname,domain,port, \
|
|
|
|
approveNickname,approveDomain,approvePort, \
|
|
|
|
followJson['actor'],federationList, \
|
|
|
|
followJson,acceptedCaps, \
|
|
|
|
sendThreads,postLog, \
|
|
|
|
cachedWebfingers,personCache, \
|
|
|
|
debug)
|
|
|
|
os.remove(followActivityfilename)
|
|
|
|
else:
|
|
|
|
approvefilenew.write(handle)
|
2019-08-07 13:49:21 +00:00
|
|
|
approvefilenew.close()
|
2019-08-07 13:05:09 +00:00
|
|
|
os.rename(approveFollowsFilename+'.new',approveFollowsFilename)
|