diff --git a/blocking.py b/blocking.py index cfa885a79..d2ddfd89e 100644 --- a/blocking.py +++ b/blocking.py @@ -7,6 +7,8 @@ __email__ = "bob@freedombone.net" __status__ = "Production" import os +from datetime import datetime +from utils import fileLastModified from utils import setConfigParam from utils import hasUsersPath from utils import getFullDomain @@ -374,6 +376,7 @@ def setBrochMode(baseDir: str, domainFull: str, enabled: bool) -> None: # remove instance allow list if os.path.isfile(allowFilename): os.remove(allowFilename) + print('Broch mode turned off') else: # generate instance allow list allowedDomains = [domainFull] @@ -405,5 +408,32 @@ def setBrochMode(baseDir: str, domainFull: str, enabled: bool) -> None: for d in allowedDomains: allowFile.write(d + '\n') allowFile.close() + print('Broch mode enabled') setConfigParam(baseDir, "brochMode", enabled) + + +def brochModeLapses(baseDir: str, lapseDays=7) -> None: + """After broch mode is enabled it automatically + elapses after a period of time + """ + allowFilename = baseDir + '/accounts/allowedinstances.txt' + if not os.path.isfile(allowFilename): + return + lastModified = fileLastModified(allowFilename) + modifiedDate = None + try: + modifiedDate = \ + datetime.strptime(lastModified, "%Y-%m-%dT%H:%M:%SZ") + except BaseException: + return + if not modifiedDate: + return + currTime = datetime.datetime.utcnow() + daysSinceBroch = (currTime - modifiedDate).days + if daysSinceBroch >= lapseDays: + try: + os.remove(allowFilename) + print('Broch mode has elapsed') + except BaseException: + pass diff --git a/inbox.py b/inbox.py index 8f216e1c6..86507b87d 100644 --- a/inbox.py +++ b/inbox.py @@ -51,6 +51,7 @@ from bookmarks import updateBookmarksCollection from bookmarks import undoBookmarksCollectionEntry from blocking import isBlocked from blocking import isBlockedDomain +from blocking import brochModeLapses from filters import isFiltered from utils import updateAnnounceCollection from utils import undoAnnounceCollectionEntry @@ -2518,6 +2519,8 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int, # heartbeat to monitor whether the inbox queue is running heartBeatCtr += 5 if heartBeatCtr >= 10: + # turn off broch mode after it has timed out + brochModeLapses(baseDir) print('>>> Heartbeat Q:' + str(len(queue)) + ' ' + '{:%F %T}'.format(datetime.datetime.now())) heartBeatCtr = 0