From 04b592d638604f042fe4be08488b4383910d533b Mon Sep 17 00:00:00 2001 From: cschantz Date: Tue, 23 Dec 2025 20:30:50 -0500 Subject: [PATCH] Fix Plesk helper sourcing and add fallback for domain discovery Problem: When domain-discovery.sh is sourced directly (not via launcher), plesk-helpers.sh wasn't being loaded because $LIB_DIR was undefined. This caused list_all_domains() to fail on Plesk with 'command not found'. Fixes: 1. Enhanced Plesk helper sourcing logic: - Try $LIB_DIR first (when sourced from launcher) - Fall back to $SCRIPT_DIR (when sourced directly) - Ensures plesk-helpers.sh loads in all contexts 2. Added fallback in list_all_domains() for Plesk: - Check if plesk_list_domains function exists - If not available, fall back to directory scan - Scans /var/www/vhosts/ excluding system directories - Ensures domains are found even without plesk-helpers.sh Impact: Domain discovery now works correctly when: - Sourced from launcher (uses plesk-helpers.sh) - Sourced directly from command line (uses fallback) - Plesk CLI unavailable (uses directory scan) Tested on: Plesk 18.0.61 production system --- lib/domain-discovery.sh | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/domain-discovery.sh b/lib/domain-discovery.sh index 6541408..9b47b7f 100644 --- a/lib/domain-discovery.sh +++ b/lib/domain-discovery.sh @@ -13,7 +13,14 @@ if [ -z "$TOOLKIT_BASE_DIR" ]; then fi # Source control panel helpers if available -[ "$SYS_CONTROL_PANEL" = "plesk" ] && [ -f "$LIB_DIR/plesk-helpers.sh" ] && source "$LIB_DIR/plesk-helpers.sh" +if [ "$SYS_CONTROL_PANEL" = "plesk" ]; then + # Try LIB_DIR first, then SCRIPT_DIR + if [ -n "$LIB_DIR" ] && [ -f "$LIB_DIR/plesk-helpers.sh" ]; then + source "$LIB_DIR/plesk-helpers.sh" + elif [ -n "$SCRIPT_DIR" ] && [ -f "$SCRIPT_DIR/plesk-helpers.sh" ]; then + source "$SCRIPT_DIR/plesk-helpers.sh" + fi +fi ############################################################################# # DOMAIN DISCOVERY (Control Panel Agnostic) @@ -36,7 +43,15 @@ list_all_domains() { ;; plesk) - plesk_list_domains + # Use plesk_list_domains if available, otherwise fallback + if type plesk_list_domains >/dev/null 2>&1; then + plesk_list_domains + else + # Fallback: scan vhosts directory + ls -1 /var/www/vhosts/ 2>/dev/null | \ + grep -v "^system$\|^chroot$\|^\.skel$\|^default$\|^fs$" | \ + grep -v "^\." || true + fi ;; interworx)