-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebServer
executable file
·48 lines (38 loc) · 1.26 KB
/
webServer
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
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
# For ubuntu install should be #!/usr/bin/env python
# Found this here: http://code.activestate.com/lists/python-list/284803/
import sys
import SocketServer
import BaseHTTPServer
import CGIHTTPServer
import os
sys.path.append(os.getcwd()+'/cgi-bin')
import emailbitcoins
class ThreadingCGIServer(SocketServer.ThreadingMixIn,
BaseHTTPServer.HTTPServer):
pass
class CustomHandlar(CGIHTTPServer.CGIHTTPRequestHandler):
def __init__(self, *args):
CGIHTTPServer.CGIHTTPRequestHandler.__init__(self,*args)
def do_POST(self):
if "emailbitcoins.py" in self.path:
length = int(self.headers.getheader('content-length'))
content = self.rfile.read(length)
resp = emailbitcoins.process(content)
self.send_response(200,'OK')
self.send_header('Content-type', 'text/plain')
self.end_headers()
self.wfile.write(bytes(resp))
return
CGIHTTPServer.CGIHTTPRequestHandler.do_POST(self)
if sys.argv[1:]:
port = int(sys.argv[1])
else:
port = 8099
server = ThreadingCGIServer(('', port), CustomHandlar)
try:
while 1:
sys.stdout.flush()
server.handle_request()
except KeyboardInterrupt:
print "Finished"