implement user list, enable, disable
This commit is contained in:
parent
b0c7abe362
commit
2c6b0e3d30
@ -45,7 +45,7 @@ class SessionController(WebpageController):
|
|||||||
if "user" in data and "password" in data:
|
if "user" in data and "password" in data:
|
||||||
if data["user"] in userlist:
|
if data["user"] in userlist:
|
||||||
user = userlist[data["user"]]
|
user = userlist[data["user"]]
|
||||||
if user.password.is_valid(data["password"]):
|
if user.is_enabled() and user.password.is_valid(data["password"]):
|
||||||
# TODO evaluate password force_change and redirect to password change
|
# TODO evaluate password force_change and redirect to password change
|
||||||
key = SessionStorage.getSharedInstance().startSession({"user": user.name})
|
key = SessionStorage.getSharedInstance().startSession({"user": user.name})
|
||||||
cookie = SimpleCookie()
|
cookie = SimpleCookie()
|
||||||
|
@ -105,6 +105,15 @@ class User(object):
|
|||||||
def setPassword(self, password: Password):
|
def setPassword(self, password: Password):
|
||||||
self.password = password
|
self.password = password
|
||||||
|
|
||||||
|
def is_enabled(self):
|
||||||
|
return self.enabled
|
||||||
|
|
||||||
|
def enable(self):
|
||||||
|
self.enabled = True
|
||||||
|
|
||||||
|
def disable(self):
|
||||||
|
self.enabled = False
|
||||||
|
|
||||||
|
|
||||||
class UserList(object):
|
class UserList(object):
|
||||||
sharedInstance = None
|
sharedInstance = None
|
||||||
@ -185,3 +194,6 @@ class UserList(object):
|
|||||||
raise KeyError("User {user} already exists".format(user=key))
|
raise KeyError("User {user} already exists".format(user=key))
|
||||||
self.users[key] = value
|
self.users[key] = value
|
||||||
self.store()
|
self.store()
|
||||||
|
|
||||||
|
def values(self):
|
||||||
|
return self.users.values()
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from owrx.version import openwebrx_version
|
from owrx.version import openwebrx_version
|
||||||
from owrxadmin.commands import NewUser, DeleteUser, ResetPassword
|
from owrxadmin.commands import NewUser, DeleteUser, ResetPassword, ListUsers, DisableUser, EnableUser
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
@ -9,12 +9,14 @@ def main():
|
|||||||
print("OpenWebRX admin version {version}".format(version=openwebrx_version))
|
print("OpenWebRX admin version {version}".format(version=openwebrx_version))
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("command", help="One of the following commands: adduser, removeuser, resetpassword")
|
parser.add_argument("command", help="""One of the following commands:
|
||||||
|
adduser, removeuser, listusers, resetpassword, enableuser, disableuser""")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--noninteractive", action="store_true", help="Don't ask for any user input (useful for automation)"
|
"--noninteractive", action="store_true", help="Don't ask for any user input (useful for automation)"
|
||||||
)
|
)
|
||||||
parser.add_argument("--silent", action="store_true", help="Ignore errors (useful for automation)")
|
parser.add_argument("--silent", action="store_true", help="Ignore errors (useful for automation)")
|
||||||
parser.add_argument("-u", "--user", help="User name to perform action upon")
|
parser.add_argument("-u", "--user", help="User name to perform action upon")
|
||||||
|
parser.add_argument("-a", "--all", action="store_true", help="Show all users")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.command == "adduser":
|
if args.command == "adduser":
|
||||||
@ -23,6 +25,12 @@ def main():
|
|||||||
command = DeleteUser()
|
command = DeleteUser()
|
||||||
elif args.command == "resetpassword":
|
elif args.command == "resetpassword":
|
||||||
command = ResetPassword()
|
command = ResetPassword()
|
||||||
|
elif args.command == "listusers":
|
||||||
|
command = ListUsers()
|
||||||
|
elif args.command == "disableuser":
|
||||||
|
command = DisableUser()
|
||||||
|
elif args.command == "enableuser":
|
||||||
|
command = EnableUser()
|
||||||
else:
|
else:
|
||||||
if not args.silent:
|
if not args.silent:
|
||||||
print("Unknown command: {command}".format(command=args.command))
|
print("Unknown command: {command}".format(command=args.command))
|
||||||
|
@ -76,3 +76,28 @@ class ResetPassword(UserCommand):
|
|||||||
# this is a change to an object in the list, not the list itself
|
# this is a change to an object in the list, not the list itself
|
||||||
# in this case, store() is explicit
|
# in this case, store() is explicit
|
||||||
userList.store()
|
userList.store()
|
||||||
|
|
||||||
|
|
||||||
|
class DisableUser(UserCommand):
|
||||||
|
def run(self, args):
|
||||||
|
username = self.getUser(args)
|
||||||
|
userList = UserList()
|
||||||
|
userList[username].disable()
|
||||||
|
userList.store()
|
||||||
|
|
||||||
|
|
||||||
|
class EnableUser(UserCommand):
|
||||||
|
def run(self, args):
|
||||||
|
username = self.getUser(args)
|
||||||
|
userList = UserList()
|
||||||
|
userList[username].enable()
|
||||||
|
userList.store()
|
||||||
|
|
||||||
|
|
||||||
|
class ListUsers(Command):
|
||||||
|
def run(self, args):
|
||||||
|
userList = UserList()
|
||||||
|
print("List of enabled users:")
|
||||||
|
for u in userList.values():
|
||||||
|
if args.all or u.enabled:
|
||||||
|
print(" {name}".format(name=u.name))
|
||||||
|
Loading…
Reference in New Issue
Block a user