diff --git a/scripts/n2nhttpd b/scripts/n2nhttpd index a69f5ac..f6202cc 100755 --- a/scripts/n2nhttpd +++ b/scripts/n2nhttpd @@ -3,10 +3,12 @@ # # Simple http server to allow user control of n2n edge nodes # -# Currently only for demonstration - needs javascript written to render the -# results properly. +# Currently only for demonstration +# - needs nicer looking html written +# - needs more json interfaces in edge # # Try it out with +# http://localhost:8080/ # http://localhost:8080/edge/peer # http://localhost:8080/edge/super @@ -69,6 +71,82 @@ def send_cmd(port, debug, cmd): result.append(data) +indexhtml = """ + + + n2n management + + +
+
+ Supernodes: +
+
+ Peers: +
+ + + + +""" + + class SimpleHandler(http.server.BaseHTTPRequestHandler): def log_request(self, code='-', size='-'): @@ -77,9 +155,18 @@ class SimpleHandler(http.server.BaseHTTPRequestHandler): def do_GET(self): url_tail = self.path + + if url_tail == "/": + self.send_response(HTTPStatus.OK) + self.send_header('Content-type', 'text/html; charset=utf-8') + self.end_headers() + self.wfile.write(indexhtml.encode('utf8')) + return + if url_tail.startswith("/edge/"): tail = url_tail.split('/') cmd = 'j.' + tail[2] + # if commands ever need args, use more of the path components try: data = send_cmd(5644, False, cmd) @@ -93,6 +180,12 @@ class SimpleHandler(http.server.BaseHTTPRequestHandler): self.send_header('Content-type', 'application/json') self.end_headers() self.wfile.write(json.dumps(data).encode('utf8')) + return + + self.send_response(HTTPStatus.NOT_FOUND) + self.end_headers() + self.wfile.write(b'Not Found') + return def main():