diff --git a/v-system-report b/v-system-report index 0f1f3bf7d..720260bdf 100644 --- a/v-system-report +++ b/v-system-report @@ -27,9 +27,9 @@ SEND_EMAIL_REPORT=true # Set to true to enable email notifications EMAIL_SUBJECT="MyVestaCP System Report - $(date '+%Y-%m-%d')" # Default email subject with date # AI Integration Configuration -AI_ENABLED=false # Set to true to enable AI analysis +AI_ENABLED=true # Set to true to enable AI analysis AI_MODE="auto" # Set to "auto" (default), "always", or "never" -AI_API_KEY="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" # Your HuggingFace API key +AI_API_KEY="" # Your HuggingFace API key AI_MODEL="mistralai/Mixtral-8x7B-Instruct-v0.1" # Updated to Mixtral model AI_MAX_LENGTH=1000 # Maximum length of the response @@ -532,8 +532,19 @@ The following is the comprehensive system status report to analyze:\n\n" return 1 fi - # Store the analysis for later use in both console and email - ai_analysis="$generated_text" + # Clean the AI response from any ANSI codes and unwanted characters + local clean_generated_text=$(echo "$generated_text" | \ + sed -r 's/\x1B\[[0-9;]*[mGK]//g' | \ + sed 's/\\033\[[0-9;]*m//g' | \ + sed 's/\[0;[0-9]*m//g' | \ + sed 's/\[1;[0-9]*m//g' | \ + sed 's/33\[[0-9;]*m//g' | \ + sed 's/[0-9]*\[[0-9;]*m//g' | \ + tr -d '\0' | \ + sed '/^$/d') + + # Store the cleaned analysis for later use in both console and email + ai_analysis="$clean_generated_text" show_progress 4 4 echo -e "\n${GREEN}✓ AI Analysis completed successfully${NC}" @@ -543,7 +554,7 @@ The following is the comprehensive system status report to analyze:\n\n" echo -e "${YELLOW}The following recommendations are based on the system status analysis:${NC}\n" # Format and display the analysis with better readability - local formatted_analysis=$(echo "$generated_text" | sed 's/^1\. Critical Issues (if any):/\n1\. Critical Issues:/' | \ + local formatted_analysis=$(echo "$clean_generated_text" | sed 's/^1\. Critical Issues (if any):/\n1\. Critical Issues:/' | \ sed 's/^2\. Medium Issues (if any):/\n2\. Medium Issues:/' | \ sed 's/^3\. Low Issues (if any):/\n3\. Low Issues:/' | \ sed 's/^- /\n • /g') @@ -1127,9 +1138,9 @@ check_email_status() { ((current_medium_issues++)) # Too many timeouts fi - # Low issues (minor problems) - if [ "${auth_failures_log:-0}" -gt 500 ]; then - ((current_low_issues++)) # Excessive auth failures might indicate brute force + # Low issues (minor problems) - only flag if extremely excessive + if [ "${auth_failures_log:-0}" -gt 10000 ]; then + ((current_low_issues++)) # Extremely excessive auth failures (>10k/day) might indicate unusual activity fi # Display statistics based on log analysis @@ -1179,12 +1190,10 @@ check_email_status() { ((current_medium_issues++)) # Not finding the email log is a medium problem fi - # Add local issues to global counters (only add 1 for low_issues if there are auth failures) + # Add local issues to global counters ((high_issues+=current_high_issues)) ((medium_issues+=current_medium_issues)) - if [ "${auth_failures_log:-0}" -gt 0 ]; then - ((low_issues++)) - fi + ((low_issues+=current_low_issues)) # Track which modules have issues and capture detailed info for AI analysis local email_details="" @@ -1229,8 +1238,8 @@ check_email_status() { if [ "${deferred:-0}" -gt 0 ] && [ "${deferred:-0}" -le 20 ]; then email_details+="$deferred deferred messages in queue (normal delays), " fi - if [ "${auth_failures_log:-0}" -gt 500 ]; then - email_details+="Excessive authentication failures (${auth_failures_log:-0} today) - possible brute force attempts" + if [ "${auth_failures_log:-0}" -gt 10000 ]; then + email_details+="Extremely high authentication failures (${auth_failures_log:-0} today) - unusual brute force activity" else email_details+="Minor configuration or performance issues" fi @@ -2791,6 +2800,16 @@ check_fail2ban_status() { echo -e " Total Attempts: ${YELLOW}$total_attempts${NC}" echo -e " Total Bans: ${RED}$total_bans${NC}" echo -e " Total Unbans: ${GREEN}$total_unbans${NC}" + + # Classify based on total attempts volume + if [ "$total_attempts" -gt 50000 ]; then + ((current_high_issues++)) # >50k attempts = HIGH (massive coordinated attack) + elif [ "$total_attempts" -gt 20000 ]; then + ((current_medium_issues++)) # 20k-50k attempts = MEDIUM (significant attack) + elif [ "$total_attempts" -gt 10000 ]; then + ((current_low_issues++)) # 10k-20k attempts = LOW (elevated activity) + fi + # 0-10k attempts = Normal (typical bot activity) else echo -e "${YELLOW}⚠️ No relevant entries found in Fail2Ban log for today.${NC}" ((current_medium_issues++)) @@ -2813,10 +2832,21 @@ check_fail2ban_status() { local fail2ban_details="" if [ $current_high_issues -gt 0 ]; then critical_modules_found+=("Fail2Ban") - fail2ban_details="Critical: Fail2Ban service not running - Security monitoring disabled" + if [ "$total_attempts" -gt 50000 ]; then + fail2ban_details="Critical: Massive coordinated attack detected - $total_attempts attempts today (>50k threshold). Fail2Ban is working but system under heavy attack." + else + fail2ban_details="Critical: Fail2Ban service not running - Security monitoring disabled" + fi elif [ $current_medium_issues -gt 0 ]; then medium_modules_found+=("Fail2Ban") - fail2ban_details="Medium issues: Problems reading Fail2Ban logs or configuration" + if [ "$total_attempts" -gt 20000 ]; then + fail2ban_details="Medium: Significant attack activity - $total_attempts attempts today (20k-50k threshold). Fail2Ban is blocking but elevated monitoring recommended." + else + fail2ban_details="Medium issues: Problems reading Fail2Ban logs or configuration" + fi + elif [ $current_low_issues -gt 0 ]; then + low_modules_found+=("Fail2Ban") + fail2ban_details="Low: Elevated attack activity - $total_attempts attempts today (10k-20k threshold). Fail2Ban is handling it but worth monitoring." else fail2ban_details="Fail2Ban functioning normally: $total_attempts total attempts, $total_bans bans, $total_unbans unbans today. MyVestaCP Panel: $myvesta_failed failed logins, $myvesta_bans bans" fi @@ -3323,20 +3353,87 @@ send_email_report() { if [ -n "$clean_ai_analysis" ]; then email_content+="