mirror of
https://github.com/wazuh/wazuh-docker.git
synced 2025-11-03 13:33:15 +00:00
Fix pass change and refactor disable user into function
This commit is contained in:
@@ -9,6 +9,7 @@ import os
|
||||
sys.path.append(os.path.dirname(sys.argv[0]) + "/../framework")
|
||||
|
||||
USER_FILE_PATH = "/var/ossec/api/configuration/admin.json"
|
||||
SPECIAL_CHARS = "@$!%*?&-_"
|
||||
|
||||
|
||||
try:
|
||||
@@ -39,6 +40,26 @@ def db_roles():
|
||||
roles_result = get_roles()
|
||||
return {role["name"]: role["id"] for role in roles_result.affected_items}
|
||||
|
||||
def disable_user(uid):
|
||||
random_pass = "".join(
|
||||
random.choices(
|
||||
string.ascii_uppercase
|
||||
+ string.ascii_lowercase
|
||||
+ string.digits
|
||||
+ SPECIAL_CHARS,
|
||||
k=8,
|
||||
)
|
||||
)
|
||||
# assure there must be at least one character from each group
|
||||
random_pass = random_pass + ''.join([random.choice(chars) for chars in [string.ascii_lowercase, string.digits, string.ascii_uppercase, SPECIAL_CHARS]])
|
||||
random_pass = ''.join(random.sample(random_pass,len(random_pass)))
|
||||
update_user(
|
||||
user_id=[
|
||||
str(uid),
|
||||
],
|
||||
password=random_pass,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if not os.path.exists(USER_FILE_PATH):
|
||||
@@ -70,21 +91,7 @@ if __name__ == "__main__":
|
||||
],
|
||||
password=password,
|
||||
)
|
||||
# set a random password for all other users
|
||||
for name, id in initial_users.items():
|
||||
if name != username:
|
||||
random_pass = "".join(
|
||||
random.choices(
|
||||
string.ascii_uppercase
|
||||
+ string.ascii_lowercase
|
||||
+ string.digits
|
||||
+ "@$!%*?&-_",
|
||||
k=16,
|
||||
)
|
||||
)
|
||||
update_user(
|
||||
user_id=[
|
||||
str(id),
|
||||
],
|
||||
password=random_pass,
|
||||
)
|
||||
# disable unused default users
|
||||
for def_user in ['wazuh', 'wazuh-wui']:
|
||||
if def_user != username:
|
||||
disable_user(initial_users[def_user])
|
||||
|
||||
Reference in New Issue
Block a user