Simple Script to add user addresses to the allowed list

This commit is contained in:
chengtripp 2023-02-06 21:39:49 +00:00 committed by GitHub
parent 845b89ae75
commit 36102e53f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

33
admin/add_user.py Normal file
View File

@ -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()