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 pprint import pprint
|
||||||
from session import createSession
|
from session import createSession
|
||||||
from webfinger import webfingerMeta
|
from webfinger import webfingerMeta
|
||||||
|
from webfinger import webfingerNodeInfo
|
||||||
from webfinger import webfingerLookup
|
from webfinger import webfingerLookup
|
||||||
from webfinger import webfingerHandle
|
from webfinger import webfingerHandle
|
||||||
|
from metadata import metaDataNodeInfo
|
||||||
from donate import getDonationUrl
|
from donate import getDonationUrl
|
||||||
from donate import setDonationUrl
|
from donate import setDonationUrl
|
||||||
from person import activateAccount
|
from person import activateAccount
|
||||||
|
@ -326,6 +328,18 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self._write(msg)
|
self._write(msg)
|
||||||
return True
|
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:
|
def _webfinger(self) -> bool:
|
||||||
if not self.path.startswith('/.well-known'):
|
if not self.path.startswith('/.well-known'):
|
||||||
return False
|
return False
|
||||||
|
@ -340,7 +354,14 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
msg=wfResult.encode('utf-8')
|
msg=wfResult.encode('utf-8')
|
||||||
self._set_headers('application/xrd+xml',len(msg),None)
|
self._set_headers('application/xrd+xml',len(msg),None)
|
||||||
self._write(msg)
|
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:
|
if self.server.debug:
|
||||||
print('DEBUG: WEBFINGER lookup '+self.path+' '+str(self.server.baseDir))
|
print('DEBUG: WEBFINGER lookup '+self.path+' '+str(self.server.baseDir))
|
||||||
|
@ -1145,6 +1166,10 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
if self._webfinger():
|
if self._webfinger():
|
||||||
self.server.GETbusy=False
|
self.server.GETbusy=False
|
||||||
return
|
return
|
||||||
|
# get nodeinfo endpoint
|
||||||
|
if self._nodeinfo():
|
||||||
|
self.server.GETbusy=False
|
||||||
|
return
|
||||||
|
|
||||||
if self.path.startswith('/login') or \
|
if self.path.startswith('/login') or \
|
||||||
(self.path=='/' and not authorized):
|
(self.path=='/' and not authorized):
|
||||||
|
@ -4403,7 +4428,8 @@ def loadTokens(baseDir: str,tokensDict: {},tokensLookup: {}) -> None:
|
||||||
tokensDict[nickname]=token
|
tokensDict[nickname]=token
|
||||||
tokensLookup[token]=nickname
|
tokensLookup[token]=nickname
|
||||||
|
|
||||||
def runDaemon(language: str,projectVersion: str, \
|
def runDaemon(registration: bool, \
|
||||||
|
language: str,projectVersion: str, \
|
||||||
instanceId: str,clientToServer: bool, \
|
instanceId: str,clientToServer: bool, \
|
||||||
baseDir: str,domain: str, \
|
baseDir: str,domain: str, \
|
||||||
port=80,proxyPort=80,httpPrefix='https', \
|
port=80,proxyPort=80,httpPrefix='https', \
|
||||||
|
@ -4453,6 +4479,7 @@ def runDaemon(language: str,projectVersion: str, \
|
||||||
print('System language: '+systemLanguage)
|
print('System language: '+systemLanguage)
|
||||||
httpd.translate=loadJson(translationsFile)
|
httpd.translate=loadJson(translationsFile)
|
||||||
|
|
||||||
|
httpd.registration=registration
|
||||||
httpd.outboxThread={}
|
httpd.outboxThread={}
|
||||||
httpd.newPostThread={}
|
httpd.newPostThread={}
|
||||||
httpd.projectVersion=projectVersion
|
httpd.projectVersion=projectVersion
|
||||||
|
|
|
@ -1455,7 +1455,11 @@ if args.testdata:
|
||||||
if args.maxMentions<4:
|
if args.maxMentions<4:
|
||||||
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, \
|
instanceId,args.client,baseDir, \
|
||||||
domain,port,proxyPort,httpPrefix, \
|
domain,port,proxyPort,httpPrefix, \
|
||||||
federationList,args.maxMentions, \
|
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
|
testServerAliceRunning = True
|
||||||
maxMentions=10
|
maxMentions=10
|
||||||
print('Server running: Alice')
|
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, \
|
httpPrefix,federationList,maxMentions,False, \
|
||||||
noreply,nolike,nopics,noannounce,cw,ocapAlways, \
|
noreply,nolike,nopics,noannounce,cw,ocapAlways, \
|
||||||
useTor,maxReplies, \
|
useTor,maxReplies, \
|
||||||
|
@ -283,7 +283,7 @@ def createServerBob(path: str,domain: str,port: int,federationList: [], \
|
||||||
testServerBobRunning = True
|
testServerBobRunning = True
|
||||||
maxMentions=10
|
maxMentions=10
|
||||||
print('Server running: Bob')
|
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, \
|
httpPrefix,federationList,maxMentions,False, \
|
||||||
noreply,nolike,nopics,noannounce,cw,ocapAlways, \
|
noreply,nolike,nopics,noannounce,cw,ocapAlways, \
|
||||||
useTor,maxReplies, \
|
useTor,maxReplies, \
|
||||||
|
@ -317,7 +317,7 @@ def createServerEve(path: str,domain: str,port: int,federationList: [], \
|
||||||
testServerEveRunning = True
|
testServerEveRunning = True
|
||||||
maxMentions=10
|
maxMentions=10
|
||||||
print('Server running: Eve')
|
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, \
|
httpPrefix,federationList,maxMentions,False, \
|
||||||
noreply,nolike,nopics,noannounce,cw,ocapAlways, \
|
noreply,nolike,nopics,noannounce,cw,ocapAlways, \
|
||||||
useTor,maxReplies,allowDeletion,True,True,False,sendThreads)
|
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
|
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:
|
def webfingerMeta(httpPrefix: str,domainFull: str) -> str:
|
||||||
"""Return /.well-known/host-meta
|
"""Return /.well-known/host-meta
|
||||||
"""
|
"""
|
||||||
#return \
|
metaStr="<?xml version=’1.0' encoding=’UTF-8'?>"
|
||||||
# "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" \
|
metaStr+="<XRD xmlns=’http://docs.oasis-open.org/ns/xri/xrd-1.0'"
|
||||||
# "<XRD xmlns=\"http://docs.oasis-open.org/ns/xri/xrd-1.0\">" \
|
metaStr+=" xmlns:hm=’http://host-meta.net/xrd/1.0'>"
|
||||||
# "<Link rel=\"lrdd\" type=\"application/xrd+xml\" template=\""+httpPrefix+"://"+domainFull+"/.well-known/webfinger?resource={uri}\"/>" \
|
metaStr+=""
|
||||||
# "</XRD>"
|
metaStr+="<hm:Host>"+domainFull+"</hm:Host>"
|
||||||
|
metaStr+=""
|
||||||
return \
|
metaStr+="<Link rel=’lrdd’"
|
||||||
"<?xml version=’1.0' encoding=’UTF-8'?>" \
|
metaStr+=" template=’"+httpPrefix+"://"+domainFull+"/describe?uri={uri}'>"
|
||||||
"<XRD xmlns=’http://docs.oasis-open.org/ns/xri/xrd-1.0'" \
|
metaStr+=" <Title>Resource Descriptor</Title>"
|
||||||
" xmlns:hm=’http://host-meta.net/xrd/1.0'>" \
|
metaStr+=" </Link>"
|
||||||
"" \
|
metaStr+="</XRD>"
|
||||||
"<hm:Host>"+domainFull+"</hm:Host>" \
|
return metaStr
|
||||||
"" \
|
|
||||||
"<Link rel=’lrdd’" \
|
|
||||||
" template=’"+httpPrefix+"://"+domainFull+"/describe?uri={uri}'>" \
|
|
||||||
" <Title>Resource Descriptor</Title>" \
|
|
||||||
" </Link>" \
|
|
||||||
"</XRD>"
|
|
||||||
|
|
||||||
def webfingerLookup(path: str,baseDir: str,port: int,debug: bool) -> {}:
|
def webfingerLookup(path: str,baseDir: str,port: int,debug: bool) -> {}:
|
||||||
"""Lookup the webfinger endpoint for an account
|
"""Lookup the webfinger endpoint for an account
|
||||||
|
|
Loading…
Reference in New Issue