mirror of https://gitlab.com/bashrc2/epicyon
Posting to permitted domains
parent
831c9ae97a
commit
27099e6450
|
@ -19,8 +19,12 @@ from person import personLookup
|
||||||
from person import personKeyLookup
|
from person import personKeyLookup
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
# domain name of this server
|
||||||
thisDomain=''
|
thisDomain=''
|
||||||
|
|
||||||
|
# List of domains to federate with
|
||||||
|
federationList=[]
|
||||||
|
|
||||||
def readFollowList(filename: str):
|
def readFollowList(filename: str):
|
||||||
"""Returns a list of ActivityPub addresses to follow
|
"""Returns a list of ActivityPub addresses to follow
|
||||||
"""
|
"""
|
||||||
|
@ -130,9 +134,11 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self._set_headers('application/json')
|
self._set_headers('application/json')
|
||||||
self.wfile.write(json.dumps(message).encode('utf-8'))
|
self.wfile.write(json.dumps(message).encode('utf-8'))
|
||||||
|
|
||||||
def runDaemon(domain: str,port=80,useTor=False) -> None:
|
def runDaemon(domain: str,port=80,allowedDomains,useTor=False) -> None:
|
||||||
global thisDomain
|
global thisDomain
|
||||||
|
global federationList
|
||||||
thisDomain=domain
|
thisDomain=domain
|
||||||
|
federationList=allowedDomains
|
||||||
|
|
||||||
if len(domain)==0:
|
if len(domain)==0:
|
||||||
domain='127.0.0.1'
|
domain='127.0.0.1'
|
||||||
|
|
|
@ -20,6 +20,7 @@ from httpsig import testHttpsig
|
||||||
from daemon import runDaemon
|
from daemon import runDaemon
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
|
allowedDomains=['mastodon.social']
|
||||||
username='testuser'
|
username='testuser'
|
||||||
#domain=socket.gethostname()
|
#domain=socket.gethostname()
|
||||||
domain='mydomain.com'
|
domain='mydomain.com'
|
||||||
|
@ -31,7 +32,7 @@ session = createSession(useTor)
|
||||||
privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson(username,domain,https,True)
|
privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson(username,domain,https,True)
|
||||||
setPreferredUsername(username,domain,'badger')
|
setPreferredUsername(username,domain,'badger')
|
||||||
setBio(username,domain,'Some personal info')
|
setBio(username,domain,'Some personal info')
|
||||||
runDaemon(domain,port,useTor)
|
runDaemon(domain,port,allowedDomains,useTor)
|
||||||
|
|
||||||
#testHttpsig()
|
#testHttpsig()
|
||||||
#sys.exit()
|
#sys.exit()
|
||||||
|
@ -40,7 +41,6 @@ runDaemon(domain,port,useTor)
|
||||||
#print('\n')
|
#print('\n')
|
||||||
#pprint(wfEndpoint)
|
#pprint(wfEndpoint)
|
||||||
|
|
||||||
allowedDomains=['mastodon.social']
|
|
||||||
handle="https://mastodon.social/@Gargron"
|
handle="https://mastodon.social/@Gargron"
|
||||||
wfRequest = webfingerHandle(session,handle,True)
|
wfRequest = webfingerHandle(session,handle,True)
|
||||||
if not wfRequest:
|
if not wfRequest:
|
||||||
|
|
11
session.py
11
session.py
|
@ -28,8 +28,17 @@ def getJson(session,url: str,headers,params):
|
||||||
session.cookies.clear()
|
session.cookies.clear()
|
||||||
return session.get(url, headers=sessionHeaders, params=sessionParams).json()
|
return session.get(url, headers=sessionHeaders, params=sessionParams).json()
|
||||||
|
|
||||||
def postJson(session,postJson,inboxUrl: str):
|
def postJson(session,postJson,allowedDomains,inboxUrl: str):
|
||||||
"""Post a json message to the inbox of another person
|
"""Post a json message to the inbox of another person
|
||||||
"""
|
"""
|
||||||
|
# check that we are posting to a permitted domain
|
||||||
|
permittedDomain=False
|
||||||
|
for domain in allowedDomains:
|
||||||
|
if domain in inboxUrl:
|
||||||
|
permittedDomain=True
|
||||||
|
break
|
||||||
|
if not permittedDomain:
|
||||||
|
return None
|
||||||
|
|
||||||
postResult = session.post(url = inboxUrl, data = postJson)
|
postResult = session.post(url = inboxUrl, data = postJson)
|
||||||
return postResult.text
|
return postResult.text
|
||||||
|
|
Loading…
Reference in New Issue