#!/bin/bash ############################################################################# # Server Management Toolkit - BETA/DEV Version # Version: 2.1-beta # # Development and testing version - SEPARATE FROM PRODUCTION # Uses independent cache, config, and data directories ############################################################################# set -eo pipefail # Check if running in interactive mode if [[ $- != *i* ]]; then # Non-interactive mode - set flag for read operations INTERACTIVE_MODE=0 else INTERACTIVE_MODE=1 fi # Configuration SUITE_VERSION="2.1.0-BETA" BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" MODULES_DIR="$BASE_DIR/modules" LIB_DIR="$BASE_DIR/lib" CONFIG_DIR="$BASE_DIR/config" # Load core libraries source "$LIB_DIR/common-functions.sh" || { echo "ERROR: Failed to load common-functions.sh"; return 1; } source "$LIB_DIR/system-detect.sh" || { echo "ERROR: Failed to load system-detect.sh"; return 1; } source "$LIB_DIR/domain-discovery.sh" || { echo "ERROR: Failed to load domain-discovery.sh"; return 1; } source "$LIB_DIR/user-manager.sh" || { echo "ERROR: Failed to load user-manager.sh"; return 1; } source "$LIB_DIR/reference-db.sh" || { echo "ERROR: Failed to load reference-db.sh"; return 1; } # Safe read helper function - handles both interactive and non-interactive modes safe_read_choice() { if [ "$INTERACTIVE_MODE" -eq 0 ]; then # Non-interactive: return 1 to indicate read failed return 1 fi if ! read -r choice /dev/null; then return 1 fi } # Color codes RED='\033[0;31m' YELLOW='\033[1;33m' GREEN='\033[0;32m' BLUE='\033[0;34m' CYAN='\033[0;36m' MAGENTA='\033[0;35m' BOLD='\033[1m' NC='\033[0m' # Banner show_banner() { clear echo "═══════════════════════════════════════════════════════════════" echo " ⚠️ Server Management Toolkit v${SUITE_VERSION}" echo " 🧪 BETA/DEV VERSION - Testing & Development" echo " Complete cPanel/Linux Server Administration Suite" echo "═══════════════════════════════════════════════════════════════" echo " ⚠️ This is a SEPARATE INSTANCE from production" echo "" } # Run a module run_module() { local category="$1" local module="$2" shift 2 if [ ! -f "$MODULES_DIR/$category/$module" ]; then echo "" echo -e "✗ Module not found: $category/$module" echo "" if ! read -p "Press Enter to continue..." /dev/null; then true # Continue even if read fails fi return 1 fi echo "" echo -e "Launching: $category/$module" echo -e "──────────────────────────────────────────────────────────────" # Run module directly - keep SYS_ variables cached for performance # Modules will use cached detection instead of re-detecting on every run "$MODULES_DIR/$category/$module" "$@" local exit_code=$? echo "" echo -e "──────────────────────────────────────────────────────────────" if [ "${exit_code:-0}" -eq 0 ]; then echo -e "✓ Completed successfully" else echo -e "✗ Exited with code: $exit_code" fi echo "" if ! read -p "Press Enter to continue..." /dev/null; then true # Continue even if read fails fi } ############################################################################# # SYSTEM INFO DISPLAY (Quick View) ############################################################################# show_system_overview() { # Only show if detection is complete if [ -z "${SYS_DETECTION_COMPLETE:-}" ]; then return fi echo "" echo "🖥️ System Information:" # Control Panel if [ "$SYS_CONTROL_PANEL" != "none" ]; then echo -n " Control Panel: ${SYS_CONTROL_PANEL^^}" [ -n "$SYS_CONTROL_PANEL_VERSION" ] && echo -n " v${SYS_CONTROL_PANEL_VERSION}" || echo -n " (version unknown)" echo "" else echo " Control Panel: Standalone (no control panel)" fi # OS echo " OS: ${SYS_OS_TYPE^^} ${SYS_OS_VERSION}" [ "${SYS_CLOUDLINUX:-}" = "yes" ] && echo " ➜ CloudLinux detected" # Web Server echo -n " Web Server: ${SYS_WEB_SERVER^^}" [ -n "$SYS_WEB_SERVER_VERSION" ] && echo " v${SYS_WEB_SERVER_VERSION}" || echo "" # Database if [ "$SYS_DB_TYPE" != "none" ]; then echo -n " Database: ${SYS_DB_TYPE^^}" [ -n "$SYS_DB_VERSION" ] && echo " v${SYS_DB_VERSION}" || echo "" fi # PHP Versions if [ ${#SYS_PHP_VERSIONS[@]} -gt 0 ]; then echo -n " PHP Versions: " local php_list=$(printf '%s, ' "${SYS_PHP_VERSIONS[@]}") echo "${php_list%, }" fi # Firewall if [ "$SYS_FIREWALL" != "none" ]; then echo -n " Firewall: ${SYS_FIREWALL^^}" [ "$SYS_FIREWALL_ACTIVE" = "yes" ] && echo " (active)" || echo " (inactive)" fi # Cloudflare [ "$SYS_CLOUDFLARE_ACTIVE" = "yes" ] && echo " Cloudflare: Detected" echo "" } ############################################################################# # MAIN MENU ############################################################################# show_main_menu() { show_banner # Show quick system overview if detection is complete [ -n "${SYS_DETECTION_COMPLETE:-}" ] && show_system_overview echo "Quick Diagnostics:" echo "" echo " 1) 🏥 System Health Check - Full server diagnostics" echo "" echo "Main Categories:" echo "" echo " 2) 🛡️ Security & Monitoring" echo " 3) 🌐 Website Diagnostics" echo " 4) 🔧 Performance & Maintenance" echo " 5) 💾 Backup & Recovery" echo " 6) 📧 Email Troubleshooting" echo "" echo "System:" echo "" echo " 7) 🗑️ Cleanup Toolkit Data - Clear cached data" echo "" echo " 0) Exit" echo "" echo "═══════════════════════════════════════════════════════════════" echo -n "Select option: " } ############################################################################# # SECURITY & MONITORING ############################################################################# ############################################################################# # SECURITY SUB-MENUS ############################################################################# # Threat Analysis Sub-Menu show_threat_analysis_menu() { show_banner echo -e "📊 Threat Analysis" echo "" echo -e " 1) 🤖 Bot & Traffic Analyzer - Full analysis (all logs)" echo -e " 2) 🤖 Quick Scan (1 hour) - Recent activity only" echo -e " 3) 📊 IP Reputation Manager - Query/manage IP database" echo -e " 4) 🔐 Suspicious Login Monitor - SSH/Panel login analysis" echo -e " 5) 🦠 Malware Scanner - ImunifyAV, ClamAV, Maldet" echo -e " 6) 🛡️ Historical Attack Analysis - Scan past logs (ET Open)" echo "" echo -e " 0) Back to Security Menu" echo "" echo -e "──────────────────────────────────────────────────────────────" echo -n "Select option: " } handle_threat_analysis_menu() { if [ "$INTERACTIVE_MODE" -eq 0 ]; then return 0 # Non-interactive mode, exit fi while true; do show_threat_analysis_menu if ! read -r choice /dev/null; then return 0 # Exit if read fails fi case "$choice" in 1) run_module "security" "bot-analyzer.sh" ;; 2) run_module "security" "bot-analyzer.sh" -H 1 ;; 3) run_module "security" "ip-reputation-manager.sh" ;; 4) run_module "security" "suspicious-login-monitor.sh" ;; 5) run_module "security" "malware-scanner.sh" ;; 6) bash "$BASE_DIR/tools/analyze-historical-attacks.sh" ;; 0) return ;; *) echo -e "Invalid option"; sleep 1 ;; esac done } # Live Monitoring Sub-Menu show_live_monitoring_menu() { show_banner echo -e "🔴 Live Monitoring" echo "" echo -e " 1) 📡 Live Attack Monitor - Unified threat intelligence" echo -e " 2) 🔐 SSH Attack Monitor - SSH brute force detection" echo -e " 3) 🌐 Web Traffic Monitor - HTTP attack detection" echo -e " 4) 🔥 Firewall Activity Monitor - CSF/iptables monitoring" echo "" echo -e " 0) Back to Security Menu" echo "" echo -e "──────────────────────────────────────────────────────────────" echo -n "Select option: " } handle_live_monitoring_menu() { if [ "$INTERACTIVE_MODE" -eq 0 ]; then return 0 # Non-interactive mode, exit fi while true; do show_live_monitoring_menu if ! read -r choice /dev/null; then return 0 # Exit if read fails fi case "$choice" in 1) run_module "security" "live-attack-monitor.sh" ;; 2) run_module "security" "ssh-attack-monitor.sh" ;; 3) run_module "security" "web-traffic-monitor.sh" ;; 4) run_module "security" "firewall-activity-monitor.sh" ;; 0) return ;; *) echo -e "Invalid option"; sleep 1 ;; esac done } # Log Viewers Sub-Menu show_log_viewers_menu() { show_banner echo -e "📋 Log Viewers" echo "" echo -e " 1) 🌐 Apache Access Log - Live web access" echo -e " 2) ❌ Apache Error Log - Live web errors" echo -e " 3) 📧 Mail Log - Live email activity" echo -e " 4) 🔐 Security Log - Live auth attempts" echo "" echo -e " 0) Back to Security Menu" echo "" echo -e "──────────────────────────────────────────────────────────────" echo -n "Select option: " } handle_log_viewers_menu() { if [ "$INTERACTIVE_MODE" -eq 0 ]; then return 0 # Non-interactive mode, exit fi while true; do show_log_viewers_menu if ! read -r choice /dev/null; then return 0 # Exit if read fails fi case "$choice" in 1) run_module "security" "tail-apache-access.sh" ;; 2) run_module "security" "tail-apache-error.sh" ;; 3) run_module "security" "tail-mail-log.sh" ;; 4) run_module "security" "tail-secure-log.sh" ;; 0) return ;; *) echo -e "Invalid option"; sleep 1 ;; esac done } # Security Actions Sub-Menu show_security_actions_menu() { show_banner echo -e "🔒 Security Actions" echo "" echo -e " 1) 🔒 Enable cPHulk Protection - Brute force protection" echo -e " 2) ⚙️ Optimize CT_LIMIT - Connection tracking tuning" echo -e " 3) 🤖 Block Malicious Bots - User-Agent blocking (Apache)" echo "" echo -e " 0) Back to Security Menu" echo "" echo -e "──────────────────────────────────────────────────────────────" echo -n "Select option: " } handle_security_actions_menu() { if [ "$INTERACTIVE_MODE" -eq 0 ]; then return 0 # Non-interactive mode, exit fi while true; do show_security_actions_menu if ! read -r choice /dev/null; then return 0 # Exit if read fails fi case "$choice" in 1) run_module "security" "enable-cphulk.sh" ;; 2) run_module "security" "optimize-ct-limit.sh" ;; 3) run_module "security" "bot-blocker.sh" ;; 0) return ;; *) echo -e "Invalid option"; sleep 1 ;; esac done } ############################################################################# # MAIN SECURITY MENU ############################################################################# show_security_menu() { show_banner echo -e "🛡️ Security & Monitoring" echo "" echo -e " 1) 📊 Threat Analysis → Analyze threats & reputation" echo -e " 2) 🔴 Live Monitoring → Real-time attack detection" echo -e " 3) 📋 Log Viewers → Tail system/security logs" echo -e " 4) 🔒 Security Actions → Hardening & protection" echo "" echo -e " 0) Back to Main Menu" echo "" echo -e "──────────────────────────────────────────────────────────────" echo -n "Select option: " } handle_security_menu() { if [ "$INTERACTIVE_MODE" -eq 0 ]; then return 0 # Non-interactive mode, exit fi while true; do show_security_menu if ! read -r choice /dev/null; then return 0 # Exit if read fails fi case "$choice" in 1) handle_threat_analysis_menu ;; 2) handle_live_monitoring_menu ;; 3) handle_log_viewers_menu ;; 4) handle_security_actions_menu ;; 0) return ;; *) echo -e "Invalid option"; sleep 1 ;; esac done } ############################################################################# # WEBSITE DIAGNOSTICS ############################################################################# show_website_menu() { show_banner echo -e "🌐 Website Diagnostics" echo "" echo -e "Error Analysis:" echo "" echo -e " 1) 🔍 Website Error Analyzer - Find 500/config errors (filters bots)" echo -e " 2) 🔥 Fast 500 Error Tracker - ONLY 500s + root cause diagnosis" echo "" echo -e "Performance & Slowness:" echo "" echo -e " 3) 🐢 Website Slowness Diagnostics - Multi-framework analysis" echo " └─ WordPress, Drupal, Joomla, Magento, Laravel, Node.js, etc." echo "" echo -e "WordPress Management:" echo "" echo -e " 4) 📦 WordPress Tools → WP-Cron manager & more tools" echo "" echo -e "Domain Analysis:" echo "" echo -e " 5) 🔶 Cloudflare Detector - Which domains use Cloudflare + location" echo "" echo -e " 0) Back to Main Menu" echo "" echo -e "──────────────────────────────────────────────────────────────" echo -n "Select option: " } handle_website_menu() { if [ "$INTERACTIVE_MODE" -eq 0 ]; then return 0 # Non-interactive mode, exit fi while true; do show_website_menu if ! read -r choice /dev/null; then return 0 # Exit if read fails fi case "$choice" in 1) run_module "website" "website-error-analyzer.sh" ;; 2) run_module "website" "500-error-tracker.sh" ;; 3) run_module "website" "website-slowness-diagnostics.sh" ;; 4) bash "$MODULES_DIR/website/wordpress-menu.sh" ;; 5) run_module "website" "cloudflare-detector.sh" ;; 0) return ;; *) echo -e "Invalid option"; sleep 1 ;; esac done } ############################################################################# # PERFORMANCE ANALYSIS ############################################################################# show_performance_menu() { show_banner echo -e "🔧 Performance & Maintenance" echo "" echo -e "Database:" echo "" echo -e " 1) 🗄️ MySQL Query Analyzer - Find slow queries & optimize" echo "" echo -e "Network & Resources:" echo "" echo -e " 2) 🌐 Network & Bandwidth - Traffic & top consumers" echo -e " 3) 💻 Hardware Health Check - SMART, memory, CPU sensors" echo "" echo -e "PHP Optimization:" echo "" echo -e " 4) ⚙️ PHP Configuration Optimizer - Per-domain PHP tuning" echo "" echo -e "System Health:" echo "" echo -e " 5) 📊 Loadwatch Health Analyzer - Historical system analysis" echo -e " 6) 💿 Disk Space Analyzer - Find space issues & cleanup files" echo "" echo -e "Caching Solutions:" echo "" echo -e " 7) ⚡ Nginx + Varnish Manager - Setup/manage caching stack" echo "" echo -e " 0) Back to Main Menu" echo "" echo -e "──────────────────────────────────────────────────────────────" echo -n "Select option: " } handle_performance_menu() { if [ "$INTERACTIVE_MODE" -eq 0 ]; then return 0 # Non-interactive mode, exit fi while true; do show_performance_menu if ! read -r choice /dev/null; then return 0 # Exit if read fails fi case "$choice" in 1) run_module "performance" "mysql-query-analyzer.sh" ;; 2) run_module "performance" "network-bandwidth-analyzer.sh" ;; 3) run_module "performance" "hardware-health-check.sh" ;; 4) run_module "performance" "php-optimizer.sh" ;; 5) handle_loadwatch_analyzer ;; 6) run_module "maintenance" "disk-space-analyzer.sh" ;; 7) run_module "performance" "nginx-varnish-manager.sh" ;; 0) return ;; *) echo -e "Invalid option"; sleep 1 ;; esac done } handle_loadwatch_analyzer() { if [ "$INTERACTIVE_MODE" -eq 0 ]; then return 0 # Non-interactive mode, exit fi show_banner echo -e "📊 Loadwatch Health Analyzer" echo "" echo -e "Select time range for analysis:" echo "" echo -e " 1) Last 1 Hour - Recent activity" echo -e " 2) Last 6 Hours - Mid-term trending" echo -e " 3) Last 24 Hours - Full day analysis" echo -e " 4) Last 7 Days - Weekly patterns" echo -e " 5) Last 30 Days - Monthly overview" echo "" echo -e " 0) Back" echo "" echo -e "──────────────────────────────────────────────────────────────" echo -n "Select time range: " if ! read -r range_choice /dev/null; then return 0 # Exit if read fails fi case "$range_choice" in 1) run_module "diagnostics" "loadwatch-analyzer.sh" "-r" "1h" ;; 2) run_module "diagnostics" "loadwatch-analyzer.sh" "-r" "6h" ;; 3) run_module "diagnostics" "loadwatch-analyzer.sh" "-r" "24h" ;; 4) run_module "diagnostics" "loadwatch-analyzer.sh" "-r" "7d" ;; 5) run_module "diagnostics" "loadwatch-analyzer.sh" "-r" "30d" ;; 0) return ;; *) echo -e "Invalid option"; sleep 1 ;; esac } ############################################################################# # BACKUP & RECOVERY ############################################################################# show_backup_menu() { show_banner echo -e "💾 Backup & Recovery" echo "" echo -e "Acronis Cyber Protect:" echo "" echo -e " 1) 🔷 Acronis Management → Complete backup management" echo "" echo -e "Database Tools:" echo "" echo -e " 2) 🔄 MySQL File Restore - Convert restored DB files to .sql" echo "" echo -e "Maintenance:" echo "" echo -e " 3) 🗑️ Cleanup Toolkit Data - Remove IP reputation & temp files" echo "" echo -e " 0) Back to Main Menu" echo "" echo -e "──────────────────────────────────────────────────────────────" echo -n "Select option: " } show_acronis_menu() { show_banner echo -e "🔷 Acronis Cyber Protect" echo "" echo -e "Installation & Setup:" echo "" echo -e " 1) Install Acronis Agent - Download and install" echo -e " 2) Register with Cloud - Connect to Acronis Cloud" echo -e " 3) Configure Agent - Adjust settings" echo "" echo -e "Backup Management:" echo "" echo -e " 4) 📊 Manage Backups - Complete backup interface" echo "" echo -e "Status & Monitoring:" echo "" echo -e " 5) Check Agent Status - Verify Acronis is running" echo -e " 6) View Logs - Check Acronis logs" echo -e " 7) Troubleshoot - Diagnose backup failures" echo "" echo -e "Maintenance:" echo "" echo -e " 8) Update Agent - Upgrade to latest version" echo -e " 9) Uninstall Acronis - Remove agent" echo "" echo -e " 0) Back to Backup Menu" echo "" echo -e "──────────────────────────────────────────────────────────────" echo -n "Select option: " } handle_backup_menu() { if [ "$INTERACTIVE_MODE" -eq 0 ]; then return 0 # Non-interactive mode, exit fi while true; do show_backup_menu if ! read -r choice /dev/null; then return 0 # Exit if read fails fi case "$choice" in 1) handle_acronis_menu ;; 2) run_module "backup" "mysql-restore-to-sql.sh" ;; 3) run_module "maintenance" "cleanup-toolkit-data.sh" ;; 0) return ;; *) echo -e "Invalid option"; sleep 1 ;; esac done } handle_acronis_menu() { if [ "$INTERACTIVE_MODE" -eq 0 ]; then return 0 # Non-interactive mode, exit fi while true; do show_acronis_menu if ! read -r choice /dev/null; then return 0 # Exit if read fails fi case "$choice" in 1) run_module "backup" "acronis-install.sh" ;; 2) run_module "backup" "acronis-register.sh" ;; 3) run_module "backup" "acronis-configure.sh" ;; 4) run_module "backup" "acronis-backup-manager.sh" ;; 5) run_module "backup" "acronis-agent-status.sh" ;; 6) run_module "backup" "acronis-logs.sh" ;; 7) run_module "backup" "acronis-troubleshoot.sh" ;; 8) run_module "backup" "acronis-update.sh" ;; 9) run_module "backup" "acronis-uninstall.sh" ;; 0) return ;; *) echo -e "Invalid option"; sleep 1 ;; esac done } ############################################################################# # EMAIL TROUBLESHOOTING & MAINTENANCE ############################################################################# show_email_menu() { show_banner echo -e "📧 Email Troubleshooting & Maintenance" echo "" echo -e "Diagnostics:" echo "" echo -e " 1) 🔍 Email Diagnostics - Verify email/domain is working ⭐" echo -e " 2) 📬 Email Deliverability Test - Test sending/receiving" echo -e " 3) 🔍 Mail Queue Inspector - View stuck emails" echo -e " 4) 📊 SMTP Connection Test - Verify mail server" echo -e " 5) 🔐 SPF/DKIM/DMARC Check - Email authentication" echo "" echo -e "Troubleshooting:" echo "" echo -e " 6) 🚫 Blacklist Check - Check IP reputation" echo -e " 7) 📧 Mail Log Analyzer - Search mail logs" echo -e " 8) 🔄 Flush Mail Queue - Clear stuck emails" echo "" echo -e "Maintenance:" echo "" echo -e " 9) 🧹 Clean Mailboxes - Remove old emails" echo -e " 10) 📈 Mailbox Size Report - Show usage per account" echo "" echo -e " 0) Back to Main Menu" echo "" echo -e "──────────────────────────────────────────────────────────────" echo -n "Select option: " } handle_email_menu() { if [ "$INTERACTIVE_MODE" -eq 0 ]; then return 0 # Non-interactive mode, exit fi while true; do show_email_menu if ! read -r choice /dev/null; then return 0 # Exit if read fails fi case "$choice" in 1) run_module "email" "email-diagnostics.sh" ;; 2) run_module "email" "deliverability-test.sh" ;; 3) run_module "email" "mail-queue-inspector.sh" ;; 4) run_module "email" "smtp-connection-test.sh" ;; 5) run_module "email" "spf-dkim-dmarc-check.sh" ;; 6) run_module "email" "blacklist-check.sh" ;; 7) run_module "email" "mail-log-analyzer.sh" ;; 8) run_module "email" "flush-mail-queue.sh" ;; 9) run_module "email" "clean-mailboxes.sh" ;; 10) run_module "email" "mailbox-size-report.sh" ;; 0) return ;; *) echo -e "Invalid option"; sleep 1 ;; esac done } ############################################################################# # INITIALIZATION ############################################################################# init_directories() { mkdir -p "$MODULES_DIR"/{security,website,performance,backup,diagnostics,maintenance,email} || { echo "ERROR: Failed to create module directories"; return 1 } mkdir -p "$LIB_DIR" "$CONFIG_DIR" "$BASE_DIR/logs" || { echo "ERROR: Failed to create base directories"; return 1 } touch "$CONFIG_DIR/whitelist-ips.txt" 2>/dev/null || true touch "$CONFIG_DIR/whitelist-user-agents.txt" 2>/dev/null || true } startup_detection() { # Initialize system detection first (required for show_system_overview) if [ -z "${SYS_DETECTION_COMPLETE:-}" ]; then initialize_system_detection fi if ! db_is_fresh; then clear print_banner "Server Management Toolkit - Initializing" echo "" print_info "Detecting server configuration..." echo "" build_reference_database echo "" print_section "Detection Summary" echo "" echo -e "System:" echo " Control Panel: $SYS_CONTROL_PANEL $SYS_CONTROL_PANEL_VERSION" echo " OS: $SYS_OS_TYPE $SYS_OS_VERSION" echo " Web Server: $SYS_WEB_SERVER $SYS_WEB_SERVER_VERSION" echo " Database: $SYS_DB_TYPE $SYS_DB_VERSION" echo "" # Count records in database with single awk pass (instead of 4 separate grep -c calls) local counts=$(awk -F'|' '{a[$1]++} END {printf "%d %d %d %d", a["USER"]+0, a["DOMAIN"]+0, a["DB"]+0, a["WP"]+0}' "$SYSREF_DB" 2>/dev/null || echo "0 0 0 0") read -r user_count domain_count db_count wp_count <<< "$counts" echo -e "Server Content:" echo " Users: $user_count" echo " Domains: $domain_count" echo " Databases: $db_count" echo " WordPress Sites: $wp_count" echo "" print_success "Detection complete! Cached for 1 hour." echo "" # Read from terminal (use /dev/tty directly) if ! read -p "Press Enter to continue..." /dev/null; then true # Continue even if read fails fi fi } ############################################################################# # MAIN LOOP ############################################################################# main() { # Initialize directories once at startup init_directories || { echo "ERROR: Failed to initialize directories" return 1 } # Detect system configuration (builds database if cache expired) startup_detection || true while true; do show_main_menu # Check if interactive mode if [ "$INTERACTIVE_MODE" -eq 0 ]; then echo "" echo "Non-interactive mode: Use this toolkit in an interactive terminal." echo "Try: source run.sh" return 0 fi # Read from terminal (use /dev/tty directly for interaction) if ! read -r choice /dev/null; then # No terminal available, return from function gracefully return 0 fi case "$choice" in 1) run_module "diagnostics" "system-health-check.sh" ;; 2) handle_security_menu ;; 3) handle_website_menu ;; 4) handle_performance_menu ;; 5) handle_backup_menu ;; 6) handle_email_menu ;; 7) run_module "maintenance" "cleanup-toolkit-data.sh" ;; 0) echo "" echo "Clean history and remove traces? (yes/no): " >&2 if ! read -r clean_hist /dev/null; then # Exit if read fails - just assume no cleanup echo "" echo "Thanks for using Server Management Toolkit!" echo "" return 0 fi if [ "$clean_hist" = "yes" ]; then touch /tmp/.cleanup_requested 2>/dev/null || true echo "" echo "Cleanup will happen automatically..." echo "" else echo "" echo "Thanks for using Server Management Toolkit!" echo "" fi return 0 ;; *) echo -e "Invalid option" sleep 1 ;; esac done } main "$@"