Added debug logs
parent
d7622fd2ab
commit
f38ef098fa
26
add-sftp.sh
26
add-sftp.sh
|
@ -1,33 +1,33 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
echo "Script started" >> /home/jelastic/add-sftp-user-addon/script_output.log
|
||||||
|
|
||||||
# Generate random username and password
|
# Generate random username and password
|
||||||
USERNAME="user$(shuf -i 10000-99999 -n 1)"
|
USERNAME="user$(shuf -i 10000-99999 -n 1)"
|
||||||
PASSWORD=$(openssl rand -base64 12)
|
PASSWORD=$(openssl rand -base64 12)
|
||||||
|
|
||||||
# Set the user's home directory within the ROOT directory
|
ROOT_DIRECTORY="/var/www/webroot/ROOT"
|
||||||
USER_HOME="/var/www/webroot/ROOT/$USERNAME"
|
|
||||||
|
|
||||||
# Check if user already exists
|
# Check if user already exists
|
||||||
if id "$USERNAME" &>/dev/null; then
|
if id "$USERNAME" &>/dev/null; then
|
||||||
echo "User $USERNAME already exists."
|
echo "User $USERNAME already exists." >> /home/jelastic/add-sftp-user-addon/script_output.log
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create user with the specified home directory
|
# Create user
|
||||||
useradd -m -d $USER_HOME $USERNAME
|
useradd -m -d $ROOT_DIRECTORY $USERNAME
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Failed to create user $USERNAME."
|
echo "Failed to create user $USERNAME." >> /home/jelastic/add-sftp-user-addon/script_output.log
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
echo "$USERNAME:$PASSWORD" | chpasswd
|
echo "$USERNAME:$PASSWORD" | chpasswd
|
||||||
|
|
||||||
# Set user's group to both litespeed and root
|
# Set user's group to both litespeed and root
|
||||||
usermod -aG litespeed,root $USERNAME
|
usermod -aG litespeed,root $USERNAME
|
||||||
|
|
||||||
# Adjust permissions for the user to write to their home directory
|
# Adjust permissions for the user to write to the ROOT_DIRECTORY
|
||||||
mkdir -p $USER_HOME
|
chown $USERNAME:root $ROOT_DIRECTORY
|
||||||
chown $USERNAME:root $USER_HOME
|
chmod 775 $ROOT_DIRECTORY
|
||||||
chmod 775 $USER_HOME
|
|
||||||
|
|
||||||
# Get the hostname (if needed later in the script)
|
# Get the hostname
|
||||||
HOSTNAME=$(hostname -f)
|
HOSTNAME=$(hostname -f)
|
||||||
|
echo "Script completed for user $USERNAME with hostname $HOSTNAME" >> /home/jelastic/add-sftp-user-addon/script_output.log
|
||||||
|
|
|
@ -52,12 +52,17 @@ actions:
|
||||||
- cmd[cp]:
|
- cmd[cp]:
|
||||||
commands: bash /home/jelastic/add-sftp-user-addon/add-sftp.sh
|
commands: bash /home/jelastic/add-sftp-user-addon/add-sftp.sh
|
||||||
user: root
|
user: root
|
||||||
|
- if ("${response.exitStatus}" != "0"):
|
||||||
|
return: sftpError
|
||||||
- return: sftpSuccess
|
- return: sftpSuccess
|
||||||
|
|
||||||
responses:
|
responses:
|
||||||
installSuccess:
|
installSuccess:
|
||||||
type: success
|
type: success
|
||||||
message: "Installed Successfully"
|
message: "Installed Successfully"
|
||||||
|
sftpError:
|
||||||
|
type: error
|
||||||
|
message: "Failed to add SFTP user. Please check the server logs for more details."
|
||||||
sftpSuccess:
|
sftpSuccess:
|
||||||
type: success
|
type: success
|
||||||
email: |-
|
email: |-
|
||||||
|
|
Loading…
Reference in New Issue