From d95ebd9439e2bd94c9e217322134db7ea37ebd65 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 20 Jul 2019 19:25:40 +0100 Subject: [PATCH] Manually approving followers --- acceptreject.py | 33 ---------------------- epicyon.py | 19 +++++++++++-- manualapprove.py | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 36 deletions(-) create mode 100644 manualapprove.py diff --git a/acceptreject.py b/acceptreject.py index ab1a5b888..04a5f4779 100644 --- a/acceptreject.py +++ b/acceptreject.py @@ -193,36 +193,3 @@ def receiveAcceptReject(session,baseDir: str, \ if debug: print('DEBUG: Uh, '+messageJson['type']+', I guess') return True - -def manualDenyFollowRequest(baseDir: str,nickname: str,domain: str,denyHandle: str) -> None: - """Manually deny a follow request - """ - handle=args.nickname+'@'+domain - accountsDir=baseDir+'/accounts/'+handle - approveFollowsFilename=accountDir+'/followrequests.txt' - if handle in open(approveFollowsFilename).read(): - with open(approveFollowsFilename+'.new', 'w') as approvefilenew: - with open(approveFollowsFilename, 'r') as approvefile: - for approveHandle in approvefile: - if not approveHandle.startswith(denyHandle): - approvefilenew.write(approveHandle) - os.rename(approveFollowsFilename+'.new',approveFollowsFilename) - print('Follow request from '+denyHandle+' was denied.') - -def manualApproveFollowRequest(baseDir: str,nickname: str,domain: str,approveHandle: str): - """Manually approve a follow request - """ - handle=nickname+'@'+domain - accountsDir=baseDir+'/accounts/'+handle - approveFollowsFilename=accountDir+'/followrequests.txt' - if handle in open(approveFollowsFilename).read(): - with open(approveFollowsFilename+'.new', 'w') as approvefilenew: - with open(approveFollowsFilename, 'r') as approvefile: - for handle in approvefile: - if handle.startswith(approveHandle): - if ':' in handle: - port=int(handle.split(':')[1].replace('\n','')) - # TODO approve follow for handle/port - else: - approvefilenew.write(handle) - os.rename(approveFollowsFilename+'.new',approveFollowsFilename) diff --git a/epicyon.py b/epicyon.py index 50554d6f9..46a70adf7 100644 --- a/epicyon.py +++ b/epicyon.py @@ -70,8 +70,8 @@ from roles import sendRoleViaServer from skills import sendSkillViaServer from availability import setAvailability from availability import sendAvailabilityViaServer -from acceptreject import manualDenyFollowRequest -from acceptreject import manualApproveFollowRequest +from manualapprove import manualDenyFollowRequest +from manualapprove import manualApproveFollowRequest import argparse def str2bool(v): @@ -336,7 +336,20 @@ if args.approve: if '@' not in args.approve: print('syntax: --approve nick@domain') sys.exit() - manualApproveFollowRequest(baseDir,args.nickname,domain,args.approve) + sendThreads=[] + postLog=[] + cachedWebfingers={} + personCache={} + acceptedCaps=[] + manualApproveFollowRequest(session,baseDir, \ + httpPrefix, + args.nickname,domain,port, \ + args.approve, \ + federationList, \ + sendThreads,postLog, \ + cachedWebfingers,personCache, \ + acceptedCaps, \ + debug) sys.exit() if args.deny: diff --git a/manualapprove.py b/manualapprove.py new file mode 100644 index 000000000..f02a0afbc --- /dev/null +++ b/manualapprove.py @@ -0,0 +1,73 @@ +__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 + """ + handle=args.nickname+'@'+domain + accountsDir=baseDir+'/accounts/'+handle + approveFollowsFilename=accountDir+'/followrequests.txt' + if handle in open(approveFollowsFilename).read(): + with open(approveFollowsFilename+'.new', 'w') as approvefilenew: + with open(approveFollowsFilename, 'r') as approvefile: + for approveHandle in approvefile: + if not approveHandle.startswith(denyHandle): + approvefilenew.write(approveHandle) + os.rename(approveFollowsFilename+'.new',approveFollowsFilename) + print('Follow request from '+denyHandle+' was denied.') + +def manualApproveFollowRequest(session,baseDir: str, \ + httpPrefix: str, + nickname: str,domain: str,port: int, \ + approveHandle: str, \ + federationList: [], \ + sendThreads: [],postLog: [], \ + cachedWebfingers: {},personCache: {}, \ + acceptedCaps: [], \ + debug: bool): + """Manually approve a follow request + """ + handle=nickname+'@'+domain + accountsDir=baseDir+'/accounts/'+handle + approveFollowsFilename=accountDir+'/followrequests.txt' + if handle in open(approveFollowsFilename).read(): + with open(approveFollowsFilename+'.new', 'w') as approvefilenew: + with open(approveFollowsFilename, 'r') as approvefile: + for handle in approvefile: + if handle.startswith(approveHandle): + if ':' in handle: + port=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=port + 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) + os.rename(approveFollowsFilename+'.new',approveFollowsFilename)