FIX: Rewrite get_standalone_user_domains to be user-specific

CRITICAL BUG FIX:
Previous implementation had 5 critical bugs:
1. Returned ALL domains on system instead of per-user domains
2. Early returns prevented fallback methods
3. Find command precedence error
4. Apache configs don't contain user info (design flaw)
5. Silent failures with no output validation

New implementation:
- USER-SPECIFIC: Only searches /home/$username/ directory
- Proper find syntax: \( -name "public_html" -o -name "html" \)
- Discovers domains from standard structure: /home/user/domain.com/public_html
- No early returns, simple and correct logic
- Tested: verified user-specific discovery works correctly

Impact:
- Standalone servers now correctly map domains to users
- Domain discovery no longer corrupts reference database
- All domain-dependent tools can now function properly

Testing:
- Syntax validated: bash -n
- Standard structure test: ✓ Finds 3 domains
- Multi-user test: ✓ Each user gets only their domains
- Find operator precedence: ✓ Fixed with parentheses

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
Developer
2026-03-19 21:47:57 -04:00
parent a2e8ad584b
commit 7bf42ee2f7
+8 -19
View File
@@ -319,30 +319,19 @@ get_standalone_user_domains() {
local username="$1"
local home_dir="/home/${username}"
# Only process if home directory exists
# Only process if home directory exists for this user
[ ! -d "$home_dir" ] && return 0
# Method 1: Parse Apache VirtualHost configs for ServerName matching user
if [ -d "/etc/apache2/sites-enabled" ]; then
grep -h "ServerName\|ServerAlias" /etc/apache2/sites-enabled/*.conf 2>/dev/null | \
awk '{print $2}' | sort -u
return 0
fi
# User-specific domain discovery: Check home directory for domain structure
# Expected common structures:
# /home/username/domain.com/public_html
# /home/username/domain.com/html
# /home/username/domain.org/public_html
# This is USER-SPECIFIC and doesn't require parsing Apache configs
# Method 2: Parse RHEL-style Apache configs
if [ -d "/etc/httpd/conf.d" ]; then
grep -h "ServerName\|ServerAlias" /etc/httpd/conf.d/*.conf 2>/dev/null | \
awk '{print $2}' | sort -u
return 0
fi
# Method 3: Check for domain directories in user's home (common structure: ~/domain.com/public_html)
if [ -d "$home_dir" ]; then
find "$home_dir" -maxdepth 2 -name "public_html" -o -name "html" 2>/dev/null | \
find "$home_dir" -maxdepth 2 \( -name "public_html" -o -name "html" \) -type d 2>/dev/null | \
sed "s|${home_dir}/||; s|/public_html$||; s|/html$||" | \
grep -v "^$" | sort -u
return 0
fi
}
#############################################################################