Initial commit: Server Management Toolkit v2.0

- Complete security menu restructure (3-mode: Analysis/Actions/Live)
- Intelligent cPHulk enablement with CSF whitelist import
- Live network security monitoring dashboard
- Multi-source threat detection and classification
- 50+ organized security tools across 4-level menu hierarchy
- System health diagnostics with cPanel/WHM integration
- Reference database for cross-module intelligence sharing
This commit is contained in:
cschantz
2025-11-03 18:21:40 -05:00
commit a51d968185
39 changed files with 15258 additions and 0 deletions
+138
View File
@@ -0,0 +1,138 @@
#!/bin/bash
#############################################################################
# Server Toolkit - Diagnostic Report Generator
# Collects system info for troubleshooting
#############################################################################
OUTPUT_FILE="/tmp/toolkit-diagnostic-$(date +%Y%m%d_%H%M%S).txt"
echo "Generating diagnostic report..."
echo "This may take a moment..."
echo ""
{
echo "========================================================================="
echo "SERVER TOOLKIT DIAGNOSTIC REPORT"
echo "Generated: $(date)"
echo "========================================================================="
echo ""
echo "--- BASIC SYSTEM INFO ---"
echo "Hostname: $(hostname)"
echo "Kernel: $(uname -r)"
echo "OS: $(cat /etc/os-release 2>/dev/null | grep "PRETTY_NAME" | cut -d= -f2 | tr -d '"')"
echo "Uptime: $(uptime -p)"
echo ""
echo "--- TOOLKIT INSTALLATION ---"
echo "Toolkit directory: /root/server-toolkit"
echo "Directory exists: $([ -d /root/server-toolkit ] && echo "YES" || echo "NO")"
echo ""
echo "Library files:"
ls -lh /root/server-toolkit/lib/*.sh 2>/dev/null || echo " ERROR: Library files not found!"
echo ""
echo "--- CONTROL PANEL DETECTION ---"
if [ -f "/usr/local/cpanel/version" ]; then
echo "Control Panel: cPanel"
echo "Version: $(cat /usr/local/cpanel/version)"
elif [ -f "/usr/local/psa/version" ]; then
echo "Control Panel: Plesk"
echo "Version: $(cat /usr/local/psa/version | head -1)"
elif [ -d "/usr/local/interworx" ]; then
echo "Control Panel: InterWorx"
else
echo "Control Panel: None (Standalone)"
fi
echo ""
echo "--- ENVIRONMENT VARIABLES ---"
echo "SYS_* variables currently set:"
env | grep "^SYS_" | sort || echo " None found"
echo ""
echo "TOOLKIT_* variables:"
env | grep "^TOOLKIT_" | sort || echo " None found"
echo ""
echo "--- TEST: DOMAIN DETECTION ---"
if [ -f "/root/server-toolkit/test-domain-detection.sh" ]; then
bash /root/server-toolkit/test-domain-detection.sh 2>&1
else
echo " ERROR: test-domain-detection.sh not found!"
fi
echo ""
echo "--- USER/DOMAIN FILES ---"
echo "cPanel user files:"
echo " /var/cpanel/users/: $(ls /var/cpanel/users/ 2>/dev/null | wc -l) files"
echo " /etc/trueuserdomains: $([ -f /etc/trueuserdomains ] && wc -l < /etc/trueuserdomains || echo "NOT FOUND") lines"
echo " /etc/userdatadomains: $([ -f /etc/userdatadomains ] && wc -l < /etc/userdatadomains || echo "NOT FOUND") lines"
echo ""
echo "--- CACHE FILES ---"
echo "Reference database:"
ls -lh /root/server-toolkit/.sysref* 2>/dev/null || echo " No cache files"
echo ""
echo "Temp directories:"
ls -ld /tmp/server-toolkit-* 2>/dev/null || echo " No temp directories"
echo ""
echo "--- PROCESS INFO ---"
echo "Running launcher processes:"
ps aux | grep "[l]auncher.sh" || echo " None running"
echo ""
echo "--- LIBRARY SYNTAX CHECK ---"
for lib in /root/server-toolkit/lib/*.sh; do
if bash -n "$lib" 2>/dev/null; then
echo "$(basename "$lib") - syntax OK"
else
echo "$(basename "$lib") - SYNTAX ERROR!"
bash -n "$lib" 2>&1 | sed 's/^/ /'
fi
done
echo ""
echo "--- DISK SPACE ---"
df -h / | tail -1
echo ""
echo "Log directory size:"
if [ -d "/var/log/apache2/domlogs" ]; then
du -sh /var/log/apache2/domlogs 2>/dev/null
elif [ -d "/usr/local/apache/domlogs" ]; then
du -sh /usr/local/apache/domlogs 2>/dev/null
else
echo " Log directory not found"
fi
echo ""
echo "--- CSF/FIREWALL STATUS ---"
if command -v csf >/dev/null 2>&1; then
echo "CSF installed: YES"
echo "Version: $(csf -v 2>/dev/null | head -1)"
else
echo "CSF installed: NO"
fi
echo ""
echo "--- RECENT ERRORS (if any) ---"
echo "Checking for common error patterns in toolkit logs..."
grep -i "error\|fail\|no such file" /tmp/bot_analysis_*.txt 2>/dev/null | tail -10 || echo " No recent errors found"
echo ""
echo "========================================================================="
echo "END OF DIAGNOSTIC REPORT"
echo "========================================================================="
echo ""
echo "If sharing this report, review it first to remove any sensitive info!"
} > "$OUTPUT_FILE" 2>&1
echo "Diagnostic report saved to: $OUTPUT_FILE"
echo ""
echo "To view:"
echo " cat $OUTPUT_FILE"
echo ""
echo "To share:"
echo " cat $OUTPUT_FILE | less"
+85
View File
@@ -0,0 +1,85 @@
#!/bin/bash
# Test Cross-Module Intelligence
# Demonstrates how modules can reference session data
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
source "$SCRIPT_DIR/lib/common-functions.sh"
source "$SCRIPT_DIR/lib/reference-db.sh"
print_banner "Cross-Module Intelligence Test"
if [ ! -f "$SYSREF_DB" ]; then
print_error "Reference database not found. Run System Health Check first!"
exit 1
fi
print_section "Testing Health Metric Queries"
# Test individual metrics
echo "Memory Usage: $(db_get_health_metric 'MEMORY_USED_PERCENT')%"
echo "CPU Load: $(db_get_health_metric 'CPU_LOAD_1MIN')"
echo "Disk Usage: $(db_get_health_metric 'DISK_USED_PERCENT')%"
echo "Network Interface: $(db_get_health_metric 'NETWORK_INTERFACE')"
echo "Network MTU: $(db_get_health_metric 'NETWORK_MTU')"
echo "TCP Retransmission: $(db_get_health_metric 'TCP_RETRANS_PERCENT')%"
echo "SMART Status: $(db_get_health_metric 'DISK_SMART_STATUS')"
echo "SSH Attacks Today: $(db_get_health_metric 'SSH_ATTACKS_TODAY')"
echo "cPHulk Status: $(db_get_health_metric 'CPHULK_STATUS')"
print_section "Testing Intelligence Functions"
# Test system load check
if db_is_system_under_load; then
print_warning "System is currently under HIGH LOAD"
echo " CPU Load: $(db_get_health_metric 'CPU_LOAD_1MIN') (cores: $(db_get_health_metric 'CPU_CORES'))"
echo " Memory: $(db_get_health_metric 'MEMORY_USED_PERCENT')%"
else
print_success "System load is NORMAL"
fi
# Test network issues check
if db_has_network_issues; then
print_warning "Network issues DETECTED"
echo " TCP Retransmission: $(db_get_health_metric 'TCP_RETRANS_PERCENT')%"
echo " RX Errors: $(db_get_health_metric 'NETWORK_RX_ERRORS')"
echo " TX Errors: $(db_get_health_metric 'NETWORK_TX_ERRORS')"
else
print_success "Network is HEALTHY"
fi
# Test attack detection
if db_is_under_attack; then
print_critical "System appears to be UNDER ATTACK"
echo " Failed SSH attempts today: $(db_get_health_metric 'SSH_ATTACKS_TODAY')"
echo " Total failed attempts: $(db_get_health_metric 'SSH_FAILED_ATTEMPTS_TOTAL')"
else
print_success "No active attacks detected"
fi
print_section "Cross-Module Intelligence Examples"
echo "Example 1: Bot Analyzer can check if network is already problematic"
echo " if db_has_network_issues; then"
echo " # Adjust recommendations - network may be causing bot issues"
echo " fi"
echo ""
echo "Example 2: MySQL Analyzer can check if system is under load"
echo " if db_is_system_under_load; then"
echo " # Slow queries might be due to overall system load, not just MySQL"
echo " fi"
echo ""
echo "Example 3: Any module can check attack status"
echo " if db_is_under_attack; then"
echo " # Correlate findings with ongoing attacks"
echo " fi"
print_section "All Health Metrics"
echo "Total health metrics stored: $(grep -c '^HEALTH|' "$SYSREF_DB")"
echo ""
echo "Sample (first 10):"
db_get_all_health | head -10
print_success "Cross-module intelligence test complete!"
+73
View File
@@ -0,0 +1,73 @@
#!/bin/bash
# Quick test script to validate domain detection is working
# Returns exit code 0 if working, 1 if broken
echo "========================================"
echo "Domain Detection Test"
echo "========================================"
echo ""
# Source libraries
SCRIPT_DIR="/root/server-toolkit"
source "$SCRIPT_DIR/lib/common-functions.sh"
source "$SCRIPT_DIR/lib/system-detect.sh"
source "$SCRIPT_DIR/lib/user-manager.sh"
echo "Step 1: Check system detection variables"
echo " SYS_CONTROL_PANEL: [$SYS_CONTROL_PANEL]"
echo " SYS_DETECTION_COMPLETE: [$SYS_DETECTION_COMPLETE]"
if [ -z "$SYS_CONTROL_PANEL" ]; then
echo " ❌ FAIL: SYS_CONTROL_PANEL is empty!"
exit 1
else
echo " ✓ PASS: SYS_CONTROL_PANEL is set"
fi
echo ""
echo "Step 2: Test get_user_domains function"
domains=$(get_user_domains "pickledperil")
echo " Domains for pickledperil: [$domains]"
if [ -z "$domains" ]; then
echo " ❌ FAIL: No domains returned!"
exit 1
else
echo " ✓ PASS: Domains found: $domains"
fi
echo ""
echo "Step 3: Test select_user_interactive caching"
# Just test the caching logic without user input
users=(pickledperil)
declare -A user_primary_domain
declare -A user_domain_count
for user in "${users[@]}"; do
local_domains=$(get_user_domains "$user" 2>/dev/null | grep -v "^$")
if [ -n "$local_domains" ]; then
user_domain_count["$user"]=$(echo "$local_domains" | wc -l)
user_primary_domain["$user"]=$(echo "$local_domains" | head -1)
else
user_domain_count["$user"]=0
user_primary_domain["$user"]="(no domains)"
fi
done
echo " Cached domain: ${user_primary_domain[pickledperil]}"
echo " Cached count: ${user_domain_count[pickledperil]}"
if [ "${user_primary_domain[pickledperil]}" = "(no domains)" ]; then
echo " ❌ FAIL: User shows as having no domains!"
exit 1
else
echo " ✓ PASS: User cache working correctly"
fi
echo ""
echo "========================================"
echo "✓ ALL TESTS PASSED!"
echo "Domain detection is working correctly."
echo "========================================"
exit 0