Consistent terminology

master
Bob Mottram 2019-06-28 21:43:37 +01:00
parent b4a2fe24da
commit 1571d350e3
4 changed files with 14 additions and 14 deletions

View File

@ -154,11 +154,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,allowedDomains,useTor=False) -> None: def runDaemon(domain: str,port=80,fedList,useTor=False) -> None:
global thisDomain global thisDomain
global federationList global federationList
thisDomain=domain thisDomain=domain
federationList=allowedDomains federationList=fedList.copy()
if len(domain)==0: if len(domain)==0:
domain='127.0.0.1' domain='127.0.0.1'

View File

@ -20,7 +20,7 @@ from httpsig import testHttpsig
from daemon import runDaemon from daemon import runDaemon
import socket import socket
allowedDomains=['mastodon.social'] federationList=['mastodon.social']
username='testuser' username='testuser'
#domain=socket.gethostname() #domain=socket.gethostname()
domain='mydomain.com' domain='mydomain.com'
@ -32,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,allowedDomains,useTor) runDaemon(domain,port,federationList,useTor)
#testHttpsig() #testHttpsig()
#sys.exit() #sys.exit()
@ -52,5 +52,5 @@ if not wfRequest:
maxMentions=10 maxMentions=10
maxEmoji=10 maxEmoji=10
maxAttachments=5 maxAttachments=5
userPosts = getUserPosts(session,wfRequest,2,maxMentions,maxEmoji,maxAttachments,allowedDomains) userPosts = getUserPosts(session,wfRequest,2,maxMentions,maxEmoji,maxAttachments,federationList)
print(str(userPosts)) print(str(userPosts))

View File

@ -16,10 +16,10 @@ try:
except ImportError: except ImportError:
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
def permitted(url: str,allowedDomains) -> bool: def permitted(url: str,federationList) -> bool:
"""Is a url from one of the permitted domains? """Is a url from one of the permitted domains?
""" """
for domain in allowedDomains: for domain in federationList:
if domain in url: if domain in url:
return True return True
return False return False
@ -53,7 +53,7 @@ def parseUserFeed(session,feedUrl,asHeader) -> None:
for item in parseUserFeed(session,nextUrl,asHeader): for item in parseUserFeed(session,nextUrl,asHeader):
yield item yield item
def getUserPosts(session,wfRequest,maxPosts,maxMentions,maxEmoji,maxAttachments,allowedDomains) -> {}: def getUserPosts(session,wfRequest,maxPosts,maxMentions,maxEmoji,maxAttachments,federationList) -> {}:
userPosts={} userPosts={}
asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'} asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'}
userUrl = getUserUrl(wfRequest) userUrl = getUserUrl(wfRequest)
@ -85,7 +85,7 @@ def getUserPosts(session,wfRequest,maxPosts,maxMentions,maxEmoji,maxAttachments,
if tagItem.get('name') and tagItem.get('icon'): if tagItem.get('name') and tagItem.get('icon'):
if tagItem['icon'].get('url'): if tagItem['icon'].get('url'):
# No emoji from non-permitted domains # No emoji from non-permitted domains
if permitted(tagItem['icon']['url'],allowedDomains): if permitted(tagItem['icon']['url'],federationList):
emojiName=tagItem['name'] emojiName=tagItem['name']
emojiIcon=tagItem['icon']['url'] emojiIcon=tagItem['icon']['url']
emoji[emojiName]=emojiIcon emoji[emojiName]=emojiIcon
@ -107,7 +107,7 @@ def getUserPosts(session,wfRequest,maxPosts,maxMentions,maxEmoji,maxAttachments,
if item['object'].get('inReplyTo'): if item['object'].get('inReplyTo'):
if item['object']['inReplyTo']: if item['object']['inReplyTo']:
# No replies to non-permitted domains # No replies to non-permitted domains
if not permitted(item['object']['inReplyTo'],allowedDomains): if not permitted(item['object']['inReplyTo'],federationList):
continue continue
inReplyTo = item['object']['inReplyTo'] inReplyTo = item['object']['inReplyTo']
@ -115,7 +115,7 @@ def getUserPosts(session,wfRequest,maxPosts,maxMentions,maxEmoji,maxAttachments,
if item['object'].get('conversation'): if item['object'].get('conversation'):
if item['object']['conversation']: if item['object']['conversation']:
# no conversations originated in non-permitted domains # no conversations originated in non-permitted domains
if permitted(item['object']['conversation'],allowedDomains): if permitted(item['object']['conversation'],federationList):
conversation = item['object']['conversation'] conversation = item['object']['conversation']
attachment = [] attachment = []
@ -124,7 +124,7 @@ def getUserPosts(session,wfRequest,maxPosts,maxMentions,maxEmoji,maxAttachments,
for attach in item['object']['attachment']: for attach in item['object']['attachment']:
if attach.get('name') and attach.get('url'): if attach.get('name') and attach.get('url'):
# no attachments from non-permitted domains # no attachments from non-permitted domains
if permitted(attach['url'],allowedDomains): if permitted(attach['url'],federationList):
attachment.append([attach['name'],attach['url']]) attachment.append([attach['name'],attach['url']])
sensitive = False sensitive = False

View File

@ -28,12 +28,12 @@ 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,allowedDomains,inboxUrl: str): def postJson(session,postJson,federationList,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 # check that we are posting to a permitted domain
permittedDomain=False permittedDomain=False
for domain in allowedDomains: for domain in federationList:
if domain in inboxUrl: if domain in inboxUrl:
permittedDomain=True permittedDomain=True
break break