From 36102e53f3472161cf7ea287c6588041ae1102de Mon Sep 17 00:00:00 2001 From: chengtripp <124098378+chengtripp@users.noreply.github.com> Date: Mon, 6 Feb 2023 21:39:49 +0000 Subject: [PATCH] Simple Script to add user addresses to the allowed list --- admin/add_user.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 admin/add_user.py diff --git a/admin/add_user.py b/admin/add_user.py new file mode 100644 index 0000000..5174b33 --- /dev/null +++ b/admin/add_user.py @@ -0,0 +1,33 @@ +import RNS.vendor.umsgpack as msgpack +import os, sys + +#Setup Paths and Config Files +userdir = os.path.expanduser("~") + +if os.path.isdir("/etc/nomadmb") and os.path.isfile("/etc/nomadmb/config"): + configdir = "/etc/nomadmb" +elif os.path.isdir(userdir+"/.config/nomadmb") and os.path.isfile(userdir+"/.config/nomadmb/config"): + configdir = userdir+"/.config/nomadmb" +else: + configdir = userdir+"/.nomadmb" + +storagepath = configdir+"/storage" +if not os.path.isdir(storagepath): + os.makedirs(storagepath) + +allowedpath = configdir+"/storage/allowed" + +allowed_list = [] +if os.path.isfile(allowedpath): + f = open(allowedpath, "rb") + allowed_list = msgpack.unpack(f) + f.close() +else: + print('No file') + +new_user = input('Add User: ') +allowed_list.append(new_user) + +f = open(allowedpath, "wb") +msgpack.pack(allowed_list, f) +f.close()