From 2fdd644c87154faed22d5d6c5bb2ca07b8a3f857 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 13 Aug 2019 10:24:55 +0100 Subject: [PATCH] Screen for suspended accounts --- daemon.py | 7 +++++ person.py | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ webinterface.py | 16 ++++++++++++ 3 files changed, 92 insertions(+) diff --git a/daemon.py b/daemon.py index 4c474f4e8..4bac92406 100644 --- a/daemon.py +++ b/daemon.py @@ -26,6 +26,7 @@ from person import registerAccount from person import personLookup from person import personBoxJson from person import createSharedInbox +from person import isSuspended from posts import outboxMessageCreateWrap from posts import savePostToBox from posts import sendToFollowers @@ -73,6 +74,7 @@ from webinterface import htmlOutbox from webinterface import htmlModeration from webinterface import htmlPostReplies from webinterface import htmlLogin +from webinterface import htmlSuspended from webinterface import htmlGetLoginCredentials from webinterface import htmlNewPost from webinterface import htmlFollowConfirm @@ -1853,6 +1855,11 @@ class PubServer(BaseHTTPRequestHandler): self.server.POSTbusy=False return else: + if isSuspended(self.server.baseDir,loginNickname): + self._login_headers('text/html') + self.wfile.write(htmlSuspended(self.server.baseDir).encode('utf-8')) + self.server.POSTbusy=False + return # login success - redirect with authorization print('Login success: '+loginNickname) self.send_response(303) diff --git a/person.py b/person.py index 4a6912050..063330aab 100644 --- a/person.py +++ b/person.py @@ -463,3 +463,72 @@ def setBio(baseDir: str,nickname: str, domain: str, bio: str) -> bool: with open(filename, 'w') as fp: commentjson.dump(personJson, fp, indent=4, sort_keys=False) return True + +def isSuspended(baseDir: str,nickname: str) -> bool: + """Returns true if the given nickname is suspended + """ + adminNickname=getConfigParam(baseDir,'admin') + if nickname==adminNickname: + return False + + suspendedFilename=baseDir+'/accounts/suspended.txt' + if os.path.isfile(suspendedFilename): + with open(suspendedFilename, "r") as f: + lines = f.readlines() + suspendedFile=open(suspendedFilename,"w+") + for suspended in lines: + if suspended.strip('\n')==nickname: + return True + return False + +def unsuspendAccount(baseDir: str,nickname: str) -> None: + """Removes an account suspention + """ + suspendedFilename=baseDir+'/accounts/suspended.txt' + if os.path.isfile(suspendedFilename): + with open(suspendedFilename, "r") as f: + lines = f.readlines() + suspendedFile=open(suspendedFilename,"w+") + for suspended in lines: + if suspended.strip('\n')!=nickname: + suspendedFile.write(suspended) + suspendedFile.close() + +def suspendAccount(baseDir: str,nickname: str,salts: {}) -> None: + """Suspends the given account + This also changes the salt used by the authentication token + so that the person can't continue to use the system without + going through the login screen + """ + # Don't suspend the admin + adminNickname=getConfigParam(baseDir,'admin') + if nickname==adminNickname: + return + + # 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 + + suspendedFilename=baseDir+'/accounts/suspended.txt' + if os.path.isfile(suspendedFilename): + with open(suspendedFilename, "r") as f: + lines = f.readlines() + for suspended in lines: + if suspended.strip('\n')==nickname: + return + suspendedFile=open(suspendedFilename,'a+') + if suspendedFile: + suspendedFile.write(nickname+'\n') + suspendedFile.close() + salts[nickname]=createPassword(32) + else: + suspendedFile=open(suspendedFilename,'w+') + if suspendedFile: + suspendedFile.write(nickname+'\n') + suspendedFile.close() + salts[nickname]=createPassword(32) diff --git a/webinterface.py b/webinterface.py index 114179a31..2eb6f3274 100644 --- a/webinterface.py +++ b/webinterface.py @@ -319,6 +319,8 @@ def htmlLogin(baseDir: str) -> str: return loginForm def htmlTermsOfService(baseDir: str,httpPrefix: str,domainFull: str) -> str: + """Show the terms of service screen + """ adminNickname = getConfigParam(baseDir,'admin') if not os.path.isfile(baseDir+'/accounts/tos.txt'): copyfile(baseDir+'/default_tos.txt',baseDir+'/accounts/tos.txt') @@ -343,6 +345,20 @@ def htmlTermsOfService(baseDir: str,httpPrefix: str,domainFull: str) -> str: TOSForm+=htmlFooter() return TOSForm +def htmlSuspended(baseDir: str) -> str: + """Show the screen for suspended accounts + """ + suspendedForm='' + with open(baseDir+'/epicyon-suspended.css', 'r') as cssFile: + suspendedCSS=cssFile.read() + suspendedForm=htmlHeader(suspendedCSS) + suspendedForm+='
' + suspendedForm+='

Account Suspended

' + suspendedForm+='

See Terms of Service

' + suspendedForm+='
' + suspendedForm+=htmlFooter() + return suspendedForm + def htmlNewPost(baseDir: str,path: str,inReplyTo: str,mentions: []) -> str: reportUrl=None if '/newreport?=' in path: