Merge branch 'main' of ssh://code.freedombone.net:2222/bashrc/epicyon

main
Bob Mottram 2021-06-05 14:20:52 +01:00
commit d4d6bb7353
5 changed files with 104 additions and 82 deletions

View File

@ -877,7 +877,8 @@ class PubServer(BaseHTTPRequestHandler):
registration: bool, registration: bool,
systemLanguage: str, systemLanguage: str,
projectVersion: str, projectVersion: str,
customEmoji: []) -> bool: customEmoji: [],
showNodeInfoAccounts: bool) -> bool:
"""This is a vestigil mastodon API for the purpose """This is a vestigil mastodon API for the purpose
of returning an empty result to sites like of returning an empty result to sites like
https://mastopeek.app-dist.eu https://mastopeek.app-dist.eu
@ -977,8 +978,12 @@ class PubServer(BaseHTTPRequestHandler):
domainFull = i2pDomain domainFull = i2pDomain
httpPrefix = 'http' httpPrefix = 'http'
if brochModeIsActive(baseDir):
showNodeInfoAccounts = False
sendJson = \ sendJson = \
metaDataInstance(instanceTitle, metaDataInstance(showNodeInfoAccounts,
instanceTitle,
instanceDescriptionShort, instanceDescriptionShort,
instanceDescription, instanceDescription,
httpPrefix, httpPrefix,
@ -1033,12 +1038,14 @@ class PubServer(BaseHTTPRequestHandler):
registration: bool, registration: bool,
systemLanguage: str, systemLanguage: str,
projectVersion: str, projectVersion: str,
customEmoji: []) -> bool: customEmoji: [],
showNodeInfoAccounts: bool) -> bool:
return self._mastoApiV1(path, callingDomain, authorized, return self._mastoApiV1(path, callingDomain, authorized,
httpPrefix, baseDir, nickname, domain, httpPrefix, baseDir, nickname, domain,
domainFull, onionDomain, i2pDomain, domainFull, onionDomain, i2pDomain,
translate, registration, systemLanguage, translate, registration, systemLanguage,
projectVersion, customEmoji) projectVersion, customEmoji,
showNodeInfoAccounts)
def _nodeinfo(self, callingDomain: str) -> bool: def _nodeinfo(self, callingDomain: str) -> bool:
if not self.path.startswith('/nodeinfo/2.0'): if not self.path.startswith('/nodeinfo/2.0'):
@ -10849,7 +10856,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.registration, self.server.registration,
self.server.systemLanguage, self.server.systemLanguage,
self.server.projectVersion, self.server.projectVersion,
self.server.customEmoji): self.server.customEmoji,
self.server.showNodeInfoAccounts):
return return
self._benchmarkGETtimings(GETstartTime, GETtimings, self._benchmarkGETtimings(GETstartTime, GETtimings,
@ -14894,11 +14902,12 @@ def runPostsWatchdog(projectVersion: str, httpd) -> None:
httpd.thrPostsQueue.start() httpd.thrPostsQueue.start()
while True: while True:
time.sleep(20) time.sleep(20)
if not httpd.thrPostsQueue.is_alive(): if httpd.thrPostsQueue.is_alive():
httpd.thrPostsQueue.kill() continue
httpd.thrPostsQueue = postsQueueOriginal.clone(runPostsQueue) httpd.thrPostsQueue.kill()
httpd.thrPostsQueue.start() httpd.thrPostsQueue = postsQueueOriginal.clone(runPostsQueue)
print('Restarting posts queue...') httpd.thrPostsQueue.start()
print('Restarting posts queue...')
def runSharesExpireWatchdog(projectVersion: str, httpd) -> None: def runSharesExpireWatchdog(projectVersion: str, httpd) -> None:
@ -14909,11 +14918,12 @@ def runSharesExpireWatchdog(projectVersion: str, httpd) -> None:
httpd.thrSharesExpire.start() httpd.thrSharesExpire.start()
while True: while True:
time.sleep(20) time.sleep(20)
if not httpd.thrSharesExpire.is_alive(): if httpd.thrSharesExpire.is_alive():
httpd.thrSharesExpire.kill() continue
httpd.thrSharesExpire = sharesExpireOriginal.clone(runSharesExpire) httpd.thrSharesExpire.kill()
httpd.thrSharesExpire.start() httpd.thrSharesExpire = sharesExpireOriginal.clone(runSharesExpire)
print('Restarting shares expiry...') httpd.thrSharesExpire.start()
print('Restarting shares expiry...')
def loadTokens(baseDir: str, tokensDict: {}, tokensLookup: {}) -> None: def loadTokens(baseDir: str, tokensDict: {}, tokensLookup: {}) -> None:

View File

@ -550,13 +550,13 @@ parser.add_argument('--location', dest='location', type=str, default=None,
parser.add_argument('--duration', dest='duration', type=str, default=None, parser.add_argument('--duration', dest='duration', type=str, default=None,
help='Duration for which to share an item') help='Duration for which to share an item')
parser.add_argument('--registration', dest='registration', type=str, parser.add_argument('--registration', dest='registration', type=str,
default=None, default='open',
help='Whether new registrations are open or closed') help='Whether new registrations are open or closed')
parser.add_argument("--nosharedinbox", type=str2bool, nargs='?', parser.add_argument("--nosharedinbox", type=str2bool, nargs='?',
const=True, default=False, const=True, default=False,
help='Disable shared inbox') help='Disable shared inbox')
parser.add_argument('--maxregistrations', dest='maxRegistrations', parser.add_argument('--maxregistrations', dest='maxRegistrations',
type=int, default=None, type=int, default=10,
help='The maximum number of new registrations') help='The maximum number of new registrations')
parser.add_argument("--resetregistrations", type=str2bool, nargs='?', parser.add_argument("--resetregistrations", type=str2bool, nargs='?',
const=True, default=False, const=True, default=False,

View File

@ -12,54 +12,6 @@ from utils import noOfAccounts
from utils import noOfActiveAccountsMonthly 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: def _getStatusCount(baseDir: str) -> int:
"""Get the total number of posts """Get the total number of posts
""" """
@ -79,7 +31,58 @@ def _getStatusCount(baseDir: str) -> int:
return statusCtr 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, instanceDescriptionShort: str,
instanceDescription: str, instanceDescription: str,
httpPrefix: str, baseDir: str, httpPrefix: str, baseDir: str,
@ -106,6 +109,13 @@ def metaDataInstance(instanceTitle: str,
httpPrefix + '://' + domainFull + '/@' + \ httpPrefix + '://' + domainFull + '/@' + \
adminActor['preferredUsername'] adminActor['preferredUsername']
if showAccounts:
activeAccounts = noOfAccounts(baseDir)
localPosts = _getStatusCount(baseDir)
else:
activeAccounts = 1
localPosts = 1
instance = { instance = {
'approval_required': False, 'approval_required': False,
'contact_account': { 'contact_account': {
@ -126,9 +136,9 @@ def metaDataInstance(instanceTitle: str,
'registrations': registration, 'registrations': registration,
'short_description': instanceDescriptionShort, 'short_description': instanceDescriptionShort,
'stats': { 'stats': {
'domain_count': 2, 'domain_count': 1,
'status_count': _getStatusCount(baseDir), 'status_count': localPosts,
'user_count': noOfAccounts(baseDir) 'user_count': activeAccounts
}, },
'thumbnail': httpPrefix + '://' + domainFull + '/login.png', 'thumbnail': httpPrefix + '://' + domainFull + '/login.png',
'title': instanceTitle, 'title': instanceTitle,

View File

@ -750,9 +750,10 @@ def runNewswireWatchdog(projectVersion: str, httpd) -> None:
httpd.thrNewswireDaemon.start() httpd.thrNewswireDaemon.start()
while True: while True:
time.sleep(50) time.sleep(50)
if not httpd.thrNewswireDaemon.is_alive(): if httpd.thrNewswireDaemon.is_alive():
httpd.thrNewswireDaemon.kill() continue
httpd.thrNewswireDaemon = \ httpd.thrNewswireDaemon.kill()
newswireOriginal.clone(runNewswireDaemon) httpd.thrNewswireDaemon = \
httpd.thrNewswireDaemon.start() newswireOriginal.clone(runNewswireDaemon)
print('Restarting newswire daemon...') httpd.thrNewswireDaemon.start()
print('Restarting newswire daemon...')

View File

@ -155,7 +155,7 @@ def runPostSchedule(baseDir: str, httpd, maxScheduledPosts: int):
if not os.path.isfile(scheduleIndexFilename): if not os.path.isfile(scheduleIndexFilename):
continue continue
_updatePostSchedule(baseDir, account, httpd, maxScheduledPosts) _updatePostSchedule(baseDir, account, httpd, maxScheduledPosts)
break break
def runPostScheduleWatchdog(projectVersion: str, httpd) -> None: def runPostScheduleWatchdog(projectVersion: str, httpd) -> None:
@ -167,12 +167,13 @@ def runPostScheduleWatchdog(projectVersion: str, httpd) -> None:
httpd.thrPostSchedule.start() httpd.thrPostSchedule.start()
while True: while True:
time.sleep(20) time.sleep(20)
if not httpd.thrPostSchedule.is_alive(): if httpd.thrPostSchedule.is_alive():
httpd.thrPostSchedule.kill() continue
httpd.thrPostSchedule = \ httpd.thrPostSchedule.kill()
postScheduleOriginal.clone(runPostSchedule) httpd.thrPostSchedule = \
httpd.thrPostSchedule.start() postScheduleOriginal.clone(runPostSchedule)
print('Restarting scheduled posts...') httpd.thrPostSchedule.start()
print('Restarting scheduled posts...')
def removeScheduledPosts(baseDir: str, nickname: str, domain: str) -> None: def removeScheduledPosts(baseDir: str, nickname: str, domain: str) -> None: