Files
Linux-Server-Management-Too…/launcher.sh
T
cschantz 2ef3561e02 Add comprehensive disk space analyzer to toolkit
New Feature: WinDirStat-like disk space analyzer for Linux
Location: modules/maintenance/disk-space-analyzer.sh
Menu: Backup & Recovery → Maintenance (option 4)

Key Features:
- 14 different analysis and cleanup options
- Inode usage monitoring (critical for detecting inode exhaustion)
- No external dependencies (bc removed, using awk for math)
- Multi-panel support (cPanel/Plesk/InterWorx)
- Interactive drill-down capability
- Preview before deletion for all cleanup operations

Analysis Types:
1. Disk usage overview with warnings (>90% critical, >75% warning)
2. Inode usage checking (often overlooked but critical)
3. Largest directories with drill-down capability
4. Largest files with type detection (log/db/archive/video/image)
5. Old log files analysis (>30 days with size totals)
6. Temporary files finder (/tmp, /var/tmp with age detection)
7. Package manager cache (yum/dnf/apt)
8. Email storage analysis (mail spools, Maildir, Maildrop)
9. Database storage (MySQL/MariaDB, PostgreSQL data dirs)
10. Backup files finder (.bak, .tar.gz, .sql with age)
11. WordPress analysis (uploads, plugins, cache by site)
12. Report generation (exports all analysis to timestamped file)

Cleanup Operations (all with preview):
13. Clean old log files (>30 days, shows preview, requires "yes")
14. Clean package cache (yum/dnf/apt, requires "yes")
15. Clean WordPress cache (per-site WP Super Cache cleanup)

Technical Improvements:
- size_to_bytes() function for human-readable to bytes conversion
- Uses awk for all floating point math (no bc dependency)
- Excludes system dirs (/proc, /sys, /dev, /run) for faster scans
- Format functions for consistent output (bytes/KB/MB/GB/TB)
- Age detection for files (shows days old)
- File type detection by extension
- Interactive menus with color coding

Safety Features:
- Dry-run preview before all deletions
- Confirmation prompts ("yes" required, not just "y")
- Size calculations shown before deletion
- First 10 files previewed in cleanup operations

Changes to launcher.sh:
- Added option 4 to Backup & Recovery menu
- Added case handler to run disk-space-analyzer.sh
- Menu text: "💿 Disk Space Analyzer - Find space issues & cleanup files"

Testing: Script is executable and ready to use

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-17 19:25:58 -05:00

486 lines
19 KiB
Bash
Executable File

#!/bin/bash
#############################################################################
# Server Management Toolkit - Main Launcher
# Version: 2.1
#
# Streamlined menu showing only implemented features
#############################################################################
set -eo pipefail
# Configuration
SUITE_VERSION="2.1.0"
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"
source "$LIB_DIR/system-detect.sh"
source "$LIB_DIR/user-manager.sh"
source "$LIB_DIR/reference-db.sh"
# 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 -e "${CYAN}═══════════════════════════════════════════════════════════════${NC}"
echo -e "${CYAN} ⚡ Server Management Toolkit v${SUITE_VERSION}${NC}"
echo -e "${CYAN} Complete cPanel/Linux Server Administration Suite${NC}"
echo -e "${CYAN}═══════════════════════════════════════════════════════════════${NC}"
echo ""
}
# Run a module
run_module() {
local category="$1"
local module="$2"
shift 2
if [ ! -f "$MODULES_DIR/$category/$module" ]; then
echo ""
echo -e "${RED}✗ Module not found: $category/$module${NC}"
echo ""
read -p "Press Enter to continue..."
return 1
fi
echo ""
echo -e "${CYAN}Launching: $category/$module${NC}"
echo -e "${CYAN}──────────────────────────────────────────────────────────────${NC}"
# 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 "${CYAN}──────────────────────────────────────────────────────────────${NC}"
if [ "${exit_code:-0}" -eq 0 ]; then
echo -e "${GREEN}✓ Completed successfully${NC}"
else
echo -e "${RED}✗ Exited with code: $exit_code${NC}"
fi
echo ""
read -p "Press Enter to continue..."
}
#############################################################################
# MAIN MENU
#############################################################################
show_main_menu() {
show_banner
echo -e "${BOLD}Quick Diagnostics:${NC}"
echo ""
echo -e " ${MAGENTA}1)${NC} 🏥 System Health Check - Full server diagnostics"
echo ""
echo -e "${BOLD}Main Categories:${NC}"
echo ""
echo -e " ${GREEN}2)${NC} 🛡️ Security & Monitoring"
echo -e " ${BLUE}3)${NC} 🌐 Website Diagnostics"
echo -e " ${MAGENTA}4)${NC} 🔧 Performance Analysis"
echo -e " ${YELLOW}5)${NC} 💾 Backup & Recovery"
echo ""
echo -e "${BOLD}System:${NC}"
echo ""
echo -e " ${YELLOW}6)${NC} 🗑️ Cleanup Toolkit Data - Clear cached data"
echo ""
echo -e " ${RED}0)${NC} Exit"
echo ""
echo -e "${CYAN}═══════════════════════════════════════════════════════════════${NC}"
echo -n "Select option: "
}
#############################################################################
# SECURITY & MONITORING
#############################################################################
show_security_menu() {
show_banner
echo -e "${GREEN}${BOLD}🛡️ Security & Monitoring${NC}"
echo ""
echo -e "${BOLD}Threat Analysis:${NC}"
echo ""
echo -e " ${CYAN}1)${NC} 🤖 Bot & Traffic Analyzer - Full analysis (all logs)"
echo -e " ${CYAN}2)${NC} 🤖 Quick Scan (1 hour) - Recent activity only"
echo -e " ${CYAN}3)${NC} 📊 IP Reputation Manager - Query/manage IP database"
echo -e " ${CYAN}4)${NC} 🦠 Malware Scanner - ImunifyAV, ClamAV, Maldet"
echo ""
echo -e "${BOLD}Live Monitoring:${NC}"
echo ""
echo -e " ${MAGENTA}5)${NC} 📡 Live Attack Monitor - Unified threat intelligence (STABLE)"
echo -e " ${MAGENTA}6)${NC} 📡 Live Attack Monitor v2.0 - Refactored version (BETA) 🚀"
echo -e " ${MAGENTA}7)${NC} 🔐 SSH Attack Monitor - SSH brute force detection"
echo -e " ${MAGENTA}8)${NC} 🌐 Web Traffic Monitor - HTTP attack detection"
echo -e " ${MAGENTA}9)${NC} 🔥 Firewall Activity Monitor - CSF/iptables monitoring"
echo ""
echo -e "${BOLD}Log Viewers:${NC}"
echo ""
echo -e " ${CYAN}10)${NC} Tail Apache Access Log - Live web access"
echo -e " ${CYAN}11)${NC} Tail Apache Error Log - Live web errors"
echo -e " ${CYAN}12)${NC} Tail Mail Log - Live email activity"
echo -e " ${CYAN}13)${NC} Tail Security Log - Live auth attempts"
echo ""
echo -e "${BOLD}Security Actions:${NC}"
echo ""
echo -e " ${YELLOW}14)${NC} 🔒 Enable cPHulk Protection - Brute force protection"
echo -e " ${YELLOW}15)${NC} ⚙️ Optimize CT_LIMIT - Connection tracking tuning"
echo ""
echo -e "${BOLD}Analysis Tools:${NC}"
echo ""
echo -e " ${GREEN}16)${NC} 🛡️ Historical Attack Analysis - Scan past logs for attacks (ET Open)"
echo ""
echo -e " ${RED}0)${NC} Back to Main Menu"
echo ""
echo -e "${CYAN}──────────────────────────────────────────────────────────────${NC}"
echo -n "Select option: "
}
handle_security_menu() {
while true; do
show_security_menu
read -r choice
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" "malware-scanner.sh" ;;
5) run_module "security" "live-attack-monitor.sh" ;;
6) run_module "security" "live-attack-monitor-v2.sh" ;;
7) run_module "security" "ssh-attack-monitor.sh" ;;
8) run_module "security" "web-traffic-monitor.sh" ;;
9) run_module "security" "firewall-activity-monitor.sh" ;;
10) run_module "security" "tail-apache-access.sh" ;;
11) run_module "security" "tail-apache-error.sh" ;;
12) run_module "security" "tail-mail-log.sh" ;;
13) run_module "security" "tail-secure-log.sh" ;;
14) run_module "security" "enable-cphulk.sh" ;;
15) run_module "security" "optimize-ct-limit.sh" ;;
16) bash "$BASE_DIR/tools/analyze-historical-attacks.sh" ;;
0) return ;;
*) echo -e "${RED}Invalid option${NC}"; sleep 1 ;;
esac
done
}
#############################################################################
# WEBSITE DIAGNOSTICS
#############################################################################
show_website_menu() {
show_banner
echo -e "${BLUE}${BOLD}🌐 Website Diagnostics${NC}"
echo ""
echo -e "${BOLD}Error Analysis:${NC}"
echo ""
echo -e " ${BLUE}1)${NC} 🔍 Website Error Analyzer - Find 500/config errors (filters bots)"
echo -e " ${RED}2)${NC} 🔥 Fast 500 Error Tracker - ONLY 500s + root cause diagnosis"
echo ""
echo -e "${BOLD}WordPress Management:${NC}"
echo ""
echo -e " ${BLUE}3)${NC} 📦 WordPress Tools → WP-Cron manager & diagnostics"
echo ""
echo -e " ${RED}0)${NC} Back to Main Menu"
echo ""
echo -e "${CYAN}──────────────────────────────────────────────────────────────${NC}"
echo -n "Select option: "
}
handle_website_menu() {
while true; do
show_website_menu
read -r choice
case $choice in
1) run_module "website" "website-error-analyzer.sh" ;;
2) run_module "website" "500-error-tracker.sh" ;;
3) bash "$MODULES_DIR/website/wordpress-menu.sh" ;;
0) return ;;
*) echo -e "${RED}Invalid option${NC}"; sleep 1 ;;
esac
done
}
#############################################################################
# PERFORMANCE ANALYSIS
#############################################################################
show_performance_menu() {
show_banner
echo -e "${MAGENTA}${BOLD}🔧 Performance Analysis${NC}"
echo ""
echo -e "${BOLD}Database:${NC}"
echo ""
echo -e " ${MAGENTA}1)${NC} 🗄️ MySQL Query Analyzer - Find slow queries & optimize"
echo ""
echo -e "${BOLD}Network & Resources:${NC}"
echo ""
echo -e " ${MAGENTA}2)${NC} 🌐 Network & Bandwidth - Traffic & top consumers"
echo -e " ${MAGENTA}3)${NC} 💻 Hardware Health Check - SMART, memory, CPU sensors"
echo ""
echo -e "${BOLD}PHP Optimization:${NC}"
echo ""
echo -e " ${MAGENTA}4)${NC} ⚙️ PHP Configuration Optimizer - Per-domain PHP tuning"
echo ""
echo -e "${BOLD}System Health:${NC}"
echo ""
echo -e " ${MAGENTA}5)${NC} 📊 Loadwatch Health Analyzer - Historical system analysis"
echo ""
echo -e " ${RED}0)${NC} Back to Main Menu"
echo ""
echo -e "${CYAN}──────────────────────────────────────────────────────────────${NC}"
echo -n "Select option: "
}
handle_performance_menu() {
while true; do
show_performance_menu
read -r choice
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 ;;
0) return ;;
*) echo -e "${RED}Invalid option${NC}"; sleep 1 ;;
esac
done
}
handle_loadwatch_analyzer() {
show_banner
echo -e "${MAGENTA}${BOLD}📊 Loadwatch Health Analyzer${NC}"
echo ""
echo -e "Select time range for analysis:"
echo ""
echo -e " ${CYAN}1)${NC} Last 1 Hour - Recent activity"
echo -e " ${CYAN}2)${NC} Last 6 Hours - Mid-term trending"
echo -e " ${CYAN}3)${NC} Last 24 Hours - Full day analysis"
echo -e " ${CYAN}4)${NC} Last 7 Days - Weekly patterns"
echo -e " ${CYAN}5)${NC} Last 30 Days - Monthly overview"
echo ""
echo -e " ${RED}0)${NC} Back"
echo ""
echo -e "${CYAN}──────────────────────────────────────────────────────────────${NC}"
echo -n "Select time range: "
read -r range_choice
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 "${RED}Invalid option${NC}"; sleep 1 ;;
esac
}
#############################################################################
# BACKUP & RECOVERY
#############################################################################
show_backup_menu() {
show_banner
echo -e "${YELLOW}${BOLD}💾 Backup & Recovery${NC}"
echo ""
echo -e "${BOLD}Acronis Cyber Protect:${NC}"
echo ""
echo -e " ${YELLOW}1)${NC} 🔷 Acronis Management → Complete backup management"
echo ""
echo -e "${BOLD}Database Tools:${NC}"
echo ""
echo -e " ${CYAN}2)${NC} 🔄 MySQL File Restore - Convert restored DB files to .sql"
echo ""
echo -e "${BOLD}Maintenance:${NC}"
echo ""
echo -e " ${RED}3)${NC} 🗑️ Cleanup Toolkit Data - Remove IP reputation & temp files"
echo -e " ${CYAN}4)${NC} 💿 Disk Space Analyzer - Find space issues & cleanup files"
echo ""
echo -e " ${RED}0)${NC} Back to Main Menu"
echo ""
echo -e "${CYAN}──────────────────────────────────────────────────────────────${NC}"
echo -n "Select option: "
}
show_acronis_menu() {
show_banner
echo -e "${YELLOW}${BOLD}🔷 Acronis Cyber Protect${NC}"
echo ""
echo -e "${BOLD}Installation & Setup:${NC}"
echo ""
echo -e " ${YELLOW}1)${NC} Install Acronis Agent - Download and install"
echo -e " ${YELLOW}2)${NC} Register with Cloud - Connect to Acronis Cloud"
echo -e " ${YELLOW}3)${NC} Configure Agent - Adjust settings"
echo ""
echo -e "${BOLD}Backup Management:${NC}"
echo ""
echo -e " ${GREEN}4)${NC} 📊 Manage Backups - Complete backup interface"
echo ""
echo -e "${BOLD}Status & Monitoring:${NC}"
echo ""
echo -e " ${CYAN}5)${NC} Check Agent Status - Verify Acronis is running"
echo -e " ${CYAN}6)${NC} View Logs - Check Acronis logs"
echo -e " ${CYAN}7)${NC} Troubleshoot - Diagnose backup failures"
echo ""
echo -e "${BOLD}Maintenance:${NC}"
echo ""
echo -e " ${YELLOW}8)${NC} Update Agent - Upgrade to latest version"
echo -e " ${RED}9)${NC} Uninstall Acronis - Remove agent"
echo ""
echo -e " ${RED}0)${NC} Back to Backup Menu"
echo ""
echo -e "${CYAN}──────────────────────────────────────────────────────────────${NC}"
echo -n "Select option: "
}
handle_backup_menu() {
while true; do
show_backup_menu
read -r choice
case $choice in
1) handle_acronis_menu ;;
2) run_module "backup" "mysql-restore-to-sql.sh" ;;
3) run_module "maintenance" "cleanup-toolkit-data.sh" ;;
4) run_module "maintenance" "disk-space-analyzer.sh" ;;
0) return ;;
*) echo -e "${RED}Invalid option${NC}"; sleep 1 ;;
esac
done
}
handle_acronis_menu() {
while true; do
show_acronis_menu
read -r choice
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 "${RED}Invalid option${NC}"; sleep 1 ;;
esac
done
}
#############################################################################
# INITIALIZATION
#############################################################################
init_directories() {
mkdir -p "$MODULES_DIR"/{security,website,performance,backup,diagnostics,maintenance}
mkdir -p "$LIB_DIR" "$CONFIG_DIR" "$BASE_DIR/logs"
touch "$CONFIG_DIR/whitelist-ips.txt" 2>/dev/null
touch "$CONFIG_DIR/whitelist-user-agents.txt" 2>/dev/null
}
startup_detection() {
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 "${BOLD}System:${NC}"
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 ""
local user_count=$(grep -c "^USER|" "$SYSREF_DB" 2>/dev/null || echo 0)
local domain_count=$(grep -c "^DOMAIN|" "$SYSREF_DB" 2>/dev/null || echo 0)
local db_count=$(grep -c "^DB|" "$SYSREF_DB" 2>/dev/null || echo 0)
local wp_count=$(grep -c "^WP|" "$SYSREF_DB" 2>/dev/null || echo 0)
echo -e "${BOLD}Server Content:${NC}"
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 -p "Press Enter to continue..."
fi
}
#############################################################################
# MAIN LOOP
#############################################################################
main() {
init_directories
startup_detection
while true; do
show_main_menu
read -r choice
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) run_module "maintenance" "cleanup-toolkit-data.sh" ;;
0)
echo ""
read -p "Clean history and remove traces? (yes/no): " clean_hist
if [ "$clean_hist" = "yes" ]; then
touch /tmp/.cleanup_requested
echo ""
echo "Cleanup will happen automatically..."
echo ""
else
echo ""
echo -e "${GREEN}Thanks for using Server Management Toolkit!${NC}"
echo ""
fi
exit 0
;;
*)
echo -e "${RED}Invalid option${NC}"
sleep 1
;;
esac
done
}
main "$@"