mirror of https://gitlab.com/bashrc2/epicyon
Function for removing an account
parent
d79a94af4d
commit
2cb5366ee9
35
daemon.py
35
daemon.py
|
@ -27,6 +27,8 @@ from person import personLookup
|
|||
from person import personBoxJson
|
||||
from person import createSharedInbox
|
||||
from person import isSuspended
|
||||
from person import suspendAccount
|
||||
from person import unsuspendAccount
|
||||
from posts import outboxMessageCreateWrap
|
||||
from posts import savePostToBox
|
||||
from posts import sendToFollowers
|
||||
|
@ -2098,11 +2100,40 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
|
||||
# moderator action buttons
|
||||
if authorized and '/users/' in self.path and \
|
||||
self.path.endswith('/moderatoraction'):
|
||||
actorStr=self.path.replace('/moderatoraction','')
|
||||
self.path.endswith('/moderationaction'):
|
||||
actorStr=self.path.replace('/moderationaction','')
|
||||
length = int(self.headers['Content-length'])
|
||||
moderationParams=self.rfile.read(length).decode('utf-8')
|
||||
print('moderationParams: '+moderationParams)
|
||||
if '&' in moderationParams:
|
||||
moderationText=None
|
||||
moderationButton=None
|
||||
for moderationStr in moderationParams.split('&'):
|
||||
if moderationStr=='moderationAction':
|
||||
if '=' in moderationStr:
|
||||
moderationText=moderationStr.split('=')[1].strip()
|
||||
moderationText=moderationText.replace('+',' ').replace('%40','@').replace('%3A',':').replace('%23','#').strip()
|
||||
elif moderationStr.startswith('submitBlock'):
|
||||
moderationButton='block'
|
||||
elif moderationStr.startswith('submitUnblock'):
|
||||
moderationButton='unblock'
|
||||
elif moderationStr.startswith('submitSuspend'):
|
||||
moderationButton='suspend'
|
||||
elif moderationStr.startswith('submitUnsuspend'):
|
||||
moderationButton='unsuspend'
|
||||
elif moderationStr.startswith('submitRemove'):
|
||||
moderationButton='remove'
|
||||
if moderationButton and moderationText:
|
||||
nickname=moderationText
|
||||
if nickname.startswith('http') or \
|
||||
nickname.startswith('dat'):
|
||||
nickname=getNicknameFromActor(nickname)
|
||||
if '@' in nickname:
|
||||
nickname=nickname.split('@')[0]
|
||||
if moderationButton=='suspend':
|
||||
suspendAccount(self.server.baseDir,nickname,self.server.salts)
|
||||
if moderationButton=='unsuspend':
|
||||
unsuspendAccount(self.server.baseDir,nickname)
|
||||
self._redirect_headers(actorStr+'/moderation',cookie)
|
||||
self.server.POSTbusy=False
|
||||
return
|
||||
|
|
21
epicyon.py
21
epicyon.py
|
@ -12,6 +12,7 @@ from person import createCapabilitiesInbox
|
|||
from person import setPreferredNickname
|
||||
from person import setBio
|
||||
from person import setProfileImage
|
||||
from person import removeAccount
|
||||
from skills import setSkillLevel
|
||||
from roles import setRole
|
||||
from person import setOrganizationScheme
|
||||
|
@ -843,25 +844,7 @@ if args.rmaccount:
|
|||
if not args.domain or not getConfigParam(baseDir,'domain'):
|
||||
print('Use the --domain option to set the domain name')
|
||||
sys.exit()
|
||||
handle=nickname+'@'+domain
|
||||
accountRemoved=False
|
||||
removePassword(baseDir,nickname)
|
||||
if os.path.isdir(baseDir+'/accounts/'+handle):
|
||||
shutil.rmtree(baseDir+'/accounts/'+handle)
|
||||
accountRemoved=True
|
||||
if os.path.isfile(baseDir+'/accounts/'+handle+'.json'):
|
||||
os.remove(baseDir+'/accounts/'+handle+'.json')
|
||||
accountRemoved=True
|
||||
if os.path.isfile(baseDir+'/wfendpoints/'+handle+'.json'):
|
||||
os.remove(baseDir+'/wfendpoints/'+handle+'.json')
|
||||
accountRemoved=True
|
||||
if os.path.isfile(baseDir+'/keys/private/'+handle+'.key'):
|
||||
os.remove(baseDir+'/keys/private/'+handle+'.key')
|
||||
accountRemoved=True
|
||||
if os.path.isfile(baseDir+'/keys/public/'+handle+'.pem'):
|
||||
os.remove(baseDir+'/keys/public/'+handle+'.pem')
|
||||
accountRemoved=True
|
||||
if accountRemoved:
|
||||
if removeAccount(baseDir,nickname,domain):
|
||||
print('Account for '+handle+' was removed')
|
||||
sys.exit()
|
||||
|
||||
|
|
36
person.py
36
person.py
|
@ -11,6 +11,7 @@ import commentjson
|
|||
import os
|
||||
import fileinput
|
||||
import subprocess
|
||||
import shutil
|
||||
from pprint import pprint
|
||||
from pathlib import Path
|
||||
from Crypto.PublicKey import RSA
|
||||
|
@ -21,6 +22,7 @@ from posts import createInbox
|
|||
from posts import createOutbox
|
||||
from posts import createModeration
|
||||
from auth import storeBasicCredentials
|
||||
from auth import removePassword
|
||||
from roles import setRole
|
||||
from media import removeMetaData
|
||||
from utils import validNickname
|
||||
|
@ -532,3 +534,37 @@ def suspendAccount(baseDir: str,nickname: str,salts: {}) -> None:
|
|||
suspendedFile.write(nickname+'\n')
|
||||
suspendedFile.close()
|
||||
salts[nickname]=createPassword(32)
|
||||
|
||||
def removeAccount(baseDir: str,nickname: str,domain: str) -> bool:
|
||||
"""Removes an account
|
||||
"""
|
||||
# Don't suspend the admin
|
||||
adminNickname=getConfigParam(baseDir,'admin')
|
||||
if nickname==adminNickname:
|
||||
return False
|
||||
|
||||
# Don't suspend moderators
|
||||
moderatorsFile=baseDir+'/accounts/moderators.txt'
|
||||
if os.path.isfile(moderatorsFile):
|
||||
with open(moderatorsFile, "r") as f:
|
||||
lines = f.readlines()
|
||||
for moderator in lines:
|
||||
if moderator.strip('\n')==nickname:
|
||||
return False
|
||||
|
||||
unsuspendAccount(baseDir,nickname)
|
||||
handle=nickname+'@'+domain
|
||||
removePassword(baseDir,nickname)
|
||||
if os.path.isdir(baseDir+'/accounts/'+handle):
|
||||
shutil.rmtree(baseDir+'/accounts/'+handle)
|
||||
if os.path.isfile(baseDir+'/accounts/'+handle+'.json'):
|
||||
os.remove(baseDir+'/accounts/'+handle+'.json')
|
||||
if os.path.isfile(baseDir+'/wfendpoints/'+handle+'.json'):
|
||||
os.remove(baseDir+'/wfendpoints/'+handle+'.json')
|
||||
if os.path.isfile(baseDir+'/keys/private/'+handle+'.key'):
|
||||
os.remove(baseDir+'/keys/private/'+handle+'.key')
|
||||
if os.path.isfile(baseDir+'/keys/public/'+handle+'.pem'):
|
||||
os.remove(baseDir+'/keys/public/'+handle+'.pem')
|
||||
if os.path.isdir(baseDir+'/sharefiles/'+nickname):
|
||||
shutil.rmtree(baseDir+'/sharefiles/'+nickname)
|
||||
return True
|
||||
|
|
Loading…
Reference in New Issue