Compare commits
4 Commits
ac6c0b5c12
...
ea78ff7c64
| Author | SHA1 | Date | |
|---|---|---|---|
| ea78ff7c64 | |||
| bdb443da72 | |||
| b9a72bff75 | |||
| 297377b7c6 |
+136
-31
@@ -10,6 +10,14 @@
|
|||||||
|
|
||||||
set -eo pipefail
|
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
|
# Configuration
|
||||||
SUITE_VERSION="2.1.0-BETA"
|
SUITE_VERSION="2.1.0-BETA"
|
||||||
BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
@@ -18,11 +26,23 @@ LIB_DIR="$BASE_DIR/lib"
|
|||||||
CONFIG_DIR="$BASE_DIR/config"
|
CONFIG_DIR="$BASE_DIR/config"
|
||||||
|
|
||||||
# Load core libraries
|
# Load core libraries
|
||||||
source "$LIB_DIR/common-functions.sh" || { echo "ERROR: Failed to load common-functions.sh"; exit 1; }
|
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"; exit 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"; exit 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"; exit 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"; exit 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/tty 2>/dev/null; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Color codes
|
# Color codes
|
||||||
RED='\033[0;31m'
|
RED='\033[0;31m'
|
||||||
@@ -56,7 +76,9 @@ run_module() {
|
|||||||
echo ""
|
echo ""
|
||||||
echo -e "✗ Module not found: $category/$module"
|
echo -e "✗ Module not found: $category/$module"
|
||||||
echo ""
|
echo ""
|
||||||
read -p "Press Enter to continue..."
|
if ! read -p "Press Enter to continue..." </dev/tty 2>/dev/null; then
|
||||||
|
true # Continue even if read fails
|
||||||
|
fi
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -77,7 +99,9 @@ run_module() {
|
|||||||
echo -e "✗ Exited with code: $exit_code"
|
echo -e "✗ Exited with code: $exit_code"
|
||||||
fi
|
fi
|
||||||
echo ""
|
echo ""
|
||||||
read -p "Press Enter to continue..."
|
if ! read -p "Press Enter to continue..." </dev/tty 2>/dev/null; then
|
||||||
|
true # Continue even if read fails
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
@@ -119,8 +143,8 @@ show_system_overview() {
|
|||||||
# PHP Versions
|
# PHP Versions
|
||||||
if [ ${#SYS_PHP_VERSIONS[@]} -gt 0 ]; then
|
if [ ${#SYS_PHP_VERSIONS[@]} -gt 0 ]; then
|
||||||
echo -n " PHP Versions: "
|
echo -n " PHP Versions: "
|
||||||
printf '%s, ' "${SYS_PHP_VERSIONS[@]}" | sed 's/, $//'
|
local php_list=$(printf '%s, ' "${SYS_PHP_VERSIONS[@]}")
|
||||||
echo ""
|
echo "${php_list%, }"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Firewall
|
# Firewall
|
||||||
@@ -194,9 +218,15 @@ show_threat_analysis_menu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handle_threat_analysis_menu() {
|
handle_threat_analysis_menu() {
|
||||||
|
if [ "$INTERACTIVE_MODE" -eq 0 ]; then
|
||||||
|
return 0 # Non-interactive mode, exit
|
||||||
|
fi
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
show_threat_analysis_menu
|
show_threat_analysis_menu
|
||||||
read -r choice
|
if ! read -r choice </dev/tty 2>/dev/null; then
|
||||||
|
return 0 # Exit if read fails
|
||||||
|
fi
|
||||||
|
|
||||||
case "$choice" in
|
case "$choice" in
|
||||||
1) run_module "security" "bot-analyzer.sh" ;;
|
1) run_module "security" "bot-analyzer.sh" ;;
|
||||||
@@ -228,9 +258,15 @@ show_live_monitoring_menu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handle_live_monitoring_menu() {
|
handle_live_monitoring_menu() {
|
||||||
|
if [ "$INTERACTIVE_MODE" -eq 0 ]; then
|
||||||
|
return 0 # Non-interactive mode, exit
|
||||||
|
fi
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
show_live_monitoring_menu
|
show_live_monitoring_menu
|
||||||
read -r choice
|
if ! read -r choice </dev/tty 2>/dev/null; then
|
||||||
|
return 0 # Exit if read fails
|
||||||
|
fi
|
||||||
|
|
||||||
case "$choice" in
|
case "$choice" in
|
||||||
1) run_module "security" "live-attack-monitor.sh" ;;
|
1) run_module "security" "live-attack-monitor.sh" ;;
|
||||||
@@ -260,9 +296,15 @@ show_log_viewers_menu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handle_log_viewers_menu() {
|
handle_log_viewers_menu() {
|
||||||
|
if [ "$INTERACTIVE_MODE" -eq 0 ]; then
|
||||||
|
return 0 # Non-interactive mode, exit
|
||||||
|
fi
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
show_log_viewers_menu
|
show_log_viewers_menu
|
||||||
read -r choice
|
if ! read -r choice </dev/tty 2>/dev/null; then
|
||||||
|
return 0 # Exit if read fails
|
||||||
|
fi
|
||||||
|
|
||||||
case "$choice" in
|
case "$choice" in
|
||||||
1) run_module "security" "tail-apache-access.sh" ;;
|
1) run_module "security" "tail-apache-access.sh" ;;
|
||||||
@@ -291,9 +333,15 @@ show_security_actions_menu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handle_security_actions_menu() {
|
handle_security_actions_menu() {
|
||||||
|
if [ "$INTERACTIVE_MODE" -eq 0 ]; then
|
||||||
|
return 0 # Non-interactive mode, exit
|
||||||
|
fi
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
show_security_actions_menu
|
show_security_actions_menu
|
||||||
read -r choice
|
if ! read -r choice </dev/tty 2>/dev/null; then
|
||||||
|
return 0 # Exit if read fails
|
||||||
|
fi
|
||||||
|
|
||||||
case "$choice" in
|
case "$choice" in
|
||||||
1) run_module "security" "enable-cphulk.sh" ;;
|
1) run_module "security" "enable-cphulk.sh" ;;
|
||||||
@@ -325,9 +373,15 @@ show_security_menu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handle_security_menu() {
|
handle_security_menu() {
|
||||||
|
if [ "$INTERACTIVE_MODE" -eq 0 ]; then
|
||||||
|
return 0 # Non-interactive mode, exit
|
||||||
|
fi
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
show_security_menu
|
show_security_menu
|
||||||
read -r choice
|
if ! read -r choice </dev/tty 2>/dev/null; then
|
||||||
|
return 0 # Exit if read fails
|
||||||
|
fi
|
||||||
|
|
||||||
case "$choice" in
|
case "$choice" in
|
||||||
1) handle_threat_analysis_menu ;;
|
1) handle_threat_analysis_menu ;;
|
||||||
@@ -373,9 +427,15 @@ show_website_menu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handle_website_menu() {
|
handle_website_menu() {
|
||||||
|
if [ "$INTERACTIVE_MODE" -eq 0 ]; then
|
||||||
|
return 0 # Non-interactive mode, exit
|
||||||
|
fi
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
show_website_menu
|
show_website_menu
|
||||||
read -r choice
|
if ! read -r choice </dev/tty 2>/dev/null; then
|
||||||
|
return 0 # Exit if read fails
|
||||||
|
fi
|
||||||
|
|
||||||
case "$choice" in
|
case "$choice" in
|
||||||
1) run_module "website" "website-error-analyzer.sh" ;;
|
1) run_module "website" "website-error-analyzer.sh" ;;
|
||||||
@@ -426,9 +486,15 @@ show_performance_menu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handle_performance_menu() {
|
handle_performance_menu() {
|
||||||
|
if [ "$INTERACTIVE_MODE" -eq 0 ]; then
|
||||||
|
return 0 # Non-interactive mode, exit
|
||||||
|
fi
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
show_performance_menu
|
show_performance_menu
|
||||||
read -r choice
|
if ! read -r choice </dev/tty 2>/dev/null; then
|
||||||
|
return 0 # Exit if read fails
|
||||||
|
fi
|
||||||
|
|
||||||
case "$choice" in
|
case "$choice" in
|
||||||
1) run_module "performance" "mysql-query-analyzer.sh" ;;
|
1) run_module "performance" "mysql-query-analyzer.sh" ;;
|
||||||
@@ -445,6 +511,10 @@ handle_performance_menu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handle_loadwatch_analyzer() {
|
handle_loadwatch_analyzer() {
|
||||||
|
if [ "$INTERACTIVE_MODE" -eq 0 ]; then
|
||||||
|
return 0 # Non-interactive mode, exit
|
||||||
|
fi
|
||||||
|
|
||||||
show_banner
|
show_banner
|
||||||
echo -e "📊 Loadwatch Health Analyzer"
|
echo -e "📊 Loadwatch Health Analyzer"
|
||||||
echo ""
|
echo ""
|
||||||
@@ -461,7 +531,9 @@ handle_loadwatch_analyzer() {
|
|||||||
echo -e "──────────────────────────────────────────────────────────────"
|
echo -e "──────────────────────────────────────────────────────────────"
|
||||||
echo -n "Select time range: "
|
echo -n "Select time range: "
|
||||||
|
|
||||||
read -r range_choice < /dev/tty
|
if ! read -r range_choice </dev/tty 2>/dev/null; then
|
||||||
|
return 0 # Exit if read fails
|
||||||
|
fi
|
||||||
|
|
||||||
case "$range_choice" in
|
case "$range_choice" in
|
||||||
1) run_module "diagnostics" "loadwatch-analyzer.sh" "-r" "1h" ;;
|
1) run_module "diagnostics" "loadwatch-analyzer.sh" "-r" "1h" ;;
|
||||||
@@ -532,9 +604,15 @@ show_acronis_menu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handle_backup_menu() {
|
handle_backup_menu() {
|
||||||
|
if [ "$INTERACTIVE_MODE" -eq 0 ]; then
|
||||||
|
return 0 # Non-interactive mode, exit
|
||||||
|
fi
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
show_backup_menu
|
show_backup_menu
|
||||||
read -r choice
|
if ! read -r choice </dev/tty 2>/dev/null; then
|
||||||
|
return 0 # Exit if read fails
|
||||||
|
fi
|
||||||
|
|
||||||
case "$choice" in
|
case "$choice" in
|
||||||
1) handle_acronis_menu ;;
|
1) handle_acronis_menu ;;
|
||||||
@@ -547,9 +625,15 @@ handle_backup_menu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handle_acronis_menu() {
|
handle_acronis_menu() {
|
||||||
|
if [ "$INTERACTIVE_MODE" -eq 0 ]; then
|
||||||
|
return 0 # Non-interactive mode, exit
|
||||||
|
fi
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
show_acronis_menu
|
show_acronis_menu
|
||||||
read -r choice
|
if ! read -r choice </dev/tty 2>/dev/null; then
|
||||||
|
return 0 # Exit if read fails
|
||||||
|
fi
|
||||||
|
|
||||||
case "$choice" in
|
case "$choice" in
|
||||||
1) run_module "backup" "acronis-install.sh" ;;
|
1) run_module "backup" "acronis-install.sh" ;;
|
||||||
@@ -601,9 +685,15 @@ show_email_menu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handle_email_menu() {
|
handle_email_menu() {
|
||||||
|
if [ "$INTERACTIVE_MODE" -eq 0 ]; then
|
||||||
|
return 0 # Non-interactive mode, exit
|
||||||
|
fi
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
show_email_menu
|
show_email_menu
|
||||||
read -r choice
|
if ! read -r choice </dev/tty 2>/dev/null; then
|
||||||
|
return 0 # Exit if read fails
|
||||||
|
fi
|
||||||
|
|
||||||
case "$choice" in
|
case "$choice" in
|
||||||
1) run_module "email" "email-diagnostics.sh" ;;
|
1) run_module "email" "email-diagnostics.sh" ;;
|
||||||
@@ -663,10 +753,9 @@ startup_detection() {
|
|||||||
echo " Database: $SYS_DB_TYPE $SYS_DB_VERSION"
|
echo " Database: $SYS_DB_TYPE $SYS_DB_VERSION"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
local user_count=$(grep -c "^USER|" "$SYSREF_DB" 2>/dev/null || echo 0)
|
# Count records in database with single awk pass (instead of 4 separate grep -c calls)
|
||||||
local domain_count=$(grep -c "^DOMAIN|" "$SYSREF_DB" 2>/dev/null || echo 0)
|
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")
|
||||||
local db_count=$(grep -c "^DB|" "$SYSREF_DB" 2>/dev/null || echo 0)
|
read -r user_count domain_count db_count wp_count <<< "$counts"
|
||||||
local wp_count=$(grep -c "^WP|" "$SYSREF_DB" 2>/dev/null || echo 0)
|
|
||||||
|
|
||||||
echo -e "Server Content:"
|
echo -e "Server Content:"
|
||||||
echo " Users: $user_count"
|
echo " Users: $user_count"
|
||||||
@@ -679,7 +768,9 @@ startup_detection() {
|
|||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Read from terminal (use /dev/tty directly)
|
# Read from terminal (use /dev/tty directly)
|
||||||
read -p "Press Enter to continue..." </dev/tty || true
|
if ! read -p "Press Enter to continue..." </dev/tty 2>/dev/null; then
|
||||||
|
true # Continue even if read fails
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -688,12 +779,26 @@ startup_detection() {
|
|||||||
#############################################################################
|
#############################################################################
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
init_directories
|
# Initialize directories once at startup
|
||||||
startup_detection
|
init_directories || {
|
||||||
|
echo "ERROR: Failed to initialize directories"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Detect system configuration (builds database if cache expired)
|
||||||
|
startup_detection || true
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
show_main_menu
|
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)
|
# Read from terminal (use /dev/tty directly for interaction)
|
||||||
if ! read -r choice </dev/tty 2>/dev/null; then
|
if ! read -r choice </dev/tty 2>/dev/null; then
|
||||||
# No terminal available, return from function gracefully
|
# No terminal available, return from function gracefully
|
||||||
@@ -710,12 +815,12 @@ main() {
|
|||||||
7) run_module "maintenance" "cleanup-toolkit-data.sh" ;;
|
7) run_module "maintenance" "cleanup-toolkit-data.sh" ;;
|
||||||
0)
|
0)
|
||||||
echo ""
|
echo ""
|
||||||
read -p "Clean history and remove traces? (yes/no): " clean_hist < /dev/tty
|
if ! read -p "Clean history and remove traces? (yes/no): " clean_hist </dev/tty 2>/dev/null; then
|
||||||
|
return 0 # Exit if read fails
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$clean_hist" = "yes" ]; then
|
if [ "$clean_hist" = "yes" ]; then
|
||||||
# Use secure temp file creation to prevent symlink attacks
|
touch /tmp/.cleanup_requested 2>/dev/null || true
|
||||||
CLEANUP_FILE=$(mktemp -t server-toolkit-cleanup.XXXXXX 2>/dev/null) || CLEANUP_FILE="/tmp/.cleanup_requested"
|
|
||||||
touch "$CLEANUP_FILE" 2>/dev/null || true
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Cleanup will happen automatically..."
|
echo "Cleanup will happen automatically..."
|
||||||
echo ""
|
echo ""
|
||||||
|
|||||||
@@ -30,7 +30,10 @@ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Run the launcher (source in current shell, don't execute in subshell)
|
# Run the launcher (source in current shell, don't execute in subshell)
|
||||||
source "$SCRIPT_DIR/launcher.sh"
|
source "$SCRIPT_DIR/launcher.sh" || {
|
||||||
|
echo "ERROR: Failed to load launcher.sh"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
# Check if cleanup is requested
|
# Check if cleanup is requested
|
||||||
if [ -f /tmp/.cleanup_requested ]; then
|
if [ -f /tmp/.cleanup_requested ]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user