forked from indymedia/epicyon
				
			Debugging POST
							parent
							
								
									d160c060c9
								
							
						
					
					
						commit
						79baa0ddf6
					
				
							
								
								
									
										37
									
								
								daemon.py
								
								
								
								
							
							
						
						
									
										37
									
								
								daemon.py
								
								
								
								
							|  | @ -155,6 +155,7 @@ class PubServer(BaseHTTPRequestHandler): | ||||||
|         self._set_headers('application/json') |         self._set_headers('application/json') | ||||||
|          |          | ||||||
|     def do_POST(self): |     def do_POST(self): | ||||||
|  |         print('**************** POST recieved!') | ||||||
|         try: |         try: | ||||||
|             if self.POSTbusy: |             if self.POSTbusy: | ||||||
|                 self.send_response(429) |                 self.send_response(429) | ||||||
|  | @ -162,35 +163,53 @@ class PubServer(BaseHTTPRequestHandler): | ||||||
|                 return                 |                 return                 | ||||||
|         except: |         except: | ||||||
|             pass |             pass | ||||||
|  |         print('**************** POST ready to receive') | ||||||
|         self.POSTbusy=True |         self.POSTbusy=True | ||||||
|         ctype, pdict = cgi.parse_header(self.headers.getheader('content-type')) |         if not self.headers.get('Content-type'): | ||||||
|  |             print('**************** No Content-type') | ||||||
|  |             self.send_response(400) | ||||||
|  |             self.end_headers() | ||||||
|  |             self.POSTbusy=False | ||||||
|  |             return | ||||||
|  |         print('*****************headers: '+str(self.headers)) | ||||||
|          |          | ||||||
|         # refuse to receive non-json content |         # refuse to receive non-json content | ||||||
|         if ctype != 'application/json': |         if self.headers['Content-type'] != 'application/json': | ||||||
|  |             print("**************** That's no Json!") | ||||||
|             self.send_response(400) |             self.send_response(400) | ||||||
|             self.end_headers() |             self.end_headers() | ||||||
|             self.POSTbusy=False |             self.POSTbusy=False | ||||||
|             return |             return | ||||||
|              |              | ||||||
|         # 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['Content-length']) | ||||||
|  |         print('**************** content-length: '+str(length)) | ||||||
|         if length>maxMessageLength: |         if length>maxMessageLength: | ||||||
|             self.send_response(400) |             self.send_response(400) | ||||||
|             self.end_headers() |             self.end_headers() | ||||||
|             self.POSTbusy=False |             self.POSTbusy=False | ||||||
|             return |             return | ||||||
|         message = json.loads(self.rfile.read(length))         |         print('**************** Reading message') | ||||||
|  |         messageBytes=self.rfile.read(length) | ||||||
|  |         messageJson = json.loads(messageBytes) | ||||||
| 
 | 
 | ||||||
|         if not inboxPermittedMessage(message,self.server.federationList): |         if not inboxPermittedMessage(self.server.domain,messageJson,self.server.federationList): | ||||||
|  |             print('**************** Ah Ah Ah') | ||||||
|             self.send_response(403) |             self.send_response(403) | ||||||
|             self.end_headers() |             self.end_headers() | ||||||
|         else:                 |             self.POSTbusy=False | ||||||
|  |             return | ||||||
|  |          | ||||||
|  |         print('**************** POST valid') | ||||||
|  |         pprint(messageJson) | ||||||
|         # add a property to the object, just to mess with data |         # add a property to the object, just to mess with data | ||||||
|             message['received'] = 'ok' |         #message['received'] = 'ok' | ||||||
|          |          | ||||||
|         # send the message back |         # send the message back | ||||||
|             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')) | ||||||
|  |         self.send_response(200) | ||||||
|  |         self.end_headers() | ||||||
|         self.POSTbusy=False |         self.POSTbusy=False | ||||||
| 
 | 
 | ||||||
| def runDaemon(domain: str,port=80,https=True,fedList=[],useTor=False) -> None: | def runDaemon(domain: str,port=80,https=True,fedList=[],useTor=False) -> None: | ||||||
|  |  | ||||||
							
								
								
									
										4
									
								
								inbox.py
								
								
								
								
							
							
						
						
									
										4
									
								
								inbox.py
								
								
								
								
							|  | @ -10,7 +10,7 @@ import json | ||||||
| import os | import os | ||||||
| import datetime | import datetime | ||||||
| 
 | 
 | ||||||
| def inboxPermittedMessage(messageJson: {},federationList: []) -> bool: | def inboxPermittedMessage(domain: str,messageJson: {},federationList: []) -> bool: | ||||||
|     """ check that we are receiving from a permitted domain |     """ check that we are receiving from a permitted domain | ||||||
|     """ |     """ | ||||||
|     testParam='actor' |     testParam='actor' | ||||||
|  | @ -18,7 +18,7 @@ def inboxPermittedMessage(messageJson: {},federationList: []) -> bool: | ||||||
|         return False |         return False | ||||||
|     actor=messageJson[testParam] |     actor=messageJson[testParam] | ||||||
|     # always allow the local domain |     # always allow the local domain | ||||||
|     if thisDomain in actor: |     if domain in actor: | ||||||
|         return True |         return True | ||||||
| 
 | 
 | ||||||
|     permittedDomain=False |     permittedDomain=False | ||||||
|  |  | ||||||
							
								
								
									
										1
									
								
								posts.py
								
								
								
								
							
							
						
						
									
										1
									
								
								posts.py
								
								
								
								
							|  | @ -16,6 +16,7 @@ import shutil | ||||||
| import threading | import threading | ||||||
| import sys | import sys | ||||||
| import trace | import trace | ||||||
|  | import time | ||||||
| from threads import threadWithTrace | from threads import threadWithTrace | ||||||
| from cache import storePersonInCache | from cache import storePersonInCache | ||||||
| from cache import getPersonFromCache | from cache import getPersonFromCache | ||||||
|  |  | ||||||
							
								
								
									
										2
									
								
								tests.py
								
								
								
								
							
							
						
						
									
										2
									
								
								tests.py
								
								
								
								
							|  | @ -176,7 +176,7 @@ def testPostMessageBetweenServers(): | ||||||
|     while not (testServerAliceRunning and testServerBobRunning): |     while not (testServerAliceRunning and testServerBobRunning): | ||||||
|         time.sleep(1) |         time.sleep(1) | ||||||
|          |          | ||||||
|     time.sleep(3) |     time.sleep(5) | ||||||
| 
 | 
 | ||||||
|     print('Alice sends to Bob') |     print('Alice sends to Bob') | ||||||
|     os.chdir(aliceDir) |     os.chdir(aliceDir) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue