From d147a81499cba9163eb7ef47c597f035c19e4895 Mon Sep 17 00:00:00 2001 From: Philip Trauner Date: Thu, 2 Mar 2017 22:24:39 +0100 Subject: [PATCH] Serve dashb0ard and static content on startup --- Server/Server.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Server/Server.py b/Server/Server.py index c523bda..34944e0 100644 --- a/Server/Server.py +++ b/Server/Server.py @@ -8,14 +8,24 @@ import re import pwd import platform from subprocess import Popen, PIPE +from _thread import start_new_thread from wsgiref.simple_server import make_server from ws4py.server.wsgirefserver import WSGIServer, WebSocketWSGIRequestHandler from ws4py.server.wsgiutils import WebSocketWSGIApplication import behem0th +from bottle.bottle import route, run, static_file +@route("/") +def index(): + return static_file("index.html", root="Shared/dashb1ard") + +@route("/static/") +def static(filepath): + return static_file(filepath, root="Shared/dashb1ard/static") + class Info(Route): def run(self, data, handler): handler.send({"routes" : list(handler.routes.keys())}, "info") @@ -195,7 +205,9 @@ CONFIG_PATH = "server.cfg" config = Config() -config.add(Option("server_address", ("127.0.0.1", 3077))) +config.add(Option("fl0w_address", ("127.0.0.1", 3077))) +config.add(Option("behem0th_address", ("127.0.0.1", 3078))) +config.add(Option("dashb0ard_address", ("127.0.0.1", 8080))) config.add(Option("debug", True, validator=lambda x: True if True or False else False)) config.add(Option("path", "Content", validator=folder_validator)) @@ -209,7 +221,7 @@ except (IOError, ExceptionInConfigError): #compile = Compile(config.source_path, config.binary_path) -server = make_server(config.server_address[0], config.server_address[1], +server = make_server(config.fl0w_address[0], config.fl0w_address[1], server_class=WSGIServer, handler_class=WebSocketWSGIRequestHandler, app=None) server.initialize_websockets_manager() @@ -239,6 +251,12 @@ sync_client = behem0th.Client(path=config.path, verbose_log=config.debug) try: Logging.header("Server loop starting.") sync_client.listen() + start_new_thread(run, (), {"host" : config.dashb0ard_address[0], + "port" : config.dashb0ard_address[1], "quiet" : True}) + Logging.info("Starting dashb0ard on 'http://%s:%d'" % (config.dashb0ard_address[0], + config.dashb0ard_address[1])) + Logging.info("Starting fl0w on 'ws://%s:%d'" % (config.fl0w_address[0], + config.fl0w_address[1])) server.serve_forever() except KeyboardInterrupt: Logging.header("Gracefully shutting down server.")