From 209ded13fc2bb708b87011a0ee59e26d7402e585 Mon Sep 17 00:00:00 2001 From: cschantz Date: Fri, 21 Nov 2025 15:40:11 -0500 Subject: [PATCH] Add Plesk support and diagnostics to bot-analyzer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ISSUES FOUND: 1. cPanel/Plesk had same "no logs found" issue as InterWorx - No diagnostic output - No fallback to analyze all logs 2. Plesk domain extraction missing - Used cPanel filename extraction for all non-InterWorx - Plesk has different path structure PLESK LOG STRUCTURE: - Logs at: /var/www/vhosts/system/domain.com/logs/ - Files: access_log, access_ssl_log, error_log - Domain in PATH (like InterWorx), not filename (like cPanel) FIXES APPLIED: 1. Enhanced Log Detection for cPanel/Plesk (lines 1869-1906): - Check for ANY logs first (without time filter) - If zero: Show diagnostics (directory, file count, samples, control panel) - If some exist: Offer to analyze all logs - Same pattern as InterWorx fix (commit 87e0ff7) 2. Added Plesk Domain Extraction (lines 325-331): - Detect Plesk via $SYS_CONTROL_PANEL - Extract domain from path: /var/www/vhosts/system/[domain]/logs/ - Uses sed pattern: 's|^/var/www/vhosts/system/\([^/]*\)/logs/.*|\1|p' - Falls back to cPanel method for other panels LOGIC FLOW: ``` if InterWorx: domain from /home/user/var/[domain]/logs/ elif Plesk: domain from /var/www/vhosts/system/[domain]/logs/ else (cPanel/other): domain from filename ``` TESTING: ✅ Syntax validation passed ✅ Handles all three panel types correctly ✅ Provides helpful diagnostics when logs not found IMPACT: - Plesk servers can now use bot-analyzer properly - Domain extraction works for Plesk log structure - Better error messages for troubleshooting - Consistent UX across all panel types Related: commit 87e0ff7 (fixed InterWorx) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- modules/security/bot-analyzer.sh | 44 +++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/modules/security/bot-analyzer.sh b/modules/security/bot-analyzer.sh index bfc1153..d011c54 100755 --- a/modules/security/bot-analyzer.sh +++ b/modules/security/bot-analyzer.sh @@ -322,8 +322,11 @@ parse_logs() { if [ "$INTERWORX_MODE" = "yes" ]; then # InterWorx: extract from path /home/user/var/domain.com/logs/transfer.log domain=$(echo "$logfile" | sed -n 's|^/home/.*/var/\([^/]*\)/logs/.*|\1|p') + elif [ "$SYS_CONTROL_PANEL" = "plesk" ]; then + # Plesk: extract from path /var/www/vhosts/system/domain.com/logs/access_log + domain=$(echo "$logfile" | sed -n 's|^/var/www/vhosts/system/\([^/]*\)/logs/.*|\1|p') else - # cPanel: extract from filename + # cPanel: extract from filename /var/log/apache2/domlogs/domain.com or domain.com-ssl_log domain=$(basename "$logfile" | sed 's/-ssl_log$//') fi @@ -1867,13 +1870,40 @@ main() { log_count=$(find "$LOG_DIR" -type f ! -name "*-bytes_log" ! -name "*.offset" ! -name "*error_log" "${find_opts[@]}" 2>/dev/null | wc -l) if [ "$log_count" -eq 0 ]; then - print_alert "Error: No log files found in $LOG_DIR" - if [ -n "$HOURS_BACK" ]; then - echo "No logs found from the last $HOURS_BACK hours" - elif [ -n "$DAYS_BACK" ]; then - echo "No logs found from the last $DAYS_BACK days" + # Try without time filter to see if ANY logs exist + local total_logs=$(find "$LOG_DIR" -type f ! -name "*-bytes_log" ! -name "*.offset" ! -name "*error_log" 2>/dev/null | wc -l) + + if [ "$total_logs" -eq 0 ]; then + print_alert "Error: No log files found in $LOG_DIR" + echo "" + echo "Diagnostic information:" + echo " Log directory: $LOG_DIR" + echo " Directory exists: $([ -d "$LOG_DIR" ] && echo "yes" || echo "no")" + if [ -d "$LOG_DIR" ]; then + echo " Total files in directory: $(find "$LOG_DIR" -type f 2>/dev/null | wc -l)" + echo " Sample files:" + find "$LOG_DIR" -type f 2>/dev/null | head -5 | sed 's/^/ /' + fi + echo "" + echo "Control panel: $SYS_CONTROL_PANEL" + exit 1 + else + print_alert "No logs found matching time filter" + if [ -n "$HOURS_BACK" ]; then + echo "No logs found from the last $HOURS_BACK hours" + elif [ -n "$DAYS_BACK" ]; then + echo "No logs found from the last $DAYS_BACK days" + fi + echo "Total logs available: $total_logs" + echo "" + read -p "Analyze all available logs instead? [y/N]: " choice + if [[ "$choice" =~ ^[Yy] ]]; then + log_count=$total_logs + find_opts=() # Clear time filter + else + exit 0 + fi fi - exit 1 fi print_info "Found $log_count log files to analyze"