Add Plesk support and diagnostics to bot-analyzer

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)
This commit is contained in:
cschantz
2025-11-21 15:40:11 -05:00
parent c6300b8abe
commit 6256d9f2f4
+37 -7
View File
@@ -322,8 +322,11 @@ parse_logs() {
if [ "$INTERWORX_MODE" = "yes" ]; then if [ "$INTERWORX_MODE" = "yes" ]; then
# InterWorx: extract from path /home/user/var/domain.com/logs/transfer.log # InterWorx: extract from path /home/user/var/domain.com/logs/transfer.log
domain=$(echo "$logfile" | sed -n 's|^/home/.*/var/\([^/]*\)/logs/.*|\1|p') 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 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$//') domain=$(basename "$logfile" | sed 's/-ssl_log$//')
fi 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) 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 if [ "$log_count" -eq 0 ]; then
print_alert "Error: No log files found in $LOG_DIR" # Try without time filter to see if ANY logs exist
if [ -n "$HOURS_BACK" ]; then local total_logs=$(find "$LOG_DIR" -type f ! -name "*-bytes_log" ! -name "*.offset" ! -name "*error_log" 2>/dev/null | wc -l)
echo "No logs found from the last $HOURS_BACK hours"
elif [ -n "$DAYS_BACK" ]; then if [ "$total_logs" -eq 0 ]; then
echo "No logs found from the last $DAYS_BACK days" 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 fi
exit 1
fi fi
print_info "Found $log_count log files to analyze" print_info "Found $log_count log files to analyze"