From 14e4117d7f9e91851fa2e9fb180ba164a23c96fc Mon Sep 17 00:00:00 2001 From: cynic Date: Mon, 31 Oct 2022 21:55:14 -0400 Subject: [PATCH] add web directory plugin --- towers/fiefdom.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 towers/fiefdom.py diff --git a/towers/fiefdom.py b/towers/fiefdom.py new file mode 100644 index 0000000..0d1ad6c --- /dev/null +++ b/towers/fiefdom.py @@ -0,0 +1,25 @@ +hooks = ["http.*:\/\/$HOST\/~.*"] + +def run(ctx, r): + + user = r.path[1:].split("/")[0].replace("~", "") + route = "/"+("/".join(r.path[1:].split("/")[1:])) + + if not(user in ctx.auth.get_real_users()): + return { + "body": f"

404! no such user!


consult users.{ctx.cfg.get('host')} to see all registered users", + "status": 404, "content_type": "text/html" + } + + requested = "/index.html" if route == "/" else route + try: f = open(f"/home/{user}/.web/{requested}").read() + except: + return { + "body": f"

404! no such path {requested}


double check the path exists in your ~/.web directory!", + "status": 404, "content_type": "text/html" + } + + return { + "content_type": "text/html", + "body": f + } \ No newline at end of file