-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
33 lines (26 loc) · 967 Bytes
/
server.py
File metadata and controls
33 lines (26 loc) · 967 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import SimpleHTTPServer
import SocketServer
import sys
import cgi
PORT = int(sys.argv[1])
class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_POST(self):
content_len = int(self.headers.getheader('content-length', 0))
post_body = self.rfile.read(content_len)
print post_body
print(type(post_body))
splitted = post_body.split("&")
splitted = [i for i in splitted if i]
persons = splitted[0].split("=")[1]
overturned = splitted[1].split("=")[1]
airbags = splitted[2].split("=")[1]
all_seatbelts = splitted[3].split("=")[1]
print persons, overturned, airbags, all_seatbelts
with open("/tmp/accident_flag", "w") as outF:
for line in splitted:
outF.write(line.split("=")[1])
outF.write("\n")
Handler = ServerHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
print "serving at port", PORT
httpd.serve_forever()