From bb742d9c7772912ec01365791ac83f9c5554b012 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 7 Nov 2021 18:59:30 -0600 Subject: [PATCH] add initial files --- index.html | 190 +++++++++++++++++++++++++++++++++++++++++++++++++++++ proxy.py | 54 +++++++++++++++ 2 files changed, 244 insertions(+) create mode 100644 index.html create mode 100644 proxy.py diff --git a/index.html b/index.html new file mode 100644 index 0000000..4f75590 --- /dev/null +++ b/index.html @@ -0,0 +1,190 @@ + + + + WebSocket demo + + + +
+
+
+

+ +
+ + + + diff --git a/proxy.py b/proxy.py new file mode 100644 index 0000000..9d318d1 --- /dev/null +++ b/proxy.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python + +import asyncio +import websockets +import os + +async def loop(ws, p): + print("connected") + writeflag = False + authed = False + async for message in ws: + if not writeflag: + split = message.split(' ') + if split[0] == 'get' and authed: + try: + fd = open('tree/' + split[1], 'r') + except FileNotFoundError: + await ws.send("text/formatted") + await ws.send("#file not found!") + await ws.send("oh no") + continue + + await ws.send("text/formatted") + for i in fd.readlines(): + await ws.send(i.rstrip()) + fd.close() + elif split[0] == 'put' and authed: + os.makedirs(os.path.dirname(split[1]), exist_ok=True) + + fd = open('tree/' + split[1], 'w+') + writeflag = True; + elif split[0] == 'auth': + accts = open('login', 'r') + linedata = [i.rstrip().split(' ') for i in accts.readlines()] + passwdmatch = False + for (username, password) in linedata: + if split[1] == username and split[2] == password: + passwdmatch = True + if passwdmatch: authed = True + await ws.send("auth succeed") + + else: + fd.write(message); + fd.close(); + writeflag = False; + + + await ws.send("hi there!") + +async def main(): + async with websockets.serve(loop, "192.168.1.30", 8765): + await asyncio.Future() + +asyncio.run(main())