forked from indymedia/epicyon
Test for permitted posts
parent
27099e6450
commit
8e81d4b7df
29
daemon.py
29
daemon.py
|
@ -77,6 +77,20 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def _permittedMessage(self,message):
|
||||||
|
""" check that we are posting to a permitted domain
|
||||||
|
"""
|
||||||
|
testParam='actor'
|
||||||
|
if not message.get(testParam):
|
||||||
|
return False
|
||||||
|
actor=message[testParam]
|
||||||
|
permittedDomain=False
|
||||||
|
for domain in allowedDomains:
|
||||||
|
if domain in actor:
|
||||||
|
permittedDomain=True
|
||||||
|
break
|
||||||
|
return permittedDomain
|
||||||
|
|
||||||
def do_GET(self):
|
def do_GET(self):
|
||||||
if not self.permittedDir(self.path):
|
if not self.permittedDir(self.path):
|
||||||
self._404()
|
self._404()
|
||||||
|
@ -126,13 +140,16 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
# read the message and convert it into a python dictionary
|
# read the message and convert it into a python dictionary
|
||||||
length = int(self.headers.getheader('content-length'))
|
length = int(self.headers.getheader('content-length'))
|
||||||
message = json.loads(self.rfile.read(length))
|
message = json.loads(self.rfile.read(length))
|
||||||
|
|
||||||
|
if not self._permittedMessage(message):
|
||||||
|
self._404()
|
||||||
|
else:
|
||||||
|
# add a property to the object, just to mess with data
|
||||||
|
message['received'] = 'ok'
|
||||||
|
|
||||||
# add a property to the object, just to mess with data
|
# send the message back
|
||||||
message['received'] = 'ok'
|
self._set_headers('application/json')
|
||||||
|
self.wfile.write(json.dumps(message).encode('utf-8'))
|
||||||
# send the message back
|
|
||||||
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,allowedDomains,useTor=False) -> None:
|
||||||
global thisDomain
|
global thisDomain
|
||||||
|
|
Loading…
Reference in New Issue