forked from rictic/reconciliation_ui
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.py
45 lines (39 loc) · 1.29 KB
/
server.py
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
import web
from os import path
import simplejson
import sys
rootdir = path.abspath('./build')
def getFile(filename):
filename = path.join(rootdir, filename)
print filename
if (not filename.startswith(rootdir)):
return None
if (not path.exists(filename)):
return None
f = open(filename, 'r')
contents = f.read()
f.close()
return contents
class index:
def handle(self, filename, i):
if (filename == ""):
filename = "recon.html"
web.header('Content-type','text/html')
contents = getFile(filename)
if ("data" in i):
data = i.data.replace("'", "\\'")
return contents.replace("<!-- POSTed data goes here -->",
"<script language='javascript'>handlePOSTdata(%s)</script>" % simplejson.dumps(data))
return contents
def POST(self, filename):
return self.handle(filename, web.input())
def GET(self, filename):
return self.handle(filename, web.input())
web.config.debug = False
urls = ('/(.*)', 'index')
app = web.application(urls, globals())
if __name__ == "__main__":
port = 9777
if (len(sys.argv) == 2):
port = int(sys.argv[1])
web.httpserver.runsimple(app.wsgifunc(), ("localhost",port))