diff --git a/check-sftp-user.sh b/check-sftp-user.sh index 897b239..b916880 100644 --- a/check-sftp-user.sh +++ b/check-sftp-user.sh @@ -5,7 +5,14 @@ # Use this script to diagnose SFTP/SSH account creation issues # ============================================================================== -USERNAME="${1:-mightyuser1}" +# Get username from argument or prompt +if [ -z "$1" ]; then + echo "Usage: $0 " + echo "Example: $0 mightyuser1" + exit 1 +fi + +USERNAME="$1" echo "==============================================================================" echo "SFTP/SSH User Diagnostic Script" @@ -106,15 +113,39 @@ if id "$USERNAME" &>/dev/null; then USER_HOME=$(getent passwd $USERNAME | cut -d: -f6) if [ -d "$USER_HOME/data" ]; then print_status "OK" "Data directory exists: $USER_HOME/data" - echo " Ownership: $(stat -c '%U:%G' $USER_HOME/data)" - echo " Permissions: $(stat -c '%a' $USER_HOME/data)" + echo " Ownership: $(stat -c '%U:%G' $USER_HOME/data 2>/dev/null || echo 'N/A')" + echo " Permissions: $(stat -c '%a' $USER_HOME/data 2>/dev/null || echo 'N/A')" if [ -d "$USER_HOME/data/ROOT" ]; then print_status "OK" "ROOT directory exists: $USER_HOME/data/ROOT" # Check if it's a mount point if mountpoint -q "$USER_HOME/data/ROOT" 2>/dev/null; then print_status "OK" "ROOT is properly mounted (bind mount)" - echo " Mount info: $(mount | grep "$USER_HOME/data/ROOT")" + MOUNT_INFO=$(mount | grep "$USER_HOME/data/ROOT" 2>/dev/null || echo "No mount info found") + echo " Mount info: $MOUNT_INFO" + + # Check webroot permissions + WEBROOT_DIR="/var/www/webroot/ROOT" + if [ -d "$WEBROOT_DIR" ]; then + WEBROOT_PERMS=$(stat -c '%a' "$WEBROOT_DIR" 2>/dev/null) + WEBROOT_GROUP=$(stat -c '%G' "$WEBROOT_DIR" 2>/dev/null) + WEBROOT_OWNER=$(stat -c '%U:%G' "$WEBROOT_DIR" 2>/dev/null) + echo " Webroot permissions: $WEBROOT_PERMS ($WEBROOT_OWNER)" + + # Check if group has write permission + GROUP_WRITE_BIT=$(echo "$WEBROOT_PERMS" | cut -c2) + if [ "$GROUP_WRITE_BIT" = "4" ] || [ "$GROUP_WRITE_BIT" = "5" ] || [ "$GROUP_WRITE_BIT" = "1" ] || [ "$GROUP_WRITE_BIT" = "0" ]; then + print_status "WARNING" "Webroot does NOT have group write permissions (current: $WEBROOT_PERMS)" + echo " Fix: chmod -R g+w $WEBROOT_DIR" + else + print_status "OK" "Webroot has group write permissions" + fi + + if [ "$WEBROOT_GROUP" != "litespeed" ]; then + print_status "WARNING" "Webroot group is not litespeed (current: $WEBROOT_GROUP)" + echo " Fix: chgrp -R litespeed $WEBROOT_DIR" + fi + fi else print_status "WARNING" "ROOT directory exists but is not mounted" echo " Fix: mount --bind /var/www/webroot/ROOT $USER_HOME/data/ROOT" @@ -312,3 +343,5 @@ echo "========================================================================== echo "Diagnostic complete!" echo "==============================================================================" +# Exit with success status +exit 0 diff --git a/manifest.jps b/manifest.jps index 4a93c44..1382a33 100644 --- a/manifest.jps +++ b/manifest.jps @@ -57,6 +57,15 @@ settings: required: true regex: ^[a-zA-Z0-9_]{3,32}$ regexText: "Username must be 3-32 characters long and contain only letters, numbers, and underscores" + diagnosticForm: + fields: + - type: string + name: diagnostic_username + caption: Username to Diagnose + description: "Enter the username you want to diagnose." + required: true + regex: ^[a-zA-Z0-9_]{3,32}$ + regexText: "Username must be 3-32 characters long and contain only letters, numbers, and underscores" globals: username: ${settings.custom_username} @@ -96,8 +105,14 @@ onInstall: exit 1 fi + echo "Downloading check-sftp-user.sh..." >> /opt/add-sftp-user-addon/logs/script_output.log + if ! wget --no-check-certificate -O /opt/add-sftp-user-addon/check-sftp-user.sh "https://deploy-proxy.mightybox.io/addons/add-sftp-user/raw/branch/main/check-sftp-user.sh" 2>&1 | tee -a /opt/add-sftp-user-addon/logs/script_output.log; then + echo "ERROR: Failed to download check-sftp-user.sh" >> /opt/add-sftp-user-addon/logs/script_output.log + exit 1 + fi + # Verify files were downloaded and are not empty - for file in /opt/add-sftp-user-addon/add-sftp.sh /opt/add-sftp-user-addon/scripts/logging.sh /opt/add-sftp-user-addon/scripts/system_prep.sh; do + for file in /opt/add-sftp-user-addon/add-sftp.sh /opt/add-sftp-user-addon/scripts/logging.sh /opt/add-sftp-user-addon/scripts/system_prep.sh /opt/add-sftp-user-addon/check-sftp-user.sh; do if [ ! -f "$file" ]; then echo "ERROR: File not found: $file" >> /opt/add-sftp-user-addon/logs/script_output.log exit 1 @@ -116,6 +131,7 @@ onInstall: done chmod +x /opt/add-sftp-user-addon/add-sftp.sh + chmod +x /opt/add-sftp-user-addon/check-sftp-user.sh chmod +x /opt/add-sftp-user-addon/scripts/*.sh # Source libraries and run the system preparation function @@ -186,12 +202,12 @@ onInstall: - return: installSuccess menu: - confirmText: "Do you want to list all users?" - loadingText: "Loading users..." - action: "list_users" - caption: "List Users" - successText: "Users listed successfully!" - logsNodeGroup: cp + - confirmText: "Do you want to list all users?" + loadingText: "Loading users..." + action: "list_users" + caption: "List Users" + successText: "Users listed successfully!" + logsNodeGroup: cp actions: add_sftp_user: @@ -437,6 +453,36 @@ actions: type: warning message: "No SFTP users found. Use the Add SFTP/SSH User button to create one." - return: listUsers + diagnose_user: + - cmd[cp]: + user: root + commands: |- + # Create log file for this run + LOG_FILE="/opt/add-sftp-user-addon/logs/diagnostic.log" + touch "$LOG_FILE" + + # Run diagnostic script + if [ -f "/opt/add-sftp-user-addon/check-sftp-user.sh" ]; then + /opt/add-sftp-user-addon/check-sftp-user.sh "${settings.diagnostic_username}" >> "$LOG_FILE" 2>&1 + DIAGNOSTIC_EXIT=$? + + # Output the diagnostic results + cat "$LOG_FILE" + + if [ $DIAGNOSTIC_EXIT -eq 0 ]; then + exit 0 + else + exit $DIAGNOSTIC_EXIT + fi + else + echo "ERROR: Diagnostic script not found at /opt/add-sftp-user-addon/check-sftp-user.sh" + exit 1 + fi + - if ("${response.exitStatus}" != "0"): + return: + type: error + message: "Diagnostic check failed for ${settings.diagnostic_username}. Check logs for details." + - return: diagnosticSuccess responses: installSuccess: @@ -465,7 +511,10 @@ responses: message: "No SFTP users have been created yet." listUsers: type: info - message: "${response.out}" + message: "${response.out}" + diagnosticSuccess: + type: info + message: "Diagnostic check completed for ${settings.diagnostic_username}.\n\n${response.out}" buttons: - settings: sfpform @@ -483,6 +532,11 @@ buttons: caption: Delete User confirmText: "Are you sure you want to delete this user? This action cannot be undone." submitButtonText: Delete User + - settings: diagnosticForm + action: diagnose_user + caption: Diagnose User + confirmText: "Do you want to run diagnostics on this user?" + submitButtonText: Run Diagnostics onUninstall: - cmd[cp]: