Fix SOURCE command safety issues (HIGH priority)
Added existence checks and error handling for all source commands
to prevent silent failures when dependencies are missing.
Library files (use 'return' for error):
- reference-db.sh: Added checks for 3 dependencies
- mysql-analyzer.sh: Added checks for 3 dependencies
- domain-discovery.sh: Added checks for 2 dependencies
- system-detect.sh: Added check for common-functions.sh
- plesk-helpers.sh: Added check for common-functions.sh
- user-manager.sh: Added checks for 2 dependencies
Executable scripts (use 'exit' for error):
- wordpress-cron-manager.sh: Added checks for 2 dependencies
- website-error-analyzer.sh: Added checks for 4 dependencies
Pattern: [ -f "file" ] && source "file" || { echo "ERROR" >&2; return/exit 1; }
This ensures scripts fail fast with clear error messages when
required dependencies are missing, rather than continuing with
undefined functions.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,8 +8,9 @@
|
|||||||
# Source dependencies
|
# Source dependencies
|
||||||
if [ -z "$TOOLKIT_BASE_DIR" ]; then
|
if [ -z "$TOOLKIT_BASE_DIR" ]; then
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
source "$SCRIPT_DIR/common-functions.sh"
|
|
||||||
source "$SCRIPT_DIR/system-detect.sh"
|
[ -f "$SCRIPT_DIR/common-functions.sh" ] && source "$SCRIPT_DIR/common-functions.sh" || { echo "ERROR: common-functions.sh not found" >&2; return 1; }
|
||||||
|
[ -f "$SCRIPT_DIR/system-detect.sh" ] && source "$SCRIPT_DIR/system-detect.sh" || { echo "ERROR: system-detect.sh not found" >&2; return 1; }
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Source control panel helpers if available
|
# Source control panel helpers if available
|
||||||
|
|||||||
@@ -8,9 +8,10 @@
|
|||||||
# Source dependencies
|
# Source dependencies
|
||||||
if [ -z "$TOOLKIT_BASE_DIR" ]; then
|
if [ -z "$TOOLKIT_BASE_DIR" ]; then
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
source "$SCRIPT_DIR/common-functions.sh"
|
|
||||||
source "$SCRIPT_DIR/system-detect.sh"
|
[ -f "$SCRIPT_DIR/common-functions.sh" ] && source "$SCRIPT_DIR/common-functions.sh" || { echo "ERROR: common-functions.sh not found" >&2; return 1; }
|
||||||
source "$SCRIPT_DIR/user-manager.sh"
|
[ -f "$SCRIPT_DIR/system-detect.sh" ] && source "$SCRIPT_DIR/system-detect.sh" || { echo "ERROR: system-detect.sh not found" >&2; return 1; }
|
||||||
|
[ -f "$SCRIPT_DIR/user-manager.sh" ] && source "$SCRIPT_DIR/user-manager.sh" || { echo "ERROR: user-manager.sh not found" >&2; return 1; }
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
# Source common functions if not already loaded
|
# Source common functions if not already loaded
|
||||||
if [ -z "$TOOLKIT_BASE_DIR" ]; then
|
if [ -z "$TOOLKIT_BASE_DIR" ]; then
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
source "$SCRIPT_DIR/common-functions.sh"
|
[ -f "$SCRIPT_DIR/common-functions.sh" ] && source "$SCRIPT_DIR/common-functions.sh" || { echo "ERROR: common-functions.sh not found" >&2; return 1; }
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
|||||||
+4
-3
@@ -9,9 +9,10 @@
|
|||||||
# Source dependencies
|
# Source dependencies
|
||||||
if [ -z "$TOOLKIT_BASE_DIR" ]; then
|
if [ -z "$TOOLKIT_BASE_DIR" ]; then
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
source "$SCRIPT_DIR/common-functions.sh"
|
|
||||||
source "$SCRIPT_DIR/system-detect.sh"
|
[ -f "$SCRIPT_DIR/common-functions.sh" ] && source "$SCRIPT_DIR/common-functions.sh" || { echo "ERROR: common-functions.sh not found" >&2; return 1; }
|
||||||
source "$SCRIPT_DIR/user-manager.sh"
|
[ -f "$SCRIPT_DIR/system-detect.sh" ] && source "$SCRIPT_DIR/system-detect.sh" || { echo "ERROR: system-detect.sh not found" >&2; return 1; }
|
||||||
|
[ -f "$SCRIPT_DIR/user-manager.sh" ] && source "$SCRIPT_DIR/user-manager.sh" || { echo "ERROR: user-manager.sh not found" >&2; return 1; }
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Reference database location
|
# Reference database location
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
# Source common functions if not already loaded
|
# Source common functions if not already loaded
|
||||||
if [ -z "$TOOLKIT_BASE_DIR" ]; then
|
if [ -z "$TOOLKIT_BASE_DIR" ]; then
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
source "$SCRIPT_DIR/common-functions.sh"
|
[ -f "$SCRIPT_DIR/common-functions.sh" ] && source "$SCRIPT_DIR/common-functions.sh" || { echo "ERROR: common-functions.sh not found" >&2; return 1; }
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Global variables (session-only) - only initialize if not already set
|
# Global variables (session-only) - only initialize if not already set
|
||||||
|
|||||||
+3
-2
@@ -8,8 +8,9 @@
|
|||||||
# Source dependencies
|
# Source dependencies
|
||||||
if [ -z "$TOOLKIT_BASE_DIR" ]; then
|
if [ -z "$TOOLKIT_BASE_DIR" ]; then
|
||||||
_LIB_SRCDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
_LIB_SRCDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
source "$_LIB_SRCDIR/common-functions.sh"
|
|
||||||
source "$_LIB_SRCDIR/system-detect.sh"
|
[ -f "$_LIB_SRCDIR/common-functions.sh" ] && source "$_LIB_SRCDIR/common-functions.sh" || { echo "ERROR: common-functions.sh not found" >&2; return 1; }
|
||||||
|
[ -f "$_LIB_SRCDIR/system-detect.sh" ] && source "$_LIB_SRCDIR/system-detect.sh" || { echo "ERROR: system-detect.sh not found" >&2; return 1; }
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Initialize temp session directory if not set
|
# Initialize temp session directory if not set
|
||||||
|
|||||||
@@ -9,10 +9,11 @@
|
|||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||||
source "$SCRIPT_DIR/lib/common-functions.sh"
|
|
||||||
source "$SCRIPT_DIR/lib/system-detect.sh"
|
[ -f "$SCRIPT_DIR/lib/common-functions.sh" ] && source "$SCRIPT_DIR/lib/common-functions.sh" || { echo "ERROR: common-functions.sh not found" >&2; exit 1; }
|
||||||
source "$SCRIPT_DIR/lib/user-manager.sh"
|
[ -f "$SCRIPT_DIR/lib/system-detect.sh" ] && source "$SCRIPT_DIR/lib/system-detect.sh" || { echo "ERROR: system-detect.sh not found" >&2; exit 1; }
|
||||||
source "$SCRIPT_DIR/lib/ip-reputation.sh"
|
[ -f "$SCRIPT_DIR/lib/user-manager.sh" ] && source "$SCRIPT_DIR/lib/user-manager.sh" || { echo "ERROR: user-manager.sh not found" >&2; exit 1; }
|
||||||
|
[ -f "$SCRIPT_DIR/lib/ip-reputation.sh" ] && source "$SCRIPT_DIR/lib/ip-reputation.sh" || { echo "ERROR: ip-reputation.sh not found" >&2; exit 1; }
|
||||||
|
|
||||||
# Configuration - Use system-detected paths
|
# Configuration - Use system-detected paths
|
||||||
APACHE_ERROR_LOG="/var/log/apache2/error_log" # Will be auto-detected
|
APACHE_ERROR_LOG="/var/log/apache2/error_log" # Will be auto-detected
|
||||||
|
|||||||
@@ -12,8 +12,9 @@
|
|||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
|
||||||
source "$SCRIPT_DIR/lib/common-functions.sh"
|
|
||||||
source "$SCRIPT_DIR/lib/system-detect.sh"
|
[ -f "$SCRIPT_DIR/lib/common-functions.sh" ] && source "$SCRIPT_DIR/lib/common-functions.sh" || { echo "ERROR: common-functions.sh not found" >&2; exit 1; }
|
||||||
|
[ -f "$SCRIPT_DIR/lib/system-detect.sh" ] && source "$SCRIPT_DIR/lib/system-detect.sh" || { echo "ERROR: system-detect.sh not found" >&2; exit 1; }
|
||||||
|
|
||||||
if [ "$EUID" -ne 0 ]; then
|
if [ "$EUID" -ne 0 ]; then
|
||||||
print_error "This script must be run as root"
|
print_error "This script must be run as root"
|
||||||
|
|||||||
Reference in New Issue
Block a user