Updated Change Password

main
Anthony 2025-04-10 20:10:26 +08:00
parent e08c6442fb
commit 8c7d4778a1
2 changed files with 18 additions and 3 deletions

View File

@ -1,3 +1,6 @@
Version 0.5 Changelogs:
- Replaced Change Password from list of users to input the username and also a field to input the password
Version 0.4 Changelogs:
- Replaced auto-generated usernames with user-defined usernames
- Added username validation (3-32 characters, alphanumeric + underscore only)

View File

@ -1,4 +1,4 @@
version: 0.4
version: 0.5
id: addsftp
type: update
description: An addon to add new SFTP users. It can also manage created user accounts. If SSH is enabled, WP-CLI will attempt to be installed if it is not yet installed.
@ -41,6 +41,12 @@ settings:
description: "Input the username you want to manage."
required: true
values: []
- type: string
name: custom_password
caption: New Password
description: "Enter a new password or leave empty to generate one automatically"
required: false
inputType: password
onBeforeInit: |
let cmd = 'ls -ld /home/sftpusers/* | awk \'{printf "%s,%s %s %s\\n", substr($9, 17), $6, $7, $8}\''
@ -127,10 +133,16 @@ actions:
type: info
message: "Connection Details\n\nSFTP Host: ${globals.sftpHost}\n\nPort: ${globals.sftpPort}\n\nLogin Credentials\n\nUsername: ${globals.username}\n\nPassword: ${globals.password}"
change_password:
- if (!${settings.custom_password:false}):
setGlobals:
custom_password: ${fn.password(min)}
else:
setGlobals:
custom_password: ${settings.custom_password}
- cmd[cp]:
user: root
commands:
- echo "${settings.manage_username}:${globals.password}" | chpasswd
- echo "${settings.manage_username}:${globals.custom_password}" | chpasswd
- echo "Password changed for ${settings.manage_username}" >> /home/jelastic/add-sftp-user-addon/logs/script_output.log
- if ("${response.exitStatus}" != "0"):
return: passwordChangeError
@ -167,7 +179,7 @@ responses:
message: "Failed to change password for ${settings.manage_username}. Check logs for details."
passwordChangeSuccess:
type: success
message: "Password changed successfully for ${settings.manage_username}.\n\n New password: ${globals.password}"
message: "Password changed successfully for ${settings.manage_username}.\n\n New password: ${globals.custom_password}"
deleteUserError:
type: error
message: "Failed to delete user ${settings.manage_username}. Check logs for details."