2019-07-20 18:25:40 +00:00
|
|
|
__filename__ = "manualapprove.py"
|
|
|
|
__author__ = "Bob Mottram"
|
|
|
|
__license__ = "AGPL3+"
|
2019-08-29 13:35:29 +00:00
|
|
|
__version__ = "1.0.0"
|
2019-07-20 18:25:40 +00:00
|
|
|
__maintainer__ = "Bob Mottram"
|
|
|
|
__email__ = "bob@freedombone.net"
|
|
|
|
__status__ = "Production"
|
|
|
|
|
|
|
|
import os
|
|
|
|
import json
|
|
|
|
import commentjson
|
|
|
|
|
|
|
|
from follow import followedAccountAccepts
|
2019-09-09 12:19:00 +00:00
|
|
|
from follow import followedAccountRejects
|
2019-09-18 17:04:19 +00:00
|
|
|
from follow import removeFromFollowRequests
|
2019-07-20 18:25:40 +00:00
|
|
|
|
2019-09-09 12:19:00 +00:00
|
|
|
def manualDenyFollowRequest(session,baseDir: str, \
|
|
|
|
httpPrefix: str,
|
|
|
|
nickname: str,domain: str,port: int, \
|
|
|
|
denyHandle: str, \
|
|
|
|
federationList: [], \
|
|
|
|
sendThreads: [],postLog: [], \
|
|
|
|
cachedWebfingers: {},personCache: {}, \
|
|
|
|
debug: bool, \
|
|
|
|
projectVersion: str) -> None:
|
2019-07-20 18:25:40 +00:00
|
|
|
"""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-09-09 08:50:28 +00:00
|
|
|
|
|
|
|
# has this handle already been rejected?
|
|
|
|
rejectedFollowsFilename=accountsDir+'/followrejects.txt'
|
|
|
|
if os.path.isfile(rejectedFollowsFilename):
|
|
|
|
if denyHandle in open(rejectedFollowsFilename).read():
|
2019-09-18 17:30:19 +00:00
|
|
|
removeFromFollowRequests(baseDir,nickname,domain,denyHandle)
|
2019-09-09 08:50:28 +00:00
|
|
|
print(denyHandle+' has already been rejected as a follower of '+nickname)
|
|
|
|
return
|
|
|
|
|
2019-09-18 17:04:19 +00:00
|
|
|
removeFromFollowRequests(baseDir,nickname,domain,denyHandle)
|
2019-09-09 08:50:28 +00:00
|
|
|
|
|
|
|
# Store rejected follows
|
|
|
|
rejectsFile=open(rejectedFollowsFilename, "a+")
|
|
|
|
rejectsFile.write(denyHandle+'\n')
|
|
|
|
rejectsFile.close()
|
2019-09-09 12:19:00 +00:00
|
|
|
|
|
|
|
denyNickname=denyHandle.split('@')[0]
|
|
|
|
approveDomain=denyHandle.split('@')[1].replace('\n','')
|
|
|
|
approvePort=port
|
|
|
|
if ':' in denyDomain:
|
|
|
|
denyPort=denyDomain.split(':')[1]
|
|
|
|
denyDomain=denyDomain.split(':')[0]
|
|
|
|
followedAccountRejects(session,baseDir,httpPrefix, \
|
|
|
|
nickname,domain,port, \
|
|
|
|
denyNickname,denyDomain,denyPort, \
|
|
|
|
followJson['actor'],federationList, \
|
|
|
|
followJson, \
|
|
|
|
sendThreads,postLog, \
|
|
|
|
cachedWebfingers,personCache, \
|
|
|
|
debug,projectVersion)
|
2019-09-09 08:50:28 +00:00
|
|
|
|
2019-08-07 13:05:09 +00:00
|
|
|
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-14 20:12:27 +00:00
|
|
|
debug: bool, \
|
|
|
|
projectVersion: str) -> None:
|
2019-07-20 18:25:40 +00:00
|
|
|
"""Manually approve a follow request
|
|
|
|
"""
|
2019-08-31 14:33:21 +00:00
|
|
|
print('Manually approving follow request from '+approveHandle)
|
2019-07-20 18:25:40 +00:00
|
|
|
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-26 22:22:01 +00:00
|
|
|
|
2019-08-07 13:52:38 +00:00
|
|
|
approvefilenew = open(approveFollowsFilename+'.new', 'w+')
|
2019-08-31 14:21:59 +00:00
|
|
|
updateApprovedFollowers=False
|
2019-08-07 13:51:54 +00:00
|
|
|
with open(approveFollowsFilename, 'r') as approvefile:
|
|
|
|
for handle in approvefile:
|
|
|
|
if handle.startswith(approveHandle):
|
2019-08-07 16:57:27 +00:00
|
|
|
handle=handle.replace('\n','')
|
2019-08-07 13:51:54 +00:00
|
|
|
port2=port
|
|
|
|
if ':' in handle:
|
2019-08-07 16:57:27 +00:00
|
|
|
port2=int(handle.split(':')[1])
|
2019-08-07 13:51:54 +00:00
|
|
|
requestsDir=accountsDir+'/requests'
|
|
|
|
followActivityfilename=requestsDir+'/'+handle+'.follow'
|
|
|
|
if os.path.isfile(followActivityfilename):
|
2019-09-30 22:39:02 +00:00
|
|
|
followJson=None
|
|
|
|
try:
|
|
|
|
with open(followActivityfilename, 'r') as fp:
|
|
|
|
followJson=commentjson.load(fp)
|
|
|
|
except Exception as e:
|
|
|
|
print(e)
|
|
|
|
if followJson:
|
2019-08-07 13:51:54 +00:00
|
|
|
approveNickname=approveHandle.split('@')[0]
|
|
|
|
approveDomain=approveHandle.split('@')[1].replace('\n','')
|
|
|
|
approvePort=port2
|
|
|
|
if ':' in approveDomain:
|
|
|
|
approvePort=approveDomain.split(':')[1]
|
|
|
|
approveDomain=approveDomain.split(':')[0]
|
2019-08-31 14:33:21 +00:00
|
|
|
print('Sending Accept for '+handle+' follow request from '+approveHandle)
|
2019-08-07 13:51:54 +00:00
|
|
|
followedAccountAccepts(session,baseDir,httpPrefix, \
|
|
|
|
nickname,domain,port, \
|
|
|
|
approveNickname,approveDomain,approvePort, \
|
|
|
|
followJson['actor'],federationList, \
|
|
|
|
followJson,acceptedCaps, \
|
|
|
|
sendThreads,postLog, \
|
|
|
|
cachedWebfingers,personCache, \
|
2019-08-14 20:12:27 +00:00
|
|
|
debug,projectVersion)
|
2019-08-07 13:51:54 +00:00
|
|
|
os.remove(followActivityfilename)
|
2019-08-31 14:21:59 +00:00
|
|
|
updateApprovedFollowers=True
|
2019-08-07 13:51:54 +00:00
|
|
|
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)
|
2019-08-31 14:21:59 +00:00
|
|
|
|
|
|
|
if updateApprovedFollowers:
|
|
|
|
# update the followers
|
|
|
|
followersFilename=accountsDir+'/followers.txt'
|
|
|
|
if os.path.isfile(followersFilename):
|
|
|
|
if approveHandle not in open(followersFilename).read():
|
|
|
|
followersFile=open(followersFilename, "a+")
|
|
|
|
followersFile.write(approveHandle+'\n')
|
|
|
|
followersFile.close()
|
|
|
|
else:
|
|
|
|
followersFile=open(followersFilename, "w+")
|
2019-08-26 22:22:01 +00:00
|
|
|
followersFile.write(approveHandle+'\n')
|
|
|
|
followersFile.close()
|