Compare commits

..

No commits in common. "5bb722a83d76fcb67d75419113b8a0d79ecbfb68" and "d7622fd2ab3ac200e8fc4fc935dcb0233375697a" have entirely different histories.

3 changed files with 26 additions and 28 deletions

View File

@ -1,30 +1,33 @@
#!/bin/bash
echo "Script started" >> /home/jelastic/add-sftp-user-addon/script_output.log
# Generate random username and password
USERNAME="user$(shuf -i 10000-99999 -n 1)"
PASSWORD=$(openssl rand -base64 12)
ROOT_DIRECTORY="/var/www/webroot/ROOT"
# Set the user's home directory within the ROOT directory
USER_HOME="/var/www/webroot/ROOT/$USERNAME"
# Check if user already exists
if id "$USERNAME" &>/dev/null; then
echo "User $USERNAME already exists." >> /home/jelastic/add-sftp-user-addon/script_output.log
echo "User $USERNAME already exists."
exit 1
fi
# Create user
useradd -m -d $ROOT_DIRECTORY $USERNAME
# Create user with the specified home directory
useradd -m -d $USER_HOME $USERNAME
if [ $? -ne 0 ]; then
echo "Failed to create user $USERNAME." >> /home/jelastic/add-sftp-user-addon/script_output.log
echo "Failed to create user $USERNAME."
exit 1
fi
echo "$USERNAME:$PASSWORD" | chpasswd
# Set user's group to both litespeed and root
usermod -aG litespeed,root $USERNAME
# Adjust permissions for the user to write to the ROOT_DIRECTORY
chown $USERNAME:root $ROOT_DIRECTORY
chmod 775 $ROOT_DIRECTORY
# Adjust permissions for the user to write to their home directory
mkdir -p $USER_HOME
chown $USERNAME:root $USER_HOME
chmod 775 $USER_HOME
HOSTNAME=$(hostname -f)
echo "Script completed for user $USERNAME with hostname $HOSTNAME" >> /home/jelastic/add-sftp-user-addon/script_output.log
# Get the hostname (if needed later in the script)
HOSTNAME=$(hostname -f)

12
install-sftp.sh 100644
View File

@ -0,0 +1,12 @@
#!/bin/bash
# Root User
sudo su
# Update sshd_config
echo -e "\nMatch User user*\nPasswordAuthentication yes" >> /etc/ssh/sshd_config
# Adjust permissions
chown root:root /var/www/webroot/ROOT
chmod 755 /var/www/webroot/ROOT
#Restart SSH daemon
sudo systemctl restart sshd

View File

@ -45,8 +45,6 @@ onInstall:
commands:
- systemctl restart sshd
user: root
- api: environment.control.RestartContainer
nodeGroup: cp
- return: installSuccess
actions:
@ -54,27 +52,12 @@ actions:
- cmd[cp]:
commands: bash /home/jelastic/add-sftp-user-addon/add-sftp.sh
user: root
- if ("${response.exitStatus}" != "0"):
return: sftpError
- return: sftpSuccess
onUninstall:
- cmd[cp]:
commands:
- rm -rf /home/jelastic/add-sftp-user-addon/
user: root
- return: uninstallSuccess
responses:
uninstallSuccess:
type: success
message: "Uninstalled Successfully"
installSuccess:
type: success
message: "Installed Successfully"
sftpError:
type: error
message: "Failed to add SFTP user. Please check the server logs for more details."
sftpSuccess:
type: success
email: |-