diff --git a/daemon.py b/daemon.py index 7ad7d5ee4..24233f648 100644 --- a/daemon.py +++ b/daemon.py @@ -877,7 +877,8 @@ class PubServer(BaseHTTPRequestHandler): registration: bool, systemLanguage: str, projectVersion: str, - customEmoji: []) -> bool: + customEmoji: [], + showNodeInfoAccounts: bool) -> bool: """This is a vestigil mastodon API for the purpose of returning an empty result to sites like https://mastopeek.app-dist.eu @@ -977,8 +978,12 @@ class PubServer(BaseHTTPRequestHandler): domainFull = i2pDomain httpPrefix = 'http' + if brochModeIsActive(baseDir): + showNodeInfoAccounts = False + sendJson = \ - metaDataInstance(instanceTitle, + metaDataInstance(showNodeInfoAccounts, + instanceTitle, instanceDescriptionShort, instanceDescription, httpPrefix, @@ -1033,12 +1038,14 @@ class PubServer(BaseHTTPRequestHandler): registration: bool, systemLanguage: str, projectVersion: str, - customEmoji: []) -> bool: + customEmoji: [], + showNodeInfoAccounts: bool) -> bool: return self._mastoApiV1(path, callingDomain, authorized, httpPrefix, baseDir, nickname, domain, domainFull, onionDomain, i2pDomain, translate, registration, systemLanguage, - projectVersion, customEmoji) + projectVersion, customEmoji, + showNodeInfoAccounts) def _nodeinfo(self, callingDomain: str) -> bool: if not self.path.startswith('/nodeinfo/2.0'): @@ -10849,7 +10856,8 @@ class PubServer(BaseHTTPRequestHandler): self.server.registration, self.server.systemLanguage, self.server.projectVersion, - self.server.customEmoji): + self.server.customEmoji, + self.server.showNodeInfoAccounts): return self._benchmarkGETtimings(GETstartTime, GETtimings, @@ -14894,11 +14902,12 @@ def runPostsWatchdog(projectVersion: str, httpd) -> None: httpd.thrPostsQueue.start() while True: time.sleep(20) - if not httpd.thrPostsQueue.is_alive(): - httpd.thrPostsQueue.kill() - httpd.thrPostsQueue = postsQueueOriginal.clone(runPostsQueue) - httpd.thrPostsQueue.start() - print('Restarting posts queue...') + if httpd.thrPostsQueue.is_alive(): + continue + httpd.thrPostsQueue.kill() + httpd.thrPostsQueue = postsQueueOriginal.clone(runPostsQueue) + httpd.thrPostsQueue.start() + print('Restarting posts queue...') def runSharesExpireWatchdog(projectVersion: str, httpd) -> None: @@ -14909,11 +14918,12 @@ def runSharesExpireWatchdog(projectVersion: str, httpd) -> None: httpd.thrSharesExpire.start() while True: time.sleep(20) - if not httpd.thrSharesExpire.is_alive(): - httpd.thrSharesExpire.kill() - httpd.thrSharesExpire = sharesExpireOriginal.clone(runSharesExpire) - httpd.thrSharesExpire.start() - print('Restarting shares expiry...') + if httpd.thrSharesExpire.is_alive(): + continue + httpd.thrSharesExpire.kill() + httpd.thrSharesExpire = sharesExpireOriginal.clone(runSharesExpire) + httpd.thrSharesExpire.start() + print('Restarting shares expiry...') def loadTokens(baseDir: str, tokensDict: {}, tokensLookup: {}) -> None: diff --git a/epicyon.py b/epicyon.py index ab5997893..c33449033 100644 --- a/epicyon.py +++ b/epicyon.py @@ -550,13 +550,13 @@ parser.add_argument('--location', dest='location', type=str, default=None, parser.add_argument('--duration', dest='duration', type=str, default=None, help='Duration for which to share an item') parser.add_argument('--registration', dest='registration', type=str, - default=None, + default='open', help='Whether new registrations are open or closed') parser.add_argument("--nosharedinbox", type=str2bool, nargs='?', const=True, default=False, help='Disable shared inbox') parser.add_argument('--maxregistrations', dest='maxRegistrations', - type=int, default=None, + type=int, default=10, help='The maximum number of new registrations') parser.add_argument("--resetregistrations", type=str2bool, nargs='?', const=True, default=False, diff --git a/metadata.py b/metadata.py index 1c117a672..99f252225 100644 --- a/metadata.py +++ b/metadata.py @@ -12,54 +12,6 @@ from utils import noOfAccounts from utils import noOfActiveAccountsMonthly -def metaDataNodeInfo(baseDir: str, - aboutUrl: str, - termsOfServiceUrl: str, - registration: bool, version: str, - showAccounts: bool) -> {}: - """ /nodeinfo/2.0 endpoint - Also see https://socialhub.activitypub.rocks/t/ - fep-f1d5-nodeinfo-in-fediverse-software/1190/4 - - Note that there are security considerations with this. If an adversary - sees a lot of accounts and "local" posts then the instance may be - considered a higher priority target. - Also exposure of the version number and number of accounts could be - sensitive - """ - if showAccounts: - activeAccounts = noOfAccounts(baseDir) - activeAccountsMonthly = noOfActiveAccountsMonthly(baseDir, 1) - activeAccountsHalfYear = noOfActiveAccountsMonthly(baseDir, 6) - else: - activeAccounts = 1 - activeAccountsMonthly = 1 - activeAccountsHalfYear = 1 - - nodeinfo = { - 'openRegistrations': registration, - 'protocols': ['activitypub'], - 'software': { - 'name': 'epicyon', - 'version': version - }, - 'documents': { - 'about': aboutUrl, - 'terms': termsOfServiceUrl - }, - 'usage': { - 'localPosts': 1, - 'users': { - 'activeHalfyear': activeAccountsHalfYear, - 'activeMonth': activeAccountsMonthly, - 'total': activeAccounts - } - }, - 'version': '2.0' - } - return nodeinfo - - def _getStatusCount(baseDir: str) -> int: """Get the total number of posts """ @@ -79,7 +31,58 @@ def _getStatusCount(baseDir: str) -> int: return statusCtr -def metaDataInstance(instanceTitle: str, +def metaDataNodeInfo(baseDir: str, + aboutUrl: str, + termsOfServiceUrl: str, + registration: bool, version: str, + showAccounts: bool) -> {}: + """ /nodeinfo/2.0 endpoint + Also see https://socialhub.activitypub.rocks/t/ + fep-f1d5-nodeinfo-in-fediverse-software/1190/4 + + Note that there are security considerations with this. If an adversary + sees a lot of accounts and "local" posts then the instance may be + considered a higher priority target. + Also exposure of the version number and number of accounts could be + sensitive + """ + if showAccounts: + activeAccounts = noOfAccounts(baseDir) + activeAccountsMonthly = noOfActiveAccountsMonthly(baseDir, 1) + activeAccountsHalfYear = noOfActiveAccountsMonthly(baseDir, 6) + localPosts = _getStatusCount(baseDir) + else: + activeAccounts = 1 + activeAccountsMonthly = 1 + activeAccountsHalfYear = 1 + localPosts = 1 + + nodeinfo = { + 'openRegistrations': registration, + 'protocols': ['activitypub'], + 'software': { + 'name': 'epicyon', + 'version': version + }, + 'documents': { + 'about': aboutUrl, + 'terms': termsOfServiceUrl + }, + 'usage': { + 'localPosts': localPosts, + 'users': { + 'activeHalfyear': activeAccountsHalfYear, + 'activeMonth': activeAccountsMonthly, + 'total': activeAccounts + } + }, + 'version': '2.0' + } + return nodeinfo + + +def metaDataInstance(showAccounts: bool, + instanceTitle: str, instanceDescriptionShort: str, instanceDescription: str, httpPrefix: str, baseDir: str, @@ -106,6 +109,13 @@ def metaDataInstance(instanceTitle: str, httpPrefix + '://' + domainFull + '/@' + \ adminActor['preferredUsername'] + if showAccounts: + activeAccounts = noOfAccounts(baseDir) + localPosts = _getStatusCount(baseDir) + else: + activeAccounts = 1 + localPosts = 1 + instance = { 'approval_required': False, 'contact_account': { @@ -126,9 +136,9 @@ def metaDataInstance(instanceTitle: str, 'registrations': registration, 'short_description': instanceDescriptionShort, 'stats': { - 'domain_count': 2, - 'status_count': _getStatusCount(baseDir), - 'user_count': noOfAccounts(baseDir) + 'domain_count': 1, + 'status_count': localPosts, + 'user_count': activeAccounts }, 'thumbnail': httpPrefix + '://' + domainFull + '/login.png', 'title': instanceTitle, diff --git a/newsdaemon.py b/newsdaemon.py index e4484beea..93afeca3f 100644 --- a/newsdaemon.py +++ b/newsdaemon.py @@ -750,9 +750,10 @@ def runNewswireWatchdog(projectVersion: str, httpd) -> None: httpd.thrNewswireDaemon.start() while True: time.sleep(50) - if not httpd.thrNewswireDaemon.is_alive(): - httpd.thrNewswireDaemon.kill() - httpd.thrNewswireDaemon = \ - newswireOriginal.clone(runNewswireDaemon) - httpd.thrNewswireDaemon.start() - print('Restarting newswire daemon...') + if httpd.thrNewswireDaemon.is_alive(): + continue + httpd.thrNewswireDaemon.kill() + httpd.thrNewswireDaemon = \ + newswireOriginal.clone(runNewswireDaemon) + httpd.thrNewswireDaemon.start() + print('Restarting newswire daemon...') diff --git a/schedule.py b/schedule.py index 7790b98c1..25cdc2868 100644 --- a/schedule.py +++ b/schedule.py @@ -155,7 +155,7 @@ def runPostSchedule(baseDir: str, httpd, maxScheduledPosts: int): if not os.path.isfile(scheduleIndexFilename): continue _updatePostSchedule(baseDir, account, httpd, maxScheduledPosts) - break + break def runPostScheduleWatchdog(projectVersion: str, httpd) -> None: @@ -167,12 +167,13 @@ def runPostScheduleWatchdog(projectVersion: str, httpd) -> None: httpd.thrPostSchedule.start() while True: time.sleep(20) - if not httpd.thrPostSchedule.is_alive(): - httpd.thrPostSchedule.kill() - httpd.thrPostSchedule = \ - postScheduleOriginal.clone(runPostSchedule) - httpd.thrPostSchedule.start() - print('Restarting scheduled posts...') + if httpd.thrPostSchedule.is_alive(): + continue + httpd.thrPostSchedule.kill() + httpd.thrPostSchedule = \ + postScheduleOriginal.clone(runPostSchedule) + httpd.thrPostSchedule.start() + print('Restarting scheduled posts...') def removeScheduledPosts(baseDir: str, nickname: str, domain: str) -> None: