Compare commits
No commits in common. "e08c6442fbcf8f8c37ea84b8771a78de06b809fc" and "be6ce918b2d7111018e9063d77306dbd4b154f31" have entirely different histories.
e08c6442fb
...
be6ce918b2
15
README.md
15
README.md
|
@ -1,18 +1,3 @@
|
||||||
Version 0.4 Changelogs:
|
|
||||||
- Replaced auto-generated usernames with user-defined usernames
|
|
||||||
- Added username validation (3-32 characters, alphanumeric + underscore only)
|
|
||||||
- Implemented duplicate username checking
|
|
||||||
- Enhanced error handling for invalid username formats
|
|
||||||
- Added user-friendly error messages for username validation
|
|
||||||
- Maintained backward compatibility with existing user management
|
|
||||||
|
|
||||||
Version 0.3 Changelogs:
|
|
||||||
- Fixed SSH configuration handling to prevent duplicate Match User entries
|
|
||||||
- Implemented idempotent sshd_config modification using pattern matching and deduplication
|
|
||||||
- Added atomic configuration updates with proper indentation handling
|
|
||||||
- Removed redundant SSH service restarts while maintaining reliability
|
|
||||||
- Added configuration validation before applying changes
|
|
||||||
|
|
||||||
Version 0.2 Changelogs:
|
Version 0.2 Changelogs:
|
||||||
- Added a submitUnchanged property to allow submitting the 'Add User' form even if the settings haven't been changed.
|
- Added a submitUnchanged property to allow submitting the 'Add User' form even if the settings haven't been changed.
|
||||||
- Changed required: true to required: false for the 'Accept User Creation' checkbox
|
- Changed required: true to required: false for the 'Accept User Creation' checkbox
|
||||||
|
|
26
add-sftp.sh
26
add-sftp.sh
|
@ -24,14 +24,9 @@ log_debug() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Validate username format
|
# Generate random username
|
||||||
validate_username() {
|
generate_username() {
|
||||||
local username=$1
|
echo "user$(shuf -i 10000-99999 -n 1)"
|
||||||
if ! [[ $username =~ ^[a-zA-Z0-9_]{3,32}$ ]]; then
|
|
||||||
log_error "Invalid username format. Username must be 3-32 characters long and contain only letters, numbers, and underscores."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
USERNAME=$1
|
USERNAME=$1
|
||||||
|
@ -40,16 +35,11 @@ SSH_ENABLED=$3
|
||||||
|
|
||||||
log "Script started"
|
log "Script started"
|
||||||
|
|
||||||
# Validate username format
|
# Check if user already exists, if yes generate a new one
|
||||||
if ! validate_username "$USERNAME"; then
|
while id "$USERNAME" &>/dev/null; do
|
||||||
exit 1
|
USERNAME=$(generate_username)
|
||||||
fi
|
log_warning "Username $USERNAME already exists, generating a new username."
|
||||||
|
done
|
||||||
# Check if user already exists
|
|
||||||
if id "$USERNAME" &>/dev/null; then
|
|
||||||
log_error "Username $USERNAME already exists. Please choose a different username."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
USER_HOME="/home/sftpusers/$USERNAME"
|
USER_HOME="/home/sftpusers/$USERNAME"
|
||||||
ROOT_DIRECTORY="/var/www/webroot/ROOT"
|
ROOT_DIRECTORY="/var/www/webroot/ROOT"
|
||||||
|
|
23
manifest.jps
23
manifest.jps
|
@ -1,4 +1,4 @@
|
||||||
version: 0.4
|
version: 0.2
|
||||||
id: addsftp
|
id: addsftp
|
||||||
type: update
|
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.
|
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.
|
||||||
|
@ -16,13 +16,6 @@ settings:
|
||||||
caption: Root Directory /var/www/webroot/ROOT/
|
caption: Root Directory /var/www/webroot/ROOT/
|
||||||
description: "A user-specific directory will be created under /home/username"
|
description: "A user-specific directory will be created under /home/username"
|
||||||
required: false
|
required: false
|
||||||
- type: string
|
|
||||||
name: custom_username
|
|
||||||
caption: Custom Username
|
|
||||||
description: "Enter a custom username (3-32 characters, alphanumeric + underscore only)"
|
|
||||||
required: true
|
|
||||||
regex: ^[a-zA-Z0-9_]{3,32}$
|
|
||||||
regexText: "Username must be 3-32 characters long and contain only letters, numbers, and underscores"
|
|
||||||
- type: checkbox
|
- type: checkbox
|
||||||
name: allow
|
name: allow
|
||||||
caption: Accept User Creation
|
caption: Accept User Creation
|
||||||
|
@ -67,7 +60,7 @@ settings:
|
||||||
|
|
||||||
|
|
||||||
globals:
|
globals:
|
||||||
username: ${settings.custom_username}
|
username: "user${fn.random(10000,99999)}"
|
||||||
password: ${fn.password(min)}
|
password: ${fn.password(min)}
|
||||||
sftpHost: ${env.domain}
|
sftpHost: ${env.domain}
|
||||||
sftpPort: 22
|
sftpPort: 22
|
||||||
|
@ -82,15 +75,9 @@ onInstall:
|
||||||
wget https://deploy-proxy.mightybox.io/addons/add-sftp-user/raw/branch/main/add-sftp.sh -O /home/jelastic/add-sftp-user-addon/add-sftp.sh
|
wget https://deploy-proxy.mightybox.io/addons/add-sftp-user/raw/branch/main/add-sftp.sh -O /home/jelastic/add-sftp-user-addon/add-sftp.sh
|
||||||
chmod +x /home/jelastic/add-sftp-user-addon/*.sh
|
chmod +x /home/jelastic/add-sftp-user-addon/*.sh
|
||||||
- cmd[cp]:
|
- cmd[cp]:
|
||||||
user: root
|
user: root
|
||||||
commands: |-
|
commands:
|
||||||
if grep -qE "^Match User user[0-9]*$" /etc/ssh/sshd_config; then
|
- echo -e "\nMatch User user*\nPasswordAuthentication yes" >> /etc/ssh/sshd_config
|
||||||
sed -i '/^Match User user[0-9]*/!b;n;c\ PasswordAuthentication yes' /etc/ssh/sshd_config
|
|
||||||
else
|
|
||||||
echo -e "\n# Added by SFTP addon\nMatch User user*\n\tPasswordAuthentication yes" >> /etc/ssh/sshd_config
|
|
||||||
fi
|
|
||||||
awk '!seen[$0]++' /etc/ssh/sshd_config > /etc/ssh/sshd_config.tmp && mv /etc/ssh/sshd_config.tmp /etc/ssh/sshd_config
|
|
||||||
systemctl restart sshd
|
|
||||||
- cmd[cp]:
|
- cmd[cp]:
|
||||||
user: root
|
user: root
|
||||||
commands:
|
commands:
|
||||||
|
|
Loading…
Reference in New Issue