forked from indymedia/epicyon
Consistent terminology
parent
b4a2fe24da
commit
1571d350e3
|
@ -154,11 +154,11 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self._set_headers('application/json')
|
||||
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 federationList
|
||||
thisDomain=domain
|
||||
federationList=allowedDomains
|
||||
federationList=fedList.copy()
|
||||
|
||||
if len(domain)==0:
|
||||
domain='127.0.0.1'
|
||||
|
|
|
@ -20,7 +20,7 @@ from httpsig import testHttpsig
|
|||
from daemon import runDaemon
|
||||
import socket
|
||||
|
||||
allowedDomains=['mastodon.social']
|
||||
federationList=['mastodon.social']
|
||||
username='testuser'
|
||||
#domain=socket.gethostname()
|
||||
domain='mydomain.com'
|
||||
|
@ -32,7 +32,7 @@ session = createSession(useTor)
|
|||
privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson(username,domain,https,True)
|
||||
setPreferredUsername(username,domain,'badger')
|
||||
setBio(username,domain,'Some personal info')
|
||||
runDaemon(domain,port,allowedDomains,useTor)
|
||||
runDaemon(domain,port,federationList,useTor)
|
||||
|
||||
#testHttpsig()
|
||||
#sys.exit()
|
||||
|
@ -52,5 +52,5 @@ if not wfRequest:
|
|||
maxMentions=10
|
||||
maxEmoji=10
|
||||
maxAttachments=5
|
||||
userPosts = getUserPosts(session,wfRequest,2,maxMentions,maxEmoji,maxAttachments,allowedDomains)
|
||||
userPosts = getUserPosts(session,wfRequest,2,maxMentions,maxEmoji,maxAttachments,federationList)
|
||||
print(str(userPosts))
|
||||
|
|
14
posts.py
14
posts.py
|
@ -16,10 +16,10 @@ try:
|
|||
except ImportError:
|
||||
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?
|
||||
"""
|
||||
for domain in allowedDomains:
|
||||
for domain in federationList:
|
||||
if domain in url:
|
||||
return True
|
||||
return False
|
||||
|
@ -53,7 +53,7 @@ def parseUserFeed(session,feedUrl,asHeader) -> None:
|
|||
for item in parseUserFeed(session,nextUrl,asHeader):
|
||||
yield item
|
||||
|
||||
def getUserPosts(session,wfRequest,maxPosts,maxMentions,maxEmoji,maxAttachments,allowedDomains) -> {}:
|
||||
def getUserPosts(session,wfRequest,maxPosts,maxMentions,maxEmoji,maxAttachments,federationList) -> {}:
|
||||
userPosts={}
|
||||
asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'}
|
||||
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['icon'].get('url'):
|
||||
# No emoji from non-permitted domains
|
||||
if permitted(tagItem['icon']['url'],allowedDomains):
|
||||
if permitted(tagItem['icon']['url'],federationList):
|
||||
emojiName=tagItem['name']
|
||||
emojiIcon=tagItem['icon']['url']
|
||||
emoji[emojiName]=emojiIcon
|
||||
|
@ -107,7 +107,7 @@ def getUserPosts(session,wfRequest,maxPosts,maxMentions,maxEmoji,maxAttachments,
|
|||
if item['object'].get('inReplyTo'):
|
||||
if item['object']['inReplyTo']:
|
||||
# No replies to non-permitted domains
|
||||
if not permitted(item['object']['inReplyTo'],allowedDomains):
|
||||
if not permitted(item['object']['inReplyTo'],federationList):
|
||||
continue
|
||||
inReplyTo = item['object']['inReplyTo']
|
||||
|
||||
|
@ -115,7 +115,7 @@ def getUserPosts(session,wfRequest,maxPosts,maxMentions,maxEmoji,maxAttachments,
|
|||
if item['object'].get('conversation'):
|
||||
if item['object']['conversation']:
|
||||
# no conversations originated in non-permitted domains
|
||||
if permitted(item['object']['conversation'],allowedDomains):
|
||||
if permitted(item['object']['conversation'],federationList):
|
||||
conversation = item['object']['conversation']
|
||||
|
||||
attachment = []
|
||||
|
@ -124,7 +124,7 @@ def getUserPosts(session,wfRequest,maxPosts,maxMentions,maxEmoji,maxAttachments,
|
|||
for attach in item['object']['attachment']:
|
||||
if attach.get('name') and attach.get('url'):
|
||||
# no attachments from non-permitted domains
|
||||
if permitted(attach['url'],allowedDomains):
|
||||
if permitted(attach['url'],federationList):
|
||||
attachment.append([attach['name'],attach['url']])
|
||||
|
||||
sensitive = False
|
||||
|
|
|
@ -28,12 +28,12 @@ def getJson(session,url: str,headers,params):
|
|||
session.cookies.clear()
|
||||
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
|
||||
"""
|
||||
# check that we are posting to a permitted domain
|
||||
permittedDomain=False
|
||||
for domain in allowedDomains:
|
||||
for domain in federationList:
|
||||
if domain in inboxUrl:
|
||||
permittedDomain=True
|
||||
break
|
||||
|
|
Loading…
Reference in New Issue