From 2593e8748964848c6858fc5e6c5c9e77794ba26c Mon Sep 17 00:00:00 2001 From: cschantz Date: Wed, 3 Dec 2025 01:30:58 -0500 Subject: [PATCH] CRITICAL: Fix SYS_* variable reset bug in system-detect.sh Problem: - Lines 16-24 reset ALL SYS_* variables to empty EVERY time system-detect.sh is sourced - When php-analyzer.sh sources system-detect.sh again, it wipes out SYS_CONTROL_PANEL - Result: get_user_domains() returns empty because SYS_CONTROL_PANEL is empty - This broke ALL multi-file sourcing scenarios Root cause: - export SYS_CONTROL_PANEL="" runs unconditionally on every source - Multiple libraries source system-detect.sh (user-manager, php-detector, php-analyzer) - Second sourcing wipes first initialization Fix: - Wrap variable initialization in SYS_DETECTION_COMPLETE check - Variables only reset if detection hasn't run yet - Preserves values across multiple sourcings Impact: - Memory capacity analysis now works (was showing 0 pools) - All domain iteration works correctly - Any script that sources multiple libraries now works --- lib/system-detect.sh | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/system-detect.sh b/lib/system-detect.sh index 4f4d15a..5cc7f13 100755 --- a/lib/system-detect.sh +++ b/lib/system-detect.sh @@ -12,16 +12,18 @@ if [ -z "$TOOLKIT_BASE_DIR" ]; then source "$SCRIPT_DIR/common-functions.sh" fi -# Global variables (session-only) -export SYS_CONTROL_PANEL="" -export SYS_CONTROL_PANEL_VERSION="" -export SYS_OS_TYPE="" -export SYS_OS_VERSION="" -export SYS_WEB_SERVER="" -export SYS_WEB_SERVER_VERSION="" -export SYS_DB_TYPE="" -export SYS_DB_VERSION="" -export SYS_LOG_DIR="" +# Global variables (session-only) - only initialize if not already set +if [ -z "$SYS_DETECTION_COMPLETE" ]; then + export SYS_CONTROL_PANEL="" + export SYS_CONTROL_PANEL_VERSION="" + export SYS_OS_TYPE="" + export SYS_OS_VERSION="" + export SYS_WEB_SERVER="" + export SYS_WEB_SERVER_VERSION="" + export SYS_DB_TYPE="" + export SYS_DB_VERSION="" + export SYS_LOG_DIR="" +fi export SYS_USER_HOME_BASE="" export SYS_PHP_VERSIONS=() export SYS_CLOUDFLARE_ACTIVE=""