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,
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,7 +14902,8 @@ def runPostsWatchdog(projectVersion: str, httpd) -> None:
httpd.thrPostsQueue.start()
while True:
time.sleep(20)
if not httpd.thrPostsQueue.is_alive():
if httpd.thrPostsQueue.is_alive():
continue
httpd.thrPostsQueue.kill()
httpd.thrPostsQueue = postsQueueOriginal.clone(runPostsQueue)
httpd.thrPostsQueue.start()
@ -14909,7 +14918,8 @@ def runSharesExpireWatchdog(projectVersion: str, httpd) -> None:
httpd.thrSharesExpire.start()
while True:
time.sleep(20)
if not httpd.thrSharesExpire.is_alive():
if httpd.thrSharesExpire.is_alive():
continue
httpd.thrSharesExpire.kill()
httpd.thrSharesExpire = sharesExpireOriginal.clone(runSharesExpire)
httpd.thrSharesExpire.start()

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,
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,

View File

@ -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,

View File

@ -750,7 +750,8 @@ def runNewswireWatchdog(projectVersion: str, httpd) -> None:
httpd.thrNewswireDaemon.start()
while True:
time.sleep(50)
if not httpd.thrNewswireDaemon.is_alive():
if httpd.thrNewswireDaemon.is_alive():
continue
httpd.thrNewswireDaemon.kill()
httpd.thrNewswireDaemon = \
newswireOriginal.clone(runNewswireDaemon)

View File

@ -167,7 +167,8 @@ def runPostScheduleWatchdog(projectVersion: str, httpd) -> None:
httpd.thrPostSchedule.start()
while True:
time.sleep(20)
if not httpd.thrPostSchedule.is_alive():
if httpd.thrPostSchedule.is_alive():
continue
httpd.thrPostSchedule.kill()
httpd.thrPostSchedule = \
postScheduleOriginal.clone(runPostSchedule)