diff --git a/lib/reference-db.sh b/lib/reference-db.sh index f9edf2d..a45026c 100755 --- a/lib/reference-db.sh +++ b/lib/reference-db.sh @@ -549,9 +549,41 @@ build_wordpress_section() { build_logs_section() { echo "[LOGS]" >> "$SYSREF_DB" - # Apache/Web server logs - # Temporarily disabled - causes hangs with large log directories - # TODO: Implement log scanning with progress indicator and limits + # Control panel-specific log discovery + case "$SYS_CONTROL_PANEL" in + cpanel) + # cPanel access and error logs + find "$SYS_LOG_DIR" -name "*.log" -o -name "access_log" -o -name "error_log" 2>/dev/null | \ + head -100 | while IFS= read -r logfile; do + echo "LOG|file|$logfile|" >> "$SYSREF_DB" + done + ;; + *) + # Standalone server - find Apache/Nginx logs safely + # Limit to recent logs and prevent hangs with large directories + if [ -d "$SYS_LOG_DIR" ]; then + # Apache access logs (with safety limits) + find "$SYS_LOG_DIR" -maxdepth 2 \( -name "*access*" -o -name "*access_log*" \) -type f -mtime -30 2>/dev/null | \ + head -50 | while IFS= read -r logfile; do + [ -n "$logfile" ] && echo "LOG|access|$logfile|" >> "$SYSREF_DB" + done + + # Apache error logs (with safety limits) + find "$SYS_LOG_DIR" -maxdepth 2 \( -name "*error*" -o -name "*error_log*" \) -type f -mtime -30 2>/dev/null | \ + head -50 | while IFS= read -r logfile; do + [ -n "$logfile" ] && echo "LOG|error|$logfile|" >> "$SYSREF_DB" + done + fi + + # Nginx logs for standalone + if [ -d "/var/log/nginx" ]; then + find /var/log/nginx -maxdepth 1 -type f -mtime -30 2>/dev/null | \ + head -20 | while IFS= read -r logfile; do + [ -n "$logfile" ] && echo "LOG|nginx|$logfile|" >> "$SYSREF_DB" + done + fi + ;; + esac echo "" >> "$SYSREF_DB" } diff --git a/lib/user-manager.sh b/lib/user-manager.sh index a255d99..4f375a9 100755 --- a/lib/user-manager.sh +++ b/lib/user-manager.sh @@ -251,7 +251,8 @@ get_user_domains() { get_interworx_user_domains "$username" ;; *) - echo "" + # Standalone server - try to find domains + get_standalone_user_domains "$username" ;; esac } @@ -313,6 +314,37 @@ get_interworx_user_domains() { fi } +get_standalone_user_domains() { + [ -z "$1" ] && return 1 + local username="$1" + local home_dir="/home/${username}" + + # Only process if home directory exists + [ ! -d "$home_dir" ] && return 0 + + # Method 1: Parse Apache VirtualHost configs for ServerName matching user + if [ -d "/etc/apache2/sites-enabled" ]; then + grep -h "ServerName\|ServerAlias" /etc/apache2/sites-enabled/*.conf 2>/dev/null | \ + awk '{print $2}' | sort -u + return 0 + fi + + # Method 2: Parse RHEL-style Apache configs + if [ -d "/etc/httpd/conf.d" ]; then + grep -h "ServerName\|ServerAlias" /etc/httpd/conf.d/*.conf 2>/dev/null | \ + awk '{print $2}' | sort -u + return 0 + fi + + # Method 3: Check for domain directories in user's home (common structure: ~/domain.com/public_html) + if [ -d "$home_dir" ]; then + find "$home_dir" -maxdepth 2 -name "public_html" -o -name "html" 2>/dev/null | \ + sed "s|${home_dir}/||; s|/public_html$||; s|/html$||" | \ + grep -v "^$" | sort -u + return 0 + fi +} + ############################################################################# # USER DATABASES #############################################################################