Skip to content

Commit

Permalink
Gives ts3http the ability to see all instance related things over the…
Browse files Browse the repository at this point in the history
… web interface. The web interface is still not working - it's just a concept proof.
  • Loading branch information
derkalle4 committed Jun 17, 2015
1 parent 723d355 commit c7bf725
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 25 deletions.
2 changes: 1 addition & 1 deletion ts3eventscripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
instances[key].daemon = True
instances[key].start()
# start webinterface
t = Thread(target=ts3http, args=(instances))
t = Thread(target=ts3http, kwargs={'inst':instances})
t.daemon = True
t.start()

Expand Down
58 changes: 34 additions & 24 deletions ts3http.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
"""
Need: sudo pip3 install jinja2
"""
instances = None

class ts3http():
def __init__(self, instances):
print (instances)
def __init__(self, inst):
global instances
instances = inst
serv = HTTPServer(('', 8080), MyRequestHandler)
serv.serve_forever()

class MyRequestHandler(CGIHTTPRequestHandler):
def do_GET(self):
global instances
print(instances)
try:
path = './wwwroot/' + self.path.split('?')[0]
if self.path == "/":
Expand All @@ -25,38 +29,44 @@ def do_GET(self):
self.wfile.write(bytes(tpl.render(), 'UTF-8'))
f.close()
return
elif '.html' in path:
elif self.path.split('/')[1] in instances:
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
f = open(path)
f = open('./wwwroot/instance.html')
tpl = Template(f.read())
self.wfile.write(bytes(tpl.render(), 'UTF-8'))
self.wfile.write(bytes(tpl.render(instance=instances[self.path.split('/')[1]]), 'UTF-8'))
f.close()
return
elif '/assets/' in self.path:
fileName, fileExtension = os.path.splitext(path)
f = open(path, 'rb')
if fileExtension == '.png':
contentType = 'image/png'
elif fileExtension == '.jpg' or fileExtension == '.jpeg':
contentType = 'image/jpeg'
elif fileExtension == '.css':
contentType = 'text/css'
else:
contentType = 'text/html'
self.send_response(200)
self.send_header('Content-type', contentType)
self.end_headers()
self.wfile.write(f.read())
f.close()
return
else:
if '/assets/' in self.path:
fileName, fileExtension = os.path.splitext(path)
f = open(path, 'rb')
if fileExtension == '.png':
contentType = 'image/png'
elif fileExtension == '.jpg' or fileExtension == '.jpeg':
contentType = 'image/jpeg'
elif fileExtension == '.css':
contentType = 'text/css'
else:
contentType = 'text/html'
self.send_response(200)
self.send_header('Content-type', contentType)
self.end_headers()
self.wfile.write(f.read())
f.close()
return
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
f = open('./wwwroot/templates/404.html')
tpl = Template(f.read())
self.wfile.write(bytes(tpl.render(), 'UTF-8'))
f.close()
except IOError:
# self.send_error(404, 'file not found: %s' % self.path)
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
# self.end_headers()
f = open('./wwwroot/templates/404.html')
tpl = Template(f.read())
self.wfile.write(bytes(tpl.render(), 'UTF-8'))
Expand Down

0 comments on commit c7bf725

Please sign in to comment.