mirror of https://gitlab.com/bashrc2/epicyon
nodeinfo metadata endpoint
parent
da4123b1ec
commit
c14ab97586
31
daemon.py
31
daemon.py
|
@ -21,8 +21,10 @@ from hashlib import sha256
|
|||
from pprint import pprint
|
||||
from session import createSession
|
||||
from webfinger import webfingerMeta
|
||||
from webfinger import webfingerNodeInfo
|
||||
from webfinger import webfingerLookup
|
||||
from webfinger import webfingerHandle
|
||||
from metadata import metaDataNodeInfo
|
||||
from donate import getDonationUrl
|
||||
from donate import setDonationUrl
|
||||
from person import activateAccount
|
||||
|
@ -326,6 +328,18 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self._write(msg)
|
||||
return True
|
||||
|
||||
def _nodeinfo(self) -> bool:
|
||||
if not self.path.startswith('/nodeinfo/2.0'):
|
||||
return False
|
||||
if self.server.debug:
|
||||
print('DEBUG: WEBFINGER nodeinfo')
|
||||
info=metaDataNodeInfo(self.server.registration,self.server.projectVersion)
|
||||
if info:
|
||||
msg=wfResult.encode('utf-8')
|
||||
self._set_headers('application/json',len(msg),None)
|
||||
self._write(msg)
|
||||
return True
|
||||
|
||||
def _webfinger(self) -> bool:
|
||||
if not self.path.startswith('/.well-known'):
|
||||
return False
|
||||
|
@ -340,7 +354,14 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
msg=wfResult.encode('utf-8')
|
||||
self._set_headers('application/xrd+xml',len(msg),None)
|
||||
self._write(msg)
|
||||
return
|
||||
return True
|
||||
if self.path.startswith('/.well-known/nodeinfo'):
|
||||
wfResult=webfingerNodeInfo(self.server.httpPrefix,self.server.domainFull)
|
||||
if wfResult:
|
||||
msg=wfResult.encode('utf-8')
|
||||
self._set_headers('application/json',len(msg),None)
|
||||
self._write(msg)
|
||||
return True
|
||||
|
||||
if self.server.debug:
|
||||
print('DEBUG: WEBFINGER lookup '+self.path+' '+str(self.server.baseDir))
|
||||
|
@ -1145,6 +1166,10 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
if self._webfinger():
|
||||
self.server.GETbusy=False
|
||||
return
|
||||
# get nodeinfo endpoint
|
||||
if self._nodeinfo():
|
||||
self.server.GETbusy=False
|
||||
return
|
||||
|
||||
if self.path.startswith('/login') or \
|
||||
(self.path=='/' and not authorized):
|
||||
|
@ -4403,7 +4428,8 @@ def loadTokens(baseDir: str,tokensDict: {},tokensLookup: {}) -> None:
|
|||
tokensDict[nickname]=token
|
||||
tokensLookup[token]=nickname
|
||||
|
||||
def runDaemon(language: str,projectVersion: str, \
|
||||
def runDaemon(registration: bool, \
|
||||
language: str,projectVersion: str, \
|
||||
instanceId: str,clientToServer: bool, \
|
||||
baseDir: str,domain: str, \
|
||||
port=80,proxyPort=80,httpPrefix='https', \
|
||||
|
@ -4453,6 +4479,7 @@ def runDaemon(language: str,projectVersion: str, \
|
|||
print('System language: '+systemLanguage)
|
||||
httpd.translate=loadJson(translationsFile)
|
||||
|
||||
httpd.registration=registration
|
||||
httpd.outboxThread={}
|
||||
httpd.newPostThread={}
|
||||
httpd.projectVersion=projectVersion
|
||||
|
|
|
@ -1455,7 +1455,11 @@ if args.testdata:
|
|||
if args.maxMentions<4:
|
||||
args.maxMentions=4
|
||||
|
||||
runDaemon(args.language,__version__, \
|
||||
registration=getConfigParam(baseDir,'registration')
|
||||
if not registration:
|
||||
registration=False
|
||||
|
||||
runDaemon(registration,args.language,__version__, \
|
||||
instanceId,args.client,baseDir, \
|
||||
domain,port,proxyPort,httpPrefix, \
|
||||
federationList,args.maxMentions, \
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
__filename__ = "metadata.py"
|
||||
__author__ = "Bob Mottram"
|
||||
__license__ = "AGPL3+"
|
||||
__version__ = "1.0.0"
|
||||
__maintainer__ = "Bob Mottram"
|
||||
__email__ = "bob@freedombone.net"
|
||||
__status__ = "Production"
|
||||
|
||||
import json
|
||||
|
||||
def metaDataNodeInfo(registration: bool,version: str) -> {}:
|
||||
""" /nodeinfo/2.0 endpoint
|
||||
"""
|
||||
nodeinfo = {
|
||||
'openRegistrations': registration,
|
||||
'protocols': ['activitypub'],
|
||||
'software': {
|
||||
'name': 'epicyon',
|
||||
'version': version
|
||||
},
|
||||
'usage': {
|
||||
'localPosts': 1,
|
||||
'users': {
|
||||
'activeHalfyear': 1,
|
||||
'activeMonth': 1,
|
||||
'total': 1
|
||||
}
|
||||
},
|
||||
'version': '2.0'
|
||||
}
|
||||
return nodeinfo
|
6
tests.py
6
tests.py
|
@ -229,7 +229,7 @@ def createServerAlice(path: str,domain: str,port: int,federationList: [], \
|
|||
testServerAliceRunning = True
|
||||
maxMentions=10
|
||||
print('Server running: Alice')
|
||||
runDaemon('en',__version__,"instanceId",False,path,domain,port,port, \
|
||||
runDaemon(True,'en',__version__,"instanceId",False,path,domain,port,port, \
|
||||
httpPrefix,federationList,maxMentions,False, \
|
||||
noreply,nolike,nopics,noannounce,cw,ocapAlways, \
|
||||
useTor,maxReplies, \
|
||||
|
@ -283,7 +283,7 @@ def createServerBob(path: str,domain: str,port: int,federationList: [], \
|
|||
testServerBobRunning = True
|
||||
maxMentions=10
|
||||
print('Server running: Bob')
|
||||
runDaemon('en',__version__,"instanceId",False,path,domain,port,port, \
|
||||
runDaemon(True,'en',__version__,"instanceId",False,path,domain,port,port, \
|
||||
httpPrefix,federationList,maxMentions,False, \
|
||||
noreply,nolike,nopics,noannounce,cw,ocapAlways, \
|
||||
useTor,maxReplies, \
|
||||
|
@ -317,7 +317,7 @@ def createServerEve(path: str,domain: str,port: int,federationList: [], \
|
|||
testServerEveRunning = True
|
||||
maxMentions=10
|
||||
print('Server running: Eve')
|
||||
runDaemon('en',__version__,"instanceId",False,path,domain,port,port, \
|
||||
runDaemon(True,'en',__version__,"instanceId",False,path,domain,port,port, \
|
||||
httpPrefix,federationList,maxMentions,False, \
|
||||
noreply,nolike,nopics,noannounce,cw,ocapAlways, \
|
||||
useTor,maxReplies,allowDeletion,True,True,False,sendThreads)
|
||||
|
|
43
webfinger.py
43
webfinger.py
|
@ -151,27 +151,34 @@ def createWebfingerEndpoint(nickname: str,domain: str,port: int, \
|
|||
}
|
||||
return account
|
||||
|
||||
def webfingerNodeInfo(httpPrefix: str,domainFull: str) -> {}:
|
||||
""" /.well-known/nodeinfo endpoint
|
||||
"""
|
||||
nodeinfo = {
|
||||
'links': [
|
||||
{
|
||||
'href': httpPrefix+'://'+domainFull+'/nodeinfo/2.0',
|
||||
'rel': 'http://nodeinfo.diaspora.software/ns/schema/2.0'
|
||||
}
|
||||
]
|
||||
}
|
||||
return nodeinfo
|
||||
|
||||
def webfingerMeta(httpPrefix: str,domainFull: str) -> str:
|
||||
"""Return /.well-known/host-meta
|
||||
"""
|
||||
#return \
|
||||
# "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" \
|
||||
# "<XRD xmlns=\"http://docs.oasis-open.org/ns/xri/xrd-1.0\">" \
|
||||
# "<Link rel=\"lrdd\" type=\"application/xrd+xml\" template=\""+httpPrefix+"://"+domainFull+"/.well-known/webfinger?resource={uri}\"/>" \
|
||||
# "</XRD>"
|
||||
|
||||
return \
|
||||
"<?xml version=’1.0' encoding=’UTF-8'?>" \
|
||||
"<XRD xmlns=’http://docs.oasis-open.org/ns/xri/xrd-1.0'" \
|
||||
" xmlns:hm=’http://host-meta.net/xrd/1.0'>" \
|
||||
"" \
|
||||
"<hm:Host>"+domainFull+"</hm:Host>" \
|
||||
"" \
|
||||
"<Link rel=’lrdd’" \
|
||||
" template=’"+httpPrefix+"://"+domainFull+"/describe?uri={uri}'>" \
|
||||
" <Title>Resource Descriptor</Title>" \
|
||||
" </Link>" \
|
||||
"</XRD>"
|
||||
metaStr="<?xml version=’1.0' encoding=’UTF-8'?>"
|
||||
metaStr+="<XRD xmlns=’http://docs.oasis-open.org/ns/xri/xrd-1.0'"
|
||||
metaStr+=" xmlns:hm=’http://host-meta.net/xrd/1.0'>"
|
||||
metaStr+=""
|
||||
metaStr+="<hm:Host>"+domainFull+"</hm:Host>"
|
||||
metaStr+=""
|
||||
metaStr+="<Link rel=’lrdd’"
|
||||
metaStr+=" template=’"+httpPrefix+"://"+domainFull+"/describe?uri={uri}'>"
|
||||
metaStr+=" <Title>Resource Descriptor</Title>"
|
||||
metaStr+=" </Link>"
|
||||
metaStr+="</XRD>"
|
||||
return metaStr
|
||||
|
||||
def webfingerLookup(path: str,baseDir: str,port: int,debug: bool) -> {}:
|
||||
"""Lookup the webfinger endpoint for an account
|
||||
|
|
Loading…
Reference in New Issue