From c5564162515f5d6afafe9082e8dbb2ed63a9d256 Mon Sep 17 00:00:00 2001 From: cbdev Date: Sat, 12 Aug 2023 23:05:18 +0200 Subject: Admin interfaces --- backend/Admin.py | 19 ++++++++++++++----- backend/config.py | 6 ++++++ backend/utils.py | 16 ++++++++++++++++ 3 files changed, 36 insertions(+), 5 deletions(-) (limited to 'backend') diff --git a/backend/Admin.py b/backend/Admin.py index a844aff..2070293 100644 --- a/backend/Admin.py +++ b/backend/Admin.py @@ -8,7 +8,10 @@ template_factory = jinja2.Environment(loader=jinja2.FileSystemLoader('../interfa admin_dirs = template_factory.get_template("admin_dirs.tmpl") admin_files = template_factory.get_template("admin_files.tmpl") +admin_upload = template_factory.get_template("admin_upload.tmpl") admin_delete = template_factory.get_template("admin_delete.tmpl") +admin_rename = template_factory.get_template("admin_rename.tmpl") +admin_aliases = template_factory.get_template("admin_aliases.tmpl") def route(path, env, post): auth = config.Auth.get(env) @@ -39,11 +42,19 @@ def route(path, env, post): files = utils.dirlisting(directory, True, False) return [admin_files.render({"user": auth["user"], "listing": files, "directory": utils.sanitize_filename(path[1])}), [("Content-Type", "text/html")], "200 OK"] + # Upload + if len(path) == 3 and path[2] == "upload": + return [admin_upload.render({"user": auth["user"], "directory": utils.sanitize_filename(path[1])}), [("Content-Type", "text/html")], "200 OK"] + # Alias management / Limits config - # TODO + if len(path) == 3 and path[2] == "aliases": + aliases = utils.aliases(auth["user"], utils.sanitize_filename(path[1])) + return [admin_aliases.render({"user": auth["user"], "directory": utils.sanitize_filename(path[1]), "aliases": aliases, "baseurl": config.baseurl}), [("Content-Type", "text/html")], "200 OK"] # Renaming - # TODO + if len(path) == 3 and path[2] == "rename": + # TODO + return [admin_rename.render({"user": auth["user"], "directory": utils.sanitize_filename(path[1])}), [("Content-Type", "text/html")], "200 OK"] # Deletion if len(path) == 3 and path[2] == "delete": @@ -52,9 +63,7 @@ def route(path, env, post): return utils.redirect("/admin") files = utils.dirlisting(directory, True, False) if len(files) == 0 or env.get("QUERY_STRING", "") == "confirm": - # TODO remove contents - # TODO remove aliases - os.rmdir(directory) + utils.cleanup(auth["user"], utils.sanitize_filename(path[1])) return utils.redirect("/admin") return [admin_delete.render({"user": auth["user"], "listing": files, "directory": utils.sanitize_filename(path[1])}), [("Content-Type", "text/html")], "200 OK"] diff --git a/backend/config.py b/backend/config.py index 2de63bc..a4a1209 100644 --- a/backend/config.py +++ b/backend/config.py @@ -8,5 +8,11 @@ global_limit = 0 user_subdirs = True # Path to the backing database database = "cargohold.db3" + +# Settings for the web admin panel + +# Base URL for rendering alias links +baseurl = "https://files.stumpf.es/" + # Select the authentication provider for the web admin interface import NoneAuth as Auth diff --git a/backend/utils.py b/backend/utils.py index bab7ebe..1e23e63 100644 --- a/backend/utils.py +++ b/backend/utils.py @@ -57,3 +57,19 @@ def dirlisting(path, files, dirs): listing.append({"name": entry, "size": size}) return listing + +def cleanup(user, subdir): + directory = userdir(user) + subdir + "/" + print("Cleaning up %s" % (directory, )) + # TODO + # Remove contents + # Remove aliases + os.rmdir(directory) + return + +def aliases(user, subdir): + aliases = [] + data = db.cursor().execute("SELECT alias, access, storage, display FROM aliases WHERE user = :user AND real = :dir", {"user": user, "dir": subdir}).fetchall() + for alias in data: + aliases.append({"alias": alias[0], "access": alias[1], "storage": alias[2], "display": alias[3]}) + return aliases -- cgit v1.2.3