Updates
parent
8c918671bd
commit
f1541e6669
62
manifest.jps
62
manifest.jps
|
@ -136,52 +136,7 @@ jps_log_system_info() {
|
||||||
jps_log "DEBUG" "SSH Status: $(systemctl status sshd | grep Active | awk '{print $2}')" "$log_file"
|
jps_log "DEBUG" "SSH Status: $(systemctl status sshd | grep Active | awk '{print $2}')" "$log_file"
|
||||||
jps_log "DEBUG" "=============================================" "$log_file"
|
jps_log "DEBUG" "=============================================" "$log_file"
|
||||||
}
|
}
|
||||||
|
EOF
|
||||||
# Function to get detailed user information including creation date
|
|
||||||
# This replaces the functionality of the retired userlogs.sh script
|
|
||||||
jps_get_user_info() {
|
|
||||||
local log_file=${1:-$LOG_DIR/list_users.log}
|
|
||||||
|
|
||||||
jps_log "INFO" "Retrieving detailed user information" "$log_file"
|
|
||||||
|
|
||||||
# Get SFTP users
|
|
||||||
local users=$(find /home/sftpusers -maxdepth 1 -mindepth 1 -type d -exec basename {} \;)
|
|
||||||
|
|
||||||
if [ -z "$users" ]; then
|
|
||||||
jps_log "INFO" "No SFTP users found" "$log_file"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
jps_log "INFO" "Found users, retrieving creation dates" "$log_file"
|
|
||||||
local result=""
|
|
||||||
|
|
||||||
# Process each user
|
|
||||||
for user in $users; do
|
|
||||||
# Get creation date from directory timestamp
|
|
||||||
local creation_date=$(stat -c "%y" "/home/sftpusers/$user" 2>/dev/null | cut -d. -f1)
|
|
||||||
|
|
||||||
# Try to get last password change as fallback
|
|
||||||
if [ -z "$creation_date" ]; then
|
|
||||||
if id "$user" &>/dev/null; then
|
|
||||||
creation_date=$(chage -l "$user" 2>/dev/null | grep "Last password change" | cut -d: -f2)
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "$creation_date" ]; then
|
|
||||||
result="${result}Username: $user - Created: $creation_date\n"
|
|
||||||
else
|
|
||||||
result="${result}Username: $user - Created: Unknown\n"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ -n "$result" ]; then
|
|
||||||
jps_log "SUCCESS" "User information retrieved successfully" "$log_file"
|
|
||||||
echo -e "$result"
|
|
||||||
else
|
|
||||||
jps_log "WARNING" "Could not retrieve user information" "$log_file"
|
|
||||||
echo ""
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Make the logging script executable
|
# Make the logging script executable
|
||||||
chmod +x /home/jelastic/add-sftp-user-addon/log_helper.sh
|
chmod +x /home/jelastic/add-sftp-user-addon/log_helper.sh
|
||||||
|
@ -530,19 +485,20 @@ actions:
|
||||||
# Log list users action
|
# Log list users action
|
||||||
jps_log "INFO" "======== LISTING SFTP USERS ========" "list_users.log"
|
jps_log "INFO" "======== LISTING SFTP USERS ========" "list_users.log"
|
||||||
|
|
||||||
# Note: This functionality replaces the retired userlogs.sh script
|
# List users with proper error handling
|
||||||
# with a more efficient and integrated approach
|
jps_log "INFO" "Retrieving list of SFTP users" "list_users.log"
|
||||||
|
|
||||||
# Get detailed user information
|
# Use a safer approach to listing
|
||||||
USER_INFO=$(jps_get_user_info "list_users.log")
|
USERS_LIST=$(ls -ld /home/sftpusers/* 2>/dev/null | grep -v "total" | awk '{printf "Username: %s - Created: %s %s %s\n", substr($9, 17), $6, $7, $8}')
|
||||||
|
|
||||||
# Output the result
|
# Check if any users were found
|
||||||
if [ -z "$USER_INFO" ]; then
|
if [ -z "$USERS_LIST" ]; then
|
||||||
jps_log "WARNING" "No SFTP users found" "list_users.log"
|
jps_log "WARNING" "No SFTP users found" "list_users.log"
|
||||||
echo ""
|
echo ""
|
||||||
else
|
else
|
||||||
jps_log "SUCCESS" "Retrieved list of SFTP users" "list_users.log"
|
jps_log "SUCCESS" "Retrieved list of SFTP users" "list_users.log"
|
||||||
echo "$USER_INFO"
|
jps_log "DEBUG" "Found users: $(echo "$USERS_LIST" | wc -l)" "list_users.log"
|
||||||
|
echo "$USERS_LIST"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
jps_log "INFO" "======== USER LISTING COMPLETED ========" "list_users.log"
|
jps_log "INFO" "======== USER LISTING COMPLETED ========" "list_users.log"
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
getent passwd | awk -F: '/^user/ {print $1}' | while read -r user; do
|
||||||
|
# Attempt to get the user's creation date from the shadow file
|
||||||
|
creation_date=$(sudo chage -l "$user" | grep 'Last password change' | cut -d: -f2)
|
||||||
|
echo "$user was created on $creation_date"
|
||||||
|
done
|
Loading…
Reference in New Issue